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()
def runBaseline(): """ Execute the baseline case. """ sim = Simulation() # Set parameters sim.runConfig.setParameter("output_prefix", "Baseline") sim.runConfig.setParameter("num_days", 60) sim.runConfig.setParameter("disease_config_file", "data/disease_measles.xml") sim.runConfig.setParameter("r0", 11) sim.runConfig.setParameter("seeding_rate", 0) sim.runConfig.setParameter("seeding_age_min", 1) sim.runConfig.setParameter("seeding_age_max", 99) sim.runConfig.setParameter("population_file", "data/pop_flanders600.csv") sim.runConfig.setParameter("output_persons", "false") sim.runConfig.setParameter("num_participants_survey", 10000) sim.runConfig.setParameter("age_contact_matrix_file", "data/contact_matrix_flanders_subpop.xml") sim.runConfig.setParameter("log_level", "SusceptibleContacts") sim.runConfig.setParameter("start_date", "2017-01-01") sim.runConfig.setParameter("holidays_file", "data/holidays_none.json") # immunity_profile # vaccine_profile # vaccine_link_probability # immunity_rate # vaccine_rate sim.runConfig.setParameter("local_information_policy", "NoLocalInformation") sim.runConfig.setParameter("global_information_policy", "NoGlobalInformation") sim.runConfig.setParameter("belief_policy/name", "NoBelief") sim.runConfig.setParameter("behaviour_policy", "NoBehaviour") sim.runConfig.setParameter("rng_seed", 1) # Register callbacks sim.RegisterCallback(measureSusceptiblesClustering) sim.RegisterCallback(seedInfection) # TODO run forks with varying parameters (itertools.product(...)) # Run simulation sim.run()
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()