From 3fd1d856283e02fa24256837fca3b56d2ec566f7 Mon Sep 17 00:00:00 2001 From: David Hendriks <davidhendriks93@gmail.com> Date: Thu, 27 Aug 2020 18:21:09 +0100 Subject: [PATCH] changed name of function --- ...ata_memaddr.py => test_persistent_data.py} | 56 +++++++++++++++---- 1 file changed, 46 insertions(+), 10 deletions(-) rename tests/{test_return_persistent_data_memaddr.py => test_persistent_data.py} (89%) diff --git a/tests/test_return_persistent_data_memaddr.py b/tests/test_persistent_data.py similarity index 89% rename from tests/test_return_persistent_data_memaddr.py rename to tests/test_persistent_data.py index 88124da6f..40b3cef17 100644 --- a/tests/test_return_persistent_data_memaddr.py +++ b/tests/test_persistent_data.py @@ -8,12 +8,14 @@ import json import textwrap import binary_c_python_api - - - from mergedict import ConfigDict +from mergedict import MergeDict + +class SumDict(MergeDict): + @MergeDict.dispatch(float) + def merge_float(this, other): + return this + other -# import unicode class Decoder(json.JSONDecoder): """ @@ -47,6 +49,8 @@ class Decoder(json.JSONDecoder): else: return o +#### + # Evolution functions def test_return_persistent_data_memaddr(): output = binary_c_python_api.return_persistent_data_memaddr("") @@ -132,6 +136,8 @@ def ensemble_output(): print(json.dumps(json_1, indent=4)) print("took {}s to decode".format(stop-start)) + + def adding_ensemble_output(): m1 = 2 # Msun m2 = 0.1 # Msun @@ -166,6 +172,9 @@ def adding_ensemble_output(): json_1 = json.loads(ensemble_jsons_1[0][len("ENSEMBLE_JSON "):], cls=Decoder) json_2 = json.loads(ensemble_jsons_2[0][len("ENSEMBLE_JSON "):], cls=Decoder) + # test_1_total_dict = SumDict(json_1) + # test_1_total_dict.merge(json_2) + with open("json_1.json", 'w') as f: f.write(json.dumps(json_1, indent=4)) with open("json_2.json", 'w') as f: @@ -267,14 +276,41 @@ def test_free_and_json_output(): print(textwrap.indent(str(json_output_by_freeing), "\t")) +def full_output(): + m1 = 15.0 # Msun + m2 = 14.0 # Msun + separation = 0 # 0 = ignored, use period + orbital_period = 453000000000.0 # days + eccentricity = 0.0 + metallicity = 0.02 + max_evolution_time = 15000 + + 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_defer 0".format( + m1, + m2, + separation, + orbital_period, + eccentricity, + metallicity, + max_evolution_time, + ) + 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")] + + start = time.time() + json_1 = json.loads(ensemble_jsons_1[0][len("ENSEMBLE_JSON "):], cls=Decoder) + stop = time.time() + + print("took {}s to decode".format(stop-start)) + + with open("json_full_ensemble.json", 'w') as f: + f.write(json.dumps(json_1, indent=4)) + #### if __name__ == "__main__": # test_return_persistent_data_memaddr() # test_passing_persistent_data_to_run_system() # ensemble_output() - adding_ensemble_output() - - - - - # test_free_and_json_output() \ No newline at end of file + # adding_ensemble_output() + # test_free_and_json_output() + full_output() \ No newline at end of file -- GitLab