Skip to main content

Regression testing for klayout and phidl

Project description

# lytest
Unit-testing tools for integrated circuit layout

Uses klayout's standalone python modules and pytest.

## A big part of this is workflow
See test_1_components.py for an example.

There are functions that generate layouts of interest.
- They are NOT pytest functions. They cannot start with 'test_' or end with '_test'.
- Their first argument MUST be a filename. They must write some kind of layout to this file.
- They CAN take other arguments after the filename.

There are functions that perform the tests.
- These simply decorate the generating functions with a difference test
- They ARE pytest functions that will be run automatically

Why separate into two functions?
- First one is isolated, regular. Can be used to update references one-by-one.
- Second one can be run automatically with access to the unit-test goodies offered by pytest (e.g. coverage)

Why not put all diffs into one pytest function?
- Each pytest function stops on an exception, but different functions do not.
- Prevents one error in an early device shadow those happening in other devices.
- Can realistically only cover default arguments
- Does not document actual usage


## Recommended workflow for device/test development
When you write a new function, you call it with various options to make sure it's working. Testing more or less means saving those calls in the right place.

### Dependencies
pdb (python debugger)
- terminal-based, as lightweight as it gets
- set breakpoint with `import pdb; pdb.set_trace()`
- you can call quickplot or kqp (klayout_quickplot) from it
- documentation [here](https://docs.python.org/3/library/pdb.html)
- builtin

pdb++
- general upgrades to pdb. drops in seamlessly
- customize it to your liking with `~/.pdbrc.py`
- documentation [here](https://pypi.org/project/pdbpp/)
- `pip install pdbpp`

ipython
- an upgraded command line shell
- close interaction with changing code
- prevents unnecessary reloading
- `pip install ipython`
- turn autoreload on by default by putting
```python
print('autoreload is on')
%load_ext autoreload
%autoreload 2
```
in `~/.ipython/profile_default/startup/auto_reloader.ipy`

lyipc
- like quickplot for the klayout window
- technically quickplot is enough, but it's having trouble with ipython
- follow instructions on the [github page](https://github.com/atait/klayout-ipc)


## Goals of testing
1. Make sure code is not raising error
- Just needs to run
2. See if code changes affected layout behavior
- Needs XOR testing


## Writing tests
#### Minimal template
```python
import nc_library as lib
@contained_geometry
def N_tron(TOP):
TOP << lib.ntron()

def test_N_tron(): difftest_it(N_tron)()
```

#### Developing a new test
1. Copy-paste this template into one of the test_*.py files
2. Replace `lib.ntron` with whatever device producing function you'd like to test
3. Rename `N_tron` and `test_N_tron`

#### Saving its reference
This is done automatically the first time that pytest encounters it.

#### Changing its reference
From command line:
```bash
python -c "from test_superconductor import *; store_reference(N_tron)"
```
but replace "test_superconductor" with the filename and "N_tron" with whatever yours is called.

#### Making it a better test
Put in a few permutations of arguments. Check corner cases. Maybe intentionally break it using `pytest.raises`.
```python
def N_tron(TOP):
TOP << lib.ntron(layer=lys['m2_nw'])
TOP << lib.ntron(channel_width=.5, gate_width=.3, layer=lys['m2_nw']).movex(20)
with pytest.raises(ValueError):
TOP << lib.ntron(channel_width=-50)
```

## Dependency
These will be installed automatically when you install lytest.

### pytest
The terminal command `pytest [target]` will run the file target (a .py file). If target is a directory, it crawls through automatically running .py files that start with `test_` or end with `_test`.

Within a file, pytest automatically calls every function starting with `test_` or ending with `_test`. If an exception is raised, it prints the stack trace but keeps going on to the next function.

### klayout
This is now on PyPI, so you have to have it now.

### lyipc (optional)
Gives more visual information. During development, the contained geometry result is sent automatically to the GUI. During testing, failed tests are prepped for XOR in the GUI.

Get it through the klayout salt Package Manager


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

lytest-0.0.1.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

lytest-0.0.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file lytest-0.0.1.tar.gz.

File metadata

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

File hashes

Hashes for lytest-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a3a84331e41b6abe07741226c229450a6237abb073dfdb9a1bebd42c9d35c034
MD5 41fcc3622d779dd41cd5f61b0a5ada02
BLAKE2b-256 12842cef0866d813256815cdb6256b84abeb4aad4c07152cfa967408e487c47b

See more details on using hashes here.

File details

Details for the file lytest-0.0.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for lytest-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 817582c382415e89aa7f9ee4ed167eb82d85c001c5de2e9c827f319a0e704f71
MD5 217f1c4b588036389b45c6144e65f8b9
BLAKE2b-256 a820f9ea2edc934d5294ba6cb837946ae2677a78797dbce294f87e0ce0ee1c20

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