Symbolic experiment step settings and terminations - #5744
Open
MarcBerliner wants to merge 6 commits into
Open
Conversation
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>
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
`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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
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
Experiment steps can take a
pybamm.Parameterorpybamm.InputParameterforduration,period,temperatureand 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.SymbolicTerminationterminates a step on any inequality over model variables, e.g.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.resolveis the one placeCoupledVariables are resolved, replacing the copies inBaseModelandDiscretisation.The custom-experiments notebook's anode-potential cut-off is now a one-line inequality.
Type of change
Key checklist
nox -s pre-commitnox -s testsCHANGELOG.md, API docs, example notebook🤖 Generated with Claude Code