def test_pulsed_infections_network_poisson(make_test_sim): ''' Test a poisson sampled number of infections''' pars, BU_pop = make_test_sim # Turn off infections from person-to-person pars['beta'] = 0 # Infect 10 people. num_days = (bu.make_dt(pars['end_day']) - bu.make_dt(pars['start_day'])).days days = (num_days + 1) * [0] # All infections on the first day. days[0] = 1 NUM_INFECTIONS = 10 interv = bv.pulsed_infections_network(BU_pop['contacts'], days, layer_name='household', pulse_sampling='poisson', pulse_count=NUM_INFECTIONS) sim = cv.Sim(pars=pars, popfile=BU_pop, verbose=False, load_pop=True, interventions=[interv], analyzers=[]) # Update the sim with our extra categories bu.update_sim_people(sim, BU_pop) # Fix the random seed cv.utils.set_seed(987654321) # run it sim.run() # Check that the correct number of infections on day 0 were created assert sim.results['new_infections'].values[0] == 9 # and none on day 1 assert sim.results['new_infections'].values[1] == 0
def test_gen_periodic_testing_interventions_real(make_test_sim): # Generate tests for every 3.5 days and every 7 days. Run the sim # for a week. Check that the sum of sim.results['new_tests'] is # equal to the number of people in the sim. beta is set to zero # to prevent any infections/symptomatic attestation going on and # triggering more tests. pars, BU_pop = make_test_sim # Turn off infections from person-to-person pars['beta'] = 0 # Set the dates. One week plus a day so we get a week of testing. pars['start_day'] = '2020-01-01' pars['end_day'] = '2020-01-08' num_days = (bu.make_dt(pars['end_day']) - bu.make_dt(pars['start_day'])).days intervs = bu.gen_periodic_testing_interventions_real( BU_pop, num_days, start_date=pars['start_day']) sim = cv.Sim(pars=pars, popfile=BU_pop, verbose=False, load_pop=True, interventions=intervs, analyzers=[]) # Update the sim with our extra categories bu.update_sim_people(sim, BU_pop) # Fix the random seed cv.utils.set_seed(987654321) # run it sim.run() # Total number of tests assert int(sum(sim.results['new_tests'])) == 10818 # each day assert list(sim.results['new_tests'])[0:-1] == [ 1683.0, 1697.0, 1747.0, 1119.0, 1128.0, 1697.0, 1747.0 ]
verbose = False # keep the simulations quiet if n_runs == 1: verbose = True #unles there's just 1. #%% Create the list of daily snapshot objects analyzers = bu.get_BU_snapshots(num_days) #%% sim = cv.Sim(pars=pars, popfile=BU_pop, verbose=verbose, load_pop=True, interventions=interventions, analyzers=analyzers) # Update the sim with our extra categories bu.update_sim_people(sim, BU_pop) #%% sims_complete = bu.parallel_run_sims(sim, n_runs=n_runs, n_cores=bu.get_n_cores()) msim = cv.MultiSim(sims_complete) msim.reduce() print("Creating dataframes") #%% Get the snapshots dataframe snapshots_df = bu.snapshots_to_df(sims_complete) #%% infection_df = bu.infection_count_to_df(sims_complete)