def runSimulation(outputPrefix, fraction, iteration, rng_seed):
    # Set up simulator
    control = PyController(data_dir="data")
    # Load configuration from file
    control.loadRunConfig(os.path.join("config", "run_generate_default.xml"))
    # Set some parameters

    outputPrefix = os.path.join(outputPrefix,
                                str(fraction) + "_" + str(iteration))

    control.runConfig.setParameter("geopop_gen.population_size", 10000)
    control.runConfig.setParameter("geopop_gen.participation_college", 0.0)
    control.runConfig.setParameter("geopop_gen.particpation_workplace", 1.0)
    control.runConfig.setParameter("geopop_gen.fraction_college_commuters",
                                   0.0)
    control.runConfig.setParameter("geopop_gen.fraction_workplace_commuters",
                                   fraction)

    control.runConfig.setParameter("output_prefix", outputPrefix)
    control.runConfig.setParameter("rng_seed", rng_seed)

    print("config done")
    control.registerCallback(trackCases, EventType.Stepped)
    # Run simulation
    control.control()
def runSimulation(outputPrefix, daycare_fraction, preschool_fraction,
                  workplace, iteration, rng_seed, days):
    print(
        f"DC: {daycare_fraction} / PS: {preschool_fraction} - Iteration {iteration}"
    )
    # Set up simulator
    control = PyController(data_dir="data")
    # Load configuration from file
    control.loadRunConfig(os.path.join("config", "daycare-preschool.xml"))
    # Set some parameters

    outputPrefix = os.path.join(
        outputPrefix,
        f"DC-{daycare_fraction}-PS-{preschool_fraction}_{iteration}")

    control.runConfig.setParameter("output_prefix", outputPrefix)
    control.runConfig.setParameter("rng_seed", rng_seed)

    control.runConfig.setParameter("num_days", str(days))
    control.runConfig.setParameter("geopop_gen.population_size", "600000")
    control.runConfig.setParameter("geopop_gen.participation_preschool",
                                   preschool_fraction)
    control.runConfig.setParameter("geopop_gen.participation_daycare",
                                   daycare_fraction)

    control.registerCallback(trackCases, EventType.Stepped)
    # Run simulation
    control.control()
    print("Simulation done")
Exemple #3
0
def runSimulation(outputPrefix, fraction, workplace, iteration, rng_seed,
                  days):
    # Set up simulator
    control = PyController(data_dir="data")
    # Load configuration from file
    control.loadRunConfig(os.path.join("config", "workplace.xml"))
    # Set some parameters

    outputPrefix = os.path.join(
        outputPrefix, workplace + str(fraction) + "_" + str(iteration))

    control.runConfig.setParameter("seeding_rate", fraction)
    control.runConfig.setParameter("disease_config_file",
                                   "disease_influenza.xml")
    control.runConfig.setParameter("output_prefix", outputPrefix)
    control.runConfig.setParameter("rng_seed", rng_seed)

    control.runConfig.setParameter("num_days", str(days))
    control.runConfig.setParameter("geopop_gen.population_size", "600000")
    control.runConfig.setParameter("geopop_gen.workplace_distribution_file",
                                   "data/" + workplace)

    control.registerCallback(trackCases, EventType.Stepped)
    # Run simulation
    control.control()
Exemple #4
0
def runSimulation(outputPrefix, v, iteration, rng_seed):
    # Set up simulator
    control = PyController(data_dir="data")
    # Load configuration from file
    control.loadRunConfig(os.path.join("config", "run_import_default.xml"))
    # Set some parameters

    if v:
        outputPrefix = os.path.join(outputPrefix,
                                    vaccinatedFolder + "_" + str(iteration))
    else:
        outputPrefix = os.path.join(outputPrefix,
                                    notVaccinatedFolder + "_" + str(iteration))

    control.runConfig.setParameter("immunity_profile", "AgeDependent")
    control.runConfig.setParameter("immunity_distribution_file",
                                   "data/lower_student_immunity.xml")
    control.runConfig.setParameter("immunity_link_probability", 0)
    control.runConfig.setParameter("population_file",
                                   "data/2_2_gengeopop.proto")
    control.runConfig.setParameter("geopopulation_file",
                                   "data/2_2_gengeopop.proto")
    control.runConfig.setParameter("output_prefix", outputPrefix)
    control.runConfig.setParameter("rng_seed", rng_seed)

    print("config done")
    if v:
        control.registerCallback(vaccinate, EventType.Stepped)
    control.registerCallback(trackCases, EventType.Stepped)
    # Run simulation
    control.control()
Exemple #5
0
def runSimulation(outputPrefix, seed, extraParams={}, callbacks=[]):
    control = PyController(data_dir="data")
    extraParams.update(getCommonParameters())
    for paramName, paramValue in extraParams.items():
        control.runConfig.setParameter(paramName, paramValue)
    control.runConfig.setParameter("rng_seed", seed)
    control.runConfig.setParameter("output_prefix", outputPrefix + "_" + str(seed))
    for callbackFunction, callbackEvent in callbacks:
        control.registerCallback(callbackFunction, callbackEvent)
    control.control()
Exemple #6
0
def runSimulation(immunity, outputPrefix):
    # Configure simulation
    controller = PyController(data_dir="data")
    controller.loadRunConfig(
        os.path.join("config", "outbreak_2019_estimates.xml"))
    controller.runConfig.setParameter("output_prefix",
                                      outputPrefix + "_" + str(immunity))
    controller.runConfig.setParameter("immunity_profile", "Random")
    controller.runConfig.setParameter("immunity_rate", immunity)
    controller.runConfig.setParameter("vaccine_profile", "None")
    controller.registerCallback(count, EventType.Stepped)
    controller.control()
Exemple #7
0
def runSimulation_vaccination(seed, filename):
    # Configure simulation
    control = PyController(data_dir="data")
    # Load Configuration file:
    control.loadRunConfig(os.path.join("config", xmlFile))
    control.runConfig.setParameter("rng_seed", seed)
    # Register callbacks
    control.registerCallback(check_days, EventType.Stepped)
    #control.registerCallback(trackCases, [EventType.Stepped, filename])
    # Let controller run the simulation
    control.control()
    return (seed,
            control.runner.getSimulator().GetPopulation().GetInfectedCount())
Exemple #8
0
def runRandom():
    control = PyController()
    setCommonParams(control)
    # Output prefix
    control.runConfig.setParameter("output_prefix", "Random")
    # Immunity profile
    control.runConfig.setParameter("immunity_profile", "Random")
    control.runConfig.setParameter("immunity_rate", 0.951513)
    # Vaccination profile is empty since random immunity was seeded
    # through immunity profile
    control.runConfig.setParameter("vaccine_profile", "None")
    control.registerCallback(getNumSusceptible, EventType.AtStart)
    control.registerCallback(trackCases, EventType.Stepped)
    control.control()
Exemple #9
0
def runSimulation(outputPrefix):
    for run in range(0, runs):
        print("run number {0} of {1}".format(run+1, runs))
        controller = PyController(data_dir="data")
        controller.loadRunConfig(os.path.join("config", config))
        controller.runConfig.setParameter("num_days", sim_days)
        controller.runConfig.setParameter("output_prefix", outputPrefix + "_" + config.split(".")[0])
        seed = ""
        for _ in range(4):
            seed += str(random.randint(1, 999999)) + ","
        seed = seed[:-1]
        controller.runConfig.setParameter("rng_seed", seed) 
        controller.registerCallback(trackCases, EventType.Stepped)
        controller.control()
Exemple #10
0
def runSimulation(outputPrefix, vaccinationLevel):
    # Set up simulator
    control = PyController(data_dir="data")
    # Load configuration from file
    control.loadRunConfig(os.path.join("config", "run_default.xml"))
    # Set some parameters
    control.runConfig.setParameter("vaccine_rate", vaccinationLevel / 100)
    control.runConfig.setParameter("output_cases", "false")
    control.runConfig.setParameter("contact_output_file", "false")
    control.runConfig.setParameter("output_prefix", outputPrefix + "_" + str(vaccinationLevel))
    control.runConfig.setParameter("seeding_rate", 0.00000334) # Seed 2 infected persons in population of 600 000
    control.registerCallback(trackCases, EventType.Stepped)
    # Run simulation
    control.control()
Exemple #11
0
def runSimulation(year, R0, seed):
    configFile = os.path.join("config", "ageImmunityShift.xml")
    control = PyController(data_dir="data")
    control.loadRunConfig(configFile)
    control.runConfig.setParameter(
        "output_prefix",
        str(year) + "_R0_" + str(R0) + "_" + str(seed))
    control.runConfig.setParameter("rng_seed", seed)
    control.runConfig.setParameter("r0", R0)
    control.runConfig.setParameter("immunity_profile", "Random")
    control.runConfig.setParameter("immunity_rate", IMMUNITY_RATES[year])
    control.registerCallback(registerSusceptibles, EventType.AtStart)
    control.registerCallback(trackCases, EventType.Stepped)
    control.control()
    return
Exemple #12
0
def runAgeDependent():
    control = PyController()
    setCommonParams(control)
    # Output prefix
    control.runConfig.setParameter("output_prefix", "AgeDependent")
    # Immunity profile
    control.runConfig.setParameter("immunity_link_probability", 0)
    control.runConfig.setParameter("immunity_profile", "AgeDependent")
    control.runConfig.setParameter("immunity_distribution", "../data/measles_natural_immunity.xml")
    # Vaccination profile
    control.runConfig.setParameter("vaccine_link_probability", 0)
    control.runConfig.setParameter("vaccine_profile", "AgeDependent")
    control.runConfig.setParameter("vaccine_distribution", "../data/measles_vaccination.xml")
    control.registerCallback(getNumSusceptible, EventType.AtStart)
    control.registerCallback(trackCases, EventType.Stepped)
    control.control()
Exemple #13
0
def runSimulation(immunity_rate):
    # Set up simulator
    control = PyController(data_dir="data")
    # Load configuration from file
    control.loadRunConfig(os.path.join("config",
                                       "outbreak_2019_estimates.xml"))
    # Set some parameters
    control.runConfig.setParameter("output_prefix",
                                   outputDirectory(immunity_rate))
    control.runConfig.setParameter("immunity_profile", "Random")
    control.runConfig.setParameter("immunity_rate", immunity_rate / 100)
    control.runConfig.setParameter("rng_seed", random.randint(0, 100000000))
    control.runConfig.setParameter("vaccine_profile", None)
    control.registerCallback(trackCases, EventType.Stepped)
    # Run simulation
    control.control()
Exemple #14
0
def runSimulation(output_prefix, immunity_level, rng_seed, iteration=1):
    """Run the simulator, for one immunity level."""
    # Set up simulator
    control = PyController(data_dir="data")
    # Load configuration from file
    cfile = os.path.join("config", "outbreak_2019_estimates.xml")
    control.loadRunConfig(cfile)
    # Set some parameters
    control.runConfig.setParameter("immunity_profile", "Random")
    control.runConfig.setParameter("immunity_rate", immunity_level / 100)
    control.runConfig.setParameter("rng_seed", rng_seed)
    control.runConfig.setParameter("vaccine_profile", "None")
    outputmap = "{}_{}_{}".format(output_prefix, immunity_level, iteration)
    control.runConfig.setParameter("output_prefix", outputmap)
    control.registerCallback(trackCases, EventType.Stepped)
    # Run simulation
    control.control()
Exemple #15
0
def runSimulation(comuter_fraction, outputPrefix):
    tree = ET.parse(os.path.join("config", 'run_generate_default.xml'))
    geopop = tree.getroot().find("geopop_gen")
    comuters = geopop.find("fraction_workplace_commuters")
    comuters.text = str(comuter_fraction)
    tree.write(os.path.join("config", "run_generate_default_temp.xml"))

    # Configure simulation
    controller = PyController(data_dir="data")
    controller.loadRunConfig(
        os.path.join("config", "run_generate_default_temp.xml"))
    controller.runConfig.setParameter("num_days", "400")
    controller.runConfig.setParameter(
        "output_prefix", outputPrefix + "_" + str(comuter_fraction))
    controller.runConfig.setParameter("seeding_rate", 0.00000334)
    controller.registerCallback(trackCases, EventType.Stepped)
    controller.control()
Exemple #16
0
def runSimulation(level, outputPrefix):
    tree = ET.parse(os.path.join("config", config))
    geopop = tree.getroot().find("geopop_gen")
    comuters = geopop.find(param)
    comuters.text = str(level)
    tree.write(os.path.join("config", config))

    for run in range(0, runs):
        print("run number {0} of {1}".format(run + 1, runs))
        controller = PyController(data_dir="data")
        controller.loadRunConfig(os.path.join("config", config))
        controller.runConfig.setParameter("num_days", sim_days)
        controller.runConfig.setParameter("output_prefix",
                                          outputPrefix + "_" + str(level))
        controller.runConfig.setParameter("seeding_rate", 0.00000334)
        seed = ""
        for _ in range(4):
            seed += str(random.randint(1, 999999999)) + ","
        seed = seed[:-1]
        controller.runConfig.setParameter("rng_seed", seed)
        controller.registerCallback(trackCases, EventType.Stepped)
        controller.control()
Exemple #17
0
def runSimulation(year, R0, numDays, seed, trackIndexCase):
    configFile = os.path.join("config", "ageImmunityShift.xml")
    control = PyController(data_dir="data")
    control.loadRunConfig(configFile)
    control.runConfig.setParameter(
        "output_prefix",
        str(year) + "_R0_" + str(R0) + "_" + str(seed))
    control.runConfig.setParameter("rng_seed", seed)
    control.runConfig.setParameter("r0", R0)
    control.runConfig.setParameter("num_days", numDays)
    control.runConfig.setParameter("immunity_link_probability", 0)
    control.runConfig.setParameter("immunity_profile", "AgeDependent")
    control.runConfig.setParameter(
        "immunity_distribution_file",
        os.path.join("data",
                     str(year) + "_measles_immunity.xml"))
    if trackIndexCase:
        control.runConfig.setParameter("track_index_case", "true")
    control.registerCallback(registerSusceptibles, EventType.AtStart)
    control.registerCallback(trackCases, EventType.Stepped)
    control.registerCallback(registerAgesInfected, EventType.AtFinished)
    control.control()
    return
Exemple #18
0
import pystride
from pystride.Event import EventType
from pystride.PyController import PyController

def vaccinate(simulator, event):
    if event.timestep == 20:
        pop = simulator.GetPopulation()
        for pIndex in range(pop.size()):
            if pop[pIndex].GetHealth().IsSusceptible():
                pop[pIndex].GetHealth().SetImmune()

def check(simulator, event):
    if event.timestep == 20:
        check.value = getattr(check, 'value', 0)
        check.value = simulator.GetPopulation().GetInfectedCount()
    if event.timestep > 20:
        assert(simulator.GetPopulation().GetInfectedCount() == check.value), "Infection count still changing on day {}".format(event.timestep)

# Configure simulation
controller = PyController(config_path="../config/run_default.xml")
# Register callbacks
controller.registerCallback(vaccinate, EventType.Stepped)
controller.registerCallback(check, EventType.Stepped)
# Let controller run the simulation
controller.control()
Exemple #19
0
from pystride.Event import EventType
from pystride.PyController import PyController


# Callback to check if number of cases produced by sim is acceptable
def checkNumCases(simulator, event):
    # Target for total number of cases after simulation
    targetCases = 118925
    actualCases = simulator.GetPopulation().GetInfectedCount()
    # Accept a 10% margin of error
    assert (abs(targetCases - actualCases) <=
            (targetCases *
             0.1)), "Expected value is {} - actual value is {}".format(
                 targetCases, actualCases)


# Configure simulation
controller = PyController(config_path="../config/run_default.xml")
controller.runConfig.setParameter("output_prefix", "testInfected")
controller.runConfig.setParameter("use_install_dirs", "true")

# Clean up leftover of previous failed testrun
if os.path.isdir("testInfected"):
    rmtree("testInfected")

# Register callback
controller.registerCallback(checkNumCases, EventType.AtFinished)

# Let controller run the simulation.
controller.control()
Exemple #20
0
import sys

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()


# Configure Simulation
controller = PyController(config_path="../config/run_default.xml")
controller.runConfig.setParameter("population_file", "pop_antwerp.csv")
controller.runConfig.setParameter("num_days", 10)
controller.runConfig.setParameter("output_prefix", "pytest_Print/")
# Register callback
controller.registerCallback(printInfected, EventType.Stepped)
# Let controller run the simulation
controller.control()