You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Deep DRC can miss violations when a cell has many shapes #2546
On a clipped deep DRC run of the vexriscv layout, a via1 in metal1 enclosure check loses 2127 of its 4296 markers. Forcing the brute force path everywhere gives all 4296. Almost every via either keeps all of its markers or loses all of them.
The cause is in the box_scanner2 sweep. It remembers the pairs it has already reported in a set, and that set is keyed on the two object pointers only. In the instance to shape interaction scan in dbHierProcessor.cc the same shape can be inserted twice with two different intruder layer ids. The second pair then looks like a duplicate and is dropped. Small cells don't use the sweep, so there both pairs are reported and the result depends on how many shapes a cell has. A small box_scanner2 test shows the same thing when one object is inserted twice with different properties and there are enough other boxes to go over the threshold.
Sure. The layout is testdata/lvs/vexriscv.oas.gz from this repository, and the script below only needs the klayout package from PyPI. It has inline metadata, so uv run --script installs that by itself. It reads metal1 and via1 in deep mode through a window in the middle of the chip and runs a via1 in metal1 enclosure check of 3 DBU. The drawn enclosure is 2 DBU, so every via is a violation. Then it runs the same check flat on the same shapes and compares the marker edges, since the marker counts of deep and flat mode can't be compared directly.
# /// script# requires-python = ">=3.9"# dependencies = ["klayout==0.30.13"]# ///importsysimportklayout.dbasdbly=db.Layout()
ly.read(sys.argv[1])
top=ly.top_cell()
# a window in the middle of the chip with 1/16 of its areab=top.bbox()
c=b.center()
clip=db.Box(c.x-b.width() //8, c.y-b.height() //8, c.x+b.width() //8, c.y+b.height() //8)
dss=db.DeepShapeStore()
metal1=db.Region(db.RecursiveShapeIterator(ly, top, ly.layer(11, 0), clip), dss)
via1=db.Region(db.RecursiveShapeIterator(ly, top, ly.layer(14, 0), clip), dss)
# the drawn via1 in metal1 enclosure is 2 DBU, so with 3 every via is a violationdeep=metal1.enclosing_check(via1, 3)
# the same check flat on exactly the same shapesflat=metal1.dup().flatten().enclosing_check(via1.dup().flatten(), 3)
deep_edges=deep.edges().merged()
flat_edges=flat.edges().merged()
missing=flat_edges-deep_edgesprint("deep markers:", deep.count())
print("flat markers:", flat.count())
print("marker edges found flat but not deep:", missing.count())
Running uv run --script repro.py testdata/lvs/vexriscv.oas.gz with klayout 0.30.13 from PyPI on macOS 27.2 arm64 gives
deep markers: 11046
flat markers: 14356
marker edges found flat but not deep: 3104
The other direction is empty, so the deep run only loses markers. Current master built on Ubuntu 24.04 aarch64 gives the same picture with 3115 missing edges. With the 2 DBU rule from my first post the script reports 1826 missing edges. Without the clip window deep and flat agree on this layout, so I only have the clipped case so far.
The error marker count is not necessarily the same between deep and flat mode. The goal is to produce markers, but they may be split or distributed hierarchically. The warranty is that there is a marker and that the markers cover the area where the violation happens. So the count can differ, the covered area shouldn't.
I translated the script into DRC (load the testdata/lvs/vexriscv.oas.gz layout before you run it):
Those are roughly your numbers. Differences may arise due to different hashing for example. So we have a different count between deep and flat, but same markers in terms of covered area. So no violation is lost.
I don't know why the patch changes that, but having a different count is basically okay. Same count is not part of the warranties and not same markers. I'd be really surprised if the analysis is correct. It is a very fundamental concept that pointer value is equal to object identity. I'm not going into further analysis here as I suspect these words go back into Claude or whatever and are turned against me.
Yet, something is wrong. The markers are not correct:
They should look like this:
Also, there are markers outside the clip, which should not happen. Both effects are related to use of the clip feature. Without the clip, everything seems to be fine. In order to limit the number of shapes or cells to meet the objective of this issue report, manually clip using Edit/Utilities/Clip Tool with the same window. When you use the DRC deck on such a case without the clip statements, you get the correct markers and a different count and still empty XOR. I think that is the truth:
deep: 6908
flat: 6736
xor: 0
(the reason for the deep count being bigger than flat is a different discussion. After all, the sample case is a very bad one for hierarchical processing).
The clip feature from the DRC deck should translate into the same scheme of the Python script and the effect should be pretty much the same. The wrong markers and the markers outside the clip window point to a problem in the clip cell variant generation.
I will debug in this direction. Please accept that I want to take care of that and do not welcome PRs that suggest some solution before I have a chance to analyze the problem.
Thanks Matthias. You're right, I get zero polygon XOR too. My edge comparison did not establish lost violations. Sorry for jumping ahead with the diagnosis. I'll leave the clipping investigation to you.
Maybe you're still right or that is a different topic. But I'd like to get the connection and still the clip feature has a bug. It's good you brought that up, even if the intention might have been a different one.
Activity
chkkbim commentedon Nov 11, 2026
Hi @nikosavola ,
Can you provide these files for people to reproduce the problem ?
nikosavola commentedon Nov 11, 2026
Sure. The layout is testdata/lvs/vexriscv.oas.gz from this repository, and the script below only needs the klayout package from PyPI. It has inline metadata, so
uv run --scriptinstalls that by itself. It reads metal1 and via1 in deep mode through a window in the middle of the chip and runs a via1 in metal1 enclosure check of 3 DBU. The drawn enclosure is 2 DBU, so every via is a violation. Then it runs the same check flat on the same shapes and compares the marker edges, since the marker counts of deep and flat mode can't be compared directly.Running
uv run --script repro.py testdata/lvs/vexriscv.oas.gzwith klayout 0.30.13 from PyPI on macOS 27.2 arm64 givesThe other direction is empty, so the deep run only loses markers. Current master built on Ubuntu 24.04 aarch64 gives the same picture with 3115 missing edges. With the 2 DBU rule from my first post the script reports 1826 missing edges. Without the clip window deep and flat agree on this layout, so I only have the clipped case so far.
Fix lost interactions in the box scanner sweep
klayoutmatthias commentedon Nov 11, 2026
No. Sorry. I don't think that's the bug.
The error marker count is not necessarily the same between deep and flat mode. The goal is to produce markers, but they may be split or distributed hierarchically. The warranty is that there is a marker and that the markers cover the area where the violation happens. So the count can differ, the covered area shouldn't.
I translated the script into DRC (load the testdata/lvs/vexriscv.oas.gz layout before you run it):
The output is (0.30.13, Ubuntu 26.04):
Same reproduces with the Python script when I add an XOR step:
Those are roughly your numbers. Differences may arise due to different hashing for example. So we have a different count between deep and flat, but same markers in terms of covered area. So no violation is lost.
I don't know why the patch changes that, but having a different count is basically okay. Same count is not part of the warranties and not same markers. I'd be really surprised if the analysis is correct. It is a very fundamental concept that pointer value is equal to object identity. I'm not going into further analysis here as I suspect these words go back into Claude or whatever and are turned against me.
Yet, something is wrong. The markers are not correct:
They should look like this:
Also, there are markers outside the clip, which should not happen. Both effects are related to use of the clip feature. Without the clip, everything seems to be fine. In order to limit the number of shapes or cells to meet the objective of this issue report, manually clip using Edit/Utilities/Clip Tool with the same window. When you use the DRC deck on such a case without the clip statements, you get the correct markers and a different count and still empty XOR. I think that is the truth:
(the reason for the deep count being bigger than flat is a different discussion. After all, the sample case is a very bad one for hierarchical processing).
The clip feature from the DRC deck should translate into the same scheme of the Python script and the effect should be pretty much the same. The wrong markers and the markers outside the clip window point to a problem in the clip cell variant generation.
I will debug in this direction. Please accept that I want to take care of that and do not welcome PRs that suggest some solution before I have a chance to analyze the problem.
Matthias
nikosavola commentedon Nov 12, 2026
Thanks Matthias. You're right, I get zero polygon XOR too. My edge comparison did not establish lost violations. Sorry for jumping ahead with the diagnosis. I'll leave the clipping investigation to you.
klayoutmatthias commentedon Nov 13, 2026
Thanks :)
Maybe you're still right or that is a different topic. But I'd like to get the connection and still the clip feature has a bug. It's good you brought that up, even if the intention might have been a different one.
Matthias