60 lines
4.9 KiB
Python
60 lines
4.9 KiB
Python
"""Geometry-metadata-only selection; no field, label, distance or kernel read."""
|
|
import csv
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import numpy as np
|
|
|
|
|
|
def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest()
|
|
|
|
|
|
def main():
|
|
out=Path('artifacts/s1-panel-precheck-2026-11-14');out.mkdir(exist_ok=False)
|
|
groups_path=Path('artifacts/intake-2026-11-13/source_groups.json')
|
|
cards_path=Path('artifacts/routes-2026-11-13/static_data_card.csv')
|
|
groups=json.loads(groups_path.read_text())
|
|
# Read geometry metadata only. Outcome/audit columns are not used to select.
|
|
cards={r['case']:{k:r[k] for k in ['case','source_key','tet_nodes','tet_cells','mixed_topology']} for r in csv.DictReader(cards_path.open())}
|
|
key=lambda s:(int(s.split('_')[0]),s)
|
|
representatives=[]
|
|
for source,members in sorted(groups.items()):
|
|
case=min(members,key=key);r=cards[case]
|
|
assert r['source_key']==source
|
|
representatives.append(dict(case=case,source_key=source,numeric_prefix=int(case.split('_')[0]),tet_nodes=int(r['tet_nodes']),tet_cells=int(r['tet_cells']),mixed_topology=r['mixed_topology']=='True',source_members=len(members)))
|
|
representatives.sort(key=lambda r:(r['tet_nodes'],r['numeric_prefix'],r['case']))
|
|
rng=np.random.Generator(np.random.PCG64(20261114));selected=[];strata=[]
|
|
for index,ids in enumerate(np.array_split(np.arange(len(representatives)),3)):
|
|
chosen=set(map(int,rng.choice(ids,size=8,replace=False)))
|
|
strata.append(dict(tertile=index+1,representatives=len(ids),min_nodes=representatives[int(ids[0])]['tet_nodes'],max_nodes=representatives[int(ids[-1])]['tet_nodes']))
|
|
for rank in ids:
|
|
r=representatives[int(rank)];r.update(tertile=index+1,stable_rank=int(rank),selected=int(rank) in chosen)
|
|
if r['selected']:selected.append(dict(r,panel_index=len(selected)))
|
|
assert len(selected)==24 and len({r['source_key'] for r in selected})==24
|
|
for name,rows in [('representatives.csv',representatives),('panel.csv',selected)]:
|
|
with (out/name).open('w') as f:
|
|
w=csv.DictWriter(f,fieldnames=list(rows[0]),lineterminator='\n');w.writeheader();w.writerows(rows)
|
|
contract=dict(status='PANEL_SELECTED_COUNT_NOT_STARTED',approval='https://arcticnimbus.slack.com/archives/C0C78UFKGRM/p1794634657902719',
|
|
source_count=len(groups),inventory_cases=len(cards),selection_seed=20261114,rng='NumPy PCG64, one stream; low/middle/high strata in order; choice without replacement',numpy=np.__version__,
|
|
representative='Lowest numeric prefix in each existing source_key group; tie full case string',
|
|
tertiles='Sort representatives by (tet_nodes,numeric_prefix,case); numpy.array_split into three equal-count consecutive groups; no quantile interpolation',
|
|
publication_order='tertile, then stable rank in full representative ordering',strata=strata,
|
|
selected_input_fields=['case','source_key','tet_nodes'],mixed_topology='Retained and flagged; no silent exclusions or replacements',
|
|
input_sha256={str(p):sha(p) for p in [groups_path,cards_path,Path(__file__)]},panel_sha256=sha(out/'panel.csv'),representatives_sha256=sha(out/'representatives.csv'),
|
|
future_s1_parameters=dict(status='Declared before any run; S1 itself not authorized',reference_sampling_seed=2026111400,permutation_seeds=[2026111401,2026111402,2026111403,2026111404,2026111405],
|
|
reference_sampling='Sequential weighted sampling without replacement by m_i, b=2000, same IDs across arms',
|
|
stable_node_order='Original tetra-submesh node IDs ascending; raw node-ID mapping retained',
|
|
per_part_rng='PCG64 SeedSequence([base_seed,numeric_prefix]); independent per part, invariant to fold traversal; same seeds across folds/slices',
|
|
zero_gap_pattern='Strict gap > 0, no epsilon',diagnostic_absolute_tolerance=1e-10,
|
|
diagnostic_policy='Store raw positive excess and exact-positive count as well as >1e-10 count for raw q/g bounds and normalized ratio ordering; no clipping/redraw; diagnostic only',
|
|
six_arms=['A2','B6','C10','A_plus_shuffled_O2_block6','B_plus_shuffled_edge_block10','B_plus_zero_pattern_stratified_normalized_edge_shuffle10'],
|
|
primary='B versus same-dimension A+S; C versus same-dimension B+plain whole-edge-block shuffle',secondary='Normalized stratified control is sensitivity only, never a pass/fail gate'),
|
|
count_budget=dict(wall_seconds=1800,memory_bytes=1342177280,neighbor_visit_alarm=500000000,visit_cap=None),
|
|
dependencies='Count requires E6 R=10*mass-weighted median full-node d. New selected-part distance preparation awaiting explicit scope decision; no substitute radius.',
|
|
no_kernel=True,no_S1_score=True,no_training=True)
|
|
(out/'panel_contract.json').write_text(json.dumps(contract,indent=2)+'\n')
|
|
print(json.dumps(contract,indent=2));print((out/'panel.csv').read_text())
|
|
|
|
|
|
if __name__=='__main__':main()
|