Skip to content

klayout Standalone KLayout Python Module

Matthias Köfferlein edited this page Jun 20, 2018 · 10 revisions

Scope

The scope of this sub-project is to supply a standalone Python Module for the KLayout classes.

The current approach is an integrated interpreter: KLayout comes with a built-in Python interpreter. KLayout's classes in the "pya" module space are injected into that interpreter when starting the application. Python scripts must run in that environment when they want to use this extension.

The reasoning for this approach was the initial use case: Python (and Ruby) scripts were intended to extend and customize KLayout's functionality.

Over time, many other applications emerged, many of them just using KLayout's algorithms - without the user interface - plus other, external libraries. The integrated interpreter approach means such applications need to run within KLayout. This limitation has received some criticism as it forces users into the KLayout infrastructure. In addition, the need for integrating third-party components such as NumPy created a maintenance issue.

The solution to this problem is to supply a standalone Python module which can be used in third-party ecosystems such as PyCharm, Anaconda etc.

A prototype is available in a separate branch already.

Vision

A Python module that can be included into your project.

First stage: supply modules for the core features:

import pykl.db as db

box = db.DBox(0, 0, 1000, 2000)
print str(box)

Second stage: supply modules for the UI components and the necessary infrastructure (Qt binding etc.). Ideally interoperable with PyQt.

from klayout.QtCore import *
from klayout.QtGui import *
from klayout.QtWidgets import *
from klayout.lay import *

app = QApplication([ "my_app" ])

w = LayoutView()
w.load_layout("myfile.gds", False)
w.max_hier()
w.show()

app.exec_()
# ensures that w is destroyed before app.
# Otherwise Qt segfaults.
w = None

Project

Here are some technical documents for this project:

Clone this wiki locally