Skip to content

Commit eb46d10

Browse files
BUG: add to_dict/from_dict to RingClusterMotor for serialization round-trip
RingClusterMotor defined neither to_dict nor from_dict, and its base class Motor (ABC) has none either (only GenericMotor does). On decode, RocketPyDecoder fell through to instantiating the class from the filtered dict, but the inherited Motor.to_dict serializes computed motor fields (thrust_source, inertias, ...) and none of the constructor arguments (motor, number, radius). Reconstruction called RingClusterMotor() with no args: TypeError: RingClusterMotor.__init__() missing 3 required positional arguments: 'motor', 'number', and 'radius' This TypeError is not caught by the decoder (only ImportError/AttributeError are), so any Rocket/Flight carrying a RingClusterMotor could not be reloaded, which also breaks Monte Carlo caching and .rpy save/load for the new motor. The inner motor is a RocketPy object and is serialized/reconstructed recursively, so from_dict just forwards the reconstructed motor plus number and radius. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 00e4952 commit eb46d10

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

rocketpy/motors/ring_cluster_motor.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,25 @@ def info(self, *args, **kwargs):
291291
print(f" - Radial Distance: {self.radius} m")
292292
return self.motor.info(*args, **kwargs)
293293

294+
def to_dict(self, **kwargs):
295+
data = super().to_dict(**kwargs)
296+
data.update(
297+
{
298+
"motor": self.motor,
299+
"number": self.number,
300+
"radius": self.radius,
301+
}
302+
)
303+
return data
304+
305+
@classmethod
306+
def from_dict(cls, data):
307+
return cls(
308+
motor=data["motor"],
309+
number=data["number"],
310+
radius=data["radius"],
311+
)
312+
294313
def draw_cluster_layout(self, rocket_radius=None, show=True):
295314
"""Draw the geometric layout of the clustered motors."""
296315
fig, ax = plt.subplots(figsize=(6, 6))

0 commit comments

Comments
 (0)