Skip to content

Commit

Permalink
Set iterator based upon tqdm
Browse files Browse the repository at this point in the history
  • Loading branch information
arjxn-py committed Nov 13, 2023
1 parent a5d2573 commit fd57f0f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pybamm/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,10 @@ def solve(
Additional key-word arguments passed to `solver.solve`.
See :meth:`pybamm.BaseSolver.solve`.
"""
tqdm = have_optional_dependency("tqdm")
try:
tqdm = have_optional_dependency("tqdm")
except ModuleNotFoundError:
tqdm = False
# Setup
if solver is None:
solver = self._solver
Expand Down Expand Up @@ -727,13 +730,18 @@ def solve(
# Update _solution
self._solution = current_solution

for cycle_num, cycle_length in enumerate(
# tqdm is the progress bar.
tqdm.tqdm(
if tqdm:
iterator = tqdm.tqdm(
self.experiment.cycle_lengths,
disable=(not showprogress),
desc="Cycling",
),
)
else:
iterator = self.experiment.cycle_lengths

for cycle_num, cycle_length in enumerate(
# tqdm is the progress bar.
iterator,
start=1,
):
logs["cycle number"] = (
Expand Down

0 comments on commit fd57f0f

Please sign in to comment.