1414
1515import numpy as np
1616from ddt import ddt , data , unpack
17+ import unittest
18+
19+ from qiskit import __version__ as qiskit_version
1720from qiskit import QuantumCircuit
1821from qiskit .circuit import Parameter
1922from qiskit .quantum_info import SparsePauliOp
20-
2123from qiskit .primitives import (
2224 StatevectorSampler as ReferenceSampler ,
2325 StatevectorEstimator as ReferenceEstimator ,
2426)
25- from qiskit_aer .primitives import Sampler as AerSampler , Estimator as AerEstimator
26- from qiskit_machine_learning .neural_networks import SamplerQNN , EstimatorQNN
2727
2828from qiskit_neko import decorators
2929from qiskit_neko .tests import base
3333class TestNeuralNetworksOnPrimitives (base .BaseTestCase ):
3434 """Test adapted from the qiskit_machine_learning tutorials."""
3535
36+ @unittest .skipIf (
37+ tuple (map (int , qiskit_version .split ("." )[:2 ])) >= (2 , 0 ),
38+ "Skipping test until Qiskit Aer and Machine Learning are ready for Qiskit 2.0. "
39+ "Tracked in: https://github.com/Qiskit/qiskit-neko/issues/54" ,
40+ )
3641 def setUp (self ):
3742 super ().setUp ()
3843
44+ from qiskit_aer .primitives import Sampler as AerSampler , Estimator as AerEstimator
45+
3946 self .input_params = [Parameter ("x" )]
4047 self .weight_params = [Parameter ("w" )]
4148 self .circuit = QuantumCircuit (1 )
@@ -48,11 +55,18 @@ def setUp(self):
4855 reference = ReferenceEstimator (seed = 42 ), aer = AerEstimator (run_options = {"seed" : 42 })
4956 )
5057
58+ @unittest .skipIf (
59+ tuple (map (int , qiskit_version .split ("." )[:2 ])) >= (2 , 0 ),
60+ "Skipping test until Qiskit Aer and Machine Learning are ready for Qiskit 2.0. "
61+ "Tracked in: https://github.com/Qiskit/qiskit-neko/issues/54" ,
62+ )
5163 @decorators .component_attr ("terra" , "aer" , "machine_learning" )
5264 @data (["reference" , 2 ], ["aer" , 1 ])
5365 @unpack
5466 def test_sampler_qnn (self , implementation , decimal ):
5567 """Test the execution of quantum neural networks using SamplerQNN."""
68+ from qiskit_machine_learning .neural_networks import SamplerQNN
69+
5670 sampler = self .samplers [implementation ]
5771
5872 qnn = SamplerQNN (
@@ -70,11 +84,18 @@ def test_sampler_qnn(self, implementation, decimal):
7084 np .testing .assert_array_almost_equal (input_grad , [[[- 0.2273 ], [0.2273 ]]], decimal )
7185 np .testing .assert_array_almost_equal (weight_grad , [[[- 0.2273 ], [0.2273 ]]], decimal )
7286
87+ @unittest .skipIf (
88+ tuple (map (int , qiskit_version .split ("." )[:2 ])) >= (2 , 0 ),
89+ "Skipping test until Qiskit Aer and Machine Learning are ready for Qiskit 2.0. "
90+ "Tracked in: https://github.com/Qiskit/qiskit-neko/issues/54" ,
91+ )
7392 @decorators .component_attr ("terra" , "aer" , "machine_learning" )
7493 @data (["reference" , 2 ], ["aer" , 1 ])
7594 @unpack
7695 def test_estimator_qnn (self , implementation , decimal ):
7796 """Test the execution of quantum neural networks using EstimatorQNN."""
97+ from qiskit_machine_learning .neural_networks import EstimatorQNN
98+
7899 estimator = self .estimators [implementation ]
79100
80101 qnn = EstimatorQNN (
0 commit comments