Skip to content

Commit fcf3821

Browse files
1D+ sensitivities error with IDAKLU output_variables (#5118)
* Adds a test checking for sensitivitiy equality between output_variables=True/False * Test with 0D, 1D and 2D variables which should all have non-zero sensitivities * Update changelog --------- Co-authored-by: Marc Berliner <[email protected]>
1 parent 78fe787 commit fcf3821

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Fix a bug in setting initial stoichiometries where the reference temperature was used instead of the initial temperature. ([#5189](https://github.com/pybamm-team/PyBaMM/pull/5189))
1313
- Fix a bug in the calculation of "Bulk" OCP terms in hysteresis models ([#5169](https://github.com/pybamm-team/PyBaMM/pull/5169))
1414
- Fixed a bug where the final duration of a drive cycle would not be inferred correctly. ([#5153](https://github.com/pybamm-team/PyBaMM/pull/5153))
15+
- Fixes a bug where sensitivities for 1D+ variables calculated using the `output_variables` options were incorrect ([#5118](https://github.com/pybamm-team/PyBaMM/pull/5118))
1516

1617
# [v25.8.0](https://github.com/pybamm-team/PyBaMM/tree/v25.8.0) - 2025-08-04
1718

tests/unit/test_solvers/test_idaklu_solver.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -942,9 +942,10 @@ def test_with_output_variables_and_sensitivities(self):
942942

943943
# Use a selection of variables of different types
944944
output_variables = [
945-
"Voltage [V]",
946-
"Time [min]",
947-
"x [m]",
945+
"Voltage [V]", # 0D
946+
"x [m]", # 1D, empty sensitivities
947+
"Negative electrode potential [V]", # 1D
948+
"Negative particle concentration [mol.m-3]", # 2D
948949
"Throughput capacity [A.h]", # ExplicitTimeIntegral
949950
]
950951

@@ -993,6 +994,17 @@ def test_with_output_variables_and_sensitivities(self):
993994
== sol_all[varname].sensitivities["all"].shape
994995
)
995996

997+
# test each of the sensitivity calculations match
998+
for varname in output_variables:
999+
for key in input_parameters:
1000+
np.testing.assert_allclose(
1001+
sol[varname].sensitivities[key],
1002+
sol_all[varname].sensitivities[key],
1003+
rtol=tol,
1004+
atol=tol,
1005+
err_msg=f"Failed for '{varname}', sensitivity '{key}'",
1006+
)
1007+
9961008
def test_with_output_variables_and_event_termination(self):
9971009
model = pybamm.lithium_ion.DFN()
9981010
parameter_values = pybamm.ParameterValues("Chen2020")

0 commit comments

Comments
 (0)