35 lines
3.0 KiB
Python
35 lines
3.0 KiB
Python
"""One supervised extraction/render task, addressed by sealed-list ordinal."""
|
|
from pathlib import Path
|
|
from zipfile import ZipFile
|
|
import hashlib,json,sys,time,resource
|
|
import numpy as np
|
|
from g1_registration_cost import geometry_only
|
|
from g1_blind_geometry import surface,ply_bytes
|
|
from render_g1_blind_surface import render_surface
|
|
|
|
ROOT=Path('artifacts/s2-g1-blind120-2026-11-14')
|
|
def main():
|
|
start=time.monotonic();index=int(sys.argv[1]);c=json.loads((ROOT/'extraction-contract.json').read_text())
|
|
for p,h in c['source_sha256'].items():
|
|
if hashlib.sha256(Path(p).read_bytes()).hexdigest()!=h:raise ValueError('Extraction code changed')
|
|
mapping=json.loads((ROOT/'custodian/sampling-and-mapping.json').read_text());case=mapping['unique_cases'][index]
|
|
asset=hashlib.sha256(bytes.fromhex(mapping['anonymous_id_secret_hex'])+b'asset\0'+case.encode()).hexdigest()[:32]
|
|
out=ROOT/'custodian/geometry'/asset;out.mkdir(parents=True,exist_ok=False)
|
|
st=Path('data.zip').stat();verification=json.loads(Path('artifacts/intake-2026-11-13/archive_verification.json').read_text())
|
|
if (st.st_size,st.st_mtime_ns,st.st_ino)!=(verification['bytes'],verification['mtime_ns'],verification['inode']):raise ValueError('Archive provenance changed')
|
|
entries=json.loads((ROOT/'custodian/geometry-source-index.json').read_text())['cases'];entry=next(e for e in entries if e['case']==case)
|
|
usable=[e for e in entry['existing_surface_caches'] if not e['contains_field_labels']]
|
|
if usable:
|
|
e=usable[0];p=Path(e['path']);stat=p.stat()
|
|
if (stat.st_size,stat.st_mtime_ns)!=(e['bytes'],e['mtime_ns']):raise ValueError('Cache changed since inventory')
|
|
with np.load(p,allow_pickle=False) as z:x=z[e['surface_coordinate_key']];f=z[e['surface_index_key']]
|
|
source_mode='existing geometry cache, coordinate and boundary arrays only'
|
|
else:
|
|
with ZipFile('data.zip') as z:
|
|
with z.open(case+'_sim.vtu') as stream:g=geometry_only(stream)
|
|
x=g['points'];f=g['boundary'];source_mode='geometry prefix only, stop before PointData/CellData'
|
|
x,f=surface(x,f);(out/'surface.ply').write_bytes(ply_bytes(x,f));render_surface(x,f,out)
|
|
receipt={'index':index,'asset_id':asset,'source_mode':source_mode,'vertices':len(x),'triangles':len(f),'files':[{'name':p.name,'bytes':p.stat().st_size,'sha256':hashlib.sha256(p.read_bytes()).hexdigest()} for p in sorted(out.iterdir())],'wall_seconds':time.monotonic()-start,'cpu_seconds':sum(resource.getrusage(resource.RUSAGE_SELF)[:2]),'peak_rss_bytes':resource.getrusage(resource.RUSAGE_SELF).ru_maxrss*1024,'registration':False,'labels_read':False,'geometry_modified':'interior unused vertices omitted; numerical coordinate values and boundary triangles preserved; view centering only in PNG'}
|
|
(out/'receipt.json').write_text(json.dumps(receipt,indent=2)+'\n');print(json.dumps({k:receipt[k] for k in ['index','vertices','triangles','wall_seconds','cpu_seconds','peak_rss_bytes']}))
|
|
if __name__=='__main__':main()
|