3.1.2. de_sim.examples package

3.1.2.2. Submodules

3.1.2.3. de_sim.examples.debug_logs module

Setup simulation example configuration

Author

Arthur Goldberg <Arthur.Goldberg@mssm.edu>

Date

2016-10-03

Copyright

2016-2020, Karr Lab

License

MIT

3.1.2.4. de_sim.examples.minimal_simulation module

A minimal simulation, containing one simulation object.

Author

Arthur Goldberg <Arthur.Goldberg@mssm.edu>

Date

2018-02-27

Copyright

2018-2020, Karr Lab

License

MIT

class de_sim.examples.minimal_simulation.MinimalSimulationObject(name, delay)[source]

Bases: de_sim.simulation_object.SimulationObject

SimulationObject subclasses represent the state of a simulation and the actions that schedule and handle events

event_handlers = [(<class 'de_sim.event_message.MessageSentToSelf'>, <function MinimalSimulationObject.handle_simulation_event>)][source]
handle_simulation_event(event)[source]

Handle a simulation event

init_before_run()[source]

Initialize before a simulation run; called by the simulator

messages_sent = [<class 'de_sim.event_message.MessageSentToSelf'>][source]
metadata = <de_sim.simulation_object.SimulationObjectMetadata object>[source]
class de_sim.examples.minimal_simulation.RunMinimalSimulation[source]

Bases: object

static main(args)[source]
static parse_args(cli_args=None)[source]

Parse command line arguments

Parameters

cli_args (list, optional) – if provided, use to test command line parsing

Returns

parsed command line arguments

Return type

argparse.Namespace

3.1.2.5. de_sim.examples.phold module

Parallel hold (PHOLD) model commonly used to benchmark parallel discrete-event simulators

Author

Arthur Goldberg <Arthur.Goldberg@mssm.edu>

Date

2016-06-10

Copyright

2016-2020, Karr Lab

License

MIT

class de_sim.examples.phold.PholdSimulationObject(name, args)[source]

Bases: de_sim.simulation_object.SimulationObject

event_handlers = [(<class 'de_sim.event_message.MessageSentToSelf'>, 'handle_simulation_event'), (<class 'de_sim.event_message.MessageSentToOtherObject'>, 'handle_simulation_event'), (<class 'de_sim.event_message.InitMsg'>, 'handle_simulation_event')][source]
handle_simulation_event(event)[source]

Handle a simulation event

init_before_run()[source]

Initialize before a simulation run; called by the simulator

log_debug_msg(msg)[source]
messages_sent = [<class 'de_sim.event_message.MessageSentToSelf'>, <class 'de_sim.event_message.MessageSentToOtherObject'>, <class 'de_sim.event_message.InitMsg'>][source]
metadata = <de_sim.simulation_object.SimulationObjectMetadata object>[source]
class de_sim.examples.phold.RunPhold[source]

Bases: object

static main(args)[source]
static parse_args(cli_args)[source]

Parse command line arguments

Parameters

cli_args (list) – command line arguments

Returns

parsed command line arguments

Return type

argparse.Namespace

de_sim.examples.phold.obj_index(obj_name)[source]
de_sim.examples.phold.obj_name(obj_num)[source]

3.1.2.6. de_sim.examples.random_walk module

Simulate a random walk whose position changes by -1 or +1 at each event, and inter-event delays are 1 or 2 time units

Author

Arthur Goldberg <Arthur.Goldberg@mssm.edu>

Date

2018-02-27

Copyright

2018-2020, Karr Lab

License

MIT

class de_sim.examples.random_walk.RandomWalkSimulationObject(name)[source]

Bases: de_sim.simulation_object.SimulationObject

A one-dimensional random walk model, with random times between steps

Each step moves either -1 or +1, with equal probability. The delay between steps is 1 or 2, also with equal probability.

name[source]

this simulation object’s name, which is unique across all simulation objects

Type

str

state[source]

the current position; initialized to 0

Type

int

history[source]

the walk’s position as a function of time

Type

dict of list

event_handlers = [(<class 'de_sim.event_message.RandomStepMessage'>, <function RandomWalkSimulationObject.handle_step_event>)][source]
handle_step_event(event)[source]

Handle a step event

init_before_run()[source]

Initialize before a simulation run; called by the simulator

Schedule the first event

messages_sent = [<class 'de_sim.event_message.RandomStepMessage'>][source]
metadata = <de_sim.simulation_object.SimulationObjectMetadata object>[source]
schedule_next_step()[source]

Schedule the next event, which is a step

class de_sim.examples.random_walk.RunRandomWalkSimulation[source]

Bases: object

static main(args)[source]
static parse_args(cli_args=None)[source]

Parse command line arguments

Parameters

cli_args (list, optional) – if provided, use to test command line parsing

Returns

parsed command line arguments

Return type

argparse.Namespace

3.1.2.7. de_sim.examples.sirs module

Example DE-Sim implementations of stochastic Susceptible, Infectious, or Recovered (SIR) epidemic models

Author

Arthur Goldberg <Arthur.Goldberg@mssm.edu>

Date

2020-07-08

Copyright

2020, Karr Lab

License

MIT

class de_sim.examples.sirs.AccessSIRObjectState(sir)[source]

Bases: de_sim.simulation_checkpoint_object.AccessStateObjectInterface

Get the state of an SIR object

sir[source]

an SIR object

Type

obj

random_state[source]

a random state

Type

numpy.random.RandomState

get_checkpoint_state(time)[source]

Get the SIR object’s state

Parameters

time (float) – current time; ignored

get_random_state()[source]

Get the SIR object’s random state

class de_sim.examples.sirs.RunSIRs(checkpoint_dir)[source]

Bases: object

last_checkpoint()[source]

Get the last checkpoint of the last simulation run

Returns

the last checkpoint of the last simulation run

Return type

Checkpoint

print_history()[source]

Print an SIR simulation’s history

simulate(sir_class, max_time, **sir_args)[source]

Create and run an SIR simulation

Parameters
  • sir_class (type) – a type of SIR class to run

  • max_time (float) – simulation end time

  • sir_args (dict) – arguments for an SIR object

class de_sim.examples.sirs.SIR(name, s, i, N, beta, gamma, recording_period)[source]

Bases: de_sim.simulation_object.SimulationObject

Implement a Susceptible, Infectious, or Recovered (SIR) epidemic model

This example uses DE-Sim to implement a continuous-time Markov chain (CTMC) SIR epidemic model, as described in section 3 of Allen (2017).

Allen, L.J., 2017. A primer on stochastic epidemic models: Formulation, numerical simulation, and analysis. Infectious Disease Modelling, 2(2), pp.128-142.

s[source]

number of susceptible subjects

Type

int

i[source]

number of infectious subjects

Type

int

N[source]

total number of susceptible subjects, a constant

Type

int

beta[source]

SIR beta parameter

Type

float

gamma[source]

SIR gamma parameter

Type

float

recording_period[source]

time step for recording state

Type

float

random_state[source]

a random state

Type

numpy.random.RandomState

history[source]

list of recorded states

Type

list

event_handlers = [(<class 'de_sim.event_message.SusceptibleToInfectious'>, 'handle_s_to_i'), (<class 'de_sim.event_message.InfectiousToRecovered'>, 'handle_i_to_r')][source]
handle_i_to_r(event)[source]

Handle an infectious to recovered event

Parameters

event (Event) – simulation event; not used

handle_s_to_i(event)[source]

Handle a susceptible to infectious event

Parameters

event (Event) – simulation event; not used

init_before_run()[source]

Send the initial events, and record the initial state

messages_sent = [<class 'de_sim.event_message.SusceptibleToInfectious'>, <class 'de_sim.event_message.InfectiousToRecovered'>][source]
metadata = <de_sim.simulation_object.SimulationObjectMetadata object>[source]
schedule_next_event()[source]

Schedule the next SIR event

class de_sim.examples.sirs.SIR2(name, s, i, N, beta, gamma, recording_period)[source]

Bases: de_sim.examples.sirs.SIR

Version 2 of an SIR epidemic model

SIR2 is similar to SIR, but uses one event message type for both transitions, and a single message handler to process transition events.

event_handlers = [(<class 'de_sim.event_message.TransitionMessage'>, 'handle_state_transition')][source]
handle_state_transition(event)[source]

Handle an infectious state transition

Parameters

event (Event) – simulation event that contains the type of transition

messages_sent = [<class 'de_sim.event_message.TransitionMessage'>][source]
metadata = <de_sim.simulation_object.SimulationObjectMetadata object>[source]
schedule_next_event()[source]

Schedule the next SIR event

class de_sim.examples.sirs.StateTransitionType[source]

Bases: enum.Enum

State transition types

i_to_r = 'Transition from Infectious to Recovered'[source]
s_to_i = 'Transition from Susceptible to Infectious'[source]

3.1.2.8. Module contents