Skip to content

Commit

Permalink
remove unnecessary obs_queue
Browse files Browse the repository at this point in the history
  • Loading branch information
albi3ro committed Nov 7, 2023
1 parent 2ab43d1 commit da8aa15
Showing 1 changed file with 0 additions and 26 deletions.
26 changes: 0 additions & 26 deletions tests/test_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ def test_sample_values(self, device, shots, tol):
with mimic_execution_for_sample(dev):
dev.apply([qml.RX(1.5708, wires=[0])])

dev._obs_queue = [qml.PauliZ(wires=[0])]

for idx in range(len(dev._obs_queue)):
dev._obs_queue[idx].return_type = qml.measurements.Sample

s1 = dev.sample(qml.PauliZ(wires=[0]))

# s1 should only contain 1 and -1
Expand All @@ -75,10 +70,6 @@ def test_sample_values_hermitian(self, device, shots, tol):
rotations=qml.Hermitian(A, wires=[0]).diagonalizing_gates(),
)

dev._obs_queue = [qml.Hermitian(A, wires=[0])]

for idx in range(len(dev._obs_queue)):
dev._obs_queue[idx].return_type = qml.measurements.Sample

s1 = dev.sample(qml.Hermitian(A, wires=[0]))

Expand All @@ -104,8 +95,6 @@ def test_sample_values_projector(self, device, shots, tol):
with mimic_execution_for_sample(dev):
dev.apply([qml.RX(theta, wires=[0])])

dev._obs_queue = [qml.Projector([0], wires=0)]
dev._obs_queue[0].return_type = qml.measurements.Sample
s1 = dev.sample(qml.Projector([0], wires=[0]))
# s1 should only contain 0 or 1, the eigenvalues of the projector
assert np.allclose(sorted(list(set(s1))), [0, 1], **tol)
Expand All @@ -114,8 +103,6 @@ def test_sample_values_projector(self, device, shots, tol):
np.var(s1), np.cos(theta / 2) ** 2 - (np.cos(theta / 2) ** 2) ** 2, **tol
)

dev._obs_queue = [qml.Projector([1], wires=0)]
dev._obs_queue[0].return_type = qml.measurements.Sample
s1 = dev.sample(qml.Projector([1], wires=[0]))
assert np.allclose(sorted(list(set(s1))), [0, 1], **tol)
assert np.allclose(np.mean(s1), np.sin(theta / 2) ** 2, **tol)
Expand Down Expand Up @@ -149,11 +136,6 @@ def test_sample_values_hermitian_multi_qubit(self, device, shots, tol):
rotations=qml.Hermitian(A, wires=[0, 1]).diagonalizing_gates(),
)

dev._obs_queue = [qml.Hermitian(A, wires=[0, 1])]

for idx in range(len(dev._obs_queue)):
dev._obs_queue[idx].return_type = qml.measurements.Sample

s1 = dev.sample(qml.Hermitian(A, wires=[0, 1]))

# s1 should only contain the eigenvalues of
Expand Down Expand Up @@ -189,30 +171,22 @@ def test_sample_values_projector_multi_qubit(self, device, shots, tol):
]
)

dev._obs_queue = [qml.Projector([0, 0], wires=[0, 1])]
dev._obs_queue[0].return_type = qml.measurements.Sample
s1 = dev.sample(qml.Projector([0, 0], wires=[0, 1]))
# s1 should only contain 0 or 1, the eigenvalues of the projector
assert np.allclose(sorted(list(set(s1))), [0, 1], **tol)
expected = (np.cos(theta / 2) * np.cos(theta)) ** 2
assert np.allclose(np.mean(s1), expected, **tol)

dev._obs_queue = [qml.Projector([0, 1], wires=[0, 1])]
dev._obs_queue[0].return_type = qml.measurements.Sample
s1 = dev.sample(qml.Projector([0, 1], wires=[0, 1]))
assert np.allclose(sorted(list(set(s1))), [0, 1], **tol)
expected = (np.cos(theta / 2) * np.sin(theta)) ** 2
assert np.allclose(np.mean(s1), expected, **tol)

dev._obs_queue = [qml.Projector([1, 0], wires=[0, 1])]
dev._obs_queue[0].return_type = qml.measurements.Sample
s1 = dev.sample(qml.Projector([1, 0], wires=[0, 1]))
assert np.allclose(sorted(list(set(s1))), [0, 1], **tol)
expected = (np.sin(theta / 2) * np.sin(theta)) ** 2
assert np.allclose(np.mean(s1), expected, **tol)

dev._obs_queue = [qml.Projector([1, 1], wires=[0, 1])]
dev._obs_queue[0].return_type = qml.measurements.Sample
s1 = dev.sample(qml.Projector([1, 1], wires=[0, 1]))
assert np.allclose(sorted(list(set(s1))), [0, 1], **tol)
expected = (np.sin(theta / 2) * np.cos(theta)) ** 2
Expand Down

0 comments on commit da8aa15

Please sign in to comment.