Freeze approved B12 path and B13 context one-fold gates

This commit is contained in:
Frank14f committed 2026-11-17 14:55:26 +08:00
1 parent 24f8a97e33
commit b685ecd3f3
20 files changed
+218283

No files matched your search

+98
View File
@@ -0,0 +1,98 @@
"""Only label-free B12/B13 preparation; immutable legacy helpers reused."""
import json
from pathlib import Path
import numpy as np
from scipy.sparse.csgraph import connected_components
from phase2_h1_worker_v2 import checked,sha,save
from gre24_features_v2 import mesh as flow_mesh,cell_flow_speed,exterior_faces
from o1_prepare import source_geometry
from o1_partition import graph,Metis,GeometryFailure,InputViolation,readout,LIBRARY_SHA,HEADER_SHA
from o1_v2 import array_sha
from phase2_b12_math import edge_geometry,paths,junction_depth
def read(p):return json.loads(Path(p).read_text())
def cached(row,name):
v=row['v5_cache'];return np.load(checked(Path(v['output'])/(name+'.npy'),v['output_sha256'][name+'.npy']),allow_pickle=False)
def input_geometry(row):
p=row['preparation'];v=row['v5_cache'];old=read(checked(Path(v['output'])/'result.json',v['result_sha256']))
if old['case']!=row['case'] or old['status']!='PASS' or old['t_scale_seconds']!=p['t_set']:
raise InputViolation('Frozen feature identity/clock differs')
with np.load(checked(Path(p['preparation_root'])/'geometry.npz',p['output_sha256']['geometry.npz']),allow_pickle=False) as z:
x=z['points_raw'].copy();t=z['tetra'].copy();raw=z['raw_node_ids'].copy()
if not np.array_equal(raw,cached(row,'raw_ids')):raise InputViolation('Original node identity differs')
return x,t,raw,old
def b12(row,c,dest):
x,t,raw,old=input_geometry(row);df=cached(row,'Df');dw=cached(row,'Dw');g=flow_mesh(x,t)
if not np.isfinite(df).all():raise GeometryFailure('NONFINITE_FROZEN_DF')
sources=np.searchsorted(raw,old['features']['gate_raw_ids'])
if np.any(sources>=len(raw)) or not np.array_equal(raw[sources],old['features']['gate_raw_ids']):raise InputViolation('Frozen gate identity absent')
speed,allwall=cell_flow_speed(g,dw,exterior_faces(t))
if not np.allclose([speed.min(),speed.max()],[old['features']['speed_min'],old['features']['speed_max']],rtol=1e-12,atol=0):raise InputViolation('Reconstructed R1 speed extrema differ')
adjacency,thickness=edge_geometry(x,t,g['volume'],speed)
parent,owner,features,diagnostic=paths(df,raw,sources,adjacency,thickness,g['mass'])
J,jdiag,tree=junction_depth(df,g['mass'],raw,adjacency,sources,owner)
extra=np.column_stack([features,J])
np.savez_compressed(dest/'path-tree.npz',parent=parent,root=owner,raw_ids=raw,**tree)
save(dest/'platforms.json',diagnostic.pop('platforms'))
valid=np.isfinite(extra);volume=g['mass'];reachable=owner>=0
return extra,dict(status='GEOMETRY_COMPLETE',kind='B12',**diagnostic,**jdiag,roots_raw_ids=raw[sources].tolist(),
finite_nodes_per_column=valid.sum(0).tolist(),finite_volume_fraction_per_column=(np.sum(valid*volume[:,None],axis=0)/volume.sum()).tolist(),
path_volume_coverage=float(volume[reachable].sum()/volume.sum()),all_missing_columns=np.all(~valid,axis=0).tolist(),
source_assignment=[dict(root_raw_id=int(raw[s]),nodes=int(np.sum(owner==s)),volume=float(volume[owner==s].sum())) for s in sources],
all_wall_tetrahedra=len(allwall),R1_speed_extrema=[float(speed.min()),float(speed.max())],path_tree_sha256=sha(dest/'path-tree.npz'),
original_gate_mode=old['features']['gate_mode'],no_Df_recompute=True,labels_read=False)
def g_metrics(mesh,g,labels):
if not np.array_equal(np.unique(labels),np.arange(8)):raise GeometryFailure('NOT_EIGHT_NONEMPTY')
volumes=np.bincount(labels,weights=mesh['volume'],minlength=8);fraction=volumes/volumes.sum();connected=[]
for region in range(8):
ids=np.flatnonzero(labels==region)
connected.append(connected_components(g['adjacency'][ids][:,ids],directed=False,return_labels=False)==1)
cut=float(g['area'][labels[g['edges'][:,0]]!=labels[g['edges'][:,1]]].sum())
return dict(volumes=volumes.tolist(),fractions=fraction.tolist(),region_connected=connected,cut_area=cut,
passed=bool(np.all(fraction>=.95/8) and np.all(fraction<=1.05/8) and all(connected) and cut>0))
def b13(row,c,dest):
# Recover original mixed-VTU tet indices exactly; stop before field arrays.
mesh,decoded=source_geometry(c['archive'],row['case']);x,t,raw,old=input_geometry(row)
if not np.array_equal(mesh['raw_nodes'],raw) or not np.array_equal(mesh['points'],x):raise InputViolation('Canonical node geometry differs')
st=np.sort(t,axis=1);ct=mesh['tets'];order=lambda a:np.lexsort(tuple(a[:,i] for i in (3,2,1,0)))
if not np.array_equal(st[order(st)],ct[order(ct)]):raise InputViolation('Canonical tetra membership differs')
g=graph(mesh);fingerprints={k:array_sha(g[k]) for k in ['xadj','adjncy','vwgt','adjwgt']};engine=Metis();cache=c['G_cache'].get(row['case']);calls=0
if cache:
prior=read(checked(cache['result'],cache['result_sha256']));arm=prior['arms']['G']
if arm['input_sha256']!=fingerprints or arm['seed']!=0:raise InputViolation('Existing G input/parameter fingerprint differs')
if 'partition_sha256' not in arm:
return np.full((len(raw),2),np.nan),dict(kind='B13',status='SCIENTIFIC_MISSING',reason='REUSED_ORIGINAL_G_FAILURE: '+arm.get('reason','unknown'),cache_hit=True,partition_calls=0,source_result=cache['result'],source_result_sha256=cache['result_sha256'],labels_read=False)
if arm['options']!=engine.options(0).tolist():raise InputViolation('Existing G options differ')
with np.load(checked(cache['graph'],prior['output_sha256']['graph.npz']),allow_pickle=False) as z:
for k,a in [('raw_nodes',mesh['raw_nodes']),('raw_cells',mesh['raw_cells']),('volume',mesh['volume'])]:
if not np.array_equal(z[k],a):raise InputViolation('Existing G mesh/order fingerprint differs')
with np.load(checked(cache['partition'],arm['partition_sha256']),allow_pickle=False) as z:labels=z['labels'].copy()
returned=dict(seed=0,cache_hit=True,source_partition=cache['partition'],source_partition_sha256=arm['partition_sha256'])
else:
calls=1;labels,returned=engine.partition(g,mesh['raw_cells'],0);returned.update(seed=0,cache_hit=False)
np.savez_compressed(dest/'graph.npz',**{k:g[k] for k in ['xadj','adjncy','vwgt','adjwgt','edges','faces_raw','area']},raw_nodes=raw,raw_cells=mesh['raw_cells'],volume=mesh['volume'])
if fingerprints!={k:array_sha(g[k]) for k in fingerprints}:raise InputViolation('METIS mutated input')
np.savez_compressed(dest/'G-partition.npz',labels=labels)
metrics=g_metrics(mesh,g,labels)
report=dict(kind='B13',partition_calls=calls,input_fingerprints=fingerprints,**returned,**metrics,decoded_geometry_arrays=decoded,
partition_sha256=sha(dest/'G-partition.npz'),labels_read=False)
if not metrics['passed']:return np.full((len(raw),2),np.nan),dict(status='SCIENTIFIC_MISSING',reason='G_SINGLE_ARM_GEOMETRY_FAIL',**report)
features=cached(row,'features');dw=cached(row,'Dw')
if not np.isfinite(dw).all() or dw.max()<=0:return np.full((len(raw),2),np.nan),dict(status='SCIENTIFIC_MISSING',reason='DW_NORMALIZATION_UNDEFINED',**report)
values=features[:,[0,9]]
if not np.isfinite(values).all():raise InputViolation('Frozen F/Dw_star nonfinite')
extra=readout(mesh['tets'],mesh['volume'],values[mesh['tets']].mean(axis=1),labels,len(raw))
mass=np.bincount(mesh['tets'].ravel(),weights=np.repeat(mesh['volume']/4,4),minlength=len(raw))
before=(mass[:,None]*values).sum(0);after=(mass[:,None]*extra).sum(0)
if not np.allclose(before,after,rtol=1e-11,atol=1e-12):raise InputViolation('Regional readout mass identity failed')
return extra,dict(status='GEOMETRY_COMPLETE',mass_integral_before=before.tolist(),mass_integral_after=after.tolist(),**report)
+225
View File
@@ -0,0 +1,225 @@
"""Approved one-fold B12/B13 gates: prepare, freeze, fit, predict, freeze, score."""
import argparse
from collections import Counter
import fcntl
import json
import os
from pathlib import Path
import resource
import sys
import time
import traceback
import joblib
import numpy as np
import xgboost as xgb
from phase2_fixed_io import BASE,freeze,verify
from phase2_h1_worker_v2 import checked,sha,save
from phase2_b1213_features import b12,b13,cached,GeometryFailure,InputViolation
from gre24_models import xgb_model
from r4bc_guard import supervise
from r4bc_common import paired_difference
from s2_custody_common import prediction_inputs
from s2_custody_statistics import last_location
from s2_models.objectives import relative_l2
from s2_recovery_monitoring import disk_usage
def read(p):return json.loads(Path(p).read_text())
def decision(field,last,undefined=False):
if undefined or field['high'] is None or last['high'] is None:return 'PARK_UNDEFINED'
return 'EXPAND_THIS_FIXED_RECIPE' if field['high']<0 or (last['high']<0 and field['high']<.001) else 'PRUNE_THIS_FIXED_RECIPE'
def coverage(rows,results):
groups={}
for r in rows:groups.setdefault(r['component_id'],[]).append(r)
good=[g for g,parts in groups.items() if all(results[r['case']]['status']=='GEOMETRY_COMPLETE' for r in parts)]
return dict(components=len(groups),complete_components=len(good),fraction=len(good)/len(groups),complete_component_ids=good,
valid_parts=sum(results[r['case']]['status']=='GEOMETRY_COMPLETE' for r in rows),total_parts=len(rows))
def prepare(kind,acceptance):
a=read(acceptance)
if a['status']!='PASS':raise ValueError('Acceptance missing')
for p,h in a['code_sha256'].items():checked(BASE/p,h)
oldpath=BASE/'artifacts/phase2-b7-gate-2026-11-17/contract.json';old=read(oldpath)
o1path=BASE/'artifacts/o1-v2-preparation-2026-11-17/contract.json';o1=read(o1path)
root=BASE/f'artifacts/phase2-{kind.lower()}-gate-2026-11-17';root.mkdir(exist_ok=False)
parts=sorted(old['rows']['learning']+old['rows']['validation'],key=lambda r:r['case'])
if len({r['case'] for r in parts})!=431:raise ValueError('Frozen full431 roles differ')
cache={}
if kind=='B13':
for row in parts:
d=BASE/'artifacts/o1-v2-preparation-2026-11-17/parts'/row['case']/'output';rp=d/'result.json'
if rp.exists():
rec=read(rp)
if rec.get('arms',{}).get('G'):
cache[row['case']]=dict(result=str(rp),result_sha256=sha(rp),graph=str(d/'graph.npz'),partition=str(d/'G-partition.npz'))
names=['phase2_b1213_gate','phase2_b1213_features','phase2_b12_math','phase2_fixed_io','phase2_h1_worker_v2','phase2_residual_math','gre24_models','gre24_features_v2','gre24_features','boundary_distance','o1_prepare','o1_partition','o1_v2','audit_samples','r4bc_common','r4bc_guard','s2_custody_common','s2_custody_statistics','s2_recovery_supervisor','s2_recovery_monitoring','freeze_g1_components','s2_models/features','s2_models/objectives']
spec=BASE/('references/2026-11-17/phase2-design/mold-b12-spec-9ac2ed43.md' if kind=='B12' else 'references/2026-11-17/phase2-design/mold-b13-spec-b0af97e6.md')
expected='9ac2ed43ec494b597156fe1f0d2d853ae3e80659fbb309a354c4a707c60d7d94' if kind=='B12' else 'b0af97e6cf854b567c9d72d8a60b0f29f0d7af3ebddcb1ddb80fbf1c05598d5f';checked(spec,expected)
save(root/'contract.json',dict(version=kind+'-one-fold-v1',kind=kind,approval='1794896825.024679',parts=parts,rows=old['rows'],baseline=old['baseline'],G_cache=cache,
archive=o1['archive'],archive_stat=o1['archive_stat'],code_sha256={f'tools/{n}.py':sha(BASE/f'tools/{n}.py') for n in names},
source_sha256={str(oldpath):sha(oldpath),str(o1path):sha(o1path),str(spec):sha(spec),str(acceptance):sha(acceptance)},
extra_columns=3 if kind=='B12' else 2,cpu=24,total_cpu_seconds=7200,setup_seconds=60,geometry_cpu_cap=3600,part_cpu_seconds=30,part_wall_seconds=60,
fit_cpu_cap=3000,predict_cpu_cap=180,score_cpu_cap=180,rss_bytes=8*1024**3,disk_bytes=5*1024**3,cost_checkpoint=10,cost_projection_factor=1.25,
training='same frozen A learning320/all-tet/unit-node/FP32; directT/t_set; XGB100/depth8/eta.1/seed0/1thread/noHPO/noextraArefit',
gate='new-minus-A component-paired2000 bootstrap95 seed2026111408; EXPAND if fieldCI.high<0 OR (lastCI.high<0 AND fieldCI.high<.001); otherwise PRUNE fixed recipe',
missing='native NaN only for defined geometrical missing; engineer/source/resource failures stop, never fabricated completed missing',
B13_coverage='learning and validation each >=80pct components with all own-role members legalG; otherwise PARK coverage before fitting',
sources='frozen Df/Dw/geometry only; no recomputeDf; B13 reuse identical Gseed0 else one G call, noT/C',
new_models=1,retry=False,gpu=False,new_label_decodes=0))
def config(root):
c=read(root/'contract.json')
if xgb.__version__!='2.1.4' or np.__version__!='1.26.4':raise InputViolation('Pinned library version differs')
for p,h in {**c['code_sha256'],**c['source_sha256']}.items():checked(p,h)
s=Path(c['archive']).stat();old=c['archive_stat']
if (s.st_size,s.st_mtime_ns,s.st_ino)!=(old['bytes'],old['mtime_ns'],old['inode']):raise InputViolation('Archive identity changed')
for role,rows in c['rows'].items():
for r in rows:
a=next(a for a in r['assignments'] if a['fold']==0)
if a['role']!=role or (role=='learning' and '100' not in a['learning_pools']):raise InputViolation('Role mismatch')
return c
def field(root,c,index):
row=c['parts'][index];dest=root/'parts'/f'{index:04d}';start=time.process_time()
try:
try:extra,report=(b12 if c['kind']=='B12' else b13)(row,c,dest)
except GeometryFailure as exc:
extra=np.full((row['nodes'],c['extra_columns']),np.nan);report=dict(status='SCIENTIFIC_MISSING',reason=str(exc),labels_read=False)
if extra.shape!=(row['nodes'],c['extra_columns']) or np.isinf(extra).any():raise InputViolation('Invalid extra feature shape/infinity')
np.save(dest/'extra.npy',extra,allow_pickle=False)
save(dest/'result.json',dict(case=row['case'],component_id=row['component_id'],index=index,nodes=row['nodes'],extra_sha256=sha(dest/'extra.npy'),
finite_nodes_per_column=np.isfinite(extra).sum(0).tolist(),**{k:v for k,v in report.items() if k!='finite_nodes_per_column'},cpu_seconds=time.process_time()-start))
except BaseException as exc:
save(dest/'failure.json',dict(type=type(exc).__name__,reason=str(exc),global_stop=True,traceback=traceback.format_exc(),cpu_seconds=time.process_time()-start));raise
def feature_manifest(root,c):
m=read(root/'features-manifest.json');by={e['case']:e for e in m['entries']}
if set(by)!={r['case'] for r in c['parts']}:raise InputViolation('Feature roster incomplete')
return by
def extra(root,row,entry):
d=root/'parts'/f"{entry['index']:04d}";r=read(checked(d/'result.json',entry['result_sha256']))
return np.load(checked(d/'extra.npy',r['extra_sha256']),allow_pickle=False),r
def train(root,c):
verify(root,'features');dest=root/'phases/train';entries=feature_manifest(root,c);n=sum(r['nodes'] for r in c['rows']['learning'])
X=np.empty((n,19+c['extra_columns']),np.float32);Y=np.empty(n,np.float32);offset=0;access=[]
for row in c['rows']['learning']:
f=cached(row,'features');e,report=extra(root,row,entries[row['case']]);raw=cached(row,'raw_ids')
if f.shape!=(row['nodes'],19) or not np.isfinite(f).all() or len(raw)!=row['nodes']:raise InputViolation('Learning feature identity')
access.append(dict(case=row['case'],role='fold0_learning',target_sha256=row['v5_cache']['output_sha256']['target.npy'],nodes=row['nodes']));save(dest/'target-access.json',access)
y=cached(row,'target');end=offset+len(y)
if y.shape!=(row['nodes'],) or not np.isfinite(y).all():raise InputViolation('Learning target shape/nonfinite')
X[offset:end,:19]=f;X[offset:end,19:]=e;Y[offset:end]=y;offset=end
save(dest/'progress.json',dict(stage='LOAD_LEARNING',parts=len(access),nodes=offset))
if offset!=n:raise InputViolation('Learning count changed')
model=xgb_model(0,1);save(dest/'progress.json',dict(stage='FIT',nodes=n,parts=len(access),columns=X.shape[1]))
model.fit(X,Y,sample_weight=np.ones(n,np.float64));model.save_model(dest/'model.ubj')
save(dest/'xgboost-config.json',json.loads(model.get_booster().save_config()))
save(dest/'result.json',dict(status='FIT_COMPLETE',checkpoint_sha256=sha(dest/'model.ubj'),nodes=n,parts=len(access),columns=X.shape[1],unit_node_weights=True,validation_labels_read=False))
def predict(root,c):
verify(root,'model');dest=root/'phases/predict';entries=feature_manifest(root,c);model=xgb.XGBRegressor();model.load_model(root/'phases/train/model.ubj')
baseline=joblib.load(checked(c['baseline']['model_path'],c['baseline']['model_sha256']));out=[]
for row in c['rows']['validation']:
q=prediction_inputs(row);raw=cached(row,'raw_ids');ix=np.searchsorted(raw,q['raw_ids'])
if np.any(ix>=len(raw)) or not np.array_equal(raw[ix],q['raw_ids']):raise InputViolation('Validation query IDs')
f=cached(row,'features');e,report=extra(root,row,entries[row['case']]);X=np.column_stack([f[ix],e[ix]]).astype(np.float32)
pred=np.asarray(model.predict(X),np.float64);a=np.asarray(baseline.predict(f[ix].astype(np.float32)),np.float64)
if not np.isfinite(pred).all() or not np.isfinite(a).all():raise ValueError('Nonfinite prediction')
p=dest/(row['case']+'.npz');np.savez_compressed(p,pred=pred,A=a,raw_ids=q['raw_ids'],counts=q['counts'],coordinates_over_Rg=q['coordinates_over_Rg'])
out.append(dict(case=row['case'],component_id=row['component_id'],path=str(p),sha256=sha(p),geometry_valid=report['status']=='GEOMETRY_COMPLETE'))
save(dest/'progress.json',dict(parts=len(out),validation_labels_read=False))
save(dest/'manifest.json',dict(entries=out,validation_labels_read=False))
def summary(rows):
groups={}
for r in rows:groups.setdefault(r['component_id'],[]).append(r)
result={}
for metric in ['relative_l2','last_location']:
values={arm:{g:float(np.mean([r[arm][metric] for r in rs])) for g,rs in groups.items() if all(r[arm][metric] is not None for r in rs)} for arm in ['new','A']}
result[metric]=dict(means={a:float(np.mean(list(v.values()))) if v else None for a,v in values.items()},new_minus_A=paired_difference(values['new'],values['A']))
return dict(parts=len(rows),components=len(groups),metrics=result)
def score(root,c):
verify(root,'predictions');dest=root/'phases/score';m=read(root/'phases/predict/manifest.json');by={r['case']:r for r in c['rows']['validation']};rows=[];access=[];undefined=[]
if len(m['entries'])!=len(by) or {e['case'] for e in m['entries']}!=set(by):raise InputViolation('Prediction roster incomplete')
for e in m['entries']:
row=by[e['case']];access.append(dict(case=row['case'],role='fold0_validation',target_sha256=row['v5_cache']['output_sha256']['target.npy']));save(dest/'target-access.json',access)
y=cached(row,'target');raw=cached(row,'raw_ids')
with np.load(checked(e['path'],e['sha256']),allow_pickle=False) as z:
ix=np.searchsorted(raw,z['raw_ids'])
if not np.array_equal(raw[ix],z['raw_ids']):raise InputViolation('Score query ID mismatch')
out=dict(case=row['case'],component_id=row['component_id'],geometry_valid=e['geometry_valid'])
for arm,key in [('new','pred'),('A','A')]:
l2=relative_l2(z[key],y[ix],z['counts'],np.ones(len(ix),bool))
out[arm]=dict(relative_l2=l2['value'],last_location=last_location(y[ix],z[key],z['raw_ids'],z['coordinates_over_Rg']))
if l2['value'] is None:undefined.append(dict(case=row['case'],arm=arm,reason=l2['reason']))
rows.append(out)
full=summary(rows);valid=summary([r for r in rows if r['geometry_valid']])
result=decision(full['metrics']['relative_l2']['new_minus_A'],full['metrics']['last_location']['new_minus_A'],bool(undefined))
save(dest/'result.json',dict(status='COMPLETE',kind=c['kind'],decision=result,full_roster=full,geometry_valid_subset_descriptive=valid,
invalid_parts=[r['case'] for r in rows if not r['geometry_valid']],undefined=undefined,rows=rows,validation_only=True,
interpretation='fixed one-fold recipe; includes missingness effect; subset never replaces full gate; B13 failure does not close type/O1/connectivity'))
def run(root):
c=config(root);os.sched_setaffinity(0,[24]);lock=(root/'run.lock').open('a');fcntl.flock(lock,fcntl.LOCK_EX|fcntl.LOCK_NB)
if (root/'started.json').exists():raise FileExistsError('Single launch; zero retries')
start=time.process_time();u0=resource.getrusage(resource.RUSAGE_CHILDREN);charged=0.;records=[];entries=[];results={}
def total():
u=resource.getrusage(resource.RUSAGE_CHILDREN);return 60+max(charged,u.ru_utime+u.ru_stime-u0.ru_utime-u0.ru_stime)+time.process_time()-start
def guard(mode,dest,cap,wall,index=None):
nonlocal charged
remaining=c['disk_bytes']-disk_usage(root)
cap=min(cap,7200-total()-120)
if cap<=0 or remaining<=0:raise RuntimeError('Resource reserve exhausted')
command=[sys.executable,'tools/phase2_b1213_gate.py',mode,str(root)]+([] if index is None else [str(index)])
g=supervise(command,dest,dict(cpu_seconds=cap,wall_seconds=wall,rss_bytes=c['rss_bytes'],disk_bytes=remaining))
charged+=g['cpu_seconds'];records.append(dict(mode=mode,index=index,guard=g));save(root/'phase-ledger.json',dict(records=records,cumulative_cpu_seconds=total()))
if g['status']!='PASS' or total()>7200 or disk_usage(root)>c['disk_bytes']:raise RuntimeError('ENGINEERING_OR_RESOURCE_STOP')
save(root/'started.json',dict(pid=os.getpid(),unix=time.time(),contract_sha256=sha(root/'contract.json')))
try:
for i,row in enumerate(c['parts']):
if total()-60+30>c['geometry_cpu_cap']:raise RuntimeError('PARK_RESOURCE_GEOMETRY_CAP')
dest=root/'parts'/f'{i:04d}';dest.mkdir(parents=True,exist_ok=False)
save(root/'live-progress.json',dict(stage='GEOMETRY_ONLY',index=i,case=row['case'],cumulative_cpu_seconds=total(),unix=time.time()))
guard('field',dest,c['part_cpu_seconds'],c['part_wall_seconds'],i)
result=read(dest/'result.json');results[row['case']]=result;entries.append(dict(case=row['case'],index=i,result_sha256=sha(dest/'result.json')))
if i+1==c['cost_checkpoint']:
projected=1.25*(total()-60)*sum(r['nodes'] for r in c['parts'])/sum(r['nodes'] for r in c['parts'][:i+1])
save(root/'first-ten-cost-check.json',dict(projected_geometry_cpu_seconds=projected,cap=c['geometry_cpu_cap'],passed=projected<=c['geometry_cpu_cap'],actual_cpu_seconds=total()))
if projected>c['geometry_cpu_cap']:raise RuntimeError('PARK_RESOURCE_FIRST_TEN_PROJECTION')
cov={role:coverage(rows,results) for role,rows in c['rows'].items()};save(root/'coverage.json',cov)
save(root/'features-manifest.json',dict(entries=entries,all431_terminal=True,labels_read=False))
freeze(root,'features',[root/'contract.json',root/'features-manifest.json',root/'coverage.json',*[BASE/p for p in c['code_sha256']]])
if c['kind']=='B13' and any(v['fraction']<.8 for v in cov.values()):
save(root/'complete.json',dict(status='COMPLETE',scientific_gate='PARK_G_COVERAGE',coverage=cov,cumulative_cpu_seconds=total(),records=records,models_fit=0,retry=False));return
for mode,cap in [('train',c['fit_cpu_cap']),('predict',c['predict_cpu_cap']),('score',c['score_cpu_cap'])]:
if mode=='predict':freeze(root,'model',[root/'contract.json',root/'phases/train/model.ubj',root/'phases/train/result.json',*[BASE/p for p in c['code_sha256']]])
if mode=='score':freeze(root,'predictions',[root/'contract.json',root/'phases/predict/manifest.json',*[BASE/p for p in c['code_sha256']]])
dest=root/'phases'/mode;dest.mkdir(parents=True,exist_ok=False);save(root/'live-progress.json',dict(stage=mode,cumulative_cpu_seconds=total(),unix=time.time()))
guard(mode,dest,cap,cap+60)
save(root/'complete.json',dict(status='COMPLETE',scientific_gate=read(root/'phases/score/result.json')['decision'],cumulative_cpu_seconds=total(),records=records,models_fit=1,retry=False))
except BaseException as exc:
save(root/'complete.json',dict(status='STOPPED',reason=type(exc).__name__+': '+str(exc),cumulative_cpu_seconds=total(),records=records,completed_geometry_parts=len(entries),retry=False));raise
if __name__=='__main__':
p=argparse.ArgumentParser();p.add_argument('mode',choices=['prepare','run','field','train','predict','score']);p.add_argument('path',type=Path);p.add_argument('index',nargs='?');a=p.parse_args()
if a.mode=='prepare':prepare(a.index,a.path)
elif a.mode=='run':run(a.path)
elif a.mode=='field':field(a.path,config(a.path),int(a.index))
else:dict(train=train,predict=predict,score=score)[a.mode](a.path,config(a.path))
+29
View File
@@ -0,0 +1,29 @@
"""Launch only the published single B12/B13 chain after host identity checks."""
import hashlib,json,pathlib,subprocess,sys,time,psutil
B=pathlib.Path('/home/frank14f/optane/MeltMind')
root=B/'artifacts/phase2-b1213-serial-2026-11-17'
proof=json.loads((root/'launch-freeze.json').read_text());assert proof['remote_published']
for rel,h in proof['files'].items():assert hashlib.sha256((B/rel).read_bytes()).hexdigest()==h,rel
c=json.loads((root/'contract.json').read_text())
for p,h in c['source_sha256'].items():assert hashlib.sha256((B/p).read_bytes()).hexdigest()==h,p
modules={'tools/phase2_b1213_serial.py','tools/phase2_b1213_gate.py'}
for p in psutil.process_iter(['pid','cmdline']):
assert not modules.intersection(p.info['cmdline'] or []),'Existing B12/B13 process'
if any(s.startswith('tools/phase2_h1_') for s in (p.info['cmdline'] or [])):
assert 24 not in p.cpu_affinity(),'CPU24 overlaps active B1'
assert not (root/'started.json').exists() and not (root/'service-launch.json').exists()
for kind in ['b12','b13']:assert not (B/f'artifacts/phase2-{kind}-gate-2026-11-17/started.json').exists()
unit='meltmind-phase2-b1213-serial-20261117'
cmd=['systemd-run','--user','--unit='+unit,'--collect','--property=Restart=no','--property=WorkingDirectory='+str(B),
'--setenv=CUDA_VISIBLE_DEVICES=','--setenv=OMP_NUM_THREADS=1','--setenv=OPENBLAS_NUM_THREADS=1','--setenv=MKL_NUM_THREADS=1',sys.executable,'tools/phase2_b1213_serial.py']
r=subprocess.run(cmd,check=True,capture_output=True,text=True)
(root/'service-launch.json').write_text(json.dumps(dict(unit=unit,unix=time.time(),commit=proof['commit'],stdout=r.stdout,stderr=r.stderr),indent=2)+'\n')
time.sleep(2)
processes=[]
for p in psutil.process_iter(['pid','cmdline']):
if modules.intersection(p.info['cmdline'] or []):
processes.append(dict(pid=p.pid,cmdline=p.info['cmdline'],affinity=p.cpu_affinity(),status=p.status()))
audit=dict(unix=time.time(),processes=processes,source_pins_pass=True,commit=proof['commit'],
started=json.loads((root/'started.json').read_text()),progress=json.loads((root/'live-progress.json').read_text()),
B12_started=(B/'artifacts/phase2-b12-gate-2026-11-17/started.json').exists(),B13_started=(B/'artifacts/phase2-b13-gate-2026-11-17/started.json').exists())
(root/'actual-start-audit.json').write_text(json.dumps(audit,indent=2)+'\n');print(json.dumps(audit))
+45
View File
@@ -0,0 +1,45 @@
"""Claude1794896825: exactly one B12 then one B13, no B1 dependency."""
import fcntl
import json
import os
from pathlib import Path
import subprocess
import sys
import time
import psutil
from phase2_h1_worker_v2 import save,sha,checked
BASE=Path('/home/frank14f/optane/MeltMind')
ROOT=BASE/'artifacts/phase2-b1213-serial-2026-11-17'
def read(p):return json.loads(Path(p).read_text())
def live(root):
return [p.pid for p in psutil.process_iter(['pid','cmdline'])
if p.pid!=os.getpid() and str(root) in (p.info['cmdline'] or [])]
def run():
c=read(ROOT/'contract.json')
for p,h in c['source_sha256'].items():checked(BASE/p,h)
os.sched_setaffinity(0,[24]);start=time.process_time()
with (ROOT/'run.lock').open('a') as lock:
fcntl.flock(lock,fcntl.LOCK_EX|fcntl.LOCK_NB)
if (ROOT/'started.json').exists():raise FileExistsError('Unique chain already attempted')
save(ROOT/'started.json',dict(pid=os.getpid(),unix=time.time(),contract_sha256=sha(ROOT/'contract.json')))
results=[]
try:
for name in ['phase2-b12-gate-2026-11-17','phase2-b13-gate-2026-11-17']:
root=BASE/'artifacts'/name
for p,h in c['source_sha256'].items():checked(BASE/p,h)
if live(root) or (root/'started.json').exists():raise RuntimeError('Gate already attempted; no duplicate')
save(ROOT/'live-progress.json',dict(stage='RUN_'+name,unix=time.time(),coordinator_cpu_seconds=time.process_time()-start))
with (ROOT/(name+'.log')).open('x') as log:
child=subprocess.run([sys.executable,'tools/phase2_b1213_gate.py','run',str(root)],stdout=log,stderr=subprocess.STDOUT)
if not (root/'complete.json').exists() or live(root):raise RuntimeError('Missing terminal or live children')
result=read(root/'complete.json');results.append(dict(gate=name,returncode=child.returncode,complete_sha256=sha(root/'complete.json'),status=result['status']))
save(ROOT/'gate-terminals.json',results)
save(ROOT/'complete.json',dict(status='BOTH_GATES_TERMINAL',results=results,coordinator_cpu_seconds=time.process_time()-start,retry=False))
except BaseException as exc:
save(ROOT/'complete.json',dict(status='STOPPED',reason=type(exc).__name__+': '+str(exc),results=results,coordinator_cpu_seconds=time.process_time()-start,retry=False));raise
if __name__=='__main__':run()
+121
View File
@@ -0,0 +1,121 @@
"""Frozen Df-guided tet-edge paths and dry merge-tree depth; no truth."""
import heapq
import math
import numpy as np
from scipy.sparse import csr_matrix
def edge_geometry(x,tets,volume,cell_speed):
pairs=[(0,1),(0,2),(0,3),(1,2),(1,3),(2,3)]
raw=np.concatenate([np.sort(tets[:,[i,j]],axis=1) for i,j in pairs])
edges,inverse=np.unique(raw,axis=0,return_inverse=True)
denominator=np.bincount(inverse,weights=np.tile(volume,6))
inside=np.bincount(inverse,weights=np.tile(volume*cell_speed,6))/denominator
length=np.linalg.norm(x[edges[:,0]]-x[edges[:,1]],axis=1)
if np.any(length<=0) or not np.isfinite(length).all():raise ValueError('NONPOSITIVE_OR_NONFINITE_EDGE')
a=np.r_[edges[:,0],edges[:,1]];b=np.r_[edges[:,1],edges[:,0]]
adjacency=csr_matrix((np.r_[length,length],(a,b)),shape=(len(x),len(x)))
thickness=csr_matrix((np.r_[2*inside,2*inside],(a,b)),shape=adjacency.shape)
return adjacency,thickness
def paths(df,raw,roots,adjacency,thickness,mass=None):
n=len(df);df=np.asarray(df);raw=np.asarray(raw);roots=set(map(int,roots))
mass=np.ones(n) if mass is None else np.asarray(mass)
if not roots or min(roots)<0 or max(roots)>=n or not np.isfinite(df).all():raise ValueError('INVALID_DF_OR_SOURCE')
if not np.array_equal(adjacency.indices,thickness.indices) or not np.array_equal(adjacency.indptr,thickness.indptr):raise ValueError('EDGE_FIELD_ALIGNMENT')
order=np.argsort(df,kind='stable');cuts=np.r_[0,np.flatnonzero(np.diff(df[order])!=0)+1,n]
parent=np.full(n,-2,np.int64);owner=np.full(n,-1,np.int64);b=np.full(n,np.nan);integral=np.full(n,np.nan);processed=[];ties=0;platforms=[]
for lo,hi in zip(cuts[:-1],cuts[1:]):
layer=set(map(int,order[lo:hi]))
while layer:
seed=min(layer,key=lambda i:int(raw[i]));layer.remove(seed);todo=[seed];nodes=[]
while todo:
i=todo.pop();nodes.append(i)
for jj in adjacency.indices[adjacency.indptr[i]:adjacency.indptr[i+1]]:
j=int(jj)
if j in layer:layer.remove(j);todo.append(j)
block=set(nodes);best={};queue=[];exits=0
for i in nodes:
options=[]
for pos in range(adjacency.indptr[i],adjacency.indptr[i+1]):
j=int(adjacency.indices[pos]);length=float(adjacency.data[pos])
if df[j]<df[i] and owner[j]>=0:options.append((-(df[i]-df[j])/length,int(raw[j]),j,pos))
if i in roots:
parent[i]=-1;owner[i]=i;b[i]=np.inf;integral[i]=0.;processed.append(i);candidate=(0.,int(raw[i]),-1,i);exits+=1
elif options:
options.sort();_,_,j,pos=options[0];ties+=sum(o[0]==options[0][0] for o in options)>1
parent[i]=j;owner[i]=owner[j];h=float(thickness.data[pos]);b[i]=min(b[j],h) if np.isfinite(h) and h>0 and not np.isnan(b[j]) else np.nan
integral[i]=integral[j]+float(adjacency.data[pos])/h**2 if np.isfinite(h) and h>0 else np.nan;processed.append(i)
candidate=(0.,int(raw[i]),int(raw[j]),i);exits+=1
else:continue
best[i]=candidate[:3];heapq.heappush(queue,candidate)
finalized=set()
while queue:
dist,exit_id,parent_id,i=heapq.heappop(queue)
if i in finalized or best.get(i)!=(dist,exit_id,parent_id):continue
finalized.add(i)
for pos in range(adjacency.indptr[i],adjacency.indptr[i+1]):
j=int(adjacency.indices[pos])
if j not in block or j in finalized:continue
candidate=(dist+float(adjacency.data[pos]),exit_id,int(raw[i]))
if candidate[0]<=dist:raise ValueError('PLATFORM_DISTANCE_PRECISION_LOSS')
if j not in best or candidate<best[j]:
best[j]=candidate;parent[j]=i;owner[j]=owner[i];h=float(thickness.data[pos])
b[j]=min(b[i],h) if np.isfinite(h) and h>0 and not np.isnan(b[i]) else np.nan
integral[j]=integral[i]+float(adjacency.data[pos])/h**2 if np.isfinite(h) and h>0 else np.nan
heapq.heappush(queue,(*candidate,j))
if parent[i]>=0 and df[parent[i]]==df[i]:processed.append(i)
platforms.append(dict(size=len(nodes),exits=exits,reachable=len(finalized),mass=math.fsum(map(float,mass[nodes])),Df=float(df[nodes[0]]),minimum_raw_id=int(min(raw[nodes]))))
b[np.isinf(b)]=np.nan
return parent,owner,np.column_stack([b,integral]),dict(platforms=platforms,lower_slope_tie_nodes=int(ties),reachable_nodes=int(np.sum(owner>=0)))
def junction_depth(df,mass,raw,adjacency,roots,parent_owner,persistence=.010):
n=len(df);order=np.argsort(-np.asarray(df),kind='stable');cuts=np.r_[0,np.flatnonzero(np.diff(np.asarray(df)[order])!=0)+1,n]
uf=np.arange(n);active=np.zeros(n,bool);birth=np.zeros(n);birth_id=np.array(raw,copy=True);top=np.full(n,-1,np.int64);location=np.full(n,-1,np.int64)
tree_parent=[];significant=[];levels=[];total=math.fsum(map(float,mass));passed=0.
def find(i):
while uf[i]!=i:uf[i]=uf[uf[i]];i=int(uf[i])
return i
for lo,hi in zip(cuts[:-1],cuts[1:]):
layer=order[lo:hi];level=passed/total;pending=set(map(int,layer));blocks=[]
while pending:
first=pending.pop();todo=[first];nodes=[];olds=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]:olds.add(find(j))
elif j in pending:pending.remove(j);todo.append(j)
blocks.append((nodes,olds))
bp=list(range(len(blocks)));seen={}
def bf(i):
while bp[i]!=i:bp[i]=bp[bp[i]];i=bp[i]
return i
for k,(_,olds) in enumerate(blocks):
for g in olds:
if g in seen:bp[bf(k)]=bf(seen[g])
else:seen[g]=k
groups={}
for k in range(len(blocks)):groups.setdefault(bf(k),[]).append(k)
for keys in groups.values():
nodes=[i for k in keys for i in blocks[k][0]];olds=set().union(*(blocks[k][1] for k in keys));event=False
tid=len(tree_parent);tree_parent.append(-1);levels.append(level)
if olds:
survivor=min(olds,key=lambda i:(birth[i],int(birth_id[i])))
event=any(level-birth[i]>=persistence and level-birth[i]>0 for i in olds-{survivor})
for g in olds:tree_parent[int(top[g])]=tid;uf[g]=survivor
else:survivor=min(nodes,key=lambda i:int(raw[i]));birth[survivor]=level;birth_id[survivor]=raw[survivor]
significant.append(event);top[survivor]=tid
for i in nodes:uf[i]=survivor;active[i]=True;location[i]=tid
passed=math.fsum((passed,math.fsum(map(float,np.asarray(mass)[layer]))))
depth=np.zeros(len(tree_parent),np.int64)
for i in range(len(depth)-1,-1,-1):
p=tree_parent[i]
if p>=0:depth[i]=depth[p]+int(significant[p])
result=np.full(n,np.nan)
valid=np.flatnonzero(parent_owner>=0)
result[valid]=depth[location[valid]]-depth[location[parent_owner[valid]]]
if np.any(result[valid]<0):raise ValueError('ROOT_NOT_ANCESTOR_IN_DRY_TREE')
return result,dict(significant_events=int(sum(significant)),tree_nodes=len(tree_parent)),dict(tree_parent=np.array(tree_parent),significant=np.array(significant),node_tree_location=location,tree_depth=depth,tree_levels=np.array(levels))
+105
View File
@@ -0,0 +1,105 @@
import unittest
import numpy as np
from scipy.sparse import csr_matrix
from phase2_b12_math import paths,junction_depth,edge_geometry
from phase2_h1_topology import events
from phase2_b1213_gate import decision,coverage
from phase2_b1213_features import g_metrics
from o1_partition import readout,Metis
from gre24_models import xgb_model
def adjacency(n,edges,length=1.):
e=np.array(edges);return csr_matrix((np.full(2*len(e),length),(np.r_[e[:,0],e[:,1]],np.r_[e[:,1],e[:,0]])),shape=(n,n))
class Acceptance(unittest.TestCase):
def test_unrelated_junction_and_multiple_sources(self):
a=adjacency(8,[(0,1),(1,2),(1,3),(4,5),(5,6),(5,7)]);h=a.copy();h.data[:]=2
df=np.array([0,1,2,2,0,1,2,2.])
_,owner,e,_=paths(df,np.arange(8),[0,4],a,h)
j,r,_=junction_depth(df,np.ones(8),np.arange(8),a,[0,4],owner)
np.testing.assert_array_equal(owner,[0]*4+[4]*4)
np.testing.assert_array_equal(j,[0,0,1,1,0,0,1,1]);self.assertEqual(r['significant_events'],2)
def test_invalid_thickness_propagates_without_invented_values(self):
a=adjacency(4,[(0,1),(1,2),(2,3)]);h=a.copy();h.data[:]=2
for i in [1,2]:
for k in range(h.indptr[i],h.indptr[i+1]):
if h.indices[k] in [1,2]:h.data[k]=0
_,owner,e,_=paths(np.arange(4),np.arange(4),[0],a,h)
np.testing.assert_array_equal(owner,[0]*4);self.assertTrue(np.isnan(e[2:]).all())
def test_field_engineering_error_never_becomes_missing(self):
import tempfile
from pathlib import Path
from unittest.mock import patch
from phase2_b1213_gate import field
from o1_partition import InputViolation
with tempfile.TemporaryDirectory() as tmp:
root=Path(tmp);d=root/'parts/0000';d.mkdir(parents=True)
c=dict(kind='B12',parts=[dict(case='synthetic',component_id='g',nodes=4)],extra_columns=3)
with patch('phase2_b1213_gate.b12',side_effect=InputViolation('synthetic hash corruption')):
with self.assertRaises(InputViolation):field(root,c,0)
self.assertTrue((d/'failure.json').exists());self.assertFalse((d/'result.json').exists());self.assertFalse((d/'extra.npy').exists())
def test_field_defined_missing_keeps_full_shape(self):
import tempfile,json
from pathlib import Path
from unittest.mock import patch
from phase2_b1213_gate import field
from o1_partition import GeometryFailure
with tempfile.TemporaryDirectory() as tmp:
root=Path(tmp);d=root/'parts/0000';d.mkdir(parents=True)
c=dict(kind='B13',parts=[dict(case='synthetic',component_id='g',nodes=4)],extra_columns=2)
with patch('phase2_b1213_gate.b13',side_effect=GeometryFailure('MULTICOMPONENT_SCOPE')):field(root,c,0)
e=np.load(d/'extra.npy');self.assertEqual(e.shape,(4,2));self.assertTrue(np.isnan(e).all())
self.assertEqual(json.loads((d/'result.json').read_text())['status'],'SCIENTIFIC_MISSING')
def test_constant_thickness_and_missing_root(self):
a=adjacency(4,[(0,1),(1,2),(2,3)]);h=a.copy();h.data[:]=2
parent,owner,extra,r=paths(np.arange(4),np.arange(4),[0],a,h)
np.testing.assert_array_equal(parent,[-1,0,1,2]);np.testing.assert_array_equal(owner,[0]*4)
self.assertTrue(np.isnan(extra[0,0]));np.testing.assert_allclose(extra[1:,0],2);np.testing.assert_allclose(extra[:,1],[0,.25,.5,.75])
j,_,_=junction_depth(np.arange(4),np.ones(4),np.arange(4),a,[0],owner);np.testing.assert_array_equal(j,[0]*4)
def test_plateau_ties_and_unknown_component(self):
a=adjacency(6,[(0,1),(0,2),(1,3),(2,3),(4,5)]);h=a.copy();h.data[:]=2
parent,owner,e,r=paths(np.array([0,1,1,1,0,1]),np.arange(6),[0],a,h)
self.assertEqual(parent[3],1);np.testing.assert_array_equal(parent[4:],[-2,-2]);self.assertTrue(np.isnan(e[4:]).all())
self.assertEqual(r['reachable_nodes'],4)
def test_flat_plateau(self):
a=adjacency(4,[(0,1),(1,2),(2,3)]);h=a.copy();h.data[:]=1
p,owner,e,r=paths(np.zeros(4),np.arange(4),[0],a,h)
np.testing.assert_array_equal(p,[-1,0,1,2]);j,_,_=junction_depth(np.zeros(4),np.ones(4),np.arange(4),a,[0],owner);np.testing.assert_array_equal(j,0)
def test_Y_and_compound_event(self):
a=adjacency(6,[(0,1),(1,2),(2,3),(2,4),(2,5)]);h=a.copy();h.data[:]=2;df=np.array([0,1,2,3,3,3.])
_,owner,_,_=paths(df,np.arange(6),[0],a,h);j,r,_=junction_depth(df,np.ones(6),np.arange(6),a,[0],owner)
np.testing.assert_array_equal(j,[0,0,0,1,1,1]);self.assertEqual(r['significant_events'],1)
old=events(df,np.ones(6),np.arange(6),np.column_stack([np.arange(6),np.zeros((6,2))]),a)
self.assertEqual(r['significant_events'],len(old['events']))
def test_edge_inner_distance_positive_at_wall(self):
x=np.array([[0,0,0],[1,0,0],[0,1,0],[0,0,1.]])
a,h=edge_geometry(x,np.array([[0,1,2,3]]),np.array([1/6]),np.array([.25]))
np.testing.assert_allclose(h.data,.5)
_,_,e,_=paths(np.array([0,1,1,1]),np.arange(4),[0],a,h);self.assertTrue(np.all(np.isfinite(e[1:])))
def test_g_readout_mass_and_permutation(self):
t=np.array([[0,3*k+1,3*k+2,3*k+3] for k in range(8)]);v=np.arange(1,9,dtype=float);labels=np.arange(8)
x=np.arange(50,dtype=float).reshape(25,2)/50;b=x[t].mean(1)
u=readout(t,v,b,labels,25);permutation=np.array([5,3,1,7,0,2,6,4]);uu=readout(t,v,b,permutation,25)
np.testing.assert_allclose(u,uu);m=np.bincount(t.ravel(),weights=np.repeat(v/4,4),minlength=25)
np.testing.assert_allclose((m[:,None]*u).sum(0),(m[:,None]*x).sum(0))
np.testing.assert_allclose(readout(t,v,np.ones((8,2))*3,labels,25),3)
np.testing.assert_allclose(u[0],np.average(b,axis=0,weights=v));np.testing.assert_allclose(u[1],b[0])
def test_g_single_arm_gate(self):
edges=np.array([(i,i+1) for i in range(7)]);g=dict(adjacency=adjacency(8,edges),edges=edges,area=np.ones(7));m=dict(volume=np.ones(8));labels=np.arange(8)
self.assertTrue(g_metrics(m,g,labels)['passed']);m['volume'][0]=2;self.assertFalse(g_metrics(m,g,labels)['passed'])
self.assertEqual(Metis().options(0)[8],0)
def test_final_gate_strict_boundaries(self):
self.assertEqual(decision({'high':-.001},{'high':1}),'EXPAND_THIS_FIXED_RECIPE')
self.assertEqual(decision({'high':.0009},{'high':-.01}),'EXPAND_THIS_FIXED_RECIPE')
self.assertEqual(decision({'high':.001},{'high':-.01}),'PRUNE_THIS_FIXED_RECIPE')
self.assertEqual(decision({'high':0},{'high':0}),'PRUNE_THIS_FIXED_RECIPE')
self.assertEqual(decision({'high':None},{'high':-.01}),'PARK_UNDEFINED')
def test_component_complete_coverage(self):
rows=[dict(case='a',component_id='g'),dict(case='b',component_id='g'),dict(case='c',component_id='h')]
results={k:dict(status='GEOMETRY_COMPLETE') for k in ['a','b','c']};results['b']['status']='SCIENTIFIC_MISSING'
c=coverage(rows,results);self.assertEqual(c['fraction'],.5);self.assertEqual(c['valid_parts'],2)
def test_native_nan_fixed_regressor(self):
x=np.arange(100,dtype=np.float32).reshape(20,5);x[:5,-1]=np.nan;y=np.arange(20,dtype=np.float32)
m=xgb_model(0,1);m.fit(x,y,sample_weight=np.ones(20));self.assertEqual(m.get_booster().num_boosted_rounds(),100);self.assertTrue(np.isfinite(m.predict(x)).all())
if __name__=='__main__':unittest.main()