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

Optimize forward step for large populations #10

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

maxsvetlik
Copy link

This introduces optimizations in the simulator's forward step that reduces the iteration time for sufficiently large populations. This is accomplished through

  1. limiting the computation of combination and product used for computing contact pairs to only the randomized indices that are relevant
  2. transparent changes to some data structures (like using dict rather than orderedSets where possible)

Based on experiments, the execution time of running the simulator at the current main branch vs these changes are as follows:

Population                main         this PR
1000                      56.0s        58.0s
2000                      2:10m        2:12m
4000                      4:15m        4:13m
10000                    ~22.0m       12:32m
100000                 3:40:05hr     2:26:43hr

Testing can be done by running scripts/run_pandemic_sim.py

@varunrajk
Copy link

@maxsvetlik Thanks for the PR - can you please fix the style checks?

@maxsvetlik
Copy link
Author

FWIW prior to implementing these changes, I had focused effort parallelizing the forward update step across multiple threads or processes, but was unsuccessful due to the overhead involved. I believe this is due to the nature of the computations happening (numerous short calls to objects).

@maxsvetlik
Copy link
Author

Absolutely. I'll push a commit to address the CI issues shortly.

@maxsvetlik
Copy link
Author

Apologies for gumming up the CI with failed builds. Didn't realize I could run it locally with run_static_checks.py.
This PR is now passing. Please let me know if there are any questions.

@varunrajk
Copy link

Ah, sorry about finding about the run_static_checks.py the hard way. I'll add it to the Readme. Thanks for fixing the style errors. We should review your PR soon.

return a[idx // b.size], b[idx % b.size]


def comb2_reduced(l: np.array, idx: list) -> tuple:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you improve the documentation on the arguments and what is happening inside the function?



@lru_cache(maxsize=None)
def nCk(n: int, k: int) -> int:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

calulate binomial coeffecients
"""
m = 0
if k == 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you comment on these conditions?



@lru_cache(maxsize=None)
def nCk(n: int, k: int) -> int:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you improve the naming of this function?

@varunrajk
Copy link

@maxsvetlik any updates to @rcapobianco's comments? Those seem very minor and we can merge this PR once you address them. Thanks.

@maxsvetlik
Copy link
Author

Hi all, apologies for the delay. I've improved documentation in the areas pointed out; I tried to be as descriptive as possible while being concise. If more verbosity is needed let me know.

Copy link
Contributor

@rcapobianco-sony rcapobianco-sony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@rcapobianco-sony
Copy link
Contributor

@varunrajk this has never been merged, although approved. I see there is a conflict with your new changes tho. Can you fix this maybe?

@rcapobianco-sony
Copy link
Contributor

It has been a while, but I still think this would deserve to get merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants