env
cosmic_warp.rl.env
Vectorized RL environment.
:class:VecEnv wraps a :class:~cosmic_warp.core.pipeline.SpacecraftSimulator
and adds a fused, fully on-device RL step:
action -> ingest -> physics -> reward -> done -> observation -> auto-reset
Everything stays on the GPU. The whole step is captured once into a CUDA graph
and replayed, so per-step launch overhead is eliminated and there is no
host synchronization inside :meth:step. Boundary tensors (action, obs,
reward) are float32; the physics stays float64 internally.
The step returns (obs, reward, terminated, truncated) as Warp arrays.
terminated and truncated are kept separate (never collapsed into a
single done) so trainers can bootstrap truncated episodes correctly;
:attr:terminal_obs holds the pre-reset observation for that.
Trainer interop is deliberately out of scope here: the arrays are exposed
natively and via zero-copy *_torch() views (dlpack, same GPU memory),
and trainer-specific adapters live separately so this core stays neutral.
VecEnv
VecEnv(
sim: SpacecraftSimulator,
task: Task,
max_episode_steps: int,
)
Vectorized, GPU-resident RL environment over a spacecraft simulator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim
|
SpacecraftSimulator
|
A constructed simulator (e.g. from |
required |
task
|
Task
|
The task defining action mapping, observation and reward. |
required |
max_episode_steps
|
int
|
Episode length after which an environment is truncated (time limit) and auto-reset, in [1, 2**31 - 1]. |
required |
Source code in cosmic_warp/rl/env.py
actions
class-attribute
instance-attribute
Normalized actions [N, act_dim] (f32), read by step().
terminal_obs
class-attribute
instance-attribute
Pre-reset observations [N, obs_dim] (f32) of the last step.
reward
class-attribute
instance-attribute
Rewards [N] (f32) of the last step.
terminated
class-attribute
instance-attribute
Terminated flags [N] (bool) of the last step.
truncated
class-attribute
instance-attribute
Truncated (time-limit) flags [N] (bool) of the last step.
max_episode_steps
property
writable
Episode length after which an environment is truncated and auto-reset. Setting it re-captures the step graph on the next step.
reset
Reset every environment and return the initial observation [N, O].
Source code in cosmic_warp/rl/env.py
step
Advance every environment by one control step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
Optional[array]
|
Normalized actions |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Returns:
| Type | Description |
|---|---|
array
|
|
array
|
reused buffers — copy into trainer storage each step, do not retain |
array
|
a view across steps. |
Source code in cosmic_warp/rl/env.py
invalidate_graph
Drop the captured CUDA graph so the next :meth:step re-captures it.
The capture bakes in every scalar passed by value to a kernel launch
(task parameters such as reward weights) and the
randomizer.enabled branch. Call this after changing any of them
mid-run; otherwise the change silently has no effect on CUDA. Setting
:attr:max_episode_steps calls it for you.