Skip to content

Commit cb276de

Browse files
committed
Update sim counter for append mode
1 parent 3114f81 commit cb276de

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

rocketpy/simulation/monte_carlo.py

+16-19
Original file line numberDiff line numberDiff line change
@@ -693,20 +693,8 @@ def __run_simulation_worker(
693693
go_read_results[i].release()
694694

695695
# update user on progress
696-
average_time = (
697-
time() - sim_counter.get_intial_time()
698-
) / sim_counter.get_count()
699-
estimated_time = int(
700-
(sim_counter.get_n_simulations() - sim_counter.get_count())
701-
* average_time
702-
)
703-
704-
msg = f"Current iteration: {sim_idx:06d}"
705-
msg += f" | Average Time per Iteration: {average_time:.3f} s"
706-
msg += f" | Estimated time left: {estimated_time} s"
707-
708696
sim_counter.reprint(
709-
msg,
697+
sim_idx,
710698
end="\n",
711699
flush=False,
712700
)
@@ -1628,6 +1616,7 @@ def __init__(self):
16281616

16291617
class SimCounter:
16301618
def __init__(self, initial_count, n_simulations, parallel_start):
1619+
self.initial_count = initial_count
16311620
self.count = initial_count
16321621
self.n_simulations = n_simulations
16331622
self._last_print_len = 0 # used to print on the same line
@@ -1649,7 +1638,7 @@ def get_n_simulations(self):
16491638
def get_intial_time(self):
16501639
return self.initial_time
16511640

1652-
def reprint(self, msg, end="\n", flush=False):
1641+
def reprint(self, sim_idx, end="\n", flush=False):
16531642
"""Prints a message on the same line as the previous one and replaces
16541643
the previous message with the new one, deleting the extra characters
16551644
from the previous message.
@@ -1667,11 +1656,19 @@ def reprint(self, msg, end="\n", flush=False):
16671656
-------
16681657
None
16691658
"""
1659+
average_time = (time() - self.initial_time) / (self.count - self.initial_count)
1660+
estimated_time = int(
1661+
(self.n_simulations - (self.count - self.initial_count)) * average_time
1662+
)
1663+
1664+
msg = f"Current iteration: {sim_idx:06d}"
1665+
msg += f" | Average Time per Iteration: {average_time:.3f} s"
1666+
msg += f" | Estimated time left: {estimated_time} s"
16701667

1671-
# len_msg = len(msg)
1672-
# if len_msg < self._last_print_len:
1673-
# msg += " " * (self._last_print_len - len_msg)
1674-
# else:
1675-
# self._last_print_len = len_msg
1668+
len_msg = len(msg)
1669+
if len_msg < self._last_print_len:
1670+
msg += " " * (self._last_print_len - len_msg)
1671+
else:
1672+
self._last_print_len = len_msg
16761673

16771674
print(msg, end=end, flush=flush)

0 commit comments

Comments
 (0)