Skip to content

Commit 675e35e

Browse files
authored
add test to verify order must only match device (#419)
1 parent 372a9af commit 675e35e

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

tests/test_measures.py

+28-4
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,15 @@ def circuit():
118118
@pytest.mark.parametrize(
119119
"cases",
120120
[
121-
[[1, 0], [0.9165164490394898, 0.08348355096051052, 0.0, 0.0]],
121+
[[0, 1], [1, 0]],
122+
[[1, 0], [0, 1]],
122123
],
123124
)
124-
def test_fail_probs_tape_unordered_wires(self, cases, tol, dev):
125-
"""Test probs with a circuit on wires=[0]"""
125+
def test_fail_probs_tape_unordered_wires(self, cases, tol):
126+
"""Test probs with a circuit on wires=[0] fails for out-of-order wires passed to probs."""
126127

127128
x, y, z = [0.5, 0.3, -0.7]
129+
dev = qml.device("lightning.qubit", wires=cases[1])
128130

129131
@qml.qnode(dev)
130132
def circuit():
@@ -137,7 +139,29 @@ def circuit():
137139
RuntimeError,
138140
match="Lightning does not currently support out-of-order indices for probabilities",
139141
):
140-
assert np.allclose(circuit(), cases[1], atol=tol, rtol=0)
142+
_ = circuit()
143+
144+
@pytest.mark.parametrize(
145+
"cases",
146+
[
147+
[[1, 0], [1, 0], [0.9165164490394898, 0.08348355096051052, 0.0, 0.0]],
148+
[[2, 0], [2, 0, 1], [0.9165164490394898, 0.08348355096051052, 0.0, 0.0]],
149+
],
150+
)
151+
def test_probs_matching_device_wire_order(self, cases, tol):
152+
"""Test probs with a circuit on wires=[0] passes if wires are sorted wrt device wires."""
153+
154+
x, y, z = [0.5, 0.3, -0.7]
155+
dev = qml.device("lightning.qubit", wires=cases[1])
156+
157+
@qml.qnode(dev)
158+
def circuit():
159+
qml.RX(0.4, wires=[0])
160+
qml.Rot(x, y, z, wires=[0])
161+
qml.RY(-0.2, wires=[0])
162+
return qml.probs(wires=cases[0])
163+
164+
assert np.allclose(circuit(), cases[2], atol=tol, rtol=0)
141165

142166
@pytest.mark.parametrize(
143167
"cases",

0 commit comments

Comments
 (0)