28
28
from pennylane import qnode
29
29
from scipy .stats import unitary_group
30
30
31
+ if not ld ._CPP_BINARY_AVAILABLE :
32
+ pytest .skip ("No binary module found. Skipping." , allow_module_level = True )
33
+
31
34
I , X , Y , Z = (
32
35
np .eye (2 ),
33
36
qml .PauliX .compute_matrix (),
@@ -109,12 +112,10 @@ def test_not_expval(self, dev):
109
112
qml .RX (0.1 , wires = 0 )
110
113
qml .state ()
111
114
112
- if device_name == "lightning.gpu" and ld . _CPP_BINARY_AVAILABLE :
115
+ if device_name == "lightning.gpu" :
113
116
message = "Adjoint differentiation does not support State measurements."
114
- elif ld ._CPP_BINARY_AVAILABLE :
115
- message = "This method does not support statevector return type."
116
117
else :
117
- message = "Adjoint differentiation method does not support measurement StateMP"
118
+ message = "Adjoint differentiation method does not support measurement StateMP. "
118
119
with pytest .raises (
119
120
qml .QuantumFunctionError ,
120
121
match = message ,
@@ -144,7 +145,6 @@ def test_empty_measurements(self, dev):
144
145
jac = dev .adjoint_jacobian (tape )
145
146
assert len (jac ) == 0
146
147
147
- @pytest .mark .skipif (not ld ._CPP_BINARY_AVAILABLE , reason = "Lightning binary required" )
148
148
def test_unsupported_op (self , dev ):
149
149
"""Test if a QuantumFunctionError is raised for an unsupported operation, i.e.,
150
150
multi-parameter operations that are not qml.Rot"""
@@ -159,7 +159,6 @@ def test_unsupported_op(self, dev):
159
159
):
160
160
dev .adjoint_jacobian (tape )
161
161
162
- @pytest .mark .skipif (not ld ._CPP_BINARY_AVAILABLE , reason = "Lightning binary required" )
163
162
def test_proj_unsupported (self , dev ):
164
163
"""Test if a QuantumFunctionError is raised for a Projector observable"""
165
164
with qml .tape .QuantumTape () as tape :
@@ -332,7 +331,6 @@ def test_multiple_rx_gradient_expval_hermitian(self, tol, dev):
332
331
qubit_ops = [getattr (qml , name ) for name in qml .ops ._qubit__ops__ ] # pylint: disable=no-member
333
332
ops = {qml .RX , qml .RY , qml .RZ , qml .PhaseShift , qml .CRX , qml .CRY , qml .CRZ , qml .Rot }
334
333
335
- @pytest .mark .skipif (not ld ._CPP_BINARY_AVAILABLE , reason = "Lightning binary required" )
336
334
def test_multiple_rx_gradient_expval_hamiltonian (self , tol , dev ):
337
335
"""Tests that the gradient of multiple RX gates in a circuit yields the correct result
338
336
with Hermitian observable
@@ -522,7 +520,6 @@ def test_gradient_gate_with_multiple_parameters_hermitian(self, dev):
522
520
# the different methods agree
523
521
assert np .allclose (grad_D , grad_F , atol = tol , rtol = 0 )
524
522
525
- @pytest .mark .skipif (not ld ._CPP_BINARY_AVAILABLE , reason = "Lightning binary required" )
526
523
def test_gradient_gate_with_multiple_parameters_hamiltonian (self , dev ):
527
524
"""Tests that gates with multiple free parameters yield correct gradients."""
528
525
x , y , z = [0.5 , 0.3 , - 0.7 ]
@@ -601,7 +598,6 @@ def test_provide_starting_state(self, tol, dev):
601
598
dM2 = dev .adjoint_jacobian (tape , starting_state = state_vector )
602
599
assert np .allclose (dM1 , dM2 , atol = tol , rtol = 0 )
603
600
604
- @pytest .mark .skipif (not ld ._CPP_BINARY_AVAILABLE , reason = "Lightning binary required" )
605
601
def test_provide_wrong_starting_state (self , dev ):
606
602
"""Tests raise an exception when provided starting state mismatches."""
607
603
x , y , z = [0.5 , 0.3 , - 0.7 ]
@@ -624,7 +620,6 @@ def test_provide_wrong_starting_state(self, dev):
624
620
device_name == "lightning.gpu" ,
625
621
reason = "Adjoint differentiation does not support State measurements." ,
626
622
)
627
- @pytest .mark .skipif (not ld ._CPP_BINARY_AVAILABLE , reason = "Lightning binary required" )
628
623
def test_state_return_type (self , dev ):
629
624
"""Tests raise an exception when the return type is State"""
630
625
with qml .tape .QuantumTape () as tape :
@@ -635,7 +630,7 @@ def test_state_return_type(self, dev):
635
630
636
631
with pytest .raises (
637
632
qml .QuantumFunctionError ,
638
- match = "This method does not support statevector return type ." ,
633
+ match = "Adjoint differentiation method does not support measurement StateMP ." ,
639
634
):
640
635
dev .adjoint_jacobian (tape )
641
636
@@ -675,7 +670,6 @@ def circ(x):
675
670
):
676
671
qml .grad (circ )(0.1 )
677
672
678
- @pytest .mark .skipif (not ld ._CPP_BINARY_AVAILABLE , reason = "Lightning binary required" )
679
673
def test_qnode (self , mocker , dev ):
680
674
"""Test that specifying diff_method allows the adjoint method to be selected"""
681
675
args = np .array ([0.54 , 0.1 , 0.5 ], requires_grad = True )
@@ -766,7 +760,6 @@ def cost(p1, p2):
766
760
767
761
assert np .allclose (grad_D [0 ], expected , atol = tol , rtol = 0 )
768
762
769
- @pytest .mark .skipif (not ld ._CPP_BINARY_AVAILABLE , reason = "Lightning binary required" )
770
763
def test_gradient_repeated_gate_parameters (self , mocker , dev ):
771
764
"""Tests that repeated use of a free parameter in a multi-parameter gate yields correct
772
765
gradients."""
0 commit comments