randomization
cosmic_warp.core.randomization
Domain randomization of per-entity vehicle parameters.
Parameters are resampled entirely on the GPU whenever entities are reset, from counter-based per-entity streams like ResetManager's (on their own stream id, cosmic_warp.core.rng), so randomization stays valid inside CUDA graph captures (reset_terminated / simulate(auto_reset_terminated=True)).
Sampling respects the physical couplings
- Propellant is sampled, not total mass: state mass = mass_dry + propellant, so entities can never spawn below dry mass (which the dynamics would silently clamp to "out of propellant").
- Mass randomization preserves the velocity, not the momentum: the state's momentum is rescaled by new_mass / old_mass, so the sampled trajectory (in particular an orbit drawn in orbital-element reset mode) is unchanged by how much propellant the vehicle carries.
- The inertia tensor is randomized through a scalar scale factor applied to the body's nominal tensor, preserving symmetry, positive definiteness and the triangle inequality of the principal moments.
RandomizationConfig
Per-body uniform sampling bounds. A field is active when its flag is nonzero.
DomainRandomizer
DomainRandomizer(
num_envs: int,
vehicle: VehicleManager,
device: str = "cuda",
num_bodies: int = 1,
seed: int = 1234,
)
Resamples vehicle parameters (and propellant load) per entity on reset.
Bounds are per body and broadcast across environments; every entity draws its own values from its body's bounds. Inertia scaling applies to each entity's own configured (nominal) tensor, so per-environment inertia is kept; a later vehicle.set_config takes effect at the next sim.reset(), reset_terminated(), simulate() or RL VecEnv.step().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_envs
|
int
|
Number of parallel environments |
required |
vehicle
|
VehicleManager
|
The simulator's VehicleManager |
required |
device
|
str
|
Device to run on |
'cuda'
|
num_bodies
|
int
|
Number of bodies per environment |
1
|
seed
|
int
|
RNG seed for parameter sampling |
1234
|
Source code in cosmic_warp/core/randomization.py
reseed
Restart the per-entity RNG streams at draw 0 of seed (an
integer in [0, 2**64)).
set_bounds
set_bounds(
*,
mass_dry: tuple = None,
propellant: tuple = None,
inertia_scale: tuple = None,
body_ids: list = None,
) -> None
Enable randomization of vehicle parameters for specific bodies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass_dry
|
tuple
|
(min, max) dry mass [kg]. Requires |
None
|
propellant
|
tuple
|
(min, max) propellant mass [kg], sampled on top of the (possibly randomized) dry mass: state mass = dry + propellant. |
None
|
inertia_scale
|
tuple
|
(min, max) scale factor applied to each entity's configured (nominal) inertia tensor. |
None
|
body_ids
|
list
|
List of body indices to configure (None = all bodies) |
None
|
Source code in cosmic_warp/core/randomization.py
get_bounds
The bounds set for one body, as {name: (min, max)}; a parameter absent from the dict is not randomized. A copy: edit with set_bounds.
Source code in cosmic_warp/core/randomization.py
sync_nominal
Upload the configured inertia as the nominal for inertia scaling, if it changed since the last upload (host-side check, no device read). Called by set_bounds, sim.reset(), reset_terminated() (outside a capture), simulate() and the RL VecEnv.step().
Source code in cosmic_warp/core/randomization.py
randomize_all
Resample randomized parameters for all entities.
Source code in cosmic_warp/core/randomization.py
randomize_masked
Resample randomized parameters for masked entities (graph-safe).
Source code in cosmic_warp/core/randomization.py
randomize_kernel
randomize_kernel(
states: array(dtype=State),
vehicles: array(dtype=VehicleConfig),
config: array(dtype=RandomizationConfig),
rng_state: array(dtype=RNG_STATE),
inertia_nominal: array(dtype=mat33d),
inertia_inv_nominal: array(dtype=mat33d),
num_bodies: int32,
) -> None
Resample randomized parameters for all entities.
Source code in cosmic_warp/core/randomization.py
randomize_masked_kernel
randomize_masked_kernel(
states: array(dtype=State),
vehicles: array(dtype=VehicleConfig),
config: array(dtype=RandomizationConfig),
rng_state: array(dtype=RNG_STATE),
inertia_nominal: array(dtype=mat33d),
inertia_inv_nominal: array(dtype=mat33d),
mask: array(dtype=bool),
num_bodies: int32,
) -> None
Resample randomized parameters for masked entities only.