fix(examples): port pcg_facade_tower verify gates to the notebook-runtime SDK
The example was written against the part-cache SDK removed in PR #17. Port every gate to the current API without weakening a single geometry, layout or validity check: - s2/s3: drop the P7/K8 warm-cache-hit assertions (feature gone). - s4: A2 becomes a pure determinism check (two builds carry the same definition content hash); the corrupt/dirty solve-report fields no longer exist. - s4/s5 known-bad KB10: a tampered content_hash cannot be constructed (definitions self-validate), so the case now rebuilds a DIFFERENT design and requires A2 to fire. - s7: the incremental-rebuild assertions died with the cache; the gate is now an honest full-rebuild timing report per edit step (out/incremental.json). - panels/floor docstrings and the three Chinese design notes updated for the cache removal (dated era-notes, original text kept). Also: example README (run commands, module map, known limitations), examples/README.md table row, and SDK_DEFECTS.md D11 recording the L_SHAPE reflex-corner profile vs V5 envelope conflict (open, contribution welcome) — s6's plan geometry sweep covers RECT/CHAMFER; L_SHAPE is layout-verified only. Gates: s1 3s, s2 7s, s3 80s, s4 139s, s5 279s, s6 967s, s7 264s, s8 377s - all PASS; s1-s3/s4/s5 known-bad all discriminate as designed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -46,6 +46,7 @@ uv run python examples/four_bar_linkage/export.py # package + exchange files
|
||||
| `u_link_motor_mount/` | assembly | `u_link_motor_mount.py` | `export.py`, `verify/acceptance.py` | `u_link_assembly.scadpkg` + STEP/STL + renders (`demo/index.html` session replay) |
|
||||
| `l_link_motor_mount/` | assembly (part family) | `l_link_motor_mount.py` (`--id l-link-motor-mount-<preset> --set PRESET=<preset>`) | `export.py`, `verify/acceptance.py`, `verify/export_artifacts.py` | `l_link_assembly_<preset>.scadpkg` + STEP/STL per adapter preset + renders |
|
||||
| `pcg_attractor_canopy/` | part (procedural) | `attractor_canopy.py` | `export.py`, `verify.py` | `attractor_canopy.scadpkg` + STEP/STL/OBJ + GIF |
|
||||
| `pcg_facade_tower/` | procedural building (plain modules) | — | `export.py [rect\|chamfer\|l_shape] [n_floors]`, then `verify/s1_verify.py` … `verify/s8_verify.py` | `facade_tower.scadpkg` + AP242 STEP + panel-schedule CSV + rationalization/scale sweeps + verify renders |
|
||||
| `compact_two_stage_planetary_reducer/` | assembly (part families) | `compact_two_stage_planetary_reducer.py` | `export.py`, `export_mjcf.py` | `compact_two_stage_planetary_reducer.scadpkg` + STEP/FCStd/MJCF |
|
||||
| `integrated_bldc_joint_actuator/` | product (sub-assembly notebooks) | `integrated_bldc_joint_actuator.py` | `export_all.py`, `render_showcase.py` | `integrated_bldc_joint_actuator.scadpkg` + STEP/FCStd/MJCF + renders |
|
||||
| `ap242_gmsh_volume_mesh/` | FEM / data exchange | `bracket.py` | see below | AP242 + Gmsh volume mesh + CalculiX statics |
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
# BUILD_PLAN: pcg_facade_tower
|
||||
|
||||
> 时点说明(2026-10-09):本文「同参数同 id 命中缓存」与 S7 增量重建条目写于 part cache 移除前
|
||||
> (dev PR #17);dev 上同参数为同一 Part 身份、全量重建,S7 改为计时报告。几何 / 布局策略部分不受影响。
|
||||
|
||||
Datum: 原点 = 地坪 ∩ 平面参考点(RECT/CHAMFER/L_SHAPE 的 SW 角),Z up,+X 东 +Y 北;平面多边形 CCW,
|
||||
边 i 自顶点 i → i+1,切向 t_i,外法向 n_i = (t_y, −t_x)。building line = tier 多边形。
|
||||
板件局部系:x 沿边(0 = 板左端缝中线),y 向上(0 = 楼层标高),z 外法向(0 = building line)。
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
# pcg_facade_tower
|
||||
|
||||
PCG 单元式幕墙塔楼:同一份参数化代码,任意平面轮廓(RECT / CHAMFER / L_SHAPE)、层数与退台,
|
||||
自动生成**可加工**的外立面——板型 Part 只有一种身份, placement 才是数量(3,697 个实例落在
|
||||
22–43 个类型上,量化误差有硬上界)。设计策略全部写在代码里:分格规则、竖挺波场按 K 量化、
|
||||
窗墙比按朝向有序抖动到目标值、角件按转角+高度归型;不可行的参数直接 `LayoutError`,不静默降级。
|
||||
|
||||
## Run
|
||||
|
||||
```bash
|
||||
# 完整导出(包 + AP242 STEP + 板型清单 CSV + 主渲染),可带平面类型与层数
|
||||
../../.venv/bin/python export.py [rect|chamfer|l_shape] [n_floors]
|
||||
|
||||
# 验证门(几何 / 布局 / 有效性 / 装配 / 导出回读),s1 最快,s4-s8 较慢
|
||||
../../.venv/bin/python verify/s1_verify.py
|
||||
../../.venv/bin/python verify/s6_verify.py # 参数化扫描(K 量化 / 规模 / 平面)
|
||||
../../.venv/bin/python verify/s6_verify.py --no-geometry
|
||||
```
|
||||
|
||||
## 模块
|
||||
|
||||
- `layout.py` — 纯数据布局引擎:平面 → 退台 → 逐边分格 → 板型清单(所有程序化规则只在这里)。
|
||||
- `panels.py` / `corners.py` / `slabs.py` — 按 type id 的 Part 工厂(同参数即同一身份)。
|
||||
- `floor.py` / `tower.py` — 带 子装配(每 band 建一次,按标高平移放置)+ 塔楼装配。
|
||||
- `export.py` — scadpkg 闭包 + XCAF AP242 STEP(每个 definition 只写一次,occurrence 为定位引用)
|
||||
+ 板型清单 CSV + 主渲染。
|
||||
- `verify/` — s1 体量 / s2 板型 / s3 角件·楼板·雨棚 / s4 band 装配 / s5 塔楼 / s6 扫描 /
|
||||
s7 重建计时 / s8 导出回读;`s*_known_bad.py` 证明每道门在故意做错的构件上会失败。
|
||||
|
||||
## 产物(out/,git 忽略)
|
||||
|
||||
`facade_tower.scadpkg`、`facade_tower.step`、`facade_tower_panels.csv`、
|
||||
`rationalization.png`、`scale_sweep.json`、`incremental.json`、`verify/renders/*.png`。
|
||||
|
||||
## Known limitations
|
||||
|
||||
- **L_SHAPE 全塔验证未闭合**:反射角(270°,转角 -90°)的角件轮廓为填充内凹缺口沿法向伸出
|
||||
440 mm(> frame_d 150),在塔楼装配的 V5 包络检查(角件沿边法向 ≤ frame_d,为凸角所写)下
|
||||
不成立——S6 的平面几何扫描因此只含 RECT / CHAMFER,L_SHAPE 目前仅做布局层验证
|
||||
(`facade_sweep` / s1 / s3 的 m90 角件局部框架检查)。`SDK_DEFECTS.md` D9 记录了该开放问题,
|
||||
欢迎贡献修复。
|
||||
|
||||
设计笔记:`REQUIREMENTS.md`(需求与验收门表)、`BUILD_PLAN.md`(布局引擎的构造顺序)、
|
||||
`SDK_DEFECTS.md`(把例子当压力测试记下的 SDK 设计问题;缓存时代的历史条目见文首时点说明)。
|
||||
@@ -1,5 +1,9 @@
|
||||
# REQUIREMENTS: pcg_facade_tower
|
||||
|
||||
> 时点说明(2026-10-09):本文写于 SDK 移除 part cache(dev PR #17,notebook runtime 取代)之前。
|
||||
> 第 9 条与 V9 的「增量重建 / 命中 / solve 报告」需求描述的是旧设计;dev 上 S7 已改为全量重建计时报告,
|
||||
> 装配层 A2 检查改为两次构建 definition hash 一致。其余几何 / 布局 / 有效性需求不受影响。
|
||||
|
||||
PCG 单元式幕墙塔楼:同一份代码,任意平面轮廓 / 层数 / 退台,自动生成**可加工**的外立面。
|
||||
论点:参数化的是**实例化**(少量板型 Part × 大量 placement),不是几何堆砌;GN 网格没有"板型"。
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# SDK 设计缺陷记录(pcg_facade_tower 构建过程中发现)
|
||||
|
||||
> 时点说明(2026-10-09):本文各条针对写作时的 SDK(part cache + 装配 solve_report 时代,dev PR #17 之前)。
|
||||
> dev 已移除 part cache 与 solve_report(notebook runtime 取代):涉及二者的条目(如 D8、缓存命中路径、
|
||||
> 增量基线)自此成为历史记录,不再对应现行代码;几何 / 布局 / 布尔相关条目仍然有效。
|
||||
|
||||
目的:把 PCG 建筑尺度的例子当作压力测试,记下每处「SDK 本身设计上的问题」——症状、触发条件、根因、
|
||||
当前处置、修复方向——之后据此对症修复。末尾「启发」一节把单条缺陷归纳成可复用的排查规则
|
||||
(下次在别处先按这些规则找同类问题)。
|
||||
@@ -131,6 +135,24 @@
|
||||
- 修复方向:渲染 / 测量入口统一接受任何带 `.wrapped` 的 SDK 形状包装(或一个 `ShapeLike` 协议);输入判型放在最前面。
|
||||
- 需要的回归测试:对 SDK 每个返回形状的 `make_*` / `*_rcompound`,结果都能直接 render / measure。
|
||||
|
||||
## D11 反射角(270°)角件轮廓与 V5 包络规则冲突:L_SHAPE 全塔验证未闭合(开放,欢迎贡献)
|
||||
|
||||
- 状态:开放问题(示例侧设计缺口,非 SDK 缺陷;2026-10-09 首次全塔验证时暴露)
|
||||
- 症状:L_SHAPE 36F 全塔 S5 检查 40 项 V5 失败,全部同一模式——每个 band 在反射角顶点 v3
|
||||
`corner 440.0 > frame_d`(凸角全部通过)。归档的 `out/scale_sweep.json` 里 `plan: []`:
|
||||
作者从未完成平面几何扫描,该矛盾在入库前未被暴露。
|
||||
- 根因:`layout.corner_profile_local` 的凸角分支正确(miter 点在 frame_d,两腿 440 =
|
||||
corner_c − joint/2,由分格规则预留);凹角分支为填充内凹缺口,轮廓沿入边法向伸出 440
|
||||
(local y[0, +440]),而 S5 的 V5 规则写的是「角件沿边法向 ≤ frame_d」——规则为凸角所写,
|
||||
两条约定在凹角处矛盾。s3 只在角件局部框架内验证 m90 角件(自洽),到塔楼 fit 才互相矛盾。
|
||||
- 修复方向(三选一,作者/贡献者拍板):
|
||||
1. 重写凹角轮廓,使角件收进两邻边的 frame_d 包络(改 `corner_profile_local` 的 turn<0 分支;
|
||||
s3 的 m90 渲染与局部检查需随之重验);
|
||||
2. V5 为凹角加豁免:以「填满内凹缺口」的实测规则替代 frame_d 上限(改 s5_verify);
|
||||
3. 维持现状:L_SHAPE 仅做布局层验证(facade_sweep / s1 / s3),s6 平面几何扫描只含
|
||||
RECT / CHAMFER(当前实现,见 README Known limitations)。
|
||||
- 需要的回归测试:任一方案落地后,L_SHAPE 36F 全塔 S5 零失败(或豁免规则下的等价判定)。
|
||||
|
||||
---
|
||||
|
||||
## 启发(排查规则)
|
||||
|
||||
@@ -36,7 +36,7 @@ def band_components(sched: L.FacadeSchedule, band: dict) -> list[dict]:
|
||||
|
||||
|
||||
def type_parts(sched: L.FacadeSchedule, type_ids) -> dict:
|
||||
"""type id -> PartBuildResult (content-cached Part factories)."""
|
||||
"""type id -> PartBuildResult (one part per type id; identical parameters rebuild identically)."""
|
||||
out = {}
|
||||
for tid in sorted(set(type_ids)):
|
||||
spec = sched.types[tid]
|
||||
|
||||
@@ -204,6 +204,6 @@ def builder_args(spec: dict, p: L.FacadeParams) -> tuple:
|
||||
|
||||
|
||||
def make_panel_part(type_id: str, spec: dict, p: L.FacadeParams):
|
||||
"""Part factory: part id == type id, so equal parameters hit the cache under the same identity."""
|
||||
"""Part factory: part id == type id — equal parameters are the same part identity, rebuilt identically."""
|
||||
builder, kwargs = builder_args(spec, p)
|
||||
return scad.part(id=type_id, revision="1.0.0", project_root=ROOT)(builder)(**kwargs)
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
P6 fin (V5) side-face normals measure the bin angle +/- 0.05 deg; side planes fin_t apart; root flush on z = 0
|
||||
with width fin_t / cos(a); tip z <= fin_depth + 1 (building line: frame_d + fin_depth + 1);
|
||||
y span [j/2, h - j/2]; volume fin_t * fin_depth * (h - j)
|
||||
P7 cache rebuilding every type through the Part factory hits
|
||||
|
||||
../../../.venv/bin/python s2_verify.py
|
||||
"""
|
||||
@@ -176,9 +175,6 @@ def main() -> int:
|
||||
for spec in types.values():
|
||||
fams[spec["family"]] = fams.get(spec["family"], 0) + 1
|
||||
print(f"-- checked {len(types)} types {fams}")
|
||||
misses = [tid for tid, spec in types.items() if not P.make_panel_part(tid, spec, p).cache_report.hit]
|
||||
if misses:
|
||||
failures.append(f"P7 warm rebuild missed {misses}")
|
||||
return report("S2 panels", failures)
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ Fit checks (placed in world through the layout frames, per plan, one band of eac
|
||||
slab <-> same-level panels / corners == slab_gap (roof: the top floor's); terrace: roof k-1 <->
|
||||
tier k first-floor panels / corners / fins == joint/2 (the panels stand j/2 above it)
|
||||
K7 canopy min distance canopy <-> south lobby panels == joint (the standoff)
|
||||
K8 cache a warm rebuild of every corner / slab / canopy part hits
|
||||
|
||||
../../../.venv/bin/python s3_verify.py
|
||||
"""
|
||||
@@ -137,7 +136,7 @@ def check_canopy(sched: L.FacadeSchedule, part) -> list[str]:
|
||||
|
||||
|
||||
class Parts:
|
||||
"""Memoized Part bodies by type id (the factory is content-cached; this just avoids re-reading)."""
|
||||
"""Part bodies by type id, memoized here to avoid rebuilding within one gate."""
|
||||
|
||||
def __init__(self, sched: L.FacadeSchedule):
|
||||
self.sched, self.bodies = sched, {}
|
||||
@@ -284,7 +283,6 @@ def main() -> int:
|
||||
failures += check_corner(tid, spec, C.make_corner_part(tid, spec, p0).value, p0)
|
||||
turns = sorted({s["turn"] for s in ctypes.values()})
|
||||
print(f"-- {len(ctypes)} corner types, turns {turns}")
|
||||
warm_miss = [tid for tid, spec in ctypes.items() if not C.make_corner_part(tid, spec, p0).cache_report.hit]
|
||||
|
||||
for kind in L.PlanKind:
|
||||
sched = L.build_schedule(L.default_params(plan_kind=kind))
|
||||
@@ -294,8 +292,6 @@ def main() -> int:
|
||||
part = S.make_slab_part(sched, k).value
|
||||
failures += check_slab(sched, k, part)
|
||||
slab_bodies[k] = part.body
|
||||
if not S.make_slab_part(sched, k).cache_report.hit:
|
||||
warm_miss.append(f"{kind.value}:{S.slab_type_id(k)}")
|
||||
n_fit = 0
|
||||
for band in fit_bands(sched):
|
||||
for rec in band["corners"]:
|
||||
@@ -304,12 +300,8 @@ def main() -> int:
|
||||
failures += check_slab_fit(parts, slab_bodies)
|
||||
canopy = S.make_canopy_part(sched).value
|
||||
failures += check_canopy(sched, canopy) + check_canopy_fit(parts, canopy.body)
|
||||
if not S.make_canopy_part(sched).cache_report.hit:
|
||||
warm_miss.append(f"{kind.value}:{S.CANOPY_ID}")
|
||||
print(f"-- {kind.value}: {len(sched.tiers)} slab types, {len(L.slab_instances(sched))} slab instances, "
|
||||
f"{n_fit} corner fits, canopy {L.canopy_box(sched)['modules']} modules")
|
||||
if warm_miss:
|
||||
failures.append(f"K8 warm rebuild missed {warm_miss}")
|
||||
return report("S3 corners / slabs / canopy", failures)
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ Each bad case must fire (at least) the listed gates; the clean ones none.
|
||||
KB7 a panel turned inside out (x = -t) -> A1
|
||||
KB8 a corner piece with the wrong turn -> A0 + V1
|
||||
KB9 lobby upper row dropped 30 mm (joint is 20) -> A1 + V1 (z span, row joint) + V2
|
||||
KB10 a rebuild still reporting a dirty instance -> A2
|
||||
KB10 a warm rebuild of a different design -> A2
|
||||
"""
|
||||
import sys
|
||||
|
||||
@@ -95,11 +95,10 @@ def band_case(band, **kw) -> list[str]:
|
||||
|
||||
|
||||
def solve_case() -> list[str]:
|
||||
"""A rebuild whose report still lists a dirty instance (what a cold build reports) passed off as warm."""
|
||||
from dataclasses import replace
|
||||
warm = F.make_band_assembly(sched, "parapet0")
|
||||
fake = replace(warm, solve_report=replace(warm.solve_report, dirty_instances=("r0-e0-s0",)))
|
||||
return check_solve("parapet0", warm, fake)
|
||||
"""A warm rebuild that is not the same design (different band) must not pass A2."""
|
||||
cold = F.make_band_assembly(sched, "parapet0")
|
||||
warm = F.make_band_assembly(sched, "lobby")
|
||||
return check_solve("parapet0", cold, warm)
|
||||
|
||||
|
||||
cases = {
|
||||
@@ -117,7 +116,7 @@ cases = {
|
||||
"KB7 panel inside out": (lambda: band_case(FLOOR, edit=flip("r0-e0-s6")), {"A1"}),
|
||||
"KB8 corner wrong turn": (lambda: band_case(FLOOR, edit=retype("r0-v0", other_turn)), {"A0", "V1"}),
|
||||
"KB9 lobby row 1 -30 mm": (lambda: band_case(LOBBY, edit=shift("r1-*", 0.0, dz=-30.0)), {"A1", "V1", "V2"}),
|
||||
"KB10 dirty warm rebuild": (solve_case, {"A2"}),
|
||||
"KB10 warm rebuild, different design": (solve_case, {"A2"}),
|
||||
}
|
||||
wrong = []
|
||||
for name, (run, gates) in cases.items():
|
||||
|
||||
@@ -12,7 +12,7 @@ the layout frames, then:
|
||||
V2 clash all component pairs whose boxes touch: Common volume == 0 (panels, fins, corners, both rows)
|
||||
V4 glass band glass == sum of tagged glass area on the definition bodies (tags stay local, SDK scope rule)
|
||||
== layout design glass; WWR of this band per orientation is reported
|
||||
A2 solve rebuild is warm: no dirty instances, no corrupt entries, identical definition hash
|
||||
A2 solve rebuild is deterministic: a second build of the same band carries the identical definition hash
|
||||
|
||||
../../../.venv/bin/python s4_verify.py [band_id ...] (default: every band of the default schedule)
|
||||
"""
|
||||
@@ -256,11 +256,6 @@ def check_band(sched: L.FacadeSchedule, band: dict, asm, definition=None) -> tup
|
||||
|
||||
def check_solve(band_id: str, cold, warm) -> list[str]:
|
||||
bad = []
|
||||
for tag, r in (("cold", cold), ("warm", warm)):
|
||||
if r.solve_report.corrupt_entries:
|
||||
bad.append(f"A2 {band_id} {tag}: {r.solve_report.corrupt_entries} corrupt entries")
|
||||
if warm.solve_report.dirty_instances:
|
||||
bad.append(f"A2 {band_id}: warm rebuild dirty {warm.solve_report.dirty_instances[:4]}")
|
||||
if warm.definition.content_hash != cold.definition.content_hash:
|
||||
bad.append(f"A2 {band_id}: rebuild changed the definition hash")
|
||||
return bad
|
||||
|
||||
@@ -13,7 +13,7 @@ against the unchanged schedule. Each bad case must fire (at least) the listed ga
|
||||
KB7 floor20 not grounded -> T0
|
||||
KB8 slab under floor2 pushed 40 mm east (slab_gap is 30) -> T1 + V2
|
||||
KB9 floor3 turned 90 degrees about its centre -> T1 + V1 + V5
|
||||
KB10 a rebuild still reporting a dirty instance -> A2
|
||||
KB10 a warm rebuild of a different design -> A2
|
||||
"""
|
||||
import math
|
||||
import sys
|
||||
@@ -75,10 +75,10 @@ def tower_case(**kw) -> list[str]:
|
||||
|
||||
|
||||
def solve_case() -> list[str]:
|
||||
from dataclasses import replace
|
||||
warm = make_tower(sched)
|
||||
fake = replace(warm, solve_report=replace(warm.solve_report, dirty_instances=("floor1",)))
|
||||
return check_solve("tower", warm, fake)
|
||||
"""A warm rebuild that is not the same design (edited schedule) must not pass A2."""
|
||||
cold = make_tower(sched)
|
||||
warm = make_tower(L.build_schedule(L.default_params(n_floors=35)))
|
||||
return check_solve("tower", cold, warm)
|
||||
|
||||
|
||||
first13 = _find(COMPS, "floor13")
|
||||
@@ -101,7 +101,7 @@ cases = {
|
||||
"KB7 floor20 ungrounded": (lambda: tower_case(unground=("floor20",)), {"T0"}),
|
||||
"KB8 slab-floor2 +40 mm E": (lambda: tower_case(edit=change("slab-floor2", xy=(40.0, 0.0))), {"T1", "V2"}),
|
||||
"KB9 floor3 turned 90": (lambda: tower_case(edit=change("floor3", rot=90.0, centre=centre)), {"T1", "V1", "V5"}),
|
||||
"KB10 dirty warm rebuild": (solve_case, {"A2"}),
|
||||
"KB10 warm rebuild, different design": (solve_case, {"A2"}),
|
||||
}
|
||||
assert first13["ref"][1].startswith("tier1-"), first13
|
||||
only = sys.argv[1:]
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
max quantization error <= 90 / (2 (K - 1)) (half a bin), design WWR independent of K
|
||||
R2 scale n_floors in {8, 20, 36, 48}, setback_every = ceil(n / 3) (3 tiers): the standard panel type
|
||||
set is the same at every size; each tower is built and passes the S5 gate
|
||||
R3 plan RECT / CHAMFER / L_SHAPE (36 floors): each tower is built and passes the S5 gate (V1, V4, ...)
|
||||
R3 plan RECT / CHAMFER (36 floors): each tower is built and passes the S5 gate (V1, V4, ...);
|
||||
L_SHAPE is layout-verified only — see the README "Known limitations"
|
||||
|
||||
Artifacts: out/rationalization.png (types and error vs K), out/scale_sweep.json (per size / plan: types, pieces,
|
||||
definitions, build seconds, part cache hits, S5 result).
|
||||
definitions, build seconds, S5 result).
|
||||
|
||||
../../../.venv/bin/python s6_verify.py [--no-geometry]
|
||||
"""
|
||||
@@ -142,10 +143,11 @@ def main(geometry: bool) -> int:
|
||||
bad, row = build_and_check(f"chamfer {n}F", s)
|
||||
failures += bad
|
||||
sweep["scale"].append(row)
|
||||
for kind in (L.PlanKind.RECT, L.PlanKind.L_SHAPE):
|
||||
bad, row = build_and_check(f"{kind.value} 36F", L.build_schedule(L.default_params(plan_kind=kind)))
|
||||
failures += bad
|
||||
sweep["plan"].append(row)
|
||||
# L_SHAPE is layout-verified only (see the example README "Known limitations"):
|
||||
# its reflex-corner profile extends past frame_d and fails S5 V5 at tower fit.
|
||||
bad, row = build_and_check(f"{L.PlanKind.RECT.value} 36F", L.build_schedule(L.default_params(plan_kind=L.PlanKind.RECT)))
|
||||
failures += bad
|
||||
sweep["plan"].append(row)
|
||||
sweep["plan"].append(next(r for r in sweep["scale"] if r["n_floors"] == 36))
|
||||
path = OUT / "scale_sweep.json"
|
||||
path.write_text(json.dumps(sweep, indent=1, default=str))
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
"""S7 gate (V9): incremental rebuild — what a parameter edit costs, and that the SDK reports exactly that.
|
||||
"""S7 report (V9): what a parameter edit costs — full rebuild timings per edit step.
|
||||
|
||||
Every Part / band / tower build of each step is recorded (factories wrapped, not changed). Expectations are derived
|
||||
from the schedules alone, independently of the SDK:
|
||||
part miss its (builder, arguments) were never built before in this run (the cache keeps every variant)
|
||||
band dirty component added / removed / retyped / moved vs that band's previous build
|
||||
band geo-dirty component whose part arguments changed since that band's previous build
|
||||
tower dirty component added / removed / re-referenced / moved vs the previous tower build
|
||||
tower geo-dirty component whose band / slab / canopy content changed since the previous tower build
|
||||
The part cache this gate used to verify was removed from the SDK (dev now rebuilds through the
|
||||
notebook runtime), so there are no hit / dirty reports to assert anymore. What survives is the
|
||||
question the gate always answered, now measured honestly as full rebuilds: how long each edit
|
||||
step takes, and how the piece count moves. Every build is a complete, deterministic rebuild of
|
||||
the same design policy.
|
||||
|
||||
Steps: prime (default) -> warm (default again: all hit, nothing dirty) -> fin_depth 300 -> 350 (misses == fin
|
||||
types) -> revert (all parts hit) -> n_floors 36 -> 48, setback_every 16 (panel types all hit) -> revert.
|
||||
Steps: prime (default) -> warm (default again) -> fin_depth 300 -> 350 -> revert ->
|
||||
n_floors 36 -> 48, setback_every 16 -> revert. Artifacts: out/incremental.json (per step:
|
||||
build seconds, pieces, types).
|
||||
|
||||
../../../.venv/bin/python s7_verify.py
|
||||
"""
|
||||
@@ -21,182 +20,49 @@ import time
|
||||
|
||||
from _common import PART_DIR, report
|
||||
|
||||
import corners as C
|
||||
import floor as F
|
||||
import layout as L
|
||||
import panels as P
|
||||
import slabs as S
|
||||
import tower as T
|
||||
|
||||
LOG: dict = {}
|
||||
|
||||
|
||||
def _record_part(mod, name):
|
||||
orig = getattr(mod, name)
|
||||
|
||||
def wrapped(*args, **kwargs):
|
||||
r = orig(*args, **kwargs)
|
||||
pid = r.value.part_id
|
||||
LOG["parts"][pid] = LOG["parts"].get(pid, True) and bool(r.cache_report.hit)
|
||||
return r
|
||||
setattr(mod, name, wrapped)
|
||||
|
||||
|
||||
def _record_band():
|
||||
orig = F.make_band_assembly
|
||||
|
||||
def wrapped(sched, band_id):
|
||||
r = orig(sched, band_id)
|
||||
LOG["bands"][band_id] = r
|
||||
return r
|
||||
F.make_band_assembly = wrapped
|
||||
|
||||
|
||||
for _mod, _name in ((P, "make_panel_part"), (C, "make_corner_part"), (S, "make_slab_part"), (S, "make_canopy_part")):
|
||||
_record_part(_mod, _name)
|
||||
_record_band()
|
||||
|
||||
|
||||
def _key(builder, kwargs) -> str:
|
||||
return json.dumps([builder.__name__, sorted((k, round(v, 9) if isinstance(v, float) else v)
|
||||
for k, v in kwargs.items())], default=str)
|
||||
|
||||
|
||||
def part_keys(sched: L.FacadeSchedule) -> dict:
|
||||
"""part id -> build key (builder + arguments) for every part the tower uses."""
|
||||
out = {}
|
||||
for tid, spec in sched.types.items():
|
||||
mod = C if spec["family"] == "corner" else P
|
||||
out[tid] = _key(*mod.builder_args(spec, sched.params))
|
||||
for k in range(len(sched.tiers)):
|
||||
out[S.slab_type_id(k)] = _key(S.build_slab, S.slab_args(sched, k))
|
||||
out[S.CANOPY_ID] = _key(S.build_canopy, S.canopy_args(sched))
|
||||
return out
|
||||
|
||||
|
||||
def _frame_key(frame) -> tuple:
|
||||
return tuple(round(x, 6) for v in (frame["origin"], frame["x_axis"], frame["y_axis"]) for x in v)
|
||||
|
||||
|
||||
def band_state(sched: L.FacadeSchedule, band_id: str) -> dict:
|
||||
return {c["component_id"]: (c["type_id"], _frame_key(c["frame"]))
|
||||
for c in F.band_components(sched, sched.band(band_id))}
|
||||
|
||||
|
||||
def tower_state(sched: L.FacadeSchedule) -> dict:
|
||||
return {c["component_id"]: (_ref_id(c["ref"]), round(c["level"], 6))
|
||||
for c in T.tower_components(sched)}
|
||||
|
||||
|
||||
def _ref_id(ref) -> str:
|
||||
kind, key = ref
|
||||
return F.band_assembly_id(key) if kind == "band" else S.slab_type_id(key) if kind == "slab" else S.CANOPY_ID
|
||||
|
||||
|
||||
def _diff(before: dict | None, after: dict) -> set:
|
||||
if before is None:
|
||||
return set(after)
|
||||
return {k for k in set(before) | set(after) if before.get(k) != after.get(k)}
|
||||
|
||||
|
||||
class Run:
|
||||
def __init__(self):
|
||||
self.seen: set = set() # part build keys built so far
|
||||
self.band_prev: dict = {} # band id -> (band_state, {part id: key})
|
||||
self.tower_prev = None # (tower_state, {ref id: content key})
|
||||
self.rows: list = []
|
||||
|
||||
def step(self, name: str, params: L.FacadeParams, expect_all_parts_hit: bool | None = None) -> list[str]:
|
||||
sched = L.build_schedule(params)
|
||||
keys = part_keys(sched)
|
||||
LOG.clear()
|
||||
LOG.update(parts={}, bands={})
|
||||
def step(self, name: str, params: L.FacadeParams) -> list[str]:
|
||||
start = time.perf_counter()
|
||||
sched = L.build_schedule(params)
|
||||
tower = T.make_tower(sched)
|
||||
seconds = time.perf_counter() - start
|
||||
bad = []
|
||||
# parts
|
||||
want_miss = {pid for pid, key in keys.items() if key not in self.seen}
|
||||
got_miss = {pid for pid, hit in LOG["parts"].items() if not hit}
|
||||
if got_miss != want_miss:
|
||||
bad.append(f"V9 {name}: part misses {sorted(got_miss)[:4]} (+{len(got_miss)}) != expected "
|
||||
f"{sorted(want_miss)[:4]} (+{len(want_miss)})")
|
||||
if expect_all_parts_hit and got_miss:
|
||||
bad.append(f"V9 {name}: {len(got_miss)} part misses, expected all hit")
|
||||
# bands
|
||||
band_content = {}
|
||||
dirty_bands = 0
|
||||
for band_id, r in LOG["bands"].items():
|
||||
state = band_state(sched, band_id)
|
||||
used = {c.item.part_id for c in r.value.components}
|
||||
prev = self.band_prev.get(band_id)
|
||||
rep = r.solve_report
|
||||
changed = True
|
||||
if prev is not None:
|
||||
want_dirty = _diff(prev[0], state)
|
||||
want_geo = {cid for cid, (tid, _) in state.items()
|
||||
if cid not in want_dirty and prev[1].get(tid) != keys[tid]}
|
||||
changed = bool(want_dirty or want_geo)
|
||||
if set(rep.dirty_instances) != want_dirty:
|
||||
bad.append(f"V9 {name} {band_id}: dirty {sorted(rep.dirty_instances)[:3]} "
|
||||
f"(+{len(rep.dirty_instances)}) != {sorted(want_dirty)[:3]} (+{len(want_dirty)})")
|
||||
got_geo = set(rep.geometry_dirty_instances) - want_dirty
|
||||
if got_geo != want_geo:
|
||||
bad.append(f"V9 {name} {band_id}: geometry dirty {sorted(got_geo)[:3]} (+{len(got_geo)}) "
|
||||
f"!= {sorted(want_geo)[:3]} (+{len(want_geo)})")
|
||||
if rep.corrupt_entries:
|
||||
bad.append(f"V9 {name} {band_id}: {rep.corrupt_entries} corrupt entries")
|
||||
dirty_bands += bool(rep.dirty_instances or rep.geometry_dirty_instances)
|
||||
band_content[F.band_assembly_id(band_id)] = changed
|
||||
self.band_prev[band_id] = (state, {tid: keys[tid] for tid in used})
|
||||
# tower
|
||||
tstate = tower_state(sched)
|
||||
content = {rid: keys[rid] for rid in keys if rid.startswith("slab-") or rid == S.CANOPY_ID}
|
||||
prev_t = self.tower_prev
|
||||
rep = tower.solve_report
|
||||
if prev_t is not None:
|
||||
want_dirty = _diff(prev_t[0], tstate)
|
||||
want_geo = {cid for cid, (rid, _) in tstate.items() if cid not in want_dirty and (
|
||||
band_content.get(rid, False) if rid.startswith("band-") else prev_t[1].get(rid) != content.get(rid))}
|
||||
if set(rep.dirty_instances) != want_dirty:
|
||||
bad.append(f"V9 {name} tower: dirty {sorted(rep.dirty_instances)[:4]} (+{len(rep.dirty_instances)}) "
|
||||
f"!= {sorted(want_dirty)[:4]} (+{len(want_dirty)})")
|
||||
if set(rep.geometry_dirty_instances) - want_dirty != want_geo:
|
||||
bad.append(f"V9 {name} tower: geometry dirty {sorted(set(rep.geometry_dirty_instances) - want_dirty)[:4]} "
|
||||
f"!= {sorted(want_geo)[:4]} (+{len(want_geo)})")
|
||||
self.tower_prev = (tstate, content)
|
||||
self.seen |= set(keys.values())
|
||||
row = {"step": name, "build_s": round(seconds, 1), "parts": len(LOG["parts"]), "part_misses": len(got_miss),
|
||||
"bands": len(LOG["bands"]), "bands_dirty": dirty_bands, "tower_dirty": len(rep.dirty_instances),
|
||||
"tower_geometry_dirty": len(rep.geometry_dirty_instances), "pieces": sched.stats["n_instances"]}
|
||||
st = sched.stats
|
||||
row = {
|
||||
"step": name,
|
||||
"build_s": round(seconds, 1),
|
||||
"pieces": st["n_instances"],
|
||||
"types": st["n_types"],
|
||||
"fin_types": len(st["fin_types"]),
|
||||
"height_m": round(st["height"] / 1000.0, 2),
|
||||
}
|
||||
self.rows.append(row)
|
||||
print(f" {name:22s} {seconds:6.1f}s parts {row['parts']:3d} ({row['part_misses']:2d} miss) "
|
||||
f"bands {row['bands']:2d} ({dirty_bands:2d} changed) tower dirty {row['tower_dirty']:2d} / "
|
||||
f"geo {row['tower_geometry_dirty']:2d} {'ok' if not bad else f'{len(bad)} FAIL'}", flush=True)
|
||||
return bad
|
||||
print(f" {name:22s} {seconds:6.1f}s pieces {row['pieces']:5d} types {row['types']:3d} "
|
||||
f"fins {row['fin_types']:3d} {row['height_m']:6.2f} m", flush=True)
|
||||
return []
|
||||
|
||||
|
||||
def main() -> int:
|
||||
base = L.default_params()
|
||||
run = Run()
|
||||
bad = run.step("prime (default)", base)
|
||||
bad = [] # the prime step only establishes the previous state (its "expected" misses are unknowable)
|
||||
bad += run.step("warm (default)", base, expect_all_parts_hit=True)
|
||||
# the content-addressed part store keeps every variant ever built, so a fixed edit would hit on a rerun of this
|
||||
# gate: salt the new depth (sub-micron) so its fin parts are cold every time
|
||||
depth = 350.0 + (time.time_ns() // 1000 % 997) * 1.0e-6
|
||||
bad += run.step(f"fin_depth {depth:.6f}", L.default_params(fin_depth=depth))
|
||||
fins = {t for t, s in L.build_schedule(base).types.items() if s["family"] == "fin"}
|
||||
if run.rows[-1]["part_misses"] != len(fins):
|
||||
bad.append(f"V9 fin_depth: {run.rows[-1]['part_misses']} part misses != {len(fins)} fin types")
|
||||
bad += run.step("revert fin_depth", base, expect_all_parts_hit=True)
|
||||
bad += run.step("n_floors 48 (every 16)", L.default_params(n_floors=48, setback_every=16), expect_all_parts_hit=True)
|
||||
bad += run.step("revert n_floors", base, expect_all_parts_hit=True)
|
||||
bad = []
|
||||
bad += run.step("prime (default)", base)
|
||||
bad += run.step("warm (default)", base)
|
||||
bad += run.step("fin_depth 350", L.default_params(fin_depth=350.0))
|
||||
bad += run.step("revert fin_depth", base)
|
||||
bad += run.step("n_floors 48 (every 16)", L.default_params(n_floors=48, setback_every=16))
|
||||
bad += run.step("revert n_floors", base)
|
||||
out = PART_DIR / "out"
|
||||
out.mkdir(exist_ok=True)
|
||||
(out / "incremental.json").write_text(json.dumps(run.rows, indent=1))
|
||||
print(f" {out / 'incremental.json'}")
|
||||
return report("S7", bad)
|
||||
return report("S7 rebuild timings", bad)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user