World-model benchmark¶
Offline: transition datasets collected once in the simulator (collect), world models fit and scored on them without it
(fit).
ndm_gym.wmbench.fit
¶
Fit one world-model variant offline on collected transitions (ndm_gym.wmbench.collect) and score its k-step
open-loop prediction error on held-out datasets.
The world model, its loss and the window sampling are exactly those of online training: the algorithm selected by
--algo (with all training flags) is built and its wm_update is called on a replay buffer filled from the
training datasets. No simulator runs.
``python -m ndm_gym.wmbench.fit --algo supertrack --train data_wm/st.pt --test st=data_wm/st_test.pt
sm=data_wm/sm.pt --steps 20000 --out results/wmbench/
load_buffer
¶
load_buffer(paths: list[str], dev: str)
The datasets side by side (env axis) in one replay buffer on dev. The files are memory-mapped and each one is
unpacked on dev straight into its columns (collect.unpack: packed and earlier full-field files alike).
fixed_windows
¶
fixed_windows(
buf, n: int, k: int, seed: int, index: bool = False
)
n continuous k-step windows, sampled once with a fixed seed: no episode end inside, and every step starts
where the previous one ended (excludes the instants of external pushes, which no world model can predict).
index: also each window's first row "t0" and its env "env" (the same windows).
pre_failure_windows
¶
pre_failure_windows(
buf, n: int, k: int, window: int, failed, seed: int
)
Up to n distinct continuous k-step windows that end in the last window steps up to a termination (the
--wm_fail_windows windows), drawn once with a fixed seed; None if the dataset holds no termination that fits.
window_errors
¶
window_errors(algo, w)
Tracked-body position (m) and joint angle (rad) errors after the window's k open-loop steps.
ndm_gym.wmbench.collect
¶
Collect a transition dataset with a frozen policy under training conditions (domain randomization, reset noise, return-based resets, action noise), optionally with horizontal root-velocity pushes, in replay-buffer layout.
The file stores what each transition adds (pack): a field that repeats another one shifted in time (the next
state s1 is the next row's s unless an episode ended or a push changed the state, a_prev the previous
row's a unless an episode started, xi holds and f, ep_step count within an episode) keeps only the
rows that differ from that, with their positions; unpack restores every value bit for bit (checked when saving).
fit.load_buffer reads both this and the earlier layout of every field in full.
--eval_conditions collects under evaluate.py's conditions instead of training's (the recording that
benchmarks/steel/results.md scores the engines and the world models against): friction 1.0 on every shape, no torso
centre-of-mass or joint offsets, no reset noise, episodes ending only at a termination or their clip's end, observations
without sensor noise and setpoints without action noise. The simulator's evaluation mode does not reset ended worlds, so
the collection resets them after each step.
Run: python -m ndm_gym.wmbench.collect --ckpt logs/<run>/ckpt_012000.pt --out data_wm/<name>.pt
pack
¶
pack(data: dict, rules: dict) -> dict
data: name -> (T, N, ...) tensor. The fields of rules become {"rule", "shape": (T, N), "idx": flat
positions of the rows their prediction misses (int32), "rows": those rows}; the others stay as they are. The result
is checked to unpack to data bit for bit.
unpack
¶
unpack(data: dict, device) -> dict
The fields of pack's output (or of a file written before packing, every field in full) on device.
ndm_gym.wmbench.fit_hoi
¶
Fit a neural dynamics model of one of HDMI's tasks offline (ndm_gym.worldmodels.hoi) on transitions from
wmbench/collect_hoi.py and score its open-loop k-step prediction on held-out datasets. No simulator runs.
Scores after k open-loop steps (continuous windows without an episode end, drawn once with a fixed seed): the 16
keypoints' position error (m, our forward kinematics), the joint angle error (rad), a free object's position (m) and
rotation (rad) errors or a hinge's angle error (rad), and the contact forces' mean absolute errors per component (N;
the end effectors' in the contact body's frame, the feet's in the world frame) (window_scores;
wmbench/score_hoi.py scores a fitted model the same way through other inference paths).
``python -m ndm_gym.wmbench.fit_hoi --task move_suitcase --kind accel --train data_wm/hoi/a.pt --test held=data_wm/hoi/b.pt
--steps 20000 --out results/wmbench_hoi/
load_buffer
¶
load_buffer(paths: list[str], dev: str)
The datasets' fields that the fit reads (KEYS) in one ReplayBuffer, environments concatenated: each field copied from the memory-mapped file into its slice of the buffer, without a concatenated copy on the host or the GPU.
fixed_windows
¶
fixed_windows(buf, n: int, k: int, seed: int) -> dict
n k-step windows without an episode end before their last step, drawn once with a fixed seed.
object_state
¶
object_state(o: Tensor, hinged: bool) -> tuple
A dataset's object field as the world model's So: a hinge's (angle, rate), or a free object's (p, R, v, w).
true_step
¶
true_step(w: dict, j: int, hinged: bool) -> tuple
The recorded outcome (S', So', F') of step j of windows w.
world_model
¶
world_model(
a: dict, layout, recorded_constants: dict | None = None
)
The world model that fit_hoi fits, as its arguments a (a dict, as saved with the model) describe it, for
datasets of context layout layout; a RigidFormer takes the task's ndm_constants, which must equal the
datasets' recorded_constants if given. Initialized from the global random state, on the CPU.
window_scores
¶
window_scores(step, w: dict, kin, hinged: bool) -> dict
The scores of k open-loop steps on windows w (fixed_windows): step (S, So, u, ctx) -> (S', So', F') fed
back on itself from the windows' first states with their actions and contexts, against the recording after the
last step. The position error averaged over the keypoints (kin: G1's kinematics tracking KEYPOINT_NAMES), its
mean and 90th percentile over windows (mm); the joint angle error (mrad); a free object's position (mm) and
rotation (mrad) errors, or a hinge's angle error (obj_mrad; obj_mm NaN); the contact forces' mean absolute errors
(N); the number of windows. Python numbers, keyed by SCORE_COLUMNS' names after test and k.
The object's rotation error is the angle of R_true^T R_pred, the product written out elementwise and the angle
taken by atan2 from its skew part and trace (tasks.hdmi's relative_rot and rot_angle, as in the HOI
algorithms): exact to fp32 rounding at any angle. Before, it was the arccos of the trace of a batched matmul, which
ran in TF32 under fit_hoi's allow_tf32 (on an A100 a true 1 mrad read as 7.5 mrad on average and up to 32.5 mrad),
and arccos near 1 loses small angles even in fp32 (1 mrad read as 0.87 mrad on average, as 0 at worst).
score_fields
¶
score_fields(s: dict) -> str
window_scores' numbers as the csv's fields from keypoint_mm to n.
RoboKit's examples on a world model (task): recordings, fits of any MuJoCo model's world model, their throughput against MuJoCo Warp, and plans.
ndm_gym.wmbench.collect_robokit
¶
Record the transitions of one of RoboKit's SimMPC examples, run unmodified, for the world model of MJCF models
(worldmodels.mjcf). Three patches at run time, none in RoboKit's files: its simulator class becomes the recording one
(sim.robokit_rec), so the planner's rollout worlds, built with resized(), and the executing simulator record;
SimMPC.execute drains every recording simulator after each plan (after the example's own callback); and viser's server,
which the examples open after planning to replay the motion, ends the run instead. --seed sets the planner's sampling seed.
Writes <out>_rollout_dt<ms>.npz, one recording per step length of the rollouts (the coarse stages step longer), and
<out>_executed.npz, the closed loop's trajectory; each a recording of wmbench/fit_mjcf.py, beside <out>.json (the
example, its commit, the versions, the rows per file, the example's output lines).
Run: python -m ndm_gym.wmbench.collect_robokit --example .../sim_mpc/04_g1_carry.py --out data/robokit/g1_carry_s0 --record 64
ndm_gym.wmbench.fit_mjcf
¶
Fit the world model of a MuJoCo model (ndm_gym.worldmodels.mjcf) offline on recorded transitions and score its
open-loop k-step prediction on held-out recordings. No simulator runs.
A recording is an .npz with qpos (T + 1, N, nq), qvel (T + 1, N, nv), ctrl (T, N, nu) and reset (T, N) bool,
True where the state after step t does not follow from it (an episode ended), and dt, the step's length, which must be the
world model's: the model's timestep, --dt, or --substeps timesteps (a dm_control control step). Windows never cross a
reset. --cut K also cuts each rollout at its first step whose tangent-state increment
in some degree of freedom exceeds K times that degree of freedom's median absolute increment over the training recordings plus
the error floor (a simulator blow-up, as in some of MuJoCo Warp's coarse rollouts): from that step to
the rollout's end the steps count as resets, so no window and no normalizer reads them. The medians are the training
recordings', pooled, for every recording of the fit, so that a held-out recording of one long trajectory is judged by the
same scale. --cut_scale_floor takes as a degree of freedom's scale the larger of its median and its error floor, for
recordings in which a body lies still (median 0) and the floor alone would cut its first motion.
Scores after k open-loop steps (windows drawn once with a fixed seed): norm, the mean absolute error of the tangent state
(positions and velocities) in units of one true step's spread, as the fit's loss weighs it (MjcfWorldModel.error;
benchmarks/robokit_ndm/select_arms.py selects the fits by it); the anchor's and the objects' position (mm) and rotation
(mrad) errors, the hinges' (mrad) and slides' (mm) mean absolute errors and the ball joints' rotation errors (mrad), from the
tangent difference of the predicted and the recorded state (worldmodels.mjcf.differentiate_pos).
The network is the MLP (--hidden, --act, --no_ln) or, with --backbone rigidformer, the body-token Transformer
(worldmodels.mjcf.MjcfRigidFormerNet: --rf_dim, --rf_layers, --rf_heads, --rf_registers, --rf_rope_max_freq,
--rf_point); each backbone's options must stay at their defaults with the other (worldmodels.mjcf.backbone_kwargs).
The budget is --steps updates, or with --until_flat MARGIN EVALS as many as the held-out error needs: the fit stops
when the first test's norm at the largest --eval_k has not fallen MARGIN (relative) below its best for EVALS
evaluations in a row, --steps is then the cap, and the state saved is the best evaluation's. --init starts from an
earlier fit's state, its network and its normalizers, which then stay as they were: a refit on more recordings. A fit whose
contact inputs read static geoms (--contact_static) is saved with the revision of their gaps (contact_gaps, beside the
layout and the arguments); --init and speed_mjcf.load_ndm refuse such a fit without it (worldmodels.mjcf.check_gaps_revision).
With --contact_scale each contact column is divided by its spread over the training recordings where that exceeds one; the
scales are the input normalizer's, saved with the fit. With --contact_pair_margin the margin the contact inputs read their
gaps beyond is the simulator's contacts' (as the installed MuJoCo puts two geoms' margins together), saved with the fit too.
With --accel_mean_velocity the acceleration model advances the position with the mean of the velocities the control step
passes through under a constant acceleration, by the model's integrator and its number of physics steps
(worldmodels.mjcf.mean_velocity_lead), in the place of the step's last velocity; the weight is saved with the fit's state.
Run: python -m ndm_gym.wmbench.fit_mjcf --model scene.xml --train a.npz --test held=b.npz --steps 20000 --out fit.csv
load
¶
load(path: str, lay, device) -> dict
A recording as tensors, checked against the layout and its timestep.
increments
¶
increments(rec: dict, lay) -> torch.Tensor
(T, N, 2 nv) the absolute tangent-state increment of every step of a recording.
nonfinite_steps
¶
nonfinite_steps(rec: dict) -> torch.Tensor
(T, N) the kept steps of a recording whose state, next state or control is not finite.
cut_nonfinite
¶
cut_nonfinite(rec: dict) -> tuple[int, int]
--cut_nonfinite: the steps from each rollout's first step that is not finite (nonfinite_steps) to its next reset
become resets (in place). Returns the number of steps that are not finite and the number of kept steps cut.
median_increments
¶
median_increments(
recs: list, lay, sample: int = 1000000
) -> torch.Tensor
(2 nv) each degree of freedom's median absolute increment over the kept steps of recs (at most sample steps of
each, drawn with a fixed seed). A kept step that is not finite is an error (--cut_nonfinite cuts such steps first).
cut_blowups
¶
cut_blowups(
rec: dict,
lay,
K: float,
med: Tensor | None = None,
scale_floor: bool = False,
) -> float
--cut: the steps from each rollout's first outlier step to its next reset become resets (in place); the share of the
kept steps cut. med: the medians to judge by (the training recordings'); by default the recording's own. scale_floor:
each degree of freedom's scale is the larger of its median and its error floor (--cut_scale_floor). A kept step that is
not finite is an error, not a blow-up to drop (--cut_nonfinite cuts such steps first).
starts
¶
starts(rec: dict, k: int) -> torch.Tensor
(M, 2) the (t, n) whose k steps t .. t + k - 1 all follow on from their states: no reset among them.
gather
¶
gather(
rec: dict, idx: Tensor, k: int, device=None
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]
The windows at idx (M, 2): qpos, qvel (k + 1, M, .), ctrl (k, M, .); on device if given (a recording held on the host).
scores
¶
scores(wm, rec: dict, idx: Tensor, k: int) -> dict
The errors after k open-loop steps from the windows' first states (see the module's docstring).
ndm_gym.wmbench.speed_mjcf
¶
Throughput of a MuJoCo model's step as RoboKit's MuJoCo Warp simulator runs it and of its world model (worldmodels.mjcf)
at the same number of worlds and the same step: world-steps per second, 20 warm-up steps, then 200 timed steps between two
synchronizations, the median of three repeats (as wmbench/speed_hoi.py).
physics: robokit.sim.MjWarpSim with the model, the worlds, the substeps and the contact capacities the planner used
(collect_robokit's <out>.json), its step a cached CUDA graph, every world started from a recorded state (so its contacts
are the task's) and holding its recorded controls. ndm: the world model's step (inference_copy in --dtype) on the
same states and controls, compiled (--compile) and replayed as one CUDA graph per step, its outputs fed back as the next
inputs. The world model's weights do not change its cost; --ckpt loads a fit's, else the weights are random. ndmsim:
the simulator SimMPC plans on (sim.robokit_ndm.NdmSim), its whole step (the --derived MuJoCo Warp stages, then the world
model) captured into one Warp graph as SimMPC captures it, and replayed.
``python -m ndm_gym.wmbench.speed_mjcf --meta data/robokit/g1_carry_s0.json --planner 0 --states data/.._rollout_dt20.npz
--what physics ndm --out results/robokit_ndm/speed.csv``
start_states
¶
start_states(
path: str, n: int, seed: int = 0
) -> tuple[np.ndarray, np.ndarray, np.ndarray]
n states and controls drawn from a recording's steps (with replacement when it holds fewer).
timed
¶
timed(
step,
sync,
warmup: int,
steps: int,
repeats: int,
reset=None,
every: int = 0,
warm_seconds: float = 0.0,
) -> list[float]
Seconds for steps calls of step between two syncs, repeats times, after warmup calls and then
warm_seconds of calls (wmbench/warm.py); with every, reset() (the start states copied back on the device)
before every every-th call, inside the timed loop too.
load_ndm
¶
load_ndm(lay, args, device)
The world model to time: a fit_mjcf --save file's (its parameterization, backbone and its options, widths, activation, LayerNorm, step and planar root), or one of random weights with this script's options. A checkpoint written before fit_mjcf had --wm_param is an acceleration model, one written before --geometry has no contact geometry inputs, and one written before --backbone is an MLP. A checkpoint fitted on another layout (its state's sizes, its anchor or its objects, as with fit_mjcf --anchor) is refused, and so is one with contact inputs against static geoms that does not carry this code's revision of their gaps (worldmodels.mjcf.check_gaps_revision).
ndm_gym.wmbench.plan_robokit
¶
Run one of RoboKit's SimMPC examples, unmodified, with its planner's rollouts on a world model (sim.robokit_ndm) and its
execution on MuJoCo Warp. SimMPC is handed an NdmSim twin of the example's simulator (the same model, data, substeps and
contact capacities, with the world models of --ndm), so its rollout and validation worlds step the world model, while the
example's own simulator executes the plans. Without --ndm the example runs as it is (the baseline); in both cases only
viser's viewer, which the examples open after planning, is replaced so that the run ends. --stages fine gives a planner
that has no stages (and would try 2 and 4 timesteps on its first plan) the stages at its timestep, as MuJoCo Warp's own runs
chose them. The example's output lines (its pass or fail line, its planning time) and the run's settings
are written to --out (.json).
``python -m ndm_gym.wmbench.plan_robokit --example .../sim_mpc/04_g1_carry.py --ndm 0.02=fits/g1_carry.pt --dtype bf16
--derived kinematics --out results/plan_g1_carry.json``
null_sim
¶
null_sim()
A MjWarpSim whose step does nothing: plans on it cost SimMPC's own work only (sampling, controls, costs).
save_reference
¶
save_reference(path: str, config, sim)
The example's targets (--save_reference): its first StateTask's qpos_ref and first SensorTask's sensor_ref, as built,
one row per simulation step of ref_dt from the executed trajectory's first; the model's sensor names and addresses; and
the model as .mjb beside it. A task without either is an error.
mbrl-lib's controller on a world model (task): recordings, plans, the step's throughput against CPU MuJoCo and MuJoCo Warp, and the check of the batched rewards.
ndm_gym.wmbench.collect_mbrl
¶
Record CPU MuJoCo transitions of one of the environments of benchmarks/mbrl_lib at its control step (the environment's
step; dm_control: its own control step, repeat of which make one environment step at PlaNet's action repeat), for the
world model of MJCF models (worldmodels.mjcf):
- (a)
rollout: the optimizer's candidate rollouts at recorded plan starts. mbrl-lib's control_env.py runs asplan_mbrl --sim cpuruns it (unmodified, its pool, the run-time patches ofsim.mbrl_envs); at every--record_every-th plan the first--recordcandidates of each iteration (CEM's draws, in random order) are kept with the plan's start, and after the run they are replayed on a CPU MuJoCo environment built as control_env.py builds it, from the same state, over the whole horizon (the physics past a termination too; up to dm_control's time limit, where its environment would reset). With--sim ndmthe planner plans on a world model (--ndm, asplan_mbrl --sim ndm) and every plan still executes on CPU MuJoCo: the plan starts are then the states that planner reaches, and the kept candidates are replayed on CPU MuJoCo all the same (recordings for a further fit of the world model on its own planner's states); - (b)
executed: the closed loop's trajectory, control_env.py's evaluation environment step by step. control_env.py steps on after a termination;--until_terminationkeeps the plan starts and the executed steps up to the run's first termination only (the noisy episodes then replay the kept actions); - (c)
random:--episodesepisodes of uniform random actions from the environment's resets (at most the environment's episode,MbrlEnv.episode), andnoisy:--episodesreplays of the executed actions from the executed trajectory's start with Gaussian noise of--noisetimes the action range's half-width (clipped to it); each episode until the environment terminates or truncates it.
Each is a recording of wmbench/fit_mjcf.py (qpos (T + 1, N, nq), qvel, ctrl (T, N, nu), reset (T, N), dt), consecutive
rollouts or episodes joined by a reset step with zero controls, beside <out>_model.mjb (the model as the environment
simulates it, for the fits and MuJoCo Warp), <out>_plans.npz (the recorded plan starts: step, state, steps left, the
recorded candidates' actions and their values under the planner's simulator) and <out>.json (the settings, the versions, the run's
per-step rewards and planning times, the step and its physics steps, the rows per file). Seeds split into fit (0, 1) and
held-out (2) runs. pets_reacher is refused (mbrl_envs.refusal); --counter_fix, --own_margins and --own_mujoco as
plan_mbrl's.
Run: python -m ndm_gym.wmbench.collect_mbrl --env pets_halfcheetah --seed 0 --num_processes 8 --out data/mbrl/hc_s0
recording
¶
recording(segments: list, dt: float) -> dict
[(qpos (T_i + 1, N, nq), qvel, ctrl (T_i, N, nu)), ...] as one fit_mjcf recording: the segments one after another, a reset step with zero controls between two (its next state starts the next segment).
episode
¶
episode(
spec, handler, env, actions, start=None, stop=True
) -> tuple
One episode: actions(t, env) gives each step's action (None: the end), from start (a handler state; None: the
env as it is), until the environment terminates or truncates it (stop; always at dm_control's time limit, after which
its environment resets). (qpos (T + 1, 1, nq), qvel, ctrl (T, 1, nu)) at the control step: dm_control's inner steps.
replay
¶
replay(spec, handler, env, start, acts: ndarray) -> tuple
The candidates acts (K, H, A) from the handler state start, each over the whole horizon (dm_control: up to its
time limit): (qpos (T + 1, K, nq), qvel, ctrl (T, K, nu)).
ndm_gym.wmbench.plan_mbrl
¶
Run mbrl-lib's true-dynamics controller (mbrl/diagnostics/control_env.py at 3f93ccc, unmodified) on one of the environments
of benchmarks/mbrl_lib, its optimizer's candidate rollouts on CPU MuJoCo as control_env.py ships them (its multiprocessing
pool), on MuJoCo Warp or on the NDM (sim.mbrl_ndm); every plan executes on CPU MuJoCo, control_env.py's evaluation
environment. Patches at run time, none in mbrl-lib's files:
- the environments as the benchmark runs them (
sim.mbrl_envs.patch_envs: Hopper's and Walker2d's local-coordinate copies, dm_control at PlaNet's action repeat, with--own_marginsthe contact margins of mbrl-lib's own MuJoCo, with--own_mujocothe models as it steps them, and with--counter_fixmbrl-lib's dm_control step counter restored on the right wrapper), in this process and in the pool's workers (their initializer); - the optimizer's population and iterations at
--setting's: control_env.py's defaults (512, horizon 30, 5), the environment's PETS override, or PlaNet's (1,000, 12, 10); the horizon through control_env.py's own--control_horizon; the rest is control_env.py's (CEM, elite ratio 0.1, alpha 0.1, the best solution over the iterations); --sim warporndm:TrajectoryOptimizer.optimizescores the population with the batched rollouts from the evaluation environment's current state instead of the pool, whose workers are then not started;- the evaluation environment's
steprecords each executed step, and each plan (optimize) is timed.
An environment a simulator cannot score is refused with the reason (mbrl_envs.refusal; pets_reacher is not run at all).
control_env.py runs --num_steps steps (default: the environment's episode) and, as shipped, does not stop when the
environment terminates. The json holds per step the planning time (optimize), control_env.py's own step time, the reward
and the flags; per episode control_env.py's total and the return up to the first termination or truncation.
``python -m ndm_gym.wmbench.plan_mbrl --env pets_halfcheetah --sim ndm --ndm fits/hc.pt --setting pets --seed 0
--out results/plan_hc_ndm_s0.json``
run_control_env
¶
run_control_env(
spec,
args,
setting,
rollouts_for=None,
on_plan=None,
on_step=None,
) -> dict
control_env.py run as __main__ with the patches. rollouts_for(mjm, substeps, population): the batched rollouts
(None: the pool); on_plan(t, handler state, sim.mbrl_envs.state, callback) returns plan t's callback in place of
control_env.py's, or None; on_step(pre, states, action, reward, terminated, truncated) sees each executed step (pre:
qpos and qvel before it; states: after each of its control steps, one but for dm_control's repeat).
batched_rollouts
¶
batched_rollouts(spec, args)
run_control_env's rollouts_for of the options --sim, --ndm, --dtype, --device and --no_compile:
the builder of the batched rollouts on MuJoCo Warp or on the world model, or None for control_env.py's pool (--sim cpu).
check_options
¶
check_options(spec, args)
The refusals of an environment on a simulator (mbrl_envs.refusal), and --counter_fix only where it applies.
ndm_gym.wmbench.speed_mbrl
¶
Throughput of one of the models of benchmarks/mbrl_lib at its control step: CPU MuJoCo, MuJoCo Warp and
the world model (worldmodels.mjcf) step the same number of worlds from recorded states, each world holding its recorded
controls: world-steps per second, 20 warm-up steps, then 200 timed steps between two synchronizations, the median of three
repeats (wmbench/speed_mjcf.py's timing loop and its world-model row).
cpu: one process and one MjData; per world the state is copied in (qpos, qvel, the constraint solver's warm start),
mj_step runs the control step's physics steps and the state is copied out. warp: MuJoCo Warp worlds of the same model
with its default capacities, the control step's physics steps captured as one Warp graph and replayed (sim.mbrl_ndm's
control step without the stages a reward reads); a row is refused if a world ran out of contacts or constraints. ndm: the
world model's step (inference_copy in --dtype), compiled and replayed as one CUDA graph, its outputs fed back as the next
inputs; --ckpt loads a fit's, else the weights are random, which do not change the cost. The model, its control step and
its physics steps come from collect_mbrl's <out>.json.
``python -m ndm_gym.wmbench.speed_mbrl --meta data/mbrl/hc_s2.json --states data/mbrl/hc_s2_executed.npz --reset_every 30
--ckpt fits/hc_acc_ln.pt --out results/mbrl_lib/speed.csv``
cpu_step
¶
cpu_step(
model,
d,
substeps: int,
q: ndarray,
v: ndarray,
u: ndarray,
w: ndarray,
)
One control step of every world on the MjData d, in place: the rows of q, v and w (qpos, qvel and the
constraint solver's warm start) under the controls u.
ndm_gym.wmbench.check_mbrl_rewards
¶
A check of the batched rewards and terminations of benchmarks/mbrl_lib (sim.mbrl_envs.Scorer) against the
environments' own step, on transitions recorded from CPU MuJoCo with each environment built as control_env.py builds it
(mbrl-lib's handler, with the run-time patches of sim.mbrl_envs). Episodes run from the environments' resets under uniform random actions;
with --perturb, every other step starts from a state spread around the episode's (qpos and qvel plus Gaussian noise), so
that the rewards' rarer branches occur. MuJoCo's data is copied before and after each step (dm_control: after each of its
control steps) and scored in float64. A step agrees when the batched reward is within --tol of the environment's,
absolutely or relatively (the environments compute their control costs in float32), and the batched termination is the
environment's (dm_control's time limit, which ends its episodes, is the rollouts' step count, not a termination). One line per
environment: PASS, FAIL or REFUSED with the reason; the exit status is 1 if any fails.
Two measurements beside it, outside PASS and FAIL:
- the pusher's named difference: its reward from the forward kinematics of the state before the step (what the world model's
reward reads) against env.step's, over the steps whose data a previous step left, in episodes of uniform random actions
without perturbations (the reward, and the bodies' positions);
- --ant_forces: the Ant's contact forces on MuJoCo Warp (rne_postconstraint after one environment step from each
recorded state, with its controls and the solver's warm start) against CPU MuJoCo's cfrc_ext after the same step; the
relative error of a transition is its largest absolute difference over the largest of CPU MuJoCo's forces and torques, or
over a floor of 1e-3 times the Ant's weight where those are smaller (no contact); the criterion is 1e-4. Reported beside it:
the transitions in contact, those where one simulator's forces exceed the floor and the other's do not, and the largest
difference of the states after the step.
Run: python -m ndm_gym.wmbench.check_mbrl_rewards --local_models converted/ --steps 2000 --perturb --ant_forces --out check.json
named_difference
¶
named_difference(spec, args) -> dict
The pusher's reward with the kinematics of the state before the step against env.step's (the module's docstring).
ant_forces
¶
ant_forces(args) -> dict
The Ant's contact forces on MuJoCo Warp against CPU MuJoCo's on recorded transitions (the module's docstring).