homemaker-layout/experiments/run_search.py
Bruno Postle 8e762b80d8 Phase-2 gate results: 2/3 seeds → REVIEW; fix patterns.config re-score bug
benchmark_vs_urbevolve.py results (2026-06-13, budget=2000, URB_NO_OCCLUSION=1):
- Seeded designs: memetic beats urb-evolve 1.91× (c964435) and 1.63× (2f45907)
- Blank slate init.dom: memetic at 18 fails vs urb-evolve at 6 fails (topology
  diversity gap from single-seed mutation chain vs random-population init)

Bug fixed: run_search.py was calling oracle.score on out.parent without
patterns.config present — causing the re-score to return near-zero instead of
the correct tracked fitness. Added shutil.copy to propagate patterns.config
alongside the output .dom before the standalone re-score.

Gate recorded in DESIGN.md §7. Closes homemaker-py-way.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-13 09:56:01 +01:00

61 lines
2.4 KiB
Python

#!/usr/bin/env python3
"""End-to-end memetic search on programme-house (homemaker-py-b39 acceptance).
Runs driver.search from a corpus seed within a stated oracle-evaluation
budget, logs every improvement, writes the best design to
scratch/search_best.dom and independently re-scores it through the oracle to
prove the output is a valid .dom whose recorded fitness is reproducible.
The interesting bar: the seed's geometry-only optimum (inner loop alone,
DESIGN §4.7 reference: c964435 -> 0.00674). Anything above that is value
added by *topology* search.
Run under the go-forward fitness:
URB_NO_OCCLUSION=1 python3 experiments/run_search.py [budget] [rng-seed] [seed.dom] [out.dom]
"""
from __future__ import annotations
import math
import shutil
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from homemaker import dom, driver, oracle # noqa: E402
URB = Path("/home/bruno/src/urb")
EX = URB / "examples" / "programme-house"
SEED_FILE = EX / "c964435454c459f86c3ed9a5a7621132.dom"
OUT = Path(__file__).resolve().parents[1] / "scratch" / "search_best.dom"
def main() -> int:
budget = int(sys.argv[1]) if len(sys.argv) > 1 else 2000
rng_seed = int(sys.argv[2]) if len(sys.argv) > 2 else 0
seed_file = Path(sys.argv[3]) if len(sys.argv) > 3 else SEED_FILE
out = Path(sys.argv[4]) if len(sys.argv) > 4 else OUT
print(f"seed={seed_file.name} budget={budget} oracle evals, rng seed {rng_seed}",
flush=True)
r = driver.search(dom.load(str(seed_file)), EX, budget=budget,
urb_root=URB, seed=rng_seed, log=lambda m: print(m, flush=True))
print(f"\ndone: {r.n_evals} oracle evals across {r.n_topologies} topologies")
print(f"best: {r.best.fitness:.6g} (fails {r.best.n_fails}) via {r.best.lineage}")
print("population: " + ", ".join(f"{p.fitness:.4g}/{p.n_fails}f" for p in r.population))
out.parent.mkdir(parents=True, exist_ok=True)
config_src = EX / "patterns.config"
if config_src.exists() and not (out.parent / "patterns.config").exists():
shutil.copy(config_src, out.parent)
dom.dump(r.best.root, str(out))
s = oracle.score(out, URB)
ok = math.isclose(s.fitness, r.best.fitness, rel_tol=1e-9)
print(f"\n{out} re-scored standalone: {s.fitness:.6g} ({s.n_fails} fails) "
f"-> {'MATCHES search record' if ok else 'MISMATCH'}")
return 0 if ok else 1
if __name__ == "__main__":
sys.exit(main())