Skip to content

Commit 934298e

Browse files
committed
Optional new pennylane functionality
1 parent 82228f4 commit 934298e

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

qualtran/_infra/bloq.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,13 @@ def as_pl_op(self, wires: 'Wires') -> 'Operation':
484484
instance truly should not be included in the PennyLane circuit (e.g. for reshaping
485485
bloqs). A bloq with no PennyLane equivalent should raise an exception instead.
486486
"""
487-
from pennylane.io import FromBloq
487+
try:
488+
from pennylane.io import FromBloq
489+
except ImportError:
490+
raise NotImplementedError(
491+
f"{self} does not have a native PennyLane operation. "
492+
f"pennylane>=0.41 will wrap this bloq in the `pennylane.io.FromBloq` adapter."
493+
)
488494

489495
return FromBloq(bloq=self, wires=wires)
490496

qualtran/_infra/bloq_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ def test_bloq():
3737
def test_as_pl_op():
3838
import pennylane as qml
3939

40+
if not hasattr(qml, 'FromBloq'):
41+
pytest.xfail("Requires pennylane>=0.41")
42+
4043
tb = TestTwoBitOp()
4144

4245
assert tb.as_pl_op(wires=[0, 1]) == qml.FromBloq(TestTwoBitOp(), wires=[0, 1])

qualtran/bloqs/basic_gates/cnot_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def test_cnot_tensor():
4242

4343
def test_cnot_vs_pl():
4444
bloq = CNOT()
45+
if not hasattr(qml, 'FromBloq'):
46+
pytest.xfail("requires pennylane>=0.41")
4547
matrix = qml.FromBloq(bloq, wires=[0, 1]).matrix()
4648
# fmt: off
4749
should_be = np.array([

0 commit comments

Comments
 (0)