Initializing sim with 10000 agents
Profiling 1 function(s):
<function Infection.infect at 0x7f8d78e1ca40>
Running 2000.01.01 ( 0/21) (0.00 s) ———————————————————— 5%
Running 2010.01.01 (10/21) (0.07 s) ••••••••••—————————— 52%
Running 2020.01.01 (20/21) (0.14 s) •••••••••••••••••••• 100%
Elapsed time: 0.166 s
————————————————————————————————————————————————————————————
Profile of diseases.Infection.infect: 0.0647676 s (38.9776%)
————————————————————————————————————————————————————————————
Total time: 0.0647676 s
File: /home/runner/work/starsim/starsim/starsim/diseases.py
Function: Infection.infect at line 257
Line # Hits Time Per Hit % Time Line Contents
==============================================================
257 def infect(self):
258 """ Determine who gets infected on this timestep via transmission on the network """
259 21 19657.0 936.0 0.0 new_cases = []
260 21 8498.0 404.7 0.0 sources = []
261 21 8409.0 400.4 0.0 networks = []
262 21 591735.0 28177.9 0.9 betamap = self.validate_beta()
263
264 # Compute effective transmissibility and susceptibility directly on the raw
265 # (full-length) arrays. This avoids the gather/scatter, full-length astype copy,
266 # and extra wrapper allocations of the Arr math operators; edges only ever index
267 # living agents, so stale raw values for inactive agents are never used.
268 21 432553.0 20597.8 0.7 rel_trans = self.rel_trans.asnew(self.infectious.raw * self.rel_trans.raw, copy=False)
269 21 264078.0 12575.1 0.4 rel_sus = self.rel_sus.asnew(self.susceptible.raw * self.rel_sus.raw, copy=False)
270
271 42 151366.0 3604.0 0.2 for i, (nkey,route) in enumerate(self.sim.networks.items()):
272 21 34617.0 1648.4 0.1 nk = ss.standardize_netkey(nkey)
273
274 # Main use case: networks
275 21 14637.0 697.0 0.0 if isinstance(route, ss.Network):
276 21 254847.0 12135.6 0.4 if len(route): # Skip networks with no edges
277 21 9786.0 466.0 0.0 edges = route.edges
278 21 357757.0 17036.0 0.6 p1_to_p2 = [edges.p1, edges.p2, betamap[nk][0]] # p1→p2 direction, beta 0
279 21 343433.0 16354.0 0.5 p2_to_p1 = [edges.p2, edges.p1, betamap[nk][1]] # p2→p1 direction, beta 1
280 63 42450.0 673.8 0.1 for src, trg, beta in [p1_to_p2, p2_to_p1]:
281 42 72054.0 1715.6 0.1 if beta: # Skip networks with no transmission
282 42 1157897.0 27569.0 1.8 disease_beta = beta.to_prob(self.t.dt) if isinstance(beta, ss.Rate) else beta
283 42 1907900.0 45426.2 2.9 beta_per_dt = route.net_beta(disease_beta=disease_beta, disease=self) # Compute beta for this network and timestep
284 42 46388479.0 1.1e+06 71.6 randvals = self.trans_rng.rvs(src, trg) # Generate a new random number based on the two other random numbers
285 42 37014.0 881.3 0.1 args = (src, trg, rel_trans, rel_sus, beta_per_dt, randvals) # Set up the arguments to calculate transmission
286 42 9961974.0 237189.9 15.4 target_uids, source_uids = self.compute_transmission(*args) # Actually calculate it
287 42 27183.0 647.2 0.0 new_cases.append(target_uids)
288 42 17189.0 409.3 0.0 sources.append(source_uids)
289 42 425045.0 10120.1 0.7 networks.append(np.full(len(target_uids), dtype=ss_int, fill_value=i))
290
291 # Handle everything else: mixing pools, environmental transmission, etc.
292 elif isinstance(route, ss.Route):
293 # Mixing pools are unidirectional, only use the first beta value
294 disease_beta = betamap[nk][0].to_prob(self.t.dt) if isinstance(betamap[nk][0], ss.Rate) else betamap[nk][0]
295 target_uids = route.compute_transmission(rel_sus, rel_trans, disease_beta, disease=self)
296 new_cases.append(target_uids)
297 sources.append(np.full(len(target_uids), dtype=ss_int, fill_value=ss.dtypes.int_nan))
298 networks.append(np.full(len(target_uids), dtype=ss_int, fill_value=i))
299 else:
300 errormsg = f'Cannot compute transmission via route {type(route)}; please subclass ss.Route and define a compute_transmission() method'
301 raise TypeError(errormsg)
302
303 # Finalize
304 21 15325.0 729.8 0.0 if len(new_cases) and len(sources):
305 21 357042.0 17002.0 0.6 new_cases = ss.uids.concatenate(new_cases)
306 21 1431352.0 68159.6 2.2 new_cases, inds = new_cases.unique(return_index=True)
307 21 319734.0 15225.4 0.5 sources = ss.uids.concatenate(sources)[inds]
308 21 103734.0 4939.7 0.2 networks = np.concatenate(networks)[inds]
309 else:
310 new_cases = ss.uids()
311 sources = ss.uids()
312 networks = np.empty(0, dtype=ss_int)
313
314 21 11902.0 566.8 0.0 return new_cases, sources, networks
————————————————————————————————————————————————————————————
Profile of diseases.Infection.infect: 0.0647676 s (38.9776%)
————————————————————————————————————————————————————————————
Total time: 0.0647676 s
File: /home/runner/work/starsim/starsim/starsim/diseases.py
Function: Infection.infect at line 257
Line # Hits Time Per Hit % Time Line Contents
==============================================================
257 def infect(self):
258 """ Determine who gets infected on this timestep via transmission on the network """
259 21 19657.0 936.0 0.0 new_cases = []
260 21 8498.0 404.7 0.0 sources = []
261 21 8409.0 400.4 0.0 networks = []
262 21 591735.0 28177.9 0.9 betamap = self.validate_beta()
263
264 # Compute effective transmissibility and susceptibility directly on the raw
265 # (full-length) arrays. This avoids the gather/scatter, full-length astype copy,
266 # and extra wrapper allocations of the Arr math operators; edges only ever index
267 # living agents, so stale raw values for inactive agents are never used.
268 21 432553.0 20597.8 0.7 rel_trans = self.rel_trans.asnew(self.infectious.raw * self.rel_trans.raw, copy=False)
269 21 264078.0 12575.1 0.4 rel_sus = self.rel_sus.asnew(self.susceptible.raw * self.rel_sus.raw, copy=False)
270
271 42 151366.0 3604.0 0.2 for i, (nkey,route) in enumerate(self.sim.networks.items()):
272 21 34617.0 1648.4 0.1 nk = ss.standardize_netkey(nkey)
273
274 # Main use case: networks
275 21 14637.0 697.0 0.0 if isinstance(route, ss.Network):
276 21 254847.0 12135.6 0.4 if len(route): # Skip networks with no edges
277 21 9786.0 466.0 0.0 edges = route.edges
278 21 357757.0 17036.0 0.6 p1_to_p2 = [edges.p1, edges.p2, betamap[nk][0]] # p1→p2 direction, beta 0
279 21 343433.0 16354.0 0.5 p2_to_p1 = [edges.p2, edges.p1, betamap[nk][1]] # p2→p1 direction, beta 1
280 63 42450.0 673.8 0.1 for src, trg, beta in [p1_to_p2, p2_to_p1]:
281 42 72054.0 1715.6 0.1 if beta: # Skip networks with no transmission
282 42 1157897.0 27569.0 1.8 disease_beta = beta.to_prob(self.t.dt) if isinstance(beta, ss.Rate) else beta
283 42 1907900.0 45426.2 2.9 beta_per_dt = route.net_beta(disease_beta=disease_beta, disease=self) # Compute beta for this network and timestep
284 42 46388479.0 1.1e+06 71.6 randvals = self.trans_rng.rvs(src, trg) # Generate a new random number based on the two other random numbers
285 42 37014.0 881.3 0.1 args = (src, trg, rel_trans, rel_sus, beta_per_dt, randvals) # Set up the arguments to calculate transmission
286 42 9961974.0 237189.9 15.4 target_uids, source_uids = self.compute_transmission(*args) # Actually calculate it
287 42 27183.0 647.2 0.0 new_cases.append(target_uids)
288 42 17189.0 409.3 0.0 sources.append(source_uids)
289 42 425045.0 10120.1 0.7 networks.append(np.full(len(target_uids), dtype=ss_int, fill_value=i))
290
291 # Handle everything else: mixing pools, environmental transmission, etc.
292 elif isinstance(route, ss.Route):
293 # Mixing pools are unidirectional, only use the first beta value
294 disease_beta = betamap[nk][0].to_prob(self.t.dt) if isinstance(betamap[nk][0], ss.Rate) else betamap[nk][0]
295 target_uids = route.compute_transmission(rel_sus, rel_trans, disease_beta, disease=self)
296 new_cases.append(target_uids)
297 sources.append(np.full(len(target_uids), dtype=ss_int, fill_value=ss.dtypes.int_nan))
298 networks.append(np.full(len(target_uids), dtype=ss_int, fill_value=i))
299 else:
300 errormsg = f'Cannot compute transmission via route {type(route)}; please subclass ss.Route and define a compute_transmission() method'
301 raise TypeError(errormsg)
302
303 # Finalize
304 21 15325.0 729.8 0.0 if len(new_cases) and len(sources):
305 21 357042.0 17002.0 0.6 new_cases = ss.uids.concatenate(new_cases)
306 21 1431352.0 68159.6 2.2 new_cases, inds = new_cases.unique(return_index=True)
307 21 319734.0 15225.4 0.5 sources = ss.uids.concatenate(sources)[inds]
308 21 103734.0 4939.7 0.2 networks = np.concatenate(networks)[inds]
309 else:
310 new_cases = ss.uids()
311 sources = ss.uids()
312 networks = np.empty(0, dtype=ss_int)
313
314 21 11902.0 566.8 0.0 return new_cases, sources, networks