TypeError: Layout.multi_clip_into()

 blist = getRegionbbox(regions)
 nlayout = pya.Layout.new()
 ncell = layout.multi_clip_into(tcell.cell_index(), nlayout, blist)

The above code works with previous klayout versions. But with 0.28.8 amd 0.28.9. It triggers the following TypeError. How may I solve this? thx!

TypeError: Ambiguous overload variants - multiple method declarations match arguments in Layout.multi_clip_into

Comments

  • I may be able to help if you tell me what object getRegionbbox returns. This is not a complete sample.

    0.28 got overloads accepting micron-unit boxes. This means that with an empty list of boxes there will be an ambiguity. If that is your case, you will need to guard this function against empty lists of boxes:

    if len(blist) > 0:
      ncell = layout.multi_clip_into(tcell.cell_index(), nlayout, blist)
      ...
    

    Matthias

  • Thanks Matthias. getRegionbbox can return empty list and cause ambiguity. So, your suggestion to guard this function works in my case!

  • I also run into this p.holes() Runtime Error from multi_chip_into when I applied it to certain layers. Any suggestions how may I debug this issue?

    ncell = layout.multi_clip_into(tcell.cell_index(), nlayout, blist)
    

    RuntimeError: Internal error: src/db/db/dbPolygon.h:2473 p.holes () == 0 was not true in Layout.multi_clip_into

  • That is a problem. I assume you're trying to use the multi_clip_into on a layer that has been generated by some operation generating polygons with holes. Direct input from GDS does not produce such polygons, but they may be generated by boolean operations for example.

    A complete code sample is very helpful to give further advice!

    Matthias

  • I have some overlapping polygons from the GDS. In order to calculate the total area by these polygons, I did a region.merge() to eliminate these extra polygons. So, I suppose the merge operation will create polygons with holes. Do you have any suggestion to remove these overlapping polygons for the purpose of area calculation so that I can avoid a merge? If not, is there is any operation I can break down these merged regions into simple polygons so that the is no hole? The code I used to merge and to calculate the area is as followed. Thx!

    Merge

    region = pya.Region(tcell.begin_shapes_rec(i))
    region.merge()
    tcell.layout().clear_layer(i)
    tcell.shapes(i).insert(region)

    Area

    area = 0
    for c in nlayout.each_cell():
    ...shapes1 = c.shapes(i)
    ...for shape in shapes1.each():
    ......area += shape.area()

  • After I read in the GDS, I also flattened the top cell. Actually, I would prefer not to do this step, but I was uncertain if my merge and area code will work nicely with multi_chip_into() and what extra steps are needed to handle the hierarchical data:

    Flatten

    t = layout.top_cell().cell_index()
    cell = layout.flatten(t, -1, True)

  • I have created to ticket to deal with support for polygons with holes inside the clip functions: https://github.com/KLayout/klayout/issues/1407

    But you don't need to merge in order to compute the area:

    region.area()
    

    will simply give you the area post-merge without changing the polygons.

    But I don't get the full picture. When do you do the flatten? After clip? No need to do so - clip will generate a new cell hierarchy very efficiently. Region objects work on hierarchical data although internally they will flatten unless they are used with hierarchy support (DeepShapeStore class).

    Again, a complete sample was helpful.

    Matthias

  • I have this same problem right now as well,
    I have a cell that I flattened,
    extracted a region from all shapes on the layer I wanted
    and then merged the region.
    deleted all the original unmerged shapes from the cell/layer
    inserted my merged region into that cell/layer

    now I'm trying to clip subsets out of that cell and I'm getting

    Internal error: ../../../src/db/db/dbPolygon.h:2464 p.holes () == 0 was not true in Layout.clip
    (eval):1

    @Matthias

  • @rrzzxx22 Which version are you using? I have not found any version that features an assertion at the line you give. Clip function support for polygons with holes should be there since version 0.28.10.

    Matthias

  • edited January 30

    @Matthias I am using KLayout 0.28.7 updating now and will retry my script.

    Updating to 0.28.15

    Update: fixed my issue, thank you so much.

    Sorry I didn't try that myself first. Really appreciate you taking the time.

  • Very good. Thanks for letting us know :)

    Regards,

    Matthias

Sign In or Register to comment.