72 lines
4.2 KiB
Python
72 lines
4.2 KiB
Python
"""Read-only scientific result verification; no estimator or reference rerun."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import numpy as np
|
|
if __package__:
|
|
from .run_o2a_transverse_refinement import diagnostics, mirror_map, MIRROR, region_masks
|
|
else:
|
|
from run_o2a_transverse_refinement import diagnostics, mirror_map, MIRROR, region_masks
|
|
|
|
|
|
def verify(out):
|
|
contract=json.loads((out/'execution_contract.json').read_text())
|
|
receipt=json.loads((out/'work_receipt.json').read_text())
|
|
summary=json.loads((out/'O2A_result.json').read_text())
|
|
assert receipt['new_estimates']==6 and receipt['reused_estimates']==2
|
|
assert not receipt['training'] and not receipt['new_reference_integration']
|
|
for path,digest in contract['input_sha256'].items():
|
|
assert hashlib.sha256(Path(path).read_bytes()).hexdigest()==digest,path
|
|
frozen_hash=hashlib.sha256((out/'execution_contract.json').read_bytes()).hexdigest()
|
|
assert frozen_hash==json.loads((out/'O2A.started.json').read_text())['contract_sha256']
|
|
fixed=dict(np.load(out/'fixed_anchors.npz')); anchors=fixed['query']
|
|
assert anchors.shape==(2197,3)
|
|
masks=region_masks(anchors)
|
|
assert {k:int(v.sum()) for k,v in masks.items()}==dict(all=2197,interior=275,wall=1584,end=338)
|
|
for k,v in masks.items(): np.testing.assert_array_equal(v,fixed[k])
|
|
arrays={}
|
|
for spec in contract['estimates']:
|
|
name=spec['name']; a=dict(np.load(out/(name+'.npz'))); arrays[name]=a
|
|
np.testing.assert_array_equal(a['query'],anchors)
|
|
assert a['tensor'].shape==(2197,3,3) and np.isfinite(a['tensor']).all()
|
|
np.testing.assert_allclose(a['tensor'],a['tensor'].transpose(0,2,1),atol=1e-13)
|
|
assert np.linalg.eigvalsh(a['tensor']).min()>-1e-12
|
|
assert np.trace(a['tensor'],axis1=1,axis2=2).max()<=1+1e-12
|
|
if spec['reuse']:
|
|
source=Path(contract['reuse_directory'])/f"z48_{spec['rule']}.npz"
|
|
assert (out/(name+'.npz')).read_bytes()==source.read_bytes()
|
|
else:
|
|
row=json.loads((out/(name+'.json')).read_text())
|
|
n=spec['nx']; assert row['nodes']==(n+1)**2*49 and row['tets']==n*n*48*6
|
|
assert row['samples']==(row['nodes'] if spec['rule']=='lumped_vertex' else row['tets']*4)
|
|
d=diagnostics(a['tensor']); stored=dict(np.load(out/(name+'_diagnostics.npz')))
|
|
for k,v in d.items(): np.testing.assert_allclose(v,stored[k],rtol=1e-12,atol=1e-13)
|
|
for region,mask in masks.items():
|
|
r=summary['estimates'][name]['regions'][region]
|
|
assert r['N']==int(mask.sum())
|
|
assert r['support']==int((mask&a['support_resolved']).sum())
|
|
assert r['quality']==int((mask&a['quadrature_quality']).sum())
|
|
assert sum(r['mode_counts'].values())==r['N']
|
|
np.testing.assert_allclose([r['full_spectral_split']['median'],r['full_spectral_split']['p95']],np.quantile(d['split'][mask],[.5,.95]),rtol=1e-12,atol=1e-13)
|
|
ids=mirror_map(anchors)
|
|
mirror_errors={}
|
|
for rule in ['lumped_vertex','tetra_four_point']:
|
|
a=arrays[f'xy24_standard_{rule}']; b=arrays[f'xy24_mirror_{rule}']
|
|
error=float(np.linalg.norm(b['tensor']-MIRROR@a['tensor'][ids]@MIRROR,axis=(1,2)).max())
|
|
mirror_errors[rule]=error
|
|
# Engineering identity check, not a new physical or spectral eligibility gate.
|
|
assert error<1e-10
|
|
old=Path(contract['reuse_directory'])
|
|
historical={}
|
|
for rule in ['lumped_vertex','tetra_four_point']:
|
|
a=dict(np.load(old/f'z24_{rule}.npz'))
|
|
historical[rule]=int((masks['end']&a['support_resolved']&a['quadrature_quality']).sum())
|
|
assert historical[rule]==0
|
|
return dict(status='PASS',contract_sha256=frozen_hash,input_hashes_verified=len(contract['input_sha256']),estimates_verified=8,new_estimates=6,reused_byte_identical=2,anchor_count=2197,region_counts={k:int(v.sum()) for k,v in masks.items()},mirror_covariance_max=mirror_errors,old_z24_qualified_endpoints=historical,verification_scope='Postprocessing and invariants only; no mesh, quadrature, optimization, training or reference recalculation.')
|
|
|
|
|
|
if __name__=='__main__':
|
|
p=argparse.ArgumentParser();p.add_argument('output',type=Path);a=p.parse_args()
|
|
print(json.dumps(verify(a.output),indent=2,allow_nan=False))
|