Closed rbelew closed 4 years ago
Hi @rbelew , thanks for raising this. The original error seems to be caused by:
sciris.sc_utils.KeyNotFoundError: Key(s) ['storage', 'tot_pop'] not found
Are the keys 'storage'
and 'tot_pop'
present in the parameters object you are supplying? The only parameters that should be entered in the pars
object are those present by default:
import covasim as cv
sim = cv.Sim()
sim.pars.keys()
>>> dict_keys(['pop_size', 'pop_infected', 'pop_type', 'location', 'start_day', 'end_day', 'n_days', 'rand_seed', 'verbose', 'pop_scale', 'rescale', 'rescale_threshold', 'rescale_factor', 'beta', 'contacts', 'dynam_layer', 'beta_layer', 'n_imports', 'beta_dist', 'viral_dist', 'asymp_factor', 'iso_factor', 'quar_factor', 'quar_period', 'dur', 'rel_symp_prob', 'rel_severe_prob', 'rel_crit_prob', 'rel_death_prob', 'prog_by_age', 'prognoses', 'interventions', 'analyzers', 'timelimit', 'stopping_func', 'n_beds_hosp', 'n_beds_icu', 'no_hosp_factor', 'no_icu_factor'])
The data file and location are properties of the simulation, not model parameters, so they should only be supplied as arguments to Sim()
and should not be present in the parameters object. Storage only pertains to Optuna, and should also not be part of the pars
object. The pars
object passed to Sim()
is indeed used to population sim.pars
, and the error occurs when you pass an invalid or unrecognized value to it (here, 'storage'
and 'tot_pop'
).
Hope that answers your question but if not happy to provide more information.
Got it! yes, i was using pars for both simulation and model parameters. thanks for your quick response.
and since this is my first but i am sure not last interaction with you: THANKS, THANKS for your group's work on covasim!! between the code base and the {panovska-griffiths20} publication, it is a game changer!
You're most welcome @rbelew! Happy to be of help and let us know if you have more questions.
Describe the bug
I am getting
KeyNotFoundError: Key(s)
exceptions, despite mypars
containing these key/values?To reproduce
I am trying to replicate the behavior described in the {panovska-griffiths20} and therefore use the following call sequence:
sim = create_sim(pars.best)
def create_sim(x):
Note that this call to
Sim()
specifies bothdatafile
andlocation
parameters, AGAIN as separate parameters to Sim(), because otherwise it complained these were missing; Question#1: why?!Here is the full error stack:
I've added debug output to
Sim.update_pars()
just before it callssuper().update_pars()
:I've also added debug output to
ParseObj.update_pars()
This results in the
Sim.update_pars()
output to be produced twice, the first time with 39 keys, and the second time with only 19, whencreate_sim
is called again by theobjective()
function required for optuna.The output from the
ParseObj.update_pars()
output showQuestion#2: I'm not sure of the intent of distinguishing between the passed
pars
value andself.pars
, leading to theKeyNotFoundError
?For now, I have just removed that test, and everything seems to work.
Expected behavior
The call to
Sim()
should make use of thepars
dictionary provided.Platform (please complete the following information):