Repository navigation
feat(rust): observe rust-model solutions natively - #5963
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/07-idaklu-rust-mode #5963 +/- ##
=============================================================
- Coverage 98.21% 98.20% -0.02%
=============================================================
Files 353 353
Lines 36733 37029 +296
=============================================================
+ Hits 36076 36363 +287
- Misses 657 666 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Oct 22, 2026
BradyPlanden
force-pushed
the
stack/08-native-observation
branch
from
October 28, 2026 09:55
73c029c to
879f508
Compare
BradyPlanden
force-pushed
the
stack/08-native-observation
branch
2 times, most recently
from
October 28, 2026 14:11
26c1029 to
63e4b86
Compare
BradyPlanden
force-pushed
the
stack/08-native-observation
branch
2 times, most recently
from
October 29, 2026 08:01
b77ac50 to
52b69b1
Compare
BradyPlanden
marked this pull request as ready for review
October 29, 2026 08:56
Contributor
|
| Project | PyBaMM |
| Branch | stack/08-native-observation |
| 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.
A second reader in build_variable: a model bound with ObserverCache.bind_rust_model reads each segment through native tapes kept on its ObserverCache, with shared-tape variable sets and native sensitivities.
BradyPlanden
force-pushed
the
stack/08-native-observation
branch
from
October 29, 2026 17:26
52b69b1 to
b55c69e
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
Reads variables, and their sensitivities, from a rust-model
IDAKLUSolversolution in Rust.set_upbinds theCompiledModelto the model'sObserverCache(refactor: read solution variables through per-model observer caches #5786).build_variablethen evaluates each variable on a tape compiled into the model's retained graph: one Rust call per segment, cubic-Hermite between time points when the solution stores derivatives.Besides
CompiledModel.graph, a getter it adds to the bindings with its stub, this PR is Python only; the other Rust methods it calls (n_states,ExprGraph.from_expr) are from #5962.ObserverCache:bind_rust_model,native_leaf(a variable's tape, compiled once per model),native_set(several variables on one tape, sharing subexpressions) andpost_sum_leaf.set_updrops the native leaves.observation.pysays.NativeObserver: evaluates raw values (eval_trajectory), Hermite values (eval_trajectory_hermite) and sensitivities. Time integrals add their post-sum sensitivities throughnative_postfix_sensitivities. On anoutput_variablessolve, a variable that is not an output reads its values and sensitivities from the placeholder states, as on the CasADi path.Solution.update([...]):SharedOutputstape and sweeps its sensitivities once per parameter, and each variable reads its rows through aSharedOutputLeaf. A segment with no time points gives empty rows.output_variablessolve) nothing is stored. Before, on CasADi and rust alike, the names before the failing one were rebuilt and kept.update("name")with one string is unchanged.QuickPlotandSolution.get_data_dictbuild all their variables this way.ProcessedVariableTimeIntegral.sum_over_timeis public, andcheck_discrete_timesis a method, for the native path.When native reading applies:
IDAKLUSolver.VectorFieldvariables.VectorFieldvariables are read one by one, not on a shared tape.calculate_sensitivitiesraisesValueError, as onmain.On the CasADi path, values are unchanged.
Solution.updatededuplicates its names and stores all or nothing, andQuickPlotandget_data_dictbuild every variable up front.Review on #5732
observation.pykeeps the observer naming from refactor: read solution variables through per-model observer caches #5786 onmain(ObserverCache,VariableObserver), and the class under review is not in this stack.backend[key]is:SharedOutputsholds one result for as many reads as it has leaves, which its docstring states. Each call keeps its own result and a lock guards the held one, so threads reading different solutions while the GIL is released get their own rows.Type of change
New feature, under
## FeaturesinCHANGELOG.md.Key checklist
pre-commit runt_interp;output_variablessolve;updatestoring nothing when one name fails.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"rust"as the defaultconvert_to_format