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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Attention: The newest changes should be on top -->


### Fixed

- BUG: Fix the handling of reference pressure for older rpy files. [#808](https://github.com/RocketPy-Team/RocketPy/pull/808)
- BUG: Non-overshootable simulations error on time parsing. [#807](https://github.com/RocketPy-Team/RocketPy/pull/807)

## v1.9.0 - 2025-03-24
Expand Down
104 changes: 59 additions & 45 deletions rocketpy/_encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import numpy as np

from rocketpy.mathutils.function import Function
from rocketpy.prints.flight_prints import _FlightPrints
from rocketpy.plots.flight_plots import _FlightPlots
from rocketpy.prints.flight_prints import _FlightPrints


class RocketPyEncoder(json.JSONEncoder):
Expand Down Expand Up @@ -91,50 +91,7 @@ def object_hook(self, obj):
new_flight = class_.__new__(class_)
new_flight.prints = _FlightPrints(new_flight)
new_flight.plots = _FlightPlots(new_flight)
attributes = (
"rocket",
"env",
"rail_length",
"inclination",
"heading",
"initial_solution",
"terminate_on_apogee",
"max_time",
"max_time_step",
"min_time_step",
"rtol",
"atol",
"time_overshoot",
"name",
"solution",
"out_of_rail_time",
"apogee_time",
"apogee",
"parachute_events",
"impact_state",
"impact_velocity",
"x_impact",
"y_impact",
"t_final",
"flight_phases",
"ax",
"ay",
"az",
"out_of_rail_time_index",
"function_evaluations",
"alpha1",
"alpha2",
"alpha3",
"R1",
"R2",
"R3",
"M1",
"M2",
"M3",
)
for attribute in attributes:
setattr(new_flight, attribute, obj[attribute])
new_flight.t_initial = new_flight.initial_solution[0]
set_minimal_flight_attributes(new_flight, obj)
return new_flight
elif hasattr(class_, "from_dict"):
return class_.from_dict(obj)
Expand All @@ -153,6 +110,63 @@ def object_hook(self, obj):
return obj


def set_minimal_flight_attributes(flight, obj):
attributes = (
"rocket",
"env",
"rail_length",
"inclination",
"heading",
"initial_solution",
"terminate_on_apogee",
"max_time",
"max_time_step",
"min_time_step",
"rtol",
"atol",
"time_overshoot",
"name",
"solution",
"out_of_rail_time",
"apogee_time",
"apogee",
"parachute_events",
"impact_state",
"impact_velocity",
"x_impact",
"y_impact",
"t_final",
"flight_phases",
"ax",
"ay",
"az",
"out_of_rail_time_index",
"function_evaluations",
"speed",
"alpha1",
"alpha2",
"alpha3",
"R1",
"R2",
"R3",
"M1",
"M2",
"M3",
"net_thrust",
)

for attribute in attributes:
try:
setattr(flight, attribute, obj[attribute])
except KeyError:
# Manual resolution of new attributes
if attribute == "net_thrust":
flight.net_thrust = obj["rocket"].motor.thrust
flight.net_thrust.set_discrete_based_on_model(flight.speed)

flight.t_initial = flight.initial_solution[0]


def get_class_signature(obj):
"""Returns the signature of a class so it can be identified on
decoding. The signature is a dictionary with the module and
Expand Down
2 changes: 1 addition & 1 deletion rocketpy/motors/hybrid_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def from_dict(cls, data):
grains_center_of_mass_position=data["grains_center_of_mass_position"],
nozzle_position=data["nozzle_position"],
throat_radius=data["throat_radius"],
reference_pressure=data["reference_pressure"],
reference_pressure=data.get("reference_pressure"),
)

for tank in data["positioned_tanks"]:
Expand Down
2 changes: 1 addition & 1 deletion rocketpy/motors/liquid_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def from_dict(cls, data):
nozzle_position=data["nozzle_position"],
interpolation_method=data["interpolate"],
coordinate_system_orientation=data["coordinate_system_orientation"],
reference_pressure=data["reference_pressure"],
reference_pressure=data.get("reference_pressure"),
)

for tank in data["positioned_tanks"]:
Expand Down
2 changes: 1 addition & 1 deletion rocketpy/motors/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,5 +1896,5 @@ def from_dict(cls, data):
),
nozzle_position=data["nozzle_position"],
interpolation_method=data["interpolate"],
reference_pressure=data["reference_pressure"],
reference_pressure=data.get("reference_pressure"),
)
2 changes: 1 addition & 1 deletion rocketpy/motors/solid_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,5 +821,5 @@ def from_dict(cls, data):
throat_radius=data["throat_radius"],
interpolation_method=data["interpolate"],
coordinate_system_orientation=data["coordinate_system_orientation"],
reference_pressure=data["reference_pressure"],
reference_pressure=data.get("reference_pressure"),
)
10 changes: 8 additions & 2 deletions rocketpy/simulation/monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
try:
while sim_monitor.keep_simulating():
sim_monitor.increment()
inputs_json, outputs_json = "", ""

Check warning on line 284 in rocketpy/simulation/monte_carlo.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/simulation/monte_carlo.py#L284

Added line #L284 was not covered by tests

flight = self.__run_single_simulation()
inputs_json = self.__evaluate_flight_inputs(sim_monitor.count)
Expand Down Expand Up @@ -406,6 +407,7 @@

while sim_monitor.keep_simulating():
sim_idx = sim_monitor.increment() - 1
inputs_json, outputs_json = "", ""

Check warning on line 410 in rocketpy/simulation/monte_carlo.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/simulation/monte_carlo.py#L410

Added line #L410 was not covered by tests

flight = self.__run_single_simulation()
inputs_json = self.__evaluate_flight_inputs(sim_idx)
Expand Down Expand Up @@ -484,7 +486,9 @@
for item in d.items()
)
inputs_dict["index"] = sim_idx
return json.dumps(inputs_dict, cls=RocketPyEncoder) + "\n"
return (

Check warning on line 489 in rocketpy/simulation/monte_carlo.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/simulation/monte_carlo.py#L489

Added line #L489 was not covered by tests
json.dumps(inputs_dict, cls=RocketPyEncoder, **self._export_config) + "\n"
)

def __evaluate_flight_outputs(self, flight, sim_idx):
"""Evaluates the outputs of a single flight simulation.
Expand Down Expand Up @@ -518,7 +522,9 @@
) from e
outputs_dict = outputs_dict | additional_exports

return json.dumps(outputs_dict, cls=RocketPyEncoder) + "\n"
return (

Check warning on line 525 in rocketpy/simulation/monte_carlo.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/simulation/monte_carlo.py#L525

Added line #L525 was not covered by tests
json.dumps(outputs_dict, cls=RocketPyEncoder, **self._export_config) + "\n"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change had already been done by PR #679, however is was likely undone by merging errors at some point.

)

def __terminate_simulation(self):
"""
Expand Down
12 changes: 6 additions & 6 deletions rocketpy/utilities.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import ast
import inspect
import traceback
import warnings
import json
import os

from pathlib import Path
from importlib.metadata import version
import traceback
import warnings
from datetime import date
from importlib.metadata import version
from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import solve_ivp

from ._encoders import RocketPyDecoder, RocketPyEncoder
from .environment.environment import Environment
from .mathutils.function import Function
from .plots.plot_helpers import show_or_save_plot
from .rocket.aero_surface import TrapezoidalFins
from .simulation.flight import Flight
from ._encoders import RocketPyEncoder, RocketPyDecoder


def compute_cd_s_from_drop_test(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_utilities.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from unittest.mock import patch

import os
import numpy as np
import pytest

Expand Down
Loading