Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add null qubit #1179

Merged
merged 88 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
4ebd364
make DummyDevice NullDevice
AmintorDusko Oct 4, 2024
8e284af
update wheels building workflows
AmintorDusko Oct 4, 2024
a9e13ff
update check-catalyst workflow
AmintorDusko Oct 4, 2024
06aaf3e
update workflow scripts
AmintorDusko Oct 4, 2024
81d7696
update CustomDevice example in docs
AmintorDusko Oct 4, 2024
64a9ced
update version
AmintorDusko Oct 4, 2024
271a78e
update frontend tests
AmintorDusko Oct 4, 2024
696e0fa
add NullDevice to qjit_device
AmintorDusko Oct 4, 2024
4e4daf0
update test for DLManager
AmintorDusko Oct 4, 2024
d1ceaed
add NullDevice to the list of devices in the building procedure
AmintorDusko Oct 4, 2024
e684ed5
update runtime Makefile
AmintorDusko Oct 4, 2024
432e69b
add the null_device subdirectory to the building procedure
AmintorDusko Oct 4, 2024
f8bc59b
update Makefile
AmintorDusko Oct 4, 2024
e0558be
Merge branch 'main' of https://github.com/PennyLaneAI/catalyst
AmintorDusko Oct 4, 2024
20cb30b
Merge branch 'main' into add_NullDevice
AmintorDusko Oct 4, 2024
c6a5cb2
codefactor
AmintorDusko Oct 4, 2024
3cb63de
fix (?) custom_device pytest
AmintorDusko Oct 4, 2024
cdd93d3
fix comment
AmintorDusko Oct 4, 2024
5623fc2
one more fix
AmintorDusko Oct 4, 2024
2e1bd52
Update frontend/test/lit/test_device_api.py
AmintorDusko Oct 4, 2024
e765b36
Update frontend/test/lit/test_device_api.py
AmintorDusko Oct 4, 2024
d4a692c
Merge branch 'main' into add_NullDevice
AmintorDusko Oct 4, 2024
a010106
Merge branch 'main' into add_NullDevice
AmintorDusko Oct 7, 2024
d19adf9
Merge branch 'main' into add_NullDevice
AmintorDusko Oct 7, 2024
896a6e2
expand gitignore to include venv/
AmintorDusko Oct 8, 2024
b60cb0d
update MAkefile to reflect null.device installation with runtime
AmintorDusko Oct 8, 2024
80741d2
update check-catalyst workflow to reflect null.device installation wi…
AmintorDusko Oct 8, 2024
2d5c872
update NullDevice to ship with runtime as a shared library
AmintorDusko Oct 8, 2024
0bda050
update CPP test utilities and ExecutionContext; update Tests
AmintorDusko Oct 8, 2024
0cba7c4
update C++ test build system to include the null device library
AmintorDusko Oct 8, 2024
0ed5a28
add null_device to runtime and update tests to allow no-lightning setup
AmintorDusko Oct 8, 2024
9cb6c0a
Merge branch 'main' into add_NullDevice
AmintorDusko Oct 8, 2024
dba0726
Merge branch 'add_NullDevice' of https://github.com/PennyLaneAI/catal…
AmintorDusko Oct 8, 2024
2cdcb7d
change NullDevice to NullQubit
AmintorDusko Oct 8, 2024
cf28953
Update frontend/catalyst/_configuration.py
AmintorDusko Oct 8, 2024
c4a1639
change NullDevice to NullQubit
AmintorDusko Oct 8, 2024
34f1861
rename test file
AmintorDusko Oct 8, 2024
e1b6e4c
update tests
AmintorDusko Oct 8, 2024
f7bb34b
update test_device_api
AmintorDusko Oct 8, 2024
07e68e9
change toml file
AmintorDusko Oct 8, 2024
1170ae9
more naming
AmintorDusko Oct 8, 2024
24c0e8a
format
AmintorDusko Oct 8, 2024
e11b502
rename dummy devices
AmintorDusko Oct 8, 2024
530bdfe
fix tests
AmintorDusko Oct 8, 2024
f1fa489
more renaming
AmintorDusko Oct 9, 2024
6339949
Merge branch 'main' into add_NullDevice
AmintorDusko Oct 9, 2024
f57a3a2
add custom device decomposing BlockEncoding
AmintorDusko Oct 9, 2024
739ce34
add missing imports
AmintorDusko Oct 9, 2024
50aa60a
another fix
AmintorDusko Oct 9, 2024
d5f6d32
format
AmintorDusko Oct 9, 2024
e9b715d
fix tests(?)
AmintorDusko Oct 9, 2024
3e216f9
fix tests(?)
AmintorDusko Oct 9, 2024
708280f
Update .gitignore
AmintorDusko Oct 9, 2024
8847954
add custom device toml file; some cleaning;
AmintorDusko Oct 9, 2024
f8a88e9
Merge branch 'main' into add_NullDevice
AmintorDusko Oct 9, 2024
8a3c76a
Merge branch 'add_NullDevice' of https://github.com/PennyLaneAI/catal…
AmintorDusko Oct 9, 2024
c92e8db
more cleaning
AmintorDusko Oct 9, 2024
d625080
codefactor
AmintorDusko Oct 9, 2024
898b4e2
fix path
AmintorDusko Oct 9, 2024
615bc61
fix file location
AmintorDusko Oct 9, 2024
26f7284
codefactor
AmintorDusko Oct 9, 2024
b0d1333
Update runtime/lib/backend/null_qubit/NullQubit.cpp
AmintorDusko Oct 10, 2024
d7f60c4
Merge branch 'main' into add_NullDevice
AmintorDusko Oct 10, 2024
b92b108
add frontend test path to conftest
AmintorDusko Oct 10, 2024
953e50b
update null qubit toml file to a Lightning compatible one
AmintorDusko Oct 10, 2024
0883319
get test path from conftest
AmintorDusko Oct 10, 2024
56dc06a
make CustomDevice clear and use custom_device toml file
AmintorDusko Oct 10, 2024
803d8da
some cleaning
AmintorDusko Oct 10, 2024
dd1a716
more cleaning
AmintorDusko Oct 10, 2024
313676a
fix import path
AmintorDusko Oct 10, 2024
cf2d0bd
Make device Custom
AmintorDusko Oct 10, 2024
204c13c
more cleaning
AmintorDusko Oct 10, 2024
3a8f5bd
Merge branch 'main' into add_NullDevice
AmintorDusko Oct 11, 2024
ee4f697
add CONFIG_CUSTOM_DEVICE path variable
AmintorDusko Oct 11, 2024
d2f6c1e
cleaning
AmintorDusko Oct 11, 2024
ae64a56
format
AmintorDusko Oct 11, 2024
f4604a5
more tests
AmintorDusko Oct 11, 2024
698bdfe
add C++ tests
AmintorDusko Oct 11, 2024
b308470
Update runtime/tests/Test_NullQubit.cpp
AmintorDusko Oct 11, 2024
24faed8
Update runtime/lib/backend/null_qubit/null_qubit.toml
AmintorDusko Oct 11, 2024
cacb141
Update frontend/test/pytest/test_preprocess.py
AmintorDusko Oct 11, 2024
0187efc
Merge branch 'main' into add_NullDevice
AmintorDusko Oct 11, 2024
0070563
add CONFIG_CUSTOM_DEVICE for lit and pytest independently
AmintorDusko Oct 11, 2024
88dbce0
format
AmintorDusko Oct 11, 2024
a780a5b
cleaning
AmintorDusko Oct 11, 2024
6774bbe
cleaning
AmintorDusko Oct 11, 2024
0fd6f11
last fix
AmintorDusko Oct 11, 2024
7b71301
another last fix
AmintorDusko Oct 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-wheel-linux-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ jobs:
-DENABLE_OPENMP=OFF \
-DLQ_ENABLE_KERNEL_OMP=OFF

cmake --build runtime-build --target rt_capi rtd_lightning rtd_openqasm rtd_dummy
cmake --build runtime-build --target rt_capi rtd_lightning rtd_openqasm rtd_null_qubit

# Build OQC-Runtime
- name: Build OQC-Runtime
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-wheel-macos-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ jobs:
-DENABLE_OPENMP=OFF \
-DLQ_ENABLE_KERNEL_OMP=OFF

cmake --build runtime-build --target rt_capi rtd_lightning rtd_openqasm rtd_dummy
cmake --build runtime-build --target rt_capi rtd_lightning rtd_openqasm rtd_null_qubit

- name: Test Catalyst-Runtime
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-wheel-macos-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ jobs:
-DENABLE_OPENMP=OFF \
-DLQ_ENABLE_KERNEL_OMP=OFF

cmake --build runtime-build --target rt_capi rtd_lightning rtd_openqasm rtd_dummy
cmake --build runtime-build --target rt_capi rtd_lightning rtd_openqasm rtd_null_qubit

# Build OQC-Runtime
- name: Build OQC-Runtime
Expand Down
9 changes: 0 additions & 9 deletions .github/workflows/check-catalyst.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ jobs:
ENABLE_ASAN=OFF \
make runtime

# This is needed in the artifact for the pytests
# Note the lack of sanitizers.
# Left other flags the same.
COMPILER_LAUNCHER="" \
C_COMPILER=$(which ${{ needs.constants.outputs[format('c_compiler.{0}', matrix.compiler)] }}) \
CXX_COMPILER=$(which ${{ needs.constants.outputs[format('cxx_compiler.{0}', matrix.compiler)] }}) \
RT_BUILD_DIR="$(pwd)/runtime-build" \
make dummy_device

COMPILER_LAUNCHER="" \
C_COMPILER=$(which ${{ needs.constants.outputs[format('c_compiler.{0}', matrix.compiler)] }}) \
CXX_COMPILER=$(which ${{ needs.constants.outputs[format('cxx_compiler.{0}', matrix.compiler)] }}) \
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/scripts/linux_arm64/rh8/build_catalyst.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ export PYTHON_PACKAGE=$4
export PYTHON_ALTERNATIVE_VERSION=$5

# Install system dependencies
dnf update -y
dnf update -y
dnf install -y libzstd-devel gcc-toolset-${GCC_VERSION}
if [ "$PYTHON_VERSION" != "3.10" ]; then
dnf install -y ${PYTHON_PACKAGE} ${PYTHON_PACKAGE}-devel
fi
dnf clean all -y

# Make GCC the default compiler
source /opt/rh/gcc-toolset-${GCC_VERSION}/enable -y
export C_COMPILER=/opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcc
source /opt/rh/gcc-toolset-${GCC_VERSION}/enable -y
export C_COMPILER=/opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcc
export CXX_COMPILER=/opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/g++

# Set the right Python interpreter
rm -rf /usr/bin/python3
ln -s /opt/_internal/cpython-${PYTHON_VERSION}.${PYTHON_SUBVERSION}/bin/python3 /usr/bin/python3
ln -s /opt/_internal/cpython-${PYTHON_VERSION}.${PYTHON_SUBVERSION}/bin/python3 /usr/bin/python3
export PYTHON=/usr/bin/python3

# Add LLVM, Python and GCC to the PATH env var
Expand All @@ -51,7 +51,7 @@ cmake -S runtime -B runtime-build -G Ninja \
-DENABLE_OPENQASM=ON \
-DENABLE_OPENMP=OFF \
-DLQ_ENABLE_KERNEL_OMP=OFF
cmake --build runtime-build --target rt_capi rtd_lightning rtd_openqasm rtd_dummy
cmake --build runtime-build --target rt_capi rtd_lightning rtd_openqasm rtd_null_qubit

# Build OQC
export OQC_BUILD_DIR="/catalyst/oqc-build"
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ frontend/mlir_quantum
doc/_build
doc/code/api
.ipynb*

# Development
venv
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ help:
@echo " mlir to build MLIR and custom Catalyst dialects"
@echo " runtime to build Catalyst Runtime"
@echo " oqc to build Catalyst-OQC Runtime"
@echo " dummy_device needed for frontend tests"
@echo " test to run the Catalyst test suites"
@echo " docs to build the documentation for Catalyst"
@echo " clean to uninstall Catalyst and delete all temporary and cache files"
Expand Down Expand Up @@ -112,9 +111,6 @@ dialects:
runtime:
$(MAKE) -C runtime runtime

dummy_device:
$(MAKE) -C runtime dummy_device

oqc:
$(MAKE) -C frontend/catalyst/third_party/oqc/src oqc

Expand Down Expand Up @@ -268,11 +264,11 @@ format-frontend:
ifdef check
$(PYTHON) ./bin/format.py --check $(if $(version:-=),--cfversion $(version)) ./frontend/catalyst/utils
black --check --verbose .
isort --check --diff .
isort --check --diff .
else
$(PYTHON) ./bin/format.py $(if $(version:-=),--cfversion $(version)) ./frontend/catalyst/utils
black .
isort .
isort .
endif

.PHONY: docs clean-docs
Expand Down
4 changes: 2 additions & 2 deletions doc/dev/custom_devices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ The Pennylane device API allows you to build a QJIT compatible device in a simpl
.. code-block:: python

class CustomDevice(qml.devices.Device):
"""Dummy Device"""
"""Custom Device"""

config = pathlib.Path("absolute/path/to/configuration/file.toml")

Expand All @@ -178,7 +178,7 @@ The Pennylane device API allows you to build a QJIT compatible device in a simpl
the location to the shared object with the C/C++ device implementation.
"""

return "CustomDevice", "absolute/path/to/librtd_dummy.so"
return "CustomDevice", "absolute/path/to/librtd_custom.so"

def __init__(self, shots=None, wires=None):
super().__init__(wires=wires, shots=shots)
Expand Down
1 change: 1 addition & 0 deletions frontend/catalyst/device/qjit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
# TODO: This should be removed after implementing `get_c_interface`
# for the following backend devices:
SUPPORTED_RT_DEVICES = {
"null.qubit": ("NullQubit", "librtd_null_qubit"),
"lightning.qubit": ("LightningSimulator", "librtd_lightning"),
"braket.aws.qubit": ("OpenQasmDevice", "librtd_openqasm"),
"braket.local.qubit": ("OpenQasmDevice", "librtd_openqasm"),
Expand Down
3 changes: 0 additions & 3 deletions frontend/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@

# pylint: disable=unused-import,wrong-import-position
import platform

import numpy as np
import pennylane as qml
import pytest


Expand Down
4 changes: 2 additions & 2 deletions frontend/test/lit/test_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ def get_c_interface():
"""
system_extension = ".dylib" if platform.system() == "Darwin" else ".so"
lib_path = (
get_lib_path("runtime", "RUNTIME_LIB_DIR") + "/librtd_dummy" + system_extension
get_lib_path("runtime", "RUNTIME_LIB_DIR") + "/librtd_null_qubit" + system_extension
)
return "dummy.remote", lib_path
return "NullQubit", lib_path

def execute(self, circuits, execution_config):
"""Execution."""
Expand Down
25 changes: 15 additions & 10 deletions frontend/test/lit/test_device_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

"""Test for the device API.
"""
import os
import pathlib
import platform
from typing import Optional

Expand All @@ -27,11 +29,14 @@
from catalyst import qjit
from catalyst.compiler import get_lib_path

TEST_PATH = os.path.dirname(__file__)
CONFIG_CUSTOM_DEVICE = pathlib.Path(f"{TEST_PATH}/../custom_device/custom_device.toml")

class DummyDevice(Device):
"""A dummy device from the device API."""

config = get_lib_path("runtime", "RUNTIME_LIB_DIR") + "/backend/dummy_device.toml"
class CustomDevice(Device):
"""A custom device that does nothing."""

config = CONFIG_CUSTOM_DEVICE

def __init__(self, wires, shots=1024):
super().__init__(wires=wires, shots=shots)
Expand All @@ -42,11 +47,11 @@
the location to the shared object with the C/C++ device implementation.
"""
system_extension = ".dylib" if platform.system() == "Darwin" else ".so"
lightning_lib_path = (
get_lib_path("runtime", "RUNTIME_LIB_DIR") + "/librtd_lightning" + system_extension
null_qubit_lib_path = (
get_lib_path("runtime", "RUNTIME_LIB_DIR") + "/librtd_null_qubit" + system_extension
)

return "dummy.remote", lightning_lib_path
return "Custom", null_qubit_lib_path

def execute(self, circuits, execution_config):
"""Execute"""
Expand All @@ -60,13 +65,13 @@
transform_program = TransformProgram()
transform_program.add_transform(qml.transforms.split_non_commuting)
return transform_program, execution_config

Check notice on line 68 in frontend/test/lit/test_device_api.py

View check run for this annotation

codefactor.io / CodeFactor

frontend/test/lit/test_device_api.py#L68

Line too long (104/100) (line-too-long)

def test_circuit():
"""Test a circuit compilation to MLIR when using the new device API."""

# CHECK: quantum.device["[[PATH:.*]]librtd_lightning.{{so|dylib}}", "dummy.remote", "{'shots': 2048}"]
dev = DummyDevice(wires=2, shots=2048)
# CHECK: quantum.device["[[PATH:.*]]librtd_null_qubit.{{so|dylib}}", "Custom", "{'shots': 2048}"]
dev = CustomDevice(wires=2, shots=2048)

@qjit(target="mlir")
@qml.qnode(device=dev)
Expand All @@ -85,13 +90,13 @@
test_circuit()


def test_preprocess():

Check notice on line 93 in frontend/test/lit/test_device_api.py

View check run for this annotation

codefactor.io / CodeFactor

frontend/test/lit/test_device_api.py#L93

Line too long (104/100) (line-too-long)
"""Test a circuit (with preprocessing transforms) compilation to MLIR when
using the new device API.
TODO: we need to readd the two check-not once we accept the device preprocessing."""

# CHECK: quantum.device["[[PATH:.*]]librtd_lightning.{{so|dylib}}", "dummy.remote", "{'shots': 2048}"]
dev = DummyDevice(wires=2, shots=2048)
# CHECK: quantum.device["[[PATH:.*]]librtd_null_qubit.{{so|dylib}}", "Custom", "{'shots': 2048}"]
dev = CustomDevice(wires=2, shots=2048)

@qjit(target="mlir")
@qml.qnode(device=dev)
Expand Down
22 changes: 22 additions & 0 deletions frontend/test/pytest/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2023 Xanadu Quantum Technologies Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Pytest configuration file for Catalyst test suite.
"""

import os
import pathlib

TEST_PATH = os.path.dirname(__file__)
CONFIG_CUSTOM_DEVICE = pathlib.Path(f"{TEST_PATH}/../custom_device/custom_device.toml")
4 changes: 2 additions & 2 deletions frontend/test/pytest/device/test_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ def get_c_interface():
"""
system_extension = ".dylib" if platform.system() == "Darwin" else ".so"
lib_path = (
get_lib_path("runtime", "RUNTIME_LIB_DIR") + "/librtd_dummy" + system_extension
get_lib_path("runtime", "RUNTIME_LIB_DIR") + "/librtd_null_qubit" + system_extension
)
return "dummy.remote", lib_path
return "NullQubit", lib_path

def execute(self, circuits, execution_config):
"""Execution."""
Expand Down
18 changes: 0 additions & 18 deletions frontend/test/pytest/test_config_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from tempfile import TemporaryDirectory
from textwrap import dedent

import pennylane as qml
import pytest

from catalyst.utils.exceptions import CompileError
Expand All @@ -32,23 +31,6 @@
)


class DeviceToBeTested(qml.devices.QubitDevice):
"""Test device"""

name = "Dummy Device"
short_name = "dummy.device"
pennylane_requires = "0.33.0"
version = "0.0.1"
author = "Dummy"

operations = []
observables = []

def apply(self, operations, **kwargs):
"""Unused"""
raise RuntimeError("Only C/C++ interface is defined")


def get_test_config(config_text: str) -> TOMLDocument:
"""Parse test config into the TOMLDocument structure"""
with TemporaryDirectory() as d:
Expand Down
Loading
Loading