InstituteforDiseaseModeling / covasim

COVID-19 Agent-based Simulator (Covasim): a model for exploring coronavirus dynamics and interventions
https://covasim.org
MIT License
250 stars 223 forks source link

Unittest interventions #175

Closed CWiswell-IDM closed 4 years ago

CWiswell-IDM commented 4 years ago

Should add tests necessary for

Any suggestions of things to add, ground to cover, appreciated!

CWiswell-IDM commented 4 years ago

Looking at failures now...

CWiswell-IDM commented 4 years ago

One was a test defect that I'm pushing a fix for.

One I believe to be a real bug: https://github.com/InstituteforDiseaseModeling/covasim/issues/150

One is a real issue #176, but I changed the test to work around it (set test_delay to 1 instead of 0)

CWiswell-IDM commented 4 years ago

Somewhere along the way, change beta began showing effects on the day it was invoked, rather than the following day (either way is acceptable depending on how you want it to work...) the feature is doing a thing that is acceptable, but we really ought to write this down. @JSchripsema-IDM, if we have / are ready to create intervention documentation this would go in there. Script to demonstrate the timing effect below:

import covasim as cv
import json

change_beta_intervention = cv.change_beta(
    days    =[ 30,  32,  40,  42,  50],
    changes= [0.0, 1.0, 0.0, 1.0, 0.0]
)

params = {
    'pop_size': 10000,
    'n_days': 60,
    'interventions': change_beta_intervention
}

sim = cv.Sim(pars=params)
sim.run()
save_filename = "DEBUG_change_beta_days_test.json"
sim.to_json(filename=save_filename,
            indent=4)
with open(save_filename) as infile:
    sim_json = json.load(infile)
    pass

results = sim_json['results']
new_infections = results['new_infections']

print(f"New infections before, during, after brutal change beta: {new_infections[29:33]}")

Hope this helps! I pushed a commit to update that test (test_change_beta_days) and the test is now passing locally.

CWiswell-IDM commented 4 years ago

Failing test is because of #150, I think this is good.

ckerr-IDM commented 4 years ago

@CWiswell-IDM thank you! it wasn't documented before and remains undocumented, except in the docstring. probably don't need to document that it now works as expected, though :) @CWiswell-IDM is this PR ready for review? (i just updated master btw, if you want to merge)

cliffckerr commented 4 years ago

I'm not sure why the number of commits shown is wrong...but it seems fine.

CWiswell-IDM commented 4 years ago

I'll try your code! I'll be trying a 0.9 sensitivity though.