9fe9d27865
Consolidate next-stage docs, archive superseded narratives, and preserve frozen document inputs. Retain invalid P2 pairs, partial RootXY training, failed attempts and nonselectable checkpoints as explicit limitations. Include supervised evaluation/training, desktop GPU admission, bounded evidence and atomic-publication monitor repairs with CPU regressions. Ignore local dotenv configuration. Validation: 1403 passed, 6 skipped for contact-cycle and related contracts/CLI tests. Full-suite legacy ABI and registration tests require Python 3.12/Torch 2.10/pxr; no runtime checks relaxed. No new physical run or accepted skill.
487 lines
24 KiB
Python
487 lines
24 KiB
Python
"""CPU only: frozen load math/scheduler, runtime guard stack, pinned source layouts.
|
|
|
|
AST-extracted backend Python classes never import Kit or start AppLauncher. These
|
|
are not actual imported-backend identity evidence.
|
|
"""
|
|
import ast
|
|
import copy
|
|
import importlib.util
|
|
import logging
|
|
import random
|
|
import sys
|
|
import types
|
|
from abc import ABC, abstractmethod
|
|
from contextlib import contextmanager
|
|
from hashlib import sha256
|
|
from pathlib import Path
|
|
from types import SimpleNamespace as NS
|
|
|
|
import numpy as np
|
|
import pytest
|
|
import torch
|
|
from SkillFactory.legs.contact_cycle_sim.evaluation_audit import TrialAudit, carry_state, fingerprint
|
|
from test_contact_cycle_sim_evaluation_runtime import protocol, runtime # noqa: F401
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
PATH = ROOT / 'source/SkillFactory/SkillFactory/tasks/manager_based/contact_cycle_sim/evaluation_instrumentation.py'
|
|
spec = importlib.util.spec_from_file_location('cpu_evaluation_instrumentation', PATH)
|
|
ins = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(ins)
|
|
|
|
|
|
def source_classes(monkeypatch, module, names, **dependencies):
|
|
path = ins.BACKEND_SOURCE_INVENTORY[module][0]
|
|
tree = ast.parse(Path(path).read_text())
|
|
nodes = [n for n in tree.body if isinstance(n, ast.ClassDef) and n.name in names]
|
|
code = 'from __future__ import annotations\n' + '\n'.join(ast.unparse(n) for n in nodes)
|
|
obj = types.ModuleType(module)
|
|
obj.__dict__.update(torch=torch, logger=logging.getLogger(__name__), **dependencies)
|
|
exec(compile(code, path, 'exec'), obj.__dict__)
|
|
monkeypatch.setitem(sys.modules, module, obj)
|
|
return obj
|
|
|
|
|
|
@pytest.fixture
|
|
def backend(monkeypatch):
|
|
circular = source_classes(monkeypatch, 'isaaclab.utils.buffers.circular_buffer', ['CircularBuffer'])
|
|
delay = source_classes(monkeypatch, 'isaaclab.utils.buffers.delay_buffer', ['DelayBuffer'],
|
|
CircularBuffer=circular.CircularBuffer)
|
|
base = source_classes(monkeypatch, 'isaaclab.actuators.actuator_base', ['ActuatorBase'],
|
|
ABC=ABC, abstractmethod=abstractmethod)
|
|
pd = source_classes(monkeypatch, ins.ACTUATOR_MODULE,
|
|
['ImplicitActuator', 'IdealPDActuator', 'DelayedPDActuator'],
|
|
ActuatorBase=base.ActuatorBase, DelayBuffer=delay.DelayBuffer)
|
|
|
|
def actuator(kind='ImplicitActuator'):
|
|
cfg = NS(**{k: 1.0 for k in ('stiffness', 'damping', 'armature', 'friction',
|
|
'dynamic_friction', 'viscous_friction', 'velocity_limit', 'velocity_limit_sim',
|
|
'effort_limit', 'effort_limit_sim')}, max_delay=3, min_delay=1)
|
|
return getattr(pd, kind)(cfg, ['a', 'b', 'c'], slice(None), 1, 'cpu',
|
|
effort_limit=10., velocity_limit=10.)
|
|
return NS(actuator=actuator, pd=pd)
|
|
|
|
|
|
def scoped(value):
|
|
import copy
|
|
|
|
from SkillFactory.tasks.manager_based.contact_cycle_sim.evaluation_rng_scope import (
|
|
EVIDENCE_SCOPE,
|
|
UNOBSERVED_INTERNALS,
|
|
)
|
|
return {**value, 'evidence_scope': copy.deepcopy(EVIDENCE_SCOPE),
|
|
'unobserved_internals': copy.deepcopy(UNOBSERVED_INTERNALS)}
|
|
|
|
|
|
def backend_rng(_state):
|
|
return scoped({'coverage': {'cpu_mock': {'status': 'observed', 'sources': [__file__],
|
|
'evidence': 'Test-owned explicit deterministic RNG buffer, not a PhysX claim',
|
|
'state': [7, 8, 9]}}})
|
|
|
|
|
|
@pytest.fixture
|
|
def setup(runtime, backend, monkeypatch): # noqa: F811 - imported pytest fixture
|
|
monkeypatch.setattr(runtime.base.CycleState, 'apply_loads', runtime.real_apply_loads)
|
|
composer_class = type(runtime.Robot().permanent_wrench_composer)
|
|
old_setter = composer_class.set_forces_and_torques_index
|
|
|
|
def setter(c, **kw):
|
|
result = old_setter(c, **kw)
|
|
for name in ('global_force_w', 'local_force_b', 'local_torque_b'):
|
|
setattr(c, name, torch.zeros_like(kw['forces']))
|
|
c.global_force_at_com_w = kw['forces'].clone()
|
|
c.global_torque_w = kw['torques'].clone()
|
|
if getattr(c, 'corrupt', False):
|
|
c.local_force_b += 1
|
|
return result
|
|
monkeypatch.setattr(composer_class, 'set_forces_and_torques_index', setter)
|
|
|
|
@contextmanager
|
|
def opened(stage='P2', trial=4, callback=None):
|
|
hooks = runtime.env.RuntimeHooks(runtime.Sim, [(runtime.Robot, 'reset'),
|
|
(runtime.Robot, 'write_root_pose_to_sim'), (runtime.Scene, 'reset')])
|
|
with hooks:
|
|
env = runtime.env.EvaluationContactCycleEnv(runtime.config(), protocol=protocol(stage),
|
|
trial_index=0, runtime_hooks=hooks, evidence_callback=lambda *a: ())
|
|
# CPU fixture selects a row without running preceding physical trials.
|
|
if trial:
|
|
env.evaluation_trial_index = trial
|
|
with hooks.scope('initialization'):
|
|
env._cycle_state = runtime.mdp.EvaluationCycleState(env)
|
|
env._guard_trial_objects()
|
|
robot = env._cycle_state.robot
|
|
robot.actuators = {'joints': backend.actuator()}
|
|
for key in ('_joint_pos_target_sim', '_joint_vel_target_sim', '_joint_effort_target_sim'):
|
|
setattr(robot, key, torch.zeros(1, 3))
|
|
for key in ('joint_pos_target', 'joint_vel_target', 'joint_effort_target'):
|
|
setattr(robot.data, key, NS(torch=torch.zeros(1, 3)))
|
|
evidence = []
|
|
with ins.EvaluationInstrumentation(env, backend_rng=backend_rng, generators={}) as observer:
|
|
def record(event, s):
|
|
evidence.append((event.kind, observer.supplemental(s)))
|
|
return () if callback is None else callback(event, s)
|
|
env.evidence_callback = record
|
|
env._cycle_state.safety_causes = lambda: ()
|
|
env.reset()
|
|
yield NS(env=env, s=env._cycle_state, hooks=hooks, observer=observer, evidence=evidence)
|
|
return opened
|
|
|
|
|
|
def apply_one(f):
|
|
with f.hooks.wrench_update(f.s.robot.permanent_wrench_composer):
|
|
f.s.apply_loads()
|
|
# Advance only CPU evidence clock, never a simulator step.
|
|
f.s.substeps += 1
|
|
f.s.time[:] = f.s.substeps * .002
|
|
return f.observer.supplemental(f.s)
|
|
|
|
|
|
def test_unique_submission_actual_frozen_world_frames_and_com_arm(setup):
|
|
with setup() as f:
|
|
s, c = f.s, f.s.robot.permanent_wrench_composer
|
|
# Distinct environment-origin/world coordinates and nontrivial xyzw poses.
|
|
s.env.scene.env_origins[:] = torch.tensor([[11., -3., 2.]])
|
|
s.robot.data.body_link_pos_w.torch[:] = torch.tensor([[[12., 4., 3.]]])
|
|
s.robot.data.body_com_pos_w.torch[:] = torch.tensor([[[12.2, 4.1, 3.4]]])
|
|
s.robot.data.body_link_quat_w.torch = torch.tensor([[[0., 0., 2**-.5, 2**-.5]]]).repeat(1, 4, 1)
|
|
# Real event 0 is world-force/body-point; use actual scheduler time without re-execution.
|
|
s.time[:] = s.cc['events'][0]['start_s'] + .1
|
|
before = c.set_calls
|
|
out = apply_one(f)
|
|
applied = out['applied']
|
|
e = applied['events'][0]
|
|
assert applied['trial_index'] == 4 and applied['global_tick'] == 1
|
|
assert e['event_index'] == 0 and e['envelope'] > 0
|
|
assert c.set_calls == before + 1
|
|
assert f.hooks.composer_buffer_replacements == 1
|
|
assert applied['total_com_wrench'] == torch.cat((c.last['forces'], c.last['torques']), -1)[0].tolist()
|
|
force, couple = torch.tensor(e['force_world']), torch.tensor(e['couple_world'])
|
|
torque = couple + torch.cross(torch.tensor(e['point_world']) - torch.tensor(e['com_world']), force, dim=-1)
|
|
torch.testing.assert_close(s.external[0, e['body_index'], 3:], torque)
|
|
assert e['point_frame_origin_world'] == [12., 4., 3.]
|
|
assert e['frame_quat_xyzw'] == [0., 0., 0., 1.]
|
|
# Validate the exact frozen auditor schema/arithmetic with no fabricated setter.
|
|
audit = TrialAudit(s.protocol, s.trial.index)
|
|
state = {'applied': applied, 'external': s.external[0].tolist(), 'guide': s.guide[0].tolist(),
|
|
'auxiliary': s.auxiliary[0].tolist(), 'body_names': s.robot.body_names,
|
|
'event_program': s.cc['events'], 'env_origin': s.env.scene.env_origins[0].tolist(),
|
|
'events': [{'envelope': float(s.schedule.envelope[0, j])} for j in range(len(s.cc['events']))]}
|
|
assert list(audit._applied(state, s.protocol.evidence_clock(4, 1))) == [0]
|
|
# Returned mutable JSON containers are owned copies, never live tensor aliases.
|
|
out['applied']['events'][0]['point_world'][0] = -999
|
|
out['actuator_state']['groups']['joints']['buffers']['applied_effort'][0][0] = -999
|
|
assert f.observer.supplemental(s)['applied']['events'][0]['point_world'][0] != -999
|
|
assert s.robot.actuators['joints'].applied_effort[0, 0] == 0
|
|
|
|
|
|
@pytest.mark.parametrize('trial', [4, 8, 12])
|
|
def test_selected_events_every_zero_envelope_tick_and_next_reference(setup, trial):
|
|
with setup(trial=trial) as f:
|
|
assert f.evidence[0][1]['applied'] is None
|
|
before = f.env.sim.calls
|
|
result = f.env.step(torch.zeros(1, 3))
|
|
assert result.stop is None
|
|
ticks = [v for k, v in f.evidence if k == 'tick']
|
|
assert len(ticks) == 5 and f.env.sim.calls == before + 5
|
|
for i, value in enumerate(ticks, 1):
|
|
assert value['applied']['global_tick'] == i
|
|
assert [e['event_index'] for e in value['applied']['events']] == list(f.s.trial.event_indices)
|
|
assert all(e['envelope'] == 0 for e in value['applied']['events'])
|
|
assert f.evidence[-1][0] == 'next_reference'
|
|
assert f.evidence[-1][1] == ticks[-1]
|
|
assert f.s.robot.permanent_wrench_composer.set_calls == 5
|
|
assert f.hooks.composer_buffer_replacements == 5
|
|
|
|
|
|
@pytest.mark.parametrize('stage,trial', [('P1', 0), ('P2', 0), ('P2', 16)])
|
|
def test_no_event_rows_never_fabricate_application(setup, stage, trial):
|
|
with setup(stage, trial) as f:
|
|
assert f.observer.supplemental(f.s)['applied'] is None
|
|
out = apply_one(f)
|
|
assert out['applied'] is None
|
|
assert not f.s.external.any()
|
|
assert not f.s.schedule.fired.any()
|
|
|
|
|
|
@pytest.mark.parametrize('frame', ['world', 'mount', 'body'])
|
|
@pytest.mark.parametrize('point_frame', ['world', 'mount', 'body'])
|
|
def test_frame_matrix_uses_frozen_load_math(setup, frame, point_frame):
|
|
with setup() as f:
|
|
# Test-local descriptor variation exercises all frozen supported frame combinations.
|
|
e = f.s.cc['events'][0]
|
|
e.update(frame=frame, point_frame=point_frame)
|
|
f.s.env.scene.env_origins[:] = torch.tensor([[5., 7., 1.]])
|
|
f.s.robot.data.body_link_pos_w.torch[:] = torch.arange(12).reshape(1, 4, 3)
|
|
f.s.robot.data.body_link_quat_w.torch = torch.tensor([[[0., 0., 1., 0.]]]).repeat(1, 4, 1)
|
|
f.s.time[:] = e['start_s'] + e['ramp_s']
|
|
out = apply_one(f)['applied']['events'][0]
|
|
assert out['frame_quat_xyzw'] == ([0., 0., 0., 1.] if frame == 'world' else [0., 0., 1., 0.])
|
|
if point_frame == 'world':
|
|
assert out['point_frame_origin_world'] == [5., 7., 1.]
|
|
expected = (torch.tensor(e['point_m']) + torch.tensor([5., 7., 1.])).tolist()
|
|
assert out['point_world'] == pytest.approx(expected)
|
|
|
|
|
|
def test_repeated_supplemental_seam_fingerprint_and_rng_unchanged(setup):
|
|
with setup() as f:
|
|
f.s.time[:] = f.s.cc['events'][0]['start_s'] + .1
|
|
before = apply_one(f)
|
|
schedule = copy.deepcopy(f.observer._schedule_state)
|
|
c = f.s.robot.permanent_wrench_composer
|
|
torch_rng = torch.get_rng_state().clone()
|
|
for _ in range(3):
|
|
after = f.observer.supplemental(f.s)
|
|
assert fingerprint(carry_state(before)) == fingerprint(carry_state(after))
|
|
assert torch.equal(torch_rng, torch.get_rng_state())
|
|
assert f.observer._schedule_state == schedule
|
|
assert c.set_calls == 1
|
|
# Exercise actual auditor event integration once and its reference-only dispatch.
|
|
audit = TrialAudit(f.s.protocol, f.s.trial.index)
|
|
audit.initial = {'state': {'time': 1.1, 'liftoff': False, 'touchdown': False, 'edge_phase': -1,
|
|
'events': [dict(fired=False, completed=False, start=0., envelope=0., integral=0.)
|
|
for _ in f.s.cc['events']]}, 'event': {'command': {'phase': 0}}}
|
|
state = {**before, 'refreshes': 1, 'external': f.s.external[0].tolist(),
|
|
'guide': f.s.guide[0].tolist(), 'auxiliary': f.s.auxiliary[0].tolist(),
|
|
'body_names': f.s.robot.body_names, 'event_program': f.s.cc['events'],
|
|
'env_origin': f.s.env.scene.env_origins[0].tolist(),
|
|
'events': [{k: schedule[k][0][j] for k in ins.SCHEDULE_FIELDS}
|
|
for j in range(len(f.s.cc['events']))]}
|
|
audit.last = {'state': state}
|
|
assert not audit._events(state, f.s.protocol.evidence_clock(f.s.trial.index, 1))
|
|
impulse = copy.deepcopy(audit.event_integrals)
|
|
force = before['applied']['events'][0]['force_world']
|
|
assert impulse[0]['force_impulse_Ns'] == pytest.approx([x * .002 for x in force])
|
|
audit.tick, audit.needs_reference = 5, True
|
|
next_state = {**state, 'refreshes': 2}
|
|
assert audit._reference_event({'state': next_state}, 'next_reference', next_state, {'causes': []}, 5) == ()
|
|
assert audit.event_integrals == impulse
|
|
# The public consumer returns immediately after this dispatch, before _events.
|
|
audit_path = ROOT / 'source/SkillFactory/SkillFactory/legs/contact_cycle_sim/evaluation_audit.py'
|
|
tree = ast.parse(audit_path.read_text())
|
|
consumer = next(n for n in ast.walk(tree) if isinstance(n, ast.FunctionDef) and n.name == '_consume')
|
|
text = ast.unparse(consumer)
|
|
assert text.index('return handled') < text.index('self._events(')
|
|
|
|
|
|
@pytest.mark.parametrize('failure', ['setter', 'buffer', 'duplicate_schedule', 'duplicate_setter', 'pose'])
|
|
def test_exception_restores_guard_stack_and_permissions(setup, failure):
|
|
with setup() as f:
|
|
c, h, s = f.s.robot.permanent_wrench_composer, f.hooks, f.s
|
|
wrapper = c.set_forces_and_torques_index
|
|
schedule_wrapper = s.schedule.step
|
|
if failure == 'setter':
|
|
c.fail = True
|
|
elif failure == 'buffer':
|
|
c.corrupt = True
|
|
with pytest.raises((RuntimeError, ins.InstrumentationError)), h.wrench_update(c):
|
|
if failure in ('setter', 'buffer'):
|
|
s.apply_loads()
|
|
elif failure == 'duplicate_setter':
|
|
s.apply_loads()
|
|
c.set_forces_and_torques_index(**c.last)
|
|
else:
|
|
args = (s.time, s.reference()[0], s.edge_off, s.edge_on, s.scenarios, .002)
|
|
s.schedule.step(*args)
|
|
if failure == 'duplicate_schedule':
|
|
s.schedule.step(*args)
|
|
else:
|
|
s.robot.data.body_com_pos_w.torch += 1
|
|
c.set_forces_and_torques_index()
|
|
assert h._load_owner is h._replacement_owner is None
|
|
assert c.set_forces_and_torques_index is wrapper and s.schedule.step is schedule_wrapper
|
|
with pytest.raises(ins.InstrumentationError):
|
|
f.observer.supplemental(s)
|
|
# Instrumentation unwound first, runtime hooks restored original instance ownership.
|
|
assert 'set_forces_and_torques_index' not in vars(c)
|
|
assert 'step' not in vars(s.schedule)
|
|
|
|
|
|
@pytest.mark.parametrize('change', ['past', 'future', 'scheduler'])
|
|
def test_stale_future_or_changed_schedule_rejected(setup, change):
|
|
with setup() as f:
|
|
apply_one(f)
|
|
if change == 'past':
|
|
f.s.substeps += 1
|
|
elif change == 'future':
|
|
f.s.substeps.zero_()
|
|
else:
|
|
f.s.schedule.start += 1
|
|
with pytest.raises(ins.InstrumentationError):
|
|
f.observer.supplemental(f.s)
|
|
|
|
|
|
def test_p2_begin_trial_replaces_schedule_clears_capture_without_extra_reset(setup):
|
|
with setup(trial=0) as f:
|
|
assert f.env.step(torch.zeros(1, 3)).stop is None
|
|
old_state = f.s
|
|
old_schedule = old_state.schedule
|
|
f.env._stop(('functional_mock_failure',))
|
|
f.env.acknowledge_finalized(f.env.stop_result)
|
|
before = f.s.robot.permanent_wrench_composer.set_calls
|
|
f.env.begin_trial(f.s.protocol, 1)
|
|
assert f.env._cycle_state is not old_state
|
|
assert 'step' not in vars(old_schedule)
|
|
assert f.observer._state is f.env._cycle_state
|
|
assert f.observer._capture is None
|
|
assert f.evidence[-1][0] == 'initial' and f.evidence[-1][1]['applied'] is None
|
|
assert f.env._cycle_state.robot.permanent_wrench_composer.set_calls == before
|
|
assert f.hooks._load_owner is f.hooks._replacement_owner is None
|
|
|
|
|
|
@pytest.mark.parametrize('kind', ['ImplicitActuator', 'IdealPDActuator', 'DelayedPDActuator'])
|
|
def test_pinned_source_actuator_delay_layout_complete(setup, backend, kind):
|
|
with setup() as f:
|
|
a = backend.actuator(kind)
|
|
f.s.robot.actuators = {'joints': a}
|
|
if kind == 'DelayedPDActuator':
|
|
for name in ins.DELAY_NAMES:
|
|
delay = getattr(a, name)
|
|
delay.set_time_lag(2)
|
|
for i in range(6):
|
|
delay.compute(torch.full((1, 3), float(i)))
|
|
snapshot = f.observer.supplemental(f.s)['actuator_state']['groups']['joints']
|
|
assert snapshot['implicit_solver'] == (kind == 'ImplicitActuator')
|
|
if kind == 'DelayedPDActuator':
|
|
d = snapshot['buffers']['positions_delay_buffer']
|
|
assert d['_time_lags'] == [2]
|
|
assert d['_circular_buffer']['_num_pushes'] == [6]
|
|
assert [row[0][0] for row in d['_circular_buffer']['_buffer']] == [2., 3., 4., 5.]
|
|
else:
|
|
assert snapshot['memory'] == 'stateless_controller'
|
|
|
|
|
|
@pytest.mark.parametrize('unsupported', ['extra', 'subclass', 'newton', 'empty', 'delay_extra'])
|
|
def test_unsupported_hidden_actuator_state_fails_closed(setup, backend, unsupported):
|
|
with setup() as f:
|
|
robot = f.s.robot
|
|
if unsupported == 'extra':
|
|
robot.actuators['joints'].secret_history = torch.zeros(1)
|
|
elif unsupported == 'subclass':
|
|
robot.actuators['joints'].__class__ = type('ImplicitActuator', (type(robot.actuators['joints']),), {})
|
|
elif unsupported == 'newton':
|
|
robot._has_newton_actuators = True
|
|
elif unsupported == 'empty':
|
|
robot.actuators = {}
|
|
else:
|
|
robot.actuators['joints'] = backend.actuator('DelayedPDActuator')
|
|
robot.actuators['joints'].positions_delay_buffer._circular_buffer.secret = 1
|
|
with pytest.raises(ins.InstrumentationError):
|
|
f.observer.supplemental(f.s)
|
|
|
|
|
|
def test_rng_generator_inventory_no_draw_and_owned_copies():
|
|
generators = {'python': random.Random(4), 'numpy': np.random.default_rng(5),
|
|
'legacy': np.random.RandomState(6), 'torch': torch.Generator().manual_seed(7)}
|
|
before = ins.rng_snapshot(None, backend_rng, generators)
|
|
after = ins.rng_snapshot(None, backend_rng, generators)
|
|
assert before == after
|
|
after['generators']['torch'][0] = -1
|
|
assert ins.rng_snapshot(None, backend_rng, generators) == before
|
|
with pytest.raises(ins.InstrumentationError):
|
|
ins.rng_snapshot(None, backend_rng, {'unbound': object()})
|
|
|
|
|
|
@pytest.mark.parametrize('value', [{}, {'coverage': {}}, {'coverage': {'x': {}}},
|
|
{'coverage': {'x': {'status': 'unavailable', 'sources': ['physx'], 'evidence': 'No getter', 'state': None}}}])
|
|
def test_missing_invalid_unavailable_backend_rng_is_a_blocker(value):
|
|
with pytest.raises(ins.InstrumentationError):
|
|
ins.qualify_backend_rng(value)
|
|
|
|
|
|
def test_explicit_not_applicable_is_not_fabricated_rng_state():
|
|
value = scoped({'coverage': {'x': {'status': 'not_applicable', 'sources': [__file__],
|
|
'evidence': 'CPU mock has no solver RNG; not a production qualification', 'state': None}}})
|
|
assert ins.qualify_backend_rng(value) == value
|
|
value['coverage']['x']['state'] = [0]
|
|
with pytest.raises(ins.InstrumentationError):
|
|
ins.qualify_backend_rng(value)
|
|
with pytest.raises(ins.InstrumentationError):
|
|
ins.EvaluationInstrumentation(None, backend_rng=None, generators={})
|
|
|
|
|
|
def test_backend_source_inventory_hashes_and_real_import_required():
|
|
for path, digest in ins.BACKEND_SOURCE_INVENTORY.values():
|
|
assert sha256(Path(path).read_bytes()).hexdigest() == digest
|
|
with pytest.raises(ins.InstrumentationError, match='identity'):
|
|
ins.verify_backend_sources()
|
|
data = Path(ins.BACKEND_SOURCE_INVENTORY['isaaclab_physx.assets.articulation.articulation_data'][0]).read_text()
|
|
assert '(x, y, z, w)' in data
|
|
kernels = Path(ins.BACKEND_SOURCE_INVENTORY['isaaclab.utils.warp.kernels'][0]).read_text()
|
|
assert 'global_force_at_com_w[ei, bi] = forces[tid_env, tid_body]' in kernels
|
|
assert 'local_force_b[ei, bi] = forces[tid_env, tid_body]' in kernels
|
|
|
|
|
|
def test_no_call_before_initial_read_and_missing_setter_rejected(setup):
|
|
with setup() as f:
|
|
initial = f.observer.supplemental(f.s)
|
|
assert initial == f.evidence[0][1]
|
|
assert f.s.robot.permanent_wrench_composer.set_calls == 0
|
|
with f.hooks.wrench_update(f.s.robot.permanent_wrench_composer):
|
|
f.s.schedule.step(f.s.time, f.s.reference()[0], f.s.edge_off, f.s.edge_on, f.s.scenarios, .002)
|
|
with pytest.raises(ins.InstrumentationError, match='without completed'):
|
|
f.observer.supplemental(f.s)
|
|
|
|
|
|
def test_nested_observer_rejected_without_disturbing_original(setup):
|
|
with setup() as f:
|
|
setter = f.s.robot.permanent_wrench_composer.set_forces_and_torques_index
|
|
scheduled = f.s.schedule.step
|
|
with pytest.raises(ins.InstrumentationError, match='Nested'), ins.EvaluationInstrumentation(
|
|
f.env, backend_rng=backend_rng, generators={}):
|
|
pytest.fail('nested observer admitted')
|
|
assert f.s.robot.permanent_wrench_composer.set_forces_and_torques_index is setter
|
|
assert f.s.schedule.step is scheduled
|
|
apply_one(f)
|
|
|
|
|
|
def test_exit_restores_existing_guard_before_runtime_unwinds(setup):
|
|
with setup() as f:
|
|
c = f.s.robot.permanent_wrench_composer
|
|
guarded = c.set_forces_and_torques_index.__wrapped__
|
|
f.observer.__exit__(None, None, None)
|
|
assert c.set_forces_and_torques_index is guarded
|
|
assert 'step' not in vars(f.s.schedule)
|
|
with pytest.raises(RuntimeError, match='Only the bound physics action'):
|
|
c.set_forces_and_torques_index()
|
|
assert f.hooks._load_owner is f.hooks._replacement_owner is None
|
|
|
|
|
|
def test_actual_total_includes_nonzero_guide_auxiliary_and_event(setup):
|
|
with setup() as f:
|
|
s = f.s
|
|
s.command_clock = s.protocol.evidence_clock(s.trial.index, 2400)
|
|
s.time[:] = 4.8
|
|
s.stiffness[:] = torch.tensor([0., 0., 0., 1., 1., 1.])
|
|
s.damping[:] = 1.
|
|
# Frozen root getter mock has zero velocity, so give it a known physical velocity.
|
|
root = s.root()
|
|
s.root = lambda: (root[0], root[1], torch.tensor([[.1, .2, 0.]]), root[3])
|
|
applied = apply_one(f)['applied']
|
|
assert s.guide.any() and s.auxiliary.any() and s.external.any()
|
|
expected = (s.guide + s.auxiliary + s.external)[0]
|
|
torch.testing.assert_close(torch.tensor(applied['total_com_wrench']), expected)
|
|
|
|
|
|
@pytest.mark.parametrize('field', ['evidence_scope', 'unobserved_internals'])
|
|
def test_rng_scope_is_mandatory_and_copied(field):
|
|
value = backend_rng(None)
|
|
copied = ins.qualify_backend_rng(value)
|
|
value[field].clear()
|
|
assert copied[field]
|
|
with pytest.raises(ins.InstrumentationError):
|
|
ins.qualify_backend_rng(value)
|
|
|
|
|
|
@pytest.mark.parametrize('replacement', ['not_applicable', 'observed', None, [0]])
|
|
def test_native_unknowns_cannot_be_not_applicable_or_pseudo_state(replacement):
|
|
value = backend_rng(None)
|
|
value['unobserved_internals']['internal_stochastic_state_if_any'] = replacement
|
|
with pytest.raises(ins.InstrumentationError):
|
|
ins.qualify_backend_rng(value)
|
|
|
|
|
|
def test_complete_backend_or_replay_claim_rejected():
|
|
value = backend_rng(None)
|
|
value['evidence_scope']['claims']['deterministic_replay'] = True
|
|
with pytest.raises(ins.InstrumentationError):
|
|
ins.qualify_backend_rng(value)
|