unisim.backend.isaacgym.backend

IsaacGym specialization of the shared MJCF subprocess host adapter.

IsaacGym Preview 4 runs in an external Python 3.8 process. The shared owner layer supplies pipe/shm lifecycle, MJCF metadata, selected reset, NumPy state views, and native-render command plumbing; this module only selects the IsaacGym runtime and worker entrypoint.

Classes

IsaacGymBackend

NumPy-facing SimBackend client for the IsaacGym worker.

IsaacGymModelInfo

Opaque metadata returned by the IsaacGym worker handshake.

Exceptions

IsaacGymWorkerError

Raised when the external IsaacGym worker fails.

class unisim.backend.isaacgym.backend.IsaacGymBackend[source]

Bases: MjcfSubprocessBackend

NumPy-facing SimBackend client for the IsaacGym worker.

Parameters:
__init__(scene, num_envs, sim_dt, *, env_spacing=4.0, **kwargs)[source]
Parameters:
get_dr_capabilities()[source]

Advertise mapped-scene reset DR and interval wrenches.

The model-file raw-MJCF path declares only the selected-reset PD-gain bridge; mapped entity scenes declare the reset terms the worker writes and reads back natively. Per-env gravity/dof_damping have no PhysX channel (sim-wide parameter, drive-only joint damping) and the multi-root scene has no single base target, so those terms stay unsupported. The host-plane sets cover torch.cpu payloads; the device plane (torch.cuda) carries the CUDA IPC PD-gain lane only.

Return type:

DomainRandomizationCapabilities

get_reset_term_default(term)[source]

Return per-environment variant-assigned mapped reset defaults.

Parameters:

term (str)

Return type:

ndarray

apply_interval_randomization(plan)[source]

Apply a scheduled interval randomization plan.

Generic dispatch: each op yielded by plan.iter_ops() is validated against the builtin term specs (custom terms pass through) and routed to the backend-owned handler table returned by _interval_term_handlers(). Op payloads are torch-first: Torch tensors or TensorIntervalPayload values produced by the caller; host adapters convert tensors at their private boundary through unisim.dr._host, and a missing producer-sampled payload fails closed. A term without a handler fails closed with NotImplementedError naming the backend class and the term. Backends that need per-plan prologue/epilogue semantics (for example clearing staged external forces before the ops accumulate) keep a thin override that calls this base implementation.

Parameters:

plan (IntervalRandomizationPlan)

Return type:

None

apply_body_force(body_ids, force, torque=None)[source]

Stage a world-frame wrench for the next mapped-scene step.

The force acts at each target body’s center of mass and the optional torque is about that center. Repeated submissions accumulate until the next successful step consumes them.

Parameters:
Return type:

None

get_playback_model(env_index=None)[source]

Return the playback model source used by detached MuJoCo replay.

Whole-MJCF (raw) scenes replay through their construction source and mapped entity scenes through the composed MJCF; fixed-variant scenes follow the Drake contract — an explicit env_index is required and the row’s assigned variant source is returned.

Parameters:

env_index (int | None)

Return type:

Any

get_play_capabilities()[source]

Return backend-native play/render capabilities.

Return type:

PlayCapabilities

get_physics_state_layout()[source]

Return the snapshot layout; unsupported scene shapes fail closed.

Return type:

PhysicsStateLayout

get_physics_state()[source]

Assemble contract [time, qpos, qvel, (mocap)?] rows in MuJoCo layout.

The worker owns the physics state; one GET_PHYSICS_STATE request returns the canonical [qpos, qvel, (mocap_pos, mocap_quat)?] block for every environment in a single reply frame (no out-of-band channel and no per-env round trips). The leading time column is the host-side per-env accumulator because the worker protocol carries no simulation clock.

Return type:

ndarray

set_physics_state(state)[source]

Restore a get_physics_state snapshot through the set_state path.

Parameters:

state (ndarray)

Return type:

None

get_playback_mocap_state(env_index=0)[source]

Return copied (mocap_pos, mocap_quat) rows for detached playback.

Parameters:

env_index (int)

Return type:

tuple[ndarray, ndarray]

reset_entities(request)[source]

Validate the complete selected-entity request, then commit it once.

Validation failure leaves all state unchanged. A native partial commit failure must fault the backend unless the adapter can actually roll back. Unselected entities/environments and fixed identity remain unchanged.

Parameters:

request (SceneResetRequest)

Return type:

None

get_tensor_execution()[source]

Declare the optional tensor lifecycle without discovering SDKs.

Return type:

TensorExecution

get_tensor_capabilities()[source]

Return fail-closed tensor methods and negotiable state fields.

Return type:

TensorLifecycleCapabilities

compile_cuda_ipc_io(device=None)[source]
Parameters:

device (Any | None)

Return type:

IsaacGymCudaIpcPlan

get_state_views(fields=None, device=None)[source]

Return backend-owned state through the declared tensor lifecycle.

Tensor views are Torch tensors. Returned values are logically read-only and mutation is undefined.

DEVICE_RESIDENT adapters return stable live views on the backend’s exact accelerator device; device=None selects that device and any other device is rejected. HOST_BRIDGE adapters return explicit copies from authoritative host state; device=None selects host CPU and callers pass an explicit accelerator device for H2D copies. Unlike the removed 1.x NumPy snapshot API, successful tensor adapters do not return NumPy arrays. Consume the declared tensor execution mode rather than probing the array implementation.

Parameters:
Return type:

Mapping[str, Any]

get_public_state_widths()[source]

Return the synthetic raw-MJCF public tensor state widths.

Return type:

PublicStateWidths

get_sensor_view(name, device=None)[source]

Return one named sensor view on the declared tensor lifecycle.

Parameters:
Return type:

Any

step_tensor(ctrl, nsteps=1)[source]

Advance physics from a backend-declared accelerator control tensor.

ctrl is a contiguous float32 Torch tensor with shape (num_envs, num_actuators), lives on the adapter-required device, and must be finite. The method consumes it before synchronizing and returning.

Parameters:
Return type:

dict[str, dict[str, float]]

set_state_tensor(env_indices, qpos, qvel, randomization=None)[source]

Set selected state through the adapter-declared tensor lifecycle.

env_indices is a contiguous one-dimensional int64 Torch tensor with unique values in [0, num_envs); qpos and qvel are contiguous float32 tensors with shapes (len(env_indices), nq) and (len(env_indices), nv). All three share one adapter-accepted device and must be finite. Adapters may use a bounded synchronization for fail-closed row validation. DEVICE_RESIDENT adapters otherwise avoid a host detour; HOST_BRIDGE adapters make their explicit accelerator-to-host boundary measurable before CPU state is updated. Inputs are consumed before return.

randomization is the unified torch-first TensorResetRandomizationPayload: every populated field is a dense selected-row Torch tensor table. Tensors on torch.cpu form the host plane, checked against DomainRandomizationCapabilities.supported_reset_terms; tensors on any other device form the device plane, checked against supported_device_reset_terms (empty by default, so undeclared device support fails closed naming the term). Non-delta terms hold final absolute values applied as selected-row in-place scatters; base_mass_delta and base_com_offset hold deltas merged with the adapter baseline. Host adapters convert tensors at their private NumPy boundary through unisim.dr._host.

Parameters:
Return type:

dict[str, dict[str, float]]

set_state_tensor_mask(reset_mask, qpos, qvel, randomization=None, *, full_refresh=False)[source]

Commit full-width state through a backend-owned mask projection.

Parameters:
Return type:

dict[str, dict[str, float]] | None

bind_packed_reset(*, device=None)[source]

Begin a packed transaction over the external CUDA IPC reset boundary.

Parameters:

device (Any | None)

Return type:

Any

close()[source]

Shut down the worker and release shared memory. Idempotent.

Return type:

None

class unisim.backend.isaacgym.backend.IsaacGymModelInfo[source]

Bases: SubprocessModelInfo

Opaque metadata returned by the IsaacGym worker handshake.

Parameters:
__init__(num_dof, num_bodies, dof_names, body_names, gravity, use_gpu_pipeline)
Parameters:
exception unisim.backend.isaacgym.backend.IsaacGymWorkerError[source]

Bases: SubprocessWorkerError

Raised when the external IsaacGym worker fails.

Parameters: