Files
MeltMind/tools/s3b_v04_runtime.py
T

54 lines
2.7 KiB
Python

"""Independent v0.4 pins, cumulative budget and narrowly allowed fallback."""
from pathlib import Path
from s3b_runtime import read, sha, checked, restrict_prediction_io
ROOT=Path('artifacts/s3b-a-v04-ten-2026-11-15')
RULE='1794745781.398039'
CLARIFICATION='1794745880.964439'
OLD_CPU=3239.962177
TOTAL=72000.
RESERVE=7200.
PRESSURE_PHASES={'PRESSURE_MATRIX','PRESSURE_FACTORIZE','PRESSURE_SOLVE','PRESSURE_POSTCHECK'}
def contract(root):
c=read(Path(root)/'contract.json')
for p,h in {**c['code_sha256'],**c['source_sha256']}.items():checked(p,h)
freeze=read(Path(root)/'code-freeze.json')
if freeze['contract_sha256']!=sha(Path(root)/'contract.json') or not freeze.get('git_commit'):
raise ValueError('Not Git-frozen')
if (c['authorizing_ruling']!=RULE or c['clarification']!=CLARIFICATION or
c['old_worker_CPU_s']!=OLD_CPU or c['limits']['total_worker_CPU_s']!=TOTAL or
c['limits']['postfit_reserve_CPU_s']!=RESERVE):raise ValueError('Scope/ledger mismatch')
return c
def reserve_job(new_spent,cap=1800.):
return new_spent>=0 and OLD_CPU+new_spent+cap+RESERVE<=TOTAL
def failure_classification(guard,failure=None,progress=None,result=None):
"""A gate failure never becomes evidence for changing the solver."""
failure=failure or {};progress=progress or {};result=result or {}
if guard.get('monitor_errors'):
return dict(category='MONITOR_FAILURE',solver_attributable=False,reason='monitor_errors')
stop=guard.get('stop_reason')
if stop:
attributable=(stop in {'wall_limit','tree_rss_limit','job_cpu_limit',
'wall_limit_after_exit','rss_limit_after_exit','cpu_limit_after_exit'}
and progress.get('stage') in PRESSURE_PHASES)
return dict(category='RESOURCE_STOP',solver_attributable=attributable,reason=stop,
last_phase=progress.get('stage','UNKNOWN'))
if failure:
return dict(category='NUMERICAL_FAILURE' if failure.get('type')=='SolverFailure' else 'ROUTING_OR_INPUT_FAILURE',
solver_attributable=failure.get('type')=='SolverFailure',
reason=failure.get('message','UNKNOWN'),exception_type=failure.get('type','UNKNOWN'))
if guard.get('status')=='PASS' and result.get('status')=='COMPLETE':
return dict(category='PASS',solver_attributable=False,reason=None)
return dict(category='GEOMETRIC_BLOCKED' if result.get('status')=='BLOCKED' else 'UNKNOWN_FAILURE',
solver_attributable=False,reason=result.get('status','missing terminal result'))
def may_switch(method,classification,gate='candidate'):
return method=='splu' and gate=='candidate' and classification.get('solver_attributable',False)