Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small speed increase in making new cases with multirng #217

Merged
merged 2 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ All notable changes to the codebase are documented in this file. Changes that ma
:depth: 1


Version 0.1.7 (2024-01-27)
--------------------------
- Performance enhancement for disease transmission, leading to a 10% decrease in runtime.
- *GitHub info*: PR `217 <https://github.com/amath-idm/stisim/pull/217>`_


Version 0.1.6 (2024-01-23)
--------------------------
- Adds template interventions and products for diagnostics and treatment
Expand Down
14 changes: 8 additions & 6 deletions starsim/diseases/disease.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ def _make_new_cases_multirng(self, people):
n = len(people.uid) # TODO: possibly could be shortened to just the people who are alive
p_acq_node = np.zeros(n)

dfs = []
avec = []
bvec = []
pvec = []
for lkey, layer in people.networks.items():
if lkey in self.pars['beta']:
contacts = layer.contacts
Expand All @@ -358,12 +360,12 @@ def _make_new_cases_multirng(self, people):
continue

a, b = contacts[lbl_src], contacts[lbl_tgt]
df = pd.DataFrame({'p1': a, 'p2': b})
df['p'] = (rel_trans[a] * rel_sus[b] * contacts.beta * beta * people.dt).values
df = df.loc[df['p'] > 0]
dfs.append(df)
nzi = (rel_trans[a]>0) & (rel_sus[b]>0) & (contacts.beta>0)
avec.append(a[nzi])
bvec.append(b[nzi])
pvec.append(rel_trans[a[nzi]].__array__() * rel_sus[b[nzi]].__array__() * contacts.beta[nzi] * beta * people.dt)

df = pd.concat(dfs)
df = pd.DataFrame({'p1': np.concatenate(avec), 'p2': np.concatenate(bvec), 'p': np.concatenate(pvec)})
if len(df) == 0:
return [], []

Expand Down
4 changes: 2 additions & 2 deletions starsim/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

__all__ = ['__version__', '__versiondate__', '__license__']

__version__ = '0.1.6'
__versiondate__ = '2024-01-23'
__version__ = '0.1.7'
__versiondate__ = '2024-01-27'
__license__ = f'STIsim {__version__} ({__versiondate__}) — © 2024 by IDM'
8 changes: 4 additions & 4 deletions tests/benchmark.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"time": {
"people": 0.019,
"initialize": 0.046,
"run": 0.275
"people": 0.018,
"initialize": 0.041,
"run": 0.251
},
"parameters": {
"n_agents": 10000,
"n_years": 20,
"dt": 0.2
},
"cpu_performance": 0.30820661368745095
"cpu_performance": 0.9938153654580599
}
Empty file modified tests/update_baseline.py
100644 → 100755
Empty file.
Loading