Loading src/binary_c_python.c +1 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; } Loading tests/test_return_persistent_data_memaddr.py +51 −11 Original line number Diff line number Diff line import binary_c_python_api import textwrap import json # Evolution functions Loading @@ -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 = 453000000000.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, Loading @@ -30,13 +33,50 @@ 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?:") Loading Loading
src/binary_c_python.c +1 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; } Loading
tests/test_return_persistent_data_memaddr.py +51 −11 Original line number Diff line number Diff line import binary_c_python_api import textwrap import json # Evolution functions Loading @@ -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 = 453000000000.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, Loading @@ -30,13 +33,50 @@ 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?:") Loading