From 5108af7d9cdae43715d08694b7a31fd35eacec02 Mon Sep 17 00:00:00 2001 From: Callum J Hays Date: Mon, 10 Oct 2022 13:49:56 +1000 Subject: [PATCH] fix: simulate_dynamic_system(display_progress_bar=False) --- mathpad/simulate_dynamic_system.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/mathpad/simulate_dynamic_system.py b/mathpad/simulate_dynamic_system.py index cb910ec..5377f90 100644 --- a/mathpad/simulate_dynamic_system.py +++ b/mathpad/simulate_dynamic_system.py @@ -15,7 +15,10 @@ from mathpad.equation import Equation from mathpad.algebra import subs, SubstitutionMap, simplify from mathpad._quality_of_life import t -from tqdm.notebook import tqdm +try: + from tqdm.notebook import tqdm +except ImportError: + from tqdm import tqdm def simulate_dynamic_system( @@ -250,18 +253,22 @@ def step(x: float, state: np.ndarray): t_prev = 0 - with tqdm(total=x_f, leave=False) if display_progress_bar else None as pbar: - while integrator.status == "running": - msg = integrator.step() + pbar = tqdm(total=x_f, leave=False) if display_progress_bar else None - if integrator.status == "failed": - print(f"integration completed with failed status: {msg}") - break + while integrator.status == "running": + msg = integrator.step() + + if integrator.status == "failed": + print(f"integration completed with failed status: {msg}") + break - if pbar: - dt = integrator.t - t_prev - pbar.update(dt) - t_prev = integrator.t + if pbar: + dt = integrator.t - t_prev + pbar.update(dt) + t_prev = integrator.t + + if pbar: + pbar.close() _print_if(verbose, "Simulation finished. Plotting...")