Commit faa416a8 authored by David Hendriks's avatar David Hendriks
Browse files

working on ensemble_tests

parent ab211961
Loading
Loading
Loading
Loading
+62 −16
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ ensemble_filters_off {8} ensemble_filter_{9} 1 probability 0.1"

    return argstring


def test_return_persistent_data_memaddr():
    """
    Test case to check if the memory adress has been created succesfully
@@ -90,7 +91,9 @@ def test_passing_persistent_data_to_run_system():
    ensemble_jsons_1 = [
        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.
    output_1_deferred = _binary_c_bindings.run_system(
@@ -102,14 +105,18 @@ def test_passing_persistent_data_to_run_system():
    ensemble_jsons_2 = [
        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.
    output_1_again = _binary_c_bindings.run_system(argstring=argstring_1)
    ensemble_jsons_1 = [
        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 (
        json_1 == json_1_again
@@ -117,18 +124,62 @@ def test_passing_persistent_data_to_run_system():
    assert (
        json_1 != json_2
    ), "The output of the deferred two systems should not be the same as the first undeferred output"


import pickle


def pickle_n_checksize(obj):

    name = os.path.join(TMP_DIR, "test", "pickle")

    with open(name, 'wb') as file:
    with open(name, "wb") as file:
        pickle.dump(obj, file)

    file_stats = os.stat(name)
    print("size: {}mb".format(file_stats.st_size / (1024 * 1024)))
    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():
    """
    Function to just output the whole ensemble
@@ -145,8 +196,6 @@ def test_full_ensemble_output():
    argstring_1 += " ensemble_filter_SPECTRAL_TYPES 1 "
    argstring_1 += " ensemble_filter_HRD 1 "



    output_1 = _binary_c_bindings.run_system(argstring=argstring_1)
    pickle_n_checksize(output_1)
    ensemble_jsons_1 = [
@@ -155,13 +204,13 @@ def test_full_ensemble_output():

    pickle_n_checksize(ensemble_jsons_1[0][len("ENSEMBLE_JSON ") :])

    print('start')
    print("start")
    start = time.time()
    json_1 = handle_ensemble_string_to_json(
        ensemble_jsons_1[0][len("ENSEMBLE_JSON ") :]
    )
    stop = time.time()
    print('stop')
    print("stop")

    pickle_n_checksize(json_1)

@@ -248,9 +297,7 @@ def test_adding_ensemble_output():
    )

    # Get a memory location
    test_2_persistent_data_memaddr = (
        _binary_c_bindings.return_persistent_data_memaddr()
    )
    test_2_persistent_data_memaddr = _binary_c_bindings.return_persistent_data_memaddr()

    # Run the systems and defer the output each time
    _ = _binary_c_bindings.run_system(
@@ -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
    # data after that, so it will print it after the second run is done

    test_3_persistent_data_memaddr = (
        _binary_c_bindings.return_persistent_data_memaddr()
    )
    test_3_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
    # automatically prints out the results
@@ -399,6 +444,7 @@ def test_free_and_json_output():
def all():
    # test_return_persistent_data_memaddr()
    # test_passing_persistent_data_to_run_system()
    test_full_ensemble_output_new()
    # test_full_ensemble_output()
    test_adding_ensemble_output()
    test_free_and_json_output()