Beispiel #1
0
import pystride
from pystride.PyController import PyController

# Set the workspace (default = .)
pystride.workspace = "pytest_Forker"

# Configure simulation
controller = PyController(config_path="../config/run_default.xml")
controller.runConfig.setParameter("output_prefix", "forks/")
controller.runConfig.setParameter("num_days", 2)

# Create 5 identical forks except for the seed
for index in range(3):
    fork = controller.fork("instance" + str(index))
    fork.runConfig.setParameter("rng_seed", index)

# Run all forks
controller.controlForks()
Beispiel #2
0
import pystride
from pystride.Event import EventType
from pystride.PyController import PyController


def printInfected(simulator, event):
    day = event.timestep
    print("Infected at day {}: {}".format(
        day,
        simulator.GetPopulation().GetInfectedCount()))
    sys.stdout.flush()


# Set the workspace (default = .)
pystride.workspace = "experiment"

# Configure simulation
controller = PyController("../config/run_default.xml")
controller.runConfig.setParameter("num_days", 2)

# Create forks with varying parameters
for r0, ir in list(itertools.product([10.0, 25.0], [0.4, 0.01])):
    # Create fork
    fork = controller.fork("r0_" + str(r0) + "-ir_" + str(ir))
    fork.runConfig.setParameter("r0", r0)
    fork.runConfig.setParameter("immunity_rate", ir)
    fork.registerCallback(printInfected, EventType.Stepped)

# Run all forks
controller.controlForks()
Beispiel #3
0
# Configure simulation
controller = PyController(config_path="./config/run_default.xml",
                          data_dir="./data")
controller.runConfig.setParameter("vaccine_profile", "None")
controller.runConfig.setParameter("num_days", 18)
controller.runConfig.setParameter("num_participants_survey", 10)
controller.runConfig.setParameter("contact_log_level", "Transmissions")
controller.runConfig.setParameter("track_index_case", "true")
controller.runConfig.setParameter("seeding_rate", "0.000002")
controller.runConfig.setParameter("output_summary", "true")

# Design of Experiement: parameter values
rng_opt = range(1)
r0_opt = [14]

# Create forks with varying parameters
f_id = 0  # fork id
for r0, rng_seed in list(itertools.product(r0_opt, rng_opt)):
    # Create fork
    fork = controller.fork("exp" + str(f_id))
    fork.runConfig.setParameter("rng_seed", f_id)
    fork.runConfig.setParameter("r0", r0)
    fork.registerCallback(getCases, EventType.Stepped)
    fork.registerCallback(getSummary, EventType.AtFinished)
    fork.registerCallback(parseLogfile, EventType.AtFinished)

    f_id = f_id + 1

# Run all forks
controller.controlForks()
Beispiel #4
0
import pystride
from pystride.PyRunner import PyRunner
from pystride.PyController import PyController

t_start = time.mktime(time.localtime())

# Configure simulation
controller = PyController("../config/run_default.xml")
controller.runConfig.setParameter("output_prefix", "R0Runs")
controller.runConfig.setParameter("num_days", "3")

# Create forks with different values for R0
r0_values = [0, 4, 8]
for r0 in r0_values:
    # Create fork
    fork = controller.fork("r0_" + str(r0))
    fork.runConfig.setParameter("r0", r0)

# Run all forks
controller.controlForks()

for fork in controller.forks:
    num_infected = fork.runner.getSimulator().GetPopulation().GetInfectedCount(
    )
    r0 = fork.runConfig.getParameter("r0")
    print("R0 = {0:2d} : infection count = {1:7d}".format(
        int(r0), num_infected))

t_elapsed = time.mktime(time.localtime()) - t_start
print("Total time elapsed: " + str(round(t_elapsed)) + " seconds")