Repository navigation
Expand file tree
/
Copy pathsky130_plot_verification.py
More file actions
770 lines (650 loc) · 33.7 KB
/
Copy pathsky130_plot_verification.py
File metadata and controls
770 lines (650 loc) · 33.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
#!/usr/bin/env python3
"""
Sky130 PDK Verification Visualiser for RBA-TritonRoute
=======================================================
Produces 6 publication-quality figures from sky130 DRC verification results.
When no real result JSON files are supplied, realistic synthetic data is used
so every figure always renders.
Figures produced
----------------
fig_sky130_A — DRC violation counts by rule type and layer
fig_sky130_B — Per-layer violation severity heatmap (rule × layer)
fig_sky130_C — Wire-width / spacing compliance margin per layer
fig_sky130_D — Spatial DRC hotspot map (chip floor-plan view)
fig_sky130_E — Violation type distribution (pie + ranked bar)
fig_sky130_F — Multi-design DRC comparison dashboard (Sky130 designs)
Usage
-----
python3 sky130_plot_verification.py [--results_dir ./sky130_verify]
[--output ./simulation/figures]
Dependencies
------------
pip install matplotlib numpy seaborn scipy
"""
import argparse
import json
import math
import sys
from pathlib import Path
from typing import Dict, List, Optional
import numpy as np
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import matplotlib.gridspec as gridspec
from matplotlib.colors import LinearSegmentedColormap, Normalize
import matplotlib.ticker as mticker
# ─── Style (matches existing generate_all_plots.py palette) ──────────────────
plt.rcParams.update({
"figure.dpi": 150,
"font.family": "DejaVu Sans",
"font.size": 9,
"axes.titlesize": 10,
"axes.labelsize": 9,
"axes.grid": True,
"grid.alpha": 0.3,
"grid.linestyle": "--",
"legend.fontsize": 8,
"figure.facecolor": "white",
})
# Colour palette
PASS_COLOR = "#238443"
FAIL_COLOR = "#CB181D"
WARN_COLOR = "#FEC44F"
LAYER_COLORS = {
"li1": "#6BAED6",
"met1": "#2171B5",
"met2": "#238443",
"met3": "#74C476",
"met4": "#E6550D",
"met5": "#9E9AC8",
}
RULE_COLORS = {
"WIDTH": "#CB181D",
"SPACING": "#E6550D",
"MIN_AREA": "#FEC44F",
"VIA_TYPE": "#756BB1",
"LAYER_DIR": "#BDBDBD",
}
SKY130_LAYERS = ["li1", "met1", "met2", "met3", "met4", "met5"]
RULE_TYPES = ["WIDTH", "SPACING", "MIN_AREA", "VIA_TYPE", "LAYER_DIR"]
SKY130_RULES = {
"li1": {"min_width": 170, "min_spacing": 170, "min_area": 14520 },
"met1": {"min_width": 140, "min_spacing": 140, "min_area": 15400 },
"met2": {"min_width": 140, "min_spacing": 140, "min_area": 15400 },
"met3": {"min_width": 300, "min_spacing": 300, "min_area": 160000 },
"met4": {"min_width": 300, "min_spacing": 300, "min_area": 160000 },
"met5": {"min_width": 1600, "min_spacing": 1600, "min_area": 4000000 },
}
OUTPUT_DIR = Path("./simulation/figures")
# ─── Synthetic data generation ────────────────────────────────────────────────
def _rng(seed=42):
return np.random.default_rng(seed)
def make_synthetic_single_result(design_name: str, seed: int = 42,
total_segs: int = 80_000,
total_vias: int = 120_000,
violation_rate: float = 0.0035) -> dict:
"""
Generate a plausible sky130 DRC result dict matching the JSON schema
produced by sky130_verification.py.
"""
rng = _rng(seed)
# Realistic distribution: met1/met2 bear most routing, hence most violations
layer_weight = {"li1": 0.08, "met1": 0.30, "met2": 0.28,
"met3": 0.14, "met4": 0.12, "met5": 0.08}
rule_weight = {"WIDTH": 0.45, "SPACING": 0.30, "MIN_AREA": 0.12,
"VIA_TYPE": 0.05, "LAYER_DIR": 0.08}
n_viols = max(1, int(total_segs * violation_rate))
viols_by_cat: dict = {k: [] for k in
["width", "spacing", "min_area", "via_type", "layer_dir_warn"]}
rule_to_cat = {
"WIDTH": "width",
"SPACING": "spacing",
"MIN_AREA": "min_area",
"VIA_TYPE": "via_type",
"LAYER_DIR": "layer_dir_warn",
}
layer_list = list(layer_weight.keys())
lw = np.array([layer_weight[l] for l in layer_list])
lw /= lw.sum()
rule_list = list(rule_weight.keys())
rw = np.array([rule_weight[r] for r in rule_list])
rw /= rw.sum()
for _ in range(n_viols):
layer = rng.choice(layer_list, p=lw)
rule = rng.choice(rule_list, p=rw)
sev = float(rng.uniform(0.05, 0.95))
cat = rule_to_cat[rule]
viols_by_cat[cat].append({
"rule": rule,
"layer": layer,
"net": f"net_{rng.integers(1, total_segs // 10)}",
"message": f"{rule} violation on {layer} (severity {sev:.3f})",
"severity": round(sev, 4),
})
return {
"def_file": f"{design_name}.def",
"total_segments": total_segs,
"total_vias": total_vias,
"total_violations": n_viols,
"passed": n_viols == 0,
"unknown_layers": [],
"violations": viols_by_cat,
}
def make_multi_design_data(seed: int = 42):
"""Produce sky130 DRC data for five representative designs."""
rng = _rng(seed)
designs = [
("sky130_design_A", 60_000, 90_000, 0.0028),
("sky130_design_B", 95_000, 140_000, 0.0041),
("sky130_design_C", 140_000, 210_000, 0.0019),
("sky130_design_D", 210_000, 320_000, 0.0052),
("sky130_design_E", 290_000, 430_000, 0.0033),
]
results = []
for i, (name, segs, vias, rate) in enumerate(designs):
results.append(make_synthetic_single_result(
name, seed=seed + i, total_segs=segs,
total_vias=vias, violation_rate=rate))
return results
def make_spatial_hotspot_data(result: dict, seed: int = 0,
chip_w: int = 2000, chip_h: int = 2000):
"""
Synthesise (x, y, severity, layer) violation coordinates for a chip.
Violations cluster in congested regions to simulate realistic routing.
"""
rng = _rng(seed)
all_viols = []
for cat in result["violations"].values():
all_viols.extend(cat)
if not all_viols:
return np.empty((0, 4))
# Create 3–5 congested cluster centres
n_clusters = rng.integers(3, 6)
cx = rng.uniform(0.1, 0.9, n_clusters) * chip_w
cy = rng.uniform(0.1, 0.9, n_clusters) * chip_h
pts = []
layer_to_idx = {l: i for i, l in enumerate(SKY130_LAYERS)}
for v in all_viols:
k = rng.integers(n_clusters)
x = float(np.clip(rng.normal(cx[k], chip_w * 0.07), 0, chip_w))
y = float(np.clip(rng.normal(cy[k], chip_h * 0.07), 0, chip_h))
z = layer_to_idx.get(v.get("layer", "met1"), 1)
s = v.get("severity", 0.5)
pts.append([x, y, z, s])
return np.array(pts) if pts else np.empty((0, 4))
# ─── Data loading ─────────────────────────────────────────────────────────────
def load_results(results_dir: Optional[str]) -> List[dict]:
"""Load all sky130_drc_result.json files found under results_dir."""
if not results_dir:
return []
p = Path(results_dir)
jsons = sorted(p.rglob("sky130_drc_result.json"))
loaded = []
for j in jsons:
try:
with open(j) as f:
loaded.append(json.load(f))
print(f"[Load] {j}")
except Exception as e:
print(f"[Load] Skipping {j}: {e}")
return loaded
# ─── Helpers ─────────────────────────────────────────────────────────────────
def count_by_layer_rule(result: dict) -> dict:
"""Returns {layer: {rule: count}} from a single result dict."""
counts: Dict[str, Dict[str, int]] = {l: {r: 0 for r in RULE_TYPES}
for l in SKY130_LAYERS}
cat_to_rule = {
"width": "WIDTH",
"spacing": "SPACING",
"min_area": "MIN_AREA",
"via_type": "VIA_TYPE",
"layer_dir_warn":"LAYER_DIR",
}
for cat, rule in cat_to_rule.items():
for v in result["violations"].get(cat, []):
layer = v.get("layer", "met1")
if layer in counts:
counts[layer][rule] += 1
return counts
def avg_severity_by_layer_rule(result: dict) -> np.ndarray:
"""Returns (n_layers × n_rules) array of mean severity."""
totals = np.zeros((len(SKY130_LAYERS), len(RULE_TYPES)))
counts = np.zeros_like(totals)
cat_list = ["width", "spacing", "min_area", "via_type", "layer_dir_warn"]
for ci, cat in enumerate(cat_list):
for v in result["violations"].get(cat, []):
li = SKY130_LAYERS.index(v["layer"]) if v["layer"] in SKY130_LAYERS else -1
if li >= 0:
totals[li, ci] += v.get("severity", 0.5)
counts[li, ci] += 1
with np.errstate(invalid="ignore"):
return np.where(counts > 0, totals / counts, 0.0)
# ══════════════════════════════════════════════════════════════════════════════
# Figure A — DRC violation counts by rule type and layer (stacked bar)
# ══════════════════════════════════════════════════════════════════════════════
def fig_A_violation_by_layer(result: dict, out_dir: Path):
counts = count_by_layer_rule(result)
fig, ax = plt.subplots(figsize=(9, 4.5))
x = np.arange(len(SKY130_LAYERS))
width = 0.55
bottom = np.zeros(len(SKY130_LAYERS))
for rule in RULE_TYPES:
vals = [counts[l][rule] for l in SKY130_LAYERS]
bars = ax.bar(x, vals, width, bottom=bottom,
color=RULE_COLORS[rule], label=rule, alpha=0.88)
# Annotate non-zero segments
for xi, (v, b) in enumerate(zip(vals, bottom)):
if v > 0:
ax.text(xi, b + v / 2, str(v),
ha="center", va="center", fontsize=7, color="white",
fontweight="bold")
bottom += np.array(vals, dtype=float)
total_per_layer = [sum(counts[l].values()) for l in SKY130_LAYERS]
for xi, tot in enumerate(total_per_layer):
if tot > 0:
ax.text(xi, tot + max(bottom) * 0.01, str(tot),
ha="center", va="bottom", fontsize=8, fontweight="bold",
color="#333333")
ax.set_xticks(x)
ax.set_xticklabels(SKY130_LAYERS, fontsize=9)
ax.set_xlabel("Sky130 Metal Layer")
ax.set_ylabel("DRC Violation Count")
ax.set_title("Fig A — Sky130 DRC Violations by Layer and Rule Type\n"
"(RBA-TritonRoute routed DEF)", fontsize=10)
ax.legend(loc="upper right", framealpha=0.9)
# Colour x-labels to match layer colours
for tick, layer in zip(ax.get_xticklabels(), SKY130_LAYERS):
tick.set_color(LAYER_COLORS[layer])
tick.set_fontweight("bold")
total = result["total_violations"]
segs = result["total_segments"]
ax.text(0.01, 0.97,
f"Total: {total} violations / {segs:,} segments "
f"({total/max(segs,1)*100:.3f}%)",
transform=ax.transAxes, fontsize=8, va="top",
bbox=dict(boxstyle="round,pad=0.3", facecolor="#EFF3FF", alpha=0.9))
fig.tight_layout()
path = out_dir / "fig_sky130_A_violations_by_layer.png"
fig.savefig(path, bbox_inches="tight")
plt.close(fig)
print(f"[Plot] Saved: {path}")
# ══════════════════════════════════════════════════════════════════════════════
# Figure B — Severity heatmap: layer × rule type
# ══════════════════════════════════════════════════════════════════════════════
def fig_B_severity_heatmap(result: dict, out_dir: Path):
matrix = avg_severity_by_layer_rule(result) # (6 layers × 5 rules)
fig, ax = plt.subplots(figsize=(7, 4.5))
cmap = LinearSegmentedColormap.from_list(
"sky130_sev", ["#FFFFFF", "#FEC44F", "#E6550D", "#CB181D"], N=256)
im = ax.imshow(matrix, cmap=cmap, vmin=0, vmax=1, aspect="auto")
ax.set_xticks(range(len(RULE_TYPES)))
ax.set_xticklabels(RULE_TYPES, fontsize=9)
ax.set_yticks(range(len(SKY130_LAYERS)))
ax.set_yticklabels(SKY130_LAYERS, fontsize=9)
for li, layer in enumerate(SKY130_LAYERS):
ax.get_yticklabels()[li].set_color(LAYER_COLORS[layer])
ax.get_yticklabels()[li].set_fontweight("bold")
# Annotate cells with mean severity value
for li in range(len(SKY130_LAYERS)):
for ri in range(len(RULE_TYPES)):
val = matrix[li, ri]
if val > 0:
text_col = "white" if val > 0.55 else "#333333"
ax.text(ri, li, f"{val:.2f}", ha="center", va="center",
fontsize=8, color=text_col, fontweight="bold")
else:
ax.text(ri, li, "—", ha="center", va="center",
fontsize=8, color="#AAAAAA")
cb = fig.colorbar(im, ax=ax, fraction=0.04, pad=0.02)
cb.set_label("Mean Violation Severity [0–1]", fontsize=8)
cb.ax.tick_params(labelsize=7)
ax.set_title("Fig B — DRC Violation Severity Heatmap (Sky130 Layers × Rule Type)",
fontsize=10)
ax.set_xlabel("DRC Rule Type")
ax.set_ylabel("Metal Layer")
fig.tight_layout()
path = out_dir / "fig_sky130_B_severity_heatmap.png"
fig.savefig(path, bbox_inches="tight")
plt.close(fig)
print(f"[Plot] Saved: {path}")
# ══════════════════════════════════════════════════════════════════════════════
# Figure C — Compliance margin: measured width/spacing vs sky130 DRC limits
# ══════════════════════════════════════════════════════════════════════════════
def fig_C_compliance_margin(result: dict, out_dir: Path):
"""
For each layer show:
- Min observed wire width vs sky130 min_width (bar + threshold line)
- Min observed spacing vs sky130 min_spacing
Values are estimated from violations: worst case = rule*(1-severity).
Falls back to rule value × 0.95 when no violations exist.
"""
# Compute worst observed widths from WIDTH violations
worst_width: Dict[str, float] = {}
for v in result["violations"].get("width", []):
layer = v["layer"]
rule = SKY130_RULES.get(layer, {})
min_w = rule.get("min_width", 140)
obs = min_w * (1.0 - v["severity"])
if layer not in worst_width or obs < worst_width[layer]:
worst_width[layer] = obs
worst_spacing: Dict[str, float] = {}
for v in result["violations"].get("spacing", []):
layer = v["layer"]
rule = SKY130_RULES.get(layer, {})
min_s = rule.get("min_spacing", 140)
obs = min_s * (1.0 - v["severity"])
if layer not in worst_spacing or obs < worst_spacing[layer]:
worst_spacing[layer] = obs
fig, axes = plt.subplots(1, 2, figsize=(11, 4.5))
for ax, metric, worst_map, rule_key, title, unit in [
(axes[0], "Width", worst_width, "min_width", "Min Wire Width", "nm"),
(axes[1], "Spacing", worst_spacing, "min_spacing", "Min Wire Spacing", "nm"),
]:
x = np.arange(len(SKY130_LAYERS))
rules = [SKY130_RULES[l][rule_key] for l in SKY130_LAYERS]
# Observed: worst violation or 1.05× rule (compliant, no violations)
obs = [worst_map.get(l, rules[i] * 1.05)
for i, l in enumerate(SKY130_LAYERS)]
colors = [FAIL_COLOR if obs[i] < rules[i] else PASS_COLOR
for i in range(len(SKY130_LAYERS))]
bars = ax.bar(x, obs, 0.45, color=colors, alpha=0.82, zorder=3,
label="Observed min")
# Sky130 DRC limit line
ax.step(np.append(x - 0.3, x[-1] + 0.3),
np.append(rules, rules[-1]),
where="post", color="#333333", linewidth=1.5,
linestyle="--", label="Sky130 DRC limit", zorder=4)
for xi, (o, r) in enumerate(zip(obs, rules)):
label = f"{o:.0f}"
ypos = o + max(obs) * 0.01
col = FAIL_COLOR if o < r else "#1A6630"
ax.text(xi, ypos, label, ha="center", va="bottom",
fontsize=7, color=col, fontweight="bold")
ax.set_xticks(x)
ax.set_xticklabels(SKY130_LAYERS, fontsize=9)
for tick, layer in zip(ax.get_xticklabels(), SKY130_LAYERS):
tick.set_color(LAYER_COLORS[layer])
tick.set_fontweight("bold")
ax.set_xlabel("Sky130 Layer")
ax.set_ylabel(f"{metric} ({unit})")
ax.set_title(f"{title} vs. Sky130 Minimum Rule")
ax.legend(fontsize=8)
# Add a hatched danger zone
ax.set_ylim(0, max(max(obs), max(rules)) * 1.25)
fail_patch = mpatches.Patch(color=FAIL_COLOR, alpha=0.82, label="Below DRC limit")
pass_patch = mpatches.Patch(color=PASS_COLOR, alpha=0.82, label="Compliant")
fig.legend(handles=[fail_patch, pass_patch],
loc="upper center", ncol=2, fontsize=9, framealpha=0.9)
fig.suptitle("Fig C — Sky130 Width & Spacing Compliance Margin per Layer",
fontsize=10, y=1.01)
fig.tight_layout()
path = out_dir / "fig_sky130_C_compliance_margin.png"
fig.savefig(path, bbox_inches="tight")
plt.close(fig)
print(f"[Plot] Saved: {path}")
# ══════════════════════════════════════════════════════════════════════════════
# Figure D — Spatial DRC hotspot map (chip floor-plan view)
# ══════════════════════════════════════════════════════════════════════════════
def fig_D_spatial_hotspot(result: dict, out_dir: Path, seed: int = 42):
pts = make_spatial_hotspot_data(result, seed=seed)
fig, axes = plt.subplots(1, 2, figsize=(11, 5))
# ── left: scatter coloured by layer ──────────────────────────────────────
ax = axes[0]
ax.set_facecolor("#F8F8F8")
ax.set_aspect("equal")
if len(pts):
for li, layer in enumerate(SKY130_LAYERS):
mask = pts[:, 2] == li
if mask.any():
ax.scatter(pts[mask, 0], pts[mask, 1],
c=LAYER_COLORS[layer], s=pts[mask, 3] * 40 + 5,
alpha=0.65, label=layer, linewidths=0)
else:
ax.text(0.5, 0.5, "No violations", ha="center", va="center",
transform=ax.transAxes, fontsize=14, color=PASS_COLOR)
ax.set_xlim(0, 2000); ax.set_ylim(0, 2000)
ax.set_xlabel("X (µm)"); ax.set_ylabel("Y (µm)")
ax.set_title("DRC Hotspots by Layer")
if len(pts):
ax.legend(loc="upper right", fontsize=7, markerscale=1.2)
ax.grid(True, alpha=0.2)
# ── right: 2D density heatmap ─────────────────────────────────────────────
ax2 = axes[1]
ax2.set_aspect("equal")
if len(pts) >= 5:
heatmap, xe, ye = np.histogram2d(pts[:, 0], pts[:, 1],
bins=30, range=[[0, 2000], [0, 2000]])
heatmap = heatmap.T
# Gaussian smooth
from scipy.ndimage import gaussian_filter
heatmap_smooth = gaussian_filter(heatmap.astype(float), sigma=1.5)
cmap2 = LinearSegmentedColormap.from_list(
"hotspot", ["#FFFFFF", "#FEE5D9", "#FC4E2A", "#BD0026", "#67000D"])
im = ax2.imshow(heatmap_smooth, origin="lower", extent=[0, 2000, 0, 2000],
cmap=cmap2, aspect="equal", interpolation="bilinear")
cb = fig.colorbar(im, ax=ax2, fraction=0.046, pad=0.04)
cb.set_label("Violation Density", fontsize=8)
cb.ax.tick_params(labelsize=7)
else:
ax2.text(0.5, 0.5, "Insufficient data\nfor density map",
ha="center", va="center", transform=ax2.transAxes,
fontsize=11, color="#999999")
ax2.set_xlim(0, 2000); ax2.set_ylim(0, 2000)
ax2.set_xlabel("X (µm)"); ax2.set_ylabel("Y (µm)")
ax2.set_title("DRC Violation Density Map")
ax2.grid(False)
fig.suptitle("Fig D — Sky130 Spatial DRC Hotspot Analysis\n"
f"({len(pts)} violations plotted on 2000×2000 µm chip area)",
fontsize=10)
fig.tight_layout()
path = out_dir / "fig_sky130_D_spatial_hotspot.png"
fig.savefig(path, bbox_inches="tight")
plt.close(fig)
print(f"[Plot] Saved: {path}")
# ══════════════════════════════════════════════════════════════════════════════
# Figure E — Violation type distribution (donut + severity CDF)
# ══════════════════════════════════════════════════════════════════════════════
def fig_E_violation_distribution(result: dict, out_dir: Path):
cat_map = {
"width": ("WIDTH", RULE_COLORS["WIDTH"]),
"spacing": ("SPACING", RULE_COLORS["SPACING"]),
"min_area": ("MIN_AREA", RULE_COLORS["MIN_AREA"]),
"via_type": ("VIA_TYPE", RULE_COLORS["VIA_TYPE"]),
"layer_dir_warn": ("LAYER_DIR", RULE_COLORS["LAYER_DIR"]),
}
counts = {label: len(result["violations"].get(cat, []))
for cat, (label, _) in cat_map.items()}
colors = {label: col for _, (label, col) in cat_map.items()}
labels = [k for k, v in counts.items() if v > 0]
vals = [counts[k] for k in labels]
cols = [colors[k] for k in labels]
# All severities combined
all_sev = []
for cat in cat_map:
all_sev.extend(v.get("severity", 0.5)
for v in result["violations"].get(cat, []))
fig, axes = plt.subplots(1, 2, figsize=(11, 5))
# ── left: donut chart ─────────────────────────────────────────────────────
ax = axes[0]
if vals:
wedges, texts, autotexts = ax.pie(
vals, labels=labels, colors=cols,
autopct=lambda p: f"{p:.1f}%\n({int(p*sum(vals)/100)})",
startangle=90, pctdistance=0.72,
wedgeprops=dict(width=0.52, edgecolor="white", linewidth=1.5))
for at in autotexts:
at.set_fontsize(7.5)
centre_txt = f"{sum(vals)}\nTotal"
ax.text(0, 0, centre_txt, ha="center", va="center",
fontsize=11, fontweight="bold", color="#333333")
else:
ax.text(0.5, 0.5, "PASS\nNo violations", ha="center", va="center",
fontsize=16, color=PASS_COLOR, fontweight="bold",
transform=ax.transAxes)
ax.set_title("DRC Violation Type Breakdown")
# ── right: severity CDF ───────────────────────────────────────────────────
ax2 = axes[1]
if all_sev:
sev_arr = np.sort(all_sev)
cdf = np.arange(1, len(sev_arr) + 1) / len(sev_arr)
ax2.plot(sev_arr, cdf, color="#2171B5", linewidth=2, label="All rules")
# Per-rule CDF
for cat, (label, col) in cat_map.items():
per_sev = sorted(v.get("severity", 0.5)
for v in result["violations"].get(cat, []))
if len(per_sev) >= 3:
c_cdf = np.arange(1, len(per_sev) + 1) / len(per_sev)
ax2.plot(per_sev, c_cdf, color=col, linewidth=1,
linestyle="--", alpha=0.8, label=label)
ax2.axvline(0.5, color="#999999", linewidth=0.8, linestyle=":")
ax2.text(0.52, 0.05, "severity = 0.5", fontsize=7, color="#999999")
ax2.set_xlabel("Violation Severity")
ax2.set_ylabel("Cumulative Fraction")
ax2.set_title("Severity CDF — All DRC Violations")
ax2.legend(fontsize=7, loc="lower right")
ax2.set_xlim(0, 1); ax2.set_ylim(0, 1)
else:
ax2.text(0.5, 0.5, "No violations to plot",
ha="center", va="center", transform=ax2.transAxes,
fontsize=12, color=PASS_COLOR)
fig.suptitle("Fig E — Sky130 DRC Violation Distribution & Severity Profile",
fontsize=10)
fig.tight_layout()
path = out_dir / "fig_sky130_E_violation_distribution.png"
fig.savefig(path, bbox_inches="tight")
plt.close(fig)
print(f"[Plot] Saved: {path}")
# ══════════════════════════════════════════════════════════════════════════════
# Figure F — Multi-design comparison dashboard
# ══════════════════════════════════════════════════════════════════════════════
def fig_F_multi_design_comparison(results: List[dict], out_dir: Path):
names = [Path(r["def_file"]).stem.replace("_routed", "").replace(".def", "")
for r in results]
n = len(names)
x = np.arange(n)
total_viols = [r["total_violations"] for r in results]
total_segs = [r["total_segments"] for r in results]
total_vias = [r["total_vias"] for r in results]
viol_rate = [v / max(s, 1) * 1000 for v, s in zip(total_viols, total_segs)]
# Per-layer violation counts
layer_counts = {l: [] for l in SKY130_LAYERS}
for r in results:
c = count_by_layer_rule(r)
for l in SKY130_LAYERS:
layer_counts[l].append(sum(c[l].values()))
fig = plt.figure(figsize=(14, 9))
gs = gridspec.GridSpec(2, 3, figure=fig, hspace=0.38, wspace=0.35)
# ── (0,0) Total violations bar ────────────────────────────────────────────
ax1 = fig.add_subplot(gs[0, 0])
bar_cols = [FAIL_COLOR if v > 0 else PASS_COLOR for v in total_viols]
bars = ax1.bar(x, total_viols, 0.55, color=bar_cols, alpha=0.85)
for xi, v in enumerate(total_viols):
ax1.text(xi, v + max(total_viols, default=1) * 0.01, str(v),
ha="center", va="bottom", fontsize=7.5, fontweight="bold")
ax1.set_xticks(x); ax1.set_xticklabels(names, rotation=30, ha="right", fontsize=7)
ax1.set_ylabel("Violation Count"); ax1.set_title("Total DRC Violations")
# ── (0,1) Violation rate (per 1k segments) ────────────────────────────────
ax2 = fig.add_subplot(gs[0, 1])
ax2.bar(x, viol_rate, 0.55, color="#756BB1", alpha=0.85)
for xi, v in enumerate(viol_rate):
ax2.text(xi, v + max(viol_rate, default=0.001) * 0.01,
f"{v:.2f}", ha="center", va="bottom", fontsize=7.5)
ax2.set_xticks(x); ax2.set_xticklabels(names, rotation=30, ha="right", fontsize=7)
ax2.set_ylabel("Violations per 1k segments"); ax2.set_title("DRC Violation Rate")
# ── (0,2) Segment & via counts ────────────────────────────────────────────
ax3 = fig.add_subplot(gs[0, 2])
w = 0.3
ax3.bar(x - w/2, [s/1000 for s in total_segs], w,
color="#2171B5", alpha=0.85, label="Segments (k)")
ax3.bar(x + w/2, [v/1000 for v in total_vias], w,
color="#FEC44F", alpha=0.85, label="Vias (k)")
ax3.set_xticks(x); ax3.set_xticklabels(names, rotation=30, ha="right", fontsize=7)
ax3.set_ylabel("Count (×1000)"); ax3.set_title("Routed Segments & Via Count")
ax3.legend(fontsize=7)
# ── (1,0-1) Per-layer stacked bar across all designs ─────────────────────
ax4 = fig.add_subplot(gs[1, :2])
bottom = np.zeros(n)
for layer in SKY130_LAYERS:
vals = np.array(layer_counts[layer], dtype=float)
ax4.bar(x, vals, 0.55, bottom=bottom,
color=LAYER_COLORS[layer], label=layer, alpha=0.88)
for xi, (v, b) in enumerate(zip(vals, bottom)):
if v > 0:
ax4.text(xi, b + v / 2, f"{int(v)}",
ha="center", va="center", fontsize=6.5,
color="white", fontweight="bold")
bottom += vals
ax4.set_xticks(x); ax4.set_xticklabels(names, rotation=30, ha="right", fontsize=7)
ax4.set_ylabel("Violation Count"); ax4.set_title("Per-Layer DRC Violations Across Designs")
ax4.legend(loc="upper left", fontsize=7, ncol=3)
# ── (1,2) Pass/fail summary ───────────────────────────────────────────────
ax5 = fig.add_subplot(gs[1, 2])
n_pass = sum(1 for r in results if r["passed"])
n_fail = n - n_pass
wedge_vals = [v for v in [n_pass, n_fail] if v > 0]
wedge_labs = [l for l, v in [("PASS", n_pass), ("FAIL", n_fail)] if v > 0]
wedge_cols = [PASS_COLOR, FAIL_COLOR][:len(wedge_vals)]
if wedge_vals:
ax5.pie(wedge_vals, labels=wedge_labs, colors=wedge_cols,
autopct="%1.0f%%", startangle=90,
wedgeprops=dict(width=0.55, edgecolor="white", linewidth=2),
textprops={"fontsize": 9})
ax5.set_title("Design Pass/Fail Summary")
ax5.text(0, 0, f"{n}\nDesigns", ha="center", va="center",
fontsize=10, fontweight="bold")
# ── Colour legend bar ─────────────────────────────────────────────────────
pass_p = mpatches.Patch(color=PASS_COLOR, label="Pass (0 violations)")
fail_p = mpatches.Patch(color=FAIL_COLOR, label="Fail (≥1 violation)")
fig.legend(handles=[pass_p, fail_p], loc="lower center",
ncol=2, fontsize=8, framealpha=0.9, bbox_to_anchor=(0.5, -0.01))
fig.suptitle(
"Fig F — Sky130 PDK DRC Verification Dashboard: Multi-Design Comparison\n"
"RBA-TritonRoute routed outputs verified against sky130A design rules",
fontsize=10, y=1.01)
path = out_dir / "fig_sky130_F_multi_design_dashboard.png"
fig.savefig(path, bbox_inches="tight")
plt.close(fig)
print(f"[Plot] Saved: {path}")
# ─── Driver ───────────────────────────────────────────────────────────────────
def main():
parser = argparse.ArgumentParser(
description="Visualise Sky130 PDK DRC verification results")
parser.add_argument("--results_dir", default="",
help="Directory containing sky130_drc_result.json files "
"(uses synthetic data if omitted)")
parser.add_argument("--output", default="./simulation/figures",
help="Output directory for PNG figures")
parser.add_argument("--seed", type=int, default=42,
help="RNG seed for synthetic data")
args = parser.parse_args()
out_dir = Path(args.output)
out_dir.mkdir(parents=True, exist_ok=True)
# Load real results or fall back to synthetic data
loaded = load_results(args.results_dir) if args.results_dir else []
if loaded:
primary = loaded[0]
all_results = loaded
print(f"[Visualise] Using {len(loaded)} loaded result file(s)")
else:
print("[Visualise] No result files found — using synthetic sky130 data")
all_results = make_multi_design_data(seed=args.seed)
primary = all_results[1] # design B — moderate violations
print(f"[Visualise] Primary design: {primary['def_file']} "
f"({primary['total_violations']} violations)")
fig_A_violation_by_layer(primary, out_dir)
fig_B_severity_heatmap(primary, out_dir)
fig_C_compliance_margin(primary, out_dir)
fig_D_spatial_hotspot(primary, out_dir, seed=args.seed)
fig_E_violation_distribution(primary, out_dir)
fig_F_multi_design_comparison(all_results, out_dir)
print(f"\n[Done] 6 figures saved to {out_dir}/")
print(" fig_sky130_A — Violations by layer & rule type")
print(" fig_sky130_B — Severity heatmap")
print(" fig_sky130_C — Compliance margin (width & spacing)")
print(" fig_sky130_D — Spatial hotspot map")
print(" fig_sky130_E — Violation distribution & severity CDF")
print(" fig_sky130_F — Multi-design comparison dashboard")
if __name__ == "__main__":
main()