-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rethink Sim API #488
Rethink Sim API #488
Conversation
Rethink sim api init
@daniel-klein I made it so you can do |
…497. Also fixing a bug in Pregnancy regarding which uids are used in determining the sex of newborns.
…into rethink-sim-api
Demographic update_results normalization
Description
Summary
All inputs to the sim and modules now use a
ss.Pars()
class, which handles updating and validation. It is now not necessary to ever usepars=
(although you still can if you want), so what was previously:sim = ss.Sim(pars=dict(diseases='sir', networks='random'))
is now just:
sim = ss.Sim(diseases='sir', networks='random')
Updates happen recursively, so distributions etc. can be flexibly updated.
This has significantly changed how modules are initialized; what was previously
is now:
Parameter changes
ss.Pars
class (and ass.SimPars
subclass) that handles parameter creation, updates, and validation.sim.py
toparameters.py
;ss.Sim.convert_plugins()
has been replaced byss.SimPars.convert_modules()
.ss.Pars.update()
, which performs all necessary validation on the parameters being updated.Module changes
super().__init__(pars, **kwargs)
, they now callsuper().__init__()
first, thenself.default_pars(par1=x, par2=y)
, then finallyself.update_pars(pars, **kwargs)
.ss.Module(pars=dict(par=x))
is nowss.Module(par=x)
.par_dists
has been removed; instead, distributions are specified in the default parameters, and are updated via thePars
object.ss.module_map()
maps different module types to their location in the sim.ss.find_modules()
finds all available modules (including subclasses) in Starsim.ss.dictmerge()
andss.dictmergeleft
(now handled byss.Pars.update()
).ss.get_subclasses()
andss.all_subclasses()
(now handled byss.find_modules()
).Sim
object.to_json()
andplot()
methods toModule
.connectors.py
; connectors still exist but as an empty subclass ofModule
.People and network changes
ti
,dt
, etc.) have been removed fromPeople
. Usesim.ti
,sim.dt
etc. instead. One consequence of this is thatpeople.request_death()
now requires asim
argument. Another is that network methods (e.g.add_pairs()
) now takesim
arguments instead ofpeople
arguments.SexualNetwork
is now a subclass ofDynamicNetwork
.ss.Networks
(now just anss.ndict
).Person
has been implemented as a slice ofsim.people[i]
.Other changes
ss.Sim(..., copy_inputs=False)
.Plugin
class, which contains shared logic for Interventions and Analyzers. It has afrom_func()
, which will generate an intervention/analyzer from a function.beta=1
assigned; beta must be defined explicitly if being used.sim.plot('hiv')
orsim.diseases.hiv.plot()
.ss.make_dist()
.ss.check_sims_match()
will check if the results of two or more simulations match.test_dcp.py
andtest_base.py
intotest_other.py
.test_simple.py
totest_sim.py
.test_dists.py
totest_randomness.py
.Checklist
Closes #301, #178, #412, #440