Skip to content

Commit

Permalink
* #3690 fix issue with skipped steps
Browse files Browse the repository at this point in the history
* #3690 changelog

* #3690 add test
  • Loading branch information
rtimms authored and Saransh-cpp committed Jan 16, 2024
1 parent e0d8fce commit a080257
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pybamm/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,20 @@ def solve(

steps.append(step_solution)

cycle_solution = cycle_solution + step_solution
# If there haven't been any successful steps yet in this cycle, then
# carry the solution over from the previous cycle (but
# `step_solution` should still be an EmptySolution so that in the
# list of returned step solutions we can see which steps were
# skipped)
if (
cycle_solution is None
and isinstance(step_solution, pybamm.EmptySolution)
and not isinstance(current_solution, pybamm.EmptySolution)
):
cycle_solution = current_solution.last_state
else:
cycle_solution = cycle_solution + step_solution

current_solution = cycle_solution

callbacks.on_step_end(logs)
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_experiments/test_simulation_with_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,25 @@ def test_run_experiment_skip_steps(self):
decimal=5,
)

def test_skipped_step_continuous(self):
model = pybamm.lithium_ion.SPM({"SEI": "solvent-diffusion limited"})
experiment = pybamm.Experiment(
[
("Rest for 24 hours (1 hour period)",),
(
"Charge at C/3 until 4.1 V",
"Hold at 4.1V until C/20",
"Discharge at C/3 until 2.5 V",
),
]
)
sim = pybamm.Simulation(model, experiment=experiment)
sim.solve(initial_soc=1)
np.testing.assert_array_almost_equal(
sim.solution.cycles[0].last_state.y.full(),
sim.solution.cycles[1].steps[-1].first_state.y.full(),
)

def test_all_empty_solution_errors(self):
model = pybamm.lithium_ion.SPM()
parameter_values = pybamm.ParameterValues("Chen2020")
Expand Down

0 comments on commit a080257

Please sign in to comment.