Converting PCells to static cells

Hello,

I'm trying to convert PCells to static cells with the Ruby code below:

`
module MyMacro

include RBA

layout_view = Application.instance.main_window.current_view
layout = layout_view.active_cellview.layout

# Convert PCells to "static cells"

layout.each_cell do |cell|

    if !cell.is_pcell_variant?

        cell.each_inst do |instance|

            if instance.is_pcell?

                puts "PCell instance \" #{instance.cell.name}\" converted to static cell..."

                instance.convert_to_static

            end #  if

        end #  each_inst

    end #  if

end # each_cell

end
`

It's crashing on me and I don't have a clue why. Some suggestions?

Cheers,

Tomas

Exception code: 0xc0000005
Program Version: KLayout 0.25.8 (2019-02-23 rd3f93cc) AMD64

Backtrace:
0x14c3255 - (klayout_db.dll) +602709
0x159cca4 - (klayout_db.dll) +1494180
0x196510 - (klayout_rba.dll) +25872
0x1b217e - (klayout_rba.dll) +139646
0x67ae6cc6 - (x64-msvcrt-ruby240.dll) +1469638
0x67aed16c - (x64-msvcrt-ruby240.dll) +1495404
0x67af23f4 - (x64-msvcrt-ruby240.dll) +1516532
0x67afae2c - (x64-msvcrt-ruby240.dll) +1551916
0x679e3698 - (x64-msvcrt-ruby240.dll) +407192
0x19ecb1 - (klayout_rba.dll) +60593
0x195921 - (klayout_rba.dll) +22817
0x1b3ebe - (klayout_rba.dll) +147134
0x67ae6cc6 - (x64-msvcrt-ruby240.dll) +1469638
0x67aece04 - (x64-msvcrt-ruby240.dll) +1494532
0x67af23f4 - (x64-msvcrt-ruby240.dll) +1516532
0x67afae2c - (x64-msvcrt-ruby240.dll) +1551916
0x679e3698 - (x64-msvcrt-ruby240.dll) +407192
0x19ecb1 - (klayout_rba.dll) +60593
0x195921 - (klayout_rba.dll) +22817
0x1b40ce - (klayout_rba.dll) +147662
0x67ae6cc6 - (x64-msvcrt-ruby240.dll) +1469638
0x67af43e0 - (x64-msvcrt-ruby240.dll) +1524704
0x67aece04 - (x64-msvcrt-ruby240.dll) +1494532
0x67af23f4 - (x64-msvcrt-ruby240.dll) +1516532
0x67af2c68 - (x64-msvcrt-ruby240.dll) +1518696
0x67af30e5 - (x64-msvcrt-ruby240.dll) +1519845
0x67af4de4 - (x64-msvcrt-ruby240.dll) +1527268
0x67af64d7 - (x64-msvcrt-ruby240.dll) +1533143
0x67af6d25 - (x64-msvcrt-ruby240.dll) +1535269
0x679e3698 - (x64-msvcrt-ruby240.dll) +407192
0x19eabe - (klayout_rba.dll) +60094
0x19ebde - (klayout_rba.dll) +60382
0x6397ea - (klayout_lym.dll) +38890
0x6a591c8b - (klayout_lay.dll) +334987
0x6a5920a2 - (klayout_lay.dll) +336034
0x6a673b44 - (klayout_lay.dll) +1260356
0x668e82bb - (Qt5Core.dll) +1737403
0x2074af1 - (Qt5Widgets.dll) +1002225
0x2075d25 - (Qt5Widgets.dll) +1006885
0x2075eb5 - (Qt5Widgets.dll) +1007285
0x213262e - (Qt5Widgets.dll) +1779246
0x1fce0e8 - (Qt5Widgets.dll) +319720
0x213270c - (Qt5Widgets.dll) +1779468
0x1f8a3bc - (Qt5Widgets.dll) +41916
0x1f905c3 - (Qt5Widgets.dll) +67011
0x6a54b9fb - (klayout_lay.dll) +47611
0x668c7812 - (Qt5Core.dll) +1603602
0x1f8eca9 - (Qt5Widgets.dll) +60585
0x1fe4667 - (Qt5Widgets.dll) +411239
0x1fe6edb - (Qt5Widgets.dll) +421595
0x1f8a3bc - (Qt5Widgets.dll) +41916
0x1f8f746 - (Qt5Widgets.dll) +63302
0x6a54b9fb - (klayout_lay.dll) +47611
0x668c7812 - (Qt5Core.dll) +1603602
0x29964fc - (Qt5Gui.dll) +156924
0x2997c25 - (Qt5Gui.dll) +162853
0x297cdde - (Qt5Gui.dll) +52702
0x6690effa - (Qt5Core.dll) +1896442
0x7ff9e1e874d6 - (USER32.dll) +95446
0x7ff9e1e86ff2 - (USER32.dll) +94194
0x6690e683 - (Qt5Core.dll) +1894019
0x6dd32cd5 - (qwindows.dll) +470229
0x668c6a5d - (Qt5Core.dll) +1600093
0x668cd827 - (Qt5Core.dll) +1628199
0x6a54ea5e - (klayout_lay.dll) +59998
0x6a553049 - (klayout_lay.dll) +77897
0x401f28 - (klayout_app.exe) +7976
0x191702 - (klayout_rba.dll) +5890
0x67ae6cc6 - (x64-msvcrt-ruby240.dll) +1469638
0x67af43e0 - (x64-msvcrt-ruby240.dll) +1524704
0x67aed16c - (x64-msvcrt-ruby240.dll) +1495404
0x67af23f4 - (x64-msvcrt-ruby240.dll) +1516532
0x679dff4e - (x64-msvcrt-ruby240.dll) +393038
0x679e2b2f - (x64-msvcrt-ruby240.dll) +404271
0x19836f - (klayout_rba.dll) +33647
0x401a7a - (klayout_app.exe) +6778
0x4013f8 - (klayout_app.exe) +5112
0x4014eb - (klayout_app.exe) +5355
0x7ff9df6e7974 - (KERNEL32.DLL) +96628
0x7ff9e225a2f1 - (ntdll.dll) +369393

Comments

  • @tomas2004 First of all iterating while manipulating is always a bad idea. When you do "convert_to_static", cells will be created and others removed. When you iterate, you may come across cells which have already been removed.

    Usually it's a good way to collect objects first and then manipulate them.

    In this case there is a nasty pitfall - if your PCells internally have other PCells and if you convert the upper one to static the internal ones are gone too, so instances you have stored are invalidated this way.

    The solution is to traverse top-down and stop on PCells. Here is a sample code:

    ly = RBA::CellView.active.layout
    cell = RBA::CellView.active.cell
    
    def collect_pcell_instances(cell, seen, pcell_instances)
      seen[cell.cell_index] = true
      cell.each_child_cell do |child_cell_index|
        child_cell = cell.layout.cell(child_cell_index)
        if !child_cell.is_pcell_variant? && !seen[child_cell_index]
          collect_pcell_instances(child_cell, seen, pcell_instances)
        end
      end
      cell.each_inst do |inst|
        if inst.is_pcell?
          pcell_instances << inst
        end
      end
    end
    
    seen = {}
    pcell_instances = []
    collect_pcell_instances(cell, seen, pcell_instances)
    
    pcell_instances.each do |pc|
      pc.convert_to_static
    end
    

    Matthias

  • Hi Matthias,

    Thanks for the tip and fast reply! It works like a charm.

    Cheers,

    Tomas

Sign In or Register to comment.