App crashes without much info when running python script with multiple cell instances

edited December 2024 in Python scripting

Hi! I'm creating a layout by inserting some CellInstArrays (via python scripting) and at some point the GUI app crashes.
It look like it crashes only when using the zoom wheel and the hierarchy level is set to 2. In fact, if I flatten all cells from the layout object with prune = True, the problem seems to disappear.

The only stack trace I get is this (no prompt message):


Does this error sound familiar to you @Matthias ? could I run Klayout in a single thread perhaps?

This happens in both 0.28.6 and 0.29.10 versions, under Windows and under Linux (through WSL)

For more conext, this is how I'm adding library cells from python, am I doing it in the right way?

import pya
pya.MainWindow.instance().create_layout(1)
MAIN_LAYOUT = pya.CellView.active().layout()
TOP = MAIN_LAYOUT .create_cell("TOP")
pya.CellView.active().cell = MAIN_LAYOUT.cell("TOP")

# Adding library cell
lib = pya.Library.library_by_name("MyLib", "MyTech")
lib_layout = lib.layout()
my_cell = lib_layout.cell("MyCell")
added_cell = MAIN_LAYOUT.add_lib_cell(lib, my_cell.cell_index())
new_cell_inst = pya.CellInstArray(added_cell, pya.DCplxTrans())
TOP.insert(new_cell_inst)

# Adding library pcell
pcell_lib = pya.Library.library_by_name("MyLibOfPCells", "MyTech")
pcell_lib_layout = pcell_lib.layout()
pcell_dcl = pcell_lib_layout.pcell_declaration("MyPcell")
added_pcell= MAIN_LAYOUT.add_pcell_variant(pcell_lib, pcell_dcl.id(), {})
new_pcell_inst = pya.CellInstArray(added_pcell, pya.DCplxTrans())
TOP.insert(new_pcell_inst )

Comments

  • No, that does not sound familiar. The message can have manifold reasons. Usually that happens if shapes or instances get removed while some code is still accessing them.

    I don't have the "MyLib" library you're using. If you're providing code, please provide complete examples. I assume your library internally instantiates other cells and that causes the issue. But without the code for "MyLib" I cannot assist in debugging.

    I rewrote you sample to a simple PCell instantiation of the CIRCLE PCell from the Basic library. Please note the simplified version of the code. You don't need to use "add_pcell_variant" for example. "create_cell" does that for you:

    import pya
    
    cell_view = pya.MainWindow.instance().create_layout(1)
    
    main_layout = cell_view.layout()
    # create layer 1/0
    main_layout.layer(1, 0)
    top = main_layout.create_cell("TOP")
    cell_view.cell = top
    
    # Adding library pcell
    # This is Basic.CIRCLE on layer 1/0 with a radius of 5µm
    added_pcell = main_layout.create_cell("CIRCLE", "Basic", { "layer": pya.LayerInfo(1, 0), "actual_radius": 5.0 })
    new_pcell_inst = pya.CellInstArray(added_pcell, pya.DCplxTrans())
    top.insert(new_pcell_inst)
    
    # make sure, layer 1/0 is shown in the layer list
    cell_view.view().add_missing_layers()
    

    I don't see any issues with the results of that setup.

    Matthias

  • Thank you very much @Matthias for your help; your work and dedication are excellent. Unfortunately, I cannot share the full code as it is protected by industrial property, and we have also built a rather complex framework on top of your Python API/wrapper, which would be difficult to share here. I will try your suggestion and get back to you as soon as possible. Thank you again, and Happy New Year!

Sign In or Register to comment.