Files
MeltMind/tools/inventory_g1_materials.py
T

80 lines
7.5 KiB
Python

"""Inventory existing metadata and NPZ member names only; no geometry processing.
Identity-bearing output is for the designated custodian, never a blind view.
No original archive/VTU/LOG or NPZ payload is read. Historical mixed JSON is
parsed, but only pre-existing geometry fields are selected; process/results
fields are not exported or used. No parent identity is inferred from filenames.
"""
from pathlib import Path
from zipfile import ZipFile
from collections import Counter, defaultdict
import hashlib,json,re,resource,time
CASE=re.compile(r'\d{8}_[a-zA-Z0-9]+_step_\d{3}')
def write(path,data):
path.write_text(json.dumps(data,indent=2,ensure_ascii=False,allow_nan=False)+'\n')
def main():
start=time.monotonic();out=Path('artifacts/s2-g1-inventory-2026-11-14');out.mkdir(exist_ok=False)
private=out/'custodian';public=out/'public';private.mkdir();public.mkdir()
base=Path('artifacts/intake-2026-11-13')
inputs={n:base/n for n in ['source_groups.json','geometry_log_census.json','geometry_screening.json']}
groups=json.loads(inputs['source_groups.json'].read_text());cases=sorted(c for v in groups.values() for c in v);case_set=set(cases)
metadata=json.loads(inputs['geometry_log_census.json'].read_text())
allowed=['bbox_size_raw','covariance_eigenvalues','exact_sorted_points_sha256']
historic={r['case']:{k:r[k] for k in allowed if k in r} for r in metadata};del metadata
screening=json.loads(inputs['geometry_screening.json'].read_text());pairs=screening['candidate_pairs'];assert len(pairs)==30
exposed_old={p[k] for p in pairs for k in ['a','b']};assert exposed_old<=case_set
caches=defaultdict(list);exposure=defaultdict(set);npz_count=0
# Directory names are evidence of previous individual work, not independent truth.
diagnostic_prefixes=('s1-real-scoring','s1-sampled-o2','e6-','o2-rep','o2a-','capacity-projectors','physical-support','routes-')
for path in sorted(Path('artifacts').rglob('*')):
if not path.is_file() or out in path.parents:continue
ids=set(CASE.findall(str(path)))&case_set
stage=path.parts[1]
if stage.startswith(diagnostic_prefixes):
for case in ids:exposure[case].add(stage)
if path.suffix!='.npz':continue
npz_count+=1
with ZipFile(path) as z:keys=set(n.removesuffix('.npy') for n in z.namelist())
surface=({'points','boundary'}<=keys or {'points_raw','boundary_triangles'}<=keys)
if surface:
st=path.stat();entry={'path':str(path),'bytes':st.st_size,'mtime_ns':st.st_mtime_ns,'surface_coordinate_key':'points' if 'points' in keys else 'points_raw','surface_index_key':'boundary' if 'boundary' in keys else 'boundary_triangles','contains_field_labels':'fill_time_raw' in keys,'validation':'ZIP member-name availability only; no arrays read or geometry validity asserted','producer_version':'E1 contract' if stage=='s2-e1-2026-11-14' else 'existing stage source/receipt; not revalidated'}
for case in ids:caches[case].append(entry)
rows=[]
for case in cases:
events=sorted(exposure[case]);known=case in exposed_old or bool(events)
rows.append({'case':case,'source_key':case.split('_')[1],'source_key_evidence':str(inputs['source_groups.json']),
'verified_parent_geometry':None,'parent_provenance':None,'parent_gap':'No independently verified CAD parent/source relationship found in existing reviewed manifests; source key is not a verified parent',
'exposure_state':'KNOWN_DEVELOPMENT_EXPOSED' if known else 'UNKNOWN',
'old_30_pair_endpoint':case in exposed_old,'individual_diagnostic_stages':events,
'all_corpus_historical_screening':True,'unexposed_claim':False,'surface_caches':caches[case],
'historical_geometry_metadata':historic.get(case,{}),'historical_fingerprint_source':str(inputs['geometry_log_census.json']),
'historical_fingerprint_limit':'unweighted full point-cloud covariance/extent/hash; mesh-density dependent; mixed-cell cases not tet-only; not note16 area/volume weighted descriptor',
'note16_complete_fingerprint':False,'note16_fingerprint_path':None,'independent_holdout_eligible':False})
by_case={r['case']:r for r in rows};cluster_rows=[]
for key,members in sorted(groups.items()):
n=sum(by_case[c]['exposure_state']=='KNOWN_DEVELOPMENT_EXPOSED' for c in members)
cluster_rows.append({'source_key':key,'members':sorted(members),'known_exposed_members':n,'state':'EXPOSED_CLUSTER' if n else 'UNKNOWN_EXPOSURE_CLUSTER','verified_parent_cluster':False,'holdout_eligible':False})
old=[{'a':p['a'],'b':p['b'],'historical_rank':i+1,'discovery':'legacy covariance/extent nearest-neighbor screen','discovery_source':str(inputs['geometry_screening.json']),'development_exposed':True,'independent_discovery_evidence':None,'confirmed_relation':None,'natural_positive_truth':False} for i,p in enumerate(pairs)]
write(private/'parts.json',rows);write(private/'source_clusters.json',cluster_rows);write(private/'old_exposed_pairs.json',old)
write(private/'independent_natural_pairs.json',{'pairs':[],'status':'MISSING_INDEPENDENT_SOURCE_EVIDENCE','not_a_claim_of_absence_of_duplicates':True})
private_manifest=[{'file':p.name,'sha256':hashlib.sha256(p.read_bytes()).hexdigest(),'bytes':p.stat().st_size} for p in sorted(private.glob('*.json'))]
write(private/'manifest.json',private_manifest)
summary={'scope':'existing material inventory only; no new descriptors, candidates, pair extraction, labels from original source, LOG reread, registration, training or GPU',
'cases':len(rows),'source_keys':len(groups),'verified_parent_links':0,'verified_independent_natural_positive_pairs':0,
'old_exposed_pairs':len(old),'old_exposed_endpoint_cases':len(exposed_old),
'exposure_counts':dict(Counter(r['exposure_state'] for r in rows)),
'cluster_exposure_counts':dict(Counter(r['state'] for r in cluster_rows)),
'independent_holdout_eligibility_certified_cases':0,'surface_cache_cases':sum(bool(r['surface_caches']) for r in rows),
'surface_cache_records':sum(len(r['surface_caches']) for r in rows),'npz_member_directories_inspected':npz_count,
'legacy_geometry_metadata_cases':sum(bool(r['historical_geometry_metadata']) for r in rows),'note16_complete_fingerprint_cases':0,
'custody':'IDENTITY_TABLES_PREPARED_LOCALLY; designated custodian/interface pending Claude; no anonymous IDs or blind bundle generated',
'identity_manifest_sha256':hashlib.sha256((private/'manifest.json').read_bytes()).hexdigest(),
'input_sha256':{str(p):hashlib.sha256(p.read_bytes()).hexdigest() for p in inputs.values()},
'producer_sha256':hashlib.sha256(Path(__file__).read_bytes()).hexdigest(),
'interpretation':'0 certified independent positives/eligible cases means missing proof, not zero true relatives; unknown exposure cannot be promoted to unexposed. Old geometry screening is not the proposed fingerprint. Source keys are not CAD ancestry.',
'mixed_metadata_disclosure':'Existing geometry_log_census JSON also stores historical process/output fields; parsed as a container, only bbox/covariance/point hash selected. Other fields not used or exported. NPZ access is ZIP member names only, no payload.',
'cpu_seconds':sum(resource.getrusage(resource.RUSAGE_SELF)[:2]),'wall_seconds':time.monotonic()-start,'peak_rss_bytes':resource.getrusage(resource.RUSAGE_SELF).ru_maxrss*1024}
write(public/'summary.json',summary);print(json.dumps(summary,ensure_ascii=False,indent=2))
if __name__=='__main__':main()