Skip to content

Commit 6ff7848

Browse files
MarcBerlineragriyakhetarpalswastim01valentinsulzercnaples79
authored
Observe custom variables after solving + faster simulation build time (pybamm-team#5308)
* Don't be too strict with func_args longer than symbol.children * Add a test * Add support for uniform grid sizing across subdomains (pybamm-team#720) (pybamm-team#5253) Co-authored-by: Valentin Sulzer <valentinsulzer@hotmail.com> * Fix typo in Butler-Volmer equation docstring (pybamm-team#5279) * fix bug with bulk ocp lithiation (pybamm-team#5280) * doc: fix typo in concentration description in notebook (pybamm-team#5284) * 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: instruct uv to install into system for CI (pybamm-team#5288) * Fix `InputParameter` serialisation (pybamm-team#5289) * fix `InputParameter` serialisation * Update CHANGELOG.md * Bugfix: inputs for `initial_conditions_from` scale evaluation (pybamm-team#5285) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * Add `silence_sundials_errors` solver option (pybamm-team#5290) * feat: add`silence_sundial_warnings` solver option * refactor: `silence_sundials_warnings` -> `silence_sundials_errors` * Update C-Rate current for changing nominal capacity (pybamm-team#5286) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * Update `IDAKLUSolver` error handling (pybamm-team#5291) * 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 * revive `SymbolReplacer` * add `VariableReplacementMap` * Create replace_symbols.rst * Update index.rst * cleanup * attach `parameter_values` to model for lazy post-processing * update `model.parameter_values` serialization * Update test_serialisation.py * Update test_parameter_values.py * add `observe` to solution for lazy evaluation of discretized symbols * Update test_solution.py * style * Update CHANGELOG.md * fix docstrings * docs * docs2 * Update replace_symbols.py * Update replace_symbols.py * remove `SymbolReplacer` * add slots to `SpatialMethod` for memory * add `SymbolProcessor` for `BaseModel` symbol eval * add `ModelSolutionObservability` enums for `BaseModel` * parameter_values: delay variable processing * fix stale symbol id: use `scale` and `reference` setters * discretisation delayed var processing, don't overwrite `model.variables` * pass `delayed_variable_processing` args through `process_model` * add `DUMMY_INPUT_PARAMETER_VALUE` const * Update __init__.py * Update index.rst * Delete replace_symbols.py * update symbol `scale` and `reference` setters * update variable hash * explicit `_variables_processed` base model attribute * use `get_processed_variable_or_event` getter * copy model in `Simulation` * disable observability with `output_variables` * delay variable processing in `Simulation` build * add `Solution.observe(symbol)` * update serialization * update examples * Update CONTRIBUTING.md * Update CHANGELOG.md * add observe tests * update serialization tests * Update test_base_model.py * update symbol processor getters * add model observability tests * update symbol and base variable id setters * Update symbol_processor.py * Update CHANGELOG.md * fix model serialization notebook * Update symbol_processor.py * remove unused serialisation methods * remove debug statement * update observe test comments * add observe test failure for new parameters * remove `_solution_observable` from custom model serialization * fix observe test error * set `DUMMY_INPUT_PARAMETER_VALUE = np.nan` to make errors more obvious --------- Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Co-authored-by: Swasti Mishra <140950062+swastim01@users.noreply.github.com> Co-authored-by: Valentin Sulzer <valentinsulzer@hotmail.com> Co-authored-by: Chase Naples <cnaples79@gmail.com> Co-authored-by: Robert Timms <43040151+rtimms@users.noreply.github.com> Co-authored-by: Gregor Decristoforo <gregor.decristoforo@gmail.com> Co-authored-by: Pip Liggins <philippa.liggins@dtc.ox.ac.uk> Co-authored-by: Brady Planden <55357039+BradyPlanden@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent a0b2614 commit 6ff7848

40 files changed

Lines changed: 2657 additions & 724 deletions

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Features
44

5+
- Reduced the time to build `Simulation`s by creating a post-processing step for variables. ([#5308](https://github.com/pybamm-team/PyBaMM/pull/5308))
6+
- Adds the ability to observe custom variables from a `Solution` object using `Solution.observe(symbol)`. ([#5308](https://github.com/pybamm-team/PyBaMM/pull/5308))
57
- Added inverse kinetics for linear kinetics. ([#5303](https://github.com/pybamm-team/PyBaMM/pull/5303))
68
- Adds `silence_sundials_errors` IDAKLU solver option with `default=False` to match historical output. ([#5290](https://github.com/pybamm-team/PyBaMM/pull/5290))
79

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ This also means that, if you can't fix the bug yourself, it will be much easier
329329
```python3
330330
pybamm.set_logging_level("DEBUG")
331331
```
332-
6. In models that inherit from `pybamm.BaseBatteryModel` (i.e. any battery model), you can use `self.process_parameters_and_discretise` to process a symbol and see what it will look like.
332+
6. In models that inherit from `pybamm.BaseBatteryModel` (i.e. any battery model), you can use `self.process_symbol` to process a symbol with a fully built model to see what it will look like.
333333

334334
### Profiling
335335

docs/source/api/models/base_models/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Base Models
77
base_model
88
base_battery_model
99
event
10+
symbol_processor
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Symbol Processor
2+
================
3+
4+
.. autoclass:: pybamm.SymbolProcessor
5+
:members:

docs/source/examples/notebooks/getting_started/tutorial-6-managing-simulation-outputs.ipynb

Lines changed: 668 additions & 82 deletions
Large diffs are not rendered by default.

docs/source/examples/notebooks/models/pouch-cell-model.ipynb

Lines changed: 21 additions & 39 deletions
Large diffs are not rendered by default.

docs/source/examples/notebooks/solution-data-and-processed-variables.ipynb

Lines changed: 254 additions & 76 deletions
Large diffs are not rendered by default.

examples/scripts/compare_comsol/compare_comsol_DFN.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,13 @@ def get_interp_fun(variable_name, domain):
112112
"Negative particle surface concentration [mol.m-3]": comsol_c_n_surf,
113113
"Electrolyte concentration [mol.m-3]": comsol_c_e,
114114
"Positive particle surface concentration [mol.m-3]": comsol_c_p_surf,
115-
"Current [A]": pybamm_model.variables["Current [A]"],
115+
"Current [A]": pybamm_model.get_processed_variable("Current [A]"),
116116
"Negative electrode potential [V]": comsol_phi_n,
117117
"Electrolyte potential [V]": comsol_phi_e,
118118
"Positive electrode potential [V]": comsol_phi_p,
119119
"Voltage [V]": comsol_voltage,
120120
}
121+
comsol_model.update_processed_variables(comsol_model.variables)
121122

122123
# Make new solution with same t and y
123124
# Update solution scales to match the pybamm model

src/pybamm/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
from .expression_tree.operations.serialise import Serialise,ExpressionFunctionParameter
6262

6363
# Model classes
64-
from .models.base_model import BaseModel
64+
from .models.base_model import BaseModel, ModelSolutionObservability
65+
from .models.symbol_processor import SymbolProcessor
6566
from .models.event import Event
6667
from .models.event import EventType
6768

0 commit comments

Comments
 (0)