Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests running the C executable #146

Open
ghost opened this issue Jul 13, 2020 · 1 comment
Open

Tests running the C executable #146

ghost opened this issue Jul 13, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Jul 13, 2020

A lot of tests still run by using the compiled C executable covid19ibm.exe. In #10 I added a new function in C so that the parameters can be passed using a buffer instead of saving the parameters to a file and then opening the file from C like in the following test from test_ibm.py.

        """
        Set parameter value to zero should result in zero sum of output column
        """
        params = ParameterSet(constant.TEST_DATA_FILE, line_number = 1)
        if parameter == 'fraction_asymptomatic':
            params = utils.set_fraction_asymptomatic_all( params, 0.0 )
        if parameter == 'n_seed_infection':
            params.set_param( 'n_seed_infection', 0 )
        params = utils.set_fatality_fraction_all(params, 0.0)
        params.write_params(constant.TEST_DATA_FILE)

        # Call the model, pipe output to file, read output file
        file_output = open(constant.TEST_OUTPUT_FILE, "w")
        completed_run = subprocess.run([constant.command], stdout = file_output, shell = True)
        df_output = pd.read_csv(constant.TEST_OUTPUT_FILE, comment = "#", sep = ",")

        np.testing.assert_equal(df_output[output_column].sum(), 0)

@p-robot @roberthinch how does these tests work? is there anything to run the test in Python just like in C or do I have to recreate what's in main.c in Python?

After sorting this out I should be able to change all the tests to run from Python without using the executable.

@p-robot
Copy link
Contributor

p-robot commented Jul 13, 2020

@danielmonterocr, I think all the tests should be able to be ported to the Python interface. We've been trying to write all new tests using the Python interface. The above test is parameterised, but for the situation where parameter == 'n_seed_infection' I think the above could be run using the Python interface in the following manner ...

params = utils.get_params_swig()

params.set_param( 'n_seed_infection', 0 )
params = utils.set_fatality_fraction_all(params, 0.0)

model  = utils.get_model_swig( params )
for time in range( params[ "end_time" ] ):
    model.one_time_step()
np.testing.assert_equal(model.one_time_step_results()["total_infected"][-1], 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant