How can I get the information of the instance?

Hello everyone,

I want to get the information of all the instance in the topcell, such as name, location, width, height and pin-information, etc.
cell name : r493/FE_OFC16857_n623
position : 126.920 26.180 127.490 27.580
type: BUF_X1
fanin pins: A
fanout pins: Z )

How can I get them from the gds files using python script?



  • @blues That's not a GDS instance information. GDS does not have

    • Instance names ("cell name")
    • Cell types (I assume that is supposed to be the cell name)
    • Pin information

    GDS is a pure layout format. It can give you the location of a cell, that's it. LEF/DEF can give you that information for example.


  • @Matthias
    Hi Matthias,

    Thanks for your help.

    I still want to know that may I get the location and size of the pin from the gds file?

    Not like the pin information above(fanin pins: A fanout pins: Z ), just the physical information of pin-box.


  • This depends on the use of GDSII layers in the design which is determined by the PDK. Sometimes people use a dedicated GDSII datatype for the pins, and if that's being done it's easy to find them, just write out the boxes for this layer, and look for the texts on that layer if they are being used.

  • @ejprinz
    Thanks for your kind reply.

    But I could still not find a way to achieve it.

    It seems that the dedicated GDSII datatype is not used in my file.

    Could you give me more details?


  • edited February 2023

    First look at the GDSII file in KLayout in GUI mode. Go to a hierarchy of "1" (e.g. hit the "1" key). Now you should see all instances in the top cell, plus you'll see any other shapes also included in the top cell (in the "Layers" window, hit "Show All"). You can then hit "+" and go down the hierarchy until you are at the bottom and see no instances anymore, only shapes.
    If you need more info you need to know more about your GDSII file. You need a map file from the PDK which tells you what each GDSII layer/datatype (both integer numbers) means. Typically this is a correspondence of (Layer Name, Layer Purpose, GDSII Layer #, GDSII Datatype). If you find such a map file in the PDK, convert it to a KLayout .lyp file. Then you see the info in the "Layers" window.
    Which layers are pins and ports is a convention in the PDK. A pin or port is typically a box on a specific layer with a GDSII text either on the same or a different layer. The LVS tool then can use the text labels and annotate circuits with it.
    Once you understand what you see in the GUI, scripting it is straightforward. Something like:

    import klayout.db as kl
    lyo = kl.Layout()
    layer_map ='Your GDSII or OASIS file name path')
    # In this case the pin shapes & text are on the same GDSII layer
    pin_shape_layer = lyo.layer(13, 0)
    pin_text_layer = lyo.layer(13, 0)
    # Ideally there is only one top cell. If not iterate over all of them.
    top_cells = lyo.top_cells()
    for top_cell in top_cells:
        for first_level_cell_index in top_cell.each_child_cell():
            first_level_cell = lyo.cell(first_level_cell_index)
            # Print all instances
            for inst in first_level_cell.each_inst():
                print(f'{} / {}, ({}, {inst.to_s()}, {inst.trans.to_s()})')
            # Print all top level shapes for ports
            for shp in first_level_cell.shapes(pin_shape_layer).each():
                if shp.is_box():
                    print(f'{} / {}: Shape {shp.to_s()}')
            # Print all top level texts for ports
            for shp in first_level_cell.shapes(pin_text_layer).each():
                if shp.is_text():
                    print(f'{} / {}: Text {shp.to_s()}')

    At this point if you want to add something you need to read the docs. Also use a good Python IDE like VS Code or Neovim.

Sign In or Register to comment.