Repository navigation
feat(rust): pybamm.DiffsolSolver, integrating rust models with diffsol - #5965
Open
BradyPlanden wants to merge 1 commit into
Open
BradyPlanden wants to merge 1 commit into
BradyPlanden wants to merge 1 commit into
Conversation
2 of 4 tasks
This was referenced Oct 22, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## stack/09-rust-core-diffsol #5965 +/- ##
=============================================================
Coverage ? 98.15%
=============================================================
Files ? 354
Lines ? 37278
Branches ? 0
=============================================================
Hits ? 36592
Misses ? 686
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/10-diffsol-solver
branch
from
October 28, 2026 09:55
d3bb4ff to
856f633
Compare
| on_failure, | ||
| output_variables, | ||
| ) | ||
| self.name = "diffsol solver (bdf)" |
| self.name = "diffsol solver (bdf)" | ||
| self._calc_ic = calc_ic | ||
| self._hermite_interpolation = bool(hermite_interpolation) | ||
| self._supports_interp = True |
| self._calc_ic = calc_ic | ||
| self._hermite_interpolation = bool(hermite_interpolation) | ||
| self._supports_interp = True | ||
| self._supports_t_eval_discontinuities = True |
BradyPlanden
force-pushed
the
stack/10-diffsol-solver
branch
2 times, most recently
from
October 28, 2026 14:11
76e3077 to
283bed6
Compare
BradyPlanden
force-pushed
the
stack/10-diffsol-solver
branch
2 times, most recently
from
October 29, 2026 08:01
37788fe to
b9bb622
Compare
BradyPlanden
marked this pull request as ready for review
October 29, 2026 08:56
Contributor
|
| Project | PyBaMM |
| Branch | stack/10-diffsol-solver |
| 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.
PreparedSolver bindings, pybamm.DiffsolSolver and its docs.
BradyPlanden
force-pushed
the
stack/10-diffsol-solver
branch
from
October 29, 2026 17:26
b9bb622 to
519f514
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
Adds
pybamm.DiffsolSolver, which integrates a rust model entirely in Rust through the solver from #5964, with no CasADi or SUNDIALS on the path. It releases the GIL while it integrates.set_upswitches the model toconvert_to_format = "rust", lowers it withRustModelLowering(#5962), and reads its solutions natively (#5963).rtol, andatolas a scalar or per state.calc_ic=True: diffsol finds consistent initial conditions. WithFalse, they are root-solved first withroot_method, which defaults toNonlinearSolverfor DAEs.hermite_interpolation=Trueandsens_atol_factor=1.0.options: a dict of diffsol's 15OdeSolverOptions, plusnum_threads.Nonewhere only the growth and shrink bounds take it), and an invalidnum_threadsorsens_atol_factorraiseSolverErrornaming the option. NumPy scalars are accepted.on_failuretakes only"error", the default;"warn"and"ignore"raiseSolverError, since diffsol returns no partial solution.t_evalis the discontinuity map, as forIDAKLUSolver. Output times aret_eval ∪ t_interpplus the discontinuity times, and each discontinuity segment gets only thet_interppoints inside it.t_interp, they also include 100 uniform points over the span, chosen from the times passed in, before discontinuities are merged. A bare[t0, tf]therefore gives 100 points plus the discontinuity times, and a coarset_evalsuch as[0, 1800, 3600]still has a grid fine enough for Hermite reads. Passt_interp=t_evalfor output at exactlyt_eval, as forIDAKLUSolver.t_interpkeeps exactlyt_evalwhen that has three or more points, which drive-cycle experiment steps rely on.num_threads > 1solves several input sets concurrently withsolve_batch, or multithreads a single set's sparse LU. Withnum_threads = 1, the sets run one after another.forkduring a build cannot deadlock the child.yp, as forIDAKLUSolver, andhermite_interpolation=Falsedropsyp.ypis never stored foroutput_variables, or above 4096 output points.sens_atol_factorscaling the sensitivity floor.sens_atol_factoras the likely cause.Solution.solver_statistics.sens_error_control_relaxedrecords it.output_variablessolve keeps the states and state sensitivities at both ends, sofirst_state,last_stateand a continued step have them. Like IDAKLU's, it lists its sensitivity names with zero-row state sensitivities, sostep()'s restart checks find them.pybamm.rust.PreparedSolver,SolveOutcome,SolverStatisticsanddefault_solver_options, with stubs.SolveOutcome.event_indexnames the event that ended a solve, and solutions setclosest_event_idxfrom it.pybamm-core,check_batch_widthswith itsBatchWidthsandBatchSensWidtherrors, andTermination::as_flag,event_timeandevent_index, which these bindings use.pybamm.SolverStatisticsgains diffsol's counters, includingproblem_setup_time_secs, and combinessens_error_control_relaxedwith OR when solutions are added. Unpickling one saved by 26.10 fills the new fields with their defaults, so it still adds to a new one.IDAKLUSolverthroughBaseSolver: theatolcheck,_internal_initialisation, and the event-violation guard.OutputAssembly.stack_parameter_blocksstacks sensitivity blocks, andhatch_build.pybuildspybamm.rustwith thediffsolfeature.api/solvers/diffsol_solver.rst.Errors and limits:
SolverErrorwith the binding's message. Sensitivity names that are not inputs raiseSolverErrorfrom the lowering.SolverErrornaming the input set.TensorFieldoutput variables, raiseSolverError, as on IDAKLU's Rust path.nprocis ignored.Review on #5732
rayon_pool.rs: the thread pools are inpybamm-python/src/rayon_pool.rs.Type of change
New feature, under
## FeaturesinCHANGELOG.md.Key checklist
pre-commit run--all-features, 1 ignored)t_eval;output_variablessolves;SolverErrorfor unknown keys, wrong types, out-of-range values, invalid tolerances, unknown sensitivity parameters andon_failure;closest_event_idxfor state and output solves;num_threads: serial equals batch (Hypothesis), result order, shared and evicted pools, a forked child, failures named per set;atoland time discontinuities.IDAKLUSolverat rtol 1e-5 and atol 1e-8:sens_atol_factor, and the relaxed retry at a floor no step can meet;dy0/dpseeding;t_eval: within 2e-6 V on diffsol's own grid, and 1.2 mV (Hermite) or 19 mV (linear) at worst in between;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 EISpybammsolvers: IDAKLU over the C ABIIDAKLUSolveron rust modelspybamm-core: diffsol DAE solverpybamm.DiffsolSolver← this PR"rust"as the defaultconvert_to_format