Skip to content

Commit

Permalink
fix: simulate_dynamic_system(display_progress_bar=False)
Browse files Browse the repository at this point in the history
  • Loading branch information
CallumJHays committed Oct 10, 2022
1 parent da60844 commit 5108af7
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions mathpad/simulate_dynamic_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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...")

Expand Down

0 comments on commit 5108af7

Please sign in to comment.