Custom query in a python script / bugs

edited April 2019 in KLayout Support

I observe some problems with the "custom queries" in this script:

query = "select from instances of .."
result = [ for item in pya.LayoutQuery(query).each(layout)]

Problem 1

The result of this script is result = [['top'], ['Shape'], ['Square*(200*nm)'], ..., , ['Square*(200*nm)'], None]. Surprisingly, the last element of the list is None. I don't understand what it corresponds to and I think it should be absent from the list.

Problem 2

I now use a more specific selection:
query = "select from instances of .. where cell_name ~ 'Square*'"
for which I adequately get result = [['Square*(200*nm)'], ..., , ['Square*(200*nm)'], None] (except for the last item that is strange).

Unfortunately, if I specify the name of my cell named 'Shape' instead of 'Square':
query = "select from instances of .. where cell_name ~ 'Shape*'"
I now get result = [None], which is not satisfactory because I expected to find my instance named 'Shape' (note that this instance was adequately found in the output of Problem 1). At the same time, the "Search and Replace" from the GUI finds the 'Shape' instance adequately.

Can someone confirm that these are bugs?


  • edited April 2019

    For problem 1, I add the information that my cell 'Square*(200*nm)' is instantiated as an array.
    It seems that in result, one output is replaced by None.

  • edited April 2019

    After more testing, I think that problems 1 and 2 are caused by the same bug. The bug is that in a query like below, the last unduly returns None. So if there is only one cell instance matching the query, I get result = [None], which is disappointing.

    query = "select from instances of .. where cell_name ~ 'CellName1'"
    result = [ for item in pya.LayoutQuery(query).each(layout)]

    Olivier (KLayout 0.25.8)

  • Thanks for the bug report on GitHub! It looks like an issue with the Python iterator protocol (or the way I understand that). I'll take care of this.

    Kind regards,


Sign In or Register to comment.