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

Avoid a deepcopy when constructing MPBP from SIS #128

Merged
merged 1 commit into from
May 2, 2024
Merged

Conversation

stecrotti
Copy link
Owner

@stecrotti stecrotti commented May 2, 2024

mpbp(sis::SIS) and similar become quite slow for large graph sizes / long times. Profiling shows most of the time is spent at this call to deepcopy. This PR eliminates it

Warning: let's check first that this doesn't break anything

Benchmark

[crotti@sibyl MatrixProductBP]$ git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
[crotti@sibyl MatrixProductBP]$ julia -e '
> using MatrixProductBP, MatrixProductBP.Models, Graphs, IndexedGraphs
> T = 10^3        # final time
> k = 3         # degree
> λ = 0.07      # rate of transmission
> ρ = 0.1       # rate of recovery
> γ = 0.2      # prob. of zero patient
> N = 5*10^3
> gg = random_regular_graph(N, k; seed=0)
> g = IndexedGraph(gg)
> sis = SIS(g, λ, ρ, T; γ)
> # run once for compilation
> bp = mpbp(sis)
> # measure runtime
> @time mpbp(sis)
> '
225.252552 seconds (160.36 M allocations: 9.850 GiB, 26.75% gc time)
[crotti@sibyl MatrixProductBP]$ 
[crotti@sibyl MatrixProductBP]$ git checkout no-copy
Switched to branch 'no-copy'
Your branch is up to date with 'origin/no-copy'.
[crotti@sibyl MatrixProductBP]$ 
[crotti@sibyl MatrixProductBP]$ julia -e '
> using MatrixProductBP, MatrixProductBP.Models, Graphs, IndexedGraphs
> T = 10^3        # final time
> k = 3         # degree
> λ = 0.07      # rate of transmission
> ρ = 0.1       # rate of recovery
> γ = 0.2      # prob. of zero patient
> N = 5*10^3
> gg = random_regular_graph(N, k; seed=0)
> g = IndexedGraph(gg)
> sis = SIS(g, λ, ρ, T; γ)
> # run once for compilation
> bp = mpbp(sis)
> # measure runtime
> @time mpbp(sis)
> '

 40.912102 seconds (140.32 M allocations: 6.984 GiB, 58.05% gc time)

shows more than x5 speed-up

Copy link

codecov bot commented May 2, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 90.69%. Comparing base (4570681) to head (102be4f).

Files Patch % Lines
src/Models/epidemics/sis_heterogeneous_bp.jl 50.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #128      +/-   ##
==========================================
+ Coverage   90.65%   90.69%   +0.04%     
==========================================
  Files          22       22              
  Lines        1305     1300       -5     
==========================================
- Hits         1183     1179       -4     
+ Misses        122      121       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stecrotti stecrotti merged commit 289d074 into main May 2, 2024
4 of 5 checks passed
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.

1 participant