OpenABM-Covid19
OpenABM-Covid19 copied to clipboard
Tests running the C executable
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.
@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)