Repository navigation
refactor(rust): IDAKLU sizes itself from the evaluator's own table - #6133
Closed
BradyPlanden wants to merge 1 commit into
Closed
BradyPlanden wants to merge 1 commit into
BradyPlanden wants to merge 1 commit into
Conversation
IDAKLU's set-up read 15 CompiledModel members in Python and passed 20 arguments to create_rust_solver_group, whose RustFunctions took 15, eight of them counts the evaluator's FFI table already answers. Each count was checked three times: in Python, in idaklu.cpp, and in C++ against the table. The Rust Newton solver took its block split and Jacobian pattern from Python the same way, with Python shifting the pattern's columns into the block. The table now also carries the Jacobian's CSC pattern, each state's IDA id, the algebraic Jacobian's COO pattern, and which event components read y_dot, appended within ABI version 2. RustFunctions reads a RustLayout from its own evaluator and works out the band widths from the pattern, so create_rust_solver_group takes only the evaluators, atol, rtol, options and whether to use the algebraic sub-block. It refuses an atol of the wrong length, evaluators with different counts, and a sub-block that covers only some of the states the mass matrix marks algebraic. The Newton solver reads its block from the table and shifts the columns itself, beside the gather that puts the block at the trailing states. IDA counts one root per event component, as the flags do, so C++ no longer refuses a vector event; the lowering still does. The C++ pattern checks, Python's _csc_bandwidths, and the CompiledModel members that only fed C++ (has_algebraic, algebraic_jacobian_nnz, algebraic_jacobian_sparsity_pattern) go, with the tests that faked a disagreement to reach those checks.
This was referenced Nov 30, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## stack/07-idaklu-rust-mode #6133 +/- ##
=============================================================
+ Coverage 98.39% 98.41% +0.02%
=============================================================
Files 363 363
Lines 38590 38976 +386
=============================================================
+ Hits 37969 38358 +389
+ Misses 621 618 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
Author
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
IDAKLUSolversizes a rust model's solver from the evaluator's own FFI table instead of from counts Python reads off theCompiledModeland passes down.y_dot, appended within ABI version 2.test_ffi_abi_contract.rspins the layout against pybammsolvers' header.create_rust_solver_grouptakes the evaluators,atol,rtol, options and whether to use the algebraic sub-block. It refuses anatolof the wrong length, evaluators of different models, and a sub-block that covers only some of the states the mass matrix marks algebraic._csc_bandwidths, theCompiledModelmembers that only fed C++ (has_algebraic,algebraic_jacobian_nnz,algebraic_jacobian_sparsity_pattern), and the tests that faked a disagreement to reach those checks.Evidence
After: nothing can disagree, so those six go, with
test_csc_bandwidthsand the vector-event refusal. New tests pin what the table carries and what C++ still refuses:jac_pattern_writes_the_jacobian_in_csc_order,alg_jac_pattern_matches_the_order_alg_jac_assemble_fills,state_ids_mark_the_states_the_mass_matrix_leaves_out_as_algebraic,events_read_y_dot_flags_every_component_of_each_event,every_buffer_of_the_layout_queries_is_null_checked.create_rust_solver_grouprefusing anatolof another length, evaluators of different models, an evaluator count other thannum_solvers, and a sub-block over only some algebraic states; the Newton solver taking onlyatol's size from Python, refusing a model without algebraic states, and solving a DAE's algebraic states at its differential states.Merge Danger
Door: two-way.
create_rust_solver_group's signature changes, but it is pybammsolvers API from #5961, which no pybammsolvers release has shipped (0.13.0 predates it).Blast Radius: IDAKLU on rust models. A pybamm-core whose table is shorter than the one pybammsolvers reads is refused before any call, as the ABI header already does, so the two extensions must be built from one tree (
rust_idaklu_build.mdsays so).Type of change
Internal refactor: no changelog fragment.
Key checklist
pre-commit runcargo test --all-features, clippy over every feature combination with-D warnings, and the 1.89 MSRV checkRust 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 expressions;pybamm.rustexceptions, array-likes, threads and Ctrl-Cpybamm.rust.inspection; every tape, Jacobian and trajectory derived in one place"rust"as the defaultconvert_to_format