Skip to content

Add DiffSL export functionality#5370

Open
martinjrobins wants to merge 35 commits intomainfrom
i5262-diffsl-export
Open

Add DiffSL export functionality#5370
martinjrobins wants to merge 35 commits intomainfrom
i5262-diffsl-export

Conversation

@martinjrobins
Copy link
Contributor

@martinjrobins martinjrobins commented Feb 2, 2026

Description

This PR adds the ability to export PyBaMM models to the DiffSL format, enabling models to be used with the DiffSL solver ecosystem.

Note this was started before the move from develop to main, in the process some commits got added, but these don't affect the diff

Changes

  • New DiffSLExport class in src/pybamm/expression_tree/operations/diffsl.py:

    • Converts PyBaMM models to DiffSL format
  • Unit and integration tests:

    • Added tests for ODE export (test_ode)
    • Added tests for heat equation export (test_heat_equation)
    • Integration tests for SPM, SPMe, and DFN models

Related Issues

Closes #5262

Checklist

  • Tests added
  • Documentation/docstrings updated (inline in code)
  • CHANGELOG updated
  • Code follows style guidelines

agriyakhetarpal and others added 28 commits November 13, 2025 09:12
Co-authored-by: Valentin Sulzer <valentinsulzer@hotmail.com>
* Fix typo in concentration description in notebook

* Add CHANGELOG.md entry for typo fix

* Remove unneccesary changelog entry

Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>

---------

Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
* fix `InputParameter` serialisation

* Update CHANGELOG.md
…-fix

Don't be too strict with func_args longer than symbol.children
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* feat: add`silence_sundial_warnings` solver option

* refactor: `silence_sundials_warnings` -> `silence_sundials_errors`
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* raise `SolverError` at failure to init sundials

* Update simulation.py

* Update idaklu_solver.py

* reuse `pybammsolvers` error messages

* Update test_idaklu_solver.py

* bump `pybammsolvers`

* Update CHANGELOG.md

* Update CHANGELOG.md

Update CHANGELOG.md
Co-authored-by: martinjrobins <martinjrobins@gmail.com>
@martinjrobins martinjrobins requested a review from a team as a code owner February 2, 2026 09:32
@martinjrobins martinjrobins changed the title Add DiffSL export functionality with significant digits formatting Add DiffSL export functionality Feb 2, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds the ability to export discretized PyBaMM models to the DiffSL format, enabling integration with the DiffSL solver ecosystem (specifically pydiffsol). The implementation converts PyBaMM expression trees to DiffSL code that can be compiled and solved using diffsol's ODE/DAE solvers.

Changes:

  • New DiffSLExport class for converting PyBaMM models to DiffSL format
  • Unit tests covering basic ODE and heat equation (PDE) exports
  • Integration tests validating exports against actual pydiffsol solver for SPM, SPMe, and DFN battery models

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
src/pybamm/expression_tree/operations/diffsl.py Core implementation of DiffSL export functionality with methods to convert PyBaMM symbols, vectors, and matrices to DiffSL format
tests/unit/test_expression_tree/test_operations/test_diffsl_export.py Unit tests for basic ODE and PDE model exports
tests/integration/test_solvers/test_diffsl_export.py Integration tests validating DiffSL export against pydiffsol solver for multiple battery models
src/pybamm/__init__.py Export of DiffSLExport class to public API
pyproject.toml Addition of pydiffsol as dev dependency for testing
CHANGELOG.md Documentation of new feature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.05%. Comparing base (c9121be) to head (0ddf5e0).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5370      +/-   ##
==========================================
+ Coverage   98.03%   98.05%   +0.02%     
==========================================
  Files         327      328       +1     
  Lines       28690    29050     +360     
==========================================
+ Hits        28126    28486     +360     
  Misses        564      564              

☔ View full report in Codecov by Sentry.
📢 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.

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.

diffsl export

10 participants