Repository navigation
feat!: default convert_to_format to rust - #5966
Open
BradyPlanden wants to merge 12 commits into
Open
BradyPlanden wants to merge 12 commits into
BradyPlanden wants to merge 12 commits into
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
2 of 3 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## stack/10b-graph-inspection #5966 +/- ##
=============================================================
Coverage ? 98.44%
=============================================================
Files ? 369
Lines ? 39875
Branches ? 0
=============================================================
Hits ? 39255
Misses ? 620
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Oct 22, 2026
BradyPlanden
force-pushed
the
stack/11-default-rust
branch
from
October 28, 2026 09:55
cef6708 to
18aae11
Compare
BradyPlanden
force-pushed
the
stack/11-default-rust
branch
2 times, most recently
from
October 28, 2026 14:11
58c95d5 to
2ef0d3e
Compare
BradyPlanden
force-pushed
the
stack/11-default-rust
branch
from
October 28, 2026 15:28
2ef0d3e to
9fbc37e
Compare
BradyPlanden
force-pushed
the
stack/11-default-rust
branch
from
October 29, 2026 08:01
9fbc37e to
fd167d2
Compare
BradyPlanden
marked this pull request as ready for review
October 29, 2026 10:10
Member
Author
|
I'm marking this ready-for-review to get benchers results with rust as the default backend. It should not be merged until the rust backend is verified as stable. |
Contributor
|
| Project | PyBaMM |
| Branch | stack/11-default-rust |
| Testbed | bare-metal |
⚠️ WARNING: Truncated view!The full continuous benchmarking report exceeds the maximum length allowed on this platform.
🚨 1 Alert
🐰 View full continuous benchmarking report in Bencher
BradyPlanden
force-pushed
the
stack/11-default-rust
branch
from
November 30, 2026 10:24
72ec68b to
f8102e1
Compare
BradyPlanden
changed the base branch from
stack/10c-graph-inspection
to
stack/10b-graph-inspection
November 30, 2026 11:54
BradyPlanden
force-pushed
the
stack/11-default-rust
branch
from
November 30, 2026 11:54
f8102e1 to
12f34f4
Compare
4 tasks done
BradyPlanden
force-pushed
the
stack/11-default-rust
branch
from
November 30, 2026 15:40
12f34f4 to
675c565
Compare
BradyPlanden
force-pushed
the
stack/11-default-rust
branch
from
December 2, 2026 09:22
675c565 to
ab67b6f
Compare
BaseModel defaults to "rust"; CasADi-specific tests pin their format; user guide and multithreading docs describe the rust backend.
The Rust backend refuses a symbol it cannot lower with `NotImplementedError`.
The Rust backend guide listed events among DiffsolSolver's features without saying that, unlike IDAKLUSolver's since #6056, they cannot read the state time derivatives.
DiffsolSolver overrode a model's `convert_to_format` in place with only an info log. Now that Rust is the default, any other format was chosen, so overriding it warns, naming the model and the format replaced.
It said DiffsolSolver's sensitivities are always under error control, now an option, and that IDAKLU's off-grid reads beat diffsol's on a coarse `t_interp`, where IDAKLU drops its Hermite data and reads linearly. It now also says when diffsol drops its own, that `on_failure` must be "error", and that converting another format warns.
A Rust model was lowered several times over. Each integrator compiled its CompiledModel through its own copy of the recipe, NonlinearSolver compiled a second one for its Newton step, and process() gave every symbol it compiled a graph of its own: the initial conditions, discontinuity times and step state mappers of every solve, and every part a solver other than IDAKLU read. Two class flags chose the path. A model now keeps one RustModelLowering, made by RustModelLowering.of and kept while its input names stay the same; a copy or pickle of the model drops it. BaseSolver.set_up compiles the model's CompiledModel on it for every solver: the residual, the algebraic block of a DAE, the termination events, the df/dp of any sensitivities, the output variables and the upsampling output a solver's _upsampling_variable names. The generic rhs_eval, algebraic_eval and rhs_algebraic_eval, their Jacobians and the termination events are views of it, as RustEvaluator now takes a view's rows and a prepared Jacobian. process(), the EIS output Jacobian and NonlinearSolver compile on the same graph, and NonlinearSolver reuses the model's CompiledModel rather than compiling its own. A model without states compiles over an empty mass matrix. A ScipySolver set-up of an SPM builds one graph rather than six. A DFN set up for a Newton initialisation compiles one CompiledModel rather than two, in 2.7 ms rather than 4.4 ms.
The guide's account of how a model compiles now says the graph fixes its inputs, and that a set-up compiles the CompiledModel whole or not at all.
…ough of The guide claimed a failed set-up leaves the model as it was; it keeps the evaluators of its last set-up, as the initial conditions are set before the CompiledModel compiles. The Newton tests now make their lowerings with RustModelLowering.of, as source does.
…onditions a graph of their own The lowering kept the last compile's output lengths and sensitivity names for IDAKLU and Diffsol to read back, so two solvers setting up one model at once could read each other's, and it bound the model's evaluators itself. Initial conditions compiled on the model's graph, which grew by one node, carried by every pickle, for each initial state a sweep tried. compile_model now keeps only the CompiledModel, for the Newton step to reuse. BaseSolver._set_up_rust_model compiles it, binds the model's evaluators as its views, and hands it to the solver's _prepare_integrator, which IDAKLU and Diffsol implement in place of _set_up_rust and _prepare_solver; output lengths come from the CompiledModel's outputs and sensitivity names from the model. Initial conditions, which change from solve to solve, compile on a graph of their own. IDAKLU refuses a model without states as it checks the model, before anything compiles, and a Rust set-up returns before the CasADi path's preparation.
Above 4096 output columns a solve stopped storing yp, so off-grid reads fell from cubic to linear without saying so. The reason given, that a dense grid's chord is already at the integration error floor, depends on the model's timescales against the span, not on the column count, and IDAKLU has no such cap. hermite_interpolation=False remains the way to save the memory.
A single solve could factorise its sparse LU on num_threads workers of a shared pool, documented as worthwhile from about 50k states. Timed on Chen2020 DFNs of 962, 8262 and 50652 states and an SPM, 2, 4 and 8 threads were never faster than one, and on the 50652-state DFN 4 and 8 threads were 12% and 24% slower. IDAKLU's num_threads only solves input sets in parallel, so DiffsolSolver's now does the same. SolveRequest loses lu_threads, PreparedSolver.solve loses num_threads, and the solve loses the lu_par it carried through Run, Recorder and its LU helpers. Every LU still runs at an explicit serial Par, since a host may disable faer's global parallelism.
…e Rust backend guide The guide arrives with the switch to Rust by default, after the Ctrl-C handling and pybamm.rust's exception classes it now describes.
BradyPlanden
force-pushed
the
stack/11-default-rust
branch
from
December 4, 2026 10:47
ab67b6f to
6bc0a4d
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
Models default to
convert_to_format = "rust"instead of"casadi"(BaseModel._DEFAULT_CONVERT_TO_FORMAT). Every model is lowered to the Rust core unless it opts out withmodel.convert_to_format = "casadi". With the rest of the stack:the default
IDAKLUSolversolves and reads rust models in Rust;ScipySolver,AlgebraicSolverand EIS evaluate them through compiled functions;CasadiSolverandCasadiAlgebraicSolverconvert them to CasADi, logging the conversion at INFO for a model left at the default format and at WARNING for a format chosen explicitly, so the deprecated solvers'DeprecationWarningstays the one warning a default model sees.DiffsolSolver: overriding a model's chosen format now warns, naming the model and the format it replaces, where it logged at INFO.Serialisation: saving falls back to the default format, and a file saved without a
convert_to_formatkey loads as"rust".Tests:
"casadi": the CasADi solver suites (through autouse fixtures), CasADi leaves and pickles, AOT compilation, the lead-acid comparisons, the IDAKLU sparse-output sensitivity guard, and single tests in ten more files, among them the bitwise CasADi parity of input-dependent discontinuity times. Among those,test_multiple_inputskeeps covering CasADi with fewer solvers than threads.standard_output_testsraises its absolute tolerance from 2e-14 to 5e-14, since round-off differs by backend.Docs:
user_guide/rust_backend.rst, covers choosing the backend, its differences from CasADi,DiffsolSolver's output times and Hermite reads, interrupting a solve, and adding a new expression type. The Ctrl-C andUnsupportedExpressionErrorparagraphs describe feat(rust): interpolant tables over input parameters and expressions #6134, which lands before this PR.num_threadsacross the backends.rust_idaklu_build.mdand thepybamm-rustREADME point to the guide.What raises on the Rust backend:
IDAKLUSolverraisesSolverErrorfor sensitivities with respect to an input of width above 1, and solves withnum_solversequal tonum_threads, as the guide says.return_jacp_stackedandTensorFieldoutput variables also raiseSolverError.TypeErrororNotImplementedError, and an interpolant table Rust refuses raisesModelError.Performance
A release needs
pybammsolvers0.14.0 on PyPI (#5961) and the platform wheels from #5958.Type of change
Breaking change, under
## Breaking changesinCHANGELOG.md, with the migration note "Setmodel.convert_to_format = "casadi"to restore the previous backend."Key checklist
pre-commit runnox -s doctests"casadi". The CasADi solvers' conversion test, from feat(rust): evaluate rust models through compiled evaluators #5960, now checks the log level for a default and a chosen formatRust execution engine stack: proposal #5667, showcase #5732
Each PR builds 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 EISpybammsolvers: IDAKLU over the C ABIIDAKLUSolveron rust modelspybamm-core: diffsol DAE solverpybamm.DiffsolSolverInterpolantover input parameters and expressionspybamm.rust's own errors, array-likes, threads and Ctrl-Cpybamm.rust.inspection; every tape derived in one place"rust"as the defaultconvert_to_format← this PR