Skip to content

Loss function solver - #5652

Open
martinjrobins wants to merge 16 commits into
mainfrom
loss_function_solver
Open

Loss function solver#5652
martinjrobins wants to merge 16 commits into
mainfrom
loss_function_solver

Conversation

@martinjrobins

Copy link
Copy Markdown
Contributor

Description

Adds a LossSolver class that takes a pybamm simulation instance and constructs a loss function which is encoded as a pybamm.Symbol instance over a set duration provided by the user. The loss function can either contain a pybamm.ExplicitTimeIntegral, in which case the loss function is a continuous integral over the simulation trajectory, or a pybamm.DiscreteTimeSum, in which case the loss function is a discrete sum defined at a series of times.

Under the hood this uses pydiffsol (https://github.com/alexallmont/pydiffsol) as the solver, so any solver instance on the Simulation is ignored, except for the predict method, which uses the original Simulation solver. This is mainly provided as a convenience method.

Fixes #5559

Type of change

Add an entry under # [Unreleased] in CHANGELOG.md, in one of ## Breaking changes, ## Deprecated, ## Features, or ## Bug fixes (include PR number; breaking and deprecation entries need a one-line migration note). Internal-only PRs — refactor, docs, CI, tests — can skip this. See RELEASE.md for the full policy.

Important checks:

Please confirm the following before marking the PR as ready for review:

  • No style issues: nox -s pre-commit
  • All tests pass: nox -s tests
  • The documentation builds: nox -s doctests
  • Code is commented for hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@martinjrobins
martinjrobins requested a review from a team as a code owner July 15, 2026 12:49
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.22222% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.12%. Comparing base (9e97e94) to head (a93876a).

Files with missing lines Patch % Lines
...mm/src/pybamm/expression_tree/operations/diffsl.py 90.47% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5652      +/-   ##
==========================================
- Coverage   98.12%   98.12%   -0.01%     
==========================================
  Files         339      340       +1     
  Lines       32079    32284     +205     
==========================================
+ Hits        31477    31678     +201     
- Misses        602      606       +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.

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.

pybamm loss function solver

1 participant