diff options
Diffstat (limited to 'tools/pnr_eval.sh')
| -rw-r--r-- | tools/pnr_eval.sh | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tools/pnr_eval.sh b/tools/pnr_eval.sh new file mode 100644 index 0000000..ed73828 --- /dev/null +++ b/tools/pnr_eval.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# Apply, route and DRC-check placer candidates, several in parallel. Called by tools/pnr.sh run. +# +# E=BOARD_DIR BOARD=NAME sh tools/pnr_eval.sh OUT_DIR placement.json... +# TOML=route.toml ROUTER=path/to/router JOBS=4 (optional; TOML defaults to $E/route.toml) +# +# Per placement: placer/apply.py -> router/dump_board.py -> router route -> router/write_board.py +# -> kicad-cli DRC, in OUT_DIR/<placement>/ (routed.kicad_pcb, drc.json, route.log). One line +# per board is printed, sorted by name, then +# SUMMARY complete=<boards with 0 unconnected after DRC>/<total> unconnected=<sum> vias=<mean> length=<mean> +T=$(cd "$(dirname "$0")" && pwd) +. "$T/kicad_env.sh" +: "${E:?set E to the board directory}" "${BOARD:?set BOARD to the board name}" +ROUTER=${ROUTER:-$T/router-rs/target/release/router} +TOML=${TOML:-$E/route.toml} +PLANE=${PLANE:-GND} # the plane net whose dangling vias write_board.py prunes +export E BOARD ROUTER TOML PLANE + +if [ "$1" = "--one" ]; then + OUT=$2; P=$3 + N=$(basename "$P" .json) + D="$OUT/$N" + mkdir -p "$D" + $KPY "$T/placer/apply.py" "$E/$BOARD.kicad_pcb" "$P" "$D/$BOARD.kicad_pcb" >/dev/null 2>&1 + $KPY "$T/router/dump_board.py" "$D/$BOARD.kicad_pcb" "$D/board.json" >/dev/null 2>&1 + "$ROUTER" route "$D/board.json" "$TOML" "$D/routes.json" > "$D/route.log" 2>&1 || true + $KPY "$T/router/write_board.py" "$D/$BOARD.kicad_pcb" "$D/routes.json" "$D/routed.kicad_pcb" \ + --replace --prune-vias "$PLANE" >/dev/null 2>&1 + cp "$D/$BOARD.kicad_pro" "$D/routed.kicad_pro" + [ -f "$D/$BOARD.kicad_dru" ] && cp "$D/$BOARD.kicad_dru" "$D/routed.kicad_dru" + $KC pcb drc --refill-zones --format json -o "$D/drc.json" "$D/routed.kicad_pcb" >/dev/null 2>&1 + DRC=$(python3 -c " +import collections, json, sys +d = json.load(open(sys.argv[1])) +c = collections.Counter(v['type'] for v in d['violations'] if not v['type'].startswith('silk')) +print('unconnected=%d drc=%s' % (len(d['unconnected_items']), dict(c)))" "$D/drc.json" 2>/dev/null || echo "unconnected=? drc=error") + R=$(grep RESULT "$D/route.log" | sed 's/RESULT //') + printf "%-12s %s %s\n" "$N" "${R:-CRASH $(tail -n 1 "$D/route.log")}" "$DRC" > "$D/line.txt" + exit 0 +fi + +OUT=$1; shift +mkdir -p "$OUT" +printf '%s\n' "$@" | xargs -P "${JOBS:-4}" -I{} sh "$0" --one "$OUT" {} +for P in "$@"; do cat "$OUT/$(basename "$P" .json)/line.txt"; done | sort | tee "$OUT/lines.txt" +python3 - "$OUT/lines.txt" <<'PY' +import re, sys +rows = [l for l in open(sys.argv[1]) if l.strip()] +unc = [int(m.group(1)) if (m := re.search(r"unconnected=(\d+)", l)) else 0 for l in rows] +def f(k): return [float(m.group(1)) for l in rows if (m := re.search(k + r"=([\d.]+)", l))] +v, ln = f("vias"), f("length") +print("SUMMARY complete=%d/%d unconnected=%d vias=%.1f length=%.1f" % ( + sum(1 for u in unc if u == 0), len(rows), sum(unc), sum(v) / max(len(v), 1), sum(ln) / max(len(ln), 1))) +PY |
