Skip to article frontmatterSkip to article content

Installation

We support Python 3.11, 3.12 and 3.13, and recommend VSCode IDE and UV.

However we recommend python3.11 or 3.12 as some extensions may not work on python3.13 yet.

Installation for users

You can install the latest released gdsfactory using the following command:

pip install gdsfactory --upgrade

If you want to install the latest pre-released version you can run:

pip install git+https://github.com/gdsfactory/gdsfactory --force-reinstall

Installation for contributors

We recommend uv for installing GDSFactory:

# On macOS and Linux.
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows.
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Then you can install gdsfactory with:

uv venv --python 3.12
uv sync --extra docs --extra dev

As a contributor, if you are on windows you need to download Git and optionally GitHub Desktop.

Then you need to fork the GitHub repository, git clone it (download it), git add, git commit, git push your improvement. Then pull request your changes to the main branch from the GitHub website.

The following lines will:

git clone git@github.com:YourUserName/gdsfactory.git
cd gdsfactory
git clone https://github.com/gdsfactory/gdsfactory-test-data.git -b test_klayout test-data-gds
uv venv --python 3.12
uv sync --extra docs --extra dev
uv run pre-commit install

Debugging installation

Please note that some PDKs may only work for a specific version of gdsfactory. Ensure you install the correct gdsfactory version specified in the pyproject.toml file. This will automatically happen when you install gdsfactory as one of the PDK dependencies. For example, pip install cspdk will install the latest gdsfactory version tested for the CSPDK PDK.

To determine your python and gdsfactory versions, use the following code:

import sys
print(sys.version)
print(sys.executable)

import gdsfactory as gf
gf.config.print_version_plugins()

Tutorials

You can download the jupyter notebooks tutorial and open them with VSCode.

We recommend running the tutorials with VSCode but you can also install and run them with jupyterlab.

pip install jupyterlab

Style

Pre-commit makes sure your code is formatted following black and checks syntax. If you forgot to pre-commit install you can fix pre-commit issues by running

pre-commit run --all-files

until you fix all the issues that the pre-commit check complaints about.

Tests

gdsfactory tests are written with pytest. You can run them, from the root of the repository with pytest:

pytest -s

pytest will test any function that starts with test_. You can assert the number of polygons, the name, the length of a route or whatever you want.

In addition to unit tests run against the library, gdsfactory has a suite of regression tests which ensure that Components are never unintentionally modified between revisions. These regression tests include

Test TypePathFormatPurpose
GDStests/components/test_components.py:test_gdsGDSTests that GDS files have not changed either structurally (cell names and hierarchy) or geometrically (XOR).
Settingstests/components/test_components.py:test_settingsYAMLTests that component settings have not changed.
Netlisttests/test_netlists.pyYAMLTests that you can convert components from YAML back and forth.

To regenerate regression reference files, you can run

pytest --force-regen -s

Note that the --force-regen flag will regenerate textual reference files, via pytest-regressions. When GDS file regressions are found, the -s flag will cause pytest to step through the failures one-by-one, so you can inspect the XOR result in Klayout (automatically loaded via klive) and debug messages in the terminal. You will be prompted if you would like to accept or reject the set of changes for each file.

Build your own Reticles/projects/PDKs

We recommend creating a separate python project for each mask and PDK.

pip install cookiecutter
cookiecutter gh:joamatab/python

Make sure you pin the version of gdsfactory that you are using in your pyproject.toml

Test own Reticles/projects/PDKs

You can take a look at the tests of other open source PDKs.

What do we test?

import pytest
from pytest_regressions.data_regression import DataRegressionFixture

from gdsfactory.difftest import difftest
from gdsfactory.samples.pdk.fab_c import cells

cell_names = list(cells.keys())
dirpath = pathlib.Path(__file__).absolute().with_suffix(".gds")

@pytest.fixture(params=cell_names, scope="function")
def component_name(request) -> str:
    return request.param


def test_gds(component_name: str) -> None:
    """Avoid regressions in GDS names, shapes and layers.

    Runs XOR and computes the area.

    """
    component = cells[component_name]()
    test_name = f"fabc_{component_name}"
    difftest(component, test_name=test_name, dirpath=dirpath)


def test_settings(component_name: str, data_regression: DataRegressionFixture) -> None:
    """Avoid regressions in component settings and ports."""
    component = cells[component_name]()
    data_regression.check(component.to_dict())

For questions join the Join the chat at https://gitter.im/gdsfactory-dev/community with element.io or use GitHub issues or discussions.

Docker container

As an alternative, you can use the pre-built Docker image from github

For instance, VS Code supports development inside a container. See Developing inside a Container for details.