From fbbec590aecec401208a38a08553557258f1cdef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 27 Nov 2025 16:19:41 +0000 Subject: [PATCH 1/2] Fix parallel Monte Carlo iteration count display to show monotonically increasing completed count Co-authored-by: Gui-FernandesBR <63590233+Gui-FernandesBR@users.noreply.github.com> --- rocketpy/simulation/monte_carlo.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/rocketpy/simulation/monte_carlo.py b/rocketpy/simulation/monte_carlo.py index 25531fc9a..b94c165b3 100644 --- a/rocketpy/simulation/monte_carlo.py +++ b/rocketpy/simulation/monte_carlo.py @@ -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() @@ -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() @@ -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 @@ -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" From 7cfc5a575a54599a933f6731fb512b23a690af1c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 27 Nov 2025 16:29:15 +0000 Subject: [PATCH 2/2] Add PR #806 to CHANGELOG.md Co-authored-by: Gui-FernandesBR <63590233+Gui-FernandesBR@users.noreply.github.com> --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c65e36614..4c3aa2373 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)