Repository navigation
perf: faster model build and IDAKLU set-up for large models - #5994
Merged
Merged
Conversation
- StateVector stores its slices as index ranges instead of a boolean mask. - CasADi functions and matrices are shared with pybammsolvers instead of copied. - IDAKLU no longer builds the rhs-only jacobian, which only ScipySolver uses. - Unstructured meshes gather faces per vertex.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5994 +/- ##
==========================================
- Coverage 98.24% 98.22% -0.02%
==========================================
Files 350 350
Lines 36112 36173 +61
==========================================
+ Hits 35478 35532 +54
- Misses 634 641 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…oo; type-check the SWIG address
MarcBerliner
marked this pull request as ready for review
October 28, 2026 18:09
Contributor
|
| Project | PyBaMM |
| Branch | perf/large-model-build-v2 |
| Testbed | bare-metal |
🐰 View full continuous benchmarking report in Bencher
⚠️ WARNING: Truncated view!The full continuous benchmarking report exceeds the maximum length allowed on this platform.
BradyPlanden
requested changes
Oct 29, 2026
…ut default, naming and imports
MarcBerliner
enabled auto-merge (squash)
October 30, 2026 13:30
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.
Description
Speeds up model build and
IDAKLUSolverset-up for large models (hundreds of thousands to millions of states), where several steps scaled worse than linearly or copied large objects needlessly:StateVectorstores its slices as index ranges instead of a dense boolean evaluation array over every state. Construction,size, Jacobians and CasADi conversion no longer touch an array the length of the state vector for each node.pybammsolversby pointer when it links the same CasADi library as the Python package (idaklu.shares_python_casadi), instead of being serialised and rebuilt. Sparse and densecasadi.DMs are filled from NumPy/SciPy buffers in one copy (to_casadi_dm, CSC and CSR), rather than element by element through SWIG. Without a shared library, the serialised path is used as before.IDAKLUSolverno longer builds the rhs-only Jacobian, which onlyScipySolveruses (BaseSolver.uses_rhs_jacobian)._group_rows) instead ofnp.unique(axis=0); hex geometry is about 2.5x faster at 400k cells, with identical volumes.stack_inputsconcatenates input values with one buffer copy.Shared functions keep CasADi's reference counting, so the solver owns them for its lifetime and releases them on deletion: 40 repeated set-up and solve cycles of a 38k-state model show no memory growth, in either the shared or the serialised mode.
Benchmarks
Best of 3,
IDAKLUSolver()defaults, 1 h discharge; end voltages agree withmainto 10 digits.Type of change
CHANGELOG.md):StateVectorandStateVectorDotnow raiseShapeErrorfor stepped, overlapping or out-of-order slices, and theirevaluation_arrayargument is deprecated and ignored.Important checks:
Please confirm the following before marking the PR as ready for review:
nox -s pre-commitnox -s testsnox -s doctests