Skip to content
Snippets Groups Projects
Commit faa416a8 authored by David Hendriks's avatar David Hendriks
Browse files

working on ensemble_tests

parent ab211961
No related branches found
No related tags found
No related merge requests found
...@@ -59,6 +59,7 @@ ensemble_filters_off {8} ensemble_filter_{9} 1 probability 0.1" ...@@ -59,6 +59,7 @@ ensemble_filters_off {8} ensemble_filter_{9} 1 probability 0.1"
return argstring return argstring
def test_return_persistent_data_memaddr(): def test_return_persistent_data_memaddr():
""" """
Test case to check if the memory adress has been created succesfully Test case to check if the memory adress has been created succesfully
...@@ -90,7 +91,9 @@ def test_passing_persistent_data_to_run_system(): ...@@ -90,7 +91,9 @@ def test_passing_persistent_data_to_run_system():
ensemble_jsons_1 = [ ensemble_jsons_1 = [
line for line in output_1.splitlines() if line.startswith("ENSEMBLE_JSON") line for line in output_1.splitlines() if line.startswith("ENSEMBLE_JSON")
] ]
json_1 = handle_ensemble_string_to_json(ensemble_jsons_1[0][len("ENSEMBLE_JSON ") :]) json_1 = handle_ensemble_string_to_json(
ensemble_jsons_1[0][len("ENSEMBLE_JSON ") :]
)
# Doing 2 systems in a row. # Doing 2 systems in a row.
output_1_deferred = _binary_c_bindings.run_system( output_1_deferred = _binary_c_bindings.run_system(
...@@ -102,14 +105,18 @@ def test_passing_persistent_data_to_run_system(): ...@@ -102,14 +105,18 @@ def test_passing_persistent_data_to_run_system():
ensemble_jsons_2 = [ ensemble_jsons_2 = [
line for line in output_2.splitlines() if line.startswith("ENSEMBLE_JSON") line for line in output_2.splitlines() if line.startswith("ENSEMBLE_JSON")
] ]
json_2 = handle_ensemble_string_to_json(ensemble_jsons_2[0][len("ENSEMBLE_JSON ") :]) json_2 = handle_ensemble_string_to_json(
ensemble_jsons_2[0][len("ENSEMBLE_JSON ") :]
)
# Doing system one again. # Doing system one again.
output_1_again = _binary_c_bindings.run_system(argstring=argstring_1) output_1_again = _binary_c_bindings.run_system(argstring=argstring_1)
ensemble_jsons_1 = [ ensemble_jsons_1 = [
line for line in output_1_again.splitlines() if line.startswith("ENSEMBLE_JSON") line for line in output_1_again.splitlines() if line.startswith("ENSEMBLE_JSON")
] ]
json_1_again = handle_ensemble_string_to_json(ensemble_jsons_1[0][len("ENSEMBLE_JSON ") :]) json_1_again = handle_ensemble_string_to_json(
ensemble_jsons_1[0][len("ENSEMBLE_JSON ") :]
)
assert ( assert (
json_1 == json_1_again json_1 == json_1_again
...@@ -117,18 +124,62 @@ def test_passing_persistent_data_to_run_system(): ...@@ -117,18 +124,62 @@ def test_passing_persistent_data_to_run_system():
assert ( assert (
json_1 != json_2 json_1 != json_2
), "The output of the deferred two systems should not be the same as the first undeferred output" ), "The output of the deferred two systems should not be the same as the first undeferred output"
import pickle import pickle
def pickle_n_checksize(obj): def pickle_n_checksize(obj):
name = os.path.join(TMP_DIR, "test", "pickle") name = os.path.join(TMP_DIR, "test", "pickle")
with open(name, 'wb') as file: with open(name, "wb") as file:
pickle.dump(obj, file) pickle.dump(obj, file)
file_stats = os.stat(name) file_stats = os.stat(name)
print("size: {}mb".format(file_stats.st_size/(1024*1024))) print("size: {}mb".format(file_stats.st_size / (1024 * 1024)))
os.remove(name) os.remove(name)
def test_full_ensemble_output_new():
"""
Function to just output the whole ensemble
"""
argstring_1 = return_argstring(defer_ensemble=0, ensemble_filters_off=0)
print(argstring_1)
quit()
output_1 = _binary_c_bindings.run_system(argstring=argstring_1)
# print(output_1)
ensemble_jsons_1 = [
line for line in output_1.splitlines() if line.startswith("ENSEMBLE_JSON")
]
print("start")
start = time.time()
json_1 = eval(ensemble_jsons_1[0][len("ENSEMBLE_JSON ") :])
# json_1 = eval(
# [line for line in _binary_c_bindings.run_system(argstring=argstring_1).splitlines() if line.startswith("ENSEMBLE_JSON")][0][len("ENSEMBLE_JSON ") :]
# )
stop = time.time()
print("stop")
pickle_n_checksize(json_1)
print("took {}s to decode".format(stop - start))
# print("Size of the json in memory: {}".format(sys.getsizeof(json_1)))
print(json_1.keys())
# assert statements:
assert "number_counts" in json_1.keys()
assert "HRD" in json_1.keys()
assert "HRD(t)" in json_1.keys()
assert "Xyield" in json_1.keys()
assert "distributions" in json_1.keys()
assert "scalars" in json_1.keys()
def test_full_ensemble_output(): def test_full_ensemble_output():
""" """
Function to just output the whole ensemble Function to just output the whole ensemble
...@@ -145,8 +196,6 @@ def test_full_ensemble_output(): ...@@ -145,8 +196,6 @@ def test_full_ensemble_output():
argstring_1 += " ensemble_filter_SPECTRAL_TYPES 1 " argstring_1 += " ensemble_filter_SPECTRAL_TYPES 1 "
argstring_1 += " ensemble_filter_HRD 1 " argstring_1 += " ensemble_filter_HRD 1 "
output_1 = _binary_c_bindings.run_system(argstring=argstring_1) output_1 = _binary_c_bindings.run_system(argstring=argstring_1)
pickle_n_checksize(output_1) pickle_n_checksize(output_1)
ensemble_jsons_1 = [ ensemble_jsons_1 = [
...@@ -155,13 +204,13 @@ def test_full_ensemble_output(): ...@@ -155,13 +204,13 @@ def test_full_ensemble_output():
pickle_n_checksize(ensemble_jsons_1[0][len("ENSEMBLE_JSON ") :]) pickle_n_checksize(ensemble_jsons_1[0][len("ENSEMBLE_JSON ") :])
print('start') print("start")
start = time.time() start = time.time()
json_1 = handle_ensemble_string_to_json( json_1 = handle_ensemble_string_to_json(
ensemble_jsons_1[0][len("ENSEMBLE_JSON ") :] ensemble_jsons_1[0][len("ENSEMBLE_JSON ") :]
) )
stop = time.time() stop = time.time()
print('stop') print("stop")
pickle_n_checksize(json_1) pickle_n_checksize(json_1)
...@@ -248,9 +297,7 @@ def test_adding_ensemble_output(): ...@@ -248,9 +297,7 @@ def test_adding_ensemble_output():
) )
# Get a memory location # Get a memory location
test_2_persistent_data_memaddr = ( test_2_persistent_data_memaddr = _binary_c_bindings.return_persistent_data_memaddr()
_binary_c_bindings.return_persistent_data_memaddr()
)
# Run the systems and defer the output each time # Run the systems and defer the output each time
_ = _binary_c_bindings.run_system( _ = _binary_c_bindings.run_system(
...@@ -283,9 +330,7 @@ def test_adding_ensemble_output(): ...@@ -283,9 +330,7 @@ def test_adding_ensemble_output():
# Then the second one uses that memory to combine its results with, but doesn't defer the # Then the second one uses that memory to combine its results with, but doesn't defer the
# data after that, so it will print it after the second run is done # data after that, so it will print it after the second run is done
test_3_persistent_data_memaddr = ( test_3_persistent_data_memaddr = _binary_c_bindings.return_persistent_data_memaddr()
_binary_c_bindings.return_persistent_data_memaddr()
)
# Run the systems and defer the output once and the second time not, so that the second run # Run the systems and defer the output once and the second time not, so that the second run
# automatically prints out the results # automatically prints out the results
...@@ -337,7 +382,7 @@ def test_combine_with_empty_json(): ...@@ -337,7 +382,7 @@ def test_combine_with_empty_json():
""" """
Test for merging with an empty dict Test for merging with an empty dict
""" """
argstring_1 = return_argstring(defer_ensemble=0) argstring_1 = return_argstring(defer_ensemble=0)
output_1 = _binary_c_bindings.run_system(argstring=argstring_1) output_1 = _binary_c_bindings.run_system(argstring=argstring_1)
ensemble_jsons_1 = [ ensemble_jsons_1 = [
...@@ -399,6 +444,7 @@ def test_free_and_json_output(): ...@@ -399,6 +444,7 @@ def test_free_and_json_output():
def all(): def all():
# test_return_persistent_data_memaddr() # test_return_persistent_data_memaddr()
# test_passing_persistent_data_to_run_system() # test_passing_persistent_data_to_run_system()
test_full_ensemble_output_new()
# test_full_ensemble_output() # test_full_ensemble_output()
test_adding_ensemble_output() test_adding_ensemble_output()
test_free_and_json_output() test_free_and_json_output()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment