Converting a specific PCell to static

edited May 2022 in Python scripting

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

  • Hello!
    Going off of this discussion..
    Is there a way to do the opposite? Go from a static cell to a PCell through Python scripting? I haven’t been able to find any “convert_to_pcell” functions or maybe I’ve overlooked something.
    Thanks in advance!

  • No, that's not possible. A PCell is basically code that generates geometry (polygons, boxes etc.).

    I assume what you are looking for is something that creates code to reproduce a specific geometry. But that code would only generate code for this specific geometry that there is not much gained. A PCell does much more: as the "P" stands for "parametric", it will generate geometry according to specific parameters (e.g. width and length of a MOS transistor). So it offers flexibility which you cannot derive from a static layout example.

    Matthias

Sign In or Register to comment.