Skip to content

Symbolic experiment step settings and terminations - #5744

Open
MarcBerliner wants to merge 6 commits into
mainfrom
step-input-params
Open

Symbolic experiment step settings and terminations#5744
MarcBerliner wants to merge 6 commits into
mainfrom
step-input-params

Conversation

@MarcBerliner

Copy link
Copy Markdown
Member

Description

Experiment steps can take a pybamm.Parameter or pybamm.InputParameter for duration, period, temperature and the control value. The parameter pass runs once at setup (BaseStep.process_parameters); at solve time each setting is evaluated with the solver inputs, so one built model serves any value. Drive cycles repeat by wrapping the step time instead of being tiled to a fixed duration.

SymbolicTermination terminates a step on any inequality over model variables, e.g.

pybamm.step.c_rate(-1, termination=pybamm.CoupledVariable("Voltage [V]") > pybamm.InputParameter("V hold"))

The voltage, current and C-rate terminations are built on it, and every termination round-trips through Experiment.to_config/from_config, symbolic thresholds included. SymbolProcessor.resolve is the one place CoupledVariables are resolved, replacing the copies in BaseModel and Discretisation.

The custom-experiments notebook's anode-potential cut-off is now a one-line inequality.

Type of change

  • New feature (non-breaking change which adds functionality)

Key checklist

  • No style issues: nox -s pre-commit
  • All tests pass: nox -s tests
  • Documentation updated: CHANGELOG.md, API docs, example notebook

🤖 Generated with Claude Code

MarcBerliner and others added 3 commits September 3, 2026 16:06
Two things a step can now take as symbols, resolved at solve time rather
than at construction:

- `duration=pybamm.InputParameter("...")` (or any expression), evaluated
  against the inputs passed to `solve` to give the step's final time.
  Drive cycles support this too, because the interpolant no longer
  depends on the duration: instead of tiling the cycle out to a fixed
  duration, it wraps the step time with a modulo, which also means one
  built model now serves any duration.
- `termination=pybamm.CoupledVariable("Voltage [V]") > pybamm.InputParameter("V hold")`,
  or any inequality over model variables, input parameters and numbers.
  A heaviside is "left < right", so `left - right` is already in the
  event convention; the CoupledVariables in it are resolved against the
  model variables and the whole thing becomes a CustomTermination.

A symbolic duration round-trips through `to_config`/`from_config` via the
serialisation kernel. DiffSL export bakes the schedule into generated
code, so it raises for a symbolic duration.
Step duration, period, temperature and control value may be a
`pybamm.Parameter` or `pybamm.InputParameter`. The parameter pass runs
once at setup (`BaseStep.process_parameters`); solving evaluates each
setting with the solver inputs.

`SymbolicTermination` terminates a step on any inequality over model
variables. The voltage, current and C-rate terminations build on it,
and every termination serialises, symbolic thresholds included.

`SymbolProcessor.resolve` is the one place `CoupledVariable`s are looked
up, replacing the copies in `BaseModel` and `Discretisation`.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@MarcBerliner
MarcBerliner requested a review from a team as a code owner September 4, 2026 17:00
@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

MarcBerliner and others added 3 commits September 4, 2026 13:01
`None in _Direction` raises TypeError on 3.10, so compare against the
values. CurrentTermination's get_event_name matched the inherited one.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.01980% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.08%. Comparing base (78fe10a) to head (3e3304c).

Files with missing lines Patch % Lines
...mm/src/pybamm/expression_tree/operations/diffsl.py 72.72% 3 Missing ⚠️
...amm/src/pybamm/experiment/step/step_termination.py 97.82% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5744      +/-   ##
==========================================
- Coverage   98.21%   98.08%   -0.13%     
==========================================
  Files         340      340              
  Lines       32743    32770      +27     
==========================================
- Hits        32158    32142      -16     
- Misses        585      628      +43     

☔ 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.

1 participant