Initializing sim with 10000 agents
Profiling 1 function(s):
<function Infection.infect at 0x73bca11b98a0>
Running 2000.01.01 ( 0/21) (0.00 s) ———————————————————— 5%
Running 2010.01.01 (10/21) (0.04 s) ••••••••••—————————— 52%
Running 2020.01.01 (20/21) (0.08 s) •••••••••••••••••••• 100%
Elapsed time: 88.3 ms
————————————————————————————————————————————————————————————
Profile of diseases.Infection.infect: 0.0349516 s (39.5574%)
————————————————————————————————————————————————————————————
Total time: 0.0349516 s
File: /home/cliffk/idm/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 11465.0 546.0 0.0 new_cases = []
258 21 5290.0 251.9 0.0 sources = []
259 21 4411.0 210.0 0.0 networks = []
260 21 341341.0 16254.3 1.0 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 314990.0 14999.5 0.9 rel_trans = self.rel_trans.asnew(self.infectious.raw * self.rel_trans.raw, copy=False)
267 21 173785.0 8275.5 0.5 rel_sus = self.rel_sus.asnew(self.susceptible.raw * self.rel_sus.raw, copy=False)
268
269 42 79997.0 1904.7 0.2 for i, (nkey,route) in enumerate(self.sim.networks.items()):
270 21 18078.0 860.9 0.1 nk = ss.standardize_netkey(nkey)
271
272 # Main use case: networks
273 21 9397.0 447.5 0.0 if isinstance(route, ss.Network):
274 21 127366.0 6065.0 0.4 if len(route): # Skip networks with no edges
275 21 5824.0 277.3 0.0 edges = route.edges
276 21 188440.0 8973.3 0.5 p1_to_p2 = [edges.p1, edges.p2, betamap[nk][0]] # p1→p2 direction, beta 0
277 21 178856.0 8517.0 0.5 p2_to_p1 = [edges.p2, edges.p1, betamap[nk][1]] # p2→p1 direction, beta 1
278 63 28584.0 453.7 0.1 for src, trg, beta in [p1_to_p2, p2_to_p1]:
279 42 40517.0 964.7 0.1 if beta: # Skip networks with no transmission
280 42 658484.0 15678.2 1.9 disease_beta = beta.to_prob(self.t.dt) if isinstance(beta, ss.Rate) else beta
281 42 1437431.0 34224.5 4.1 beta_per_dt = route.net_beta(disease_beta=disease_beta, disease=self) # Compute beta for this network and timestep
282 42 25601420.0 609557.6 73.2 randvals = self.trans_rng.rvs(src, trg) # Generate a new random number based on the two other random numbers
283 42 24475.0 582.7 0.1 args = (src, trg, rel_trans, rel_sus, beta_per_dt, randvals) # Set up the arguments to calculate transmission
284 42 3402477.0 81011.4 9.7 target_uids, source_uids = self.compute_transmission(*args) # Actually calculate it
285 42 14000.0 333.3 0.0 new_cases.append(target_uids)
286 42 9649.0 229.7 0.0 sources.append(source_uids)
287 42 264792.0 6304.6 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 10435.0 496.9 0.0 if len(new_cases) and len(sources):
303 21 230669.0 10984.2 0.7 new_cases = ss.uids.concatenate(new_cases)
304 21 1511146.0 71959.3 4.3 new_cases, inds = new_cases.unique(return_index=True)
305 21 184583.0 8789.7 0.5 sources = ss.uids.concatenate(sources)[inds]
306 21 66489.0 3166.1 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 7230.0 344.3 0.0 return new_cases, sources, networks
————————————————————————————————————————————————————————————
Profile of diseases.Infection.infect: 0.0349516 s (39.5574%)
————————————————————————————————————————————————————————————
Total time: 0.0349516 s
File: /home/cliffk/idm/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 11465.0 546.0 0.0 new_cases = []
258 21 5290.0 251.9 0.0 sources = []
259 21 4411.0 210.0 0.0 networks = []
260 21 341341.0 16254.3 1.0 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 314990.0 14999.5 0.9 rel_trans = self.rel_trans.asnew(self.infectious.raw * self.rel_trans.raw, copy=False)
267 21 173785.0 8275.5 0.5 rel_sus = self.rel_sus.asnew(self.susceptible.raw * self.rel_sus.raw, copy=False)
268
269 42 79997.0 1904.7 0.2 for i, (nkey,route) in enumerate(self.sim.networks.items()):
270 21 18078.0 860.9 0.1 nk = ss.standardize_netkey(nkey)
271
272 # Main use case: networks
273 21 9397.0 447.5 0.0 if isinstance(route, ss.Network):
274 21 127366.0 6065.0 0.4 if len(route): # Skip networks with no edges
275 21 5824.0 277.3 0.0 edges = route.edges
276 21 188440.0 8973.3 0.5 p1_to_p2 = [edges.p1, edges.p2, betamap[nk][0]] # p1→p2 direction, beta 0
277 21 178856.0 8517.0 0.5 p2_to_p1 = [edges.p2, edges.p1, betamap[nk][1]] # p2→p1 direction, beta 1
278 63 28584.0 453.7 0.1 for src, trg, beta in [p1_to_p2, p2_to_p1]:
279 42 40517.0 964.7 0.1 if beta: # Skip networks with no transmission
280 42 658484.0 15678.2 1.9 disease_beta = beta.to_prob(self.t.dt) if isinstance(beta, ss.Rate) else beta
281 42 1437431.0 34224.5 4.1 beta_per_dt = route.net_beta(disease_beta=disease_beta, disease=self) # Compute beta for this network and timestep
282 42 25601420.0 609557.6 73.2 randvals = self.trans_rng.rvs(src, trg) # Generate a new random number based on the two other random numbers
283 42 24475.0 582.7 0.1 args = (src, trg, rel_trans, rel_sus, beta_per_dt, randvals) # Set up the arguments to calculate transmission
284 42 3402477.0 81011.4 9.7 target_uids, source_uids = self.compute_transmission(*args) # Actually calculate it
285 42 14000.0 333.3 0.0 new_cases.append(target_uids)
286 42 9649.0 229.7 0.0 sources.append(source_uids)
287 42 264792.0 6304.6 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 10435.0 496.9 0.0 if len(new_cases) and len(sources):
303 21 230669.0 10984.2 0.7 new_cases = ss.uids.concatenate(new_cases)
304 21 1511146.0 71959.3 4.3 new_cases, inds = new_cases.unique(return_index=True)
305 21 184583.0 8789.7 0.5 sources = ss.uids.concatenate(sources)[inds]
306 21 66489.0 3166.1 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 7230.0 344.3 0.0 return new_cases, sources, networks