Skip to main content

Tools to make klayout, the standalone, and python environments work better together

Project description

Build Status

klayout-gadgets

Tools to make klayout, the standalone, and python environments work better together.

Particular focus on script-based layout of integrated circuits. There are some python-driven scripters and others that use the klayout language. Both can use tools to get certain simple information about klayout. The problem is that their environments and even execution engines are extremely different.

The purpose of this package is to provide simple klayout-related tools in a way that is highly robust to the environment in which it is being interpreted.

  • No import errors when you are trying to test/debug a pure python aspect of an otherwise klayout GSI script.
  • No inconsistencies between GSI and system namespace.

Installation

Step 1: install the python package

From PyPI

pip install lygadgets

or from source

git clone git@github.com:atait/klayout-gadgets.git
pip install klayout-gadgets

Step 2: link to klayout

You have a new terminal script that can link all kinds of stuff to the proper places in the klayout configuration directories.

lygadgets_link lygadgets

Definition of terms

lypackage (or salt package): handled by the klayout Package Manager. It includes a grain.xml. These can define macros, DRC, python packages, etc.

salt package: A lypackage that is published and available through the klayout Package Manager.

pypackage: python package included as part of a lypackage.

system python: the interpreter that runs when you type python xxx.py in the command line.

system namespace: the modules that are visisble to system python

GSI (generic scripting interface): an interpreter than can run python and Ruby within the special namespace available to klayout.

GSI/klayout namespace modules visible in GSI. This includes regular python builtins, Pypackages located in salt packages. And sometimes the system namespace, but only if you launch klayout from the command line.

GUI mode: running scripts when there an open application window. In this mode, GSI is the primary interpreter.

Features: simple stuff everybody uses for script-based layout

Environment

Detects the interpreter in which code is being run. Provides a pya that is safe to import. In system interpreter, this will break

import pya

but this will never break:

from lygadgets import pya

however, of course, you then cannot try to use the GUI features of pya. You can't use it at all if you are running system python.

If you have the klayout python standalone, that is what you will get as "pya". Then, its layout database features will be available, just like the regular GSI version of pya in batch mode. In GSI mode, lygadgets gives the GSI pya so as not disrupt things.

Linking all sorts of things into klayout scope

lygadgets_link creates symlinks stuff (pypackages, technologies, salt packages) to the right places, just as if you had downloaded them through salt. Symlinking is useful if you have project that changes, and you want them to be immediately reflected in the application.

Python packages

Right after pip install mypack, run lygadgets_link mypack, and it will show up to klayout's GSI. This creates a symlink from source files to the ~/.klayout/python directory.

As of v0.1.25, this command can also trigger linking of other dependencies. The trigger list is a package attribute called __lygadget_link__, defined in __init__. Here is where you put pip dependencies:

# setup.py
setup(name='lygadgets',
      ...
      install_requires=['future', 'xmltodict'],
      )

Now, we also put them in __init__.py.

# lygadgets/__init__.py
__version__ = '0.1.25'
__lygadget_link__ = ['future', 'xmltodict']

Sometimes you get lucky and GSI finds dependencies without the additional linking. While that may work on one system, it might not work on another. Linking makes sure.

Environment, more aggressive

GSI pya contains more than the standalone klayout.db. Your exiting python scripts that were run using klayout -r script.py and all of its dependencies that auto-run a whole bunch of stuff in their __init__.pys -- all of that stuff contains references to pya and GUI features of pya. So you definitely cannot do python script.py.

The command lygadgets.patch_environment() solves this problem. Just put it at the very top of script.py, after importing lygadgets. Now, you no longer need to do from lygadgets import pya. GUI calls will be stifled. The downside is that this aggressive approach is less likely to work cross-platform. It is still being debugged on Windows and Anaconda.

Once again backwards compatibility with GSI is the top priority of patch_environment. If it detects the GSI, it will do nothing.

Markup reading

This will, in the future, expand into technology component access, which are just XML files. Outside of GSI, pya.Technology breaks, and klayout.db.Technology has not loaded the technology list.

Also includes the yaml package, so you can just import yaml within the GSI.

Messaging

message and message_loud will detect the best way to report to the user, either in or out of GUI mode.

Namespace linkage

These are technical notes, worth understanding if you are developing new klayout packages with hybrid GSI/system aspects.

The lygadgets_link command can insert a variety of things into the klayout namespace. It works with

  • lypackages (i.e. klayout_dot_config)
  • python packages
  • python modules
  • klayout technologies, either .lyt file or enclosing tech directory
  • macros: ruby or python

It has flags --force to overwrite anything that is currently there. However, you won't have to do this often because links are symbolic, meaning they update as you update the file/directory. The --copy flag lets you make static copies instead of links.

NB: This package so far tested on MacOS HighSierra and is expected to work on other distributions of MacOS and Linux with python 3 and klayout >= 0.25.3. Windows supports python > klayout linking, but not klayout > system. Full testing with Anaconda managers is underway.

Implementation rules for developers. Users should also take note if they have compatibility/organization interests

  • no reference to particular technologies or specific types of properties (e.g. "WAVEGUIDES.xml")
  • no calling subprocess.call('klayout -r foo.py')
  • no phidl in the implementation. Of course phidl packages will use this one.
  • klayout.db is allowed if it speeds it up, but it cannot be required

Todo

  • detect version of lypackages and pypackages to determine whether or not to force

Authors: Alex Tait, Adam McCaughan, Sonia Buckley, Jeff Chiles, Jeff Shainline, Rich Mirin, Sae Woo Nam

National Institute of Standards and Technology, Boulder, CO, USA

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lygadgets-0.1.28.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

lygadgets-0.1.28-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file lygadgets-0.1.28.tar.gz.

File metadata

  • Download URL: lygadgets-0.1.28.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5

File hashes

Hashes for lygadgets-0.1.28.tar.gz
Algorithm Hash digest
SHA256 96474d5beebf9d28e06330b73a5bbeb3e2b7092e5045dd029126179c7b7251cf
MD5 77855e0bbcf9db7fee1634836ec64db6
BLAKE2b-256 4874bd43e33e345a7ed7cc2cc4c82ade9261588607110298ccf0028d31d5ef21

See more details on using hashes here.

File details

Details for the file lygadgets-0.1.28-py3-none-any.whl.

File metadata

  • Download URL: lygadgets-0.1.28-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5

File hashes

Hashes for lygadgets-0.1.28-py3-none-any.whl
Algorithm Hash digest
SHA256 29d5554f66f5196ec7aea91a785ab07cc464f8ba24cf20ddd461e7a552d37d14
MD5 df86a91d962e21653fd86bbf0f7b7978
BLAKE2b-256 a339dbe214153bfa00130b5e3c828a278a8642561cd99d40e547ad484ce4352b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page