Semi hierarchical layer operations via RBA/DRC code

edited March 2017 in KLayout Development

Hi Matthias,

I remember that you mentioned the layer operating functions in Edit=>Layer=>BooleanOperations/Size with semi hierarchical option is different from the DRC boolean engine(flat mode) and working with it, Is it possible to run semi hierarchical layer operations via RBA or DRC code now?

In some case I hope to use this function to do layer operations in batch mode to avoid typo~

Best Regards,

chhung

Comments

  • edited March 2017

    Hi chhung,

    "semi-hierarchical" mode is not available for DRC. I can be emulated with RBA, but it's easier with the upcoming 0.25 version. For this version there will be a constructor RBA::Region that takes a Shapes container:

    lv = RBA::LayoutView::current
    ly = lv.active_cellview.layout
    
    # Sample: do a per-cell XOR between layers 16 and 23 and put the results to 100
    l1 = ly.layer(16, 0)
    l2 = ly.layer(23, 0)
    lout = ly.layer(100, 0)
    
    ly.each_cell do |cell|
      # Do a XOR for each cell individually
      r1 = RBA::Region::new(cell.shapes(l1))   # requires 0.25
      r2 = RBA::Region::new(cell.shapes(l2))   # requires 0.25
      cell.shapes(lout).insert(r1 ^ r2)
    end
    
    lv.add_missing_layers
    

    With version <0.25 you'll need to emulate the XOR with RBA::ShapeProcessor:

    lv = RBA::LayoutView::current
    ly = lv.active_cellview.layout
    
    # Sample: do a per-cell XOR between layers 16 and 23 and put the results to 100
    l1 = ly.layer(16, 0)
    l2 = ly.layer(23, 0)
    lout = ly.layer(100, 0)
    
    sp = RBA::ShapeProcessor::new
    
    ly.each_cell do |cell|
      # Do a XOR for each cell individually
      sp.boolean(ly, cell, l1, ly, cell, l2, cell.shapes(lout), RBA::EdgeProcessor::ModeXor, false, true, false)
    end
    
    lv.add_missing_layers
    

    Matthias

  • edited March 2017
    Hi Matthias,

    Thanks for your code, it works like a charm.

    And another two questions. XD

    According to the document in http://www.klayout.de/doc/code/class_ShapeProcessor.html , the first false option is "hierarchical: Collect shapes from sub cells as well", once I change it to true, the program stop running, is it because the program is running on "layout.each_cell" and should not set the hierarchical to true ?

    If two layer operations are independence(for ex: B = Sizing Up A 0.1um ; C = Sizing Up A 0.2um), could I parallel run the two operations to reduce run time?

    Thank you~ :D
    --
    chhung
  • edited November -1

    Hi chhung,

    Setting the "hierarchical" flag to true will make the boolean collect all shapes include the ones from the child cells. That's what we don't want to do if we iterate over the cells independently.

    And regarding parallel runs: I'm sorry, but multi core usage is something for C++ and rather tricky on a complex data structure such as a layout object. No way to do this in Python or Ruby currently.

    Matthias

  • edited November -1
    Hi Matthias,

    If the hierarchy is:
    Cell TOP (With layer 1/0 pattern) => Cell A (With layer 1/0 pattern)
    Once we tried to TOP OR A, the result is correct, however if we tried to TOP NOT A or TOP AND A with hierarchical=false, due to the layer 1/0 pattern are in different cells, the boolean result isn't what we want.

    So if we want to avoid this condition, we have to set hierarchical=true, and only run it on topcell, not layout.each_cell, is it correct ?

    Best Regards,
    --
    chhung
  • edited November -1

    Hi chhung,

    the "semi-hierarchical" approach is a very weak approximation, so please don't expect the same results as "hierarchical=true". It is valid only, if all inputs for an operation are available within the same cell and if there no cross-hierarchy interactions that would modify the output. That's why I call it "semi-hierarchical": it considers cells to be independent entities and assumes that each cell can be considered isolated from child, sibling or parent cells.

    There are very few good use cases for this. One example is an oversize of via layers. The OR operation is trivial, so it works out of the box in semi-hierarchical mode. For other operations this may or may not be the case. I don't know your actual use case, so I can't advise here.

    Bottom line is that this mode is rarely applicable. That's why it's not part of the DRC feature.

    Matthias

  • edited November -1
    Hi Matthias,

    Thanks for the explanation in detail, now we know the limitation of semi-hierarchical. We would only use this function carefully on layer OR/Sizing operations. :)

    Best Regards,
    --
    chhung
Sign In or Register to comment.