"""Check gate and edge vectors under the candidate frame's sign orbit.""" import json from pathlib import Path import numpy as np from route_feasibility import spectral_features base=Path('artifacts/routes-2026-11-13');rows=[] rng=np.random.default_rng(421);q,_=np.linalg.qr(rng.normal(size=(3,3)));q*=np.linalg.det(q) for p in sorted(base.glob('*.routes.json')): r=json.loads(p.read_text());a=np.load(base/(r['case']+'.route_arrays.npz'));d=np.load(Path('artifacts/intake-2026-11-13/samples')/(r['case']+'.npz')) x=d['points_raw'];gate=d['gate_location_raw'];t=a['tensor'];f=spectral_features(t);e=f['basis'];full=f['full'];entry={'case':r['case'],'checks':{}} for name,R in [('rotation',q),('reflection',q@np.diag([-1.,1.,1.]))]: shift=np.array([3.1,-7.,2.]);xp=x@R.T+shift;gp=gate@R.T+shift ep=spectral_features(R@t@R.T)['basis'];expected=R@e;sign=np.sign(np.einsum('nij,nij->nj',ep,expected));sign[sign==0]=1;ep=ep*sign[:,None,:] local_gate=np.einsum('ni,nij->nj',gate-x,e);local_gate_p=np.einsum('ni,nij->nj',gp-xp,ep) edge=d['edges'];chosen=edge[full[edge[:,0]]];chosen=chosen[np.linspace(0,len(chosen)-1,min(1024,len(chosen)),dtype=int)] i,j=chosen.T;local_edge=np.einsum('ni,nij->nj',x[j]-x[i],e[i]);local_edge_p=np.einsum('ni,nij->nj',xp[j]-xp[i],ep[i]) entry['checks'][name]=dict(determinant=float(np.linalg.det(R)),gate_distance_max_error_raw=float(abs(np.linalg.norm(gp-xp,axis=1)-np.linalg.norm(gate-x,axis=1)).max()),gate_local_orbit_error_on_spectral_pass=float(abs(local_gate[full]-local_gate_p[full]).max()),edge_local_orbit_error_raw=float(abs(local_edge-local_edge_p).max()),checked_edges=len(chosen)) rows.append(entry) out=base/'pose_input_checks.json' if out.exists():raise FileExistsError(out) out.write_text(json.dumps({'cases':rows,'scope':'Transforms part and YML gate together, retaining full vectors. Tensor transform consistency itself was independently recomputed from rotated mesh in main probe. No model/predicted-field invariance claim.'},indent=2)+'\n') print(json.dumps(rows,indent=2))