Extracting PCell parameters of netlist subcircuit cells

edited October 9 in Python scripting

I manage to generate netlist via python API, browse the nets, pins in the net and subcircuits of the pins. Now I would like to access the cell referenced by the subcircuit and the pcell parameters of the cell. How to do that? I have tried cell_index=pin_ref.subcircuit().circuit_ref().cell_index to get the cell index, but these cell indexes do not seem to correspond to the layout.cell(cell_index) DB. Sometimes the cell_index does not even exist in the layout. Also layout.cell(pin_ref.subcircuit().circuit_ref().cell_index).name) gives a completely different result than pin_ref.subcircuit().circuit_ref().name.

Here is a full example of my test code

import pya

layout = ...
top_cell = layout.top_cell()

shapes_iter = layout.begin_shapes(top_cell, layout.layer(foo))

ltn = pya.LayoutToNetlist(shapes_iter)

connector_region = ltn.make_layer( layout.layer(foo, "connector")
ltn.connect(connector_region)
ltn.extract_netlist()
netlist = ltn.netlist()

for circuit in netlist.each_circuit():
    print(circuit.name)

circuit = netlist.circuit_by_name(bar)

used_cells = set()
for net in circuit.each_net():
    print("net:", net.expanded_name())
    for pin_refin net.each_subcircuit_pin():
        try:
            print("- pin:", pin_ref.pin().name(), ":", pin_ref.pin().expanded_name(), "subcircuit:", pin_ref.subcircuit().name, ":", pin_ref.subcircuit().expanded_name(), "subcircuit ref:", pin_ref.subcircuit().circuit_ref().name, "subcircuit cell id",  pin_ref.subcircuit().circuit_ref().cell_index, "cell name", layout.cell(pin_ref.subcircuit().circuit_ref().cell_index).name)
        except:
            print("- pin:", pin_ref.pin().name(), ":", pin_ref.pin().expanded_name(), "subcircuit:", pin_ref.subcircuit().name, ":", pin_ref.subcircuit().expanded_name(), "subcircuit ref:", pin_ref.subcircuit().circuit_ref().name, "subcircuit cell id",  pin_ref.subcircuit().circuit_ref().cell_index, "not present in the layout")
        used_cells.add(pin_ref.subcircuit().circuit_ref().cell_index)
    print()

print(used_cells)

Comments

  • edited October 9

    Now I figured out that the cell indexes actually refer to the internal_layout and I can get the correct cell name from
    ltn.internal_layout().cell(pin_ref.subcircuit().circuit_ref().cell_index).name.
    However, these are static copies of PCells. Is there any way to retrieve a reference to the original PCell such that I could obtain vales of the PCell parameters?

  • edited October 9

    I think I figured it out :)
    name=pin_ref.subcircuit().circuit_ref().name
    gives a name which also exists in the layout and the PCell can be retrieved by
    cell = layout.cell(name).

  • Yes, that's one option.

    You can also use

    cm = ltn.const_cell_mapping_into(original_layout, original_top_cell)
    

    to get a CellMapping object. With this you can get the corresponding original cell index this way:

    if cm.has_mapping(internal_cell):
      original_cell = cm.cell_mapping(internal_cell)
    else:
      ... no original cell for this internal one ...
    

    There is a reason why there is an internal layout: in the presence of clipping or hierarchy path enabling/disabling the internal layout will deviate in structure from the original one and cell variants may be present there. In this case, there is no non-ambiguous mapping back to the original layout. These cases will trigger the "else" path above.

    Matthias

  • Thanks! I made use of the cell_mapping.

    Just for record for future readers, in your example the internal_cell and original_cell are not Cell objects but cell indices.

        if cm.has_mapping(internal_cell.cell_index()):
                original_cell_index = cm.cell_mapping(internal_cell.cell_index())
                original_cell = layout.cell(original_cell_index)
    
Sign In or Register to comment.