Skip to content

Commit 0c6c292

Browse files
authored
Merge branch 'develop' into develop
2 parents 6387b88 + 1c1dd75 commit 0c6c292

26 files changed

+580
-138
lines changed

.github/workflows/run_periodic_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
strategy:
3131
fail-fast: false
3232
matrix:
33-
os: [ ubuntu-latest, macos-13, macos-14, windows-latest ]
33+
os: [ ubuntu-latest, macos-13, macos-latest, windows-latest ]
3434
python-version: ["3.10", "3.11", "3.12"]
3535
name: Tests (${{ matrix.os }} / Python ${{ matrix.python-version }})
3636

@@ -48,7 +48,7 @@ jobs:
4848
sudo apt-get install libopenblas-dev texlive-latex-extra dvipng
4949
5050
- name: Install macOS system dependencies
51-
if: matrix.os == 'macos-13' || matrix.os == 'macos-14'
51+
if: matrix.os == 'macos-13' || matrix.os == 'macos-latest'
5252
env:
5353
HOMEBREW_NO_INSTALL_CLEANUP: 1
5454
HOMEBREW_NO_AUTO_UPDATE: 1

.github/workflows/scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ jobs:
6565
# Upload the results to GitHub's code scanning dashboard (optional).
6666
# Commenting out will disable upload of results to your repo's Code Scanning dashboard
6767
- name: "Upload to code-scanning"
68-
uses: github/codeql-action/upload-sarif@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
68+
uses: github/codeql-action/upload-sarif@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
6969
with:
7070
sarif_file: results.sarif

.github/workflows/test_on_push.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
strategy:
4949
fail-fast: false
5050
matrix:
51-
os: [ubuntu-latest, macos-13, macos-14, windows-latest]
51+
os: [ubuntu-latest, macos-13, macos-latest, windows-latest]
5252
python-version: ["3.10", "3.11", "3.12"]
5353
name: Tests (${{ matrix.os }} / Python ${{ matrix.python-version }})
5454

@@ -74,7 +74,7 @@ jobs:
7474
sudo apt-get install libopenblas-dev texlive-latex-extra dvipng
7575
7676
- name: Install macOS system dependencies
77-
if: matrix.os == 'macos-13' || matrix.os == 'macos-14'
77+
if: matrix.os == 'macos-13' || matrix.os == 'macos-latest'
7878
env:
7979
HOMEBREW_NO_INSTALL_CLEANUP: 1
8080
HOMEBREW_NO_AUTO_UPDATE: 1

.pre-commit-config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ci:
44

55
repos:
66
- repo: https://github.com/astral-sh/ruff-pre-commit
7-
rev: "v0.12.0"
7+
rev: "v0.12.1"
88
hooks:
99
- id: ruff
1010
args: [--fix, --show-fixes]
@@ -44,7 +44,6 @@ repos:
4444
- id: sp-repo-review
4545

4646
- repo: https://github.com/woodruffw/zizmor-pre-commit
47-
rev: v1.9.0
47+
rev: v1.11.0
4848
hooks:
4949
- id: zizmor
50-
args: [--pedantic]

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
## Features
44

5+
- Creates `BaseProcessedVariable` to enable object combination when adding solutions together ([#5076](https://github.com/pybamm-team/PyBaMM/pull/5076))
56
- Added a `Constant` symbol for named constants. This is a subclass of `Scalar` and is used to represent named constants such as the gas constant. This avoids constants being simplified out when constructing expressions. ([#5070](https://github.com/pybamm-team/PyBaMM/pull/5070))
67
- Generalise `pybamm.DiscreteTimeSum` to allow it to be embedded in other expressions ([#5044](https://github.com/pybamm-team/PyBaMM/pull/5044))
78
- Adds `all` key-value pair to `output_variables` sensitivity dictionaries, accessible through `solution[var].sensitivities['all']`. Aligns shape with conventional solution sensitivities object. ([#5067](https://github.com/pybamm-team/PyBaMM/pull/5067))
9+
- Add support for `output_variables` to `pybamm.DiscreteTimeSum` and `pybamm.ExplicitTimeIntegral` expressions. ([#5071](https://github.com/pybamm-team/PyBaMM/pull/5071))
810

911
## Bug fixes
1012

13+
- Fixed a bug that ignored the default duration of drive cycles for `CRate` steps and a bug that overwrote custom `period` arguments for drive cycles. ([#5090](https://github.com/pybamm-team/PyBaMM/pull/5090))
1114
- Converts sensitivities to numpy objects, fixing bug in `DiscreteTimeSum` sensitivity calculation ([#5037](https://github.com/pybamm-team/PyBaMM/pull/5037))
1215
- Raises error if `pybamm.Interpolant` given 1D x values that are not strictly increasing ([#5061](https://github.com/pybamm-team/PyBaMM/pull/5061))
1316
- Removes the discontinuity caused by a Heaviside (which is a function of time) when a solver is called with a non-zero initial time ([#5075](https://github.com/pybamm-team/PyBaMM/pull/5075)).

src/pybamm/experiment/step/base_step.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,12 @@ def __init__(
147147
pybamm.t - pybamm.InputParameter("start time"),
148148
name="Drive Cycle",
149149
)
150-
self.period = np.diff(t).min()
150+
if period is None:
151+
# Infer the period from the drive cycle
152+
self.period = np.diff(t).min()
153+
else:
154+
self.period = _convert_time_to_seconds(period)
155+
151156
elif is_python_function:
152157
t = pybamm.t - pybamm.InputParameter("start time")
153158
self.value = value(t)
@@ -272,6 +277,12 @@ def __eq__(self, other):
272277
def __hash__(self):
273278
return hash(self.basic_repr())
274279

280+
def _default_timespan(self, value):
281+
"""
282+
Default timespan for the step is one day (24 hours).
283+
"""
284+
return 24 * 3600
285+
275286
def default_duration(self, value):
276287
"""
277288
Default duration for the step is one day (24 hours) or the duration of the
@@ -281,7 +292,7 @@ def default_duration(self, value):
281292
t = value[:, 0]
282293
return t[-1]
283294
else:
284-
return 24 * 3600 # one day in seconds
295+
return self._default_timespan(value)
285296

286297
@staticmethod
287298
def default_period():

src/pybamm/experiment/step/steps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def __init__(self, value, **kwargs):
157157
def current_value(self, variables):
158158
return self.value * pybamm.Parameter("Nominal cell capacity [A.h]")
159159

160-
def default_duration(self, value):
160+
def _default_timespan(self, value):
161161
# "value" is C-rate, so duration is "1 / value" hours in seconds
162162
# with a 2x safety factor
163163
return 1 / abs(value) * 3600 * 2

src/pybamm/expression_tree/unary_operators.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,10 @@ def _from_json(cls, snippet: dict):
10931093
def _unary_new_copy(self, child, perform_simplifications=True):
10941094
return self.__class__(child, self.initial_condition)
10951095

1096+
def _unary_evaluate(self, child):
1097+
# return result of evaluating the child, we'll only implement the sum once the model is solved (in pybamm.ProcessedVariable)
1098+
return child
1099+
10961100
def is_constant(self):
10971101
return False
10981102

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from __future__ import annotations
2+
3+
import abc
4+
5+
import pybamm
6+
7+
8+
class BaseProcessedVariable(abc.ABC):
9+
"""
10+
Shared API for both 'on-demand' and 'computed' processed variables.
11+
"""
12+
13+
@abc.abstractmethod
14+
def __call__(self, **coords): ...
15+
16+
@abc.abstractmethod
17+
def as_computed(self) -> pybamm.ProcessedVariableComputed: ...
18+
19+
def update(
20+
self,
21+
other: BaseProcessedVariable,
22+
new_sol: pybamm.Solution,
23+
) -> pybamm.ProcessedVariableComputed:
24+
"""
25+
Return a *new* CPV that is `self` followed by `other`.
26+
Works no matter which concrete types we start with.
27+
"""
28+
return self.as_computed()._concat(other.as_computed(), new_sol)

src/pybamm/solvers/base_solver.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,22 @@ def set_up(self, model, inputs=None, t_eval=None, ics_only=False):
260260
self.computed_var_fcns = {}
261261
self.computed_dvar_dy_fcns = {}
262262
self.computed_dvar_dp_fcns = {}
263+
self._time_integral_vars = {}
263264
for key in self.output_variables:
264-
# ExplicitTimeIntegral's are not computed as part of the solver and
265-
# do not need to be converted
266-
if isinstance(model.variables_and_events[key], pybamm.ExplicitTimeIntegral):
267-
continue
265+
# Check for any ExplicitTimeIntegral or DiscreteTimeSum variables
266+
processed_time_integral = (
267+
pybamm.ProcessedVariableTimeIntegral.from_pybamm_var(
268+
model.variables_and_events[key],
269+
model.len_rhs_and_alg,
270+
)
271+
)
272+
# We will evaluate the sum node in the solver and sum it afterwards
273+
if processed_time_integral is None:
274+
var = model.variables_and_events[key]
275+
else:
276+
var = processed_time_integral.sum_node
277+
self._time_integral_vars[key] = processed_time_integral
278+
268279
# Generate Casadi function to calculate variable and derivates
269280
# to enable sensitivites to be computed within the solver
270281
(
@@ -273,7 +284,7 @@ def set_up(self, model, inputs=None, t_eval=None, ics_only=False):
273284
self.computed_dvar_dp_fcns[key],
274285
_,
275286
) = process(
276-
model.variables_and_events[key],
287+
var,
277288
BaseSolver._wrangle_name(key),
278289
vars_for_processing,
279290
use_jacobian=True,
@@ -1470,7 +1481,7 @@ def _check_empty_model(self, model):
14701481

14711482
def get_platform_context(self, system_type: str):
14721483
# Set context for parallel processing depending on the platform
1473-
if system_type.lower() in ["linux", "darwin"]:
1484+
if system_type.lower() in ["linux"]:
14741485
return "fork"
14751486
return "spawn"
14761487

0 commit comments

Comments
 (0)