starsimhub / starsim

Starsim disease modeling framework
http://starsim.org
MIT License
14 stars 8 forks source link

Inconsistent results between runs #278

Closed robynstuart closed 8 months ago

robynstuart commented 8 months ago
s1 = ss.Sim(n_agents=2e3, pars=dict(networks='randomnet', diseases='sir'))
s2 = ss.Sim(n_agents=2e3, pars=dict(networks='randomnet', diseases='sir'))
s1.run()
s2.run()
s2.summarize()
s1.summarize()

returns:

s2.summarize()
Out[10]: 
#0. 'n_alive':            3903.8888888888887
#1. 'new_deaths':         133.88888888888889
#2. 'sir_n_susceptible':  239.30555555555554
#3. 'sir_n_infected':     3649.8611111111113
#4. 'sir_n_recovered':    14.722222222222221
#5. 'sir_prevalence':     0.9664213405874297
#6. 'sir_new_infections': 277.77777777777777
s1.summarize()
Out[11]: 
#0. 'n_alive':            3848.6111111111113
#1. 'new_deaths':         135.0
#2. 'sir_n_susceptible':  240.83333333333334
#3. 'sir_n_infected':     3583.3333333333335
#4. 'sir_n_recovered':    24.444444444444443
#5. 'sir_prevalence':     0.9634548621557708
#6. 'sir_new_infections': 277.77777777777777

these should be identical

robynstuart commented 8 months ago

Updates:

robynstuart commented 8 months ago

... or maybe not - changing dead_uids to an empty array in the sir model doesn't fix the problem, but commenting out

self.ti_dead[rec_uids] = sim.ti + p.dur_inf.rvs(dead_uids)

on line 68 of sir.py does 🤔

daniel-klein commented 8 months ago

Oh yikes, and this is just using the single rng! I am able to reproduce the bug, and have tested reproducibility extensively, so there's something strange going on here. One initial idea is that I saw a warning that ti_dead was repeated in a ndict, maybe something related to that?

daniel-klein commented 8 months ago

Perhaps as expected, renaming ti_dead in sir didn't change anything. Hmm!

daniel-klein commented 8 months ago

Found the bug! self.ti_dead[rec_uids] = sim.ti + p.dur_inf.rvs(dead_uids)

That should be rec_uids on the left, not dead_uids!

daniel-klein commented 8 months ago

Fixed