reset
cosmic_warp.core.reset
Reset functionality for initializing/resetting simulation environments.
Random sampling draws from counter-based per-entity streams kept in device memory (cosmic_warp.core.rng), so repeated resets draw fresh values and remain valid inside CUDA graph captures.
ResetConfig
Configuration for environment reset (dynamic state only).
ResetManager
ResetManager(
num_envs: int,
device: str = "cuda",
num_bodies: int = 1,
pos_bounds: tuple = None,
mom_bounds: tuple = None,
ang_mom_bounds: tuple = None,
mass_bounds: tuple = None,
att_nominal: tuple = None,
att_max_angle: float = None,
seed: int = 42,
vel_bounds: tuple = None,
)
Manages entity resets with configurable initial conditions.
Initialize reset manager.
The bounds are used for random sampling (overridden by reset_to_conditions).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_envs
|
int
|
Number of parallel environments |
required |
device
|
str
|
Device to run on |
'cuda'
|
num_bodies
|
int
|
Number of bodies per environment |
1
|
pos_bounds
|
tuple
|
(min, max) position bounds [m] |
None
|
mom_bounds
|
tuple
|
(min, max) momentum bounds [kg*m/s] |
None
|
vel_bounds
|
tuple
|
(min, max) velocity bounds [m/s], alternative to mom_bounds: momentum = sampled mass * sampled velocity, so the bounds hold for any mass. Default: circular 400 km LEO speed along +Y, +/- 1 m/s |
None
|
ang_mom_bounds
|
tuple
|
(min, max) angular momentum bounds [kg*m^2/s] |
None
|
mass_bounds
|
tuple
|
(min, max) mass bounds [kg] |
None
|
att_nominal
|
tuple
|
nominal attitude quaternion (x, y, z, w), default identity |
None
|
att_max_angle
|
float
|
attitude cone half-angle [rad] around att_nominal, in [0, pi]. Default pi = uniform over SO(3); 0 = always exactly att_nominal |
None
|
seed
|
int
|
RNG seed for random initial conditions |
42
|
Source code in cosmic_warp/core/reset.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
reseed
Restart the per-entity RNG streams of the reset sampler at draw 0
of seed (an integer in [0, 2**64)).
set_bounds
set_bounds(
*,
pos_bounds: tuple = None,
vel_bounds: tuple = None,
mom_bounds: tuple = None,
ang_mom_bounds: tuple = None,
mass_bounds: tuple = None,
att_nominal: tuple = None,
att_max_angle: float = None,
body_ids: list = None,
) -> None
Override reset sampling bounds for specific bodies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos_bounds
|
tuple
|
(min, max) position bounds [m] (None = keep current) |
None
|
vel_bounds
|
tuple
|
(min, max) velocity bounds [m/s]; momentum = sampled mass * sampled velocity. Setting one of mom_bounds/vel_bounds replaces the other (None = keep current) |
None
|
mom_bounds
|
tuple
|
(min, max) momentum bounds [kg*m/s] (None = keep current) |
None
|
ang_mom_bounds
|
tuple
|
(min, max) angular momentum bounds [kg*m^2/s] (None = keep current) |
None
|
mass_bounds
|
tuple
|
(min, max) mass bounds [kg] (None = keep current) |
None
|
att_nominal
|
tuple
|
nominal attitude quaternion (x, y, z, w) (None = keep current) |
None
|
att_max_angle
|
float
|
attitude cone half-angle [rad] around att_nominal, in [0, pi]; pi = uniform over SO(3), 0 = always exactly att_nominal (None = keep current) |
None
|
body_ids
|
list
|
List of body indices to configure (None = all bodies) |
None
|
Source code in cosmic_warp/core/reset.py
set_orbit_bounds
set_orbit_bounds(
*,
semi_major_axis_bounds: tuple = None,
altitude_bounds: tuple = None,
eccentricity_bounds: tuple = None,
inclination_bounds: tuple = None,
raan_bounds: tuple = None,
arg_periapsis_bounds: tuple = None,
true_anomaly_bounds: tuple = None,
mean_anomaly_bounds: tuple = None,
body_ids: list = None,
) -> None
Sample orbital elements instead of Cartesian boxes for specific bodies.
Enables orbit sampling mode: on every reset each element is drawn uniformly within its bounds and converted to an ECI state entirely on device, so position and momentum are always dynamically consistent (momentum = mass * velocity). pos_bounds and mom_bounds are ignored in this mode; angular momentum, mass and attitude sampling apply unchanged. Angles in radians; the orbits are about Earth (MU_EARTH, the value the dynamics use).
Unspecified elements keep their current values (defaults: a circular 400 km LEO orbit, uniform true anomaly). Use set_sample_mode to switch a body back to Cartesian sampling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
semi_major_axis_bounds
|
tuple
|
(min, max) semi-major axis [m] |
None
|
altitude_bounds
|
tuple
|
(min, max) altitude above the Earth equatorial radius [m] (alternative to semi_major_axis_bounds) |
None
|
eccentricity_bounds
|
tuple
|
(min, max) eccentricity, within [0, 1) |
None
|
inclination_bounds
|
tuple
|
(min, max) inclination [rad], within [0, pi] |
None
|
raan_bounds
|
tuple
|
(min, max) right ascension of the ascending node [rad] |
None
|
arg_periapsis_bounds
|
tuple
|
(min, max) argument of periapsis [rad] |
None
|
true_anomaly_bounds
|
tuple
|
(min, max) true anomaly [rad] |
None
|
mean_anomaly_bounds
|
tuple
|
(min, max) mean anomaly [rad] — uniform in time along the orbit (alternative to true_anomaly_bounds) |
None
|
body_ids
|
list
|
List of body indices to configure (None = all bodies) |
None
|
Source code in cosmic_warp/core/reset.py
set_sample_mode
Switch bodies between "cartesian" (box) and "orbit" (element) sampling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
"cartesian" or "orbit" |
required |
body_ids
|
list
|
List of body indices to configure (None = all bodies) |
None
|
Source code in cosmic_warp/core/reset.py
get_bounds
The reset bounds of one body, keyed by the set_bounds and set_orbit_bounds argument names, plus "sample_mode" ("cartesian" or "orbit"). The momentum box is under vel_bounds or mom_bounds, whichever is set, and the anomaly under true_anomaly_bounds or mean_anomaly_bounds; an altitude is reported as its semi_major_axis_bounds. Bounds are tuples of floats. A copy: edit with set_bounds, set_orbit_bounds and set_sample_mode.
Source code in cosmic_warp/core/reset.py
build_mask
Fill the reusable selection mask from id selections.
Reuses preallocated buffers, so no device memory is allocated. The returned array is shared between calls: consume it before calling build_mask again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env_ids
|
list
|
List of environment indices (None = no selection) |
None
|
body_ids
|
list
|
List of body indices (None = all bodies) |
None
|
entity_ids
|
list
|
Optional flat entity indices (env_id * num_bodies + body_id) |
None
|
Returns:
| Type | Description |
|---|---|
array
|
Bool mask array [num_entities], or None when the selection is empty |
Source code in cosmic_warp/core/reset.py
reset_all
reset_all(states: array(dtype=State)) -> None
Reset all environments to random initial conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
states
|
array(dtype=State)
|
WARP array of State structs to reset |
required |
Source code in cosmic_warp/core/reset.py
reset_masked
reset_masked(
states: array(dtype=State), mask: array(dtype=bool)
) -> None
Reset specific entities using a boolean mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
states
|
array(dtype=State)
|
WARP array of State structs |
required |
mask
|
array(dtype=bool)
|
WARP array of bools where True indicates entity to reset |
required |
Source code in cosmic_warp/core/reset.py
check_orbit_defaults
check_orbit_defaults(
env_ids: list = None,
body_ids: list = None,
entity_ids: list = None,
) -> None
Reject default positions/momenta for the selected orbit-sampled bodies.
The reset_to_conditions defaults are the Cartesian bound centers, which for a body configured via set_orbit_bounds are stale leftovers rather than a state on the configured orbits.
Source code in cosmic_warp/core/reset.py
check_conditions
Check reset_to_conditions arrays on their metadata (no device read): a Warp array of the field's dtype, of length num_entities, on this manager's device. A kernel would read a short array past its end, and an array on another device cannot be launched with.
Source code in cosmic_warp/core/reset.py
reset_to_conditions
reset_to_conditions(
states: array(dtype=State),
positions: array = None,
momenta: array = None,
angular_momenta: array = None,
quaternions: array = None,
masses: array = None,
mask: array = None,
) -> None
Reset entities to specific conditions (dynamic state only).
The condition arrays are always indexed by flat entity id, so they keep the full [num_entities] length even when resetting a subset. Only the arrays' metadata is checked here; sim.reset_to_conditions also checks the values, the selection and orbit-mode bodies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
states
|
array(dtype=State)
|
WARP array of State structs |
required |
positions
|
array
|
WARP array of positions [num_entities] (vec3d), None uses ResetConfig center |
None
|
momenta
|
array
|
WARP array of momenta [num_entities] (vec3d), None uses ResetConfig center |
None
|
angular_momenta
|
array
|
WARP array of angular momenta [num_entities] (vec3d), None uses ResetConfig center |
None
|
quaternions
|
array
|
WARP array of quaternions [num_entities] (quatd), normalized on write; None uses identity |
None
|
masses
|
array
|
WARP array of masses [num_entities] (float64), None uses ResetConfig center |
None
|
mask
|
array
|
Bool mask [num_entities] selecting the entities to reset; None resets all |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if an array is not a Warp array of the listed dtype, of length num_entities, on this manager's device. |
Source code in cosmic_warp/core/reset.py
reset_random_kernel
reset_random_kernel(
states: array(dtype=State),
config: array(dtype=ResetConfig),
vehicles: array(dtype=VehicleConfig),
rng_state: array(dtype=RNG_STATE),
episode_steps: array(dtype=int32),
num_bodies: int32,
) -> None
Reset all environments with random initial conditions (dynamic state only).
Source code in cosmic_warp/core/reset.py
reset_masked_kernel
reset_masked_kernel(
states: array(dtype=State),
config: array(dtype=ResetConfig),
vehicles: array(dtype=VehicleConfig),
rng_state: array(dtype=RNG_STATE),
mask: array(dtype=bool),
episode_steps: array(dtype=int32),
num_bodies: int32,
) -> None
Reset only masked environments (dynamic state only).
Also the device path of reset_terminated, simulate(auto_reset_terminated) and the RL VecEnv, none of which can raise: a mass_bounds minimum below the dry mass (rejected by sim.reset(), but possible after a later set_bounds) spawns at the dry mass rather than below it.
Source code in cosmic_warp/core/reset.py
reset_to_conditions_kernel
reset_to_conditions_kernel(
states: array(dtype=State),
config: array(dtype=ResetConfig),
vehicles: array(dtype=VehicleConfig),
positions: array(dtype=vec3d),
momenta: array(dtype=vec3d),
angular_momenta: array(dtype=vec3d),
quaternions: array(dtype=quatd),
masses: array(dtype=float64),
mask: array(dtype=bool),
episode_steps: array(dtype=int32),
num_bodies: int32,
) -> None
Reset to specific or default conditions (dynamic state only).
An empty mask (shape 0) selects all entities.