"""Validate a source-connected rerun; no model inference or training involved.""" from pathlib import Path import hashlib,json,sys import numpy as np import pandas as pd ROOT=Path(__file__).resolve().parents[1] out=Path(sys.argv[1] if len(sys.argv)>1 else 'recomputed');raw=Path(sys.argv[2] if len(sys.argv)>2 else 'raw_sources') v=json.loads((ROOT/'provenance/source_verification.json').read_text()) m=raw/'download_manifest.json' assert hashlib.sha256(m.read_bytes()).hexdigest()==v['complete_pass_manifest_sha256'],'Source acquisition manifest does not match the recorded source identities.' for name in ['gradient.npy','eval.npy']: np.testing.assert_array_equal(np.load(out/name,allow_pickle=False),np.load(ROOT/'data'/name,allow_pickle=False)) g=np.load(out/'geometry.npy',allow_pickle=False);assert g.shape==(167,16) s=pd.read_csv(ROOT/'data/selected_checkpoint_metrics.csv',float_precision='round_trip') for row in s.itertuples(index=False): z=g[g[:,0]==row[0]][0];np.testing.assert_allclose([z[3],z[8]],[row[1],row[2]],rtol=1e-10,atol=1e-12,equal_nan=True) p=np.load(out/'pca.npy',allow_pickle=False);ref=np.load(ROOT/'data/pca.npy',allow_pickle=False) np.testing.assert_array_equal(p[:,0],ref[:,0]);np.testing.assert_allclose(p[:,1:],ref[:,1:],rtol=1e-8,atol=1e-10) a=json.loads((out/'analysis_summary.json').read_text());assert a['zero_effective_update_steps']==[1];assert a['effective_norm_monotone'];assert a['max_stable_vs_gram_corner_error']<1e-6 sensitivity=pd.read_csv(ROOT/'data/corner_sensitivity.csv') for x,y in zip(a['amplitude_sensitivity'],sensitivity.itertuples(index=False)): assert x['lag']==y.lag and x['threshold']==y.amplitude_threshold assert x['eligible']==y.eligible_centers assert x['B_peak_step']==x['effective_peak_step']==y.peak_step_B_and_effective np.testing.assert_allclose([x['B_peak'],x['effective_peak']],[y.B_peak_cosine,y.effective_peak_cosine],atol=1e-6,rtol=0) print('PASS: original file identities, exact log values, selected geometric metrics, PCA scores, 18 sensitivity settings, and stable-form validation.')