0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

KLayout の Python API を試してみた!(Instance Class)

0
Last updated at Posted at 2025-12-09

1990年、NHKが「電子立国日本」と持て囃した半導体業界に 30年ぶりにスポットライトが当たっています。舞台に立っているのは最先端製造技術ですが、ここでは裏方として舞台を支えてきた製造+設計の橋渡し役である PDK や半導体の開発コスト構造、レガシー半導体の活用等々、製造技術に偏りがちの半導体を設計やビジネス面からの切り口で論考を上げて来ました。今回は、生業である設計エンジニアから見たオープンソース EDA ツールである KLayoutPython API に関して簡単に紹介したいと思います。設計者だけでなく、製造やプロセス開発畑の方にも参考になる内容に膨らましていますので、ご笑読頂ければ幸いです。

なお、本内容は、過去の業務経験を元にした、個人的意見・見解の表明であり、いかなる組織を代表したものではありません

第一回の「Klayout の Python API を試してみた!」では、LayoutCell Class に関して解説していますが、今回、第二回では Instance Class を試して見たいと思います。

Instance Class

Instance は Cell への参照になります。Cell には Shape 情報と同様に他のセルへの Instance 情報が記載されています。次のようなコードを書いて見ます。

#! /usr/bin/env python3
import sys
import klayout.db as db
#
ly    = db.Layout()  
args  = sys.argv
#
ifile = args[1]
#
ly.read(ifile)
#
if ly.top_cell() != None :
    for inst in ly.top_cell().each_inst() :
        print( inst )
    #    
#           
exit

実行すると

% ./TEST5.py TEST_LVS.gds
cell_index=1 r90 -46000,18000
cell_index=0 r0 -10000,90000
cell_index=2 r0 89800,105400

Cell の index 情報に加えて、rotation と origin 情報が得られます。

以下のように Layout を編集して CSIO を複数配置して見ます。

Screenshot 2025-12-04 at 9.55.02.png

この GDSII に実行してみると

 % ./TEST5.py TEST_LVS.gds
cell_index=1 r90 -46000,18000
cell_index=2 r0 -10000,90000
cell_index=0 r0 89800,105400
cell_index=1 r90 -126000,18000

ちなみに、前回の Cell の構造にアクセスする以下のコード

#! /usr/bin/env python3
import sys
import klayout.db as db
#
ly    = db.Layout()  
args  = sys.argv
#
ifile = args[1]
#
ly.read(ifile)
#
if ly.each_cell() != None :
    for idx in ly.each_cell_top_down() :
        cl = ly.cell(idx)
        print("CELL(%2d):%-10s" % (idx, cl.name), end='>> ' )
        for id in cl.each_child_cell() :
            print( "CHILD(%2d):%-10s" % (id, ly.cell(id).name), end=' ' )
        #    
        print()
#           
exit

を実行すると、小セルの数が増えていないことが分かります。

% ./TEST4.py TEST_LVS.gds
CELL( 3):TEST_LVS  >> CHILD( 0):RS         CHILD( 1):CSIO       CHILD( 2):RR         
CELL( 0):RS        >> 
CELL( 1):CSIO      >> 
CELL( 2):RR        >> 

CellInstance の違いが分かりますね!

次に、以下のようにコードを変更してみます。

#! /usr/bin/env python3
import sys
import klayout.db as db
#
ly    = db.Layout()  
args  = sys.argv
#
ifile = args[1]
#
ly.read(ifile)
#
if ly.top_cell() != None :
    for inst in ly.top_cell().each_inst() :
        tr = inst.trans
        print("Name = %-10s: Rot = %-3d X = %8d: Y = %8d" % 
            ( inst.cell.name, tr.rot, tr.disp.x, tr.disp.y ))
    #    
#           
exit

これを実行すると

% ./TEST6.py TEST_LVS.gds
Name = CSIO      : Rot = 1   X =   -46000: Y =    18000
Name = RR        : Rot = 0   X =   -10000: Y =    90000
Name = RS        : Rot = 0   X =    89800: Y =   105400
Name = CSIO      : Rot = 1   X =  -126000: Y =    18000

Instance の name 情報、rotation 情報、XY origin の情報へのアクセスの仕方が分かりました。

なお、上記の例の Python code では、Module:dbLayout classInstace classVector class を使っています。それぞれの Class の詳細はこちらを参照下さい

まとめ

Python API を使って GDSII ファイルの内部構造へのアクセスを試してみました。Cadence の Skill と同じく、EDA ツールの Layout データに直接アクセスできる手段があると、設計の効率を上げるツールを自ら開発することが可能になります。チュートリアルが乏しいことは、少し残念ではありますが、振り返ると 1987 年に導入した Cadence の前身の SDA 社の Edge ツール で Skill 言語を学んだ時も、資料が乏しい中で Cut & Try だった事を思い出しています。皆さんも是非挑戦して見て下さい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?