Beispiel #1
0
def run_simulator(seed, num_days):
    """
    Runs the simulator once.
    Configures the num_days and seed parameter of the simulator.

    :param seed for the random number generator, used by the simulator
    :param num_days the number of days (steps) the simulator needs to run.
    """

    simulator = Simulation()
    simulator.loadRunConfig("../config/run_default_nolog.xml")
    set_influenza(simulator)
    simulator.runConfig.setParameter("rng_seed", seed)
    simulator.run()
if not len(sys.argv) == 2:
    sys.exit(
        "Please add the amount of runs as an argument: \npython3 runExperimentsBatchRuns.py 100"
    )

t_start = time.perf_counter()

try:
    amount_of_runs = int(sys.argv[1])
except ValueError:
    sys.exit("amount of runs is not a number.")

# Configure simulation
simulation = Simulation()
simulation.loadRunConfig("../config/run_batchruntests1.xml")
simulation.runConfig.setParameter("output_prefix", "BatchRunsTesting")

# Create forks with different values for RNG
RNG_values = []
for i in range(amount_of_runs):
    RNG_values.append(random.randint(0, 4294967294))

for rng in RNG_values:
    # Create fork
    fork = simulation.fork("rng_" + str(rng))
    fork.runConfig.setParameter("rng_seed", rng)

# Run all forks
simulation.runForks()
import pystride

from pystride.Simulation import Simulation

pystride.workspace = "simulations"


def checkFinished(sim, timestep):
    pop = sim.GetSimulator().GetPopulation()
    infected = pop.GetInfectedCount()
    print("Amount infected: ", infected)
    if infected >= 4000:
        sim.Stop()


# Configure simulation
simulation = Simulation()
simulation.loadRunConfig("../config/run_default.xml")
simulation.runConfig.setParameter("generate_person_file", 0)
simulation.registerCallback(checkFinished)

simulation.run()
Beispiel #4
0
import csv
import pystride
from pystride.Simulation import Simulation

# RNG types to test
# Note: Default (mrg2) -- See results from previous test
RNG_TYPES = ["lcg64", "yarn2", "lcg64_shift", "mrg3", "yarn3"]
# Amount of random values to test
amount_of_runs = 1

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

# Configure simulation
simulation = Simulation()
simulation.loadRunConfig("../config/run_batch_measles.xml")
simulation.runConfig.setParameter("output_prefix", "BatchRngTypeTesting")

# Initialize the random values
rng_values = []
for i in range(amount_of_runs)):
    rng_values.append(random.randint(0, 4294967294))
## Create Forks
for rng_type in RNG_TYPES:
    for rng_value in rng_values:
        # measles_16
        fork16 = simulation.fork("measles_16_" + rng_type + "_" + str(rng_value))
        fork16.runConfig.setParameter("r0", 16)
        fork16.runConfig.setParameter("rng_type", rng_type)
        fork16.runConfig.setParameter("rng_seed", rng_value)
        # measles_60
Beispiel #5
0
#############################################################################
# Script for simulations with no-vaccination clustering                     #
# using Imitation belief policy.                                            #
#############################################################################

import itertools

import pystride
from pystride.Simulation import Simulation

# TODO callback to vaccinate + seed after x days

sim = Simulation()
sim.loadRunConfig("config/common.xml")

# Set parameters that are the same for all simulations
sim.runConfig.setParameter("output_prefix", "Imitation")
sim.runConfig.setParameter("seeding_rate", 0)

# TODO natural immunity?
sim.runConfig.setParameter("immunity_rate", 0)
sim.runConfig.setParameter("vaccine_rate", 0)

sim.runConfig.setParameter("local_information_policy", "LocalDiscussion")
sim.runConfig.setParameter("global_information_policy", "NoLocalInformation")
sim.runConfig.setParameter("belief_policy/name", "Imitation")
sim.runConfig.setParameter("belief_policy/accept_threshold", 0.95)
sim.runConfig.setParameter("belief_policy/no_accept_threshold", -0.95)
sim.runConfig.setParameter("behaviour_policy", "Vaccination")

seeds = list(range(10))