"""Pack HFD motion segments for the unchanged OmniHM Text/Speech evaluator. Also score the complete idle/listen/motion episode and each GT-defined phase. Physics is evaluated with the same FK, contact thresholds and jerk definition. """ import argparse import json import os import subprocess import sys from pathlib import Path from types import SimpleNamespace from common import WORK, OMG, OMNI, EVALUATOR, PEER, qpos_from_absolute, sha256, write_json from session_data import flattened_rows import numpy as np def verify_scores(cohort, generated, output): """Verify the complete score bundle against the frozen cohort, not file presence.""" def read(path): return json.loads(Path(path).read_text()) def require(ok, message): if not ok:raise ValueError(message) manifest=read(cohort/'manifest.json');identity=read(generated/'identity.json') protocol=read(output/'protocol.json');native=output/'motion' rows=flattened_rows(manifest['rows']);n=len(rows) ids=np.asarray([r['sample_id'] for r in rows]) require(identity['cohort_sha256']==sha256(cohort/'manifest.json'),'Generated cohort differs') require(all(protocol.get(k)==v for k,v in identity.items()),'Metric generation identity differs') require(protocol['count']==n and protocol['session_count']==len(manifest['rows']),'Metric counts differ') state=read(native/'run_state.json') require(state.get('status')=='complete' and state.get('kind')=='benchmark' and state.get('paper_row_complete') is True,'Native scoring is incomplete') raw=read(native/'metrics.json');paper=read(native/'paper_metrics.json') require(raw['protocol']['num_samples']==n,'Native sample count differs') require(paper.get('complete') is True and len(paper['values'])==14 and np.isfinite(np.asarray(paper['values'],float)).all(),'Incomplete/nonfinite paper row') sys.path[:0]=[str(OMNI),str(OMG/'src')] from metrics import build_paper_payload require(paper==build_paper_payload('text',raw),'Displayed metrics differ from raw native results') tracker=raw['tracker_executed'] require(tracker.get('enabled') is True and tracker.get('paper_eligible') is True and tracker['num_samples']==n,'Missing/noncanonical/partial tracking') for key in ('generated_retrieval_diagnostics','reference_retrieval_diagnostics'): require(raw['generated_target']['text'][key]['retrieval_num_samples']==n//32*32, 'Retrieval tail count differs') arrays={ 'sample_metrics.npz':('contact_sliding_speed','body_jerk_mean'), 'tracker_failure_flags.npz':('mpjpe','g_mpjpe','e_vel','e_acc','fall','joint_limit'), 'embeddings.npz':('reference_embeddings','generated_embeddings','text_embeddings', 'distribution_reference_embeddings','distribution_generated_embeddings')} for name,required in arrays.items(): with np.load(native/name,allow_pickle=False) as z: require(np.array_equal(z['sample_id'],ids),f'{name}: sample identities/order differ') require(set(required)<=set(z.files),f'{name}: missing metric arrays') require(all(z[k].dtype.kind in 'biufc' for k in required),f'{name}: nonnumeric metric array') for key in z.files: value=z[key] if value.dtype.kind in 'biufc': require(value.ndim>=1 and len(value)==n and np.isfinite(value).all(), f'{name}: invalid array {key}') with np.load(output/'inputs/conditions.npz',allow_pickle=False) as z: require(np.array_equal(z['sample_id'],ids),'Packed input identities differ') require(z['captions'].tolist()==[r['caption'] for r in rows],'Final-command captions differ') phase=read(output/'phase_physics.json') require(phase['summary']['all']['sources']==len(manifest['rows']),'Incomplete full-session physics') all_rows=[r for r in phase['per_segment'] if r['phase']=='all'] require(len(all_rows)==len(manifest['rows']) and {r['sample_id'] for r in all_rows} =={r['sample_id'] for r in manifest['rows']},'Full-session physics identities differ') for row in phase['per_segment']: require(all(np.isfinite(v) for k in ('generated','gt') for v in row[k].values()), 'Nonfinite phase physics') require(set(protocol['source_hashes'])=={str(p) for p in (OMNI/'evaluate.py',OMNI/'metrics.py',EVALUATOR)}, 'Missing native metric/encoder provenance') for path,expected in protocol['source_hashes'].items(): require(sha256(path)==expected,'Metric implementation/encoder changed: '+path) adapter=read(native/'hfd_adapter.json') require(adapter['adapter_sha256']==sha256(WORK/'native_eval.py'),'Native adapter changed') receipt=dict(complete=True,session_count=len(manifest['rows']),motion_segments=n, retrieval_count=n//32*32,cohort_sha256=identity['cohort_sha256'], paper_metrics_sha256=sha256(native/'paper_metrics.json'), scope='Completion/identity/finite-value check; no extra generation or score changes') write_json(output/'result_audit.json',receipt) return receipt def pack(rows, cohort, generated, destination): sys.path.insert(0,str(OMG/'src')) from omg.robots.g1.constants import G1_JOINT_NAMES pred=[];gt=[] for row in rows: s,e=row['score_start'],row['score_end'] with np.load(generated/(row.get('parent_sample_id',row['sample_id'])+'.npz')) as z:p=z['absolute'] with np.load(cohort/row['reference_file']) as z:g=z['absolute'] if len(p)