homemaker-layout/experiments/run_search_scaled.py
Claude d0567d7a74
Remove the Perl oracle
Owner's decision: "we need to abandon the perl oracle, this was only useful
when initially porting, but I suspect many of the remaining problems have been
carried in from the perl (such as the weird scoring of outdoor and circulation
space, which definitely needs fixing)".

39 supports that second clause. Every defect the section found is inherited,
not introduced: the two-sided crinkliness gaussian that double-charges surplus
daylight (39.14), quality as a product over a variable number of factors
(39.18), value_supported priced as value_inside so a terrace was worth more per
m2 than a room (39.19), and circulation returning 0.07 per unit cost (hxi).

So parity with the oracle was never a safety net -- it was a commitment to
reproduce those defects. Each of 39.14, 39.18 and 39.19 would have been a
parity failure had parity ever been checked, and keeping the tests would have
meant reverting the fixes or explaining the failures away.

Removed: oracle.py, test_oracle.py, the two parity tests and their fixture
machinery in test_dom_corpus.py, innerloop.OracleEvaluator with its use_native
and urb_root plumbing, the same plumbing through driver, and fourteen
experiments/ scripts that could only run against Perl. Several of those are
cited in earlier DESIGN sections; the citations now point into git history,
which is the honest state -- they had been unrunnable since the oracle root
(/home/bruno/src/urb) stopped being present. run_search is superseded by
run_search_scaled, which does the same job natively.

Kept: dump_areas.pl/.py, which validate GEOMETRY against Urb (4.1) rather than
fitness, and the prose in fitness_cmd.py and dom.py explaining why the
.score/.fails formats are shaped as they are. Provenance is worth keeping; a
dead code path is not.

CLAUDE.md updated: fitness.py is the only evaluator, and "Urb did it this way"
is no longer an argument that a constant is right. 39.16 is the standing
counterweight in the other direction -- the crinkliness target WAS right and
twice looked wrong only because the code reading it was misunderstood.
Inheritance is neither evidence for nor against.

410 passed. The 69 removed cases account exactly: 64 parity (all skipped, since
no oracle .score was ever committed), 4 in test_oracle.py, and the guard test
39.20 added as a stopgap.

Closes homemaker-py-118. Files homemaker-py-bk9 for the re-baseline that 39.19
made necessary.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MJ84Feep79Hhm3E4zZJmnB
2026-09-06 07:56:24 +00:00

152 lines
5.9 KiB
Python

#!/usr/bin/env python3
"""Scaled topology search on native fitness (homemaker-py-ccw, Phase 3).
Runs driver.search at larger budget using the native Python fitness exclusively
— no Perl oracle, no wall-clock bottleneck from Perl startup.
This unlocks two things the Phase-2 oracle-bounded run could not do:
1. Larger evaluation budgets on programme-house (beat Phase-2 best).
2. Programmes too large for the oracle (e.g. harbor-house, 16 rooms).
Usage:
URB_NO_OCCLUSION=1 python3 experiments/run_search_scaled.py [programme_dir] [budget] [rng_seed] [seed.dom] [out.dom]
Defaults: programme-house, budget=20000, rng_seed=0, best corpus seed.
Phase-2 reference bars (URB_NO_OCCLUSION=1, budget=2000, native fitness):
c964435 seed → 7.65e-03 (2 fails) beats urb-evolve p128 4.00e-03
2f45907 seed → 2.13e-02 (2 fails) beats urb-evolve p128 1.30e-02
"""
from __future__ import annotations
import math
import os
import sys
import time
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from homemaker_layout import dom, driver, fitness, innerloop # noqa: E402
URB_EX = Path("/home/bruno/src/urb/examples")
PH_DIR = URB_EX / "programme-house"
PH_SEED = PH_DIR / "c964435454c459f86c3ed9a5a7621132.dom"
def _native_score(root: dom.Node, programme_dir: Path) -> tuple[float, int]:
"""Re-score a design with native fitness (no oracle dependency)."""
import copy
conf, cost = fitness.load_config(programme_dir)
fit = fitness.Fitness(conf, cost)
score, fails = fit.score_with_fails(copy.deepcopy(root))
return score, len(fails)
def main() -> int:
programme_dir = Path(sys.argv[1]) if len(sys.argv) > 1 else PH_DIR
budget = int(sys.argv[2]) if len(sys.argv) > 2 else 20000
rng_seed = int(sys.argv[3]) if len(sys.argv) > 3 else 0
seed_file = Path(sys.argv[4]) if len(sys.argv) > 4 else None
out = Path(sys.argv[5]) if len(sys.argv) > 5 else (
Path(__file__).resolve().parents[1] / "scratch" / "scaled_best.dom"
)
if seed_file is None:
# pick the default seed for known programmes, else fall back to init.dom
if programme_dir.name == "programme-house":
seed_file = PH_SEED
else:
seed_file = programme_dir / "init.dom"
if not seed_file.exists():
candidates = sorted(programme_dir.glob("*.dom"))
seed_file = candidates[0] if candidates else None
if seed_file is None:
print(f"ERROR: no .dom seed found in {programme_dir}", file=sys.stderr)
return 1
use_grade = os.environ.get("USE_GRADE") == "1" # §11.4 graded objective A/B
# §11.5 structural niching + restarts A/B. NICHE=0 falls back to the legacy
# fitness-scalar dedup (the "before"); RESTART_PATIENCE=<evals> enables soft
# restarts (default off).
niche = os.environ.get("NICHE", "0") == "1"
# 6zy: tournament size (selection pressure), default k=2 (legacy binary).
tournament_k = int(os.environ.get("HOMEMAKER_TOURNAMENT_K", "2"))
rp = os.environ.get("RESTART_PATIENCE")
restart_patience = int(rp) if rp else None
adj = os.environ.get("ADJ", "1") == "1" # s44 adjacency-aware seeding
prop = os.environ.get("PROP", "1") == "1" # leu.2 proportion-aware split sizing (default-on)
print(f"programme : {programme_dir.name}")
print(f"seed : {seed_file.name}")
print(f"budget : {budget} native evals")
print(f"rng seed : {rng_seed}")
print(f"use_grade : {use_grade}")
print(f"niche : {niche}")
print(f"tourn_k : {tournament_k}")
print(f"restart_p : {restart_patience}")
print(f"adj_aware : {adj}")
print(f"prop_aware: {prop}")
print(flush=True)
seed_root = dom.load(str(seed_file))
t0 = time.perf_counter()
r = driver.search(
seed_root,
programme_dir,
budget=budget,
pop_size=16, # up from 8 — more diversity at scale
child_budget=80,
seed_budget=300, # up from 200 — thorough seed optimisation
p_crossover=0.2,
seed=rng_seed,
log=lambda m: print(m, flush=True),
use_grade=use_grade,
tournament_k=tournament_k,
niche_by_signature=niche,
restart_patience=restart_patience,
seed_adjacency_aware=adj,
seed_proportion_aware=prop,
)
elapsed = time.perf_counter() - t0
evals_per_sec = r.n_evals / elapsed
print(f"\n--- done ---")
print(f"elapsed : {elapsed:.1f}s ({evals_per_sec:.1f} evals/s)")
print(f"evals : {r.n_evals} across {r.n_topologies} topologies")
print(f"best : {r.best.fitness:.6g} ({r.best.n_fails} fails) via {r.best.lineage}")
print("population: " + ", ".join(
f"{p.fitness:.4g}/{p.n_fails}f" for p in r.population
))
# §11.5 diversity: distinct topology signatures seen, current population
# structural spread, and restart count.
pop_distinct = len({p.sig for p in r.population})
print(f"diversity : {r.n_distinct_signatures} distinct topologies seen, "
f"{pop_distinct}/{len(r.population)} distinct in final population, "
f"{r.n_restarts} restarts")
if r.diversity_history:
print("pop-distinct over time (evals, pop_distinct, cumulative): "
+ ", ".join(f"({e},{d},{c})" for e, d, c in r.diversity_history))
if r.history:
print("\nimprovement history:")
for ev, fit_val, lin in r.history:
print(f" [{ev:6d}] {fit_val:.6g} ({lin})")
out.parent.mkdir(parents=True, exist_ok=True)
dom.dump(r.best.root, str(out))
# native re-score as ground truth (oracle retired in Phase 3)
rs, rf = _native_score(r.best.root, programme_dir)
ok = math.isclose(rs, r.best.fitness, rel_tol=1e-9)
print(f"\n{out.name} re-scored (native): {rs:.6g} ({rf} fails) "
f"{'OK' if ok else 'MISMATCH'}")
return 0 if ok else 1
if __name__ == "__main__":
sys.exit(main())