Skip to content

state

cosmic_warp.core.state

State

Dynamic state variables for spacecraft states (float64).

allocate_state

allocate_state(
    num_envs, num_bodies: int = 1, device: str = "cuda"
)

Allocate state storage for all environments and bodies.

States are stored in a flat array of length num_envs * num_bodies. Use entity_id = env_id * num_bodies + body_id for indexing.

Source code in cosmic_warp/core/state.py
def allocate_state(num_envs, num_bodies: int = 1, device: str = "cuda"):
    """
    Allocate state storage for all environments and bodies.

    States are stored in a flat array of length num_envs * num_bodies.
    Use entity_id = env_id * num_bodies + body_id for indexing.
    """
    return wp.zeros(num_envs * num_bodies, dtype=State, device=device)