Skip to content

Commit 4c47029

Browse files
authored
Bugfix: IDAKLU output variables with Experiments (#4753)
* save computed variables in cycle solutions * Add test for computed variables in cycle solutions * switch assert_array_almost_equal to assert_allclose for test_idaklu file * Trigger RTD build
1 parent 5de71ec commit 4c47029

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/pybamm/solvers/solution.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,10 @@ def make_cycle_solution(
11301130
sum_sols.all_yps,
11311131
sum_sols.variables_returned,
11321132
)
1133+
1134+
if sum_sols.variables_returned:
1135+
cycle_solution._variables = sum_sols._variables
1136+
11331137
cycle_solution._all_inputs_casadi = sum_sols.all_inputs_casadi
11341138
cycle_solution._sub_solutions = sum_sols.sub_solutions
11351139

tests/integration/test_solvers/test_idaklu.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,23 +133,23 @@ def test_interpolation(self):
133133
t_combined = np.concatenate((sol3.t, t_interp_dense))
134134
t_combined = np.unique(t_combined)
135135
t_combined.sort()
136-
np.testing.assert_array_almost_equal(sol3.t, t_combined)
136+
np.testing.assert_allclose(sol3.t, t_combined)
137137

138138
# 4. sparse t_eval + sparse t_interp
139139
sol4 = solver.solve(
140140
model_disc, t_eval_sparse, t_interp=t_interp_sparse, inputs=inputs
141141
)
142-
np.testing.assert_array_almost_equal(sol4.t, np.array([t0, tf]))
142+
np.testing.assert_allclose(sol4.t, np.array([t0, tf]))
143143

144144
sols = [sol1, sol2, sol3, sol4]
145145
for sol in sols:
146146
# test that y[0] = to true solution
147147
true_solution = a_value * sol.t
148-
np.testing.assert_array_almost_equal(sol.y[0], true_solution)
148+
np.testing.assert_allclose(sol.y[0], true_solution)
149149

150150
# test that y[1:3] = to true solution
151151
true_solution = b_value * sol.t
152-
np.testing.assert_array_almost_equal(sol.y[1:3], true_solution)
152+
np.testing.assert_allclose(sol.y[1:3], true_solution)
153153

154154
def test_with_experiments(self):
155155
summary_vars = []
@@ -195,10 +195,16 @@ def test_with_experiments(self):
195195
np.testing.assert_array_equal(
196196
sols[0]["Pressure [Pa]"].data, sols[1]["Pressure [Pa]"].data
197197
)
198-
np.testing.assert_array_almost_equal(
198+
np.testing.assert_allclose(
199199
sols[0]["Voltage [V]"].data, sols[1]["Voltage [V]"].data
200200
)
201201

202202
# check summary variables are the same if output variables are specified
203203
for var in model.summary_variables:
204204
assert summary_vars[0][var] == summary_vars[1][var]
205+
206+
# check variables are accessible for each cycle
207+
np.testing.assert_allclose(
208+
sols[0].cycles[-1]["Current [A]"].data,
209+
sols[1].cycles[-1]["Current [A]"].data,
210+
)

0 commit comments

Comments
 (0)