Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Custom query in a python script / bugs

edited April 13 in KLayout Support

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

query = "select cell.name from instances of .."
result = [item.data() 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 cell.name 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 cell.name 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?
Olivier

Comments

  • edited April 13

    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 13

    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 item.data() unduly returns None. So if there is only one cell instance matching the query, I get result = [None], which is disappointing.

    query = "select cell.name from instances of .. where cell_name ~ 'CellName1'"
    result = [item.data() 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,

    Matthias

Sign In or Register to comment.