Bug In KLayout 0.28.7 When Doing Cell By Cell OR Operation On Shapes With User Properties

I am getting a different result between KLayout 0.27.7 on Windows vs. a Linux 0.28.7 installation when performing a simple cell by cell OR operation.

There appears to be a bug on the 0.28.7 version when operating on shapes with a User Property associated with them.

To illustrate I am running the simple script below:

# Get current view and layout
the_layout = pya.CellView.active().layout() 
the_cell = pya.CellView.active().cell

# Layer for Boolean OR output
hierarchical_layerID = the_layout.layer(10, 0, 'HIERARCHICAL_OR')

# Hierarchical OR operation
for cell in the_layout.each_cell():
    r1 = pya.Region(cell.shapes(the_layout.layer(1, 0 ) ) )  # requires 0.25
    r2 = pya.Region(cell.shapes(the_layout.layer(2, 0) ) )  # requires 0.25
    cell.shapes(the_layout.layer(10 , 0 )).insert(r1 + r2 )

I have a layout with 2 boxes drawn on layer 1;0 and 2 boxes drawn on 2;0. For both layers one box has a User Property and one box does not. When running the code below on KLayout 0.27.7 on Windows I always get the correct result, where all 4 boxes are generated on layer 10;0.

When running this on 0.28.7 on Linux the box on layer 2;0 with a User Property is left out of the Boolean output layer.

Interestingly, if change the order of the OR operation to:
cell.shapes(the_layout.layer(10 , 0 )).insert(r2 + r1 )

the box with the User Property on layer 1;0 is omitted from the Boolean output layer.

This sure looks like some kind of bug with the 0.28.7 implementation.

Initial layout. The 2 boxes on the right have the User Property #1: 'TEST_STRING' associated with them.

Result of the script above on KLayout 0.27.7 on Windows. Output is correct.

Result of the script above on KLayout 0.28.7 on Linux. Box with the User Property is omitted.

This is my first time posting on the forum. Hopefully I am doing this correctly. :-)

Comments

  • @winebarp Thanks a lot for this report! And yes, this post was done very correctly :)

    I can reproduce the issue. It's actually a bug. User properties were not considered before but have been added to support connectivity-aware DRC checks for example. The "+" operator is not correctly implemented - in fact is uses only the shapes without user properties from the second input.

    I have created an issue for this problem: https://github.com/KLayout/klayout/issues/1373

    There are two workarounds at least:

    1. instead created Region from a Shapes object, create it from a zero-depth recursive shape iterator:
    for cell in the_layout.each_cell():
        i1 = cell.begin_shapes_rec(the_layout.layer(1, 0) )
        i1.max_depth = 0
        r1 = pya.Region(i1)
        i2 = cell.begin_shapes_rec(the_layout.layer(2, 0) )
        i2.max_depth = 0
        r2 = pya.Region(i2)
        cell.shapes(the_layout.layer(10, 0) ).insert(r1 + r2 )
    
    1. use the "copy" function which basically does internally what you do in a loop here:
    l10 = the_layout.layer(10, 0)
    the_layout.clear_layer(l10)
    the_layout.copy_layer(the_layout.layer(1, 0), l10)
    the_layout.copy_layer(the_layout.layer(2, 0), l10)
    

    Matthias

  • Hi Matthias,
    Thanks for the workarounds.
    Thanks even more for the truly awesome application. It is incredibly useful to me. :-)

  • You're welcome :)

    The problem is solved and I will release the fix in the next minor release. Thanks for reporting that issue!

    Kind regards,

    Matthias

  • The benefit of this bug is that I switched to using copy_layer() function workaround that you provided. This runs dramatically faster than a cell by cell Boolean OR operation. :-)

Sign In or Register to comment.