B11 approved persistence reconstruction gate and synthetic acceptance

This commit is contained in:
Frank14f committed 2026-11-17 13:12:03 +08:00
1 parent 265fa06518
commit 5b676d4c31
23 files changed
+7179

No files matched your search

@@ -0,0 +1,18 @@
{
"status": "PASS",
"unique_tests": 9,
"test_executions": 12,
"cpu_seconds": 1.5624479999999998,
"receipts": [
"attempt-01/worker.receipt.json",
"attempt-02/worker.receipt.json",
"actual-guard-integration/worker.receipt.json"
],
"code_sha256": {
"tools/phase2_b11_math.py": "923822aeeabd8023c1ba9850f681545f5e6ac0a27cb949dbf6c217ab0d30b1fc",
"tools/phase2_b11_gate.py": "90faab3e4c2ab04df92562ebf92f5eda8696feb0e9c50ee5f5a966c0aa20526c",
"tools/test_phase2_b11.py": "fe304722336f1cdd11d2eee7f28cd31ef140f2aff274858886df3a544532b7f1",
"tools/test_phase2_b11_integration.py": "d2840fe51349920a78c737e64290e5b53635294a4ca2b35763d13dfb14a88913"
},
"last_source_annotation": "after tests only added two CPU timing fields; arithmetic and decisions unchanged"
}
@@ -0,0 +1,5 @@
{
"pid": 4,
"unix": 1794892240.1899996,
"guard_pid": 3
}
@@ -0,0 +1,8 @@
test_eik_build_never_requires_target_files (__main__.IntegrationTests) ... ok
test_out_of_fold_selection_rejects_learning_substitution (__main__.IntegrationTests) ... ok
test_scoring_requires_parent_git_freeze_authorization (__main__.IntegrationTests) ... ok
----------------------------------------------------------------------
Ran 3 tests in 0.040s
OK
@@ -0,0 +1,20 @@
{
"status": "PASS",
"returncode": 0,
"stop_reason": null,
"cpu_seconds": 0.5543319999999999,
"wall_seconds": 0.6049850209965371,
"peak_tree_rss_bytes": 77361152,
"peak_process_count": 1,
"monitor_errors": [],
"max_poll_gap_seconds": 0.2012726310058497,
"reaped_orphan_cpu_seconds": 0.0,
"limits": {
"cpu_seconds": 60,
"wall_seconds": 60,
"rss_bytes": 1073741824,
"disk_bytes": 104857600
},
"retry": false,
"gpu_visible": false
}
@@ -0,0 +1,14 @@
{
"command": [
"/home/frank14f/optane/MeltMind/artifacts/gre24-reproduction-2026-11-15/environment/venv/bin/python",
"tools/test_phase2_b11_integration.py",
"-v"
],
"limits": {
"cpu_seconds": 60,
"wall_seconds": 60,
"rss_bytes": 1073741824,
"disk_bytes": 104857600
},
"unix": 1794892240.188538
}
Whitespace-only changes.
@@ -0,0 +1,10 @@
{
"cpu_seconds_charged": 0.44036299999999995,
"attempts": [
{
"name": "worker",
"status": "PASS",
"cpu_seconds": 0.44036299999999995
}
]
}
@@ -0,0 +1,11 @@
test_compound_all_dying_bars_match_b3 (__main__.B11Tests) ... ok
test_disconnected_components_keep_infinite (__main__.B11Tests) ... ok
test_exact_threshold_kept_and_raw_id_elder (__main__.B11Tests) ... ok
test_gate_empty_and_incomplete_cannot_pass (__main__.B11Tests) ... ok
test_required_chain (__main__.B11Tests) ... ok
test_single_plateau_identity (__main__.B11Tests) ... ok
----------------------------------------------------------------------
Ran 6 tests in 0.035s
OK
@@ -0,0 +1,23 @@
{
"status": "PASS",
"command": [
"/home/frank14f/optane/MeltMind/artifacts/gre24-reproduction-2026-11-15/environment/venv/bin/python",
"tools/test_phase2_b11.py",
"-v"
],
"returncode": 0,
"stop_reason": null,
"cpu_seconds": 0.44036299999999995,
"wall_seconds": 0.45562026399420574,
"peak_tree_rss_bytes": 73056256,
"peak_process_count": 2,
"output_disk_bytes_before_receipt": 8192,
"max_poll_gap_seconds": 0.0209066349780187,
"poll_target_seconds": 0.02,
"reaped_orphan_cpu_seconds": 0.0,
"supervision": "sampled process-tree monitoring; wait4 final CPU/HWM; overshoot retained as failure",
"gpu_visible": false,
"retry": false,
"monitor_errors": 0,
"last_monitor_error": null
}
@@ -0,0 +1,16 @@
{
"command": [
"/home/frank14f/optane/MeltMind/artifacts/gre24-reproduction-2026-11-15/environment/venv/bin/python",
"tools/test_phase2_b11.py",
"-v"
],
"limits": {
"job_wall_seconds": 60,
"job_cpu_seconds": 60,
"total_cpu_seconds": 60,
"tree_rss_bytes": 1073741824,
"max_processes": 4,
"disk_bytes": 104857600
},
"started_unix": 1794892013.5100167
}
Whitespace-only changes.
@@ -0,0 +1,10 @@
{
"cpu_seconds_charged": 0.567753,
"attempts": [
{
"name": "worker",
"status": "PASS",
"cpu_seconds": 0.567753
}
]
}
@@ -0,0 +1,8 @@
test_eik_build_never_requires_target_files (__main__.IntegrationTests) ... ok
test_out_of_fold_selection_rejects_learning_substitution (__main__.IntegrationTests) ... ok
test_scoring_requires_parent_git_freeze_authorization (__main__.IntegrationTests) ... ok
----------------------------------------------------------------------
Ran 3 tests in 0.041s
OK
@@ -0,0 +1,23 @@
{
"status": "PASS",
"command": [
"/home/frank14f/optane/MeltMind/artifacts/gre24-reproduction-2026-11-15/environment/venv/bin/python",
"tools/test_phase2_b11_integration.py",
"-v"
],
"returncode": 0,
"stop_reason": null,
"cpu_seconds": 0.567753,
"wall_seconds": 0.581146955024451,
"peak_tree_rss_bytes": 80019456,
"peak_process_count": 2,
"output_disk_bytes_before_receipt": 8192,
"max_poll_gap_seconds": 0.021126472973264754,
"poll_target_seconds": 0.02,
"reaped_orphan_cpu_seconds": 0.0,
"supervision": "sampled process-tree monitoring; wait4 final CPU/HWM; overshoot retained as failure",
"gpu_visible": false,
"retry": false,
"monitor_errors": 0,
"last_monitor_error": null
}
@@ -0,0 +1,16 @@
{
"command": [
"/home/frank14f/optane/MeltMind/artifacts/gre24-reproduction-2026-11-15/environment/venv/bin/python",
"tools/test_phase2_b11_integration.py",
"-v"
],
"limits": {
"job_wall_seconds": 60,
"job_cpu_seconds": 60,
"total_cpu_seconds": 60,
"tree_rss_bytes": 1073741824,
"max_processes": 4,
"disk_bytes": 104857600
},
"started_unix": 1794892194.783706
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,15 @@
# B11 已批准执行合同
Claude1794891811.393839已明确批准Mold全文364446c724c434eea18ca646e1efa352bb9614249b8d6ac00340df4e83a45471及四项门,无需再索取go。完整原文字节保存在`references/2026-11-17/phase2-design/mold-b11-spec-364446c7.md`。当前B5已终态;B1原队列继续,不改其pins/参数/冻结。
唯一新根`artifacts/phase2-b11-gate-2026-11-17`,CPU22,整个EIK→A/H1链共享7200 CPU秒,包括worker、协调/守卫、Git子进程与60秒setup预留。合成1.562448 CPU秒在该setup内一次计入;每phase最多1800 CPU/墙钟秒、8GiB RSS,整根5GiB输出,0重试/拟合/新解码/GPU。累计帽不足则减phase余量或停止。A/H1依赖等待最多6小时墙钟,等待CPU同账;未到冻结或原B1停止则只留EIK及缺失原因。不会启动第二个B1或推理队列。
精确同值整层和B3 elder复合合并规则提取完整出生平台及全部有限/无限条,有限寿命≥.020(恰等保留)及所有无限条为标记;原tet图多源最大瓶颈重建。保存每个条的全部节点/ID、生死/寿命、保留标记、原/新场、全域最高平台/查询末点、变动体积及提取/重建成本。只降不升且标记平台原值不变,每个物理分量有无限类;不假定既有FP均为短峰。
EIK先行:复用B3冻结50不同学习组件、原图/质量/Rg/真事件及冻结Vf*t_set。对原EIK复用B3已固定的事件/匹配结果,避免重算原B3;清理场重新计算完整严格体积分位及事件,评分持续度.010、距.10Rg、阶段差.05不变。raw/clean预测完整manifest及评分代码先Git冻结,协调器核Git字节后发一次评分许可,再读该面板已有真场。worker不启动子进程。
A/H1由同一协调器等B1原`scoring-git-freeze.json`及全部预测终态账齐全,核原Git/文件哈希后,仅取该50件各自test折、grouped100%、原ID严格一致的共同A/H1全节点预测;不会混入学习拟合值或另行模型推理。缺失/重复/域不符保留原原因,两臂缺共同域均不可过门。面板已基于学习证据选择,外折预测不把本门变成新盲测。
原R4bc query ID、multiplicity、near-wall、坐标/Rg、并列最小rawID末点及原固定5000抽样对tau-b保持;报告原/新相对L2、末点、tau-b、并列对比例、缺失和未定义分母。50件一件一组件,组件均值即面板均值。四门逐臂全部满足才RETAIN_FOR_INDEPENDENT_PANEL:微平均precision绝对增≥.010、recall损失≤.020、末点距离/Rg均值增≤.010、tau-b均值损失≤.010。缺50完整共同域或任何成对末点/tau分母不可判,则PARK,不删件换分母;事件全空亦不可过门。完整分母下不过,只剪该固定规则在该臂的用途。
新增数学6项与集成3项PASS;实际单进程guard又执行集成3项PASS,以验证短测试中旧守卫采样曾见2进程不会直接误用为新guard验收。合计12次、9个独立测试,所有原回执保留。最后只补提取/重建分账计时输出,不变算子/判据;记录该小差异,不声称新增独立科学验证。本合同及代码冻结不等于实际运行,实际状态由started/phase ledger/终态证明。
@@ -0,0 +1,25 @@
# B11 · 用持久极大平台重建预测到达场
MoldAstra,2026-11-17,供 Claude 裁量、MeltAstra 在 B5 小门之后执行。此稿只定义一次无训练后处理。B3 的 50 个学习组件各取一件,真场含 660 个合并事件。记录精度的两种扰动下 precision/recall 分别为 0.954/0.921 和 0.947/0.915。EIK 的 TP/FP/FN 为 244/16,956/416。FP 表示按固定口径没有配到参考事件,其寿命长短及物理成因尚未查明。B4 的 0.09158 对 A 的 0.06645 只排除了该面板上给固定 Df 单独换单调时钟就能超过 A 的假设。[固定报告与证据](https://gitea.frank14f.online/Frank14f/MeltMind/src/commit/a6998f72a92f1044e3b03ea183b3a2df34d18fd2/docs/phase2-b3-b4-results-2026-11-17.md)
## 改什么
输入只用每件冻结的预测到达场 S、原 retained-tet 边图 G、节点体积 m 和原 ID;S 用与评分一致的时间单位。对 **原预测** 复用 B3 的干区逆时扫描,节点扫描坐标 vᵢ=Σⱼmⱼ1[Sⱼ>Sᵢ]/Σⱼmⱼ。原值完全相等者整层加入,局部极大平台出生,复合合并按 B3 的 elder 规则逐个配对。保存每个出生平台的全部节点、有限条的出生/消亡分位与每个物理分量的无限条。单用 B3 导出的一行复合事件不足以恢复全部配对,需要原图、原预测和完整条记录。
**清理阈值一次固定为 0.020 全件体积分位跨度。** 保留所有无限条,以及寿命 v_死−v_生≥0.020 的有限条;恰等保留。标记集 P 为这些条的出生平台并集。这个门槛取 B3 评分门槛 0.010 的两倍,以便检验原本会被计分的短寿事件。它是看过原 B3 汇总后提出的学习侧假设;不扫阈值,不读取真场来挑峰。
**输出是一幅完整到达场。** 每个顶点 i 的新值取所有从保留标记到 i 的真实图路径中,路径最低原时间的最大值:
C(i) = max_{p∈P、路径 γ:p→i} min_{j∈γ} S(j)。
允许长度零的路径。每个物理分量有标记。等价地,在任一原时间水平 t,仅保留 {S≥t} 中含标记的连通部分;被剪去的峰随水平降低到能连回保留峰的鞍部时才重新出现。用多源最大优先队列实现:标记初始化为 S(p),余点为 −∞,沿边用 min(当前值,S邻点) 松弛取大,最后所有点必须有限。时间 O((|V|+|E|)log|V|),不产生跨空隙边。保留平台以原单位精确复现,C≤S。此式采用已有的标记形态学重建;本项目的选择是以 B3 的体积秩寿命选标记,然后在原时间场重建。[Vincent,形态学重建](https://pubmed.ncbi.nlm.nih.gov/18296207/)
纸面自检:链 S=(4,1,2),相应质量 (0.970,0.015,0.015)。右峰的出生分位为 0.970、消亡为 0.985,寿命 0.015。原图上达到 B3 计分门槛,在 B11 中被剪,输出 (4,1,1)。若原场只有一个区域极大平台,重建返回原场。原场具有唯一全件最高点时,其全域末填位置严格不动;若最高值有多个相互分离的并列平台,elder 规则可能保留其中的子集。仅在查询集选末点时,即便全域最高点唯一,局部改序仍可改变查询末点。逐件记原/新全域最高平台与查询末点,避免把并列变化当成位置改进。
## 怎么判
1. 完全沿用 B3 的面板、网格、质量、节点 ID 及真场。第一组用 B3 原全节点 EIK;等 B1 全节点预测冻结后,再对同 50 件的 A/H1 做同一变换。A/H1 优先取 100% 池中该件所属外测折的同身份预测,两臂同折同名单;面板是基于既有学习结果选定的,分折预测不使这次选题变成新盲测。若缺共同预测,列出缺件、原因和角色,不混入学习拟合值。每臂成对保存 raw/clean 的哈希和覆盖,先冻结预测,再评分。真场始终保持原样。
2. 对 C **重新计算**其全件严格体积分位、平台和事件,用 B3 原评分器重新一对一匹配:持续度 ≥0.010、图距 ≤0.10Rg、阶段差 ≤0.05。清理后的秩和配对可改变,不能直接从旧 FP 列表删行。报告 TP/FP/FN、微平均 precision/recall、匹配位置中位数和四种空事件件数。对原 R4bc 查询 ID、次数及并列规则计算同件 raw/clean 的末填距离/Rg 与 Kendall τ-b;另列未定义件、并列增量和共同有效分母。新值只会向下调,附原协议场相对 L2 及改动节点体积比例,供判断定位收益有没有时间误差代价。
3. 建议冻结一个学习侧继续条件,逐臂判断:同面板微平均 precision 至少提高 **0.010 绝对值**,recall 损失 ≤0.020;在同件有效配对上,组件等权平均末填距离/Rg 增量 ≤0.010、τ-b 减量 ≤0.010。缺分母记不可判,不把事件全清空计为通过。若缺 50 件完整共同域或清理新增未定义的末点/τ,则只能报告诊断,不能靠删件通过。EIK 和之后的 A/H1 分开记录;某臂不过只剪这套固定规则在该臂的用途。过门仅支持换独立面板复核;工程阈值不代表已知的工业可接受差异。
Melt 在 B5 后使用既有预测、同一执行者,整枝建议 ≤2 worker CPU-h,分账记录提取、重建、评分及未完成分母。B1 未到只进行 EIK 部分。该指标评价到达场空间结构,未验证重剖稳定性、焊线或气穴,也不据一次事后简化推断学习器需要拓扑损失。
+249
View File
@@ -0,0 +1,249 @@
"""Single approved B11 chain: EIK, then frozen out-of-fold A/H1; no fitting."""
import argparse
import fcntl
import hashlib
import json
import os
from pathlib import Path
import resource
import shutil
import subprocess
import sys
import time
import numpy as np
from scipy.sparse import csr_matrix
from phase2_b11_math import reconstruct,gate_decision
from phase2_h1_worker_v2 import checked,sha,save
from phase2_h1_topology import events,match
from phase2_gates_34 import totals
from s2_custody_common import prediction_inputs
from s2_custody_statistics import part_metrics
from r4bc_guard import supervise
from s2_recovery_monitoring import disk_usage
BASE=Path('/home/frank14f/optane/MeltMind')
ROOT=BASE/'artifacts/phase2-b11-gate-2026-11-17'
H1=BASE/'artifacts/phase2-h1-execution-2026-11-17'
B3=BASE/'artifacts/phase2-b3-gate-2026-11-17'
WRITER=Path('/tmp/meltmind-git-review-20261114-v1-29ebglg8')
def read(p):return json.loads(Path(p).read_text())
def prepare(acceptance):
a=read(acceptance);assert a['status']=='PASS'
for p,h in a['code_sha256'].items():checked(BASE/p,h)
old=read(B3/'contract.json');sources={str(B3/'contract.json'):sha(B3/'contract.json'),str(H1/'contract.json'):sha(H1/'contract.json'),str(acceptance):sha(acceptance)}
for row in old['parts']:
for name in ['geometry.npz','truth-events.json','eik-events.json']:
p=B3/'parts'/row['case']/name;sources[str(p)]=sha(p)
spec=BASE/'references/2026-11-17/phase2-design/mold-b11-spec-364446c7.md'
checked(spec,'364446c724c434eea18ca646e1efa352bb9614249b8d6ac00340df4e83a45471');sources[str(spec)]=sha(spec)
names=['phase2_b11_math','phase2_b11_gate','phase2_h1_worker_v2','phase2_residual_math','phase2_h1_topology','phase2_gates_34','phase2_gate_math','s2_custody_common','s2_custody_statistics','r4bc_guard','s2_recovery_supervisor','s2_recovery_monitoring']
ROOT.mkdir(exist_ok=False)
save(ROOT/'contract.json',dict(version='B11-marker-reconstruction-v1',approval='1794891811.393839',parts=old['parts'],
source_sha256=sources,code_sha256={f'tools/{n}.py':sha(BASE/f'tools/{n}.py') for n in names},
threshold=.020,score_thresholds=[.010,.10,.05],gate=dict(precision_gain=.010,recall_loss=.020,last_increase=.010,tau_loss=.010),
cpu=22,total_cpu_seconds=7200,setup_charge_seconds=60,phase_cpu_max=1800,phase_wall_seconds=1800,rss_bytes=8*1024**3,disk_bytes=5*1024**3,
model_wait_wall_seconds=21600,arms=['EIK','A','H1'],query_metrics='unchanged R4bc query IDs/counts/ties and seeded5000-pair tau-b; 50 distinct components',
missing_policy='missing full50 or any undefined paired metric => PARK; no replacement or fitted learning values',new_models=0,new_decodes=0,gpu=False,retry=False))
def config(root):
c=read(root/'contract.json')
for p,h in {**c['code_sha256'],**c['source_sha256']}.items():checked(p,h)
for r in c['parts']:
a=next(x for x in r['assignments'] if x['fold']==0)
if a['role']!='learning' or '100' not in a['learning_pools']:raise PermissionError('B11 label access outside panel')
return c
def freeze(root,name,files):
with Path('/tmp/meltmind-single-writer.lock').open('a') as lock:
fcntl.flock(lock,fcntl.LOCK_EX)
def git(*args):return subprocess.check_output(['git','-C',str(WRITER),*args],text=True).strip()
if git('branch','--show-current')!='codex/s2-execution-diff-20261114' or git('status','--porcelain'):raise RuntimeError('Single writer not clean')
paths=[];hashes={}
for p in files:
p=Path(p);rel=str(p.resolve().relative_to(BASE));dest=WRITER/rel;dest.parent.mkdir(parents=True,exist_ok=True);shutil.copyfile(p,dest);paths.append(rel);hashes[rel]=sha(p)
subprocess.run(['git','-C',str(WRITER),'add','--',*paths],check=True)
if git('diff','--cached','--name-only'):subprocess.run(['git','-C',str(WRITER),'commit','-m','B11 '+name+' frozen predictions and scoring sources'],check=True)
commit=git('rev-parse','HEAD')
for p,h in hashes.items():
if hashlib.sha256(subprocess.check_output(['git','-C',str(WRITER),'show',commit+':'+p])).hexdigest()!=h:raise ValueError('B11 Git mismatch')
proof=dict(commit=commit,checkout=str(WRITER),sha256=hashes,remote_published=False)
save(root/(name+'-git-freeze.json'),proof)
return proof
def verify_freeze(path,check_git=True):
proof=read(path)
for rel,h in proof['sha256'].items():
checked(BASE/rel,h)
if check_git:
data=subprocess.check_output(['git','show',proof['commit']+':'+rel],cwd=proof['checkout'])
if hashlib.sha256(data).hexdigest()!=h:raise ValueError('Frozen Git bytes differ')
def model_entries(check_git=False):
proof=read(H1/'scoring-git-freeze.json')
for name in ['contract.json','predictions-freeze.json','geometry/manifest.json']:
checked(H1/name,proof['sha256'][name])
if check_git:
rel=str((H1/name).relative_to(BASE));data=subprocess.check_output(['git','show',proof['commit']+':'+rel],cwd=proof['checkout'])
if hashlib.sha256(data).hexdigest()!=proof['sha256'][name]:raise ValueError('B1 full-node freeze mismatch')
f=read(H1/'predictions-freeze.json')
if not f['all_prediction_attempts_terminal'] or not f['accounting_complete']:raise PermissionError('B1 prediction barrier incomplete')
return f['entries']
def select_entry(row,entries):
fold=next(a['fold'] for a in row['assignments'] if a['role']=='test')
found=[e for e in entries if e['protocol']=='grouped' and e['pool']==100 and e['fold']==fold and e['case']==row['case']]
if len(found)!=1:raise ValueError('Missing/duplicate full-node out-of-fold100 common A/H1 prediction')
return found[0]
def geometry(row,c):
p=B3/'parts'/row['case']/'geometry.npz'
with np.load(checked(p,c['source_sha256'][str(p)]),allow_pickle=False) as z:
x=z['points'].copy();raw=z['raw_ids'].copy();mass=z['mass'].copy();rg=float(z['rg'])
adjacency=csr_matrix((z['data'],z['indices'],z['indptr']),shape=(len(raw),len(raw)))
return x,raw,mass,rg,adjacency
def build(root,c,kind):
phase=root/'phases'/(kind+'-build');dest=phase/'parts';dest.mkdir(exist_ok=False)
if kind=='models':
authorization=read(root/'models-source-authorization.json')
checked(H1/'scoring-git-freeze.json',authorization['freeze_sha256']);checked(H1/'predictions-freeze.json',authorization['manifest_sha256'])
entries=model_entries() if kind=='models' else None
output=[];failures=[];start=time.process_time()
for row in c['parts']:
case=row['case'];out=dest/case;out.mkdir();x,raw,mass,rg,adjacency=geometry(row,c)
try:
if kind=='eik':
cache=row['v5_cache'];p=Path(cache['output'])/'Vf.npy'
fields=dict(EIK=np.load(checked(p,cache['output_sha256']['Vf.npy']),allow_pickle=False)*row['preparation']['t_set']);source=dict(path=str(p),sha256=sha(p),role='frozen input-only EIK')
else:
e=select_entry(row,entries)
with np.load(checked(e['path'],e['sha256']),allow_pickle=False) as z:
if not np.array_equal(z['raw_ids'],raw):raise ValueError('B11 A/H1 original node domain differs')
fields=dict(A=z['A_seconds'].copy(),H1=z['seconds'].copy())
source=dict(**e,role='100pct original out-of-fold predictions on selected learning panel')
for arm,field in fields.items():
before=time.process_time();clean,bars=reconstruct(field,mass,raw,adjacency,c['threshold']);seconds=time.process_time()-before
p=out/(arm+'.npz');np.savez_compressed(p,raw=field,clean=clean,raw_ids=raw)
barpath=out/(arm+'-bars.json');save(barpath,bars)
top=lambda a:sorted(map(int,raw[a==a.max()]))
info=dict(case=case,component_id=row['component_id'],arm=arm,path=str(p),sha256=sha(p),bars_path=str(barpath),bars_sha256=sha(barpath),
source=source,reconstruction_cpu_seconds=seconds,raw_full_max_ids=top(field),clean_full_max_ids=top(clean),
changed_volume_fraction=float(mass[clean!=field].sum()/mass.sum()),target_values_read=False)
save(out/(arm+'-result.json'),info);output.append(info)
except Exception as exc:
failure=dict(case=case,type=type(exc).__name__,message=str(exc));save(out/'failure.json',failure);failures.append(failure)
if disk_usage(root)>=c['disk_bytes']:raise RuntimeError('Whole B11 disk cap')
save(phase/'progress.json',dict(cases=len({x['case'] for x in output}),fields=len(output),failures=failures,cpu_seconds=time.process_time()-start))
save(phase/'manifest.json',dict(entries=output,failures=failures,kind=kind,cpu_seconds=time.process_time()-start,contract_sha256=sha(root/'contract.json')))
def tie_fraction(a):
_,counts=np.unique(a,return_counts=True);n=len(a)
return float(np.sum(counts*(counts-1))/(n*(n-1))) if n>1 else None
def score(root,c,kind):
authorization=read(root/(kind+'-score-authorization.json'))
checked(root/(kind+'-git-freeze.json'),authorization['freeze_sha256'])
verify_freeze(root/(kind+'-git-freeze.json'),check_git=False)
built=read(root/'phases'/(kind+'-build')/'manifest.json');phase=root/'phases'/(kind+'-score');out=phase/'parts';out.mkdir(exist_ok=False)
rows=[];failures=list(built['failures']);start=time.process_time();by={r['case']:r for r in c['parts']}
for e in built['entries']:
case=e['case'];row=by[case];dest=out/(case+'-'+e['arm']);dest.mkdir()
try:
x,raw,mass,rg,adjacency=geometry(row,c)
with np.load(checked(e['path'],e['sha256']),allow_pickle=False) as z:
if not np.array_equal(raw,z['raw_ids']):raise ValueError('B11 field IDs changed')
fields={k:z[k].copy() for k in ['raw','clean']}
for p,h in [(e['bars_path'],e['bars_sha256'])]:checked(p,h)
refpath=B3/'parts'/case/'truth-events.json';ref=read(checked(refpath,c['source_sha256'][str(refpath)]))
cache=row['v5_cache'];yp=Path(cache['output'])/'seconds.npy'
save(dest/'target-access.json',dict(role='B3_selected_learning_panel_only',path=str(yp),sha256=cache['output_sha256']['seconds.npy']))
truth=np.load(checked(yp,cache['output_sha256']['seconds.npy']),allow_pickle=False)
q=prediction_inputs(row);ix=np.searchsorted(raw,q['raw_ids'])
if np.any(ix>=len(raw)) or not np.array_equal(raw[ix],q['raw_ids']):raise ValueError('R4bc query IDs differ')
result=dict(case=case,component_id=row['component_id'],arm=e['arm'],changed_volume_fraction=e['changed_volume_fraction'],query_ids=list(map(int,q['raw_ids'])),query_counts=list(map(int,q['counts'])))
for label,field in fields.items():
if e['arm']=='EIK' and label=='raw':
p=B3/'parts'/case/'eik-events.json';old=read(checked(p,c['source_sha256'][str(p)]));ev=old['events'];matching=old['match']
else:ev=events(field,mass,raw,x,adjacency);matching=match(ref,ev,adjacency,rg)
save(dest/(label+'-events.json'),dict(events=ev,match=matching));result[label]=matching
result[label+'_metrics']=part_metrics(field[ix],truth[ix],q['counts'],q['near_wall'],q['raw_ids'],q['coordinates_over_Rg'],int(case.split('_')[0]))
result[label+'_query_tie_fraction']=tie_fraction(field[ix])
qtop=q['raw_ids'][field[ix]==field[ix].max()];result[label+'_query_last_raw_id']=int(qtop.min());result[label+'_query_max_plateau_ids']=list(map(int,qtop))
save(dest/'result.json',result);rows.append(result)
except Exception as exc:
failure=dict(case=case,arm=e['arm'],type=type(exc).__name__,message=str(exc));save(dest/'failure.json',failure);failures.append(failure)
if disk_usage(root)>=c['disk_bytes']:raise RuntimeError('Whole B11 disk cap')
save(phase/'progress.json',dict(scored=len(rows),failures=failures,cpu_seconds=time.process_time()-start))
summaries={}
for arm in (['EIK'] if kind=='eik' else ['A','H1']):
selected=[r for r in rows if r['arm']==arm];rawtot=totals(selected,'raw');cleantot=totals(selected,'clean');paired={};undefined={}
for metric in ['last_location','kendall_tau_b','relative_l2']:
good=[(r['raw_metrics'][metric]['value'],r['clean_metrics'][metric]['value']) for r in selected if r['raw_metrics'][metric]['value'] is not None and r['clean_metrics'][metric]['value'] is not None]
paired[metric]=good;undefined[metric]=[r['case'] for r in selected if r['raw_metrics'][metric]['value'] is None or r['clean_metrics'][metric]['value'] is None]
summaries[arm]=dict(raw=rawtot,clean=cleantot,parts=len(selected),undefined=undefined,paired_denominators={k:len(v) for k,v in paired.items()},
field_means={k:dict(raw=float(np.mean([a for a,b in v])) if v else None,clean=float(np.mean([b for a,b in v])) if v else None) for k,v in paired.items()},
tree_gate=gate_decision(rawtot,cleantot,{k:paired[k] for k in ['last_location','kendall_tau_b']},len(selected),failures))
save(phase/'result.json',dict(status='COMPLETE',kind=kind,summaries=summaries,rows=rows,failures=failures,cpu_seconds=time.process_time()-start,
interpretation='learning-selected panel posthoc gate; no independent blind evaluation; no weld or remesh claim'))
def run(root):
c=config(root);os.sched_setaffinity(0,[c['cpu']]);start=time.process_time();charges=0.;records=[];completed=[]
usage0=resource.getrusage(resource.RUSAGE_CHILDREN);child_start=usage0.ru_utime+usage0.ru_stime
with (root/'run.lock').open('a') as lock:
fcntl.flock(lock,fcntl.LOCK_EX|fcntl.LOCK_NB)
if (root/'actual-start.json').exists():raise FileExistsError('No B11 retry')
save(root/'actual-start.json',dict(pid=os.getpid(),unix=time.time(),contract_sha256=sha(root/'contract.json')))
def total():
usage=resource.getrusage(resource.RUSAGE_CHILDREN)
return c['setup_charge_seconds']+max(charges,usage.ru_utime+usage.ru_stime-child_start)+time.process_time()-start
def phase(kind,mode):
nonlocal charges
name=kind+'-'+mode;dest=root/'phases'/name;dest.mkdir(parents=True,exist_ok=False)
cap=min(c['phase_cpu_max'],c['total_cpu_seconds']-total()-120)
if cap<=0:raise RuntimeError('Cumulative B11 CPU exhausted')
save(root/'live-progress.json',dict(stage=name,completed=completed,cumulative_cpu_seconds=total(),unix=time.time()))
g=supervise([sys.executable,'tools/phase2_b11_gate.py',mode,str(root),kind],dest,
dict(cpu_seconds=cap,wall_seconds=c['phase_wall_seconds'],rss_bytes=c['rss_bytes'],disk_bytes=c['disk_bytes']))
charges+=g['cpu_seconds'];records.append(dict(phase=name,guard=g));save(root/'phase-ledger.json',dict(records=records,cumulative_cpu_seconds=total()))
if g['status']!='PASS' or total()>c['total_cpu_seconds'] or disk_usage(root)>c['disk_bytes']:raise RuntimeError('B11 phase/resource stop: '+name)
try:
for kind in ['eik','models']:
if kind=='models':
begin=time.monotonic()
while not (H1/'scoring-git-freeze.json').exists():
done=read(H1/'complete.json') if (H1/'complete.json').exists() else None
if done or time.monotonic()-begin>=c['model_wait_wall_seconds']:raise RuntimeError('H1 full-node freeze unavailable; EIK retained')
save(root/'live-progress.json',dict(stage='WAIT_ORIGINAL_H1_PREDICTION_FREEZE',completed=completed,cumulative_cpu_seconds=total(),unix=time.time()))
if total()>=c['total_cpu_seconds']-120:raise RuntimeError('B11 waiting CPU cap')
time.sleep(15)
model_entries(check_git=True)
save(root/'models-source-authorization.json',dict(freeze_sha256=sha(H1/'scoring-git-freeze.json'),manifest_sha256=sha(H1/'predictions-freeze.json')))
phase(kind,'build')
manifest=root/'phases'/(kind+'-build')/'manifest.json'
freeze(root,kind,[root/'contract.json',manifest,*[BASE/p for p in c['code_sha256']]])
verify_freeze(root/(kind+'-git-freeze.json'))
save(root/(kind+'-score-authorization.json'),dict(freeze_sha256=sha(root/(kind+'-git-freeze.json'))))
phase(kind,'score');completed.append(kind)
save(root/(kind+'-complete.json'),dict(status='COMPLETE',result_sha256=sha(root/'phases'/(kind+'-score')/'result.json'),cumulative_cpu_seconds=total()))
save(root/'complete.json',dict(status='COMPLETE',completed=completed,records=records,cumulative_cpu_seconds=total(),retry=False))
except BaseException as exc:
save(root/'complete.json',dict(status='STOPPED',reason=type(exc).__name__+': '+str(exc),completed=completed,records=records,cumulative_cpu_seconds=total(),retry=False));raise
if __name__=='__main__':
p=argparse.ArgumentParser();p.add_argument('mode',choices=['prepare','run','build','score']);p.add_argument('path',type=Path);p.add_argument('kind',nargs='?');a=p.parse_args()
if a.mode=='prepare':prepare(a.path)
elif a.mode=='run':run(a.path)
else:(build if a.mode=='build' else score)(a.path,config(a.path),a.kind)
+87
View File
@@ -0,0 +1,87 @@
"""Full dry-H0 bars and marker reconstruction, independent of pinned B1 code."""
import heapq
import math
import time
import numpy as np
def full_bars(field,mass,raw,adjacency):
s=np.asarray(field,dtype=np.float64);m=np.asarray(mass,dtype=np.float64);raw=np.asarray(raw);n=len(s)
if s.shape!=m.shape or raw.shape!=s.shape or adjacency.shape!=(n,n) or not n:raise ValueError('Bar domain mismatch')
if not np.isfinite(s).all() or not np.isfinite(m).all() or np.any(m<=0) or len(np.unique(raw))!=n:raise ValueError('Invalid bar input')
order=np.argsort(-s,kind='stable');bounds=np.r_[0,np.flatnonzero(np.diff(s[order])!=0)+1,n]
parent=np.arange(n);active=np.zeros(n,bool);birth=np.zeros(n);birth_id=raw.copy();records={}
def find(i):
while parent[i]!=i:parent[i]=parent[parent[i]];i=int(parent[i])
return i
total=math.fsum(map(float,m));passed=0.
for lo,hi in zip(bounds[:-1],bounds[1:]):
layer=order[lo:hi];level=passed/total;pending=set(map(int,layer));blocks=[]
while pending:
first=next(iter(pending));pending.remove(first);todo=[first];nodes=[];old=set()
while todo:
i=todo.pop();nodes.append(i)
for jj in adjacency.indices[adjacency.indptr[i]:adjacency.indptr[i+1]]:
j=int(jj)
if active[j]:old.add(find(j))
elif j in pending:pending.remove(j);todo.append(j)
blocks.append((nodes,old))
bp=list(range(len(blocks)));owner={}
def bf(i):
while bp[i]!=i:bp[i]=bp[bp[i]];i=bp[i]
return i
for k,(_,old) in enumerate(blocks):
for g in old:
if g in owner:bp[bf(k)]=bf(owner[g])
else:owner[g]=k
compound={}
for k in range(len(blocks)):compound.setdefault(bf(k),[]).append(k)
for keys in compound.values():
nodes=[i for k in keys for i in blocks[k][0]];olds=set().union(*(blocks[k][1] for k in keys))
if olds:
survivor=min(olds,key=lambda i:(birth[i],int(birth_id[i])))
for g in sorted(olds-{survivor},key=lambda i:(birth[i],int(birth_id[i]))):
records[g].update(death=float(level),persistence=float(level-birth[g]),infinite=False)
for g in olds:parent[g]=survivor
else:
survivor=min(nodes,key=lambda i:int(raw[i]));birth[survivor]=level;birth_id[survivor]=raw[survivor]
records[survivor]=dict(birth=float(level),birth_raw_id=int(raw[survivor]),birth_nodes=sorted(nodes,key=lambda i:int(raw[i])),
birth_raw_ids=sorted(map(int,raw[nodes])),birth_value=float(s[survivor]),death=None,persistence=None,infinite=True)
for i in nodes:parent[i]=survivor;active[i]=True
passed=math.fsum((passed,math.fsum(map(float,m[layer]))))
roots={find(i) for i in range(n)}
if {k for k,v in records.items() if v['infinite']}!=roots:raise ValueError('Infinite class identity mismatch')
return dict(bars=sorted(records.values(),key=lambda r:(r['birth'],r['birth_raw_id'])),infinite_classes=len(roots),nodes=n,total_mass=total)
def reconstruct(field,mass,raw,adjacency,threshold=.020):
start=time.process_time();s=np.asarray(field,dtype=np.float64);detail=full_bars(s,mass,raw,adjacency)
extracted=time.process_time()
markers=[]
for bar in detail['bars']:
bar['kept']=bar['infinite'] or bar['persistence']>=threshold
if bar['kept']:markers.extend(bar['birth_nodes'])
clean=np.full(len(s),-np.inf);heap=[]
for i in markers:clean[i]=s[i];heapq.heappush(heap,(-float(s[i]),int(i)))
while heap:
negative,i=heapq.heappop(heap);value=-negative
if value!=clean[i]:continue
for jj in adjacency.indices[adjacency.indptr[i]:adjacency.indptr[i+1]]:
j=int(jj);candidate=min(value,float(s[j]))
if candidate>clean[j]:clean[j]=candidate;heapq.heappush(heap,(-candidate,j))
if not np.isfinite(clean).all() or np.any(clean>s) or not np.array_equal(clean[markers],s[markers]):raise ValueError('Reconstruction invariant failed')
detail.update(threshold=threshold,marker_nodes=sorted(markers),changed_nodes=int(np.count_nonzero(clean!=s)),
extraction_cpu_seconds=extracted-start,reconstruction_cpu_seconds=time.process_time()-extracted)
return clean,detail
def gate_decision(raw,clean,metric_pairs,parts,failures):
values=[raw.get('precision'),clean.get('precision'),raw.get('recall'),clean.get('recall')]
if parts!=50 or failures or any(x is None for x in values):return dict(decision='PARK_UNDEFINED_OR_COVERAGE')
if any(not pairs for pairs in metric_pairs.values()):return dict(decision='PARK_UNDEFINED_OR_COVERAGE')
if any(len(pairs)!=50 for pairs in metric_pairs.values()):return dict(decision='PARK_UNDEFINED_OR_COVERAGE')
last=float(np.mean([b-a for a,b in metric_pairs['last_location']]))
tau=float(np.mean([a-b for a,b in metric_pairs['kendall_tau_b']]))
changes=dict(precision_gain=clean['precision']-raw['precision'],recall_loss=raw['recall']-clean['recall'],last_distance_increase=last,tau_b_loss=tau)
passed=changes['precision_gain']>=.010 and changes['recall_loss']<=.020 and last<=.010 and tau<=.010
return dict(decision='RETAIN_FOR_INDEPENDENT_PANEL' if passed else 'PRUNE_THIS_FIXED_RULE_ON_THIS_ARM',changes=changes)
+46
View File
@@ -0,0 +1,46 @@
import unittest
import numpy as np
from scipy.sparse import csr_matrix
from phase2_b11_math import full_bars,reconstruct,gate_decision
from phase2_h1_topology import events
def graph(n,edges):
a=[i for i,j in edges]+[j for i,j in edges];b=[j for i,j in edges]+[i for i,j in edges]
return csr_matrix((np.ones(len(a)),(a,b)),shape=(n,n))
class B11Tests(unittest.TestCase):
def test_required_chain(self):
s=np.array([4.,1.,2.]);a=graph(3,[(0,1),(1,2)])
clean,detail=reconstruct(s,[.970,.015,.015],np.arange(3),a)
np.testing.assert_array_equal(clean,[4.,1.,1.]);self.assertEqual(len(detail['bars']),2)
self.assertAlmostEqual(detail['bars'][1]['persistence'],.015)
def test_single_plateau_identity(self):
s=np.array([4.,4.,2.,1.]);a=graph(4,[(0,1),(1,2),(2,3)])
clean,d=reconstruct(s,np.ones(4),np.arange(4),a)
np.testing.assert_array_equal(clean,s);self.assertEqual(d['bars'][0]['birth_nodes'],[0,1])
def test_disconnected_components_keep_infinite(self):
s=np.array([4.,1.,2.,0.]);a=graph(4,[(0,1),(2,3)])
clean,d=reconstruct(s,np.ones(4),np.arange(4),a)
np.testing.assert_array_equal(clean,s);self.assertEqual(d['infinite_classes'],2)
def test_compound_all_dying_bars_match_b3(self):
s=np.array([4.,3.,2.,1.,1.]);a=graph(5,[(0,3),(1,3),(1,4),(2,4)])
d=full_bars(s,np.ones(5),np.arange(5),a);e=events(s,np.ones(5),np.arange(5),np.c_[np.arange(5),np.zeros((5,2))],a)
finite=[(b['birth_raw_id'],b['birth'],b['death'],b['persistence']) for b in d['bars'] if not b['infinite']]
old=[(b['birth_raw_id'],b['birth'],b['death'],b['persistence']) for event in e['events'] for b in event['bars']]
self.assertEqual(sorted(finite),sorted(old));self.assertEqual(len(finite),2)
def test_exact_threshold_kept_and_raw_id_elder(self):
s=np.array([4.,1.,2.]);a=graph(3,[(0,1),(1,2)])
clean,_=reconstruct(s,[30.,1.,1.],np.arange(3),a,threshold=1/32)
np.testing.assert_array_equal(clean,s)
tied=np.array([4.,1.,4.]);clean,d=reconstruct(tied,[1.,100.,1.],np.array([10,20,1]),a,threshold=1.)
np.testing.assert_array_equal(clean,[1.,1.,4.]);self.assertEqual(next(b for b in d['bars'] if b['infinite'])['birth_raw_id'],1)
def test_gate_empty_and_incomplete_cannot_pass(self):
paired={'last_location':[(0.,0.)]*50,'kendall_tau_b':[(1.,1.)]*50}
self.assertEqual(gate_decision(dict(precision=.1,recall=.9),dict(precision=.2,recall=.9),paired,50,[])['decision'],'RETAIN_FOR_INDEPENDENT_PANEL')
self.assertEqual(gate_decision(dict(precision=.1,recall=.9),dict(precision=None,recall=0.),paired,50,[])['decision'],'PARK_UNDEFINED_OR_COVERAGE')
self.assertEqual(gate_decision(dict(precision=.1,recall=.9),dict(precision=.2,recall=.9),paired,49,[])['decision'],'PARK_UNDEFINED_OR_COVERAGE')
if __name__=='__main__':unittest.main()
+38
View File
@@ -0,0 +1,38 @@
import json
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import patch
import unittest
import numpy as np
from scipy.sparse import csr_matrix
import phase2_b11_gate as gate
class IntegrationTests(unittest.TestCase):
def test_out_of_fold_selection_rejects_learning_substitution(self):
row=dict(case='synthetic',assignments=[dict(fold=0,role='learning'),dict(fold=2,role='test')])
learning=dict(case='synthetic',protocol='grouped',pool=100,fold=0)
test=dict(case='synthetic',protocol='grouped',pool=100,fold=2)
self.assertEqual(gate.select_entry(row,[learning,test]),test)
with self.assertRaises(ValueError):gate.select_entry(row,[learning])
with self.assertRaises(ValueError):gate.select_entry(row,[test,test])
def test_eik_build_never_requires_target_files(self):
with TemporaryDirectory() as tmp:
base=Path(tmp);b3=base/'b3';d=b3/'parts/synthetic';d.mkdir(parents=True)
a=csr_matrix(([1.,1.,1.,1.],([0,1,1,2],[1,0,2,1])),shape=(3,3));raw=np.array([10,20,30])
np.savez(d/'geometry.npz',points=np.c_[np.arange(3),np.zeros((3,2))],raw_ids=raw,mass=[.970,.015,.015],rg=1.,data=a.data,indices=a.indices,indptr=a.indptr)
cache=base/'cache';cache.mkdir();np.save(cache/'Vf.npy',[4.,1.,2.])
row=dict(case='synthetic',component_id='synthetic',v5_cache=dict(output=str(cache),output_sha256={'Vf.npy':gate.sha(cache/'Vf.npy')}),preparation=dict(t_set=1.))
root=base/'gate';(root/'phases/eik-build').mkdir(parents=True)
c=dict(parts=[row],source_sha256={str(d/'geometry.npz'):gate.sha(d/'geometry.npz')},threshold=.020,disk_bytes=1024**3)
(root/'contract.json').write_text(json.dumps(c))
with patch.object(gate,'B3',b3):gate.build(root,c,'eik')
result=json.loads((root/'phases/eik-build/manifest.json').read_text());self.assertFalse(result['failures']);self.assertEqual(len(result['entries']),1)
with np.load(result['entries'][0]['path']) as z:np.testing.assert_array_equal(z['clean'],[4.,1.,1.])
self.assertFalse(result['entries'][0]['target_values_read']);self.assertFalse((cache/'seconds.npy').exists())
def test_scoring_requires_parent_git_freeze_authorization(self):
with TemporaryDirectory() as tmp:
with self.assertRaises(FileNotFoundError):gate.score(Path(tmp),{},'eik')
if __name__=='__main__':unittest.main()