Skip to content

Commit

Permalink
MNT: remove post processing scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
phmbressan committed Jul 26, 2024
1 parent 2a42b26 commit 8008aa7
Show file tree
Hide file tree
Showing 13 changed files with 3,629 additions and 2,502 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

3,659 changes: 3,585 additions & 74 deletions docs/notebooks/monte_carlo_analysis/monte_carlo_class_usage.ipynb

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions requirements-optional.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ ipywidgets>=7.6.3
jsonpickle
timezonefinder
imageio
h5py
easygui
h5py
53 changes: 23 additions & 30 deletions rocketpy/simulation/monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import json
import os
import pickle
import warnings
from copy import deepcopy
from pathlib import Path
import warnings
from time import process_time, time

import h5py
Expand Down Expand Up @@ -102,7 +102,7 @@ def __init__(
export_list=None,
batch_path=None,
export_sample_time=0.1,
): # pylint: disable=too-many-statements
): # pylint: disable=too-many-statements
"""
Initialize a MonteCarlo object.
Expand Down Expand Up @@ -165,7 +165,7 @@ def __init__(

if not os.path.exists(self.batch_path):
os.makedirs(self.batch_path)

self.export_list = self.__check_export_list(export_list)

try:
Expand All @@ -191,7 +191,6 @@ def simulate(
light_mode=False,
parallel=False,
n_workers=None,

): # pylint: disable=too-many-statements
"""
Runs the Monte Carlo simulation and saves all data.
Expand Down Expand Up @@ -246,7 +245,6 @@ def simulate(
else:
self.__run_in_serial(append, light_mode=light_mode)


def __run_in_serial(self, append, light_mode):
"""
Runs the monte carlo simulation in serial mode.
Expand Down Expand Up @@ -468,7 +466,7 @@ def __run_in_parallel(self, append, light_mode, n_workers=None):
print(f"Number of simulations: {self.number_of_simulations}")

# Creates n_workers processes then starts them
for i in range(n_workers - 2): # leave 2 cores for the writer workers
for _ in range(n_workers - 2): # leave 2 cores for the writer workers
p = Process(
target=self.__run_simulation_worker,
args=(
Expand Down Expand Up @@ -542,27 +540,24 @@ def __run_in_parallel(self, append, light_mode, n_workers=None):
input_writer_stop_event.set()
results_writer_stop_event.set()

print("Waiting for writer workers to join.")
# join the writer workers
input_writer.join()
results_writer.join()

self.number_of_simulations = sim_counter.get_count()

parallel_end = time()

print("-" * 80 + "\nAll workers joined, simulation complete.")
print("-" * 80 + "\n")
print("All workers joined, simulation complete.")
print(
f"In total, {sim_counter.get_count() - idx_i} simulations were performed."
)
print(
"Simulation took",
parallel_end - parallel_start_time,
"seconds to run.",
f"Simulation took {(parallel_end - parallel_start_time):.2f} seconds to run."
)

finally:
# ensure shared memory is realeased
# ensure shared memory is released
shared_inputs_buffer.close()
shared_results_buffer.close()
shared_inputs_buffer.unlink()
Expand Down Expand Up @@ -649,22 +644,14 @@ def __run_simulation_worker(
if sim_idx == -1:
break

env = sto_env.create_object()
rocket = sto_rocket.create_object()
rail_length = sto_flight._randomize_rail_length()
inclination = sto_flight._randomize_inclination()
heading = sto_flight._randomize_heading()
initial_solution = sto_flight.initial_solution
terminate_on_apogee = sto_flight.terminate_on_apogee

monte_carlo_flight = Flight(
rocket=rocket,
environment=env,
rail_length=rail_length,
inclination=inclination,
heading=heading,
initial_solution=initial_solution,
terminate_on_apogee=terminate_on_apogee,
rocket=sto_rocket.create_object(),
environment=sto_env.create_object(),
rail_length=sto_flight._randomize_rail_length(),
inclination=sto_flight._randomize_inclination(),
heading=sto_flight._randomize_heading(),
initial_solution=sto_flight.initial_solution,
terminate_on_apogee=sto_flight.terminate_on_apogee,
)

# Export to file
Expand Down Expand Up @@ -793,7 +780,7 @@ def __run_single_simulation(
terminate_on_apogee=self.flight.terminate_on_apogee,
)

self._inputs_dict = dict(
inputs_dict = dict(
item
for d in [
self.environment.last_rnd_dict,
Expand All @@ -802,7 +789,13 @@ def __run_single_simulation(
]
for item in d.items()
)
self._inputs_dict["idx"] = sim_idx
inputs_dict["idx"] = sim_idx

inputs_dict = MonteCarlo.prepare_export_data(
inputs_dict, self.export_sample_time, remove_functions=True
)

self._inputs_dict = inputs_dict

# Export inputs and outputs to file
if light_mode:
Expand Down
Empty file.
Empty file.
49 changes: 0 additions & 49 deletions rocketpy/stochastic/post_processing/scripts/stochastic_apogee.py

This file was deleted.

This file was deleted.

37 changes: 0 additions & 37 deletions rocketpy/stochastic/post_processing/scripts/stochastic_mach.py

This file was deleted.

42 changes: 0 additions & 42 deletions rocketpy/stochastic/post_processing/scripts/stochastic_maxQ.py

This file was deleted.

Loading

0 comments on commit 8008aa7

Please sign in to comment.