diff --git a/.github/workflows/build-wheel-linux-x86_64.yaml b/.github/workflows/build-wheel-linux-x86_64.yaml index 823ae35ac6..806cf6ee5f 100644 --- a/.github/workflows/build-wheel-linux-x86_64.yaml +++ b/.github/workflows/build-wheel-linux-x86_64.yaml @@ -254,7 +254,7 @@ jobs: run: | cmake -S runtime -B runtime-build -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$PWD/runtime-build/lib \ + -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$GITHUB_WORKSPACE/runtime-build/lib \ -DPYTHON_EXECUTABLE=$(which python${{ matrix.python_version }}) \ -Dpybind11_DIR=$(python${{ matrix.python_version }} -c "import pybind11; print(pybind11.get_cmake_dir())") \ -DENABLE_LIGHTNING_KOKKOS=ON \ @@ -262,7 +262,8 @@ jobs: -DKokkos_ENABLE_SERIAL=ON \ -DKokkos_ENABLE_OPENMP=ON \ -DENABLE_WARNINGS=OFF \ - -DENABLE_OPENQASM=ON + -DENABLE_OPENQASM=ON \ + -DENABLE_OPENMP=ON cmake --build runtime-build --target rt_capi diff --git a/.github/workflows/build-wheel-macos-arm64.yaml b/.github/workflows/build-wheel-macos-arm64.yaml index 63d7aa1bff..c892e2712c 100644 --- a/.github/workflows/build-wheel-macos-arm64.yaml +++ b/.github/workflows/build-wheel-macos-arm64.yaml @@ -159,7 +159,7 @@ jobs: cmake --build enzyme-build --target EnzymeStatic-18 - catalyst-macos-wheels-x86-64: + catalyst-macos-wheels-arm64: needs: [constants, build-dependencies] strategy: fail-fast: false @@ -244,9 +244,11 @@ jobs: -DENABLE_LIGHTNING_KOKKOS=ON \ -DLIGHTNING_GIT_TAG="latest_release" \ -DKokkos_ENABLE_SERIAL=ON \ + -DKokkos_ENABLE_OPENMP=OFF \ -DKokkos_ENABLE_COMPLEX_ALIGN=OFF \ -DENABLE_WARNINGS=OFF \ - -DENABLE_OPENQASM=ON + -DENABLE_OPENQASM=ON \ + -ENABLE_OPENMP=OFF cmake --build runtime-build --target rt_capi diff --git a/.github/workflows/build-wheel-macos-x86_64.yaml b/.github/workflows/build-wheel-macos-x86_64.yaml index 68bc0eb8fe..e7e685a3f2 100644 --- a/.github/workflows/build-wheel-macos-x86_64.yaml +++ b/.github/workflows/build-wheel-macos-x86_64.yaml @@ -246,10 +246,12 @@ jobs: -DLIGHTNING_GIT_TAG="latest_release" \ -DENABLE_LIGHTNING_KOKKOS=ON \ -DKokkos_ENABLE_SERIAL=ON \ + -DKokkos_ENABLE_OPENMP=OFF \ -DKokkos_ENABLE_COMPLEX_ALIGN=OFF \ -DKokkos_ENABLE_DEPRECATION_WARNINGS=OFF \ -DENABLE_WARNINGS=OFF \ - -DENABLE_OPENQASM=ON + -DENABLE_OPENQASM=ON \ + -DENABLE_OPENMP=OFF cmake --build runtime-build --target rt_capi diff --git a/Makefile b/Makefile index df2eb3a30c..8303939020 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ BLACKVERSIONMINOR := $(if $(BLACKVERSIONMINOR),$(BLACKVERSIONMINOR),0) MK_ABSPATH := $(abspath $(lastword $(MAKEFILE_LIST))) MK_DIR := $(dir $(MK_ABSPATH)) LLVM_BUILD_DIR ?= $(MK_DIR)/mlir/llvm-project/build -MHLO_BUILD_DIR ?= $(MK_DIR)/mlir/mlir-hlo/mhlo-build +MHLO_BUILD_DIR ?= $(MK_DIR)/mlir/mlir-hlo/bazel-build DIALECTS_BUILD_DIR ?= $(MK_DIR)/mlir/build RT_BUILD_DIR ?= $(MK_DIR)/runtime/build ENZYME_BUILD_DIR ?= $(MK_DIR)/mlir/Enzyme/build @@ -129,6 +129,8 @@ wheel: $(PYTHON) $(MK_DIR)/setup.py bdist_wheel + rm -r $(MK_DIR)/build + .PHONY: clean clean-all clean: @echo "uninstall catalyst and delete all temporary and cache files" diff --git a/doc/dev/installation.rst b/doc/dev/installation.rst index b1e90c0f14..3c67639c37 100644 --- a/doc/dev/installation.rst +++ b/doc/dev/installation.rst @@ -10,6 +10,14 @@ pre-built binaries are being distributed via the Python Package Index (PyPI) for pip install pennylane-catalyst +.. warning:: + + macOS does not ship with a system compiler by default, which Catalyst depends on. Please + ensure that `XCode `_ -requiring the use of C++20 standard library headers, and leverages the `QIR -standard library `_. Assuming -``libomp-dev`` is available, you can build the runtime from the top level -directory: +By default, the runtime builds and installs the `PennyLane-Lightning +`_ simulator device, which requires C++20 +standard library features. Older C++ compilers may not support this, so it is recommended to use a +modern compiler with these features. An additional dependency, the `QIR +standard library `_, is automatically fetched and +built on supported platforms. + +From the root project directory, the runtime can then be built as follows: .. code-block:: console make runtime -The runtime supports multiple backend devices, enabling the execution of quantum -circuits locally on CPUs and GPUs, and remotely on Amazon Braket NISQ hardware. -A list of supported backends, along with Make arguments for each device, is available in the +Additional devices are constantly added, enabling the execution of quantum circuits on CPUs, GPUs, +and remote services, such as Amazon Braket. The full list of supported backends, and additional +configuration options, are available in the `Catalyst Runtime `_ page. +To install Catalyst with all available backends, simply run: + +.. code-block:: console + + make runtime ENABLE_LIGHTNING_KOKKOS=ON ENABLE_OPENQASM=ON + MLIR Dialects """"""""""""" @@ -234,11 +251,69 @@ To make required tools in ``llvm-project/build``, ``mlir-hlo/mhlo-build``, and Tests ^^^^^ -The following target runs all available test suites in Catalyst: +The following target runs all available test suites with the default execution device in Catalyst: .. code-block:: console make test You can also test each module separately by using running the ``test-frontend``, -``test-dialects``, and ``test-runtime`` targets instead. +``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: + +.. code-block:: console + + 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: + +.. code-block:: console + + 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: + +.. code-block:: console + + 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``: + +.. code-block:: console + + 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: + +.. code-block:: console + + sudo apt install doxygen pandoc + +On **macOS**, `homebrew `_ is the easiest way to install these packages: + +.. code-block:: console + + brew install doxygen pandoc diff --git a/doc/index.rst b/doc/index.rst index 2581b5b00c..6aa014ba2e 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -54,7 +54,7 @@ Catalyst .. mdinclude:: ../README.md :start-line: 19 - :end-line: 73 + :end-line: 72 .. toctree:: :maxdepth: 2 diff --git a/frontend/test/lit/test_autograph.py b/frontend/test/lit/test_autograph.py index 5fd3996db8..0a82bf6294 100644 --- a/frontend/test/lit/test_autograph.py +++ b/frontend/test/lit/test_autograph.py @@ -364,7 +364,7 @@ def if_assign_existing_partial_no_type_mismatch(x: float): def if_assign_multiple(x: float): """Test a conditional that assigns to multiple existing variables.""" - # CHECK: (y, z) = (0, False) + # CHECK: {{\(?}}y, z{{\)?}} = (0, False) y, z = 0, False # CHECK: def if_body(): diff --git a/frontend/test/pytest/test_compiler.py b/frontend/test/pytest/test_compiler.py index 6e5eb5d033..ef0cfe76a8 100644 --- a/frontend/test/pytest/test_compiler.py +++ b/frontend/test/pytest/test_compiler.py @@ -340,6 +340,7 @@ def circuit(): assert "PipelineA" not in e.value.args[0] assert "Trace" not in e.value.args[0] assert isfile(os.path.join(str(compiled.workspace), "2_PipelineB_FAILED.mlir")) + compiled.workspace.cleanup() with pytest.raises(CompileError) as e: qjit(circuit, pipelines=test_pipelines, verbose=True)() diff --git a/mlir/Makefile b/mlir/Makefile index 328a7646bb..3e69912f7e 100644 --- a/mlir/Makefile +++ b/mlir/Makefile @@ -7,7 +7,7 @@ MK_ABSPATH := $(abspath $(lastword $(MAKEFILE_LIST))) MK_DIR := $(dir $(MK_ABSPATH)) DIALECTS_BUILD_DIR?=$(MK_DIR)/build LLVM_BUILD_DIR?=$(MK_DIR)/llvm-project/build -MHLO_BUILD_DIR?=$(MK_DIR)/mlir-hlo/mhlo-build +MHLO_BUILD_DIR?=$(MK_DIR)/mlir-hlo/bazel-build ENZYME_BUILD_DIR?=$(MK_DIR)/Enzyme/build RT_BUILD_DIR?=$(MK_DIR)/../runtime/build ENABLE_ASAN?=OFF diff --git a/pyproject.toml b/pyproject.toml index 3b79fd5b71..20bc95cab6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,6 +5,7 @@ extend-exclude = ''' frontend/catalyst/python_bindings | mlir/llvm-project | mlir/mlir-hlo + | mlir/Enzyme | build | env ) @@ -13,7 +14,15 @@ extend-exclude = ''' [tool.isort] profile = "black" skip = ["frontend/test/pytest/conftest.py"] -extend_skip_glob = ["mlir/llvm-project/*", "mlir/mlir-hlo/*", ".git/*", ".vscode/*"] +extend_skip_glob = [ + "mlir/llvm-project/*", + "mlir/mlir-hlo/*", + "mlir/Enzyme/*", + "mlir/build/*", + "runtime/build/*", + ".git/*", + ".vscode/*" +] [build-system] requires = ["setuptools>=62", "wheel", "pybind11>=2.7.0", "numpy>=1.22"] diff --git a/requirements.txt b/requirements.txt index 9c556ad883..c4378bac09 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ pybind11>=2.8.0 PyYAML # formatting/linting -black[jupyter] +black clang-format==14.* clang-tidy==14.* pylint @@ -19,5 +19,7 @@ pytest-xdist pytest-cov nbmake -# optional rt dependencies -tensorflow-cpu +# optional rt/test dependencies +tensorflow +amazon-braket-pennylane-plugin>=1.23.0 +pennylane-lightning[kokkos] diff --git a/runtime/README.rst b/runtime/README.rst index 672ddf87b2..e16334c7b6 100644 --- a/runtime/README.rst +++ b/runtime/README.rst @@ -109,7 +109,7 @@ You can use ``ENABLE_LIGHTNING_KOKKOS=ON`` to build the runtime with `lightning. .. code-block:: console - ENABLE_LIGHTNING_KOKKOS=ON make runtime + make runtime ENABLE_LIGHTNING_KOKKOS=ON Lightning-Kokkos provides support for other Kokkos backends including OpenMP, HIP and CUDA. Please refer to `the installation guideline `_ for the requirements. @@ -118,13 +118,13 @@ To build the runtime with Lightning-Kokkos and the ``Kokkos::OpenMP`` backend ex .. code-block:: console - ENABLE_LIGHTNING_KOKKOS=ON CMAKE_ARGS="-DKokkos_ENABLE_OPENMP=ON" make runtime + make runtime ENABLE_LIGHTNING_KOKKOS=ON CMAKE_ARGS="-DKokkos_ENABLE_OPENMP=ON" You can also use ``ENABLE_OPENQASM=ON`` to build the runtime with `Amazon-Braket-OpenQasm `_: .. code-block:: console - ENABLE_OPENQASM=ON make runtime + make runtime ENABLE_OPENQASM=ON This device currently offers generators for the `OpenQasm3 `_ specification and `Amazon Braket `_ assembly extension. @@ -136,8 +136,8 @@ is required. You can build the runtime with ``BUILD_QIR_STDLIB_FROM_SRC=ON`` aft .. code-block:: console - rustup component add llvm-tools-preview - BUILD_QIR_STDLIB_FROM_SRC=ON make runtime + rustup component add llvm-tools-preview + make runtime BUILD_QIR_STDLIB_FROM_SRC=ON To check the runtime test suite: