It looks like you're new here. If you want to get involved, click one of these buttons!
I am working to fabricate a few thousand identical devices on a wafer and add a text PCELL to each device cell which will denote its unique serial number (e.g., from 0001 to 9999). Having a unique serial number is useful for diagnosing issues post fabrication.
So far, I drew up a device cell and I filled a 6 inch wafer layer with it using the Fill Tool. But, I am having trouble figuring out how to add the serial number text PCELL. Since there are many devices, I cannot do this by hand.
I have two ideas for how to script these serial numbers with python:
Which method is better, and how would I implement it in a script? For reference, I am attaching an example GDS file showing how far I have gotten.
Side note: This problem has come up in this topic about 6 years ago. The conclusion there was a rather ugly and inconvenient solution of using excel files. I would like to instead do everything through a python script, since Klayout's python scripting has come a long way since 2015. Moreover, my actual device has 3 different subparts which each need their own serial number, so this excel solution is not robust enough.
Comments
Hi @fruitspunchsamurai
The second method will not work as you cannot change a PCell per instance. You can change it only once which will make all device instances use the same number.
So the first method is the only way to do that. The procedure is this:
With these assumptions here is a script which generates the serial number PCells:
Matthias
P.S: after posting this script I noticed you wanted to have Python. This script is Ruby. It's straightforward to translate except the sorting function for which no equally elegant solutions exists in Python AFAIK.
Thank you Matthias! Your script worked very nicely, I have converted it to Python below for others to benefit from and put it also in the attached zip file.
PS There is a very short one liner to do the sorting in python, which IMHO is more elegant than in Ruby
@fruitspunchsamurai Thank you for the conversion.
But I disagree in one respect: Python's sort key feature is not a compare function, but just a key selector. I found that quite limited. If you insist on a challenge, here is the short Ruby version
With a bit of monkey patching you can even sort by Points directly:
I actually thought that the starship operator is provided automatically by Ruby but that's not the fact. I'll need to check that.
Best regards,
Matthias
@Matthias First off thank you for the great solution above, I was able to get it to function if the Cell(Chip) is only one level below the top layer in the hierarchy. If the cell is more than one layer lower I cannot get it to function. Please bear with me as this is my first time using macros in Klayout. I assume I need to make a change at wafer=ly.top_cell but I cant figure out how to change it. Any advice you can give here would be greatly appreciated.
Update: by changing line 2 to wafer = ly.cell("cell name") that allows me to move down in the hierarchy. However I still cannot get it to identify cells nested inside of other cells. Any advice on how to achieve that?
Hi @JWK,
You mean, you like to have the label inside the chip cell? That is not possible as every chip has to get it's own label and a single chip cell is the same everywhere. Except if you turn every chip instance into a separate cell.
With the original code above, a single overlay cell is generated with the IDs that covers the whole wafer. This cell has to be on top level to sit in the same coordinate system as the wafer.
To continue this discussion, a sample and more detailed explanation of what you want to achieve was helpful.
Matthias
Let me suggest that generating the "numbering" might be
better off as a separate exercise divorced from the hierarchy.
Like, determine the "placement grid" for texts, make a routine
that indexes content along with setpping coords, and place
the instance, and on to the next.
Then place that "reticle-scale label" over the whole "real
stuff" layout.
I don't think you even need PCells if you have the 0 - 9
character layouts as "0 X" data and just rack up the sub-origins
per grid-step (maybe even easier if "0" is "000" and "1" is "001",
no need to even figure out justification - just pick digits and
place relative to main step grid?