154 lines
7.4 KiB
Python
154 lines
7.4 KiB
Python
"""Pure fixed 32-call engineering inventory; no I/O, GPU or input preparation.
|
|
|
|
Rows describe required executions and comparisons, not evidence they occurred.
|
|
The external AM reference is a symbolic role: a coordinator must bind its actual
|
|
case, overlay, sealed outputs and hashes before execution. A validated plan does
|
|
not prove input authority, comparison success, conditioning or learning.
|
|
All public results are independently constructed mutable copies.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
|
|
SCHEMA = 'phase4an-engineering-plan-draft-v1'
|
|
OVERLAYS = ('zero', 'static25')
|
|
MODES = ('reference', 'light')
|
|
CHAIN_LENGTHS = (5, 13, 1, 481, 500)
|
|
PREFIX_ENDS = (18, 19, 500)
|
|
|
|
|
|
def _fresh_id(overlay, mode, repeat=0):
|
|
return f'{overlay}--fresh--{mode}-r{repeat}'
|
|
|
|
|
|
def _prefix_id(overlay, end):
|
|
return f'{overlay}--prefix--reference-t{end:04d}'
|
|
|
|
|
|
def _chain_id(overlay, mode, index):
|
|
return f'{overlay}--chain--{mode}-s{index:02d}'
|
|
|
|
|
|
def _comparison(check, row, *, reference=None, external=None, scope, candidates=None):
|
|
"""Exact descriptors; start/stop are always absolute, half-open ticks."""
|
|
return dict(check=check, reference_row_id=reference, external_reference=external,
|
|
candidate_row_ids=[row['row_id']] if candidates is None else list(candidates),
|
|
start=row['start'], stop=row['stop'], scope=scope)
|
|
|
|
|
|
def _row(identity, overlay, mode, kind, start, stop, parent=None):
|
|
return dict(row_id=identity, overlay=overlay, mode=mode, kind=kind,
|
|
start=start, stop=stop, steps=stop - start, parent_row_id=parent,
|
|
expected_comparisons=[])
|
|
|
|
|
|
def _terminal_reference(overlay, stop):
|
|
if stop == 5:
|
|
return _chain_id(overlay, 'reference', 0)
|
|
if stop == 1000:
|
|
return _fresh_id(overlay, 'reference')
|
|
return _prefix_id(overlay, stop)
|
|
|
|
|
|
def build_plan():
|
|
"""Return the sole current proposal: 32 calls / 11,074 full-graph ticks.
|
|
|
|
kind='chain' with parent_row_id=None is its fresh first segment, NOT a
|
|
continuation from an assumed zero checkpoint. Later segments explicitly
|
|
reference their predecessor. A chain's local request/event coordinates
|
|
are translated using start; terminal.next_tick remains its local phase.
|
|
|
|
All fresh/prefix rows globally precede chains. Reference chains precede
|
|
light chains, allowing the reference first segment to supply prefix 5.
|
|
No extra prefix-5 execution, synthetic 52-call matrix, long idle run,
|
|
input selection, training, parameter update or executor is implemented.
|
|
|
|
Comparison scopes:
|
|
reference_full/reference_prefix/reference_slice: include reference
|
|
tick-state hashes, APL traces, queues, requests, events and states;
|
|
light_recorded: requests.csv, events/counts, final state, APL state,
|
|
normalized pending queues and finite/weight/arrival accounting;
|
|
terminal_state_and_normalized_queues: no comparison of segment counts
|
|
against cumulative prefix counts; counts are handled by chain_exact;
|
|
parent_state_and_pending_queues: bound parent restoration/carry checks.
|
|
A comparator must implement these scopes from artifacts, not this plan's
|
|
existence. Shift local queue headers before comparing absolute timelines.
|
|
"""
|
|
rows = []
|
|
for overlay in OVERLAYS:
|
|
for mode, repeat in (('reference', 0), ('light', 0), ('light', 1)):
|
|
row = _row(_fresh_id(overlay, mode, repeat), overlay, mode, 'fresh', 0, 1000)
|
|
scope = 'reference_full' if mode == 'reference' else 'light_recorded'
|
|
row['expected_comparisons'].append(_comparison(
|
|
'am_exact', row, external='sealed_AM_selected_case_same_overlay_r0', scope=scope))
|
|
if mode == 'light':
|
|
reference = _fresh_id(overlay, 'reference' if repeat == 0 else 'light')
|
|
row['expected_comparisons'].append(_comparison(
|
|
'fresh_exact', row, reference=reference, scope='light_recorded'))
|
|
rows.append(row)
|
|
for end in PREFIX_ENDS:
|
|
row = _row(_prefix_id(overlay, end), overlay, 'reference', 'prefix', 0, end)
|
|
row['expected_comparisons'].append(_comparison(
|
|
'prefix_of_reference', row, reference=_fresh_id(overlay, 'reference'), scope='reference_prefix'))
|
|
rows.append(row)
|
|
|
|
for overlay in OVERLAYS:
|
|
for mode in MODES:
|
|
start, parent, members = 0, None, []
|
|
for index, length in enumerate(CHAIN_LENGTHS):
|
|
row = _row(_chain_id(overlay, mode, index), overlay, mode, 'chain', start, start + length, parent)
|
|
members.append(row['row_id'])
|
|
if mode == 'reference':
|
|
row['expected_comparisons'].append(_comparison(
|
|
'segment_of_reference', row, reference=_fresh_id(overlay, 'reference'), scope='reference_slice'))
|
|
else:
|
|
row['expected_comparisons'].append(_comparison(
|
|
'segment_exact', row, reference=_chain_id(overlay, 'reference', index), scope='light_recorded'))
|
|
terminal = _terminal_reference(overlay, row['stop'])
|
|
if terminal != row['row_id']:
|
|
row['expected_comparisons'].append(_comparison(
|
|
'checkpoint_exact', row, reference=terminal, scope='terminal_state_and_normalized_queues'))
|
|
if parent is not None:
|
|
row['expected_comparisons'].append(_comparison(
|
|
'parent_carry', row, reference=parent, scope='parent_state_and_pending_queues'))
|
|
if index == len(CHAIN_LENGTHS) - 1:
|
|
comparison = _comparison('chain_exact', row, reference=_fresh_id(overlay, mode),
|
|
scope='reference_full' if mode == 'reference' else 'light_recorded', candidates=members)
|
|
comparison['start'] = 0
|
|
row['expected_comparisons'].append(comparison)
|
|
rows.append(row)
|
|
start, parent = row['stop'], row['row_id']
|
|
|
|
return dict(schema=SCHEMA, overlays=list(OVERLAYS), chain_lengths=list(CHAIN_LENGTHS),
|
|
rows=rows, total_calls=32, total_ticks=11074,
|
|
training=False, candidate_generated=False)
|
|
|
|
|
|
def _exact(actual, expected, path):
|
|
"""JSON-shaped values with exact Python types; True is not integer 1."""
|
|
if type(actual) is not type(expected):
|
|
raise ValueError(f'Plan type mismatch at {path}')
|
|
if type(expected) is dict:
|
|
if any(type(key) is not str for key in actual) or set(actual) != set(expected):
|
|
raise ValueError(f'Plan fields mismatch at {path}')
|
|
for key in expected:
|
|
_exact(actual[key], expected[key], path + '.' + key)
|
|
elif type(expected) is list:
|
|
if len(actual) != len(expected):
|
|
raise ValueError(f'Plan inventory length mismatch at {path}')
|
|
for index, (left, right) in enumerate(zip(actual, expected)):
|
|
_exact(left, right, f'{path}[{index}]')
|
|
elif actual != expected:
|
|
raise ValueError(f'Plan value mismatch at {path}')
|
|
|
|
|
|
def validate_plan(plan):
|
|
"""Reject any noncanonical plan; return a new copy, never a PASS receipt.
|
|
|
|
Exact canonical reconstruction rejects unknown fields, order changes,
|
|
omitted/extra overlays or calls, interval gaps, false parent links and
|
|
weakening/removal of required comparisons. No input files are read.
|
|
"""
|
|
canonical = build_plan()
|
|
_exact(plan, canonical, 'plan')
|
|
return canonical
|