OpenABM-Covid19 icon indicating copy to clipboard operation
OpenABM-Covid19 copied to clipboard

Tests running the C executable

Open ghost opened this issue 4 years ago • 1 comments

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.

ghost avatar Jul 13 '20 16:07 ghost

@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)

p-robot avatar Jul 13 '20 17:07 p-robot