Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions .github/workflows/reactor-v0-controls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: reactor-v0-controls

on:
pull_request:
paths:
- 'experiments/reactor_v0/**'
- '.github/workflows/reactor-v0-controls.yml'
push:
branches: [main]
paths:
- 'experiments/reactor_v0/**'
- '.github/workflows/reactor-v0-controls.yml'

permissions:
contents: read

jobs:
finite-control:
runs-on: ubuntu-latest
timeout-minutes: 10
env:
REACTOR_VERIFY_SOURCES: '1'
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97
with:
python-version: '3.11'
- name: Fetch and bind exact parent source objects
run: |
git fetch --no-tags --depth=1 origin \
88ff9223e57bf38c7fc33cb3559a88793a7b5087 \
6bd133d591e43e75a9292463bb4bfde7a34984dc
- name: Preserve an existing frozen closure
if: github.event_name == 'pull_request'
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
python3 -I -B - <<'PY'
import hashlib
import json
from pathlib import Path
import os
import subprocess

closure_path = "experiments/reactor_v0/closure.json"
closure_file = Path(closure_path)
package = Path("experiments/reactor_v0")
package_entries = list(package.rglob("*"))
if (closure_file.is_symlink() or package.is_symlink() or
any(path.is_symlink() for path in package_entries)):
raise SystemExit("frozen package may not contain symlinks")
base = os.environ["BASE_SHA"]
base_commit = subprocess.run(
["git", "cat-file", "-e", base + "^{commit}"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
check=False,
)
if base_commit.returncode != 0:
raise SystemExit("pull-request base is not an available commit")
base_path = subprocess.run(
["git", "ls-tree", "-z", base, "--", closure_path],
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
check=False,
)
if base_path.returncode != 0:
raise SystemExit("unable to inspect frozen closure at pull-request base")
if not base_path.stdout:
print("Base has no Reactor A freeze; introduction is permitted.")
raise SystemExit(0)
prior = subprocess.run(
["git", "show", base + ":" + closure_path],
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
check=False,
)
if prior.returncode != 0:
raise SystemExit("unable to read frozen closure at pull-request base")
current = closure_file.read_bytes()
if current != prior.stdout:
raise SystemExit("frozen closure.json differs from pull-request base")
closure = json.loads(prior.stdout)
expected_package = {
Path(path).relative_to("experiments/reactor_v0").as_posix()
for path in closure
if path.startswith("experiments/reactor_v0/")
} | {"closure.json"}
actual_package = {
path.relative_to(package).as_posix()
for path in package_entries
if not path.is_dir()
}
if actual_package != expected_package:
raise SystemExit("frozen package file set differs from pull-request base")
for relative, expected in closure.items():
path = Path(relative)
if path.is_symlink():
raise SystemExit("frozen closure member may not be a symlink: " + relative)
actual = hashlib.sha256(path.read_bytes()).hexdigest()
if actual != expected:
raise SystemExit("frozen byte mismatch: " + relative)
PY
- name: Normal tests and control
run: |
python3 -I -B -m unittest discover -s experiments/reactor_v0 -p 'test_*.py' -v
python3 -B experiments/reactor_v0/mutation_harness.py
python3 -B experiments/reactor_v0/run_control.py
- name: Optimized tests and control
run: |
python3 -I -B -O -m unittest discover -s experiments/reactor_v0 -p 'test_*.py' -v
python3 -B -O experiments/reactor_v0/mutation_harness.py
python3 -B -O experiments/reactor_v0/run_control.py
- name: Frozen run stage is read-only
run: |
git diff --exit-code -- experiments/reactor_v0 .github/workflows/reactor-v0-controls.yml
test -z "$(git status --porcelain --untracked-files=all --ignored -- \
experiments/reactor_v0 .github/workflows/reactor-v0-controls.yml)"
57 changes: 57 additions & 0 deletions experiments/reactor_v0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Reactor v0 — finite amplitude-transform control freeze

This directory freezes one deterministic, engineering-only regression control.
It does **not** sample a random field, run a campaign, consume a Gaussian or
asymptotic theorem conclusion, alter a scientific status, or execute Reactor B.

The 4×4 periodic integer grid in `fixture.json` has positive finite ordinary
superlevel H0 bars `[[1, 0], [8, 0]]` and essential birth `27`. The essential
class is excluded. For the declared whole-field amplitude law parameters
`alpha = 2/3`, `a = 2`, and `t = 1/4`, the exact exposed regression control is

```text
sum_i min((t / (a * lifetime_i))**alpha, 1) = 1/4 + 1/16 = 5/16.
```

Only rational powers whose required rational roots are exact are supported;
other inputs raise `ValueError`. The counted event is
`A * (birth - death) <= t` (inclusive), so every positive finite bar contributes
`min((t / (a * lifetime))**alpha, 1)`; the inclusive selector
`short_bar_lifetimes` applies to a fixed realised barcode. Expected answers are
exposed regression controls, not blind discoveries.

`source_manifest.json` allowlists the two open parent proof commits and records
raw-byte SHA-256 separately from Git blob membership. Both entries explicitly
say that no theorem conclusion is consumed. `closure.json` pins every consumed
helper, fixture, test, validator, runner, mutation harness, README, manifest,
and path-scoped workflow by raw SHA-256; it intentionally cannot hash itself.

Run the complete frozen controls from the repository root:

```sh
git fetch --no-tags --depth=1 origin \
88ff9223e57bf38c7fc33cb3559a88793a7b5087 \
6bd133d591e43e75a9292463bb4bfde7a34984dc
export REACTOR_VERIFY_SOURCES=1

python3 -I -B -m unittest discover -s experiments/reactor_v0 -p 'test_*.py' -v
python3 -I -B -O -m unittest discover -s experiments/reactor_v0 -p 'test_*.py' -v
python3 -B experiments/reactor_v0/mutation_harness.py
python3 -B -O experiments/reactor_v0/mutation_harness.py
python3 -B experiments/reactor_v0/run_control.py
python3 -B -O experiments/reactor_v0/run_control.py
```

The two fetched commits are exact, open parent-source identities. A missing
object, unavailable origin, or source length, raw SHA-256, or Git-blob mismatch
must stop this complete sequence; do not unset the selector to continue. Runs
without `REACTOR_VERIFY_SOURCES=1` are metadata/control utility runs, not the
complete source-verified control.

The workflow has read-only repository permissions, is triggered only by this
directory or its own workflow file, and ends with a clean-worktree check so the
run stage cannot silently edit the evaluator, tests, or any other tracked input.

Canonical coordination: [Reactor A pickup](https://github.com/d6g8k5htny-coder/main/issues/419#issuecomment-6204609205),
[owner mandate](https://github.com/d6g8k5htny-coder/main/blob/b665307520948308a53d190d7341bf301df3b3a2/governance/OWNER_MANDATE_20261015.md),
and [standing delegation](https://github.com/d6g8k5htny-coder/main/blob/main/governance/OP-AUTONOMY-20260923-v2.1.md).
13 changes: 13 additions & 0 deletions experiments/reactor_v0/closure.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
".github/workflows/reactor-v0-controls.yml": "117da0c992e25b788acea640f1d621036e5beb07c8274ac29b5c0adf1e2cf3b0",
"experiments/reactor_v0/README.md": "b78a30ccdaa52a00a1dd62599ee06899cfddf87b7081f3a06dce40722ae0bc85",
"experiments/reactor_v0/control.json": "ad7066c7f8b7073edb5da910250f714f969bae2e164646a4c8c7cecffa9b43a1",
"experiments/reactor_v0/evaluator.py": "92fe4dd24be870c1651b59a2e9f2a110a8b008d99f6c601efb60e11a6922c5dd",
"experiments/reactor_v0/exact_helpers.py": "2569978f248a28b3754dad8d6ba4d80b47febf338a7db925f17f53723145cb61",
"experiments/reactor_v0/fixture.json": "8fd0ffb74fc98ccb022c0f4652922bd2881dae11ef11902b7d4e79235b7f94ea",
"experiments/reactor_v0/mutation_harness.py": "ea74ee40a6ace0b6ee5152e67876be4841c2643a0646a658ab7d6758f441e78e",
"experiments/reactor_v0/run_control.py": "6af0e3ab778dbe980860fb4d7d78d83f00bd67844c882ad72876b94d050854e3",
"experiments/reactor_v0/source_manifest.json": "86c55b140acc6cf8219915f16df995085eafd95c61c249a6cde29b73a83f9c8d",
"experiments/reactor_v0/test_reactor_v0.py": "8beb2b19a3ce37175521113637923b3a9a925b14915ef1cb0bd5a8431ebb88b1",
"experiments/reactor_v0/validator.py": "2d39c1bd844f49d43aa380443fa384f8e3a0aeb9df6173a3fcf9eeaeb150bef3"
}
13 changes: 13 additions & 0 deletions experiments/reactor_v0/control.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"alpha": {"denominator": 3, "numerator": 2},
"amplitude_scale": {"denominator": 1, "numerator": 2},
"campaign_status": "B_UNRESOLVED_NO_RUN",
"closure": "closure.json",
"expected_control": {"denominator": 16, "numerator": 5},
"fixture": "fixture.json",
"schema_version": 1,
"scientific_status_effect": "NONE",
"scope": "ENGINEERING_ONLY_FINITE_AMPLITUDE_TRANSFORM_CONTROL",
"sources": "source_manifest.json",
"threshold": {"denominator": 4, "numerator": 1}
}
55 changes: 55 additions & 0 deletions experiments/reactor_v0/evaluator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""Finite amplitude-transform regression control; no sampler or theorem use."""

from fractions import Fraction

from exact_helpers import exact_periodic_h0, rational_power_exact


def short_bar_lifetimes(barcode, threshold):
"""Select positive finite bars with inclusive lifetime threshold."""
if type(threshold) is not Fraction or threshold < 0:
raise ValueError("nonnegative exact Fraction threshold required")
intervals = barcode.get("intervals")
if type(intervals) is not list:
raise ValueError("finite intervals list required")
lifetimes = []
for pair in intervals:
if (type(pair) is not list or len(pair) != 2 or
any(type(endpoint) is not int for endpoint in pair)):
raise ValueError("strict integer finite-bar endpoints required")
lifetime = pair[0] - pair[1]
if lifetime <= 0:
raise ValueError("positive finite bars required")
if Fraction(lifetime) <= threshold:
lifetimes.append(lifetime)
return tuple(lifetimes)


def _fraction(document):
return Fraction(document["numerator"], document["denominator"])


def evaluate_package(package):
fixture = package["fixture"]
control = package["control"]
barcode = exact_periodic_h0(fixture["values"], fixture["grid_side"])
if barcode != fixture["expected_barcode"]:
raise ValueError("exact barcode differs from frozen regression fixture")
threshold = _fraction(control["threshold"])
alpha = _fraction(control["alpha"])
amplitude_scale = _fraction(control["amplitude_scale"])
finite_lifetimes = tuple(birth - death for birth, death in barcode["intervals"])
# The finite transform integrates each declared positive finite lifetime.
terms = []
for lifetime in finite_lifetimes:
base = threshold / (amplitude_scale * lifetime)
terms.append(min(rational_power_exact(base, alpha), Fraction(1)))
expected = sum(terms, Fraction(0))
if expected != _fraction(control["expected_control"]):
raise ValueError("declared expected control differs from exact evaluation")
return {
"finite_bars": tuple(tuple(pair) for pair in barcode["intervals"]),
"essential_birth": barcode["essential"][0],
"included_lifetimes": finite_lifetimes,
"expected_short_bar_count": expected,
}
99 changes: 99 additions & 0 deletions experiments/reactor_v0/exact_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"""Copied exact helpers consumed by the Reactor A finite control only."""

from array import array
from fractions import Fraction


def _require(condition, message):
if not condition:
raise ValueError(message)


def exact_periodic_h0(values, side):
"""Return positive finite superlevel H0 bars and the essential birth.

This is the consumed union-find core of ``periodic_h0/exact_h0.py``.
Endpoints remain in strict integer input units and axis edges wrap.
"""
_require(type(side) is int and side >= 3, "integer grid side >= 3 required")
_require(type(values) in (list, tuple) and len(values) == side * side,
"flat square list or tuple required")
_require(all(type(value) is int for value in values),
"strict integer samples required")
count = len(values)
parent = array("i", [-1]) * count
sizes = array("I", [0]) * count
eldest = array("I", [0]) * count
order = sorted(range(count), key=values.__getitem__, reverse=True)
records = []

def root(index):
while parent[index] != index:
parent[index] = parent[parent[index]]
index = parent[index]
return index

for vertex in order:
parent[vertex] = vertex
sizes[vertex] = 1
eldest[vertex] = vertex
row, column = divmod(vertex, side)
neighbors = (
((row - 1) % side) * side + column,
((row + 1) % side) * side + column,
row * side + (column - 1) % side,
row * side + (column + 1) % side,
)
for neighbor in neighbors:
if parent[neighbor] < 0:
continue
left, right = root(vertex), root(neighbor)
if left == right:
continue
survivor, dying = eldest[left], eldest[right]
if (values[survivor] < values[dying] or
(values[survivor] == values[dying] and survivor > dying)):
survivor, dying = dying, survivor
birth, death = values[dying], values[vertex]
if birth > death:
records.append((birth, death, dying))
if sizes[left] < sizes[right]:
left, right = right, left
parent[right] = left
sizes[left] += sizes[right]
eldest[left] = survivor
records.sort()
essential_vertex = eldest[root(0)]
return {
"intervals": [[birth, death] for birth, death, _ in records],
"essential": [values[essential_vertex]],
}


def _integer_root_exact(value, order):
_require(type(value) is int and value >= 0, "nonnegative integer radicand required")
_require(type(order) is int and order > 0, "positive integer root order required")
low, high = 0, value + 1
while low + 1 < high:
middle = (low + high) // 2
if middle ** order <= value:
low = middle
else:
high = middle
if low ** order != value:
raise ValueError("rational root is not exact; exact control refused")
return low


def rational_power_exact(value, exponent):
"""Return ``value**exponent`` only when the rational root is exact."""
_require(type(value) in (int, Fraction) and value >= 0,
"nonnegative exact rational base required")
_require(type(exponent) is Fraction and exponent > 0,
"positive Fraction exponent required")
value = Fraction(value)
root = Fraction(
_integer_root_exact(value.numerator, exponent.denominator),
_integer_root_exact(value.denominator, exponent.denominator),
)
return root ** exponent.numerator
7 changes: 7 additions & 0 deletions experiments/reactor_v0/fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"exclusions": ["essential_class"],
"expected_barcode": {"essential": [27], "intervals": [[1, 0], [8, 0]]},
"grid_side": 4,
"schema_version": 1,
"values": [27, 0, 8, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
}
Loading
Loading