Installation

Catalyst is officially supported on Linux (x86_64) and macOS (aarch64, x86_64) platforms, and pre-built binaries are being distributed via the Python Package Index (PyPI) for Python versions 3.9 and higher. To install it, simply run the following pip command:

pip install pennylane-catalyst

Warning

macOS does not ship with a system compiler by default, which Catalyst depends on. Please ensure that XCode or the XCode Command Line Tools are installed on your system before using Catalyst.

The easiest method of installation is to run xcode-select --install from the Terminal app.

Pre-built packages for Windows are not yet available, and comptability with other platforms is untested and cannot be guaranteed. If you are using one of these platforms, please try out our Docker and Dev Container images described in the next section.

If you wish to contribute to Catalyst or develop against our runtime or compiler, instructions for building from source are also included further down.

Dev Containers

Try out Catalyst in self-contained, ready-to-go environments called Dev Containers:

Try Catalyst in Dev Container
You will need an existing installation of Docker, VS Code, and the VS Code Dev Containers extension.

If desired, the Docker images can also be used in a standalone fashion:

The user image provides an officially supported enviroment and automatically installs the latest release of Catalyst. The developer image only provides the right enviroment to build Catalyst from source, and requires launching the post-install script at .devcontainer/dev/post-install.sh from whithin the root of the running container.

Note

Due to a bug in the Dev Containers extension, clicking on the “Launch” badge will not prompt for a choice between the User and Dev containers. Instead, the User container is automatically chosen.

As a workaround, you can clone the Catalyst repository first, open it as a VS Code Workspace, and then reopen the Workspace in a Dev Container via the Reopen in Container command.

Building from source

To build Catalyst from source, developers should follow the instructions provided below for building all three modules: the Python frontend, the MLIR compiler, and the runtime library.

Requirements

In order to build Catalyst from source, developers need to ensure the following pre-requisites are installed and available on the path (depending on the platform):

  • The clang compiler, LLD linker (Linux only), CCache compiler cache (optional, recommended), and OpenMP.

  • The Ninja, Make, and CMake (v3.20 or greater) build tools.

  • Python 3.9 or higher for the Python frontend.

  • The Python package manager pip must be version 22.3 or higher.

They can be installed on Debian/Ubuntu via:

sudo apt install clang lld ccache libomp-dev ninja-build make cmake

Note

If the CMake version available in your system is too old, you can also install up-to-date versions of it via pip install cmake.

On macOS, it is strongly recommended to install the official XCode Command Line Tools (for clang & make). The remaining packages can then be installed via pip and brew:

pip install cmake ninja
brew install libomp

All additional build and developer dependencies are managed via the repository’s requirements.txt and can be installed as follows:

pip install -r requirements.txt

Note

Please ensure that your local site-packages for Python are available on the PATH - watch out for the corresponding warning that pip may give you during installation.

Once the pre-requisites are installed, start by cloning the project repository including all its submodules:

git clone --recurse-submodules --shallow-submodules https://github.com/PennyLaneAI/catalyst.git

For an existing copy of the repository without its submodules, they can also be fetched via:

git submodule update --init --depth=1

Catalyst

The build process for Catalyst is managed via a series of Makefiles for each component. To build the entire project from start to finish simply run the following make target from the top level directory:

make all

To build each component one by one starting from the runtime, or to build additional backend devices beyond lightning.qubit, please follow the instructions below.

Runtime

By default, the runtime builds and installs all supported backend devices, enabling the execution of quantum circuits on local simulators and remote services, such as Amazon Braket. The `PennyLane-Lightning<https://github.com/PennyLaneAI/pennylane-lightning>`_ suite devices require C++20 standard library features. Older C++ compilers may not support this, so it is recommended to use a modern compiler with these features.

The full list of supported backends, and additional configuration options, are available in the Catalyst Runtime page.

From the root project directory, the runtime can then be built as follows:

make runtime

MLIR Dialects

To build the Catalyst MLIR component, along with the necessary core MLIR and MLIR-HLO dependencies, run:

make mlir

You can also choose to build the custom Catalyst dialects only, with:

make dialects

Frontend

To install the pennylane-catalyst Python package (the compiler frontend) in editable mode:

make frontend

Variables

After following the instructions above, no configuration of environment variables should be required. However, if you are building Catalyst components in custom locations, you may need to set and update a few variables on your system by adjusting the paths in the commands below accordingly.

To make the MLIR bindings from the Catalyst dialects discoverable to the compiler:

export PYTHONPATH="$PWD/mlir/build/python_packages/quantum:$PYTHONPATH"

To make runtime libraries discoverable to the compiler:

export RUNTIME_LIB_DIR="$PWD/runtime/build/lib"

To make MLIR libraries discoverable to the compiler:

export MLIR_LIB_DIR="$PWD/mlir/llvm-project/build/lib"

To make Enzyme libraries discoverable to the compiler:

export ENZYME_LIB_DIR="$PWD/mlir/Enzyme/build/Enzyme"

To make required tools in llvm-project/build, mlir-hlo/mhlo-build, and mlir/build discoverable to the compiler:

export PATH="$PWD/mlir/llvm-project/build/bin:$PWD/mlir/mlir-hlo/mhlo-build/bin:$PWD/mlir/build/bin:$PATH"

Tests

The following target runs all available test suites with the default execution device in Catalyst:

make test

You can also test each module separately by using running the test-frontend, test-dialects, and test-runtime targets instead. Jupyter Notebook demos are also testable via test-demos.

Additional Device Backends

The runtime tests can be run on additional devices via the same flags that were used to build them, but using the test-runtime target instead:

make test-runtime ENABLE_LIGHTNING_KOKKOS=ON ENABLE_OPENQASM=ON

Note

The test-runtime targets rebuilds the runtime with the specified flags. Therefore, running make runtime OPENQASM=ON and make test-runtime in succession will leave you without the OpenQASM device installed. In case of errors it can also help to delete the build directory.

The Python test suite is also set up to run with different device backends. Assuming the respective device is available & compatible, they can be tested individually by specifying the PennyLane plugin device name in the test command:

make pytest TEST_BACKEND="lightning.kokkos"

AWS Braket devices have their own set of tests, which can be run either locally (LOCAL) or on the AWS Braket service (REMOTE) as follows:

make pytest TEST_BRAKET=LOCAL

Documentation

To build and test documentation for Catalyst, you will need to install sphinx and other packages listed in doc/requirements.txt:

pip install -r doc/requirements.txt

Additionally, doxygen is required to build C++ documentation, and pandoc to render Jupyter Notebooks.

On Debian/Ubuntu, they can be installed via:

sudo apt install doxygen pandoc

On macOS, homebrew is the easiest way to install these packages:

brew install doxygen pandoc