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() # Get attack rates for rng in RNG_values: summary_file = os.path.join(pystride.workspace, "BatchRunsTesting", "rng_" + str(rng), "summary.csv") with open(summary_file) as csvfile: reader = csv.DictReader(csvfile) print("RNG = " + str(rng) + ": Num cases = " + str(next(reader)['num_cases'])) t_end = time.perf_counter()
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 fork60 = simulation.fork("measles_60_" + rng_type + "_" + str(rng_value)) fork60.runConfig.setParameter("r0", 60) fork60.runConfig.setParameter("rng_type", rng_type) fork60.runConfig.setParameter("rng_seed", rng_value) # Run all forks simulation.runForks() # Print related data def print_test(name, test_type): results_file = os.path.join(pystride.workspace, "totalResults.txt") with open(results_file, "a+") as results:
import itertools import pystride from pystride.Simulation import Simulation # Set the workspace (default = .) pystride.workspace = "simulations" # Configure simulation simulation = Simulation() simulation.loadRunConfig("../config/run_default.xml") simulation.runConfig.setParameter("num_days", 10) # Create forks with varying parameters for b0, ir in list(itertools.product([14, 10, 5], [0.2, 0.4, 0.6])): # Create fork fork = simulation.fork("b0_" + str(b0) + "-ir_" + str(ir)) fork.diseaseConfig.setParameter("transmission/b0", b0) fork.runConfig.setParameter("immunity_rate", ir) fork.runConfig.setParameter("r0", 15) # Run all forks simulation.runForks()
amount_of_runs = int(sys.argv[1]) except ValueError: sys.exit("amount of runs is not a number.") # Set the workspace (default = .) pystride.workspace = "simulations" # Configure simulation simulation = Simulation() simulation.loadRunConfig("../config/run_batch_measles.xml") simulation.runConfig.setParameter("output_prefix", "BatchThreadTesting") ## Create Forks # measles_16 for i in range(0, amount_of_runs): fork = simulation.fork("measles_16_" + str(i)) fork.runConfig.setParameter("rng_seed", random.randint(0, 4294967294)) fork.runConfig.setParameter("r0", 16) # measles_60 for i in range(0, amount_of_runs): fork = simulation.fork("measles_60_" + str(i)) fork.runConfig.setParameter("rng_seed", random.randint(0, 4294967294)) fork.runConfig.setParameter("r0", 60) # Run all forks simulation.runForks() # Get attack rates def print_test(name, test_type): results_file = os.path.join(pystride.workspace, "totalResults.txt")
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)) # TODO belief and behaviour related parameters # Create forks with varying seeds and behaviour parameters for seed in list(itertools.product(seeds)): # Create fork fork = sim.fork(str(seed)) fork.runConfig.setParameter("rng_seed", seed) # Run all forks sim.runForks()
import pystride from pystride.Simulation import Simulation # Set the workspace (default = .) pystride.workspace = "simulations" # Configure simulation simulation = Simulation() simulation.loadRunConfig("../config/run_default.xml") simulation.runConfig.setParameter("num_days", 10) # Create 5 identical forks except for the seed for index in range(5): fork = simulation.fork("instance" + str(index)) fork.runConfig.setParameter("rng_seed", index) # Run all forks simulation.runForks()
amount_of_runs = int(sys.argv[1]) except ValueError: sys.exit("amount of runs is not a number.") # Set the workspace (default = .) pystride.workspace = "simulations" # Configure simulation simulation = Simulation() simulation.loadRunConfig("../config/run_batch_default.xml") simulation.runConfig.setParameter("output_prefix", "BatchThreadTesting") ## Create Forks # Influenza_a for i in range(0, amount_of_runs): fork = simulation.fork("influenza_a_" + str(i)) fork.runConfig.setParameter("rng_seed", random.randint(0, 4294967294)) # influenza_b for i in range(0, amount_of_runs): fork = simulation.fork("influenza_b_" + str(i)) fork.runConfig.setParameter("rng_seed", random.randint(0, 4294967294)) fork.runConfig.setParameter("seeding_rate", 0) # influenza_c for i in range(0, amount_of_runs): fork = simulation.fork("influenza_c_" + str(i)) fork.runConfig.setParameter("rng_seed", random.randint(0, 4294967294)) fork.runConfig.setParameter("seeding_rate", (1 - 0.9991) / 100) fork.runConfig.setParameter("immunity_rate", 0.9991) # Run all forks simulation.runForks()
import pystride from pystride.Simulation import Simulation t_start = time.perf_counter() # Configure simulation simulation = Simulation() simulation.loadRunConfig("../config/run_default.xml") simulation.runConfig.setParameter("output_prefix", "R0Runs") # Create forks with different values for R0 r0_values = [0, 4, 8, 12, 16] for r0 in r0_values: # Create fork fork = simulation.fork("r0_" + str(r0)) fork.runConfig.setParameter("r0", r0) # Run all forks simulation.runForks() # Get attack rates for r0 in r0_values: summary_file = os.path.join(pystride.workspace, "R0Runs", "r0_" + str(r0), "summary.csv") with open(summary_file) as csvfile: reader = csv.DictReader(csvfile) print("R0 = " + str(r0) + ": Num cases = " + str(next(reader)['num_cases'])) t_end = time.perf_counter()