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
1624025f
Commit
1624025f
authored
4 years ago
by
David Hendriks
Browse files
Options
Downloads
Patches
Plain Diff
added some tests for the persistent data and modified the bindings
parent
1490a781
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/binary_c_python.c
+1
-2
1 addition, 2 deletions
src/binary_c_python.c
tests/test_return_persistent_data_memaddr.py
+51
-11
51 additions, 11 deletions
tests/test_return_persistent_data_memaddr.py
with
52 additions
and
13 deletions
src/binary_c_python.c
+
1
−
2
View file @
1624025f
...
...
@@ -238,7 +238,7 @@ static PyObject* binary_c_run_system(PyObject *self, PyObject *args, PyObject *k
return
NULL
;
}
printf
(
"Input persistent_Data_memaddr: %lu"
,
persistent_data_memaddr
);
printf
(
"Input persistent_Data_memaddr: %lu
\n
"
,
persistent_data_memaddr
);
/* Call c-function */
char
*
buffer
;
...
...
@@ -270,7 +270,6 @@ static PyObject* binary_c_run_system(PyObject *self, PyObject *args, PyObject *k
Safe_free
(
error_buffer
);
// TODO: fix that the return_error_string is returned.
return
return_string
;
}
...
...
This diff is collapsed.
Click to expand it.
tests/test_return_persistent_data_memaddr.py
+
51
−
11
View file @
1624025f
import
binary_c_python_api
import
textwrap
import
json
# Evolution functions
...
...
@@ -10,17 +11,19 @@ def test_return_persistent_data_memaddr():
print
(
"
Binary_c output:
"
)
print
(
textwrap
.
indent
(
str
(
output
),
"
\t
"
))
return
output
def
test_passing_persistent_data_to_run_system
():
# Function to test the passing of the persistent data memoery adress, and having ensemble_defer = True
# We should see that the results of multiple systems have been added to the one output json
m1
=
15.0
# Msun
m2
=
14.0
# Msun
separation
=
0
# 0 = ignored, use period
orbital_period
=
4530.0
# days
orbital_period
=
4530
00000000
.0
# days
eccentricity
=
0.0
metallicity
=
0.02
max_evolution_time
=
15000
argstring
=
"
binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} eccentricity {4:g} metallicity {5:g} max_evolution_time {6:g}
"
.
format
(
argstring_1
=
"
binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} eccentricity {4:g} metallicity {5:g} max_evolution_time {6:g} ensemble 1 ensemble_filters_off 1 ensemble_filter_SUPERNOVAE 1
"
.
format
(
m1
,
m2
,
separation
,
...
...
@@ -30,17 +33,54 @@ def test_passing_persistent_data_to_run_system():
max_evolution_time
,
)
persistent_data_memaddr
=
test_return_persistent_data_memaddr
()
print
(
persistent_data_memaddr
)
output
=
binary_c_python_api
.
run_system
(
argstring
=
argstring
,
persistent_data_memaddr
=
persistent_data_memaddr
)
argstring_1_deferred
=
"
binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} eccentricity {4:g} metallicity {5:g} max_evolution_time {6:g} ensemble 1 ensemble_defer 1 ensemble_filters_off 1 ensemble_filter_SUPERNOVAE 1
"
.
format
(
m1
,
m2
,
separation
,
orbital_period
,
eccentricity
,
metallicity
,
max_evolution_time
,
)
argstring2
=
"
binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} eccentricity {4:g} metallicity {5:g} max_evolution_time {6:g} ensemble 1 ensemble_filters_off 1 ensemble_filter_SUPERNOVAE 1
"
.
format
(
m1
+
10
,
m2
,
separation
,
orbital_period
,
eccentricity
,
metallicity
,
max_evolution_time
,
)
persistent_data_memaddr
=
binary_c_python_api
.
return_persistent_data_memaddr
(
""
)
# print(persistent_data_memaddr)
print
(
"
function: test_run_system
"
)
print
(
"
Binary_c output:
"
)
print
(
textwrap
.
indent
(
output
,
"
\t
"
))
output_1
=
binary_c_python_api
.
run_system
(
argstring
=
argstring_1
)
ensemble_jsons_1
=
[
line
for
line
in
output_1
.
splitlines
()
if
line
.
startswith
(
"
ENSEMBLE_JSON
"
)]
json_1
=
json
.
loads
(
ensemble_jsons_1
[
0
][
len
(
"
ENSEMBLE_JSON
"
):])
# Doing 2 systems in a row.
output_1_deferred
=
binary_c_python_api
.
run_system
(
argstring
=
argstring_1_deferred
,
persistent_data_memaddr
=
persistent_data_memaddr
)
output_2
=
binary_c_python_api
.
run_system
(
argstring
=
argstring2
,
persistent_data_memaddr
=
persistent_data_memaddr
)
ensemble_jsons_2
=
[
line
for
line
in
output_2
.
splitlines
()
if
line
.
startswith
(
"
ENSEMBLE_JSON
"
)]
json_2
=
json
.
loads
(
ensemble_jsons_2
[
0
][
len
(
"
ENSEMBLE_JSON
"
):])
# Doing system one again.
output_1_again
=
binary_c_python_api
.
run_system
(
argstring
=
argstring_1
)
ensemble_jsons_1
=
[
line
for
line
in
output_1_again
.
splitlines
()
if
line
.
startswith
(
"
ENSEMBLE_JSON
"
)]
json_1_again
=
json
.
loads
(
ensemble_jsons_1
[
0
][
len
(
"
ENSEMBLE_JSON
"
):])
print
(
"
Twice the same system are they equal?:
"
)
print
(
json_1
==
json_1_again
)
print
(
"
first system vs deferred double system?:
"
)
print
(
json_1
==
json_2
)
# printf("combined double system vs deferred double system?:")
####
if
__name__
==
"
__main__
"
:
test_return_persistent_data_memaddr
()
test_passing_persistent_data_to_run_system
()
\ No newline at end of file
test_passing_persistent_data_to_run_system
()
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