Skip to content

Commit

Permalink
Merge branch 'main' into raultorres/remove_kokkos_plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
dime10 authored Aug 1, 2024
2 parents 260ce32 + 9f8c663 commit e165276
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 117 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build-wheel-linux-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ jobs:
# building with LLD is a strong requirement for mhlo
run: |
export PATH=$GITHUB_WORKSPACE/llvm-build/bin:$PATH
export TARGET_FILE=mlir/mlir-hlo/mhlo/transforms/CMakeLists.txt
export PATCH_FILE=mlir/patches/mhlo-Add-PassesIncGen-in-transforms-CMakeList.patch
if patch --dry-run -p1 $TARGET_FILE $PATCH_FILE > /dev/null 2>&1; then patch -p1 $TARGET_FILE $PATCH_FILE; fi
cmake -S mlir/mlir-hlo -B mhlo-build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
Expand All @@ -204,7 +209,7 @@ jobs:
-DCMAKE_CXX_VISIBILITY_PRESET=protected \
-DLLVM_ENABLE_LLD=ON
cmake --build mhlo-build --target check-mlir-hlo
LIT_FILTER_OUT="chlo_legalize_to_mhlo" cmake --build mhlo-build --target check-mlir-hlo
- name: Build Enzyme
if: steps.cache-enzyme-build.outputs.cache-hit != 'true'
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/build-wheel-macos-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ jobs:
if: steps.cache-mhlo-build.outputs.cache-hit != 'true'
run: |
export PATH=${{ steps.setup_env.outputs.dependency_build_dir }}/llvm-build/bin:$PATH
export TARGET_FILE=mlir/mlir-hlo/mhlo/transforms/CMakeLists.txt
export PATCH_FILE=mlir/patches/mhlo-Add-PassesIncGen-in-transforms-CMakeList.patch
if patch --dry-run -p1 $TARGET_FILE $PATCH_FILE > /dev/null 2>&1; then patch -p1 $TARGET_FILE $PATCH_FILE; fi
cmake -S ${{ steps.setup_env.outputs.dependency_build_dir }}/mlir/mlir-hlo -B ${{ steps.setup_env.outputs.dependency_build_dir }}/mhlo-build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/build-wheel-macos-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ jobs:
if: steps.cache-mhlo-build.outputs.cache-hit != 'true'
run: |
export PATH=$GITHUB_WORKSPACE/llvm-build/bin:$PATH
export TARGET_FILE=mlir/mlir-hlo/mhlo/transforms/CMakeLists.txt
export PATCH_FILE=mlir/patches/mhlo-Add-PassesIncGen-in-transforms-CMakeList.patch
if patch --dry-run -p1 $TARGET_FILE $PATCH_FILE > /dev/null 2>&1; then patch -p1 $TARGET_FILE $PATCH_FILE; fi
cmake -S mlir/mlir-hlo -B mhlo-build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scripts/linux_arm64/rh8/build_llvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ cmake -S /catalyst/mlir/llvm-project/llvm -B /catalyst/llvm-build -G Ninja \
-DPython3_EXECUTABLE=/usr/bin/python3 \
-DPython3_NumPy_INCLUDE_DIRS=/opt/_internal/cpython-${PYTHON_VERSION}.${PYTHON_SUBVERSION}/lib/python${PYTHON_VERSION}/site-packages/numpy/core/include \
-DCMAKE_CXX_VISIBILITY_PRESET=hidden
LIT_FILTER_OUT=\"Bytecode\" cmake --build /catalyst/llvm-build --target check-mlir llvm-symbolizer
LIT_FILTER_OUT="Bytecode|tosa-to-tensor" cmake --build /catalyst/llvm-build --target check-mlir llvm-symbolizer
6 changes: 5 additions & 1 deletion .github/workflows/scripts/linux_arm64/rh8/build_mhlo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export PATH=/catalyst/llvm-build/bin:/opt/_internal/cpython-${PYTHON_VERSION}.${
# Patch MHLO for correct linking
sed -i -e 's/LINK_LIBS PUBLIC/LINK_LIBS PUBLIC MLIRDeallocationUtils/g' mlir/mlir-hlo/deallocation/transforms/CMakeLists.txt

export TARGET_FILE=mlir/mlir-hlo/mhlo/transforms/CMakeLists.txt
export PATCH_FILE=mlir/patches/mhlo-Add-PassesIncGen-in-transforms-CMakeList.patch
if patch --dry-run -p1 $TARGET_FILE $PATCH_FILE > /dev/null 2>&1; then patch -p1 $TARGET_FILE $PATCH_FILE; fi

# Build MHLO
cmake -S /catalyst/mlir/mlir-hlo -B /catalyst/mhlo-build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
Expand All @@ -46,4 +50,4 @@ cmake -S /catalyst/mlir/mlir-hlo -B /catalyst/mhlo-build -G Ninja \
-DLLVM_ENABLE_ZLIB=OFF \
-DLLVM_ENABLE_ZSTD=FORCE_ON \
-DCMAKE_CXX_VISIBILITY_PRESET=hidden
cmake --build /catalyst/mhlo-build --target check-mlir-hlo
LIT_FILTER_OUT="chlo_legalize_to_mhlo" cmake --build /catalyst/mhlo-build --target check-mlir-hlo
9 changes: 8 additions & 1 deletion doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@
return y
```

<h3>Documentation</h3>

* A page has been added to the documentation, listing devices that are
Catalyst compatible.
[(#966)](https://github.com/PennyLaneAI/catalyst/pull/966)

<h3>Internal changes</h3>

* llvm O2 and Enzyme passes are only run when needed (gradients presents). Async execution of QNodes triggers now triggers a
Expand Down Expand Up @@ -303,10 +309,11 @@ This release contains contributions from (in alphabetical order):

Alessandro Cosentino,
Lillian M. A. Frederiksen,
Josh Izaac,
Kunwar Maheep Singh,
Mehrdad Malekmohammadi,
Romain Moyard,
Erick Ochoa,
Erick Ochoa Lopez,
Mudit Pandey,
nate stemen,
Raul Torres,
Expand Down
89 changes: 89 additions & 0 deletions doc/dev/devices.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

.. raw:: html

<style>
tr {
border-top: #d3d3d3 1px solid;
border-bottom: #d3d3d3 1px solid;
}
.row-odd {
background-color: #f7f7f7;
}
</style>

Supported devices
=================

Not all PennyLane devices currently work with Catalyst, and for those that do, their supported
feature set may not necessarily match supported features when used without :func:`~.qjit`.

Supported backend devices include:

.. list-table::
:widths: 20 80

* - ``lightning.qubit``

- A fast state-vector qubit simulator written with a C++ backend. See the
`Lightning documentation <https://docs.pennylane.ai/projects/lightning/en/stable/lightning_qubit/device.html>`__
for more details, as well as its
`Catalyst configuration file <https://github.com/PennyLaneAI/pennylane-lightning/blob/master/pennylane_lightning/lightning_qubit/lightning_qubit.toml>`__
for natively supported instructions.

* - ``lightning.kokkos``

- A fast state-vector qubit simulator utilizing the Kokkos library for CPU and GPU accelerated
circuit simulation. See the
`Lightning documentation <https://docs.pennylane.ai/projects/lightning/en/stable/lightning_kokkos/device.html>`__
for more details, as well as its
`Catalyst configuration file <https://github.com/PennyLaneAI/pennylane-lightning/blob/master/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml>`__
for natively supported instructions.

* - ``braket.aws.qubit``

- Interact with quantum computing hardware devices and simulators through Amazon Braket. To use
this device with Catalyst, make sure to install the
`PennyLane-Braket plugin <https://amazon-braket-pennylane-plugin-python.readthedocs.io/en/latest/>`__.
See the
`Catalyst configuration file <https://github.com/PennyLaneAI/catalyst/blob/main/runtime/lib/backend/openqasm/braket_aws_qubit.toml>`__
for natively supported instructions.

* - ``braket.local.qubit``

- Run gate-based circuits on the Braket SDK's local simulator. To use
this device with Catalyst, make sure to install the
`PennyLane-Braket plugin <https://amazon-braket-pennylane-plugin-python.readthedocs.io/en/latest/>`__.
See the
`Catalyst configuration file <https://github.com/PennyLaneAI/catalyst/blob/main/runtime/lib/backend/openqasm/braket_local_qubit.toml>`__
for natively supported instructions.

* - ``qrack.simulator``

- `Qrack <https://github.com/unitaryfund/qrack>`__ is a GPU-accelerated quantum computer
simulator with many novel optimizations including hybrid stabilizer simulation. To use this
device with Catalyst, make sure to install the
`PennyLane-Qrack plugin <https://pennylane-qrack.readthedocs.io/en/latest/>`__, and check out
the `QJIT compilation with Qrack and Catalyst tutorial <https://pennylane.ai/qml/demos/qrack/>`__.

See the `Catalyst configuration file <https://github.com/unitaryfund/pennylane-qrack/blob/master/pennylane_qrack/QrackDeviceConfig.toml>`__
for natively supported instructions.

* - ``oqc.cloud``

- Execute on `Oxford Quantum Circuits (OQC) <https://www.oqc.tech/>`__ superconducting hardware,
via `OQC Cloud <https://docs.oqc.app>`__. To use OQC Cloud with Catalyst, simply `install the
client <https://docs.oqc.app/installation.html>`__, ensure your credentials are set as
environment variables, and use the ``backend`` argument to specify the OQC backend to use:

.. code-block:: python
import os
os.environ["OQC_EMAIL"] = "your_email"
os.environ["OQC_PASSWORD"] = "your_password"
os.environ["OQC_URL"] = "oqc_url"
dev = qml.device("oqc.cloud", backend="lucy", shots=2012, wires=2)
See the `Catalyst configuration file <https://github.com/PennyLaneAI/catalyst/blob/main/frontend/catalyst/third_party/oqc/src/oqc.toml>`__
for natively supported instructions.

117 changes: 7 additions & 110 deletions doc/dev/quick_start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ PennyLane. However, some of PennyLane's features may not be fully supported yet,

.. warning::

The supported backend devices are currently ``lightning.qubit``, ``lightning.kokkos``,
``braket.local.qubit``, ``braket.aws.qubit``, and ``oqc.cloud`` but future plans include the addition of more.
Not all PennyLane devices currently work with Catalyst. Supported backend devices include
``lightning.qubit``, ``lightning.kokkos``, and ``braket.aws.qubit``. For
a full of supported devices, please see :doc:`/dev/devices`.

PennyLane tapes are still used internally by Catalyst and you can express your circuits in the
way you are used to, as long as you ensure that all operations are added to the main tape.
Expand Down Expand Up @@ -101,101 +102,19 @@ PennyLane are also supported via the decomposition mechanism in Catalyst. For ex
qml.adjoint(qml.SingleExcitation(jnp.pi / 3, wires=[0, 1]))
return qml.state()
In addition, you can jit most of :doc:`PennyLane templates <introduction/templates>` to easily construct and evaluate
more complex quantum circuits; see below for the list of currently supported operations and templates.
In addition, you can qjit most :doc:`PennyLane templates <introduction/templates>` to easily construct and evaluate
more complex quantum circuits.

.. important::

Decomposition will generally happen in accordance with the specification provided by devices,
which can vary from device to device (e.g. ``default.qubit`` and ``lightning.qubit`` might
decompose quite differently.)
which can vary from device to device (e.g., ``default.qubit`` and ``lightning.qubit`` might
decompose quite differently).
However, Catalyst's decomposition logic will differ in the following cases:

1. All :class:`qml.Controlled <pennylane.ops.op_math.Controlled>` operations will decompose to :class:`qml.QubitUnitary <pennylane.QubitUnitary>` operations.
2. The set of operations supported by Catalyst itself can in some instances lead to additional decompositions compared to the device itself.

.. raw:: html

<div class="summary-table">

.. details::
:title: List of supported native operations

.. autosummary::
:nosignatures:

~pennylane.Identity
~pennylane.PauliX
~pennylane.PauliY
~pennylane.PauliZ
~pennylane.Hadamard
~pennylane.S
~pennylane.T
~pennylane.PhaseShift
~pennylane.RX
~pennylane.RY
~pennylane.RZ
~pennylane.CNOT
~pennylane.CY
~pennylane.CZ
~pennylane.SWAP
~pennylane.IsingXX
~pennylane.IsingYY
~pennylane.IsingXY
~pennylane.IsingZZ
~pennylane.ControlledPhaseShift
~pennylane.CRX
~pennylane.CRY
~pennylane.CRZ
~pennylane.CRot
~pennylane.CSWAP
~pennylane.MultiRZ
~pennylane.QubitUnitary

.. raw:: html

</div>
<div class="summary-table">

.. details::
:title: List of supported templates

.. autosummary::
:nosignatures:

~pennylane.AllSinglesDoubles
~pennylane.AmplitudeEmbedding
~pennylane.AngleEmbedding
~pennylane.ApproxTimeEvolution
~pennylane.ArbitraryStatePreparation
~pennylane.BasicEntanglerLayers
~pennylane.BasisEmbedding
~pennylane.BasisStatePreparation
~pennylane.broadcast
~pennylane.FermionicDoubleExcitation
~pennylane.FermionicSingleExcitation
~pennylane.FlipSign
~pennylane.GateFabric
~pennylane.GroverOperator
~pennylane.IQPEmbedding
~pennylane.kUpCCGSD
~pennylane.MERA
~pennylane.MottonenStatePreparation
~pennylane.MPS
~pennylane.Permute
~pennylane.QAOAEmbedding
~pennylane.QFT
~pennylane.QuantumMonteCarlo
~pennylane.QuantumPhaseEstimation
~pennylane.RandomLayers
~pennylane.SimplifiedTwoDesign
~pennylane.StronglyEntanglingLayers
~pennylane.TTN
~pennylane.UCCSD

.. raw:: html

</div>

Observables
-----------
Expand All @@ -218,28 +137,6 @@ a tensor product of a :class:`qml.PauliX <pennylane.PauliX>`, :class:`qml.Hadama
)
return qml.expval(qml.PauliX(0) @ qml.Hadamard(1) @ qml.Hermitian(h_matrix, 2))
.. raw:: html

<div class="summary-table">

.. details::
:title: List of supported observables

.. autosummary::
:nosignatures:

~pennylane.Identity
~pennylane.PauliX
~pennylane.PauliY
~pennylane.PauliZ
~pennylane.Hadamard
~pennylane.Hermitian
~pennylane.Hamiltonian

.. raw:: html

</div>

Measurements
------------
Most PennyLane :doc:`measurement processes <introduction/measurements>`
Expand Down
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Catalyst

dev/installation
dev/quick_start
dev/devices
dev/autograph
dev/sharp_bits
dev/jax_integration
Expand Down
6 changes: 3 additions & 3 deletions frontend/catalyst/jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def qjit(
.. note::
The supported backend devices are currently ``lightning.qubit``, ``lightning.kokkos``,
``braket.local.qubit``, ``braket.aws.qubit``, and ``oqc.cloud``. For a list of supported
operations, observables, and measurements, please see the :doc:`/dev/quick_start`.
Not all PennyLane devices currently work with Catalyst. Supported backend devices include
``lightning.qubit``, ``lightning.kokkos``, and ``braket.aws.qubit``. For
a full of supported devices, please see :doc:`/dev/devices`.
Args:
fn (Callable): the quantum or classical function
Expand Down
2 changes: 2 additions & 0 deletions frontend/test/async_tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# pylint: disable=missing-function-docstring


@pytest.mark.skip(reason="Skip mlir async destruction errors.")
def test_qnode_execution(backend):
"""The two first QNodes are executed in parrallel."""
dev = qml.device(backend, wires=2)
Expand Down Expand Up @@ -67,6 +68,7 @@ def circuit3(params):
# ("parameter-shift", "auto"), ("adjoint", "auto")]
@pytest.mark.parametrize("diff_methods", [("finite-diff", "fd")])
@pytest.mark.parametrize("inp", [(1.0), (2.0), (3.0), (4.0)])
@pytest.mark.skip(reason="Skip mlir async destruction errors.")
def test_gradient(inp, diff_methods, backend):
"""Parameter shift and finite diff generate multiple QNode that are run async."""

Expand Down
8 changes: 8 additions & 0 deletions frontend/test/lit/test_instrumentation_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
# Redirect stderr to stdout to make the output visible to FileCheck.
# RUN: %PYTHON %s 2>&1 | FileCheck %s

import jax
import numpy as np
import pennylane as qml

from catalyst import qjit
from catalyst.debug import instrumentation

# Test only on CPU execution platform
original_jax_platforms = jax.config.jax_platforms if hasattr(jax.config, "jax_platforms") else None
jax.config.update("jax_platforms", "cpu")

num_layers = 1
num_wires = 1
dev = qml.device("lightning.qubit", wires=num_wires)
Expand Down Expand Up @@ -77,3 +82,6 @@ def circuit(weights):

with instrumentation(circuit.__name__, filename=None, detailed=True):
qjit(circuit)(weights)

# Restore original execution platforms
jax.config.update("jax_platforms", original_jax_platforms)

0 comments on commit e165276

Please sign in to comment.