Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Attention: The newest changes should be on top -->

### Fixed

- BUG: Fix parallel Monte Carlo simulation showing incorrect iteration count [#806](https://github.com/RocketPy-Team/RocketPy/pull/806)
- BUG: Fix CSV column header spacing in FlightDataExporter [#864](https://github.com/RocketPy-Team/RocketPy/issues/864)


Expand Down
24 changes: 12 additions & 12 deletions rocketpy/simulation/monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def __run_in_serial(self):
with open(self.output_file, "a", encoding="utf-8") as f:
f.write(outputs_json)

sim_monitor.print_update_status(sim_monitor.count)
sim_monitor.print_update_status()

sim_monitor.print_final_status()

Expand Down Expand Up @@ -430,7 +430,7 @@ def __sim_producer(self, seed, sim_monitor, mutex, error_event): # pylint: disa
with open(self.output_file, "a", encoding="utf-8") as f:
f.write(outputs_json)

sim_monitor.print_update_status(sim_idx)
sim_monitor.print_update_status()
finally:
mutex.release()

Expand Down Expand Up @@ -1208,6 +1208,7 @@ def __init__(self, initial_count, n_simulations, start_time):
self.count = initial_count
self.n_simulations = n_simulations
self.start_time = start_time
self.completed_count = 0

def keep_simulating(self):
return self.count < self.n_simulations
Expand All @@ -1216,25 +1217,24 @@ def increment(self):
self.count += 1
return self.count

def print_update_status(self, sim_idx):
def print_update_status(self):
"""Prints a message on the same line as the previous one and replaces
the previous message with the new one, deleting the extra characters
from the previous message.

Parameters
----------
sim_idx : int
Index of the current simulation.
from the previous message. This method increments the completed_count
to track how many simulations have finished (thread-safe when called
within a mutex-protected section).

Returns
-------
None
"""
self.completed_count += 1

average_time = (time() - self.start_time) / (self.count - self.initial_count)
estimated_time = int((self.n_simulations - self.count) * average_time)
average_time = (time() - self.start_time) / self.completed_count
remaining = self.n_simulations - self.initial_count - self.completed_count
estimated_time = int(remaining * average_time)

msg = f"Current iteration: {sim_idx:06d}"
msg = f"Iterations completed: {self.completed_count:06d}"
msg += f" | Average Time per Iteration: {average_time:.3f} s"
msg += f" | Estimated time left: {estimated_time} s"

Expand Down