171 lines
11 KiB
Python
171 lines
11 KiB
Python
"""Recompute the new evidence, preserve gated non-execution, then seal truthfully."""
|
|
from context import ROOT, MODEL, EXP, AJ, AJ_MODEL, AG, CFG, read, save, digest, check, integrity, budget, seal
|
|
|
|
|
|
def optional(path):
|
|
return read(path) if path.exists() else None
|
|
|
|
|
|
def decide_status(*, numerical, seed, novel, integrity_pass, reference_pass, reference_present,
|
|
known_numerical_failure=False, unauthorized_novel=False):
|
|
if not integrity_pass or (reference_present and not reference_pass):
|
|
return 'FAIL-FROZEN-INTEGRITY-OR-REGRESSION'
|
|
if known_numerical_failure or unauthorized_novel:
|
|
return 'FAIL-NUMERICAL-OR-EXECUTION-POLICY'
|
|
if not numerical or not reference_present or not seed or not seed['execution_gate_pass']:
|
|
return 'INCOMPLETE-VALIDATION-EXECUTION'
|
|
if not seed['representation_gate_pass']:
|
|
return 'FAIL-SEED-VALIDATION-REPRESENTATION'
|
|
if not novel or not novel['execution_gate_pass']:
|
|
return 'INCOMPLETE-VALIDATION-EXECUTION'
|
|
if not novel['representation_gate_pass']:
|
|
return 'FAIL-NOVEL-ODOR-REPRESENTATION'
|
|
return 'PASS-FROZEN-D18-INDEPENDENT-VALIDATION'
|
|
|
|
|
|
def component_report(group, name):
|
|
path = EXP / 'component-audit' / group / (name + '.json')
|
|
if not path.exists():
|
|
return None
|
|
report = read(path)
|
|
output = EXP / 'gpu' / group / (name + '-r0')
|
|
assert set(report.get('input_sha256', {})) == {'state.npz', 'summary.json',
|
|
'apl-drive.float32.npy', 'apl-state.float32.npy', 'apl-inhibition.float32.npy'}
|
|
for filename, checksum in report['input_sha256'].items():
|
|
assert digest(output / filename) == checksum
|
|
assert set(report.get('matrix_checks', {})) == {'input_matrix', 'output_matrix', 'input_raw', 'output_raw',
|
|
'kc_globals', 'apl_globals', 'pn_globals', 'apl_out_ids', 'input_scale', 'output_scale'}
|
|
assert set(report.get('ast_replay_bitwise_exact', {})) == {'drive', 'state', 'inhibition'}
|
|
assert set(report.get('float64_measurement', {})) == {'drive', 'state', 'inhibition'}
|
|
actual = bool(not report.get('error') and all(report['matrix_checks'].values()) and
|
|
all(report['ast_replay_bitwise_exact'].values()) and report['theoretical_bound']['applicable'] and
|
|
all(value['bound_violations'] == 0 for value in report['float64_measurement'].values()))
|
|
assert report['pass_all'] == actual
|
|
return actual
|
|
|
|
|
|
def main():
|
|
from pathlib import Path
|
|
import runtime_bridge as bridge
|
|
from validation import summarize
|
|
check(); budget()
|
|
controls_inventory, records = bridge.inventories(EXP, CFG)
|
|
controls, comparisons, components, repeats, summaries = {}, {}, {}, {}, {}
|
|
for row in controls_inventory:
|
|
name = row['name']
|
|
path = EXP / 'audit' / ('control-' + name + '.json')
|
|
if path.exists():
|
|
actual = bridge.control_identity(EXP / 'gpu/controls' / (name + '-r0'), Path(row['source_output']),
|
|
EXP / 'cases/controls' / name, Path(row['source_case']), None)
|
|
assert actual == read(path), 'Raw control evidence changed'
|
|
controls[name] = actual['pass_all']
|
|
component = component_report('controls', name)
|
|
if component is not None:
|
|
components['controls/' + name] = component
|
|
gates = {stage: optional(EXP / 'audit' / (stage + '-gate.json')) for stage in bridge.STAGES}
|
|
for cohort in CFG['validation']['cohorts']:
|
|
summary_path = EXP / 'validation' / cohort / 'summary.json'
|
|
if summary_path.exists():
|
|
actual = summarize(cohort, out_json=None)
|
|
assert actual == read(summary_path), 'Raw validation evidence changed: ' + cohort
|
|
summaries[cohort] = actual
|
|
for row in bridge.probe_rows(records, CFG, cohort):
|
|
name = row['name']
|
|
path = EXP / 'audit' / ('compare-' + cohort + '-' + name + '.json')
|
|
if path.exists():
|
|
actual = bridge.compare(EXP / 'cases' / cohort / name, EXP / 'gpu' / cohort / (name + '-r0'),
|
|
EXP / 'oracle' / cohort / name, None)
|
|
assert actual == read(path), 'Raw oracle evidence changed'
|
|
comparisons[cohort + '/' + name] = actual['pass_all']
|
|
component = component_report(cohort, name)
|
|
if component is not None:
|
|
components[cohort + '/' + name] = component
|
|
for row in bridge.cohort_rows(records, CFG, cohort):
|
|
if row['seed'] != CFG['validation']['seeds'][0]:
|
|
continue
|
|
name = row['name']
|
|
path = EXP / 'audit' / ('repeat-' + cohort + '-' + name + '.json')
|
|
if path.exists():
|
|
actual = bridge.compare_gpu_repeats(EXP / 'gpu' / cohort / (name + '-r0'),
|
|
EXP / 'gpu' / cohort / (name + '-r1'), None)
|
|
assert actual == read(path), 'Raw repeat evidence changed'
|
|
repeats[cohort + '/' + name] = actual['pass_all']
|
|
seed, novel = summaries.get('seed_validation'), summaries.get('novel_to_aj')
|
|
seed_pass = bool(seed and seed['execution_gate_pass'] and seed['representation_gate_pass'])
|
|
novel_paths = [str(path.relative_to(EXP)) for root in ('gpu', 'oracle', 'component-audit')
|
|
for path in (EXP / root / 'novel_to_aj').glob('*')]
|
|
unauthorized = bool(novel_paths and not seed_pass)
|
|
required_cohorts = ['seed_validation', 'novel_to_aj'] if seed_pass else ['seed_validation']
|
|
expected_controls = {row['name'] for row in controls_inventory}
|
|
expected_comparisons = {cohort + '/' + row['name'] for cohort in required_cohorts
|
|
for row in bridge.probe_rows(records, CFG, cohort)}
|
|
expected_components = expected_comparisons | {'controls/' + name for name in expected_controls}
|
|
expected_repeats = {cohort + '/' + row['name'] for cohort in required_cohorts
|
|
for row in bridge.cohort_rows(records, CFG, cohort) if row['seed'] == CFG['validation']['seeds'][0]}
|
|
required_stages = ['controls', 'seed-probes', 'seed-validation'] + (['novel-probes', 'novel-validation'] if seed_pass else [])
|
|
numerical = bool(set(controls) == expected_controls and set(comparisons) == expected_comparisons and
|
|
set(components) == expected_components and set(repeats) == expected_repeats and
|
|
all(all(values.values()) for values in (controls, comparisons, components, repeats)) and
|
|
all(gates[stage] and gates[stage]['pass_all'] for stage in required_stages) and
|
|
all(cohort in summaries and summaries[cohort]['execution_gate_pass'] for cohort in required_cohorts))
|
|
for cohort, summary in summaries.items():
|
|
stage = 'seed-validation' if cohort == 'seed_validation' else 'novel-validation'
|
|
if gates[stage]:
|
|
assert gates[stage]['execution_gate_pass'] == summary['execution_gate_pass']
|
|
assert gates[stage]['representation_gate_pass'] == summary['representation_gate_pass']
|
|
frozen = optional(EXP / 'regression/frozen-five.json')
|
|
integrity_result = integrity()
|
|
save(EXP / 'regression/old-integrity-after.json', integrity_result)
|
|
oldpass = all(row['pass'] for row in integrity_result.values())
|
|
failures = [read(path) for path in sorted((EXP / 'audit').glob('stopped-*.json'))]
|
|
known_failure = bool(any(not value for group in (controls, comparisons, components, repeats) for value in group.values()) or
|
|
any(gate is not None and not gate['pass_all'] for gate in gates.values()) or
|
|
any(not summary['execution_gate_pass'] for summary in summaries.values()) or
|
|
any(row.get('stop_kind') == 'execution_or_numerical_failure' for row in failures))
|
|
status = decide_status(numerical=numerical, seed=seed, novel=novel, integrity_pass=oldpass,
|
|
reference_present=frozen is not None, reference_pass=bool(frozen and frozen['pass_all']),
|
|
known_numerical_failure=known_failure, unauthorized_novel=unauthorized)
|
|
present_runs = []
|
|
for path in sorted((EXP / 'gpu').glob('*/*/summary.json')):
|
|
value = read(path)
|
|
present_runs.append(dict(group=path.parent.parent.name, run=path.parent.name,
|
|
complete=value.get('complete', False), pass_all=value.get('pass_all', False),
|
|
**{key: value.get(key) for key in ('case', 'nodes', 'edges', 'total_spikes',
|
|
'diagnostic_simulation_seconds', 'peak_allocated_vram_bytes')}))
|
|
completed_primary = [row for row in present_runs if row['group'] in CFG['validation']['cohorts']
|
|
and row['run'].endswith('-r0') and row['complete']]
|
|
result = dict(status=status, numerical_gate_pass=numerical, summaries=summaries, gates=gates,
|
|
controls=controls, comparisons=comparisons, components=components, repeats=repeats, stopped=failures,
|
|
seed_validation_pass=seed_pass, novel_to_aj_pass=bool(novel and novel['pass_all']),
|
|
novel_dynamics_executed=bool(novel_paths), novel_unlock_policy_violation=unauthorized,
|
|
planned_primary_cases=120, actual_primary_cases=len(completed_primary), measurements=present_runs,
|
|
aggregated_valid_primary_cases=sum(summary['valid_base_trials'] for summary in summaries.values()),
|
|
actual_checked_repeats=sum(summary['checked_repeats'] for summary in summaries.values()),
|
|
old_frozen_integrity_pass=oldpass, frozen_five_reference_pass=bool(frozen and frozen['pass_all']),
|
|
unchanged_sealed_runtime=True, dynamics_changed=False, old_heldout_dynamic_results_parsed=False,
|
|
novel_scope='Unused for AG/AJ calibration, not historically never simulated',
|
|
shared_APL_arithmetic_oracle_limitation=True, biological_delay_measured=False,
|
|
APL_nonKC_fast_edges_unreplaced=1212, learning_achieved=False, candidate_generated=False,
|
|
full_scientific_goal_achieved=False, payload_bytes_before_manifest=budget(),
|
|
next_gate='Credit specificity and real KC-to-MBON functional transfer before conditioning' if status.startswith('PASS-')
|
|
else 'Inspect the first failed gate without tuning this frozen branch or replacing validation inputs')
|
|
save(EXP / 'audit/final-status.json', result)
|
|
with (EXP / 'REPORT.md').open('x', encoding='utf-8') as stream:
|
|
stream.write('\n'.join(['# Phase 4AK — frozen D18 independent validation', '', f'Status: `{status}`.', '',
|
|
f'Numerical gate: {numerical}. Seed-validation pass: {seed_pass}. Novel-to-AJ pass: {result["novel_to_aj_pass"]}.',
|
|
f'Novel dynamics executed: {bool(novel_paths)}. Unauthorized unlock: {unauthorized}.',
|
|
'Both cohorts and all requested inputs were locked before trajectories; no tuning or gate changes.',
|
|
'Original sealed AJ runtime functions are used unchanged, including 1,212 unreplaced non-KC APL fast edges.',
|
|
'The second six odors were not used for AG/AJ calibration; old 4L had simulated the full panel.',
|
|
'Static seed audit is bounded, not proof of universally unused or statistically independent RNG streams.',
|
|
'Brian LIF/FIFO is independent; APL arithmetic is intentionally shared and separately component-audited.',
|
|
f'Old frozen integrity: {oldpass}. Five old reference trials: {result["frozen_five_reference_pass"]}.',
|
|
'No learning, plasticity update, candidate, game, decoder, RL or Web. This is not completion of the learning goal.',
|
|
'Next gate: ' + result['next_gate'], '']))
|
|
check(); seal(MODEL); seal(EXP)
|
|
print(status, flush=True)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|