unisim.backend.genesis.materialization¶
Cold-path scene materialization for the independent genesis backend.
Genesis 1.3.3 drops three MJCF features UniLab relies on, as measured in
the Genesis 1.3.3 feasibility audit (#1372 §3): <keyframe>,
the global <option> block, and the whole <sensor> block. This module
compensates on the cold path exactly as the report prescribes: keyframe and
sensor metadata are scanned once with the mujoco package (the isaacgym
parent-process metadata-scan pattern) and cached — hot paths never parse XML;
global options arrive as explicit owner fields; and gs.init host-side
effects (torch default device/dtype and RNG) are contained by
preserve_torch_globals() plus the one-session-per-process guard.
Functions
|
Construct the unbuilt Genesis scene with explicit global options. |
|
Tear down the process-wide session; re-initialization stays forbidden. |
Return Genesis 1.3.3's documented heterogeneous env/variant mapping. |
|
|
Initialize the process-wide Genesis session exactly once. |
|
Normalize common portable sources into independent Genesis MJCF files. |
|
Snapshot torch global defaults and restore them after |
|
Resolve the scene and scan MJCF metadata with the |
Scan composed sensors and freeze their complete identity across variants. |
|
Bind the bounded portable source and fragment sensor subsets. |
|
Require the exact mapping Genesis will materialize natively. |
Classes
MJCF metadata scanned once on the cold path (never on hot paths). |
|
Independent normalized MJCF sources for one public entity. |
|
Cold-path Genesis inputs derived from the common portable compiler. |
|
One MJCF sensor mapped onto a Genesis-readable equivalent. |
- class unisim.backend.genesis.materialization.GenesisSensorPlan[source]¶
Bases:
objectOne MJCF sensor mapped onto a Genesis-readable equivalent.
body_nameis the owning link for site sensors and the robot-side geom body for contact sensors.site_pos/site_quat(wxyz) are the local site frame in the body frame; both areNonefor contact and portable body frame fragment sensors. Contact sensors additionally retain both final geom names and whether the common fragment form is exact pair netforce, so portable validation can bind them without source-model array indices.- Parameters:
- __init__(name, kind, dim, body_name, object_name, reference_type, reference_id, site_pos, site_quat, contact_geom1_name=None, contact_geom2_name=None, contact_netforce=False, object_kind='site')¶
- class unisim.backend.genesis.materialization.GenesisModelMetadata[source]¶
Bases:
objectMJCF metadata scanned once on the cold path (never on hot paths).
- Parameters:
source_model_file (
str)nq (
int)nv (
int)nbody (
int)root_qpos_dim (
int)root_qvel_dim (
int)geom_sizes (
ndarray)actuator_ctrl_range (
ndarray)actuator_kp (
ndarray)actuator_kv (
ndarray)default_qpos (
ndarray)default_qvel (
ndarray)default_ctrl (
ndarray)dof_armature (
ndarray)gravity (
ndarray)body_mass (
ndarray)body_ipos (
ndarray)body_inertia (
ndarray)body_iquat (
ndarray)body_pos (
ndarray)body_quat (
ndarray)sensor_plans (
tuple[GenesisSensorPlan,...])
-
sensor_plans:
tuple[GenesisSensorPlan,...]¶
- __init__(source_model_file, cleanup_handle, nq, nv, nbody, root_qpos_dim, root_qvel_dim, joint_names, joint_qpos_adrs, joint_dof_adrs, body_names, geom_names, geom_body_names, geom_types, geom_sizes, actuator_names, actuator_joint_names, actuator_ctrl_range, actuator_kp, actuator_kv, keyframe_qpos, default_qpos, default_qvel, default_ctrl, joint_range, dof_armature, gravity, body_mass, body_ipos, body_inertia, body_iquat, body_pos, body_quat, sensor_plans)¶
- Parameters:
source_model_file (
str)nq (
int)nv (
int)nbody (
int)root_qpos_dim (
int)root_qvel_dim (
int)geom_sizes (
ndarray)actuator_ctrl_range (
ndarray)actuator_kp (
ndarray)actuator_kv (
ndarray)default_qpos (
ndarray)default_qvel (
ndarray)default_ctrl (
ndarray)dof_armature (
ndarray)gravity (
ndarray)body_mass (
ndarray)body_ipos (
ndarray)body_inertia (
ndarray)body_iquat (
ndarray)body_pos (
ndarray)body_quat (
ndarray)sensor_plans (
tuple[GenesisSensorPlan,...])
- class unisim.backend.genesis.materialization.GenesisPortableEntitySource[source]¶
Bases:
objectIndependent normalized MJCF sources for one public entity.
-
metadata:
tuple[GenesisModelMetadata,...]¶
-
metadata:
- class unisim.backend.genesis.materialization.GenesisPortableSources[source]¶
Bases:
objectCold-path Genesis inputs derived from the common portable compiler.
- Parameters:
entities (
tuple[GenesisPortableEntitySource,...])cleanup_handle (
Any)
-
entities:
tuple[GenesisPortableEntitySource,...]¶
- __init__(entities, cleanup_handle)¶
- Parameters:
entities (
tuple[GenesisPortableEntitySource,...])cleanup_handle (
Any)
- unisim.backend.genesis.materialization.genesis_balanced_variant_mapping(num_variants, num_envs)[source]¶
Return Genesis 1.3.3’s documented heterogeneous env/variant mapping.
Genesis dispatches variants in contiguous balanced blocks (the first remainder-sized block gets one extra environment). This local owner-side implementation deliberately does not call Genesis’ private solver helper; construction accepts an assignment only when it is exactly this mapping.
- unisim.backend.genesis.materialization.validate_genesis_variant_assignment(assignment, num_variants)[source]¶
Require the exact mapping Genesis will materialize natively.
- unisim.backend.genesis.materialization.prepare_genesis_portable_sources(mujoco, scene, layout)[source]¶
Normalize common portable sources into independent Genesis MJCF files.
The common compiler remains the sole layout, identity, and source relationship authority. This owner adapter only serializes each already normalized
MjSpecand scans the resulting source for native binding.- Parameters:
- Return type:
- unisim.backend.genesis.materialization.validate_genesis_portable_sensor_plans(mujoco, sources, layout, composed_plans)[source]¶
Bind the bounded portable source and fragment sensor subsets.
Genesis does not import MJCF sensors. Portable support is deliberately limited to entity-owned site
FramePos,FrameQuat,Gyro,Velocimeterand identity-orientationAccelerometerdeclarations whose complete semantic identity is identical in every source variant. The returned plans use qualified public sensor/body names; the backend computes pose/motion values from audited native link state and accelerometer values from a clean public native IMU.Scene-level fragments are limited further to world-referenced qualified-site and qualified-body
FramePos/FrameQuatdeclarations, world-referenced qualified-site/bodyFrameLinVel/FrameAngVeldeclarations, and exact cross-entity geom-pairfound/netforcecontact declarations. The common compiler appends them after all entity-owned source sensors, so the composed prefix must match the independently audited source plans exactly.- Parameters:
mujoco (
Any)sources (
GenesisPortableSources)layout (
Any)composed_plans (
tuple[GenesisSensorPlan,...])
- Return type:
- unisim.backend.genesis.materialization.scan_genesis_portable_composed_metadata(mujoco, composed)[source]¶
Scan composed sensors and freeze their complete identity across variants.
- Parameters:
- Return type:
- unisim.backend.genesis.materialization.preserve_torch_globals(torch)[source]¶
Snapshot torch global defaults and restore them after
gs.init.gs.initmutates the host process: it forcestorch.set_default_device("cuda:0")on the GPU lane, and passingseed=would reseed the global RNG (REPORT #1372 §3.5 [10]). The adapter never passes a seed and restores default device/dtype plus the torch RNG state so the training process observes no pollution (REPORT #1372 §5.8).
- unisim.backend.genesis.materialization.init_genesis_session(deps, *, device_id=None, logging_level='warning')[source]¶
Initialize the process-wide Genesis session exactly once.
Repeated
init -> destroycycles are functional but leak 200-450 MB of host RSS per cycle (REPORT #1372 §3.5 [9a]), so a long-lived training process gets exactly one session. Multiple GenesisBackend instances share the live session (multi-scene coexistence is measured OK, REPORT [9b]); afterdestroy_genesis_session()any further construction fails closed with a clear error.
- unisim.backend.genesis.materialization.destroy_genesis_session(deps)[source]¶
Tear down the process-wide session; re-initialization stays forbidden.
- unisim.backend.genesis.materialization.build_scene(deps, *, sim_dt, gravity, integrator, constraint_solver, friction_cone, solver_iterations)[source]¶
Construct the unbuilt Genesis scene with explicit global options.