ceca51b0d8
Default humanoid intake to command-following gait and support bounded Cartesian target dragging for arms. Carry model and actuator semantics through calibration, native verification and packaging. Document reusable intake decisions and cover them with regression tests.
82 lines
3.5 KiB
Python
82 lines
3.5 KiB
Python
"""Model facts must never masquerade as recovered actor semantics."""
|
|
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import mujoco
|
|
import pytest
|
|
|
|
from mjrl.onboarding.model_evidence import model_evidence
|
|
from mjrl.onboarding.upstream import extract_policy_metadata
|
|
|
|
_XML = """<mujoco><option timestep="0.005"/>
|
|
<worldbody><geom name="floor" type="plane" size="1 1 .1"/>
|
|
<body name="robot"><joint name="elbow" range="-60 60" damping="3"/>
|
|
<geom name="foot" size=".1" contype="0" conaffinity="0"/></body></worldbody>
|
|
<contact><pair geom1="floor" geom2="foot"/></contact>
|
|
<actuator><position name="servo" joint="elbow" kp="17" gear="2"
|
|
ctrlrange="-.5 .5" forcerange="-4 6"/></actuator>
|
|
<keyframe><key name="pose" qpos=".2" ctrl=".4"/></keyframe></mujoco>"""
|
|
|
|
|
|
def test_model_only_draft_keeps_semantics_unknown():
|
|
model = mujoco.MjModel.from_xml_string(_XML)
|
|
report = extract_policy_metadata([], model=model)
|
|
assert not report['ready']
|
|
assert report['metadata'] == {'schema': 'mjrl-policy-adapter/1'}
|
|
assert {'obs_joint_order', 'action_joint_order', 'control.control_hz',
|
|
'default_joint_pos', 'action_scale', 'observation.terms'} <= set(report['missing_fields'])
|
|
facts = report['model_evidence']
|
|
assert facts['physics_timestep_s'] == .005
|
|
assert facts['joints'][0]['damping'] == [3]
|
|
assert facts['actuators'][0]['gear'][0] == 2
|
|
assert facts['actuators'][0]['force_range'] == [-4, 6]
|
|
assert facts['actuators'][0]['control_range'] == [-.5, .5]
|
|
assert facts['keyframes'][0]['qpos'] == [.2]
|
|
assert facts['explicit_contact_pairs'][0]['geoms'] == ['floor', 'foot']
|
|
# The fingerprint must detect physical changes, not merely joint names.
|
|
model.dof_damping[0] = 4
|
|
assert model_evidence(model)['compiled_model_sha256'] != facts['compiled_model_sha256']
|
|
|
|
|
|
def test_no_sources_or_model_is_not_an_extraction():
|
|
with pytest.raises(ValueError, match='config paths or a model'):
|
|
extract_policy_metadata([])
|
|
|
|
|
|
def test_model_only_cli_persists_failed_draft(tmp_path):
|
|
model = tmp_path / 'robot.xml'
|
|
model.write_text(_XML)
|
|
output = tmp_path / 'draft'
|
|
result = subprocess.run(
|
|
[sys.executable, 'scripts/onboard.py', 'extract-tier1', '--model', str(model),
|
|
'--output', str(output)], cwd=Path(__file__).resolve().parents[1],
|
|
capture_output=True, text=True,
|
|
)
|
|
assert result.returncode == 1, result.stderr
|
|
manifest = json.loads((output / 'manifest.json').read_text())
|
|
assert manifest['ready'] is False
|
|
assert manifest['model_evidence']['dimensions']['nu'] == 1
|
|
assert json.loads((output / 'metadata.json').read_text()) == manifest['metadata']
|
|
assert not list(output.glob('*.onnx'))
|
|
|
|
|
|
def test_native_verification_accepts_explicit_pair_physics(tmp_path):
|
|
from mjrl.onboarding.verify import verify
|
|
|
|
model = tmp_path / 'robot.xml'
|
|
model.write_text(_XML)
|
|
config = {'root_body': 'robot', 'steps': 1,
|
|
'actuator_targets': {'servo': .4}, 'joint_positions': {'elbow': .2}}
|
|
report = verify(model, config)
|
|
dynamic = next(c for c in report['stages']['physics']['checks']
|
|
if c['name'] == 'dynamic_robot')
|
|
assert dynamic['passed'] and dynamic['has_collision']
|
|
model.write_text(_XML.replace('<contact><pair geom1="floor" geom2="foot"/></contact>', ''))
|
|
report = verify(model, config)
|
|
dynamic = next(c for c in report['stages']['physics']['checks']
|
|
if c['name'] == 'dynamic_robot')
|
|
assert not dynamic['passed'] and not dynamic['has_collision']
|