Skip to content

Commit

Permalink
add cycle number as a key (#4798)
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer authored Jan 24, 2025
1 parent 3d0d6ff commit f608792
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/pybamm/solvers/summary_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(
self.user_inputs = user_inputs or {}
self.esoh_solver = esoh_solver
self._variables = {} # Store computed variables
self.cycle_number = None
self.cycle_number = np.array([])

model = solution.all_models[0]
self._possible_variables = model.summary_variables # minus esoh variables
Expand Down Expand Up @@ -122,6 +122,8 @@ def __getitem__(self, key: str) -> float | list[float]:
if key in self._variables:
# return it if it exists
return self._variables[key]
elif key == "Cycle number":
return self.cycle_number
elif key not in self.all_variables:
# check it's listed as a summary variable
raise KeyError(f"Variable '{key}' is not a summary variable.")
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_solvers/test_summary_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,7 @@ def test_get_esoh_cycle_summary_vars(self):
sol = sim.solve()

assert len(sol.summary_variables.cycles) == 10
assert sol.summary_variables["Cycle number"][0] == 1
assert sol.summary_variables["Cycle number"][9] == 10
assert len(sol.summary_variables["x_100"]) == 10
assert np.isclose(sol.summary_variables["x_100"][0], 0.9493)

0 comments on commit f608792

Please sign in to comment.