Implement voltage cutoffs#14
Draft
DavidMStraub wants to merge 4 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds automatic simulation termination when PyBaMM cell voltage crosses configured over-/undervoltage cutoffs, leveraging PathSim’s new StopSimulation exception so users don’t need to wire termination logic manually.
Changes:
- Raise
StopSimulationfrom both continuous (_CellBase.func_alg) and co-sim (_CoSimCellBase._discrete_step) cell blocks when voltage exceeds cutoffs. - Improve co-simulation initial outputs to compute t=0 open-circuit outputs via CasADi evaluation (instead of placeholder zeros).
- Add termination-focused tests and temporarily pin
pathsimto a specific Git commit that includesStopSimulation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/pathsim_batt/cells/pybamm_cell.py |
Introduces voltage cutoff extraction, termination via StopSimulation, and improved co-sim initial outputs. |
tests/cells/test_pybamm_cell.py |
Adds integration tests asserting simulations stop early at voltage cutoffs and that cutoff values match PyBaMM parameters. |
pyproject.toml |
Temporarily pins pathsim to a Git commit to access StopSimulation. |
Comments suppressed due to low confidence (1)
src/pathsim_batt/cells/pybamm_cell.py:229
- Same as above: direct indexing into
parameter_valuesfor voltage cut-offs can raiseKeyErrorfor custom/alternate parameter sets. Please add an explicit check with a clear error message (or fallback defaults) to keep the constructor failure mode predictable for API consumers.
self._model = model
self._parameter_values = _prepare_parameter_values(parameter_values)
self._v_lower = float(
self._parameter_values["Lower voltage cut-off [V]"]
)
self._v_upper = float(
self._parameter_values["Upper voltage cut-off [V]"]
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
src/pathsim_batt/cells/pybamm_cell.py:321
- Same as above: the stop condition uses
V = outputs[0], which relies on_pybamm_output_varsalways having terminal voltage at index 0. To avoid fragile ordering dependencies, fetch the terminal voltage by its PyBaMM variable name or add an explicit assertion/lookup so future subclasses can’t accidentally trigger cut-offs based on the wrong output.
V = outputs[0]
if V <= self._v_lower:
raise StopSimulation(f"undervoltage: V={V:.4f} V <= {self._v_lower} V")
if V >= self._v_upper:
raise StopSimulation(f"overvoltage: V={V:.4f} V >= {self._v_upper} V")
Collaborator
Author
|
Ready to merge once new PathSim version is released. Fixes #11. |
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.
This uses the new
StopSimulationexception to stop the simulation when hitting over- or undervoltage.Temporarily pins pathsim to
master; will merge when next version is released.