Converting a specific PCell to static

Hello,

Considering the following cells hyierarchical structure:

-Top cell
-------------Chip cell
--------------------------Chip element cell
--------------------------Chip element cell
--------------------------Chip element cell
--------------------------...

I am trying to convert the PCell called "Chip cell" to static. My problem is that I don't know how to access the cell index of that specific cell.

At the moment I am using the following code to create the static version, then translate the instances and finally delete the original PCell:

        ly = self.layout
        for cell_index in ly.top_cell().each_child_cell():
            chip_cell_index = cell_index
            break
        static_cell_index = ly.convert_cell_to_static(chip_cell_index)

        for inst in ly.cell(chip_cell_index).each_inst():
            if inst.cell_index == chip_cell_index:
                inst.cell_index = static_cell_index

        ly.delete_cell(chip_cell_index)

Where I used the for loop to access the desired cell index since the only child of Top cell is Chip cell. However, it's not working, and even if it did I am sure there is a cleaner way to do it.

Comments

  • Hi @DanieleIQM,

    I think your code will work, if you replace this line:

            for inst in ly.cell(chip_cell_index).each_inst():
    

    by:

            for inst in ly.top_cell().each_inst():
    

    However, I have a different proposal to make.

    PCell instances are kind of specific - every PCell instance can be different from the other one as potentially every instance can be different parameters.

    Technically, all PCell instances with a specific set of parameters are mapped to one (normal) cell which internally acts as cache and is linked to the PCell so it can be updated when the PCell or the parameters change. But that is an implementation detail and you should not rely on that.

    This means: when converting PCells to static cells, each PCell instance has to be converted into it's own static cell as potentially every instance is different from the next one. So beware: if you have many PCell instances, you will generate many different static cells.

    To do so, you have to iterate over the instances of the top cell and call "convert_to_static" on them. It's a good practice not to manipulate the layout while iterating because of side effects, so this is the code I propose:

    import pya
    
    ly = pya.CellView.active().layout()
    
    # collect the cells to convert:
    insts_to_convert = []
    for inst in ly.top_cell().each_inst():
      if inst.is_pcell():
        insts_to_convert.append(inst)
    
    for inst in insts_to_convert:
      inst.convert_to_static()
    

    BTW: if you simply want to get rid of all PCells when exporting a layout for someone else, the easiest solution is to write a layout to GDS with "context info off". This will remove the meta information kept inside GDS for identifying the PCells and produce a clean layout.

    Matthias

Sign In or Register to comment.