Skip to content

Commit b9de52f

Browse files
authored
update wires for HybridOp (#1676)
**Context:** In my PR where I can the default `Operator.num_wires = None`: PennyLaneAI/pennylane#7312 I get failing CI: https://github.com/PennyLaneAI/pennylane/actions/runs/14602060847/job/40962850893?pr=7312 with errors: ``` TypeError: Must specify a set of wires. None is not a valid wire label. ``` Instead of having a wire label that is `Operator.num_wires`, I'm just giving `HybridOp` empty wires. **Description of the Change:** **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** [sc-89159]
1 parent e44ef7a commit b9de52f

File tree

7 files changed

+57
-21
lines changed

7 files changed

+57
-21
lines changed

.dep-versions

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ enzyme=v0.0.149
88

99
# For a custom PL version, update the package version here and at
1010
# 'doc/requirements.txt
11-
pennylane=0.42.0-dev12
11+
pennylane=0.42.0-dev15
1212

1313
# For a custom LQ/LK version, update the package version here and at
1414
# 'doc/requirements.txt'
15-
lightning=0.42.0-dev0
15+
lightning=0.42.0-dev7

.github/workflows/check-catalyst.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -608,10 +608,6 @@ jobs:
608608
echo "CATALYST_BIN_DIR=$(pwd)/quantum-build/bin" >> $GITHUB_ENV
609609
chmod +x $(pwd)/quantum-build/bin/catalyst # artifact upload does not preserve permissions
610610
611-
- name: Run Python Pytest Tests
612-
run: |
613-
make pytest TEST_BRAKET=LOCAL
614-
615611
runtime-device-tests:
616612
name: Third-Party Device Tests (C++)
617613
needs: [constants, runtime, determine_runner]

doc/releases/changelog-dev.md

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
* Stop overriding the `num_wires` property when the operator can exist on `AnyWires`. This allows the deprecation
6363
of `WiresEnum` in pennylane.
6464
[(#1667)](https://github.com/PennyLaneAI/catalyst/pull/1667)
65+
[(#1676)](https://github.com/PennyLaneAI/catalyst/pull/1676)
6566

6667
* Catalyst now includes an experimental `mbqc` dialect for representing measurement-based
6768
quantum-computing protocols in MLIR.

doc/requirements.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ lxml_html_clean
3030

3131
# Pre-install PL development wheels
3232
--extra-index-url https://test.pypi.org/simple/
33-
pennylane-lightning-kokkos==0.42.0-dev0
34-
pennylane-lightning==0.42.0-dev0
35-
pennylane==0.42.0-dev12
33+
pennylane-lightning-kokkos==0.42.0-dev7
34+
pennylane-lightning==0.42.0-dev7
35+
pennylane==0.42.0-dev15

frontend/catalyst/jax_tracer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def __init__(
457457
self.regions: List[HybridOpRegion] = regions
458458
self.expansion_strategy = expansion_strategy
459459
self.apply_reverse_transform = apply_reverse_transform
460-
super().__init__(wires=Wires(HybridOp.num_wires))
460+
super().__init__(wires=Wires(()))
461461

462462
def __repr__(self):
463463
"""Constructor-call-like representation."""

frontend/test/lit/test_multi_qubit_gates.py

+48-8
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@
1414

1515
# RUN: %PYTHON %s | FileCheck %s
1616

17+
import os
18+
import pathlib
19+
import platform
20+
1721
import numpy as np
1822
import pennylane as qml
23+
from pennylane.devices.capabilities import OperatorProperties
1924

2025
from catalyst import measure, qjit
26+
from catalyst.compiler import get_lib_path
27+
from catalyst.device import get_device_capabilities
28+
29+
TEST_PATH = os.path.dirname(__file__)
30+
CONFIG_CUSTOM_DEVICE = pathlib.Path(f"{TEST_PATH}/../custom_device/custom_device.toml")
2131

2232

2333
# CHECK-LABEL: public @jit_circuit
@@ -63,18 +73,48 @@ def circuit():
6373

6474
print(circuit.mlir)
6575

66-
"""
67-
# TODO: The only reason we are using the braket.local.qubit device here
68-
# is because this test was developed before having support for custom devices.
69-
# We should replace instead create a custom device that has support for ISWAP
70-
# and PSWAP (which I think are unsupported in lightning.qubit and hence why they
71-
# would be decomposed.
72-
"""
76+
77+
def get_custom_qjit_device(num_wires, discards, additions):
78+
"""Generate a custom device without gates in discards."""
79+
80+
class CustomDevice(qml.devices.Device):
81+
"""Custom Gate Set Device"""
82+
83+
name = "lightning.qubit"
84+
config_filepath = CONFIG_CUSTOM_DEVICE
85+
86+
def __init__(self, shots=None, wires=None):
87+
super().__init__(wires=wires, shots=shots)
88+
self.qjit_capabilities = get_device_capabilities(self)
89+
for gate in discards:
90+
self.qjit_capabilities.operations.pop(gate, None)
91+
self.qjit_capabilities.operations.update(additions)
92+
93+
@staticmethod
94+
def get_c_interface():
95+
"""Returns a tuple consisting of the device name, and
96+
the location to the shared object with the C/C device implementation.
97+
"""
98+
99+
system_extension = ".dylib" if platform.system() == "Darwin" else ".so"
100+
# Borrowing the NullQubit library:
101+
lib_path = (
102+
get_lib_path("runtime", "RUNTIME_LIB_DIR") + "/librtd_null_qubit" + system_extension
103+
)
104+
return "NullQubit", lib_path
105+
106+
def execute(self, circuits, execution_config):
107+
"""Exececute the device (no)."""
108+
raise RuntimeError("No execution for the custom device")
109+
110+
return CustomDevice(wires=num_wires)
73111

74112

75113
# CHECK-LABEL: public @jit_circuit
76114
@qjit(target="mlir")
77-
@qml.qnode(qml.device("braket.local.qubit", wires=2, shots=100))
115+
@qml.qnode(
116+
get_custom_qjit_device(2, (), {"ISWAP": OperatorProperties(), "PSWAP": OperatorProperties()})
117+
)
78118
def circuit(x: float):
79119
# CHECK: {{%.+}} = quantum.custom "ISWAP"() {{.+}} : !quantum.bit, !quantum.bit
80120
qml.ISWAP(wires=[0, 1])

frontend/test/pytest/test_braket_local_devices.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
import pennylane as qml
1818
import pytest
1919
from numpy.testing import assert_allclose
20-
from pennylane import exceptions
2120

2221
from catalyst import grad, qjit
2322

2423
try:
2524
qml.device("braket.local.qubit", backend="default", wires=1)
26-
except exceptions.DeviceError:
25+
except: # pylint: disable=bare-except
2726
pytest.skip(
28-
"skipping Braket local tests because ``amazon-braket-pennylane-plugin`` is not installed",
27+
"skipping Braket local tests because ``amazon-braket-pennylane-plugin`` is not working",
2928
allow_module_level=True,
3029
)
3130

0 commit comments

Comments
 (0)