# G1 policy: source and numerical baseline

Selected policy: **aiming**, artifact **p_83d20024f64bdb5eac501fd9**, trained run `g1_mix_aiming/2026-08-15_04-51-42_mix-aiming`. This is a 100-frame, 2-second motion (aim stance and pivot), not a general velocity-command walker. It is useful as a bounded, evaluated motion integration case with a known start state.

## Status and evidence

- Trained: real saved RSL-RL PPO actor; original ONNX and cached fused wrapper are retained unchanged.
- Evaluated: historical automated `good` verdict, August 15, references `model_9999.pt` and a 60-second rollout. Read `historical-evaluation.json` for the complete diagnosis.
- Approved: cached artifact records **legacy experiment-level acceptance only**. Checkpoint-specific human approval and video-to-ONNX identity are not established. Current authoritative API state was unavailable (local gateway timed out once); no approval was changed.
- New local verification: one 100-tick / 400-step / 2-second CPU MuJoCo rollout, plus seven standalone ONNX vectors. All states finite; pelvis height 0.6949384748–0.8194354773m, final height 0.7192651164m. Maximum raw/fused action discrepancy 2.86102294921875e-6.
- This is a numerical integration baseline, not browser, transition, obstacle, or hardware qualification. Generating the source fixture did not train or modify a policy.

## Source fixture inventory

This table describes the original local fixture, not the contents of the portable project. The shipped `public/motions/g1-aiming.lucky.zip` contains the prepared ONNX, robot archive and scene. Numeric CPU references are retained in `tests/fixtures/mjlab-g1`; model/robot bytes used by the tests come from the shipped ZIP.

| File | Role |
|---|---|
| `aiming/aiming.onnx` | Unchanged primary fused graph (float32 101 -> 29 actions plus reference outputs). |
| `aiming/aiming.raw.onnx` | Unchanged original actor/reference graph (160 observations + frame). |
| `aiming/model_config.json`, `aiming/policy_descriptor.aiming.json` | Original package metadata; scales/gains rounded to three decimals. |
| `controller.full-precision.json` | Ordered full-precision controller values recovered from this run's saved `env.yaml`; use for the numeric physics baseline. |
| `robot/g1.xml`, `robot/assets/` | Byte-identical local source robot geometry, inertia, meshes, joint limits, sites, sensors and exclusions. |
| `robot/scene.xml` | Nominal stand-alone scene: exact source robot plus plane, saved run gains/armature, force limits, collision configuration, 5ms implicitfast integration, frame-0 keyframe. |
| `robot/compiled-contract.json` | Verified MuJoCo sizes, joint/actuator addresses, gains, biases and armature. |
| `initial-state.json` | Reference frame-0 qpos, qvel, joint order, zero prior action and clock. |
| `embedded-reference.npz` | All reference arrays extracted directly from the original graph, never substituted from a current motion file. |
| `inference-vectors.json` | Seven deterministic fused/raw inputs and expected outputs, generated with CPU ONNX Runtime. These hold frame-0 physical state while varying reference time. |
| `cpu-rollout.json` | Actual nominal CPU rollout: every observation, action, target, qpos, qvel, clock, frame and contact count. |
| `fused.graph.json`, `raw.graph.json` | Exact tensor interfaces, graph metadata, operators and model hashes. |
| `provenance.json`, `SHA256SUMS` | Source identities, status limits and fixture checksums. |

The original training run saved its robot factory and configuration, not its compiled randomized model. The source G1 XML has no working-tree modifications and its last commit predates the training run. `scene.xml` is explicitly a **reconstructed nominal scene**; randomization, pushes and episode resetting are omitted. It must not be represented as a hash-identical historical compiled training world. Exact full controller values are sourced from saved run configuration, not guessed from another G1 model. CPU MuJoCo and GPU Warp are different execution backends.

## Fused graph contract

Input `obs`, float32 `[1,101]`, metres / radians / seconds, right-handed MuJoCo z-up coordinates:

| Slice | Quantity |
|---|---|
| 0:3 | Linear velocity at **imu_in_pelvis site**, in site/pelvis local axes. The site offset is `(0.04525, 0, -0.08339)`; root-origin linear velocity is not interchangeable while rotating. |
| 3:6 | Angular velocity in that site's local axes. |
| 6:35 | Joint position minus default position, in `controller.full-precision.json` joint order. |
| 35:64 | Joint velocity in the same order. |
| 64:93 | Previous raw network action; zero on activation. |
| 93:96 | `torso_link` body-origin world position, expressed in the embedded reference frame. |
| 96:100 | `torso_link` world orientation, unit **wxyz** quaternion, in that frame. |
| 100 | Seconds since activation. |

Use native `imu_lin_vel` / `imu_ang_vel` sensors, or equivalent site velocity. MuJoCo `mj_objectVelocity(...SITE..., local=1)` returns angular components first and linear components second. Do not accidentally swap those in `obs`.

There is no temporal stack, recurrent state, external history buffer, observation clipping or host normalization. The actor's mean/std normalization is embedded in ONNX. The only feedback memory is prior raw action; neither PD targets nor clipped actions belong there. Training observation corruption is disabled for the deterministic fixture.

Outputs (all float32): `actions[1,29]`, `frame[1,1]`, `ref_root_pos_w[1,3]`, `ref_root_quat_w[1,4]`, `ref_joint_pos[1,29]`.

Frame lookup is `clamp(round(time*50)+1,0,99)`. ONNX Round uses nearest-even ties. At `time=0` the reference output is **frame 1**. For frame 0 use original raw `time_step=[[0]]`, or fused `time=-0.02` and verify output `frame==0`. Some preserved legacy README text incorrectly describes fused time=0 as frame0; `initial-state.json` is the corrected explicit reset fixture.

Opset 18, no custom-domain operators, no external data: Add, Cast, Clip, Concat, Constant, Div, Elu, Gather, Gemm, Mul, Reciprocal, ReduceSum, Reshape, Round, Slice, Split, Squeeze, Sub, Unsqueeze. The Clip operators clamp reference lookup, not policy actions. `2e-4` absolute/relative action tolerance is a suggested cross-runtime inference check, not a physics or safety tolerance.

## Controller and timing

50Hz inference; trained physics configuration is 0.005s with four physics steps per action. Apply each target for the full 20ms control interval:

`target = float32(default_joint_pos) + float32(action_scale) * raw_action`

Native MuJoCo position actuator: `torque = kp*(target-q) - kd*dq`, limited to `[-effort,+effort]`. The force derivatives participate in implicitfast integration. Do not replace this with once-per-control-tick external torque or add target/action clipping. Raw actions can exceed [-1,1]. Set armature and use named joint/actuator mapping. `scene.xml` actuator order is policy joint order; another robot's actuator order may differ.

The ordinary default stance has left/right hip pitch -0.312, knee +0.669, ankle pitch -0.363, shoulder pitch +0.2, shoulder roll +0.2/-0.2, elbow +0.6 rad; other joints zero. That stance is the action offset, **not the motion's activation pose**. All 29 precise defaults, scales, kp, kd, effort and armature entries are in the controller JSON. Examples: hip pitch scale 0.5475464629911068, kp 40.17923863450712, kd 2.557889775413375; knee scale 0.35066146637882434, kp 99.09842777666111, kd 6.308801853496639; shoulder scale 0.43857731392336724, kp 14.25062309787429, kd 0.907222843292423.

Legacy metadata rounds shoulder scale to 0.439, for example. Keep original graph metadata intact; use the separate exact controller file when comparing against this CPU rollout. Browser physics at 0.002s/10 substeps still yields 50Hz control but is a different integration discretization; do not claim per-step physics parity with this 0.005s reference.

## Entry, exit and raw graph

Initialize the **simulation verification case** from `initial-state.json` or scene keyframe `reference_frame0`, including root/joint velocities. Pelvis starts at `[0.002597635379061103,-0.00453528156504035,0.8194354772567749]`. Reset last_action to zero, clock to zero, compute current FK/sensors, then infer. The initial body pose and default action-offset pose are different. No valid controller-to-policy handoff from arbitrary standing has been established.

Keep reference and observations in the same world frame. The full embedded reference ends at frame99; time clamps there, with no automatic completion or validated loop/handoff. Legacy metadata reports endpoint joint difference 2.046rad and root drift 0.269m, so automatically resetting the timer would introduce a discontinuity. This fixture does not certify post-clip holding or a blend back to standing.

Raw graph inputs: float32 `obs[1,160]`, `time_step[1,1]`. Raw observation slices: reference joint positions 0:29; reference joint velocities 29:58; reference torso-position error expressed in actual torso frame 58:61; relative rotation first two columns flattened row-major 61:67 (`R00,R01,R10,R11,R20,R21`); pelvis-site local linear 67:70 and angular 70:73 velocities; q-default 73:102; dq 102:131; last raw action 131:160. Relative rotation is `R_actual_torso.T @ R_reference_torso`. Reference error uses torso origin, not pelvis origin.

## Original local artifacts

- Package: `/home/devrim/Projects/mjlab/logs/policy_catalog/packages/p_83d20024f64bdb5eac501fd9.zip`
- Run: `/home/devrim/Projects/mjlab/logs/rsl_rl/g1_mix_aiming/2026-08-15_04-51-42_mix-aiming/`
- Checkpoint: the run's `model_9999.pt` (not copied; no checkpoint reload required).
- Raw export: the run's `2026-08-15_04-51-42_mix-aiming.onnx`.
- Evaluation: `/home/devrim/Projects/mjlab/logs/queue/evals/g1_mix_aiming-2026-08-15_04-51-42_mix-aiming.json`
- Evaluation video: the run's `videos/play/rl-video-step-0.mp4` (availability checked separately in fixture verification).
- Robot: `/home/devrim/Projects/mjlab/src/mjlab/asset_zoo/robots/unitree_g1/xmls/g1.xml`

Reproduce locally with existing dependencies only: from `/home/devrim/Projects/mjlab`, run `CUDA_VISIBLE_DEVICES='' OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 uv run --no-sync --offline python -B /tmp/lucky-mjlab-policy-fixture/build_fixture.py`. This writes only within the fixture directory and performs one CPU rollout. `SHA256SUMS` excludes itself.

## Enriched web transport (requested integration variant)

Use **`aiming/aiming.web.onnx`** when the web importer requires explicit initialization velocities and physics timestep. This is a **metadata-only derivative**: original GraphProto bytes (all graph nodes, weights and reference arrays) are identical. Both exports produce bit-identical CPU outputs for all seven stored vectors. Original files remain unchanged.

- Original fused SHA-256: `71630649e93710afff1509c04c9aa817516fdb3a456df1a01c44215a92b64877`
- Web derivative SHA-256: `a962425c2a31fbd33270679e07913d22c91a6d22428f5af92997a0a89c82a75f`
- Robot-only ZIP SHA-256: `fdd33a04e3e3ae50f2a679e73c03c63a28805feb7d68008cb255c23df47f2d58`

`web-transport.json` records all metadata changes, source hashes, graph hash, robot archive entries and required physics options. Updated CSV29 fields are `default_joint_pos`, `action_scale`, `joint_stiffness`, `joint_damping`, plus `joint_armature` and `joint_effort_limit`. Added fields include `physics_dt=0.005`, `control_decimation=4`, `policy_hz=50.0`, `initial_qpos` CSV36, `initial_qvel` CSV35, `initial_last_action` CSV29, `initial_time_s=0`, `initial_pose_reference_frame=0`, `normalization=embedded_in_actor_graph`, and `original_model_sha256`. Initial velocities follow MuJoCo order: world-frame root linear xyz, local-frame root angular xyz, then metadata joint order.

**`robot-only.zip`** contains `g1.xml` and `assets/*.STL` for engine attachment. It preserves the source robot's bodies, inertias, geometry, collision exclusions, exact nominal armatures and position actuators, force limits, materials, and sensors. It removes the added ground plane, all lights/cameras, global physics options and global keyframe. The engine owns those world settings; initialization comes from the ONNX metadata. The archive compiled successfully and its complete body/joint/controller arrays match the nominal reference scene exactly. The archive contains zero lights and zero cameras.

To reproduce the derivative and robot archive with existing CPU dependencies (no training or source edits):

```sh
cd /home/devrim/Projects/mjlab
uv run --no-sync --offline python -B /home/devrim/Projects/LuckyEngineWeb-policies/scripts/prepare-mjlab-policy.py \
  --model /tmp/lucky-mjlab-policy-fixture/aiming/aiming.onnx \
  --controller /tmp/lucky-mjlab-policy-fixture/controller.full-precision.json \
  --initial-state /tmp/lucky-mjlab-policy-fixture/initial-state.json \
  --scene /tmp/lucky-mjlab-policy-fixture/robot/scene.xml \
  --output-model /tmp/lucky-mjlab-policy-fixture/aiming/aiming.web.onnx \
  --output-robot /tmp/lucky-mjlab-policy-fixture/robot-only.zip \
  --report /tmp/lucky-mjlab-policy-fixture/web-transport.json
```

The standalone converter can be copied into repository tools/documentation. It only imports ONNX and Python standard libraries. Caller-supplied paths make it independent of mjlab source. The original two-second numeric baseline remains valid because graph computation is unchanged and the enriched metadata now describes precisely the controller/reset used there. A host must still match the recorded 5ms implicitfast/Newton/pyramidal world settings before attempting strict trajectory comparison; using the engine's existing 2ms step changes the physics result.

## Browser-engine numerical verification

`npm run test:motions` uses checked-in CPU vectors and the shipped model/robot, with no dependency on the original training directory. The actual ONNX Runtime WASM and MuJoCo WASM path was compared over 100 inference intervals / 400 physical steps / two seconds. Maximum observed errors against the reconstructed nominal CPU reference:

| Quantity | Maximum absolute error |
|---|---:|
| Fixed-input network actions (seven cases) | 0.00000190735 |
| Generalized positions over rollout | 0.00005862591 |
| Generalized velocities over rollout | 0.00230963906 |
| Closed-loop network actions | 0.00023259223 |
| Actuator targets | 0.00010200493 |

Generalized-position and velocity vectors contain mixed units (root translation/orientation and joint angles); these are numerical tolerances, not hardware safety margins. The recorded 30 fps rollout contains 61 aligned frames, 100 inference records and 400 physical control vectors. Replay with retained initial state and raw controls is bit-exact in the same MuJoCo WASM runtime, without running ONNX again. The test also checks failure paths, reset and translated/yawed placement. The engine's default solver iteration budgets are higher than the reference; matching those budgets in a separate comparison did not change this example's result.

## Browser UI and recording verification

On September 25, 2026, `npm run test:motions-ui` passed in headless Chromium
against the built application and real local Worker/D1/R2 test harness. It
detached the sample's policy, imported the standalone ONNX through the robot
Inspector, played to physical tick 400, reset, and verified the exported
project contains the identical policy bytes and 5 ms timestep. An app API key
then imported and attached the policy in a separate browser runner, stepped
and reset it, and recorded the rollout.

The saved MP4 was inspected with ffprobe and decoded frames: H.264/yuv420p,
256×256, 30 fps, 61 frames, 2.033333 seconds. Frame times cover 0–2 seconds;
the final video frame adds one 30 fps display interval. The dataset contains
all 100 inferences, 400 physical steps, nonzero initial velocities, and a
`finished-reference` result with physical task success remaining false.
Maximum recorded browser action difference from the CPU reference was
0.00023259222507476807. No browser page errors were reported. This software
rendering test verifies correctness, not interactive hardware performance or
HD encoding throughput.
