Skip to content

Commit 5329b29

Browse files
committed
ENH: add Mission orchestrator, degenerate single-flight case
Fifth slice of the multistage/mission architecture. Mission is the orchestrator that will eventually walk a vehicle's separation/ ejection events and run one Flight per configuration with state handoff between them (see mission_multistage_design.md). This commit implements only the base case the doc itself calls out as an invariant: "a single-stage vehicle with no deployables degenerates to a thin wrapper around one Flight." A plain Rocket is accepted directly (wrapped internally as a single-stage MultiStageRocket, matching flight_rocket's own auto-wrap behavior). Anything with more than one stage or any deployables raises NotImplementedError for now - multi-stage orchestration and deployable ejection are separate, later commits. mission.timeline records (time, event_name) pairs - ignition, liftoff, rail_departure, impact - sorted by time. Also updates docs/notebooks/multistage_mission.ipynb with a live Mission run against Calisto, executed end-to-end.
1 parent faf2132 commit 5329b29

3 files changed

Lines changed: 251 additions & 38 deletions

File tree

‎docs/notebooks/multistage_mission.ipynb‎

Lines changed: 82 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@
1212
"1. `Stage` — wraps a single-stage `Rocket`\n",
1313
"2. `Deployable` — a carried payload released mid-flight\n",
1414
"3. `MultiStageRocket` — composes a stage + its deployables into one flight-ready `Rocket`\n",
15-
"4. `MultiStageRocket.flight_rocket` for more than one active stage (a booster with an inert sustainer riding on top)\n"
15+
"4. `MultiStageRocket.flight_rocket` for more than one active stage (a booster with an inert sustainer riding on top)\n",
16+
"5. `Mission` — orchestrates one `Flight` per vehicle configuration (currently only the degenerate single-stage, no-deployables case: one vehicle, one `Flight`)\n"
1617
]
1718
},
1819
{
1920
"cell_type": "code",
2021
"execution_count": null,
2122
"metadata": {
2223
"execution": {
23-
"iopub.execute_input": "2026-08-14T09:07:27.168733Z",
24-
"iopub.status.busy": "2026-08-14T09:07:27.168494Z",
25-
"iopub.status.idle": "2026-08-14T09:07:28.612708Z",
26-
"shell.execute_reply": "2026-08-14T09:07:28.612298Z"
24+
"iopub.execute_input": "2026-08-14T09:14:13.695767Z",
25+
"iopub.status.busy": "2026-08-14T09:14:13.695461Z",
26+
"iopub.status.idle": "2026-08-14T09:14:15.115898Z",
27+
"shell.execute_reply": "2026-08-14T09:14:15.115438Z"
2728
}
2829
},
2930
"outputs": [],
@@ -46,10 +47,10 @@
4647
"execution_count": null,
4748
"metadata": {
4849
"execution": {
49-
"iopub.execute_input": "2026-08-14T09:07:28.615144Z",
50-
"iopub.status.busy": "2026-08-14T09:07:28.614900Z",
51-
"iopub.status.idle": "2026-08-14T09:07:28.639194Z",
52-
"shell.execute_reply": "2026-08-14T09:07:28.638875Z"
50+
"iopub.execute_input": "2026-08-14T09:14:15.118313Z",
51+
"iopub.status.busy": "2026-08-14T09:14:15.118055Z",
52+
"iopub.status.idle": "2026-08-14T09:14:15.142164Z",
53+
"shell.execute_reply": "2026-08-14T09:14:15.141816Z"
5354
}
5455
},
5556
"outputs": [],
@@ -102,10 +103,10 @@
102103
"execution_count": null,
103104
"metadata": {
104105
"execution": {
105-
"iopub.execute_input": "2026-08-14T09:07:28.666448Z",
106-
"iopub.status.busy": "2026-08-14T09:07:28.666250Z",
107-
"iopub.status.idle": "2026-08-14T09:07:28.668832Z",
108-
"shell.execute_reply": "2026-08-14T09:07:28.668508Z"
106+
"iopub.execute_input": "2026-08-14T09:14:15.170500Z",
107+
"iopub.status.busy": "2026-08-14T09:14:15.170304Z",
108+
"iopub.status.idle": "2026-08-14T09:14:15.173035Z",
109+
"shell.execute_reply": "2026-08-14T09:14:15.172701Z"
109110
}
110111
},
111112
"outputs": [],
@@ -133,10 +134,10 @@
133134
"execution_count": null,
134135
"metadata": {
135136
"execution": {
136-
"iopub.execute_input": "2026-08-14T09:07:28.670308Z",
137-
"iopub.status.busy": "2026-08-14T09:07:28.670180Z",
138-
"iopub.status.idle": "2026-08-14T09:07:28.672458Z",
139-
"shell.execute_reply": "2026-08-14T09:07:28.672176Z"
137+
"iopub.execute_input": "2026-08-14T09:14:15.174556Z",
138+
"iopub.status.busy": "2026-08-14T09:14:15.174409Z",
139+
"iopub.status.idle": "2026-08-14T09:14:15.176844Z",
140+
"shell.execute_reply": "2026-08-14T09:14:15.176509Z"
140141
}
141142
},
142143
"outputs": [],
@@ -159,10 +160,10 @@
159160
"execution_count": null,
160161
"metadata": {
161162
"execution": {
162-
"iopub.execute_input": "2026-08-14T09:07:28.673894Z",
163-
"iopub.status.busy": "2026-08-14T09:07:28.673778Z",
164-
"iopub.status.idle": "2026-08-14T09:07:28.676873Z",
165-
"shell.execute_reply": "2026-08-14T09:07:28.676536Z"
163+
"iopub.execute_input": "2026-08-14T09:14:15.178186Z",
164+
"iopub.status.busy": "2026-08-14T09:14:15.178070Z",
165+
"iopub.status.idle": "2026-08-14T09:14:15.181087Z",
166+
"shell.execute_reply": "2026-08-14T09:14:15.180771Z"
166167
}
167168
},
168169
"outputs": [],
@@ -183,10 +184,10 @@
183184
"execution_count": null,
184185
"metadata": {
185186
"execution": {
186-
"iopub.execute_input": "2026-08-14T09:07:28.678288Z",
187-
"iopub.status.busy": "2026-08-14T09:07:28.678173Z",
188-
"iopub.status.idle": "2026-08-14T09:07:28.680214Z",
189-
"shell.execute_reply": "2026-08-14T09:07:28.679876Z"
187+
"iopub.execute_input": "2026-08-14T09:14:15.182384Z",
188+
"iopub.status.busy": "2026-08-14T09:14:15.182283Z",
189+
"iopub.status.idle": "2026-08-14T09:14:15.184190Z",
190+
"shell.execute_reply": "2026-08-14T09:14:15.183898Z"
190191
}
191192
},
192193
"outputs": [],
@@ -210,10 +211,10 @@
210211
"execution_count": null,
211212
"metadata": {
212213
"execution": {
213-
"iopub.execute_input": "2026-08-14T09:07:28.681606Z",
214-
"iopub.status.busy": "2026-08-14T09:07:28.681507Z",
215-
"iopub.status.idle": "2026-08-14T09:07:28.689190Z",
216-
"shell.execute_reply": "2026-08-14T09:07:28.688895Z"
214+
"iopub.execute_input": "2026-08-14T09:14:15.185595Z",
215+
"iopub.status.busy": "2026-08-14T09:14:15.185490Z",
216+
"iopub.status.idle": "2026-08-14T09:14:15.193370Z",
217+
"shell.execute_reply": "2026-08-14T09:14:15.193085Z"
217218
}
218219
},
219220
"outputs": [],
@@ -262,10 +263,10 @@
262263
"execution_count": null,
263264
"metadata": {
264265
"execution": {
265-
"iopub.execute_input": "2026-08-14T09:07:28.690554Z",
266-
"iopub.status.busy": "2026-08-14T09:07:28.690454Z",
267-
"iopub.status.idle": "2026-08-14T09:07:28.708806Z",
268-
"shell.execute_reply": "2026-08-14T09:07:28.708458Z"
266+
"iopub.execute_input": "2026-08-14T09:14:15.194759Z",
267+
"iopub.status.busy": "2026-08-14T09:14:15.194664Z",
268+
"iopub.status.idle": "2026-08-14T09:14:15.212474Z",
269+
"shell.execute_reply": "2026-08-14T09:14:15.212187Z"
269270
}
270271
},
271272
"outputs": [],
@@ -312,10 +313,10 @@
312313
"execution_count": null,
313314
"metadata": {
314315
"execution": {
315-
"iopub.execute_input": "2026-08-14T09:07:28.710231Z",
316-
"iopub.status.busy": "2026-08-14T09:07:28.710113Z",
317-
"iopub.status.idle": "2026-08-14T09:07:28.725482Z",
318-
"shell.execute_reply": "2026-08-14T09:07:28.725174Z"
316+
"iopub.execute_input": "2026-08-14T09:14:15.213789Z",
317+
"iopub.status.busy": "2026-08-14T09:14:15.213693Z",
318+
"iopub.status.idle": "2026-08-14T09:14:15.228796Z",
319+
"shell.execute_reply": "2026-08-14T09:14:15.228517Z"
319320
}
320321
},
321322
"outputs": [],
@@ -336,6 +337,48 @@
336337
"assert after_separation.mass == 5.0"
337338
]
338339
},
340+
{
341+
"cell_type": "markdown",
342+
"metadata": {},
343+
"source": [
344+
"## `Mission`: the degenerate single-flight case\n",
345+
"\n",
346+
"`Mission` is the orchestrator that will eventually walk a vehicle's separation/ejection events and run one `Flight` per configuration with state handoff between them. Right now only the simplest case is implemented: a single-stage vehicle with no deployables degenerates to a thin wrapper around one `Flight` - confirming the invariant stated in `mission_multistage_design.md`. Anything else raises `NotImplementedError` for now.\n",
347+
"\n",
348+
"A plain `Rocket` is sugar for a single-stage `MultiStageRocket` with nothing separable, so `Mission` accepts either directly."
349+
]
350+
},
351+
{
352+
"cell_type": "code",
353+
"execution_count": null,
354+
"metadata": {
355+
"execution": {
356+
"iopub.execute_input": "2026-08-14T09:14:15.230304Z",
357+
"iopub.status.busy": "2026-08-14T09:14:15.230175Z",
358+
"iopub.status.idle": "2026-08-14T09:14:15.293164Z",
359+
"shell.execute_reply": "2026-08-14T09:14:15.292806Z"
360+
}
361+
},
362+
"outputs": [],
363+
"source": [
364+
"from rocketpy import Environment\n",
365+
"from rocketpy.simulation.mission import Mission\n",
366+
"\n",
367+
"mission = Mission(\n",
368+
" vehicle=calisto,\n",
369+
" environment=Environment(),\n",
370+
" rail_length=5.2,\n",
371+
" inclination=85,\n",
372+
" heading=0,\n",
373+
")\n",
374+
"\n",
375+
"print(f\"bodies flown: {list(mission.flights.keys())}\")\n",
376+
"print(f\"flights for 'stage_1': {mission.flights['stage_1']}\")\n",
377+
"print(\"\\ntimeline:\")\n",
378+
"for time, event in mission.timeline:\n",
379+
" print(f\" t={time:8.3f}s {event}\")"
380+
]
381+
},
339382
{
340383
"cell_type": "markdown",
341384
"metadata": {},
@@ -345,7 +388,8 @@
345388
"Deliberately out of scope for the commits so far (see the roadmap in `mission_multistage_design.md`):\n",
346389
"\n",
347390
"- Deriving stack positions from `interstage_lengths` and each stage's physical extent (stages are currently assumed to already share one coordinate frame)\n",
348-
"- `Mission` — the orchestrator that runs one `Flight` per vehicle configuration with state handoff between them\n",
391+
"- `Mission` for more than one stage or any deployables: separation timing, ignition delays, and state handoff between Flights\n",
392+
"- `Mission` deployable ejection (apogee-triggered, via `terminate_on_apogee`)\n",
349393
"- Deterministic time-based separation (motor burnout + delay) and apogee-triggered deployable ejection\n",
350394
"- `StochasticMission`\n",
351395
"\n",

‎rocketpy/simulation/mission.py‎

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
"""Mission – orchestrates one Flight per vehicle configuration."""
2+
3+
from rocketpy.rocket.multistage import MultiStageRocket
4+
from rocketpy.simulation.flight import Flight
5+
6+
7+
class Mission:
8+
"""Simulate a complete mission: a vehicle that splits into multiple
9+
bodies, each simulated to impact (or until max_time).
10+
11+
Walks the vehicle's separation/ejection events, runs one Flight per
12+
vehicle configuration with correct state handoff between them, and
13+
groups the resulting Flight objects per physical body along with a
14+
global event timeline.
15+
16+
A single-stage vehicle with no deployables degenerates to a thin
17+
wrapper around one Flight - the only case implemented so far.
18+
Multi-stage orchestration (separation, ignition delays, state
19+
handoff) and deployable ejection are later commits.
20+
21+
Parameters
22+
----------
23+
vehicle : MultiStageRocket or Rocket
24+
The vehicle to fly. A plain Rocket is sugar for a single-stage
25+
MultiStageRocket with nothing separable (one Flight).
26+
environment : Environment
27+
rail_length, inclination, heading : same vocabulary as Flight.
28+
max_time : float
29+
Mission-wide limit in seconds; every body's flight ends by then.
30+
(remaining solver parameters are passed through to each Flight)
31+
32+
Attributes
33+
----------
34+
flights : dict
35+
Body name -> list of Flight, in time order. Currently always
36+
exactly one body with exactly one Flight.
37+
timeline : list of (float, str)
38+
(time, event_name) tuples sorted by time. Canonical names so
39+
far: "ignition:<stage>", "liftoff", "impact:<stage>".
40+
"""
41+
42+
def __init__(
43+
self,
44+
vehicle,
45+
environment,
46+
rail_length,
47+
inclination=80.0,
48+
heading=90.0,
49+
name="Mission",
50+
max_time=600,
51+
rtol=1e-6,
52+
atol=None,
53+
time_overshoot=True,
54+
ode_solver="LSODA",
55+
verbose=False,
56+
):
57+
self.vehicle = (
58+
vehicle
59+
if isinstance(vehicle, MultiStageRocket)
60+
else MultiStageRocket(stages=[vehicle])
61+
)
62+
self.environment = environment
63+
self.rail_length = rail_length
64+
self.inclination = inclination
65+
self.heading = heading
66+
self.name = name
67+
self.max_time = max_time
68+
self.rtol = rtol
69+
self.atol = atol
70+
self.time_overshoot = time_overshoot
71+
self.ode_solver = ode_solver
72+
self.verbose = verbose
73+
74+
self.flights = {}
75+
self.timeline = []
76+
self._simulate()
77+
78+
def _simulate(self):
79+
"""Run the mission.
80+
81+
Only the degenerate case is implemented so far: a single stage,
82+
no deployables aboard, flown once from the rail to impact (or
83+
max_time). Anything else raises NotImplementedError until
84+
multi-stage orchestration lands.
85+
"""
86+
if len(self.vehicle.stages) != 1 or self.vehicle.deployables:
87+
raise NotImplementedError(
88+
"Mission currently only supports a single-stage vehicle "
89+
"with no deployables; multi-stage orchestration is not "
90+
"yet implemented."
91+
)
92+
stage = self.vehicle.stages[0]
93+
rocket = self.vehicle.flight_rocket(active_stages=(stage,))
94+
95+
self.timeline.append((0.0, f"ignition:{stage.name}"))
96+
self.timeline.append((0.0, "liftoff"))
97+
98+
flight = Flight(
99+
rocket=rocket,
100+
environment=self.environment,
101+
rail_length=self.rail_length,
102+
inclination=self.inclination,
103+
heading=self.heading,
104+
max_time=self.max_time,
105+
rtol=self.rtol,
106+
atol=self.atol,
107+
time_overshoot=self.time_overshoot,
108+
ode_solver=self.ode_solver,
109+
verbose=self.verbose,
110+
)
111+
112+
self.timeline.append((flight.out_of_rail_time, "rail_departure"))
113+
self.timeline.append((flight.t_final, f"impact:{stage.name}"))
114+
self.timeline.sort(key=lambda entry: entry[0])
115+
116+
self.flights[stage.name] = [flight]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from rocketpy import Flight
2+
from rocketpy.rocket.multistage import MultiStageRocket, Stage
3+
from rocketpy.simulation.mission import Mission
4+
5+
6+
def test_mission_degenerates_to_a_single_flight_for_a_plain_rocket(
7+
calisto, example_plain_env
8+
):
9+
mission = Mission(
10+
vehicle=calisto,
11+
environment=example_plain_env,
12+
rail_length=5.2,
13+
inclination=85,
14+
heading=0,
15+
)
16+
17+
assert list(mission.flights.keys()) == ["stage_1"]
18+
assert len(mission.flights["stage_1"]) == 1
19+
assert isinstance(mission.flights["stage_1"][0], Flight)
20+
21+
22+
def test_mission_timeline_has_ignition_liftoff_and_impact_only(
23+
calisto, example_plain_env
24+
):
25+
mission = Mission(
26+
vehicle=calisto,
27+
environment=example_plain_env,
28+
rail_length=5.2,
29+
inclination=85,
30+
heading=0,
31+
)
32+
33+
event_names = [name for _, name in mission.timeline]
34+
35+
assert "liftoff" in event_names
36+
assert any(name.startswith("ignition:") for name in event_names)
37+
assert any(name.startswith("impact:") for name in event_names)
38+
assert not any("separation" in name or "ejection" in name for name in event_names)
39+
40+
41+
def test_mission_uses_the_stage_name_as_the_flights_key(calisto, example_plain_env):
42+
stage = Stage(name="first_stage", rocket=calisto)
43+
vehicle = MultiStageRocket(stages=[stage])
44+
45+
mission = Mission(
46+
vehicle=vehicle,
47+
environment=example_plain_env,
48+
rail_length=5.2,
49+
inclination=85,
50+
heading=0,
51+
)
52+
53+
assert list(mission.flights.keys()) == ["first_stage"]

0 commit comments

Comments
 (0)