Skip to content

Deep DRC can miss violations when a cell has many shapes #2546

Open

Description

@nikosavola

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.

Activity

  1. chkkbim commented on Nov 11, 2026

    @chkkbim

    Hi @nikosavola ,

    Can you provide these files for people to reproduce the problem ?

    • sample layout
    • sample script
    • the output you obtained (eg screenshots etc)
    • KLayout version
    • computer OS
  2. nikosavola commented on Nov 11, 2026

    @nikosavola
    ContributorAuthor

    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"]
    # ///
    import sys
    import klayout.db as db
    
    ly = db.Layout()
    ly.read(sys.argv[1])
    top = ly.top_cell()
    
    # a window in the middle of the chip with 1/16 of its area
    b = 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 violation
    deep = metal1.enclosing_check(via1, 3)
    
    # the same check flat on exactly the same shapes
    flat = metal1.dup().flatten().enclosing_check(via1.dup().flatten(), 3)
    
    deep_edges = deep.edges().merged()
    flat_edges = flat.edges().merged()
    missing = flat_edges - deep_edges
    
    print("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.

  3. klayoutmatthias commented on Nov 11, 2026

    @klayoutmatthias
    Collaborator

    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 values your script gives:
    clip(6674.dbu, 6750.dbu, 11126.dbu, 11250.dbu)
    
    metal1 = input(11, 0)
    via1 = input(14, 0)
    
    err_deep = metal1.enclosing(via1, 3.dbu)
    err_deep_polygons = err_deep.polygons
    err_deep_polygons.output(1000, 0)
    puts("deep: #{err_deep.count}")
    
    err_flat = metal1.flatten.enclosing(via1.flatten, 3.dbu)
    err_flat_polygons = err_flat.polygons
    err_flat_polygons.output(1001, 0)
    puts("flat: #{err_flat.count}")
    
    xor = err_flat_polygons ^ err_deep_polygons
    xor.output(1002, 0)
    puts("xor: #{xor.count}")
    

    The output is (0.30.13, Ubuntu 26.04):

    deep: 11426
    flat: 14356
    xor: 0
    

    Same reproduces with the Python script when I add an XOR step:

    # XOR step:
    xor = deep.polygons() ^ flat.polygons()
    print("XOR:", xor.count())
    
    Results:
    deep markers: 11101
    flat markers: 14356
    XOR: 0
    

    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:

    image

    They should look like this:

    image

    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.

    Matthias

  4. nikosavola commented on Nov 12, 2026

    @nikosavola
    ContributorAuthor

    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.

  5. klayoutmatthias commented on Nov 13, 2026

    @klayoutmatthias
    Collaborator

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions