From 2ba7800d3988044c43fb5d60861201824a65aa5c Mon Sep 17 00:00:00 2001 From: Frank14f <1515444314@qq.com> Date: Sat, 14 Nov 2026 21:28:47 +0800 Subject: [PATCH] Start bounded G1 copy calibration with fixed dimensionless route thresholds --- .../batch-started.json | 8 + .../contract.json | 63 ++++ .../public/partial-residual-checkpoint.json | 290 ++++++++++++++++++ .../public/postprocessing-contract.json | 6 + .../public/preparation.json | 13 + .../public/startup-progress-snapshot.json | 17 + .../threshold-ruling-source.txt | 30 ++ .../copy-tests-receipt.json | 8 + .../runner-test-source.py | 26 ++ .../runner-tests.json | 22 ++ docs/s2-g1-copy-calibration-2026-11-14.md | 35 +++ tools/g1_copy_calibration.py | 101 ++++++ tools/prepare_g1_copy_calibration.py | 75 +++++ tools/run_g1_copy_calibration.py | 100 ++++++ tools/summarize_g1_copy_calibration.py | 55 ++++ tools/test_g1_copy_calibration.py | 27 ++ 16 files changed, 876 insertions(+) create mode 100644 artifacts/s2-g1-copy-calibration-2026-11-14/batch-started.json create mode 100644 artifacts/s2-g1-copy-calibration-2026-11-14/contract.json create mode 100644 artifacts/s2-g1-copy-calibration-2026-11-14/public/partial-residual-checkpoint.json create mode 100644 artifacts/s2-g1-copy-calibration-2026-11-14/public/postprocessing-contract.json create mode 100644 artifacts/s2-g1-copy-calibration-2026-11-14/public/preparation.json create mode 100644 artifacts/s2-g1-copy-calibration-2026-11-14/public/startup-progress-snapshot.json create mode 100644 artifacts/s2-g1-copy-calibration-2026-11-14/threshold-ruling-source.txt create mode 100644 artifacts/s2-g1-copy-calibration-tests-2026-11-14/copy-tests-receipt.json create mode 100644 artifacts/s2-g1-copy-calibration-tests-2026-11-14/runner-test-source.py create mode 100644 artifacts/s2-g1-copy-calibration-tests-2026-11-14/runner-tests.json create mode 100644 docs/s2-g1-copy-calibration-2026-11-14.md create mode 100644 tools/g1_copy_calibration.py create mode 100644 tools/prepare_g1_copy_calibration.py create mode 100644 tools/run_g1_copy_calibration.py create mode 100644 tools/summarize_g1_copy_calibration.py create mode 100644 tools/test_g1_copy_calibration.py diff --git a/artifacts/s2-g1-copy-calibration-2026-11-14/batch-started.json b/artifacts/s2-g1-copy-calibration-2026-11-14/batch-started.json new file mode 100644 index 000000000..83723a1d1 --- /dev/null +++ b/artifacts/s2-g1-copy-calibration-2026-11-14/batch-started.json @@ -0,0 +1,8 @@ +{ + "pid": 2, + "started_unix": 1794662686.7935393, + "jobs": 22, + "pairs": 62, + "workers": 4, + "contract_sha256": "3fecf5e32757e6946e54e746061f921cb67eb72f4c8011daec8f0ba5c2a8ae03" +} diff --git a/artifacts/s2-g1-copy-calibration-2026-11-14/contract.json b/artifacts/s2-g1-copy-calibration-2026-11-14/contract.json new file mode 100644 index 000000000..592d87d8c --- /dev/null +++ b/artifacts/s2-g1-copy-calibration-2026-11-14/contract.json @@ -0,0 +1,63 @@ +{ + "authorizing_rulings": [ + "1794661944.308269", + "1794662380.787319" + ], + "code_sha256": { + "tools/prepare_g1_copy_calibration.py": "eb4945b0fe69bc40ec9f9168c1d2dece477a01f566a8b506f9e39e9ed8723486", + "tools/g1_copy_calibration.py": "c5516eaae798be0af863c2d7cd1688d31485a938e46d627c440d31bca873fc39", + "tools/run_g1_copy_calibration.py": "2e19cfba2d8def2d6be32bea0a951cda4b4a895149cdf7b77a0d11ccf9082801", + "tools/g1_registration_cost.py": "c3d722a8cfd067dfd726f8a8729e72c37dbc63e2c24ba1b0e3d767d47f7756ba", + "tools/s2_e1_supervisor.py": "6753c9ceb0b932047ba505bd15681f109e9407bdb58fd96c55e1431a3f1b4a02", + "tools/audit_samples.py": "a3daf70ec3bcb77bf46d9dc4887d552cf7c422117880a169969780012278cd70", + "tools/boundary_distance.py": "a45c1cbce92521a96eb814913b4f465b926c0b3883932ab0b7c37d11db113ed7" + }, + "input_sha256": { + "artifacts/s2-g1-copy-calibration-2026-11-14/custodian/plan.json": "2c9c09e143020345115ee9146546f97686f033b25cdb830dc8f1d166c9283a94", + "artifacts/s2-g1-inventory-2026-11-14/custodian/parts.json": "977df4e1910607a2b540dce4a4d95dff247414c88daa54415a6799feb71abb35", + "artifacts/s2-g1-custody-handoff-2026-11-14/custodian/rigid-calibration-inputs.json": "d11b3bef2c23e010c375fa0897c529577821aea729579d91a586d3d3f5ec1bdf" + }, + "archive": "data.zip", + "archive_verification": "artifacts/intake-2026-11-13/archive_verification.json", + "existing_registration_cache": "artifacts/s2-e1-2026-11-14/cost-geometry", + "sample_seed": [ + 2026111414 + ], + "synthetic_parts": 20, + "synthetic_pairs": 60, + "natural_visual_rigid_pairs": 2, + "synthetic_transform": "independent Haar proper R; mirror R diag(-1,1,1); scale 2; t=Rg*U[-3,3]^3; original face indices retained", + "sampling": "unchanged area-PPS 2000; source numeric prefix, unique synthetic target prefix 100000000+pair_index; natural original numeric prefixes", + "registration": "unchanged g1_registration_cost.register, both routes, det +/- starts, full-triangle two-way P95; no remeshing", + "threshold_policy": { + "physical_residual": "raw P95 / mean(Rg_a,Rg_b)", + "physical_size_gate": "max(Rg_a,Rg_b)/min(Rg_a,Rg_b) <= 1.05", + "scale_free_residual": "unchanged individual Rg-normalized P95", + "positive_kinds_physical": [ + "rigid", + "mirror", + "natural_visual_rigid" + ], + "positive_kinds_scale_free": [ + "rigid", + "mirror", + "scale", + "natural_visual_rigid" + ], + "per_pair_residual": "min of det+ and det- branch best P95 within route", + "threshold": "3 * largest positive-pair residual on each route", + "link": "either route meets own threshold; physical also requires Rg ratio gate", + "negative_control": "all 20 scale copies must fail physical size gate; any pass stops", + "mirror_check": "flag a mirror copy when det- does not strictly win; do not silently discard symmetric cases" + }, + "workers": 4, + "per_pair_wall_seconds": 1800, + "per_worker_rss_bytes": 1342177280, + "aggregate_rss_bytes": 21474836480, + "worker_cpu_budget_seconds": 360000, + "wall_seconds": 28800, + "disk_bytes": 21474836480, + "scope": "only calibration; formal candidate generation and registration queue follow calibration checkpoint", + "failed_jobs": "retained; no retry/replacement; final checkpoint after 22 jobs; any failure leaves calibration incomplete", + "no_simulation_fields_no_training_no_gpu": true +} diff --git a/artifacts/s2-g1-copy-calibration-2026-11-14/public/partial-residual-checkpoint.json b/artifacts/s2-g1-copy-calibration-2026-11-14/public/partial-residual-checkpoint.json new file mode 100644 index 000000000..2da61aede --- /dev/null +++ b/artifacts/s2-g1-copy-calibration-2026-11-14/public/partial-residual-checkpoint.json @@ -0,0 +1,290 @@ +{ + "status": "PARTIAL_RESIDUAL_CHECKPOINT", + "completed_pairs": 10, + "pair_kind_counts": { + "rigid": 6, + "mirror": 2, + "scale": 2 + }, + "thresholds": null, + "threshold_ruling": "1794662380.787319", + "residual_distributions": [ + { + "pair_id": "calib-000", + "kind": "rigid", + "rg_ratio": 1.0, + "routes": { + "physical": { + "branch_residuals": { + "1": 0.0007655151816286167, + "-1": 0.0009000445166876989 + }, + "best_residual": 0.0007655151816286167, + "positive": true, + "size_gate_pass": true + }, + "scale_free": { + "branch_residuals": { + "1": 0.0007655151816283179, + "-1": 0.0009000445166877924 + }, + "best_residual": 0.0007655151816283179, + "positive": true, + "size_gate_pass": true + } + }, + "source_result_sha256": "498a51fdfcb002a5b0942c113e28a7d0d682c0d7b0740b4fdf35e53c341857a3" + }, + { + "pair_id": "calib-003", + "kind": "rigid", + "rg_ratio": 1.0, + "routes": { + "physical": { + "branch_residuals": { + "1": 0.004860985658796247, + "-1": 0.0024434709881316027 + }, + "best_residual": 0.0024434709881316027, + "positive": true, + "size_gate_pass": true + }, + "scale_free": { + "branch_residuals": { + "1": 0.004860985658795578, + "-1": 0.002443470988132329 + }, + "best_residual": 0.002443470988132329, + "positive": true, + "size_gate_pass": true + } + }, + "source_result_sha256": "c073b6a276468754ee27ea597fdca4f88cb6ad49473395adff4f313ff2e4213a" + }, + { + "pair_id": "calib-006", + "kind": "rigid", + "rg_ratio": 1.0, + "routes": { + "physical": { + "branch_residuals": { + "1": 0.0018786009642255224, + "-1": 0.004860096112958939 + }, + "best_residual": 0.0018786009642255224, + "positive": true, + "size_gate_pass": true + }, + "scale_free": { + "branch_residuals": { + "1": 0.00187860096422521, + "-1": 0.00486009611295906 + }, + "best_residual": 0.00187860096422521, + "positive": true, + "size_gate_pass": true + } + }, + "source_result_sha256": "fcfc12023693c5d879ab436be8d062a12ff82aec6a672c56b0d64d70b5a1c738" + }, + { + "pair_id": "calib-007", + "kind": "mirror", + "rg_ratio": 1.0, + "routes": { + "physical": { + "branch_residuals": { + "1": 0.003043202713277692, + "-1": 0.0030384151886850663 + }, + "best_residual": 0.0030384151886850663, + "positive": true, + "size_gate_pass": true + }, + "scale_free": { + "branch_residuals": { + "1": 0.0030432027132775655, + "-1": 0.003038415188685041 + }, + "best_residual": 0.003038415188685041, + "positive": true, + "size_gate_pass": true + } + }, + "source_result_sha256": "d4b3c0236a5bb7e4182aa7f25dcf00808527977a37f52c54d44a3f353f2e5219" + }, + { + "pair_id": "calib-008", + "kind": "scale", + "rg_ratio": 2.0, + "routes": { + "physical": { + "branch_residuals": { + "1": 0.9683416462081893, + "-1": 966.2474928284491 + }, + "best_residual": 0.9683416462081893, + "positive": false, + "size_gate_pass": false + }, + "scale_free": { + "branch_residuals": { + "1": 0.002902163907666195, + "-1": 0.003629575108848093 + }, + "best_residual": 0.002902163907666195, + "positive": true, + "size_gate_pass": true + } + }, + "source_result_sha256": "bf9d62c132733d93ad9d64af0410d47b50afbd2ab6006ce9fec99b90c2d54b9d" + }, + { + "pair_id": "calib-009", + "kind": "rigid", + "rg_ratio": 1.0, + "routes": { + "physical": { + "branch_residuals": { + "1": 0.001686208947509553, + "-1": 0.12843659353064088 + }, + "best_residual": 0.001686208947509553, + "positive": true, + "size_gate_pass": true + }, + "scale_free": { + "branch_residuals": { + "1": 0.001686208947509512, + "-1": 0.1284365935306402 + }, + "best_residual": 0.001686208947509512, + "positive": true, + "size_gate_pass": true + } + }, + "source_result_sha256": "2a6eef2c38e47664f07628664463ee2aa93e6cd2427c88badc01487033c34496" + }, + { + "pair_id": "calib-010", + "kind": "mirror", + "rg_ratio": 1.0, + "routes": { + "physical": { + "branch_residuals": { + "1": 0.1259045104245645, + "-1": 0.0015437310484486084 + }, + "best_residual": 0.0015437310484486084, + "positive": true, + "size_gate_pass": true + }, + "scale_free": { + "branch_residuals": { + "1": 0.12590451042456374, + "-1": 0.0015437310484488122 + }, + "best_residual": 0.0015437310484488122, + "positive": true, + "size_gate_pass": true + } + }, + "source_result_sha256": "c2b88df317b9f040b0a6ce5b06786d8cb3749128c539c2b0fe92f45259cb4a15" + }, + { + "pair_id": "calib-011", + "kind": "scale", + "rg_ratio": 2.0, + "routes": { + "physical": { + "branch_residuals": { + "1": 1.4764714665998997, + "-1": 1.52403929815083 + }, + "best_residual": 1.4764714665998997, + "positive": false, + "size_gate_pass": false + }, + "scale_free": { + "branch_residuals": { + "1": 0.0011272062311777908, + "-1": 0.12570653994342385 + }, + "best_residual": 0.0011272062311777908, + "positive": true, + "size_gate_pass": true + } + }, + "source_result_sha256": "709b8070346a10266472ae2048bce58f9e33857dc67841f3642a301ffebf2122" + }, + { + "pair_id": "calib-012", + "kind": "rigid", + "rg_ratio": 1.0, + "routes": { + "physical": { + "branch_residuals": { + "1": 0.0011100171704919348, + "-1": 0.001403386162929844 + }, + "best_residual": 0.0011100171704919348, + "positive": true, + "size_gate_pass": true + }, + "scale_free": { + "branch_residuals": { + "1": 0.0011100171704916712, + "-1": 0.0014033861629297489 + }, + "best_residual": 0.0011100171704916712, + "positive": true, + "size_gate_pass": true + } + }, + "source_result_sha256": "f24a0ed7e139029d421d5bf5fdb41ba2ba5b8ca5c1ecd4427b20852bd01ff526" + }, + { + "pair_id": "calib-015", + "kind": "rigid", + "rg_ratio": 1.0, + "routes": { + "physical": { + "branch_residuals": { + "1": 0.0017815282578255499, + "-1": 0.00164363252901044 + }, + "best_residual": 0.00164363252901044, + "positive": true, + "size_gate_pass": true + }, + "scale_free": { + "branch_residuals": { + "1": 0.0017815282578257847, + "-1": 0.0016436325290102565 + }, + "best_residual": 0.0016436325290102565, + "positive": true, + "size_gate_pass": true + } + }, + "source_result_sha256": "3ba378635c3617016508ecaaa6ab14bc03ef4a39f2da92e203ee582764b6b391" + } + ], + "physical_scale_negative_controls": [ + { + "pair_id": "calib-008", + "rg_ratio": 2.0, + "physical_size_gate_pass": false + }, + { + "pair_id": "calib-011", + "rg_ratio": 2.0, + "physical_size_gate_pass": false + } + ], + "mirror_branch_flags": [], + "physical_positive_size_gate_failures": [], + "claim": "Engineering calibration on development examples; not independent cross-key recall certification", + "candidate_generation_started": false, + "source_sha256": "062ba0c099f7898b72551edc4d04c3ea4661c201c537a0ffcc7d55a42d79c121" +} diff --git a/artifacts/s2-g1-copy-calibration-2026-11-14/public/postprocessing-contract.json b/artifacts/s2-g1-copy-calibration-2026-11-14/public/postprocessing-contract.json new file mode 100644 index 000000000..66d8d4a81 --- /dev/null +++ b/artifacts/s2-g1-copy-calibration-2026-11-14/public/postprocessing-contract.json @@ -0,0 +1,6 @@ +{ + "source_sha256": "062ba0c099f7898b72551edc4d04c3ea4661c201c537a0ffcc7d55a42d79c121", + "threshold_ruling": "1794662380.787319", + "final_requires": "all 22 jobs PASS, all 62 rows, 42 physical positives, 62 scale-free positives, 20 scaled negatives fail Rg gate", + "partial_checkpoint_freezes_no_threshold": true +} diff --git a/artifacts/s2-g1-copy-calibration-2026-11-14/public/preparation.json b/artifacts/s2-g1-copy-calibration-2026-11-14/public/preparation.json new file mode 100644 index 000000000..7a6bf03b9 --- /dev/null +++ b/artifacts/s2-g1-copy-calibration-2026-11-14/public/preparation.json @@ -0,0 +1,13 @@ +{ + "status": "CALIBRATION_FROZEN_NOT_STARTED", + "pairs": 62, + "synthetic_parts": 20, + "jobs": 22, + "unique_source_parts": 24, + "plan_sha256": "2c9c09e143020345115ee9146546f97686f033b25cdb830dc8f1d166c9283a94", + "contract_sha256": "3fecf5e32757e6946e54e746061f921cb67eb72f4c8011daec8f0ba5c2a8ae03", + "exposure_overlay_sha256": "c32cbbdbec72643ad43c6ea089e02239fca1998b1b3bd2234a0480d3c60c206d", + "threshold_ruling": "1794662380.787319", + "previous_review_not_repeated": true, + "split_stream_consumed": false +} diff --git a/artifacts/s2-g1-copy-calibration-2026-11-14/public/startup-progress-snapshot.json b/artifacts/s2-g1-copy-calibration-2026-11-14/public/startup-progress-snapshot.json new file mode 100644 index 000000000..e12749926 --- /dev/null +++ b/artifacts/s2-g1-copy-calibration-2026-11-14/public/startup-progress-snapshot.json @@ -0,0 +1,17 @@ +{ + "completed_jobs": 4, + "active_jobs": [ + 0, + 1, + 6, + 7 + ], + "next_job": 8, + "completed_worker_cpu_seconds": 423.61940300000003, + "live_tree_cpu_seconds": 451.83, + "active_tree_rss_bytes": 609148928, + "stop_reason": null, + "elapsed_seconds": 219.91591645299923, + "snapshot_utc": "2026-11-14T13:28:26.712114+00:00", + "snapshot_only": true +} diff --git a/artifacts/s2-g1-copy-calibration-2026-11-14/threshold-ruling-source.txt b/artifacts/s2-g1-copy-calibration-2026-11-14/threshold-ruling-source.txt new file mode 100644 index 000000000..2c8a1bb88 --- /dev/null +++ b/artifacts/s2-g1-copy-calibration-2026-11-14/threshold-ruling-source.txt @@ -0,0 +1,30 @@ + (2 total) === + +--- Reply 1 of 2 --- +From: ClaudeWorker (local) (U0C7SSQLBJ7) +Time: 2026-11-14 21:19:16 CST +Message TS: 1794662356.246479 +Accepted; working on: “MeltAstra 正在实际启动下一阶段校准,已确认无既有校准产物/进程,固定 det/2000面积PPS/全三角双向P95 协议不改。常规…” + +--- Reply 2 of 2 --- +From: ClaudeWorker (local) (U0C7SSQLBJ7) +Time: 2026-11-14 21:19:40 CST +Message TS: 1794662380.787319 +*Claude: confirmed, with one correction to the physical route* + +• *Two separate thresholds, as you propose:* τ_phys and τ_sf. Each = 3 × the largest positive-pair residual on its own route, where a pair's residual is min(det+, det−) P95. A pair links if either route, in either branch, is at or below its threshold. +• *Correction: express the physical route without units as well.* Part volumes span about 5 orders of magnitude, so a single τ in raw units would mean entirely different tolerances for small and large parts. So: + • *physical residual = P95 in raw units ÷ the mean of the two parts' R_g*; + • *the physical route also requires an R_g ratio ≤ 1.05.* That keeps it a same-size route. + + The scale-free route stays as it is (each part normalised by its own R_g). +• *Positives per route,* as you set them out: + • physical: rigid copies, mirror copies, and the 2 natural pairs; + • scale-free: all three copy types (rigid, mirror, 2× scale) plus the 2 natural pairs. +• *Negative control:* the 2× scaled copies must fail the physical route because of the R_g-ratio gate. Report that they do. If any passes, stop. +• *Also report:* + • the full residual distribution of positives per route and branch; + • for the mirror copies, which branch fits best. det− should win; if it doesn't, flag it, as a check on the implementation. + +Everything else proceeds as you described under the reproducible contract. + diff --git a/artifacts/s2-g1-copy-calibration-tests-2026-11-14/copy-tests-receipt.json b/artifacts/s2-g1-copy-calibration-tests-2026-11-14/copy-tests-receipt.json new file mode 100644 index 000000000..75d888b1e --- /dev/null +++ b/artifacts/s2-g1-copy-calibration-tests-2026-11-14/copy-tests-receipt.json @@ -0,0 +1,8 @@ +{ + "passed": 3, + "failed": 0, + "test_source": "tools/test_g1_copy_calibration.py", + "reported_test_seconds": 0.033, + "scope": "synthetic transformation invariants, independent PPS streams, improper base rejection", + "no_real_geometry": true +} diff --git a/artifacts/s2-g1-copy-calibration-tests-2026-11-14/runner-test-source.py b/artifacts/s2-g1-copy-calibration-tests-2026-11-14/runner-test-source.py new file mode 100644 index 000000000..96b26c5d4 --- /dev/null +++ b/artifacts/s2-g1-copy-calibration-tests-2026-11-14/runner-test-source.py @@ -0,0 +1,26 @@ +from pathlib import Path +import tempfile,json,subprocess,os,sys,zipfile,numpy as np +repo=Path('/home/frank14f/optane/MeltMind');base=Path(tempfile.mkdtemp(prefix='meltmind-calib-runner-'));records=[] +for fail in [False,True]: + root=base/('failure' if fail else 'success');(root/'custodian').mkdir(parents=True);cache=root/'cache';cache.mkdir();archive=root/'empty.zip' + with zipfile.ZipFile(archive,'w'):pass + st=archive.stat();ver=root/'archive.json';ver.write_text(json.dumps({'bytes':st.st_size,'mtime_ns':st.st_mtime_ns,'inode':st.st_ino})) + jobs=[] + for i in range(2): + case=f'{i+1:08d}_fixture_step_000' + if not fail:np.savez_compressed(cache/(case+'.npz'),points=np.array([[0.,0,0],[3.,0,0],[0,2.,0],[0,0,1.]]),boundary=np.array([[0,1,2],[0,1,3],[0,2,3],[1,2,3]]),center=np.array([.75,.5,.25]),rg=np.array(1.1)) + jobs.append({'cases':[case],'pairs':[{'id':f'p{i}','a':case,'kind':'rigid','rotation':np.eye(3).tolist(),'unit_translation':[1,2,3],'source_sampling_prefix':i+1,'target_sampling_prefix':1000000+i}]}) + (root/'custodian/plan.json').write_text(json.dumps({'jobs':jobs})) + contract={'code_sha256':{},'input_sha256':{},'archive':str(archive),'archive_verification':str(ver),'existing_registration_cache':str(cache),'per_pair_wall_seconds':60,'workers':2,'per_worker_rss_bytes':1342177280,'aggregate_rss_bytes':3*1024**3,'disk_bytes':1024**3,'wall_seconds':90,'worker_cpu_budget_seconds':180} + (root/'contract.json').write_text(json.dumps(contract)) + env=dict(os.environ,MELTMIND_G1_CALIBRATION_ROOT=str(root),OMP_NUM_THREADS='1',OPENBLAS_NUM_THREADS='1',MKL_NUM_THREADS='1',CUDA_VISIBLE_DEVICES='') + p=subprocess.run([sys.executable,'tools/run_g1_copy_calibration.py'],cwd=repo,env=env,capture_output=True,text=True,timeout=110) + output=json.loads((root/('batch-incomplete.json' if fail else 'batch-complete.json')).read_text()) + assert (p.returncode!=0)==fail and len(output['jobs'])==2 + assert output['failed_jobs']==(2 if fail else 0) + assert len(list((root/'jobs').glob('*/worker.receipt.json')))==2 + assert all(j['worker']['returncode'] is not None for j in output['jobs']) + records.append({'case':'intentional_missing_geometry' if fail else 'two_parallel_synthetic_jobs','pass':True,'returncode':p.returncode,'worker_cpu_seconds':output['worker_cpu_seconds'],'failed_jobs':output['failed_jobs'],'wall_seconds':output['wall_seconds']}) + print(records[-1],flush=True) +(repo/'artifacts/s2-g1-copy-calibration-tests-2026-11-14').mkdir(exist_ok=True) +(repo/'artifacts/s2-g1-copy-calibration-tests-2026-11-14/runner-tests.json').write_text(json.dumps({'tests':records,'fixture_root':str(base),'no_real_geometry_read':True},indent=2)+'\n') diff --git a/artifacts/s2-g1-copy-calibration-tests-2026-11-14/runner-tests.json b/artifacts/s2-g1-copy-calibration-tests-2026-11-14/runner-tests.json new file mode 100644 index 000000000..b9d3de7ef --- /dev/null +++ b/artifacts/s2-g1-copy-calibration-tests-2026-11-14/runner-tests.json @@ -0,0 +1,22 @@ +{ + "tests": [ + { + "case": "two_parallel_synthetic_jobs", + "pass": true, + "returncode": 0, + "worker_cpu_seconds": 65.63278199999999, + "failed_jobs": 0, + "wall_seconds": 33.96670820901636 + }, + { + "case": "intentional_missing_geometry", + "pass": true, + "returncode": 1, + "worker_cpu_seconds": 0.751822, + "failed_jobs": 2, + "wall_seconds": 1.0101391290081665 + } + ], + "fixture_root": "/tmp/meltmind-calib-runner-fi2qhnyv", + "no_real_geometry_read": true +} diff --git a/docs/s2-g1-copy-calibration-2026-11-14.md b/docs/s2-g1-copy-calibration-2026-11-14.md new file mode 100644 index 000000000..bcb923bcb --- /dev/null +++ b/docs/s2-g1-copy-calibration-2026-11-14.md @@ -0,0 +1,35 @@ +# G1 合成复制校准:实际运行合同与检查点 + +2026-11-14 21:24:46(Asia/Shanghai)实际启动。4 个 worker、22 个作业,共 62 个配准对:624 件中均匀无放回抽取 20 件,每件各一份刚体、镜像和 2 倍尺度复制,加托管交接后的两对视觉 rigid。共涉及 24 件原几何。首个公开残差检查点已完成 10 对,2 个完整作业 PASS,队列继续运行;这是部分结果,未冻结阈值或生成候选。 + +## 输入与算法 + +新 SeedSequence `[2026111414]` 的 child 0 从字典序 624 件抽样,选出后按件号排序;child 1 生成独立 Haar proper 旋转和平移。三种复制依次为 `x Rᵀ+t`、`x (R diag(-1,1,1))ᵀ+t`、`2x Rᵀ+t`,其中 `t=原 Rg × U[-3,3]^3`。体积中心和 Rg 同步变换,保留原三角面。没有消费原审后 child 1,也没有重开既有盲审、见证或旧提取队列。 + +复用严格只含 points/boundary/center/rg 的已有配准缓存,其余所选几何从 VTU 前缀读取,在场数据关联之前停止。原始文件、封存映射不改写;校准几何和结果写入新目录。24 件的开发暴露新增 overlay,保留原暴露来源。 + +`g1_registration_cost.register` 保持原实现:物理和各自 Rg 归一路,两种 det 分支,固定 PCA/退化起点、≤50 ICP 步、2000 面积 PPS 点对完整三角面双向 P95。原件使用数字前缀随机流;合成目标使用 `100000000+pair_index` 独立流。所有起点、分支、收敛和残差保留,不能把最佳局部解称全局最优证书。 + +## Claude 21:19:40 的阈值裁量 + +[原串 1794662380.787319](https://arcticnimbus.slack.com/archives/C0C78UFKGRM/p1794662380787319) 明确: + +- 物理路残差为原数值单位 P95 除以两件平均 Rg,并另要求 `max(Rg)/min(Rg) ≤ 1.05`;正例为 20 刚体、20 镜像及 2 视觉 rigid 对,共 42 对。 +- 尺度无关路沿用各件自身 Rg 归一后的 P95,三类复制及两自然对共 62 个正例。 +- 每对先取该路 det± 两分支的较小残差;每路阈值独立取正例最大残差的 3 倍。任一路符合相应阈值和门槛即可并组。 +- 20 个 2 倍尺度复制必须因 Rg 比值门槛失败于物理路;任何通过都停止,不进入候选阶段。镜像 det− 未严格胜出则标记并保留,可能涉及对称性或局部解,不静默剔除。 +- 输出每路每分支的全部正例残差;属于工程校准,不认证自然跨键召回。 + +## 资源与检查 + +4 个 worker,仍低于已允许 16。每对 30 分钟墙钟警报;单源三对作业外层总上限 90 分钟,每个 worker 1.25 GiB 进程树 RSS。协调器检查全局 8 小时、20 GiB 磁盘和聚合 RSS、100 CPU-h 上限;监督 CPU 另记且全局检查保守计入。失败保留、不替换、不自动重试;22 作业末尾按失败率检查,任何失败均不能声称完整校准。没有仿真场读取、训练或 GPU。 + +新变换/采样检查 3/3 通过。真实并发执行器在两个合成几何作业上成功收尾;另两个故意缺失几何的作业按预期失败并留回执,未读真实数据。合成执行器测试 worker CPU 为 65.632782 + 0.751822 秒,单独记录,不冒称实际校准消耗。 + +合同 SHA256 `3fecf5e32757e6946e54e746061f921cb67eb72f4c8011daec8f0ba5c2a8ae03`;抽样/变换计划 SHA256 `2c9c09e143020345115ee9146546f97686f033b25cdb830dc8f1d166c9283a94`。 + +## 接续位置 + +产物根目录为 `artifacts/s2-g1-copy-calibration-2026-11-14/`。`batch-started.json` 是启动证据,`progress.json` 为实时状态,`jobs/` 留监督回执,`custodian/results/` 留逐对完整残差,`public/partial-residual-checkpoint.json` 为不含身份的部分结果。 + +不要重新运行准备器或启动第二条队列。检查现有进程和完成标志,运行中的执行文件与合同禁止修改。正常完成会生成 `batch-complete.json`;异常生成 `batch-incomplete.json` 并保留失败。下一检查点是全 62 对完成后运行 `tools/summarize_g1_copy_calibration.py`,检查负控和分支异常、冻结两个阈值,再接双路各 k=3、min-rank 去重的候选计数和既定预算配准。`--partial` 仅报告已有残差,永不冻结阈值。公开快照标有时间,不代表持续更新的实时结果。 diff --git a/tools/g1_copy_calibration.py b/tools/g1_copy_calibration.py new file mode 100644 index 000000000..450b8d4b1 --- /dev/null +++ b/tools/g1_copy_calibration.py @@ -0,0 +1,101 @@ +"""Fixed-protocol geometric calibration; no simulation-field reads.""" +from pathlib import Path +from zipfile import ZipFile +import argparse +import hashlib +import json +import os +import resource +import signal +import time +import numpy as np +from g1_registration_cost import geometry_only, register +from s2_e1_supervisor import save + +ROOT = Path(os.environ.get('MELTMIND_G1_CALIBRATION_ROOT', 'artifacts/s2-g1-copy-calibration-2026-11-14')) + +def transformed(g, kind, rotation, translation): + r = np.asarray(rotation, dtype=float) + t = np.asarray(translation, dtype=float) + if kind not in ('rigid', 'mirror', 'scale'): + raise ValueError('Unknown synthetic relation') + if not np.allclose(r.T @ r, np.eye(3), atol=1e-12, rtol=0) or abs(np.linalg.det(r)-1) > 1e-12: + raise ValueError('Base rotation must be proper') + a = r @ (np.diag([-1., 1., 1.]) if kind == 'mirror' else np.eye(3)) + scale = 2. if kind == 'scale' else 1. + # Translation is expressed in multiples of the original volume Rg. + shift = t * float(g['rg']) + return {'points': scale * g['points'] @ a.T + shift, + 'boundary': g['boundary'].copy(), + 'center': scale * g['center'] @ a.T + shift, + 'rg': np.asarray(scale * float(g['rg']))} + +def check_contract(root): + c = json.loads((root/'contract.json').read_text()) + for path, digest in c['code_sha256'].items(): + if hashlib.sha256(Path(path).read_bytes()).hexdigest() != digest: + raise ValueError('Source changed after calibration freeze: '+path) + for path, digest in c['input_sha256'].items(): + if hashlib.sha256(Path(path).read_bytes()).hexdigest() != digest: + raise ValueError('Calibration input changed: '+path) + return c + +def load_geometry(case, contract, jobroot): + cache = Path(contract['existing_registration_cache'])/(case+'.npz') + if cache.exists(): + with np.load(cache, allow_pickle=False) as z: + if set(z.files) != {'points','boundary','center','rg'}: + raise ValueError('Registration cache is not strictly geometry-only') + g = {k: z[k].copy() for k in z.files} + mode = 'existing_geometry_only_registration_cache' + else: + with ZipFile(contract['archive']) as z, z.open(case+'_sim.vtu') as stream: + g = geometry_only(stream) + mode = 'VTU_geometry_prefix_stop_before_field_associations' + if not all(np.isfinite(v).all() for v in g.values()) or float(g['rg']) <= 0: + raise ValueError('Nonfinite geometry or invalid Rg') + dest = jobroot/(case+'.npz') + if dest.exists(): + raise FileExistsError('Never overwrite calibration geometry') + np.savez_compressed(dest, **g) + return g, mode + +def expired(*_): + raise TimeoutError('Per-pair 1800 second wall-clock limit') + +def main(): + ap = argparse.ArgumentParser();ap.add_argument('index', type=int);args = ap.parse_args() + c = check_contract(ROOT) + verification = json.loads(Path(c['archive_verification']).read_text()) + stat = Path(c['archive']).stat() + if (stat.st_size,stat.st_mtime_ns,stat.st_ino) != (verification['bytes'],verification['mtime_ns'],verification['inode']): + raise ValueError('Archive identity changed') + plan = json.loads((ROOT/'custodian/plan.json').read_text()) + job = plan['jobs'][args.index] + work = ROOT/'custodian/results'/f'job-{args.index:02d}' + work.mkdir(parents=True, exist_ok=False) + start = time.monotonic();geometry = {};modes = {} + for case in sorted(set(job['cases'])): + geometry[case], modes[case] = load_geometry(case, c, work) + signal.signal(signal.SIGALRM, expired) + for pair in job['pairs']: + a = geometry[pair['a']] + b = geometry[pair['b']] if pair['kind']=='natural_visual_rigid' else transformed(a, pair['kind'], pair['rotation'], pair['unit_translation']) + begin = time.monotonic();signal.setitimer(signal.ITIMER_REAL, c['per_pair_wall_seconds']) + try: + routes = register(a, b, pair['source_sampling_prefix'], pair['target_sampling_prefix']) + finally: + signal.setitimer(signal.ITIMER_REAL, 0) + if not all(np.isfinite(r['residual_max_two_way_area_pps_p95']) for r in routes): + raise ValueError('Nonfinite registration residual') + rga, rgb = float(a['rg']), float(b['rg']) + save(work/(pair['id']+'.json'), {'pair':pair, 'routes':routes, 'wall_seconds':time.monotonic()-begin, + 'source_rg':rga, 'target_rg':rgb, 'mean_rg':(rga+rgb)/2, 'rg_ratio':max(rga,rgb)/min(rga,rgb), + 'simulation_labels_read':False, 'model_training':False, + 'residual_definition':'Unchanged two-way area-PPS 2000 samples to full triangles P95, best start in each det branch'}) + print(json.dumps({'pair_id':pair['id'],'kind':pair['kind'],'status':'RESIDUALS_COMPLETE'}),flush=True) + save(work/'complete.json', {'index':args.index,'pairs':len(job['pairs']),'source_modes':modes, + 'cpu_seconds':sum(resource.getrusage(resource.RUSAGE_SELF)[:2]),'wall_seconds':time.monotonic()-start, + 'max_rss_bytes':resource.getrusage(resource.RUSAGE_SELF).ru_maxrss*1024,'all_pass':True}) + +if __name__=='__main__':main() diff --git a/tools/prepare_g1_copy_calibration.py b/tools/prepare_g1_copy_calibration.py new file mode 100644 index 000000000..107420c94 --- /dev/null +++ b/tools/prepare_g1_copy_calibration.py @@ -0,0 +1,75 @@ +"""Freeze a new, reproducible calibration sample without consuming split RNGs.""" +from pathlib import Path +import hashlib +import json +import numpy as np +from scipy.spatial.transform import Rotation + +ROOT=Path('artifacts/s2-g1-copy-calibration-2026-11-14') +def save(path,value): + path.write_text(json.dumps(value,indent=2,ensure_ascii=False)+'\n') +def sha(path):return hashlib.sha256(Path(path).read_bytes()).hexdigest() +def main(): + ROOT.mkdir(exist_ok=False);private=ROOT/'custodian';private.mkdir(mode=0o700);(ROOT/'public').mkdir() + inventory=Path('artifacts/s2-g1-inventory-2026-11-14/custodian/parts.json') + rigid_path=Path('artifacts/s2-g1-custody-handoff-2026-11-14/custodian/rigid-calibration-inputs.json') + parts=json.loads(inventory.read_text());frame=sorted(p['case'] for p in parts) + assert len(frame)==len(set(frame))==624 + children=np.random.SeedSequence([2026111414]).spawn(2) + sample=np.random.Generator(np.random.PCG64(children[0]));poses=np.random.Generator(np.random.PCG64(children[1])) + selected=sorted(sample.choice(frame,20,replace=False).tolist());jobs=[];pair_index=0 + for case in selected: + pairs=[] + for kind in ['rigid','mirror','scale']: + pairs.append({'id':f'calib-{pair_index:03d}','a':case,'kind':kind, + 'rotation':Rotation.random(random_state=poses).as_matrix().tolist(), + 'unit_translation':poses.uniform(-3,3,3).tolist(), + 'source_sampling_prefix':int(case.split('_')[0]), + 'target_sampling_prefix':100000000+pair_index}) + pair_index+=1 + jobs.append({'cases':[case],'pairs':pairs}) + rigid=json.loads(rigid_path.read_text())['pairs'];assert len(rigid)==2 + for r in rigid: + pa,pb=int(r['a'].split('_')[0]),int(r['b'].split('_')[0]);assert pa!=pb + jobs.append({'cases':[r['a'],r['b']],'pairs':[{'id':f'calib-{pair_index:03d}', + 'a':r['a'],'b':r['b'],'kind':'natural_visual_rigid','anonymous_pair_id':r['anonymous_pair_id'], + 'source_sampling_prefix':pa,'target_sampling_prefix':pb}]});pair_index+=1 + assert pair_index==62 + save(private/'plan.json',{'seed_sequence':[2026111414],'sample_spawn_key':[0],'transform_spawn_key':[1], + 'sampling':'uniform 20 without replacement over 624 lexicographically sorted cases; resulting cases sorted', + 'selected_cases':selected,'jobs':jobs,'review_split_rng_consumed':False}) + used={case for j in jobs for case in j['cases']} + save(private/'exposure-overlay.json',{'reason':'G1 calibration development exposure; does not rewrite sealed inventory', + 'parts':[{'case':p['case'],'source_key':p['source_key'],'prior_exposure':p['exposure_state'], + 'calibration_development_exposed':True} for p in parts if p['case'] in used]}) + for p in private.iterdir():p.chmod(0o600) + code=['prepare_g1_copy_calibration','g1_copy_calibration','run_g1_copy_calibration','g1_registration_cost','s2_e1_supervisor','audit_samples','boundary_distance'] + contract={'authorizing_rulings':['1794661944.308269','1794662380.787319'], + 'code_sha256':{f'tools/{p}.py':sha(f'tools/{p}.py') for p in code}, + 'input_sha256':{str(p):sha(p) for p in [private/'plan.json',inventory,rigid_path]}, + 'archive':'data.zip','archive_verification':'artifacts/intake-2026-11-13/archive_verification.json', + 'existing_registration_cache':'artifacts/s2-e1-2026-11-14/cost-geometry', + 'sample_seed':[2026111414],'synthetic_parts':20,'synthetic_pairs':60,'natural_visual_rigid_pairs':2, + 'synthetic_transform':'independent Haar proper R; mirror R diag(-1,1,1); scale 2; t=Rg*U[-3,3]^3; original face indices retained', + 'sampling':'unchanged area-PPS 2000; source numeric prefix, unique synthetic target prefix 100000000+pair_index; natural original numeric prefixes', + 'registration':'unchanged g1_registration_cost.register, both routes, det +/- starts, full-triangle two-way P95; no remeshing', + 'threshold_policy':{'physical_residual':'raw P95 / mean(Rg_a,Rg_b)','physical_size_gate':'max(Rg_a,Rg_b)/min(Rg_a,Rg_b) <= 1.05', + 'scale_free_residual':'unchanged individual Rg-normalized P95', + 'positive_kinds_physical':['rigid','mirror','natural_visual_rigid'],'positive_kinds_scale_free':['rigid','mirror','scale','natural_visual_rigid'], + 'per_pair_residual':'min of det+ and det- branch best P95 within route','threshold':'3 * largest positive-pair residual on each route', + 'link':'either route meets own threshold; physical also requires Rg ratio gate', + 'negative_control':'all 20 scale copies must fail physical size gate; any pass stops', + 'mirror_check':'flag a mirror copy when det- does not strictly win; do not silently discard symmetric cases'}, + 'workers':4,'per_pair_wall_seconds':1800,'per_worker_rss_bytes':1342177280, + 'aggregate_rss_bytes':20*1024**3,'worker_cpu_budget_seconds':100*3600,'wall_seconds':8*3600,'disk_bytes':20*1024**3, + 'scope':'only calibration; formal candidate generation and registration queue follow calibration checkpoint', + 'failed_jobs':'retained; no retry/replacement; final checkpoint after 22 jobs; any failure leaves calibration incomplete', + 'no_simulation_fields_no_training_no_gpu':True} + save(ROOT/'contract.json',contract) + save(ROOT/'public/preparation.json',{'status':'CALIBRATION_FROZEN_NOT_STARTED','pairs':62,'synthetic_parts':20,'jobs':22, + 'unique_source_parts':len(used),'plan_sha256':sha(private/'plan.json'), + 'contract_sha256':sha(ROOT/'contract.json'),'exposure_overlay_sha256':sha(private/'exposure-overlay.json'), + 'threshold_ruling':'1794662380.787319','previous_review_not_repeated':True,'split_stream_consumed':False}) + print((ROOT/'public/preparation.json').read_text()) + +if __name__=='__main__':main() diff --git a/tools/run_g1_copy_calibration.py b/tools/run_g1_copy_calibration.py new file mode 100644 index 000000000..8eb61ca67 --- /dev/null +++ b/tools/run_g1_copy_calibration.py @@ -0,0 +1,100 @@ +"""Four guarded calibration workers; all CPU/failures retained, no retries.""" +from pathlib import Path +import argparse +import fcntl +import json +import os +import resource +import signal +import subprocess +import sys +import time +import psutil +from g1_copy_calibration import ROOT, check_contract +from s2_e1_supervisor import supervise, save, disk_usage, stop_group + +def guard(index): + c=check_contract(ROOT);plan=json.loads((ROOT/'custodian/plan.json').read_text());n=len(plan['jobs'][index]['pairs']) + job=ROOT/'jobs'/f'job-{index:02d}';job.mkdir(parents=True,exist_ok=True) + limit=n*c['per_pair_wall_seconds'] + r=supervise([sys.executable,'tools/g1_copy_calibration.py',str(index)],job,'worker', + dict(total_cpu_seconds=limit+1,job_cpu_seconds=limit,job_wall_seconds=limit, + tree_rss_bytes=c['per_worker_rss_bytes'],disk_bytes=c['disk_bytes'],max_processes=2),poll=.25) + save(job/'guard-result.json',{'worker':r,'supervisor_cpu_seconds':sum(resource.getrusage(resource.RUSAGE_SELF)[:2])}) + return 0 if r['status']=='PASS' else 1 + +def terminate_workers(active): + # Guards stay alive to reap killed workers and write failure receipts. + for p,_ in active.values(): + try: + for child in psutil.Process(p.pid).children():stop_group(child.pid) + except psutil.NoSuchProcess:pass + +def run(): + c=check_contract(ROOT);plan=json.loads((ROOT/'custodian/plan.json').read_text()) + lock=(ROOT/'batch.lock').open('a');fcntl.flock(lock,fcntl.LOCK_EX|fcntl.LOCK_NB) + if (ROOT/'batch-started.json').exists():raise FileExistsError('Batch already attempted; no automatic restart') + env=dict(os.environ,OMP_NUM_THREADS='1',OPENBLAS_NUM_THREADS='1',MKL_NUM_THREADS='1',NUMEXPR_NUM_THREADS='1',CUDA_VISIBLE_DEVICES='') + save(ROOT/'batch-started.json',{'pid':os.getpid(),'started_unix':time.time(),'jobs':len(plan['jobs']),'pairs':sum(len(j['pairs']) for j in plan['jobs']),'workers':c['workers'],'contract_sha256':__import__('hashlib').sha256((ROOT/'contract.json').read_bytes()).hexdigest()}) + started=time.monotonic();active={};done=[];next_index=0;reason=None;peak_rss=0 + def interrupted(*_): + nonlocal reason + reason='coordinator_interrupted' + signal.signal(signal.SIGTERM,interrupted);signal.signal(signal.SIGINT,interrupted) + try: + while active or (next_index=c['wall_seconds']:reason='global_wall_limit' + if disk_usage(ROOT)>=c['disk_bytes']:reason='global_disk_limit' + live_cpu=live_rss=0 + for p,_ in active.values(): + try: + for q in [psutil.Process(p.pid)]+psutil.Process(p.pid).children(recursive=True): + try: + t=q.cpu_times();live_cpu+=t.user+t.system+t.children_user+t.children_system;live_rss+=q.memory_info().rss + except psutil.NoSuchProcess:pass + except psutil.NoSuchProcess:pass + peak_rss=max(peak_rss,live_rss) + completed_cpu=sum(r['worker']['cpu_seconds']+r['supervisor_cpu_seconds'] for r in done) + if completed_cpu+live_cpu>=c['worker_cpu_budget_seconds']:reason='global_cpu_limit' + if live_rss>=c['aggregate_rss_bytes']:reason='aggregate_rss_limit' + if reason:terminate_workers(active) + save(ROOT/'progress.json',{'completed_jobs':len(done),'active_jobs':list(active),'next_job':next_index, + 'completed_worker_cpu_seconds':sum(r['worker']['cpu_seconds'] for r in done), + 'live_tree_cpu_seconds':live_cpu,'active_tree_rss_bytes':live_rss,'stop_reason':reason,'elapsed_seconds':time.monotonic()-started}) + if active:time.sleep(.5) + finally: + terminate_workers(active) + for p,log in active.values(): + try:p.wait(timeout=10) + except subprocess.TimeoutExpired:stop_group(p.pid);p.wait() + log.close() + failures=sum(r['worker']['status']!='PASS' for r in done) + passed=reason is None and len(done)==len(plan['jobs']) and failures==0 + summary={'status':'CALIBRATION_RESIDUALS_COMPLETE' if passed else 'CALIBRATION_INCOMPLETE', + 'jobs':done,'failed_jobs':failures,'failure_rate_at_final_checkpoint':failures/len(done) if done else None, + 'stop_reason':reason,'worker_cpu_seconds':sum(r['worker']['cpu_seconds'] for r in done), + 'guard_cpu_seconds':sum(r['supervisor_cpu_seconds'] for r in done), + 'coordinator_cpu_seconds':sum(resource.getrusage(resource.RUSAGE_SELF)[:2]), + 'wall_seconds':time.monotonic()-started,'peak_aggregate_tree_rss_bytes':peak_rss, + 'disk_bytes':disk_usage(ROOT),'thresholds_frozen':False,'candidate_generation':False,'no_retries':True} + save(ROOT/'batch-complete.json' if passed else ROOT/'batch-incomplete.json',summary) + print(json.dumps({k:v for k,v in summary.items() if k!='jobs'}),flush=True) + return 0 if passed else 1 + +if __name__=='__main__': + ap=argparse.ArgumentParser();ap.add_argument('--guard',type=int);a=ap.parse_args() + sys.exit(guard(a.guard) if a.guard is not None else run()) diff --git a/tools/summarize_g1_copy_calibration.py b/tools/summarize_g1_copy_calibration.py new file mode 100644 index 000000000..4695c70c4 --- /dev/null +++ b/tools/summarize_g1_copy_calibration.py @@ -0,0 +1,55 @@ +"""Report fixed-route calibration residuals; freeze thresholds only after all jobs pass.""" +from pathlib import Path +from collections import Counter +import argparse +import hashlib +import json +import math +from g1_copy_calibration import ROOT, check_contract +from s2_e1_supervisor import save + +def main(): + ap=argparse.ArgumentParser();ap.add_argument('--partial',action='store_true');args=ap.parse_args() + check_contract(ROOT) + if not args.partial: + batch=json.loads((ROOT/'batch-complete.json').read_text()) + assert batch['status']=='CALIBRATION_RESIDUALS_COMPLETE' and batch['failed_jobs']==0 + rows=[];mirror_flags=[];negative_controls=[] + for path in sorted((ROOT/'custodian/results').glob('job-*/calib-*.json')): + r=json.loads(path.read_text());pair=r['pair'];kind=pair['kind'];out={} + assert r['mean_rg']>0 and r['rg_ratio']>=1 + for route in ['physical','scale_free']: + branches={str(v['parity']):v['residual_max_two_way_area_pps_p95']/(r['mean_rg'] if route=='physical' else 1.) for v in r['routes'] if v['route']==route} + assert set(branches)=={'1','-1'} and all(math.isfinite(v) and v>=0 for v in branches.values()) + positive=route=='scale_free' or kind!='scale' + out[route]={'branch_residuals':branches,'best_residual':min(branches.values()),'positive':positive, + 'size_gate_pass':r['rg_ratio']<=1.05 if route=='physical' else True} + if kind=='mirror' and branches['-1']>=branches['1']: + mirror_flags.append({'pair_id':pair['id'],'route':route,'det_minus':branches['-1'],'det_plus':branches['1'], + 'note':'det- did not strictly win; retain result, including possible symmetry/local optimum'}) + if kind=='scale': + negative_controls.append({'pair_id':pair['id'],'rg_ratio':r['rg_ratio'],'physical_size_gate_pass':out['physical']['size_gate_pass']}) + rows.append({'pair_id':pair['id'],'kind':kind,'rg_ratio':r['rg_ratio'],'routes':out, + 'source_result_sha256':hashlib.sha256(path.read_bytes()).hexdigest()}) + if any(r['physical_size_gate_pass'] for r in negative_controls): + save(ROOT/'public/negative-control-stop.json',{'status':'STOP','controls':negative_controls}) + raise ValueError('A scaled negative control passed the physical size gate; do not generate candidates') + thresholds=None + if not args.partial: + assert len(rows)==62 and Counter(r['kind'] for r in rows)=={'rigid':20,'mirror':20,'scale':20,'natural_visual_rigid':2} + thresholds={route:3*max(r['routes'][route]['best_residual'] for r in rows if r['routes'][route]['positive']) for route in ['physical','scale_free']} + assert sum(r['routes']['physical']['positive'] for r in rows)==42 + assert len(negative_controls)==20 + result={'status':'PARTIAL_RESIDUAL_CHECKPOINT' if args.partial else 'CALIBRATION_THRESHOLDS_FROZEN', + 'completed_pairs':len(rows),'pair_kind_counts':dict(Counter(r['kind'] for r in rows)), + 'thresholds':thresholds,'threshold_ruling':'1794662380.787319','residual_distributions':rows, + 'physical_scale_negative_controls':negative_controls,'mirror_branch_flags':mirror_flags, + 'physical_positive_size_gate_failures':[r['pair_id'] for r in rows if r['routes']['physical']['positive'] and not r['routes']['physical']['size_gate_pass']], + 'claim':'Engineering calibration on development examples; not independent cross-key recall certification', + 'candidate_generation_started':False,'source_sha256':hashlib.sha256(Path(__file__).read_bytes()).hexdigest()} + dest=ROOT/'public'/('partial-residual-checkpoint.json' if args.partial else 'calibration-thresholds.json') + if dest.exists() and not args.partial:raise FileExistsError('Frozen thresholds already exist') + save(dest,result) + print(json.dumps({k:v for k,v in result.items() if k not in ['residual_distributions','physical_scale_negative_controls']},indent=2)) + +if __name__=='__main__':main() diff --git a/tools/test_g1_copy_calibration.py b/tools/test_g1_copy_calibration.py new file mode 100644 index 000000000..6ef26396d --- /dev/null +++ b/tools/test_g1_copy_calibration.py @@ -0,0 +1,27 @@ +import unittest +import numpy as np +from scipy.spatial.transform import Rotation +from g1_copy_calibration import transformed +from g1_registration_cost import sample_surface + +class CopyChecks(unittest.TestCase): + def setUp(self): + self.g={'points':np.array([[0.,0,0],[3.,0,0],[0,2.,0],[0,0,1.]]), + 'boundary':np.array([[0,1,2],[0,1,3],[0,2,3],[1,2,3]]), + 'center':np.array([.75,.5,.25]),'rg':np.array(1.1)} + def test_lengths_rg_centroid_and_signed_volume(self): + r=Rotation.from_rotvec([.31,-.72,.2]).as_matrix();x=self.g['points'].copy() + for kind,s,parity in [('rigid',1,1),('mirror',1,-1),('scale',2,1)]: + out=transformed(self.g,kind,r,[2,-3,1]);y=out['points'] + np.testing.assert_allclose(np.linalg.norm(y[:,None]-y[None,:],axis=2),s*np.linalg.norm(x[:,None]-x[None,:],axis=2),atol=1e-13) + self.assertAlmostEqual(float(out['rg']),s*float(self.g['rg'])) + np.testing.assert_allclose(out['center'],y.mean(0),atol=1e-13) + self.assertAlmostEqual(np.linalg.det(y[1:]-y[0])/np.linalg.det(x[1:]-x[0]),parity*s**3) + np.testing.assert_array_equal(self.g['points'],x) + def test_sampling_streams_independent_and_reproducible(self): + x,_=sample_surface(self.g,42);y,_=sample_surface(self.g,100000000) + np.testing.assert_array_equal(x,sample_surface(self.g,42)[0]);self.assertFalse(np.array_equal(x,y)) + def test_improper_base_rotation_rejected(self): + with self.assertRaises(ValueError):transformed(self.g,'rigid',np.diag([-1,1,1]),[0,0,0]) + +if __name__=='__main__':unittest.main(verbosity=2)