Skip to content

feat!: default convert_to_format to rust - #5966

Open
BradyPlanden wants to merge 1 commit into
stack/10-diffsol-solverfrom
stack/11-default-rust
Open

BradyPlanden wants to merge 1 commit into
stack/10-diffsol-solverfrom
stack/11-default-rust

Conversation

@BradyPlanden

@BradyPlanden BradyPlanden commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

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 with model.convert_to_format = "casadi". With the rest of the stack:

  • the default IDAKLUSolver solves and reads rust models in Rust;

  • ScipySolver, AlgebraicSolver and EIS evaluate them through compiled functions;

  • CasadiSolver and CasadiAlgebraicSolver convert 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' DeprecationWarning stays the one warning a default model sees.

  • Serialisation: saving falls back to the default format, and a file saved without a convert_to_format key loads as "rust".

  • Tests:

    • Tests that exercise CasADi on purpose pin "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_inputs keeps covering CasADi with fewer solvers than threads.
    • standard_output_tests raises its absolute tolerance from 2e-14 to 5e-14, since round-off differs by backend.
  • Docs:

    • A new user guide page, user_guide/rust_backend.rst, covers choosing the backend, its differences from CasADi, DiffsolSolver's output times and Hermite reads, and adding a new expression type.
    • The multithreading notebook gains a prose section on num_threads across the backends.
    • rust_idaklu_build.md and the pybamm-rust README point to the guide.

What raises on the Rust backend:

  • IDAKLUSolver raises SolverError for sensitivities with respect to an input of width above 1, and solves with num_solvers equal to num_threads, as the guide says.
  • return_jacp_stacked and TensorField output variables also raise SolverError.
  • A symbol that cannot be lowered raises TypeError or NotImplementedError, and an interpolant table Rust refuses raises ModelError.
  • There is no automatic fallback to CasADi.

Performance

heatmap_light sweep_drive_cycle_light sweep_output_drive_cycle_light

A release needs pybammsolvers 0.12.0 on PyPI (#5961) and the platform wheels from #5958.

Type of change

Breaking change, under ## Breaking changes in CHANGELOG.md, with the migration note "Set model.convert_to_format = "casadi" to restore the previous backend."

Key checklist

  • No style issues: pre-commit run
  • Unit tests pass (N), as do the integration tests (N)
  • The documentation builds: nox -s doctests
  • Tests: the existing suites run on the Rust default, and the tests listed above pin "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 format
Rust execution engine stack: proposal #5667, showcase #5732

Each PR is one commit on the one above it.

# PR Adds
0 #5954 Function.create_copy keeps the function's class
0b #5955 CasADi's RegPower and uniform-grid interpolant lookups match evaluate
1 #5956 pybamm-core: expression graph, typed IR, interpreters, forward-mode AD
2 #5957 pybamm-core: CompiledModel, coloured Jacobians, the C ABI
3 #5958 pybamm.rust bindings, built into the pybamm wheel
4 #5959 Symbol.to_rust
5 #5960 convert_to_format = "rust" for ScipySolver, AlgebraicSolver and EIS
6 #5961 pybammsolvers: IDAKLU over the C ABI
7 #5962 IDAKLUSolver on rust models
8 #5963 variables and sensitivities read in Rust
9 #5964 pybamm-core: diffsol DAE solver
10 #5965 pybamm.DiffsolSolver
11 #5966 "rust" as the default convert_to_format ← this PR

@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.14%. Comparing base (b9bb622) to head (fd167d2).

Additional details and impacted files
@@                     Coverage Diff                     @@
##           stack/10-diffsol-solver    #5966      +/-   ##
===========================================================
- Coverage                    98.15%   98.14%   -0.02%     
===========================================================
  Files                          354      354              
  Lines                        37278    37279       +1     
===========================================================
- Hits                         36592    36589       -3     
- Misses                         686      690       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

BaseModel defaults to "rust"; CasADi-specific tests pin their format;
user guide and multithreading docs describe the rust backend.
@BradyPlanden

Copy link
Copy Markdown
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.

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

ProjectPyBaMM
Branchstack/11-default-rust
Testbedbare-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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant