wrong size of shapes

edited July 2018 in KLayout Support

I found size() for shapes return wrong value.
See below code, shapes.size() return 1.
However, it could find 7 if loopped with shapes.each().

import pya

nly = pya.Layout(False)
top_cell = nly.cell(0)
ss = top_cell.shapes(0)
print(top_cell.basic_name(), ss.size())

slist = [x for x in ss.each()]
print(top_cell.basic_name(), len(slist))

code results:

top 1
top 7

Is it a bug?



  • edited July 2018

    Hi Dion,

    I don't have your file, but there is a specific issue with OASIS and shapes: OASIS allows representation of shapes as shape arrays. That means a single object represents multiple effective shapes.

    "size" is a quick method that does not do expansion of the shape arrays. So a single shape array is one object, but may represent multiple shapes when they are delivered individually with "each". This explains the difference.

    The size count is correct if

    • The file format is GDS or any other format except OASIS
    • The layout is created in editable mode (True for the argument to the Layout constructor)

    I agree this is a bit unintuitive. Internally, shape arrays can either be treated as single or multiple objects, but I did not want to overload the API with such details. Basically "size" is borrowed from the internal API with the array perspective.

    I can change the "size" behaviour to reflect the real number of shapes after expansion with "each". This will make "size" a bit slower, but I don't think this will be noticeable in a Python script.

    Kind regards,


  • Hi Matthias,
    You are correct.
    I reviewed the oasis case again and found the polygons in this case are same.
    So oasis use displacement record to compress it.

    I think it's efficient to represent multiple shapes as oasis.
    So I have another question.
    Could I get the oasis shapes displacement or array in python script?


  • Hi Dion,

    no sorry, there is no way to get the real number of shapes yet. If you like, you could file a bug on GitHub https://github.com/klayoutmatthias/klayout/issues/152. Please add whatever you like to mention there.



Sign In or Register to comment.