Closed pausz closed 3 years ago
environment yaml file in txt format cause github doesn't recognise .yaml for attachments
Thanks @pausz ! So this is a couple things, a bug and a poor error message :) Actually, none of these should work since the population isn't being created with enough information (specifically, contact layer information is missing). All of the examples above now (in version 3.0.2) raise the error
KeyNotFoundError: Your population does not have any layer keys, but your simulation does ['a']. If you called cv.People() directly, you probably need cv.make_people() instead.
But you're right that floats weren't being handled correctly before in this case; this has been fixed, so now e.g. this does work:
import covasim as cv
import sciris as sc
def make_save_people(pop_size=20e3, pop_infected=0, popfilename='mypop.pop'):
ppl_pars = {'pop_size': pop_size,
'pop_infected': pop_infected,
}
# people = cv.People(pars=ppl_pars) # This won't work
people = cv.make_people(cv.Sim(ppl_pars)) # But this does
# Save object
sc.saveobj(popfilename, people)
return
popfilename='mypop-float.pop'
make_save_people(popfilename=popfilename)
sim_pars = dict(
pop_size = 20e3,
)
sim = cv.Sim(pars=sim_pars,
popfile=popfilename,
load_pop=True)
sim.initialize()
sim.run()
I had a look at making it so you could provide parameters directly to cv.make_people()
instead of supplying a sim. It's possible, but makes the logic pretty convoluted. Since it's almost as easy to call cv.make_people(cv.Sim(ppl_pars))
as cv.make_people(ppl_pars)
and since there would have to be a lot of duplication of parameter checking otherwise, I'm inclined to leave it as-is.
Original bug fixed, and error message now more informative
Describe the bug
TypeError: 'float' object cannot be interpreted as an integer
arises ifpop_size
is a float (eg, when expressed as 10e3), though the error depends on wherepop_size
was defined as a float rather than integer.This was the original stack was
To reproduce
Case A:
pop_size=200e3
inmake_save_people()
andsim_pars
Stack:
Case B:
pop_size=200000
inmake_save_people()
andpop_size=200e3
insim_pars
Stack:
Case C:
pop_size=200e3
inmake_save_people()
andpop_size=200000
insim_pars
Stack:
Case D:
pop_size=200000
inmake_save_people()
andsim_pars
No errors are produced
Expected behavior
No errors whether
pop_size
is defined by users as a (round) float or integer number, anywhere in the code. For instance, the following snippets of code work without errors despitepop_size
being a float:or
Platform:
pip install -e
;