Geometry inner loop: batched full-objective ratio optimiser (CMA-ES)
innerloop.py: optimise(root, programme_dir, x0=None, budget, method) ->
Result, optimising equal-offset free-branch ratios (midpoint projection of
legacy unequal cuts) against full oracle fitness. OracleEvaluator scores
each population in one batched perl call. Methods: cma (default) — multi-
start sigma ladder (0.05 local, 0.15 exploratory) with IPOP-style popsize
doubling and deterministic seeding (pycma treats seed 0 as clock!) — and
compass with Hooke-Jeeves pattern moves, kept for the d0s bake-off.
Acceptance (experiments/accept_innerloop.py, §4.5 bars vs unprojected
originals, within-noise tolerance 1%): x1.65 / x1.66 / x1.58 against bars
x1.24 / x1.67 / x1.59, no new failures, 46 oracle calls vs Nelder-Mead's
200. The two near-bar results are statistically indistinguishable from the
single-NM-draw bars (measured draw spread brackets them); decision approved
by Bruno 2026-06-12.
Also: tests/ scaffold (12 oracle-free unit tests, pytest pythonpath=src),
rebaseline_no_occlusion.py for homemaker-py-gp2, cma>=3.0 dependency
(installed via dnf), dead-variable cleanup in solver.py.
Closes homemaker-py-1p0.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 09:42:24 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
"""Re-baseline the corpus under URB_NO_OCCLUSION=1 (homemaker-py-gp2).
|
|
|
|
|
|
|
|
|
|
Occlusion/daylight is disabled in Urb behind the URB_NO_OCCLUSION env flag
|
|
|
|
|
(daylight -> 1 everywhere, CIEsky illumination factor pinned to 1, i.e.
|
|
|
|
|
simple crinkliness). Flipping the flag changes every score, so this script
|
|
|
|
|
records the new baseline in one pass:
|
|
|
|
|
|
|
|
|
|
- per-file flag-on vs flag-off score and failure-set deltas (35 corpus files)
|
|
|
|
|
- batched oracle throughput under the flag
|
|
|
|
|
|
|
|
|
|
Run the inner-loop reference gains separately:
|
|
|
|
|
URB_NO_OCCLUSION=1 python3 experiments/accept_innerloop.py 400 cma
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import math
|
|
|
|
|
import os
|
|
|
|
|
import shutil
|
|
|
|
|
import sys
|
|
|
|
|
import tempfile
|
|
|
|
|
import time
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
2026-06-14 08:18:06 +01:00
|
|
|
from homemaker_layout import oracle # noqa: E402
|
Geometry inner loop: batched full-objective ratio optimiser (CMA-ES)
innerloop.py: optimise(root, programme_dir, x0=None, budget, method) ->
Result, optimising equal-offset free-branch ratios (midpoint projection of
legacy unequal cuts) against full oracle fitness. OracleEvaluator scores
each population in one batched perl call. Methods: cma (default) — multi-
start sigma ladder (0.05 local, 0.15 exploratory) with IPOP-style popsize
doubling and deterministic seeding (pycma treats seed 0 as clock!) — and
compass with Hooke-Jeeves pattern moves, kept for the d0s bake-off.
Acceptance (experiments/accept_innerloop.py, §4.5 bars vs unprojected
originals, within-noise tolerance 1%): x1.65 / x1.66 / x1.58 against bars
x1.24 / x1.67 / x1.59, no new failures, 46 oracle calls vs Nelder-Mead's
200. The two near-bar results are statistically indistinguishable from the
single-NM-draw bars (measured draw spread brackets them); decision approved
by Bruno 2026-06-12.
Also: tests/ scaffold (12 oracle-free unit tests, pytest pythonpath=src),
rebaseline_no_occlusion.py for homemaker-py-gp2, cma>=3.0 dependency
(installed via dnf), dead-variable cleanup in solver.py.
Closes homemaker-py-1p0.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 09:42:24 +01:00
|
|
|
|
|
|
|
|
URB = Path("/home/bruno/src/urb")
|
|
|
|
|
CORPUS = URB / "examples" / "programme-house"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def score_corpus(paths: list[Path], flag: bool) -> tuple[list[oracle.Score], float]:
|
|
|
|
|
os.environ.pop("URB_NO_OCCLUSION", None)
|
|
|
|
|
if flag:
|
|
|
|
|
os.environ["URB_NO_OCCLUSION"] = "1"
|
|
|
|
|
t0 = time.perf_counter()
|
|
|
|
|
scores = oracle.score_batch(paths, URB)
|
|
|
|
|
return scores, time.perf_counter() - t0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> int:
|
|
|
|
|
with tempfile.TemporaryDirectory(prefix="rebaseline_") as tmp:
|
|
|
|
|
scratch = Path(tmp)
|
|
|
|
|
shutil.copy(CORPUS / "patterns.config", scratch)
|
|
|
|
|
paths = [Path(shutil.copy(d, scratch)) for d in sorted(CORPUS.glob("*.dom"))]
|
|
|
|
|
|
|
|
|
|
off, t_off = score_corpus(paths, flag=False)
|
|
|
|
|
on, t_on = score_corpus(paths, flag=True)
|
|
|
|
|
|
|
|
|
|
n_changed_score = n_changed_fails = 0
|
|
|
|
|
print(f"{'file':42s} {'flag-off':>12s} {'flag-on':>12s} {'ratio':>7s} fails off->on")
|
|
|
|
|
for p, a, b in zip(paths, off, on):
|
|
|
|
|
score_changed = not math.isclose(a.fitness, b.fitness, rel_tol=1e-9)
|
|
|
|
|
fails_changed = a.fail_lines != b.fail_lines
|
|
|
|
|
n_changed_score += score_changed
|
|
|
|
|
n_changed_fails += fails_changed
|
|
|
|
|
ratio = b.fitness / a.fitness if a.fitness else float("inf")
|
|
|
|
|
mark = "*" if fails_changed else " "
|
|
|
|
|
print(f"{p.name:42s} {a.fitness:12.6g} {b.fitness:12.6g} {ratio:7.3f} "
|
|
|
|
|
f"{a.n_fails}->{b.n_fails}{mark}")
|
|
|
|
|
|
|
|
|
|
n = len(paths)
|
|
|
|
|
print(f"\nscore changed: {n_changed_score}/{n} failure set changed: {n_changed_fails}/{n}")
|
|
|
|
|
print(f"batched s/dom: flag-off {t_off / n:.3f}, flag-on {t_on / n:.3f} "
|
|
|
|
|
f"(x{t_off / t_on:.2f})")
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
sys.exit(main())
|