@@ -124,25 +124,26 @@ def circuit():
124
124
result = qjit (circuit )()
125
125
assert np .allclose (result , expected , atol = tol_stochastic , rtol = tol_stochastic )
126
126
127
- def test_hermitian (self , backend ):
127
+ def test_hermitian (self , backend , tol_stochastic ):
128
128
"""Test expval Hermitian observables with shots."""
129
+ n_wires = 3
130
+ n_shots = 10000
131
+ dev = qml .device (backend , wires = n_wires , shots = n_shots )
129
132
130
- @qjit
131
- @qml .qnode (qml .device (backend , wires = 3 , shots = 10000 ))
133
+ @qml .qnode (dev )
132
134
def circuit (x , y ):
133
135
qml .RX (x , wires = 0 )
134
136
qml .RX (y , wires = 1 )
135
137
qml .CNOT (wires = [0 , 1 ])
136
138
A = np .array (
137
139
[[complex (1.0 , 0.0 ), complex (2.0 , 0.0 )], [complex (2.0 , 0.0 ), complex (1.0 , 0.0 )]]
138
140
)
139
- return qml .expval (qml .Hermitian (A , wires = 2 ) + qml . PauliX ( 0 ) + qml . Hermitian ( A , wires = 1 ) )
141
+ return qml .expval (qml .Hermitian (A , wires = 2 ))
140
142
141
- with pytest .raises (
142
- RuntimeError ,
143
- match = "Hermitian observables with shot measurement are not supported" ,
144
- ):
145
- circuit (np .pi / 4 , np .pi / 4 )
143
+ expected = circuit (np .pi / 4 , np .pi / 4 )
144
+ result = qjit (circuit )(np .pi / 4 , np .pi / 4 )
145
+
146
+ assert np .allclose (result , expected , atol = tol_stochastic , rtol = tol_stochastic )
146
147
147
148
def test_paulix_pauliy (self , backend , tol_stochastic ):
148
149
"""Test that a tensor product involving PauliX and PauliY works correctly"""
@@ -332,25 +333,26 @@ def circuit():
332
333
result = qjit (circuit )()
333
334
assert np .allclose (result , expected , atol = tol_stochastic , rtol = tol_stochastic )
334
335
335
- def test_hermitian_shots (self , backend ):
336
+ def test_hermitian_shots (self , backend , tol_stochastic ):
336
337
"""Test var Hermitian observables with shots."""
338
+ n_wires = 3
339
+ n_shots = 10000
340
+ dev = qml .device (backend , wires = n_wires , shots = n_shots )
337
341
338
- @qjit
339
- @qml .qnode (qml .device (backend , wires = 3 , shots = 10000 ))
342
+ @qml .qnode (dev )
340
343
def circuit (x , y ):
341
344
qml .RX (x , wires = 0 )
342
345
qml .RX (y , wires = 1 )
343
346
qml .CNOT (wires = [0 , 1 ])
344
347
A = np .array (
345
348
[[complex (1.0 , 0.0 ), complex (2.0 , 0.0 )], [complex (2.0 , 0.0 ), complex (1.0 , 0.0 )]]
346
349
)
347
- return qml .var (qml .Hermitian (A , wires = 2 ) + qml . PauliX ( 0 ) + qml . Hermitian ( A , wires = 1 ) )
350
+ return qml .var (qml .Hermitian (A , wires = 2 ))
348
351
349
- with pytest .raises (
350
- RuntimeError ,
351
- match = "Hermitian observables with shot measurement are not supported" ,
352
- ):
353
- circuit (np .pi / 4 , np .pi / 4 )
352
+ expected = circuit (np .pi / 4 , np .pi / 4 )
353
+ result = qjit (circuit )(np .pi / 4 , np .pi / 4 )
354
+
355
+ assert np .allclose (result , expected , atol = tol_stochastic , rtol = tol_stochastic )
354
356
355
357
def test_paulix_pauliy (self , backend , tol_stochastic ):
356
358
"""Test that a tensor product involving PauliX and PauliY works correctly"""
0 commit comments