Skip to content

Commit 3f00f25

Browse files
authored
Update end-to-end tests for the graph-based decomposition (#2221)
**Context:** Added a new test file `frontend/test/pytest/from_plxpr/test_decompose_transform.py` just for the graph-based decomposition. **Description of the Change:** - Removed decompose-lowering tests from `test_from_plxpr.py` - Added decompose-lowering tests to `test_decompose_transform.py` **Benefits:** - Better scoping `test_from_plxpr.py` - Dedicated test file for decompose-lowering **Possible Drawbacks:** **Related GitHub Issues:**
1 parent 03e3c75 commit 3f00f25

File tree

4 files changed

+496
-173
lines changed

4 files changed

+496
-173
lines changed

frontend/test/lit/test_decomposition.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ def rz_ry_rz(phi, theta, omega, wires: WiresLike, **__):
720720
qml.RY(theta, wires=wires)
721721
qml.RZ(omega, wires=wires)
722722

723-
@qml.register_resources({qml.RY: 1, qml.PhaseShift: 1})
723+
@qml.register_resources({qml.RY: 1, qml.GlobalPhase: 1})
724724
def ry_gp(wires: WiresLike, **__):
725725
"""Decomposition of PauliY gate using RY and GlobalPhase gates."""
726726
qml.RY(np.pi, wires=wires)
@@ -729,7 +729,7 @@ def ry_gp(wires: WiresLike, **__):
729729
@qml.qjit(target="mlir")
730730
@partial(
731731
qml.transforms.decompose,
732-
gate_set={"RX", "RZ", "PhaseShift"},
732+
gate_set={"RX", "RZ", "GlobalPhase"},
733733
fixed_decomps={
734734
qml.RY: rz_rx,
735735
qml.Rot: rz_ry_rz,

frontend/test/pytest/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ def use_capture():
5959
qml.capture.disable()
6060

6161

62+
@pytest.fixture(scope="function")
63+
def use_capture_dgraph():
64+
"""Enable capture and graph-decomposition before and disable them both after the test."""
65+
qml.capture.enable()
66+
qml.decomposition.enable_graph()
67+
try:
68+
yield
69+
finally:
70+
qml.decomposition.disable_graph()
71+
qml.capture.disable()
72+
73+
6274
@pytest.fixture(params=["capture", "no_capture"], scope="function")
6375
def use_both_frontend(request):
6476
"""Runs the test once with capture enabled and once with it disabled."""

0 commit comments

Comments
 (0)