ExoWrist_Smolvla / code /intent_rack_demo /scripts /audit_shared_intent_system.py
Lyndow's picture
Add verified ExoWrist test assets (623-716)
aaa8933 verified
Raw History Blame Contribute Delete
4.27 kB
"""Require actual learned initiation AND complete physics, retaining failures."""
import argparse
import json
from pathlib import Path
import numpy as np
def main():
p = argparse.ArgumentParser(); p.add_argument('--root', type=Path, required=True); a = p.parse_args()
spec = json.loads((a.root / 'manifest.json').read_text()); batch = json.loads((a.root / 'results.json').read_text())
declared = {r['name']: r for r in spec['cases']}; completed = {r['name']: r for r in batch['cases']}
if not batch['all_cases_completed'] or set(declared) != set(completed) or len(completed) != len(batch['cases']):
raise ValueError('all declared cases must finish exactly once')
cases = []
for name, s in declared.items():
root = a.root / name; r = completed[name]; positive = s['expected_assist']
row = {'name': name, 'expected_assist': positive, 'returncode': r['returncode'], 'passed': False}
if r['returncode'] or not all((root / f).exists() for f in ('result.json', 'trace.json', 'task_audit.json')):
row['failure'] = 'startup/process/artifact failure'; cases.append(row); continue
result = json.loads((root / 'result.json').read_text()); trace = json.loads((root / 'trace.json').read_text())
physics = json.loads((root / 'task_audit.json').read_text())
decisions = [t.get('joint_model_decision') for t in trace]
contract = bool(trace and all(d and d.get('joint_model_trained') is True
and d.get('learned_intent_prediction') is True and d.get('forced') is False
and d.get('teacher_or_object_ground_truth_input') is False for d in decisions)
and result.get('joint_architecture') == 'shared_spatial_intent'
and result.get('forced_assist') is False and result.get('external_task_request_sec') is None)
active = [d for d in decisions if d and d.get('raw_model_action') is not None]
negatives = {d['intent_observation_timestamp_sec'] for d in decisions
if d and d['intent_probabilities'][1] >= .9 and not d['need_assist']}
commands = np.array([[t['target'][f'joint{i}'] for i in range(1, 7)] + [t['target']['gripper_joint1']] for t in trace])
drift = float(np.abs(commands - commands[0]).max()) if len(commands) else None
clean = bool(trace and result.get('failure') is None and result.get('coupling_under_0_5mm_all_physics_steps')
and result.get('additional_contact_audit', {}).get('no_unexpected_contacts_observed'))
duration = len(trace) == {**spec['base_arguments'], **s['arguments']}['steps']
triggered = result.get('assistance_trigger_sim_sec') is not None and bool(active)
correct_negative = bool(not positive and not triggered and not active and len(negatives) >= 2 and duration and drift < 1e-10)
row.update(source_contract=contract, clean_physics=clean, triggered=triggered,
trigger_sec=result.get('assistance_trigger_sim_sec'), model_action_calls=len(active),
negative_distinct_confident_observations=len(negatives), command_drift=drift,
full_duration_observed=duration, task_audit=physics,
rack_max_height_m=result.get('rack_max_height_m'), rack_initial_xyz=result.get('rack_initial_xyz'),
passed=bool(contract and clean and ((positive and triggered and physics.get('simulation_task_checks_pass')) or correct_negative)))
cases.append(row)
result = {'cases': cases, 'all_cases_completed': True,
'positive_cases': sum(r['expected_assist'] for r in cases),
'positive_full_task_passed': sum(r['expected_assist'] and r['passed'] for r in cases),
'negative_cases': sum(not r['expected_assist'] for r in cases),
'negative_correct_hold': sum(not r['expected_assist'] and r['passed'] for r in cases),
'single_shared_context_checkpoint': True, 'external_modular_intent_gate_used': False,
'hard_request_latch_and_binary_actuator_retained': True, 'real_hardware_tested': False,
'independent_test_set': False}
(a.root / 'shared_intent_audit.json').write_text(json.dumps(result, indent=2) + '\n')
print(json.dumps({k: v for k, v in result.items() if k != 'cases'}))
if __name__ == '__main__': main()