Skip to content

Commit

Permalink
MNT: solve review comments on docstrings and code comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
phmbressan committed Aug 23, 2024
1 parent 6dab002 commit d07fcc2
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions rocketpy/simulation/monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,13 @@ def __init__(
self.import_outputs(self.filename.with_suffix(".outputs.txt"))
self.import_errors(self.filename.with_suffix(".errors.txt"))

# pylint: disable=consider-using-with
def simulate(
self,
number_of_simulations,
append=False,
parallel=False,
n_workers=None,
): # pylint: disable=too-many-statements
):
"""
Runs the Monte Carlo simulation and saves all data.
Expand Down Expand Up @@ -191,13 +190,10 @@ def simulate(
self.number_of_simulations = number_of_simulations
self._initial_sim_idx = self.num_of_loaded_sims if append else 0

# Begin display
_SimMonitor.reprint("Starting Monte Carlo analysis")

# Setup files
self.__setup_files(append)

# Run simulations
if parallel:
self.__run_in_parallel(n_workers)
else:
Expand Down Expand Up @@ -241,11 +237,6 @@ def __run_in_serial(self):
"""
Runs the monte carlo simulation in serial mode.
Parameters
----------
start_index : int
The index of the first simulation to be run.
Returns
-------
None
Expand Down Expand Up @@ -303,9 +294,9 @@ def __run_in_parallel(self, n_workers=None):
if n_workers < 2:
raise ValueError("Number of workers must be at least 2 for parallel mode.")

multiprocess, managers = import_multiprocess()
multiprocess, managers = _import_multiprocess()

with create_multiprocess_manager(multiprocess, managers) as manager:
with _create_multiprocess_manager(multiprocess, managers) as manager:
export_queue = manager.Queue()
mutex = manager.Lock()
consumer_stop_event = manager.Event()
Expand Down Expand Up @@ -442,10 +433,6 @@ def __sim_consumer(
----------
export_queue : multiprocess.Queue
The queue to export the results.
inputs_file : str
The file path to write the inputs.
outputs_file : str
The file path to write the outputs.
mutex : multiprocess.Lock
The mutex to lock access to critical regions.
stop_event : multiprocess.Event
Expand Down Expand Up @@ -1041,7 +1028,7 @@ def all_info(self):
self.plots.all()


def import_multiprocess():
def _import_multiprocess():
"""Import the necessary modules and submodules for the
multiprocess library.
Expand All @@ -1056,7 +1043,7 @@ def import_multiprocess():
return multiprocess, managers


def create_multiprocess_manager(multiprocess, managers):
def _create_multiprocess_manager(multiprocess, managers):
"""Creates a manager for the multiprocess control of the
Monte Carlo simulation.
Expand Down Expand Up @@ -1150,7 +1137,7 @@ def reprint(msg, end="\n", flush=True):
end : str, optional
String appended after the message. Default is a new line.
flush : bool, optional
If True, the output is flushed. Default is False.
If True, the output is flushed. Default is True.
Returns
-------
Expand Down

0 comments on commit d07fcc2

Please sign in to comment.