Initializing sim with 10000 agents
Profiling 1 function(s):
<function Infection.infect at 0x7fb5880cb100>
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.151 s
———————————————————————————————————————————————————————————
Profile of diseases.Infection.infect: 0.0573921 s (38.107%)
———————————————————————————————————————————————————————————
Total time: 0.0573921 s
File: /home/runner/work/starsim/starsim/starsim/diseases.py
Function: Infection.infect at line 255
Line # Hits Time Per Hit % Time Line Contents
==============================================================
255 def infect(self):
256 """ Determine who gets infected on this timestep via transmission on the network """
257 21 25379.0 1208.5 0.0 new_cases = []
258 21 9743.0 464.0 0.0 sources = []
259 21 10072.0 479.6 0.0 networks = []
260 21 678480.0 32308.6 1.2 betamap = self.validate_beta()
261
262 # Compute effective transmissibility and susceptibility directly on the raw
263 # (full-length) arrays. This avoids the gather/scatter, full-length astype copy,
264 # and extra wrapper allocations of the Arr math operators; edges only ever index
265 # living agents, so stale raw values for inactive agents are never used.
266 21 605703.0 28843.0 1.1 rel_trans = self.rel_trans.asnew(self.infectious.raw * self.rel_trans.raw, copy=False)
267 21 313933.0 14949.2 0.5 rel_sus = self.rel_sus.asnew(self.susceptible.raw * self.rel_sus.raw, copy=False)
268
269 42 171745.0 4089.2 0.3 for i, (nkey,route) in enumerate(self.sim.networks.items()):
270 21 32685.0 1556.4 0.1 nk = ss.standardize_netkey(nkey)
271
272 # Main use case: networks
273 21 16734.0 796.9 0.0 if isinstance(route, ss.Network):
274 21 242621.0 11553.4 0.4 if len(route): # Skip networks with no edges
275 21 10808.0 514.7 0.0 edges = route.edges
276 21 368493.0 17547.3 0.6 p1_to_p2 = [edges.p1, edges.p2, betamap[nk][0]] # p1→p2 direction, beta 0
277 21 357716.0 17034.1 0.6 p2_to_p1 = [edges.p2, edges.p1, betamap[nk][1]] # p2→p1 direction, beta 1
278 63 45410.0 720.8 0.1 for src, trg, beta in [p1_to_p2, p2_to_p1]:
279 42 76234.0 1815.1 0.1 if beta: # Skip networks with no transmission
280 42 1200626.0 28586.3 2.1 disease_beta = beta.to_prob(self.t.dt) if isinstance(beta, ss.Rate) else beta
281 42 2133806.0 50804.9 3.7 beta_per_dt = route.net_beta(disease_beta=disease_beta, disease=self) # Compute beta for this network and timestep
282 42 41289112.0 983074.1 71.9 randvals = self.trans_rng.rvs(src, trg) # Generate a new random number based on the two other random numbers
283 42 67932.0 1617.4 0.1 args = (src, trg, rel_trans, rel_sus, beta_per_dt, randvals) # Set up the arguments to calculate transmission
284 42 6817370.0 162318.3 11.9 target_uids, source_uids = self.compute_transmission(*args) # Actually calculate it
285 42 26937.0 641.4 0.0 new_cases.append(target_uids)
286 42 19693.0 468.9 0.0 sources.append(source_uids)
287 42 454647.0 10824.9 0.8 networks.append(np.full(len(target_uids), dtype=ss_int, fill_value=i))
288
289 # Handle everything else: mixing pools, environmental transmission, etc.
290 elif isinstance(route, ss.Route):
291 # Mixing pools are unidirectional, only use the first beta value
292 disease_beta = betamap[nk][0].to_prob(self.t.dt) if isinstance(betamap[nk][0], ss.Rate) else betamap[nk][0]
293 target_uids = route.compute_transmission(rel_sus, rel_trans, disease_beta, disease=self)
294 new_cases.append(target_uids)
295 sources.append(np.full(len(target_uids), dtype=ss_int, fill_value=ss.dtypes.int_nan))
296 networks.append(np.full(len(target_uids), dtype=ss_int, fill_value=i))
297 else:
298 errormsg = f'Cannot compute transmission via route {type(route)}; please subclass ss.Route and define a compute_transmission() method'
299 raise TypeError(errormsg)
300
301 # Finalize
302 21 17698.0 842.8 0.0 if len(new_cases) and len(sources):
303 21 369923.0 17615.4 0.6 new_cases = ss.uids.concatenate(new_cases)
304 21 1611571.0 76741.5 2.8 new_cases, inds = new_cases.unique(return_index=True)
305 21 299526.0 14263.1 0.5 sources = ss.uids.concatenate(sources)[inds]
306 21 105754.0 5035.9 0.2 networks = np.concatenate(networks)[inds]
307 else:
308 new_cases = ss.uids()
309 sources = ss.uids()
310 networks = np.empty(0, dtype=ss_int)
311
312 21 11738.0 559.0 0.0 return new_cases, sources, networks
———————————————————————————————————————————————————————————
Profile of diseases.Infection.infect: 0.0573921 s (38.107%)
———————————————————————————————————————————————————————————
Total time: 0.0573921 s
File: /home/runner/work/starsim/starsim/starsim/diseases.py
Function: Infection.infect at line 255
Line # Hits Time Per Hit % Time Line Contents
==============================================================
255 def infect(self):
256 """ Determine who gets infected on this timestep via transmission on the network """
257 21 25379.0 1208.5 0.0 new_cases = []
258 21 9743.0 464.0 0.0 sources = []
259 21 10072.0 479.6 0.0 networks = []
260 21 678480.0 32308.6 1.2 betamap = self.validate_beta()
261
262 # Compute effective transmissibility and susceptibility directly on the raw
263 # (full-length) arrays. This avoids the gather/scatter, full-length astype copy,
264 # and extra wrapper allocations of the Arr math operators; edges only ever index
265 # living agents, so stale raw values for inactive agents are never used.
266 21 605703.0 28843.0 1.1 rel_trans = self.rel_trans.asnew(self.infectious.raw * self.rel_trans.raw, copy=False)
267 21 313933.0 14949.2 0.5 rel_sus = self.rel_sus.asnew(self.susceptible.raw * self.rel_sus.raw, copy=False)
268
269 42 171745.0 4089.2 0.3 for i, (nkey,route) in enumerate(self.sim.networks.items()):
270 21 32685.0 1556.4 0.1 nk = ss.standardize_netkey(nkey)
271
272 # Main use case: networks
273 21 16734.0 796.9 0.0 if isinstance(route, ss.Network):
274 21 242621.0 11553.4 0.4 if len(route): # Skip networks with no edges
275 21 10808.0 514.7 0.0 edges = route.edges
276 21 368493.0 17547.3 0.6 p1_to_p2 = [edges.p1, edges.p2, betamap[nk][0]] # p1→p2 direction, beta 0
277 21 357716.0 17034.1 0.6 p2_to_p1 = [edges.p2, edges.p1, betamap[nk][1]] # p2→p1 direction, beta 1
278 63 45410.0 720.8 0.1 for src, trg, beta in [p1_to_p2, p2_to_p1]:
279 42 76234.0 1815.1 0.1 if beta: # Skip networks with no transmission
280 42 1200626.0 28586.3 2.1 disease_beta = beta.to_prob(self.t.dt) if isinstance(beta, ss.Rate) else beta
281 42 2133806.0 50804.9 3.7 beta_per_dt = route.net_beta(disease_beta=disease_beta, disease=self) # Compute beta for this network and timestep
282 42 41289112.0 983074.1 71.9 randvals = self.trans_rng.rvs(src, trg) # Generate a new random number based on the two other random numbers
283 42 67932.0 1617.4 0.1 args = (src, trg, rel_trans, rel_sus, beta_per_dt, randvals) # Set up the arguments to calculate transmission
284 42 6817370.0 162318.3 11.9 target_uids, source_uids = self.compute_transmission(*args) # Actually calculate it
285 42 26937.0 641.4 0.0 new_cases.append(target_uids)
286 42 19693.0 468.9 0.0 sources.append(source_uids)
287 42 454647.0 10824.9 0.8 networks.append(np.full(len(target_uids), dtype=ss_int, fill_value=i))
288
289 # Handle everything else: mixing pools, environmental transmission, etc.
290 elif isinstance(route, ss.Route):
291 # Mixing pools are unidirectional, only use the first beta value
292 disease_beta = betamap[nk][0].to_prob(self.t.dt) if isinstance(betamap[nk][0], ss.Rate) else betamap[nk][0]
293 target_uids = route.compute_transmission(rel_sus, rel_trans, disease_beta, disease=self)
294 new_cases.append(target_uids)
295 sources.append(np.full(len(target_uids), dtype=ss_int, fill_value=ss.dtypes.int_nan))
296 networks.append(np.full(len(target_uids), dtype=ss_int, fill_value=i))
297 else:
298 errormsg = f'Cannot compute transmission via route {type(route)}; please subclass ss.Route and define a compute_transmission() method'
299 raise TypeError(errormsg)
300
301 # Finalize
302 21 17698.0 842.8 0.0 if len(new_cases) and len(sources):
303 21 369923.0 17615.4 0.6 new_cases = ss.uids.concatenate(new_cases)
304 21 1611571.0 76741.5 2.8 new_cases, inds = new_cases.unique(return_index=True)
305 21 299526.0 14263.1 0.5 sources = ss.uids.concatenate(sources)[inds]
306 21 105754.0 5035.9 0.2 networks = np.concatenate(networks)[inds]
307 else:
308 new_cases = ss.uids()
309 sources = ss.uids()
310 networks = np.empty(0, dtype=ss_int)
311
312 21 11738.0 559.0 0.0 return new_cases, sources, networks