Repository navigation
feat(rust): evaluate rust models through compiled evaluators - #5960
Open
BradyPlanden wants to merge 1 commit into
Open
BradyPlanden wants to merge 1 commit into
BradyPlanden wants to merge 1 commit into
Conversation
This was referenced Oct 22, 2026
This was referenced Oct 22, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## stack/04-to-rust-lowering #5960 +/- ##
=============================================================
- Coverage 98.18% 98.18% -0.01%
=============================================================
Files 351 353 +2
Lines 36399 36505 +106
=============================================================
+ Hits 35738 35841 +103
- Misses 661 664 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
BradyPlanden
force-pushed
the
stack/05-rust-generic-evaluators
branch
from
October 28, 2026 09:55
db04e34 to
45bbd36
Compare
BradyPlanden
force-pushed
the
stack/05-rust-generic-evaluators
branch
2 times, most recently
from
October 28, 2026 15:28
67e6c0a to
3e4986e
Compare
BradyPlanden
force-pushed
the
stack/05-rust-generic-evaluators
branch
from
October 29, 2026 08:01
3e4986e to
b408f4d
Compare
BradyPlanden
marked this pull request as ready for review
October 29, 2026 08:55
Contributor
|
| Project | PyBaMM |
| Branch | stack/05-rust-generic-evaluators |
| 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.
"rust" is a valid convert_to_format; BaseSolver.process builds RustEvaluators; ScipySolver, AlgebraicSolver and EIS run on them.
BradyPlanden
force-pushed
the
stack/05-rust-generic-evaluators
branch
from
October 29, 2026 17:26
b408f4d to
d158fdb
Compare
This branch has not been deployed
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
Makes
"rust"a validconvert_to_format. A rust model's rhs, algebraic, Jacobian, event and initial-condition functions are compiled to Rust and evaluated byScipySolver,AlgebraicSolverand EIS. The default stays"casadi".BaseSolver.processcompiles each function into aCompiledFunctionon its ownExprGraph. Inputs are registered in stacking order at their widths (rust_graph_with_inputs).RustEvaluatorwraps the compiled function with CasADi's(t, y, inputs)calling convention. It has four roles: the value, the Jacobian (a scipy CSC built on first use), a Jacobian-vector product, andjacp, with one column per sensitivity parameter.stack_inputsgainsconvert_to_format="casadi", and returns a flat numpy array for rust models. Every caller passes the model's format (EIS, inside its rust branch, passes"rust"), and a one-argument call behaves as in v26.10.0.Moduloperiods are evaluated through the model's own compiled functions, with the inputs stacked in its format, as its residual is.pybamm.SolverErrornaming the input. So does a vector-width input that only a variable reads and that has no value, which before raised a bareValueErrorfrom Rust.IDAKLUSolver,CasadiSolverandCasadiAlgebraicSolverconvert rust models to CasADi, with a warning; feat(rust): solve rust models with IDAKLUSolver #5962 adds IDAKLU's Rust path.ScipySolverevent wrapper returnsnp.asarray(...).item(), and EIS calls.sparse()only on CasADi Jacobians, so a python or jax model's Jacobian goes tocsc_matrixas it is.validate_rust_sensitivity_widthsis added in this PR, and feat(rust): solve rust models with IDAKLUSolver #5962 calls it.Not supported in this PR:
return_jacp_stackedraisesSolverError, before anything is lowered or compiled.NonlinearSolver, still builds its residual with CasADi, so no DAE solver keeps a rust model until feat(rust): solve rust models with IDAKLUSolver #5962.ScipySolversensitivities raiseNotImplementedError, as onmain.Type of change
New feature, under
## FeaturesinCHANGELOG.md.Key checklist
pre-commit runRustEvaluatorrole against CasADi on a toy DAE (rtol 1e-12, atol 1e-14), including events, initial conditions and a rectangular Jacobian.stack_inputsfor rust models, and called with one argument;SolverErrorat widths 1 and 3, and for a missing vector input;return_jacp_stackedrejected before lowering;TestDenseMatrixToRust) and theconftest_rustfixtures from feat(rust): lower expression trees with Symbol.to_rust #5959, withrust_backendadded here;AlgebraicSolveron rust against casadi (rtol 1e-8);"rust"round-trips through serialisation.Rust execution engine stack: proposal #5667, showcase #5732
Each PR is one commit on the one above it.
Function.create_copykeeps the function's classRegPowerand uniform-grid interpolant lookups matchevaluatepybamm-core: expression graph, typed IR, interpreters, forward-mode ADpybamm-core:CompiledModel, coloured Jacobians, the C ABIpybamm.rustbindings, built into thepybammwheelSymbol.to_rustconvert_to_format = "rust"forScipySolver,AlgebraicSolverand EIS ← this PRpybammsolvers: IDAKLU over the C ABIIDAKLUSolveron rust modelspybamm-core: diffsol DAE solverpybamm.DiffsolSolver"rust"as the defaultconvert_to_format