Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
binary_c-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Izzard, Robert Dr (Maths & Physics)
binary_c-python
Commits
36397811
Commit
36397811
authored
5 years ago
by
David Hendriks
Browse files
Options
Downloads
Patches
Plain Diff
updated todo and created some logging functionality
parent
8d42bbb4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
TODO.org
+2
-12
2 additions, 12 deletions
TODO.org
binaryc_python_utils/logging_functions.py
+0
-112
0 additions, 112 deletions
binaryc_python_utils/logging_functions.py
with
2 additions
and
124 deletions
TODO.org
+
2
−
12
View file @
36397811
...
...
@@ -30,7 +30,6 @@ And then to use it via
stardata->model.dt);
'
);
**** code to handle that input
sub binary_c_log_code
{
...
...
@@ -66,11 +65,7 @@ void custom_output_function(SV * x)
#pragma pop_macro(\"MAX\")
";
}
Or use it via:
*** auto logging
We should also try to be able to have the code autogenerate some logging function via the following:
**** input in perl
...
...
@@ -83,7 +78,6 @@ $population->set( C_auto_logging => {
'model.dt'
]
});
**** code to handle that input
Which is handled in perl via (see binary_grid2.pm
sub autogen_C_logging_code
...
...
@@ -121,9 +115,6 @@ sub autogen_C_logging_code
return $code;
}
*** DONE Make function in python that puts code into c function
CLOSED: [2019-10-31 Thu 11:13]
*** DONE Make function in python that generates c-function from a list of arguments
...
...
@@ -138,9 +129,8 @@ ImportError: /home/david/projects/binary_c_root/binary_c-python/libbinary_c_api.
I get this error when I am using the master version of binary_c with either branches of the python wrapper
*** TODO Make sure this works with the last major release of binaryc
*** TODO Finish testing a simpler case (see other repo)
*** DONE Finish testing a simpler case (see other repo)
CLOSED: [2019-11-08 Fri 09:37]
** General:
*** DONE Get a more reliable way of loading the default values (running a ./tbse echo or something?)
...
...
This diff is collapsed.
Click to expand it.
binaryc_python_utils/logging_functions.py
+
0
−
112
View file @
36397811
import
textwrap
# Functions for the automatic logging of stuff
# See example_perl.pm autologging
def
autogen_C_logging_code
(
logging_dict
):
"""
Function that autogenerates PRINTF statements for binaryc
Input:
dictionary where the key is the header of that logging line and items which are lists of parameters that will be put in that logging line
example: {
'
MY_STELLAR_DATA
'
:
[
'
model.time
'
,
'
star[0].mass
'
,
'
model.probability
'
,
'
model.dt
'
'
]}
"""
# Check if the input is of the correct form
if
not
type
(
logging_dict
)
==
dict
:
print
(
"
Error: please use a dictionary as input
"
)
return
None
code
=
''
# Loop over dict keys
for
key
in
logging_dict
:
logging_dict_entry
=
logging_dict
[
key
]
# Check if item is of correct type:
if
type
(
logging_dict_entry
)
==
list
:
# Construct print statement
code
+=
'
PRINTF(
"
{}
'
.
format
(
key
)
code
+=
'
{}
'
.
format
(
'
%g
'
*
len
(
logging_dict_entry
))
code
=
code
.
strip
()
code
+=
'
\n
"'
# Add format keys
for
param
in
logging_dict_entry
:
code
+=
'
,((double)stardata->{})
'
.
format
(
param
)
code
+=
'
);
\n
'
else
:
print
(
'
Error: please use a list for the list of parameters that you want to have logged
'
)
code
=
code
.
strip
()
# print("MADE AUTO CODE\n\n{}\n\n{}\n\n{}\n".format('*'*60, repr(code), '*'*60))
return
code
autogen_C_logging_code
(
{
'
MY_STELLAR_DATA
'
:
[
'
model.time
'
,
'
star[0].mass
'
],
'
my_sss2
'
:
[
'
model.time
'
,
'
star[1].mass
'
]
}
)
####################################################################################
# see example_perl.pm binary_c_log_code
def
binary_c_log_code
(
code
):
"""
Function to construct the code to construct the custom logging function
"""
custom_logging_function_string
=
"""
#pragma push_macro(
\"
MAX
\"
)
#pragma push_macro(
\"
MIN
\"
)
#undef MAX
#undef MIN
#include
\"
binary_c.h
\"
void custom_output_function(SV * x);
SV * custom_output_function_pointer(void);
SV * custom_output_function_pointer()
{{
/*
* use PTR2UV to convert the function pointer
* &custom_output_function to an unsigned int,
* which is then converted to a Perl SV
*/
return (SV*)newSVuv(PTR2UV(custom_output_function));
}}
void custom_output_function(SV * x)
{{
struct stardata_t * stardata = (struct stardata_t *)x;
{code};
}}
#undef MAX
#undef MIN
#pragma pop_macro(
\"
MIN
\"
)
#pragma pop_macro(
\"
MAX
\"
)
"""
.
format
(
code
=
code
)
print
(
textwrap
.
dedent
(
custom_logging_function_string
))
# return custom_logging_function_string
code
=
autogen_C_logging_code
(
{
'
MY_STELLAR_DATA
'
:
[
'
model.time
'
,
'
star[0].mass
'
],
'
my_sss2
'
:
[
'
model.time
'
,
'
star[1].mass
'
]
}
)
binary_c_log_code
(
code
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment