docs: add memory best-practices notebook for large-scale models#624
Open
MaykThewessen wants to merge 4 commits intoPyPSA:masterfrom
Open
docs: add memory best-practices notebook for large-scale models#624MaykThewessen wants to merge 4 commits intoPyPSA:masterfrom
MaykThewessen wants to merge 4 commits intoPyPSA:masterfrom
Conversation
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a notebook documenting memory-efficient patterns for large-scale linopy models, as invited by @FBumann in #599.
Closes #599 (partial — notebook contribution specifically).
Context
The patterns are drawn from production experience with a 200-bus, 1,800-generator PyPSA power system model solved over 8,760 hourly snapshots in 168-hour weekly chunks (~1.4M LP variables and constraints per chunk, ~9 GB steady-state, ~15 GB peak).
Notebook contents (
examples/memory-best-practices.ipynb)constraints.flatduringmatrices.Aand COO→CSC conversion; solution unpacking); how to avoid repeated matrix buildsdel network.model+malloc_trim(0)/malloc_zone_pressure_relief()is essential (RSS does not drop without the OS-level trim)changeRowsBounds()/changeColsCost()for chunks 2+, skipping linopy rebuild entirely; saves ~50 s and ~9 GB per chunkfillnato avoid (T×N) intermediate copies; sparse RHS push viakeys >= 0maskingtracemallocandpsutil.rss_gb()patterns;estimate_model_memory()helper for sizing RAM before solvingmatrices.clean_cached_properties()(freesflat_conscache, typically 2–3 GB); detachsolver_modelbeforedel;gc.collect()+ OS trimfilter_missings=True; groupby aggregation vs dense broadcasting;merge=Falsefor per-snapshot constraintsAll code examples are from production code paths and include both the recommended pattern and the anti-pattern it replaces.
Files changed
examples/memory-best-practices.ipynb— new notebookdoc/memory-best-practices.nblink— nblink entry pointing to the notebookdoc/index.rst— addedmemory-best-practicesto the User Guide toctree