How to iterate through cells & perform sizing operation

Dear Klayout community,
I'm trying to write a ruby script that increases size by 1nm then decreases by 1nm to close gaps between polygons. I want to do it one hierarchy level below the top cell.

The following works fine if I just want to do it in the top cell:

resizeBy=1.nm

layers = {
   lay1: [16,28], 
   lay2: [17,28], 
   lay3: [18,28], 
   lay4: [19,28], 
   lay5: [95,28], 
   lay6: [21,33], 
   lay7: [71,0]}

layers.slice(:lay1, :lay2, :lay5).each do |name, indices|
   input(*indices).size(resizeBy).size(-resizeBy).output(*indices)
end

I tried to figure out how to iterate through cells. The following code doesn't work: I think it's iterating through the cells but each time placing the output on the top cell.

active_layout = RBA::CellView::active.layout

resizeBy=1.nm

layers = {
   lay1: [16,28], 
   lay2: [17,28], 
   lay3: [18,28], 
   lay4: [19,28], 
   lay5: [95,28], 
   lay6: [21,33], 
   lay7: [71,0]}
active_layout.top_cell.each_child_cell do |cell|
cellsource=source.cell(cell)
   layers.slice(:lay1, :lay2, :lay5).each do |name, indices|
      cellsource.input(*indices).size(resizeBy).size(-resizeBy).output(*indices)
   end
end

Can someone suggest what I need to do differently or point me to the right part(s) of the Klayout manual?

Thank you!
Jon

Comments

  • @LaserJon

    The DRC scripts you're using are performing flat by default.

    You can enable hierarchical processing by using the "deep" command right at the beginning of the script.

    Deep mode however does not simply iterate over the cells. That's far too naive. A cell may have a shape, and this shape may be extended by an adjacent shape from outside the cell. So in deep mode, a cell's shapes are always seen in a context. This means, if the cells are isolated, the context is empty and the algorithm degenerates to an (elaborate) iteration. In the general case however, the algorithm has to make a decision how to treat the same cell in different contexts. In the size case this means that the part common to all cell contexts is kept inside the cell and all context-specific parts are propagated up in the hierarchy.

    If you don't want this, there is a mechanism called "cheat" (https://www.klayout.de/doc-qt5/about/drc_ref_global.html#k_17), but I'd not recommend that if you're interested in physically relevant results.

    Matthias

  • @Matthias,

    Just adding the "deep" command to the top of my first script got the result I needed. I'm new to Klayout's scripting but see that it's going to be very useful. Thank you!

    Jon

Sign In or Register to comment.