diff --git a/qiskit/algorithms/amplitude_amplifiers/grover.py b/qiskit/algorithms/amplitude_amplifiers/grover.py index 60d00f62d5dc..f8e85918a136 100644 --- a/qiskit/algorithms/amplitude_amplifiers/grover.py +++ b/qiskit/algorithms/amplitude_amplifiers/grover.py @@ -116,9 +116,11 @@ class Grover(AmplitudeAmplifier): @deprecate_arg( "quantum_instance", - additional_msg="Instead, use the ``sampler`` argument.", - since="0.22.0", - pending=True, + additional_msg=( + "Instead, use the ``sampler`` argument. " + "See https://qisk.it/algo_migration for a migration guide." + ), + since="0.24.0", ) def __init__( self, @@ -145,7 +147,7 @@ def __init__( sample_from_iterations: If True, instead of taking the values in ``iterations`` as powers of the Grover operator, a random integer sample between 0 and smaller value than the iteration is used as a power, see [1], Section 4. - quantum_instance: Pending deprecation: A Quantum Instance or Backend to run the circuits. + quantum_instance: Deprecated: A Quantum Instance or Backend to run the circuits. sampler: A Sampler to use for sampling the results of the circuits. Raises: @@ -185,7 +187,7 @@ def __init__( self._quantum_instance: QuantumInstance | None = None if quantum_instance is not None: with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=PendingDeprecationWarning) + warnings.simplefilter("ignore", DeprecationWarning) self.quantum_instance = quantum_instance self._sampler = sampler @@ -194,9 +196,13 @@ def __init__( self._iterations_arg = iterations @property - @deprecate_func(since="0.23.0", pending=True, is_property=True) + @deprecate_func( + since="0.24.0", + is_property=True, + additional_msg="See https://qisk.it/algo_migration for a migration guide.", + ) def quantum_instance(self) -> QuantumInstance | None: - r"""Pending deprecation\; Get the quantum instance. + r"""Deprecated. Get the quantum instance. Returns: The quantum instance used to run this algorithm. @@ -204,9 +210,13 @@ def quantum_instance(self) -> QuantumInstance | None: return self._quantum_instance @quantum_instance.setter - @deprecate_func(since="0.23.0", pending=True, is_property=True) + @deprecate_func( + since="0.24.0", + is_property=True, + additional_msg="See https://qisk.it/algo_migration for a migration guide.", + ) def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None: - r"""Pending deprecation\; Set quantum instance. + r"""Deprecated. Set quantum instance. Args: quantum_instance: The quantum instance used to run this algorithm. diff --git a/qiskit/algorithms/amplitude_estimators/ae.py b/qiskit/algorithms/amplitude_estimators/ae.py index a14e8f70a7e9..d9aced5d9fe2 100644 --- a/qiskit/algorithms/amplitude_estimators/ae.py +++ b/qiskit/algorithms/amplitude_estimators/ae.py @@ -66,9 +66,11 @@ class AmplitudeEstimation(AmplitudeEstimator): @deprecate_arg( "quantum_instance", - additional_msg="Instead, use the ``sampler`` argument.", - since="0.22.0", - pending=True, + additional_msg=( + "Instead, use the ``sampler`` argument. See https://qisk.it/algo_migration for a " + "migration guide." + ), + since="0.24.0", ) def __init__( self, @@ -86,7 +88,7 @@ def __init__( `qiskit.circuit.library.PhaseEstimation` when None. iqft: The inverse quantum Fourier transform component, defaults to using a standard implementation from `qiskit.circuit.library.QFT` when None. - quantum_instance: Pending deprecation\: The backend (or `QuantumInstance`) to execute + quantum_instance: Deprecated: The backend (or `QuantumInstance`) to execute the circuits on. sampler: A sampler primitive to evaluate the circuits. @@ -130,9 +132,13 @@ def sampler(self, sampler: BaseSampler) -> None: self._sampler = sampler @property - @deprecate_func(since="0.23.0", pending=True, is_property=True) + @deprecate_func( + additional_msg="See https://qisk.it/algo_migration for a migration guide.", + since="0.24.0", + is_property=True, + ) def quantum_instance(self) -> QuantumInstance | None: - """Pending deprecation; Get the quantum instance. + """Deprecated: Get the quantum instance. Returns: The quantum instance used to run this algorithm. @@ -140,9 +146,13 @@ def quantum_instance(self) -> QuantumInstance | None: return self._quantum_instance @quantum_instance.setter - @deprecate_func(since="0.23.0", pending=True, is_property=True) + @deprecate_func( + additional_msg="See https://qisk.it/algo_migration for a migration guide.", + since="0.24.0", + is_property=True, + ) def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None: - """Pending deprecation; Set quantum instance. + """Deprecated: Set quantum instance. Args: quantum_instance: The quantum instance used to run this algorithm. diff --git a/qiskit/algorithms/amplitude_estimators/fae.py b/qiskit/algorithms/amplitude_estimators/fae.py index cbfeecad499b..08fedaffa34a 100644 --- a/qiskit/algorithms/amplitude_estimators/fae.py +++ b/qiskit/algorithms/amplitude_estimators/fae.py @@ -50,9 +50,11 @@ class FasterAmplitudeEstimation(AmplitudeEstimator): @deprecate_arg( "quantum_instance", - additional_msg="Instead, use the ``sampler`` argument.", - since="0.22.0", - pending=True, + additional_msg=( + "Instead, use the ``sampler`` argument. See https://qisk.it/algo_migration for a " + "migration guide." + ), + since="0.24.0", ) def __init__( self, @@ -67,7 +69,7 @@ def __init__( delta: The probability that the true value is outside of the final confidence interval. maxiter: The number of iterations, the maximal power of Q is `2 ** (maxiter - 1)`. rescale: Whether to rescale the problem passed to `estimate`. - quantum_instance: Pending deprecation\: The quantum instance or backend + quantum_instance: Deprecated: The quantum instance or backend to run the circuits. sampler: A sampler primitive to evaluate the circuits. @@ -108,9 +110,13 @@ def sampler(self, sampler: BaseSampler) -> None: self._sampler = sampler @property - @deprecate_func(since="0.23.0", pending=True, is_property=True) + @deprecate_func( + since="0.24.0", + is_property=True, + additional_msg="See https://qisk.it/algo_migration for a migration guide.", + ) def quantum_instance(self) -> QuantumInstance | None: - """Pending deprecation; Get the quantum instance. + """Deprecated. Get the quantum instance. Returns: The quantum instance used to run this algorithm. @@ -118,9 +124,13 @@ def quantum_instance(self) -> QuantumInstance | None: return self._quantum_instance @quantum_instance.setter - @deprecate_func(since="0.23.0", pending=True, is_property=True) + @deprecate_func( + since="0.24.0", + is_property=True, + additional_msg="See https://qisk.it/algo_migration for a migration guide.", + ) def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None: - """Pending deprecation; Set quantum instance. + """Deprecated. Set quantum instance. Args: quantum_instance: The quantum instance used to run this algorithm. diff --git a/qiskit/algorithms/amplitude_estimators/iae.py b/qiskit/algorithms/amplitude_estimators/iae.py index f5aa04c926c6..e420b76e6a4e 100644 --- a/qiskit/algorithms/amplitude_estimators/iae.py +++ b/qiskit/algorithms/amplitude_estimators/iae.py @@ -52,9 +52,11 @@ class IterativeAmplitudeEstimation(AmplitudeEstimator): @deprecate_arg( "quantum_instance", - additional_msg="Instead, use the ``sampler`` argument.", - since="0.22.0", - pending=True, + additional_msg=( + "Instead, use the ``sampler`` argument. See https://qisk.it/algo_migration for a " + "migration guide." + ), + since="0.24.0", ) def __init__( self, @@ -77,7 +79,7 @@ def __init__( each iteration, can be 'chernoff' for the Chernoff intervals or 'beta' for the Clopper-Pearson intervals (default) min_ratio: Minimal q-ratio (:math:`K_{i+1} / K_i`) for FindNextK - quantum_instance: Pending deprecation\: Quantum Instance or Backend + quantum_instance: Deprecated: Quantum Instance or Backend sampler: A sampler primitive to evaluate the circuits. Raises: @@ -131,9 +133,13 @@ def sampler(self, sampler: BaseSampler) -> None: self._sampler = sampler @property - @deprecate_func(since="0.23.0", pending=True, is_property=True) + @deprecate_func( + since="0.24.0", + is_property=True, + additional_msg="See https://qisk.it/algo_migration for a migration guide.", + ) def quantum_instance(self) -> QuantumInstance | None: - """Pending deprecation; Get the quantum instance. + """Deprecated. Get the quantum instance. Returns: The quantum instance used to run this algorithm. @@ -141,9 +147,13 @@ def quantum_instance(self) -> QuantumInstance | None: return self._quantum_instance @quantum_instance.setter - @deprecate_func(since="0.23.0", pending=True, is_property=True) + @deprecate_func( + since="0.24.0", + is_property=True, + additional_msg="See https://qisk.it/algo_migration for a migration guide.", + ) def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None: - """Pending deprecation; Set quantum instance. + """Deprecated. Set quantum instance. Args: quantum_instance: The quantum instance used to run this algorithm. diff --git a/qiskit/algorithms/amplitude_estimators/mlae.py b/qiskit/algorithms/amplitude_estimators/mlae.py index 469dcb09a97a..aa9f600b700e 100644 --- a/qiskit/algorithms/amplitude_estimators/mlae.py +++ b/qiskit/algorithms/amplitude_estimators/mlae.py @@ -55,9 +55,11 @@ class in named ``MaximumLikelihoodAmplitudeEstimation``. @deprecate_arg( "quantum_instance", - additional_msg="Instead, use the ``sampler`` argument.", - since="0.22.0", - pending=True, + additional_msg=( + "Instead, use the ``sampler`` argument. See https://qisk.it/algo_migration for a " + "migration guide." + ), + since="0.24.0", ) def __init__( self, @@ -77,7 +79,7 @@ def __init__( according to ``evaluation_schedule``. The minimizer takes a function as first argument and a list of (float, float) tuples (as bounds) as second argument and returns a single float which is the found minimum. - quantum_instance: Pending deprecation\: Quantum Instance or Backend + quantum_instance: Deprecated: Quantum Instance or Backend sampler: A sampler primitive to evaluate the circuits. Raises: @@ -135,9 +137,13 @@ def sampler(self, sampler: BaseSampler) -> None: self._sampler = sampler @property - @deprecate_func(since="0.23.0", pending=True, is_property=True) + @deprecate_func( + since="0.24.0", + is_property=True, + additional_msg="See https://qisk.it/algo_migration for a migration guide.", + ) def quantum_instance(self) -> QuantumInstance | None: - """Pending deprecation; Get the quantum instance. + """Deprecated. Get the quantum instance. Returns: The quantum instance used to run this algorithm. @@ -145,9 +151,13 @@ def quantum_instance(self) -> QuantumInstance | None: return self._quantum_instance @quantum_instance.setter - @deprecate_func(since="0.23.0", pending=True, is_property=True) + @deprecate_func( + since="0.24.0", + is_property=True, + additional_msg="See https://qisk.it/algo_migration for a migration guide.", + ) def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None: - """Pending deprecation; Set quantum instance. + """Deprecated. Set quantum instance. Args: quantum_instance: The quantum instance used to run this algorithm. diff --git a/qiskit/algorithms/aux_ops_evaluator.py b/qiskit/algorithms/aux_ops_evaluator.py index d0348f381d19..788b66d6e43f 100644 --- a/qiskit/algorithms/aux_ops_evaluator.py +++ b/qiskit/algorithms/aux_ops_evaluator.py @@ -34,10 +34,10 @@ @deprecate_func( additional_msg=( "Instead, use the function " - "``qiskit.algorithms.observables_evaluator.estimate_observables``." + "``qiskit.algorithms.observables_evaluator.estimate_observables``. See " + "https://qisk.it/algo_migration for a migration guide." ), - since="0.23.0", - pending=True, + since="0.24.0", ) def eval_observables( quantum_instance: QuantumInstance | Backend, @@ -47,7 +47,7 @@ def eval_observables( threshold: float = 1e-12, ) -> ListOrDict[tuple[complex, complex]]: """ - Pending deprecation: Accepts a list or a dictionary of operators and calculates + Deprecated: Accepts a list or a dictionary of operators and calculates their expectation values - means and standard deviations. They are calculated with respect to a quantum state provided. A user can optionally provide a threshold value which filters mean values falling below the threshold. diff --git a/qiskit/algorithms/eigen_solvers/eigen_solver.py b/qiskit/algorithms/eigen_solvers/eigen_solver.py index 2fc42a509627..5fd59b3e023c 100644 --- a/qiskit/algorithms/eigen_solvers/eigen_solver.py +++ b/qiskit/algorithms/eigen_solvers/eigen_solver.py @@ -23,7 +23,7 @@ class Eigensolver(ABC): - """Pending deprecation: Eigensolver Interface. + """Deprecated: Eigensolver Interface. The Eigensolver interface has been superseded by the :class:`qiskit.algorithms.eigensolvers.Eigensolver` interface. @@ -36,9 +36,11 @@ class Eigensolver(ABC): """ @deprecate_func( - additional_msg="Instead, use the interface ``qiskit.algorithms.eigensolvers.Eigensolver``", - since="0.23.0", - pending=True, + additional_msg=( + "Instead, use the interface ``qiskit.algorithms.eigensolvers.Eigensolver``. See " + "https://qisk.it/algo_migration for a migration guide." + ), + since="0.24.0", ) def __init__(self) -> None: pass @@ -76,7 +78,7 @@ def supports_aux_operators(cls) -> bool: class EigensolverResult(AlgorithmResult): - """Pending deprecation: Eigensolver Result. + """Deprecated: Eigensolver Result. The EigensolverResult class has been superseded by the :class:`qiskit.algorithms.eigensolvers.EigensolverResult` class. @@ -87,10 +89,10 @@ class EigensolverResult(AlgorithmResult): @deprecate_func( additional_msg=( - "Instead, use the class ``qiskit.algorithms.eigensolvers.EigensolverResult``." + "Instead, use the class ``qiskit.algorithms.eigensolvers.EigensolverResult``. " + "See https://qisk.it/algo_migration for a migration guide." ), - since="0.23.0", - pending=True, + since="0.24.0", ) def __init__(self) -> None: super().__init__() diff --git a/qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py b/qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py index 98da79cfff79..6b0536330441 100755 --- a/qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py +++ b/qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py @@ -32,7 +32,7 @@ class NumPyEigensolver(Eigensolver): r""" - Pending deprecation: NumPy Eigensolver algorithm. + Deprecated: NumPy Eigensolver algorithm. The NumPyEigensolver class has been superseded by the :class:`qiskit.algorithms.eigensolvers.NumPyEigensolver` class. @@ -50,10 +50,10 @@ class NumPyEigensolver(Eigensolver): @deprecate_func( additional_msg=( - "Instead, use the class ``qiskit.algorithms.eigensolvers.NumPyEigensolver``." + "Instead, use the class ``qiskit.algorithms.eigensolvers.NumPyEigensolver``. " + "See https://qisk.it/algo_migration for a migration guide." ), - since="0.23.0", - pending=True, + since="0.24.0", ) def __init__( self, diff --git a/qiskit/algorithms/eigen_solvers/vqd.py b/qiskit/algorithms/eigen_solvers/vqd.py index 90297a7dc972..72e3dd306647 100644 --- a/qiskit/algorithms/eigen_solvers/vqd.py +++ b/qiskit/algorithms/eigen_solvers/vqd.py @@ -53,7 +53,7 @@ class VQD(VariationalAlgorithm, Eigensolver): - r"""Pending deprecation: Variational Quantum Deflation algorithm. + r"""Deprecated: Variational Quantum Deflation algorithm. The VQD class has been superseded by the :class:`qiskit.algorithms.eigensolvers.VQD` class. @@ -98,9 +98,11 @@ class VQD(VariationalAlgorithm, Eigensolver): """ @deprecate_func( - additional_msg="Instead, use the class ``qiskit.algorithms.eigensolvers.VQD``", - since="0.23.0", - pending=True, + additional_msg=( + "Instead, use the class ``qiskit.algorithms.eigensolvers.VQD``." + "See https://qisk.it/algo_migration for a migration guide." + ), + since="0.24.0", ) def __init__( self, @@ -760,7 +762,7 @@ def _get_eigenstate(self, optimal_parameters) -> list[float] | dict[str, int]: class VQDResult(VariationalResult, EigensolverResult): - """Pending deprecation: VQD Result. + """Deprecated: VQD Result. The VQDResult class has been superseded by the :class:`qiskit.algorithms.eigensolvers.VQDResult` class. @@ -770,9 +772,11 @@ class VQDResult(VariationalResult, EigensolverResult): """ @deprecate_func( - additional_msg="Instead, use the class ``qiskit.algorithms.eigensolvers.VQDResult``.", - since="0.23.0", - pending=True, + additional_msg=( + "Instead, use the class ``qiskit.algorithms.eigensolvers.VQDResult``." + "See https://qisk.it/algo_migration for a migration guide." + ), + since="0.24.0", ) def __init__(self) -> None: super().__init__() diff --git a/qiskit/algorithms/evolvers/evolution_problem.py b/qiskit/algorithms/evolvers/evolution_problem.py index 856d62e19039..8d87dbd9ae6a 100644 --- a/qiskit/algorithms/evolvers/evolution_problem.py +++ b/qiskit/algorithms/evolvers/evolution_problem.py @@ -22,7 +22,7 @@ class EvolutionProblem: - """Pending deprecation: Evolution problem class. + """Deprecated: Evolution problem class. The EvolutionProblem class has been superseded by the :class:`qiskit.algorithms.time_evolvers.TimeEvolutionProblem` class. @@ -35,10 +35,10 @@ class EvolutionProblem: @deprecate_func( additional_msg=( - "Instead, use the class ``qiskit.algorithms.time_evolvers.TimeEvolutionProblem``." + "Instead, use the class ``qiskit.algorithms.time_evolvers.TimeEvolutionProblem``. " + "See https://qisk.it/algo_migration for a migration guide." ), - since="0.23.0", - pending=True, + since="0.24.0", ) def __init__( self, diff --git a/qiskit/algorithms/evolvers/evolution_result.py b/qiskit/algorithms/evolvers/evolution_result.py index f5513923ac9e..5dd9e103f669 100644 --- a/qiskit/algorithms/evolvers/evolution_result.py +++ b/qiskit/algorithms/evolvers/evolution_result.py @@ -22,7 +22,7 @@ class EvolutionResult(AlgorithmResult): - """Pending deprecation: Class for holding evolution result. + """Deprecated: Class for holding evolution result. The EvolutionResult class has been superseded by the :class:`qiskit.algorithms.time_evolvers.TimeEvolutionResult` class. @@ -33,10 +33,10 @@ class EvolutionResult(AlgorithmResult): @deprecate_func( additional_msg=( - "Instead, use the class ``qiskit.algorithms.time_evolvers.TimeEvolutionResult``." + "Instead, use the class ``qiskit.algorithms.time_evolvers.TimeEvolutionResult``. " + "See https://qisk.it/algo_migration for a migration guide." ), - since="0.23.0", - pending=True, + since="0.24.0", ) def __init__( self, diff --git a/qiskit/algorithms/evolvers/imaginary_evolver.py b/qiskit/algorithms/evolvers/imaginary_evolver.py index f6c0624f1b74..74b301d3e539 100644 --- a/qiskit/algorithms/evolvers/imaginary_evolver.py +++ b/qiskit/algorithms/evolvers/imaginary_evolver.py @@ -20,7 +20,7 @@ class ImaginaryEvolver(ABC): - """Pending deprecation: Interface for Quantum Imaginary Time Evolution. + """Deprecated: Interface for Quantum Imaginary Time Evolution. The ImaginaryEvolver interface has been superseded by the :class:`qiskit.algorithms.time_evolvers.ImaginaryTimeEvolver` interface. @@ -31,10 +31,10 @@ class ImaginaryEvolver(ABC): @deprecate_func( additional_msg=( - "Instead, use the interface ``qiskit.algorithms.time_evolvers.ImaginaryTimeEvolver``." + "Instead, use the interface ``qiskit.algorithms.time_evolvers.ImaginaryTimeEvolver``. " + "See https://qisk.it/algo_migration for a migration guide." ), - since="0.23.0", - pending=True, + since="0.24.0", ) def __init__(self) -> None: pass diff --git a/qiskit/algorithms/evolvers/real_evolver.py b/qiskit/algorithms/evolvers/real_evolver.py index 6dfd2d7c119b..5024143b59b6 100644 --- a/qiskit/algorithms/evolvers/real_evolver.py +++ b/qiskit/algorithms/evolvers/real_evolver.py @@ -20,7 +20,7 @@ class RealEvolver(ABC): - """Pending deprecation: Interface for Quantum Real Time Evolution. + """Deprecated: Interface for Quantum Real Time Evolution. The RealEvolver interface has been superseded by the :class:`qiskit.algorithms.time_evolvers.RealTimeEvolver` interface. @@ -31,10 +31,10 @@ class RealEvolver(ABC): @deprecate_func( additional_msg=( - "Instead, use the interface ``qiskit.algorithms.time_evolvers.RealTimeEvolver``" + "Instead, use the interface ``qiskit.algorithms.time_evolvers.RealTimeEvolver``. " + "See https://qisk.it/algo_migration for a migration guide." ), - since="0.23.0", - pending=True, + since="0.24.0", ) def __init__(self) -> None: pass diff --git a/qiskit/algorithms/evolvers/trotterization/trotter_qrte.py b/qiskit/algorithms/evolvers/trotterization/trotter_qrte.py index 10c5c107efcf..4c4af495e6ba 100644 --- a/qiskit/algorithms/evolvers/trotterization/trotter_qrte.py +++ b/qiskit/algorithms/evolvers/trotterization/trotter_qrte.py @@ -38,7 +38,7 @@ class TrotterQRTE(RealEvolver): - """Pending deprecation: Quantum Real Time Evolution using Trotterization. + """Deprecated: Quantum Real Time Evolution using Trotterization. The TrotterQRTE class has been superseded by the :class:`qiskit.algorithms.time_evolvers.trotterization.TrotterQRTE` class. @@ -68,9 +68,9 @@ class TrotterQRTE(RealEvolver): @deprecate_func( additional_msg=( "Instead, use the class ``qiskit.algorithms.time_evolvers.trotterization.TrotterQRTE``." + " See https://qisk.it/algo_migration for a migration guide." ), - since="0.23.0", - pending=True, + since="0.24.0", ) def __init__( self, diff --git a/qiskit/algorithms/minimum_eigen_solvers/minimum_eigen_solver.py b/qiskit/algorithms/minimum_eigen_solvers/minimum_eigen_solver.py index da0d084c20e3..6625cf30eaeb 100644 --- a/qiskit/algorithms/minimum_eigen_solvers/minimum_eigen_solver.py +++ b/qiskit/algorithms/minimum_eigen_solvers/minimum_eigen_solver.py @@ -24,7 +24,7 @@ class MinimumEigensolver(ABC): - """Pending deprecation: Minimum Eigensolver Interface. + """Deprecated: Minimum Eigensolver Interface. The Minimum Eigensolver interface has been superseded by the :class:`qiskit.algorithms.minimum_eigensolvers.MinimumEigensolver` interface. @@ -39,10 +39,10 @@ class MinimumEigensolver(ABC): @deprecate_func( additional_msg=( "Instead, use the interface " - "``qiskit.algorithms.minimum_eigensolvers.MinimumEigensolver``." + "``qiskit.algorithms.minimum_eigensolvers.MinimumEigensolver``. " + "See https://qisk.it/algo_migration for a migration guide." ), - since="0.23.0", - pending=True, + since="0.24.0", ) def __init__(self) -> None: pass @@ -84,7 +84,7 @@ def supports_aux_operators(cls) -> bool: class MinimumEigensolverResult(AlgorithmResult): - """Pending deprecation: Minimum Eigensolver Result. + """Deprecated: Minimum Eigensolver Result. The MinimumEigensolverResult class has been superseded by the :class:`qiskit.algorithms.minimum_eigensolvers.MinimumEigensolverResult` class. @@ -96,10 +96,10 @@ class MinimumEigensolverResult(AlgorithmResult): @deprecate_func( additional_msg=( "Instead, use the class " - "``qiskit.algorithms.minimum_eigensolvers.MinimumEigensolverResult``." + "``qiskit.algorithms.minimum_eigensolvers.MinimumEigensolverResult``. " + "See https://qisk.it/algo_migration for a migration guide." ), - since="0.23.0", - pending=True, + since="0.24.0", ) def __init__(self) -> None: super().__init__() diff --git a/qiskit/algorithms/minimum_eigen_solvers/numpy_minimum_eigen_solver.py b/qiskit/algorithms/minimum_eigen_solvers/numpy_minimum_eigen_solver.py index 31438445b796..83623666b715 100644 --- a/qiskit/algorithms/minimum_eigen_solvers/numpy_minimum_eigen_solver.py +++ b/qiskit/algorithms/minimum_eigen_solvers/numpy_minimum_eigen_solver.py @@ -30,7 +30,7 @@ class NumPyMinimumEigensolver(MinimumEigensolver): """ - Pending deprecation: Numpy Minimum Eigensolver algorithm. + Deprecated: Numpy Minimum Eigensolver algorithm. The NumPyMinimumEigensolver class has been superseded by the :class:`qiskit.algorithms.minimum_eigensolvers.NumPyMinimumEigensolver` class. @@ -42,10 +42,10 @@ class NumPyMinimumEigensolver(MinimumEigensolver): @deprecate_func( additional_msg=( "Instead, use the class " - "``qiskit.algorithms.minimum_eigensolvers.NumPyMinimumEigensolver``." + "``qiskit.algorithms.minimum_eigensolvers.NumPyMinimumEigensolver``. " + "See https://qisk.it/algo_migration for a migration guide." ), - since="0.23.0", - pending=True, + since="0.24.0", ) def __init__( self, diff --git a/qiskit/algorithms/minimum_eigen_solvers/qaoa.py b/qiskit/algorithms/minimum_eigen_solvers/qaoa.py index db31c22694df..fc18be860218 100644 --- a/qiskit/algorithms/minimum_eigen_solvers/qaoa.py +++ b/qiskit/algorithms/minimum_eigen_solvers/qaoa.py @@ -32,7 +32,7 @@ class QAOA(VQE): """ - Pending deprecation: Quantum Approximate Optimization Algorithm. + Deprecated: Quantum Approximate Optimization Algorithm. The QAOA class has been superseded by the :class:`qiskit.algorithms.minimum_eigensolvers.QAOA` class. @@ -62,9 +62,11 @@ class QAOA(VQE): """ @deprecate_func( - additional_msg="Instead, use the class ``qiskit.algorithms.minimum_eigensolvers.QAOA``.", - since="0.23.0", - pending=True, + additional_msg=( + "Instead, use the class ``qiskit.algorithms.minimum_eigensolvers.QAOA``. " + "See https://qisk.it/algo_migration for a migration guide." + ), + since="0.24.0", ) def __init__( self, diff --git a/qiskit/algorithms/minimum_eigen_solvers/vqe.py b/qiskit/algorithms/minimum_eigen_solvers/vqe.py index 2742edace2ef..bf9304e4d6b7 100755 --- a/qiskit/algorithms/minimum_eigen_solvers/vqe.py +++ b/qiskit/algorithms/minimum_eigen_solvers/vqe.py @@ -54,7 +54,7 @@ class VQE(VariationalAlgorithm, MinimumEigensolver): - r"""Pending deprecation: Variational Quantum Eigensolver algorithm. + r"""Deprecated: Variational Quantum Eigensolver algorithm. The VQE class has been superseded by the :class:`qiskit.algorithms.minimum_eigensolvers.VQE` class. @@ -128,9 +128,11 @@ def my_minimizer(fun, x0, jac=None, bounds=None) -> OptimizerResult: """ @deprecate_func( - additional_msg="Instead, use the class ``qiskit.algorithms.minimum_eigensolvers.VQE``.", - since="0.23.0", - pending=True, + additional_msg=( + "Instead, use the class ``qiskit.algorithms.minimum_eigensolvers.VQE``. " + "See https://qisk.it/algo_migration for a migration guide." + ), + since="0.24.0", ) def __init__( self, @@ -657,7 +659,7 @@ def _get_eigenstate(self, optimal_parameters) -> list[float] | dict[str, int]: class VQEResult(VariationalResult, MinimumEigensolverResult): - """Pending deprecation: VQE Result. + """Deprecated: VQE Result. The VQEResult class has been superseded by the :class:`qiskit.algorithms.minimum_eigensolvers.VQEResult` class. @@ -668,10 +670,10 @@ class VQEResult(VariationalResult, MinimumEigensolverResult): @deprecate_func( additional_msg=( - "Instead, use the class ``qiskit.algorithms.minimum_eigensolvers.VQEResult``." + "Instead, use the class ``qiskit.algorithms.minimum_eigensolvers.VQEResult``. " + "See https://qisk.it/algo_migration for a migration guide." ), - since="0.23.0", - pending=True, + since="0.24.0", ) def __init__(self) -> None: with warnings.catch_warnings(): diff --git a/qiskit/algorithms/optimizers/qnspsa.py b/qiskit/algorithms/optimizers/qnspsa.py index 93f79b18d1ce..21b902353e44 100644 --- a/qiskit/algorithms/optimizers/qnspsa.py +++ b/qiskit/algorithms/optimizers/qnspsa.py @@ -91,7 +91,7 @@ def loss(x): result = qnspsa.optimize(ansatz.num_parameters, loss, initial_point=initial_point) This is a legacy version solving the same problem but using Qiskit Opflow instead - of the Qiskit Primitives. Note however, that this usage is pending deprecation. + of the Qiskit Primitives. Note however, that this usage is deprecated. .. code-block:: python @@ -255,8 +255,16 @@ def settings(self) -> dict[str, Any]: return settings @staticmethod - @deprecate_arg("backend", since="0.22", pending=True) - @deprecate_arg("expectation", since="0.22", pending=True) + @deprecate_arg( + "backend", + since="0.24.0", + additional_msg="See https://qisk.it/algo_migration for a migration guide.", + ) + @deprecate_arg( + "expectation", + since="0.24.0", + additional_msg="See https://qisk.it/algo_migration for a migration guide.", + ) def get_fidelity( circuit: QuantumCircuit, backend: Backend | QuantumInstance | None = None, @@ -285,9 +293,9 @@ def get_fidelity( Args: circuit: The circuit preparing the parameterized ansatz. - backend: *Pending deprecation.* A backend of quantum instance to evaluate the circuits. + backend: Deprecated. A backend of quantum instance to evaluate the circuits. If None, plain matrix multiplication will be used. - expectation: *Pending deprecation.* An expectation converter to specify how the expected + expectation: Deprecated. An expectation converter to specify how the expected value is computed. If a shot-based readout is used this should be set to ``PauliExpectation``. sampler: A sampler primitive to sample from a quantum state. @@ -331,11 +339,11 @@ def _legacy_get_fidelity( backend: Backend | QuantumInstance | None = None, expectation: ExpectationBase | None = None, ) -> Callable[[np.ndarray, np.ndarray], float]: - r"""PENDING DEPRECATION. Get a function to compute the fidelity of ``circuit`` with itself. + r"""Deprecated. Get a function to compute the fidelity of ``circuit`` with itself. .. note:: - This method is pending deprecation. Instead use the :class:`~.ComputeUncompute` + This method is deprecated. Instead use the :class:`~.ComputeUncompute` class which implements the fidelity calculation in the same fashion as this method. Let ``circuit`` be a parameterized quantum circuit performing the operation diff --git a/qiskit/algorithms/phase_estimators/hamiltonian_phase_estimation.py b/qiskit/algorithms/phase_estimators/hamiltonian_phase_estimation.py index ee06e2b31e26..87907c39e304 100644 --- a/qiskit/algorithms/phase_estimators/hamiltonian_phase_estimation.py +++ b/qiskit/algorithms/phase_estimators/hamiltonian_phase_estimation.py @@ -14,6 +14,8 @@ from __future__ import annotations +import warnings + from qiskit import QuantumCircuit from qiskit.utils import QuantumInstance from qiskit.utils.deprecation import deprecate_arg @@ -93,9 +95,11 @@ class HamiltonianPhaseEstimation: @deprecate_arg( "quantum_instance", - additional_msg="Instead, use the ``sampler`` argument.", - since="0.22.0", - pending=True, + additional_msg=( + "Instead, use the ``sampler`` argument. See https://qisk.it/algo_migration for a " + "migration guide." + ), + since="0.24.0", ) def __init__( self, @@ -107,15 +111,18 @@ def __init__( Args: num_evaluation_qubits: The number of qubits used in estimating the phase. The phase will be estimated as a binary string with this many bits. - quantum_instance: Pending deprecation\: The quantum instance on which + quantum_instance: Deprecated: The quantum instance on which the circuit will be run. sampler: The sampler primitive on which the circuit will be sampled. """ - self._phase_estimation = PhaseEstimation( - num_evaluation_qubits=num_evaluation_qubits, - quantum_instance=quantum_instance, - sampler=sampler, - ) + # Avoid double warning on deprecated used of `quantum_instance`. + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + self._phase_estimation = PhaseEstimation( + num_evaluation_qubits=num_evaluation_qubits, + quantum_instance=quantum_instance, + sampler=sampler, + ) def _get_scale(self, hamiltonian, bound=None) -> PhaseEstimationScale: if bound is None: diff --git a/qiskit/algorithms/phase_estimators/ipe.py b/qiskit/algorithms/phase_estimators/ipe.py index 9d2f6e1417ca..e8e583027a92 100644 --- a/qiskit/algorithms/phase_estimators/ipe.py +++ b/qiskit/algorithms/phase_estimators/ipe.py @@ -41,9 +41,11 @@ class IterativePhaseEstimation(PhaseEstimator): @deprecate_arg( "quantum_instance", - additional_msg="Instead, use the ``sampler`` argument.", - since="0.22.0", - pending=True, + additional_msg=( + "Instead, use the ``sampler`` argument. See https://qisk.it/algo_migration for a " + "migration guide." + ), + since="0.24.0", ) def __init__( self, @@ -54,7 +56,7 @@ def __init__( r""" Args: num_iterations: The number of iterations (rounds) of the phase estimation to run. - quantum_instance: Pending deprecation\: The quantum instance on which the + quantum_instance: Deprecated: The quantum instance on which the circuit will be run. sampler: The sampler primitive on which the circuit will be sampled. diff --git a/qiskit/algorithms/phase_estimators/phase_estimation.py b/qiskit/algorithms/phase_estimators/phase_estimation.py index ff8e92dd11d2..a3bc1d59c60d 100644 --- a/qiskit/algorithms/phase_estimators/phase_estimation.py +++ b/qiskit/algorithms/phase_estimators/phase_estimation.py @@ -83,9 +83,11 @@ class PhaseEstimation(PhaseEstimator): @deprecate_arg( "quantum_instance", - additional_msg="Instead, use the ``sampler`` argument.", - since="0.22.0", - pending=True, + additional_msg=( + "Instead, use the ``sampler`` argument. See https://qisk.it/algo_migration for a " + "migration guide." + ), + since="0.24.0", ) def __init__( self, @@ -97,7 +99,7 @@ def __init__( Args: num_evaluation_qubits: The number of qubits used in estimating the phase. The phase will be estimated as a binary string with this many bits. - quantum_instance: Pending deprecation\: The quantum instance on which the + quantum_instance: Deprecated: The quantum instance on which the circuit will be run. sampler: The sampler primitive on which the circuit will be sampled. diff --git a/releasenotes/notes/deprecate-algorithms-c6e1e28b6091c507.yaml b/releasenotes/notes/deprecate-algorithms-c6e1e28b6091c507.yaml new file mode 100644 index 000000000000..fdcbcf8890e5 --- /dev/null +++ b/releasenotes/notes/deprecate-algorithms-c6e1e28b6091c507.yaml @@ -0,0 +1,38 @@ +--- +deprecations: + - | + All of the following features are now deprecated, after having been made pending deprecation + since 0.22.0. More information is available at https://qisk.it/algo_migration. + + Module :mod:`qiskit.algorithms.minimum_eigen_solvers` is deprecated and + superseded by :mod:`qiskit.algorithms.minimum_eigensolvers`. + + Module :mod:`qiskit.algorithms.eigen_solvers` is deprecated and + superseded by :mod:`qiskit.algorithms.eigensolvers`. + + Module :mod:`qiskit.algorithms.evolvers` is deprecated and + superseded by :mod:`qiskit.algorithms.time_evolvers`. + + Class :class:`qiskit.algorithms.TrotterQRTE` is deprecated and superseded by + :class:`qiskit.algorithms.time_evolvers.trotterization.TrotterQRTE`. + + Using :class:`~qiskit.utils.QuantumInstance` or :class:`~qiskit.providers.Backend` + is deprecated and superseded by + :class:`~qiskit.primitives.BaseSampler` in the following classes: + :class:`~qiskit.algorithms.amplitude_amplifiers.Grover`, + :class:`~qiskit.algorithms.amplitude_estimators.AmplitudeEstimation`, + :class:`~qiskit.algorithms.amplitude_estimators.FasterAmplitudeEstimation`, + :class:`~qiskit.algorithms.amplitude_estimators.IterativePhaseEstimation`, + :class:`~qiskit.algorithms.amplitude_estimators.MaximumLikelihoodAmplitudeEstimation`, + :class:`~qiskit.algorithms.phase_estimators.HamiltonianPhaseEstimation`, + :class:`~qiskit.algorithms.phase_estimators.IterativePhaseEstimation`, + :class:`~qiskit.algorithms.phase_estimators.PhaseEstimation` + + Using :class:`~qiskit.utils.QuantumInstance` or :class:`~qiskit.providers.Backend` + or :class:`~qiskit.opflow.ExpectationBase` is deprecated and superseded by + :class:`~qiskit.primitives.BaseSampler` in the following static method: + :meth:`~qiskit.algorithms.optimizers.QNSPSA.get_fidelity` + + Function :func:`~qiskit.algorithms.aux_ops_evaluator.eval_observables` is deprecated + and superseded by + :func:`~qiskit.algorithms.observables_evaluator.estimate_observables` function. diff --git a/test/python/algorithms/evolvers/test_evolution_problem.py b/test/python/algorithms/evolvers/test_evolution_problem.py index d3dd2f7bc9b2..6f0cf4e7fd83 100644 --- a/test/python/algorithms/evolvers/test_evolution_problem.py +++ b/test/python/algorithms/evolvers/test_evolution_problem.py @@ -31,7 +31,8 @@ def test_init_default(self): time = 2.5 initial_state = One - evo_problem = EvolutionProblem(hamiltonian, time, initial_state) + with self.assertWarns(DeprecationWarning): + evo_problem = EvolutionProblem(hamiltonian, time, initial_state) expected_hamiltonian = Y expected_time = 2.5 @@ -56,14 +57,15 @@ def test_init_all(self): aux_operators = [X, Y] param_value_dict = {t_parameter: 3.2} - evo_problem = EvolutionProblem( - hamiltonian, - time, - initial_state, - aux_operators, - t_param=t_parameter, - param_value_dict=param_value_dict, - ) + with self.assertWarns(DeprecationWarning): + evo_problem = EvolutionProblem( + hamiltonian, + time, + initial_state, + aux_operators, + t_param=t_parameter, + param_value_dict=param_value_dict, + ) expected_hamiltonian = Y + t_parameter * Z expected_time = 2 @@ -83,7 +85,7 @@ def test_init_all(self): @unpack def test_init_errors(self, hamiltonian, time, initial_state): """Tests expected errors are thrown on invalid time argument.""" - with assert_raises(ValueError): + with self.assertWarns(DeprecationWarning), assert_raises(ValueError): _ = EvolutionProblem(hamiltonian, time, initial_state) def test_validate_params(self): @@ -93,21 +95,30 @@ def test_validate_params(self): with self.subTest(msg="Parameter missing in dict."): hamiltonian = param_x * X + param_y * Y param_dict = {param_y: 2} - evolution_problem = EvolutionProblem(hamiltonian, 2, Zero, param_value_dict=param_dict) + with self.assertWarns(DeprecationWarning): + evolution_problem = EvolutionProblem( + hamiltonian, 2, Zero, param_value_dict=param_dict + ) with assert_raises(ValueError): evolution_problem.validate_params() with self.subTest(msg="Empty dict."): hamiltonian = param_x * X + param_y * Y param_dict = {} - evolution_problem = EvolutionProblem(hamiltonian, 2, Zero, param_value_dict=param_dict) + with self.assertWarns(DeprecationWarning): + evolution_problem = EvolutionProblem( + hamiltonian, 2, Zero, param_value_dict=param_dict + ) with assert_raises(ValueError): evolution_problem.validate_params() with self.subTest(msg="Extra parameter in dict."): hamiltonian = param_x * X + param_y * Y param_dict = {param_y: 2, param_x: 1, Parameter("z"): 1} - evolution_problem = EvolutionProblem(hamiltonian, 2, Zero, param_value_dict=param_dict) + with self.assertWarns(DeprecationWarning): + evolution_problem = EvolutionProblem( + hamiltonian, 2, Zero, param_value_dict=param_dict + ) with assert_raises(ValueError): evolution_problem.validate_params() diff --git a/test/python/algorithms/evolvers/test_evolution_result.py b/test/python/algorithms/evolvers/test_evolution_result.py index 5500b283a1cb..2fe40d8c66f8 100644 --- a/test/python/algorithms/evolvers/test_evolution_result.py +++ b/test/python/algorithms/evolvers/test_evolution_result.py @@ -23,7 +23,8 @@ class TestEvolutionResult(QiskitAlgorithmsTestCase): def test_init_state(self): """Tests that a class is initialized correctly with an evolved_state.""" evolved_state = Zero - evo_result = EvolutionResult(evolved_state=evolved_state) + with self.assertWarns(DeprecationWarning): + evo_result = EvolutionResult(evolved_state=evolved_state) expected_state = Zero expected_aux_ops_evaluated = None @@ -35,7 +36,8 @@ def test_init_observable(self): """Tests that a class is initialized correctly with an evolved_observable.""" evolved_state = Zero evolved_aux_ops_evaluated = [(5j, 5j), (1.0, 8j), (5 + 1j, 6 + 1j)] - evo_result = EvolutionResult(evolved_state, evolved_aux_ops_evaluated) + with self.assertWarns(DeprecationWarning): + evo_result = EvolutionResult(evolved_state, evolved_aux_ops_evaluated) expected_state = Zero expected_aux_ops_evaluated = [(5j, 5j), (1.0, 8j), (5 + 1j, 6 + 1j)] diff --git a/test/python/algorithms/evolvers/trotterization/test_trotter_qrte.py b/test/python/algorithms/evolvers/trotterization/test_trotter_qrte.py index 47e4940b2f07..7f7f5e797c82 100644 --- a/test/python/algorithms/evolvers/trotterization/test_trotter_qrte.py +++ b/test/python/algorithms/evolvers/trotterization/test_trotter_qrte.py @@ -92,10 +92,10 @@ def test_trotter_qrte_trotter_single_qubit(self, product_formula, expected_state operator = SummedOp([X, Z]) initial_state = StateFn([1, 0]) time = 1 - evolution_problem = EvolutionProblem(operator, time, initial_state) - - trotter_qrte = TrotterQRTE(product_formula=product_formula) - evolution_result_state_circuit = trotter_qrte.evolve(evolution_problem).evolved_state + with self.assertWarns(DeprecationWarning): + evolution_problem = EvolutionProblem(operator, time, initial_state) + trotter_qrte = TrotterQRTE(product_formula=product_formula) + evolution_result_state_circuit = trotter_qrte.evolve(evolution_problem).evolved_state np.testing.assert_equal(evolution_result_state_circuit.eval(), expected_state) @@ -107,7 +107,8 @@ def test_trotter_qrte_trotter_single_qubit_aux_ops(self): initial_state = Zero time = 3 - evolution_problem = EvolutionProblem(operator, time, initial_state, aux_ops) + with self.assertWarns(DeprecationWarning): + evolution_problem = EvolutionProblem(operator, time, initial_state, aux_ops) expected_evolved_state = VectorStateFn( Statevector([0.98008514 + 0.13970775j, 0.01991486 + 0.13970775j], dims=(2,)) @@ -126,8 +127,9 @@ def test_trotter_qrte_trotter_single_qubit_aux_ops(self): operator=operator, backend=backend, ) - trotter_qrte = TrotterQRTE(quantum_instance=backend, expectation=expectation) - evolution_result = trotter_qrte.evolve(evolution_problem) + with self.assertWarns(DeprecationWarning): + trotter_qrte = TrotterQRTE(quantum_instance=backend, expectation=expectation) + evolution_result = trotter_qrte.evolve(evolution_problem) np.testing.assert_equal( evolution_result.evolved_state.eval(), expected_evolved_state @@ -169,10 +171,10 @@ def test_trotter_qrte_trotter_two_qubits(self, operator, expected_state): """Test for TrotterQRTE on two qubits with various types of a Hamiltonian.""" # LieTrotter with 1 rep initial_state = StateFn([1, 0, 0, 0]) - evolution_problem = EvolutionProblem(operator, 1, initial_state) - - trotter_qrte = TrotterQRTE() - evolution_result = trotter_qrte.evolve(evolution_problem) + with self.assertWarns(DeprecationWarning): + evolution_problem = EvolutionProblem(operator, 1, initial_state) + trotter_qrte = TrotterQRTE() + evolution_result = trotter_qrte.evolve(evolution_problem) np.testing.assert_equal(evolution_result.evolved_state.eval(), expected_state) def test_trotter_qrte_trotter_two_qubits_with_params(self): @@ -184,14 +186,15 @@ def test_trotter_qrte_trotter_two_qubits_with_params(self): params_dict = {w_param: 2.0, u_param: 3.0} operator = w_param * (Z ^ Z) / 2.0 + (Z ^ I) + u_param * (I ^ Z) / 3.0 time = 1 - evolution_problem = EvolutionProblem( - operator, time, initial_state, param_value_dict=params_dict - ) expected_state = VectorStateFn( Statevector([-0.9899925 - 0.14112001j, 0.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j], dims=(2, 2)) ) - trotter_qrte = TrotterQRTE() - evolution_result = trotter_qrte.evolve(evolution_problem) + with self.assertWarns(DeprecationWarning): + evolution_problem = EvolutionProblem( + operator, time, initial_state, param_value_dict=params_dict + ) + trotter_qrte = TrotterQRTE() + evolution_result = trotter_qrte.evolve(evolution_problem) np.testing.assert_equal(evolution_result.evolved_state.eval(), expected_state) @data( @@ -213,11 +216,11 @@ def test_trotter_qrte_qdrift(self, initial_state, expected_state): """Test for TrotterQRTE with QDrift.""" operator = SummedOp([X, Z]) time = 1 - evolution_problem = EvolutionProblem(operator, time, initial_state) - algorithm_globals.random_seed = 0 - trotter_qrte = TrotterQRTE(product_formula=QDrift()) - evolution_result = trotter_qrte.evolve(evolution_problem) + with self.assertWarns(DeprecationWarning): + evolution_problem = EvolutionProblem(operator, time, initial_state) + trotter_qrte = TrotterQRTE(product_formula=QDrift()) + evolution_result = trotter_qrte.evolve(evolution_problem) np.testing.assert_equal(evolution_result.evolved_state.eval(), expected_state) @data((Parameter("t"), {}), (None, {Parameter("x"): 2}), (None, None)) @@ -228,8 +231,8 @@ def test_trotter_qrte_trotter_errors(self, t_param, param_value_dict): initial_state = Zero time = 1 algorithm_globals.random_seed = 0 - trotter_qrte = TrotterQRTE() - with assert_raises(ValueError): + with self.assertWarns(DeprecationWarning): + trotter_qrte = TrotterQRTE() evolution_problem = EvolutionProblem( operator, time, @@ -237,6 +240,7 @@ def test_trotter_qrte_trotter_errors(self, t_param, param_value_dict): t_param=t_param, param_value_dict=param_value_dict, ) + with assert_raises(ValueError): _ = trotter_qrte.evolve(evolution_problem) diff --git a/test/python/algorithms/optimizers/test_optimizer_aqgd.py b/test/python/algorithms/optimizers/test_optimizer_aqgd.py index d4923b7cb18b..da1c6e8db889 100644 --- a/test/python/algorithms/optimizers/test_optimizer_aqgd.py +++ b/test/python/algorithms/optimizers/test_optimizer_aqgd.py @@ -53,13 +53,14 @@ def test_simple(self): ) aqgd = AQGD(momentum=0.0) - vqe = VQE( - ansatz=RealAmplitudes(), - optimizer=aqgd, - gradient=Gradient("lin_comb"), - quantum_instance=q_instance, - ) - result = vqe.compute_minimum_eigenvalue(operator=self.qubit_op) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=RealAmplitudes(), + optimizer=aqgd, + gradient=Gradient("lin_comb"), + quantum_instance=q_instance, + ) + result = vqe.compute_minimum_eigenvalue(operator=self.qubit_op) self.assertAlmostEqual(result.eigenvalue.real, -1.857, places=3) @unittest.skipUnless(optionals.HAS_AER, "qiskit-aer is required to run this test") @@ -74,8 +75,9 @@ def test_list(self): ) aqgd = AQGD(maxiter=[1000, 1000, 1000], eta=[1.0, 0.5, 0.3], momentum=[0.0, 0.5, 0.75]) - vqe = VQE(ansatz=RealAmplitudes(), optimizer=aqgd, quantum_instance=q_instance) - result = vqe.compute_minimum_eigenvalue(operator=self.qubit_op) + with self.assertWarns(DeprecationWarning): + vqe = VQE(ansatz=RealAmplitudes(), optimizer=aqgd, quantum_instance=q_instance) + result = vqe.compute_minimum_eigenvalue(operator=self.qubit_op) self.assertAlmostEqual(result.eigenvalue.real, -1.857, places=3) def test_raises_exception(self): @@ -95,13 +97,14 @@ def test_int_values(self): ) aqgd = AQGD(maxiter=1000, eta=1, momentum=0) - vqe = VQE( - ansatz=RealAmplitudes(), - optimizer=aqgd, - gradient=Gradient("lin_comb"), - quantum_instance=q_instance, - ) - result = vqe.compute_minimum_eigenvalue(operator=self.qubit_op) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=RealAmplitudes(), + optimizer=aqgd, + gradient=Gradient("lin_comb"), + quantum_instance=q_instance, + ) + result = vqe.compute_minimum_eigenvalue(operator=self.qubit_op) self.assertAlmostEqual(result.eigenvalue.real, -1.857, places=3) diff --git a/test/python/algorithms/optimizers/test_optimizer_nft.py b/test/python/algorithms/optimizers/test_optimizer_nft.py index b3f813188c42..765c0ad3d880 100644 --- a/test/python/algorithms/optimizers/test_optimizer_nft.py +++ b/test/python/algorithms/optimizers/test_optimizer_nft.py @@ -42,16 +42,17 @@ def setUp(self): def test_nft(self): """Test NFT optimizer by using it""" - vqe = VQE( - ansatz=RealAmplitudes(), - optimizer=NFT(), - quantum_instance=QuantumInstance( - BasicAer.get_backend("statevector_simulator"), - seed_simulator=algorithm_globals.random_seed, - seed_transpiler=algorithm_globals.random_seed, - ), - ) - result = vqe.compute_minimum_eigenvalue(operator=self.qubit_op) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=RealAmplitudes(), + optimizer=NFT(), + quantum_instance=QuantumInstance( + BasicAer.get_backend("statevector_simulator"), + seed_simulator=algorithm_globals.random_seed, + seed_transpiler=algorithm_globals.random_seed, + ), + ) + result = vqe.compute_minimum_eigenvalue(operator=self.qubit_op) self.assertAlmostEqual(result.eigenvalue.real, -1.857275, places=6) diff --git a/test/python/algorithms/optimizers/test_optimizers_scikitquant.py b/test/python/algorithms/optimizers/test_optimizers_scikitquant.py index 503451de2394..f07a0238f7de 100644 --- a/test/python/algorithms/optimizers/test_optimizers_scikitquant.py +++ b/test/python/algorithms/optimizers/test_optimizers_scikitquant.py @@ -52,8 +52,9 @@ def _optimize(self, optimizer): seed_simulator=algorithm_globals.random_seed, seed_transpiler=algorithm_globals.random_seed, ) - vqe = VQE(ansatz=RealAmplitudes(), optimizer=optimizer, quantum_instance=qe) - result = vqe.compute_minimum_eigenvalue(operator=self.qubit_op) + with self.assertWarns(DeprecationWarning): + vqe = VQE(ansatz=RealAmplitudes(), optimizer=optimizer, quantum_instance=qe) + result = vqe.compute_minimum_eigenvalue(operator=self.qubit_op) self.assertAlmostEqual(result.eigenvalue.real, -1.857, places=1) def test_bobyqa(self): diff --git a/test/python/algorithms/optimizers/test_spsa.py b/test/python/algorithms/optimizers/test_spsa.py index 6204198c02ba..394bee0ba81d 100644 --- a/test/python/algorithms/optimizers/test_spsa.py +++ b/test/python/algorithms/optimizers/test_spsa.py @@ -201,9 +201,9 @@ def objective(x): def test_qnspsa_fidelity_deprecation(self): """Test using a backend and expectation converter in get_fidelity warns.""" ansatz = PauliTwoDesign(2, reps=1, seed=2) - with self.assertWarns(PendingDeprecationWarning): + with self.assertWarns(DeprecationWarning): QNSPSA.get_fidelity(ansatz, backend=StatevectorSimulatorPy()) - with self.assertWarns(PendingDeprecationWarning): + with self.assertWarns(DeprecationWarning): QNSPSA.get_fidelity(ansatz, expectation=MatrixExpectation()) # No warning when used correctly. QNSPSA.get_fidelity(ansatz) diff --git a/test/python/algorithms/test_amplitude_estimators.py b/test/python/algorithms/test_amplitude_estimators.py index 2c4b7b792171..4868f2643788 100644 --- a/test/python/algorithms/test_amplitude_estimators.py +++ b/test/python/algorithms/test_amplitude_estimators.py @@ -128,7 +128,8 @@ def sampler_shots(shots=100): @unpack def test_statevector(self, prob, qae, expect): """statevector test""" - qae.quantum_instance = self._statevector + with self.assertWarns(DeprecationWarning): + qae.quantum_instance = self._statevector problem = EstimationProblem(BernoulliStateIn(prob), 0, BernoulliGrover(prob)) result = qae.estimate(problem) @@ -185,7 +186,8 @@ def test_sampler(self, prob, qae, expect): @unpack def test_qasm(self, prob, shots, qae, expect): """qasm test""" - qae.quantum_instance = self._qasm(shots) + with self.assertWarns(DeprecationWarning): + qae.quantum_instance = self._qasm(shots) problem = EstimationProblem(BernoulliStateIn(prob), [0], BernoulliGrover(prob)) result = qae.estimate(problem) @@ -409,7 +411,8 @@ def test_statevector(self, n, qae, expect): """Statevector end-to-end test""" # construct factories for A and Q # qae.state_preparation = SineIntegral(n) - qae.quantum_instance = self._statevector + with self.assertWarns(DeprecationWarning): + qae.quantum_instance = self._statevector estimation_problem = EstimationProblem(SineIntegral(n), objective_qubits=[n]) # result = qae.run(self._statevector) @@ -454,7 +457,8 @@ def test_sampler(self, n, qae, expect): def test_qasm(self, n, shots, qae, expect): """QASM simulator end-to-end test.""" # construct factories for A and Q - qae.quantum_instance = self._qasm(shots) + with self.assertWarns(DeprecationWarning): + qae.quantum_instance = self._qasm(shots) estimation_problem = EstimationProblem(SineIntegral(n), objective_qubits=[n]) result = qae.estimate(estimation_problem) @@ -510,7 +514,8 @@ def test_sampler_with_shots(self, n, shots, qae, expect): def test_confidence_intervals(self, qae, key, expect): """End-to-end test for all confidence intervals.""" n = 3 - qae.quantum_instance = self._statevector + with self.assertWarns(DeprecationWarning): + qae.quantum_instance = self._statevector estimation_problem = EstimationProblem(SineIntegral(n), objective_qubits=[n]) # statevector simulator @@ -527,7 +532,8 @@ def test_confidence_intervals(self, qae, key, expect): # qasm simulator shots = 100 alpha = 0.01 - qae.quantum_instance = self._qasm(shots) + with self.assertWarns(DeprecationWarning): + qae.quantum_instance = self._qasm(shots) result = qae.estimate(estimation_problem) for method, expected_confint in expect.items(): confint = qae.compute_confidence_interval(result, alpha, method) @@ -537,7 +543,8 @@ def test_confidence_intervals(self, qae, key, expect): def test_iqae_confidence_intervals(self): """End-to-end test for the IQAE confidence interval.""" n = 3 - qae = IterativeAmplitudeEstimation(0.1, 0.01, quantum_instance=self._statevector) + with self.assertWarns(DeprecationWarning): + qae = IterativeAmplitudeEstimation(0.1, 0.01, quantum_instance=self._statevector) expected_confint = (0.1984050, 0.3511015) estimation_problem = EstimationProblem(SineIntegral(n), objective_qubits=[n]) @@ -551,7 +558,8 @@ def test_iqae_confidence_intervals(self): # qasm simulator shots = 100 - qae.quantum_instance = self._qasm(shots) + with self.assertWarns(DeprecationWarning): + qae.quantum_instance = self._qasm(shots) result = qae.estimate(estimation_problem) confint = result.confidence_interval np.testing.assert_array_almost_equal(confint, expected_confint) @@ -603,7 +611,8 @@ def test_run_without_rescaling(self): # construct algo without rescaling backend = BasicAer.get_backend("statevector_simulator") - fae = FasterAmplitudeEstimation(0.1, 1, rescale=False, quantum_instance=backend) + with self.assertWarns(DeprecationWarning): + fae = FasterAmplitudeEstimation(0.1, 1, rescale=False, quantum_instance=backend) # run the algo result = fae.estimate(problem) @@ -647,7 +656,8 @@ def test_rescaling_with_custom_grover_raises(self): # construct algo without rescaling backend = BasicAer.get_backend("statevector_simulator") - fae = FasterAmplitudeEstimation(0.1, 1, quantum_instance=backend) + with self.assertWarns(DeprecationWarning): + fae = FasterAmplitudeEstimation(0.1, 1, quantum_instance=backend) # run the algo with self.assertWarns(Warning): @@ -682,7 +692,8 @@ def is_good_state(bitstr): BasicAer.get_backend(backend_str), seed_simulator=2, seed_transpiler=2 ) # cannot use rescaling with a custom grover operator - fae = FasterAmplitudeEstimation(0.01, 5, rescale=False, quantum_instance=backend) + with self.assertWarns(DeprecationWarning): + fae = FasterAmplitudeEstimation(0.01, 5, rescale=False, quantum_instance=backend) # run the algo result = fae.estimate(problem) diff --git a/test/python/algorithms/test_aux_ops_evaluator.py b/test/python/algorithms/test_aux_ops_evaluator.py index 0f956bbb9adf..5a75843eeac9 100644 --- a/test/python/algorithms/test_aux_ops_evaluator.py +++ b/test/python/algorithms/test_aux_ops_evaluator.py @@ -85,9 +85,10 @@ def _run_test( observables: ListOrDict[OperatorBase], quantum_instance: Union[QuantumInstance, Backend], ): - result = eval_observables( - quantum_instance, quantum_state, observables, expectation, self.threshold - ) + with self.assertWarns(DeprecationWarning): + result = eval_observables( + quantum_instance, quantum_state, observables, expectation, self.threshold + ) if isinstance(observables, dict): np.testing.assert_equal(list(result.keys()), list(expected_result.keys())) diff --git a/test/python/algorithms/test_backendv1.py b/test/python/algorithms/test_backendv1.py index ed4bf878495a..2ed807d3d8ce 100644 --- a/test/python/algorithms/test_backendv1.py +++ b/test/python/algorithms/test_backendv1.py @@ -47,14 +47,14 @@ def test_vqe_qasm(self): qasm_simulator = QuantumInstance( self._qasm, shots=1024, seed_simulator=self.seed, seed_transpiler=self.seed ) - vqe = VQE( - ansatz=wavefunction, - optimizer=optimizer, - max_evals_grouped=1, - quantum_instance=qasm_simulator, - ) - - result = vqe.compute_minimum_eigenvalue(operator=h2_op) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=wavefunction, + optimizer=optimizer, + max_evals_grouped=1, + quantum_instance=qasm_simulator, + ) + result = vqe.compute_minimum_eigenvalue(operator=h2_op) self.assertAlmostEqual(result.eigenvalue.real, -1.86, delta=0.05) def test_run_circuit_oracle(self): @@ -65,7 +65,7 @@ def test_run_circuit_oracle(self): qi = QuantumInstance( self._provider.get_backend("fake_vigo"), seed_simulator=12, seed_transpiler=32 ) - with self.assertWarns(PendingDeprecationWarning): + with self.assertWarns(DeprecationWarning): grover = Grover(quantum_instance=qi) result = grover.amplify(problem) self.assertIn(result.top_measurement, ["11"]) @@ -78,7 +78,7 @@ def test_run_circuit_oracle_single_experiment_backend(self): backend = self._provider.get_backend("fake_vigo") backend._configuration.max_experiments = 1 qi = QuantumInstance(backend, seed_simulator=12, seed_transpiler=32) - with self.assertWarns(PendingDeprecationWarning): + with self.assertWarns(DeprecationWarning): grover = Grover(quantum_instance=qi) result = grover.amplify(problem) self.assertIn(result.top_measurement, ["11"]) @@ -118,8 +118,9 @@ def test_measurement_error_mitigation_with_vqe(self): optimizer = SPSA(maxiter=200) ansatz = EfficientSU2(2, reps=1) - vqe = VQE(ansatz=ansatz, optimizer=optimizer, quantum_instance=quantum_instance) - result = vqe.compute_minimum_eigenvalue(operator=h2_hamiltonian) + with self.assertWarns(DeprecationWarning): + vqe = VQE(ansatz=ansatz, optimizer=optimizer, quantum_instance=quantum_instance) + result = vqe.compute_minimum_eigenvalue(operator=h2_hamiltonian) self.assertGreater(quantum_instance.time_taken, 0.0) quantum_instance.reset_execution_results() self.assertAlmostEqual(result.eigenvalue.real, -1.86, delta=0.05) diff --git a/test/python/algorithms/test_backendv2.py b/test/python/algorithms/test_backendv2.py index 71712a4a5c7e..83bbf848f211 100644 --- a/test/python/algorithms/test_backendv2.py +++ b/test/python/algorithms/test_backendv2.py @@ -47,14 +47,14 @@ def test_vqe_qasm(self): qasm_simulator = QuantumInstance( self._qasm, shots=1024, seed_simulator=self.seed, seed_transpiler=self.seed ) - vqe = VQE( - ansatz=wavefunction, - optimizer=optimizer, - max_evals_grouped=1, - quantum_instance=qasm_simulator, - ) - - result = vqe.compute_minimum_eigenvalue(operator=h2_op) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=wavefunction, + optimizer=optimizer, + max_evals_grouped=1, + quantum_instance=qasm_simulator, + ) + result = vqe.compute_minimum_eigenvalue(operator=h2_op) self.assertAlmostEqual(result.eigenvalue.real, -1.86, delta=0.05) def test_run_circuit_oracle(self): @@ -65,7 +65,7 @@ def test_run_circuit_oracle(self): qi = QuantumInstance( self._provider.get_backend("fake_yorktown"), seed_simulator=12, seed_transpiler=32 ) - with self.assertWarns(PendingDeprecationWarning): + with self.assertWarns(DeprecationWarning): grover = Grover(quantum_instance=qi) result = grover.amplify(problem) self.assertIn(result.top_measurement, ["11"]) @@ -80,7 +80,7 @@ def test_run_circuit_oracle_single_experiment_backend(self): qi = QuantumInstance( self._provider.get_backend("fake_yorktown"), seed_simulator=12, seed_transpiler=32 ) - with self.assertWarns(PendingDeprecationWarning): + with self.assertWarns(DeprecationWarning): grover = Grover(quantum_instance=qi) result = grover.amplify(problem) self.assertIn(result.top_measurement, ["11"]) diff --git a/test/python/algorithms/test_grover.py b/test/python/algorithms/test_grover.py index 5658ad5a2323..ae9e627b411f 100644 --- a/test/python/algorithms/test_grover.py +++ b/test/python/algorithms/test_grover.py @@ -326,7 +326,7 @@ def _prepare_grover( sample_from_iterations=sample_from_iterations, ) else: - with self.assertWarns(PendingDeprecationWarning): + with self.assertWarns(DeprecationWarning): grover = Grover( quantum_instance=self.qasm, iterations=iterations, diff --git a/test/python/algorithms/test_measure_error_mitigation.py b/test/python/algorithms/test_measure_error_mitigation.py index b53b6fd797d0..8a53708ec5f4 100644 --- a/test/python/algorithms/test_measure_error_mitigation.py +++ b/test/python/algorithms/test_measure_error_mitigation.py @@ -152,8 +152,9 @@ def test_measurement_error_mitigation_with_vqe(self, config): optimizer = SPSA(maxiter=200) ansatz = EfficientSU2(2, reps=1) - vqe = VQE(ansatz=ansatz, optimizer=optimizer, quantum_instance=quantum_instance) - result = vqe.compute_minimum_eigenvalue(operator=h2_hamiltonian) + with self.assertWarns(DeprecationWarning): + vqe = VQE(ansatz=ansatz, optimizer=optimizer, quantum_instance=quantum_instance) + result = vqe.compute_minimum_eigenvalue(operator=h2_hamiltonian) self.assertGreater(quantum_instance.time_taken, 0.0) quantum_instance.reset_execution_results() self.assertAlmostEqual(result.eigenvalue.real, -1.86, delta=0.05) @@ -201,12 +202,13 @@ def test_measurement_error_mitigation_qaoa(self): seed_simulator=algorithm_globals.random_seed, seed_transpiler=algorithm_globals.random_seed, ) - qaoa = QAOA( - optimizer=COBYLA(maxiter=3), - quantum_instance=quantum_instance, - initial_point=initial_point, - ) - result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) + with self.assertWarns(DeprecationWarning): + qaoa = QAOA( + optimizer=COBYLA(maxiter=3), + quantum_instance=quantum_instance, + initial_point=initial_point, + ) + result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) ref_eigenvalue = result.eigenvalue.real # compute with noise @@ -224,12 +226,13 @@ def test_measurement_error_mitigation_qaoa(self): shots=10000, ) - qaoa = QAOA( - optimizer=COBYLA(maxiter=3), - quantum_instance=quantum_instance, - initial_point=initial_point, - ) - result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) + with self.assertWarns(DeprecationWarning): + qaoa = QAOA( + optimizer=COBYLA(maxiter=3), + quantum_instance=quantum_instance, + initial_point=initial_point, + ) + result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) self.assertAlmostEqual(result.eigenvalue.real, ref_eigenvalue, delta=0.05) @unittest.skipUnless(optionals.HAS_AER, "qiskit-aer is required for this test") @@ -330,8 +333,8 @@ def test_measurement_error_mitigation_with_vqe_ignis(self, config): optimizer = SPSA(maxiter=200) ansatz = EfficientSU2(2, reps=1) - vqe = VQE(ansatz=ansatz, optimizer=optimizer, quantum_instance=quantum_instance) - with self.assertWarnsRegex(DeprecationWarning, r".*ignis.*"): + with self.assertWarnsRegex(DeprecationWarning): + vqe = VQE(ansatz=ansatz, optimizer=optimizer, quantum_instance=quantum_instance) result = vqe.compute_minimum_eigenvalue(operator=h2_hamiltonian) self.assertGreater(quantum_instance.time_taken, 0.0) quantum_instance.reset_execution_results() diff --git a/test/python/algorithms/test_numpy_eigen_solver.py b/test/python/algorithms/test_numpy_eigen_solver.py index d26b6e202feb..6b2b41b796a7 100644 --- a/test/python/algorithms/test_numpy_eigen_solver.py +++ b/test/python/algorithms/test_numpy_eigen_solver.py @@ -40,8 +40,9 @@ def setUp(self): def test_ce(self): """Test basics""" - algo = NumPyEigensolver() - result = algo.compute_eigenvalues(operator=self.qubit_op, aux_operators=[]) + with self.assertWarns(DeprecationWarning): + algo = NumPyEigensolver() + result = algo.compute_eigenvalues(operator=self.qubit_op, aux_operators=[]) self.assertEqual(len(result.eigenvalues), 1) self.assertEqual(len(result.eigenstates), 1) self.assertEqual(result.eigenvalues.dtype, np.float64) @@ -49,8 +50,9 @@ def test_ce(self): def test_ce_k4(self): """Test for k=4 eigenvalues""" - algo = NumPyEigensolver(k=4) - result = algo.compute_eigenvalues(operator=self.qubit_op, aux_operators=[]) + with self.assertWarns(DeprecationWarning): + algo = NumPyEigensolver(k=4) + result = algo.compute_eigenvalues(operator=self.qubit_op, aux_operators=[]) self.assertEqual(len(result.eigenvalues), 4) self.assertEqual(len(result.eigenstates), 4) self.assertEqual(result.eigenvalues.dtype, np.float64) @@ -66,8 +68,9 @@ def test_ce_k4_filtered(self): def criterion(x, v, a_v): return v >= -1 - algo = NumPyEigensolver(k=4, filter_criterion=criterion) - result = algo.compute_eigenvalues(operator=self.qubit_op, aux_operators=[]) + with self.assertWarns(DeprecationWarning): + algo = NumPyEigensolver(k=4, filter_criterion=criterion) + result = algo.compute_eigenvalues(operator=self.qubit_op, aux_operators=[]) self.assertEqual(len(result.eigenvalues), 2) self.assertEqual(len(result.eigenstates), 2) self.assertEqual(result.eigenvalues.dtype, np.float64) @@ -81,23 +84,26 @@ def test_ce_k4_filtered_empty(self): def criterion(x, v, a_v): return False - algo = NumPyEigensolver(k=4, filter_criterion=criterion) - result = algo.compute_eigenvalues(operator=self.qubit_op, aux_operators=[]) + with self.assertWarns(DeprecationWarning): + algo = NumPyEigensolver(k=4, filter_criterion=criterion) + result = algo.compute_eigenvalues(operator=self.qubit_op, aux_operators=[]) self.assertEqual(len(result.eigenvalues), 0) self.assertEqual(len(result.eigenstates), 0) @data(X, Y, Z) def test_ce_k1_1q(self, op): """Test for 1 qubit operator""" - algo = NumPyEigensolver(k=1) - result = algo.compute_eigenvalues(operator=op) + with self.assertWarns(DeprecationWarning): + algo = NumPyEigensolver(k=1) + result = algo.compute_eigenvalues(operator=op) np.testing.assert_array_almost_equal(result.eigenvalues, [-1]) @data(X, Y, Z) def test_ce_k2_1q(self, op): """Test for 1 qubit operator""" - algo = NumPyEigensolver(k=2) - result = algo.compute_eigenvalues(operator=op) + with self.assertWarns(DeprecationWarning): + algo = NumPyEigensolver(k=2) + result = algo.compute_eigenvalues(operator=op) np.testing.assert_array_almost_equal(result.eigenvalues, [-1, 1]) def test_aux_operators_list(self): @@ -105,8 +111,9 @@ def test_aux_operators_list(self): aux_op1 = PauliSumOp.from_list([("II", 2.0)]) aux_op2 = PauliSumOp.from_list([("II", 0.5), ("ZZ", 0.5), ("YY", 0.5), ("XX", -0.5)]) aux_ops = [aux_op1, aux_op2] - algo = NumPyEigensolver() - result = algo.compute_eigenvalues(operator=self.qubit_op, aux_operators=aux_ops) + with self.assertWarns(DeprecationWarning): + algo = NumPyEigensolver() + result = algo.compute_eigenvalues(operator=self.qubit_op, aux_operators=aux_ops) self.assertEqual(len(result.eigenvalues), 1) self.assertEqual(len(result.eigenstates), 1) self.assertEqual(result.eigenvalues.dtype, np.float64) @@ -122,7 +129,8 @@ def test_aux_operators_list(self): # Go again with additional None and zero operators extra_ops = [*aux_ops, None, 0] - result = algo.compute_eigenvalues(operator=self.qubit_op, aux_operators=extra_ops) + with self.assertWarns(DeprecationWarning): + result = algo.compute_eigenvalues(operator=self.qubit_op, aux_operators=extra_ops) self.assertEqual(len(result.eigenvalues), 1) self.assertEqual(len(result.eigenstates), 1) self.assertEqual(result.eigenvalues.dtype, np.float64) @@ -144,8 +152,9 @@ def test_aux_operators_dict(self): aux_op1 = PauliSumOp.from_list([("II", 2.0)]) aux_op2 = PauliSumOp.from_list([("II", 0.5), ("ZZ", 0.5), ("YY", 0.5), ("XX", -0.5)]) aux_ops = {"aux_op1": aux_op1, "aux_op2": aux_op2} - algo = NumPyEigensolver() - result = algo.compute_eigenvalues(operator=self.qubit_op, aux_operators=aux_ops) + with self.assertWarns(DeprecationWarning): + algo = NumPyEigensolver() + result = algo.compute_eigenvalues(operator=self.qubit_op, aux_operators=aux_ops) self.assertEqual(len(result.eigenvalues), 1) self.assertEqual(len(result.eigenstates), 1) self.assertEqual(result.eigenvalues.dtype, np.float64) @@ -161,7 +170,8 @@ def test_aux_operators_dict(self): # Go again with additional None and zero operators extra_ops = {**aux_ops, "None_operator": None, "zero_operator": 0} - result = algo.compute_eigenvalues(operator=self.qubit_op, aux_operators=extra_ops) + with self.assertWarns(DeprecationWarning): + result = algo.compute_eigenvalues(operator=self.qubit_op, aux_operators=extra_ops) self.assertEqual(len(result.eigenvalues), 1) self.assertEqual(len(result.eigenstates), 1) self.assertEqual(result.eigenvalues.dtype, np.float64) diff --git a/test/python/algorithms/test_numpy_minimum_eigen_solver.py b/test/python/algorithms/test_numpy_minimum_eigen_solver.py index 160e2796de4e..c4d5a3b43ddd 100644 --- a/test/python/algorithms/test_numpy_minimum_eigen_solver.py +++ b/test/python/algorithms/test_numpy_minimum_eigen_solver.py @@ -45,10 +45,11 @@ def setUp(self): def test_cme(self): """Basic test""" - algo = NumPyMinimumEigensolver() - result = algo.compute_minimum_eigenvalue( - operator=self.qubit_op, aux_operators=self.aux_ops_list - ) + with self.assertWarns(DeprecationWarning): + algo = NumPyMinimumEigensolver() + result = algo.compute_minimum_eigenvalue( + operator=self.qubit_op, aux_operators=self.aux_ops_list + ) self.assertAlmostEqual(result.eigenvalue, -1.85727503 + 0j) self.assertEqual(len(result.aux_operator_eigenvalues), 2) np.testing.assert_array_almost_equal(result.aux_operator_eigenvalues[0], [2, 0]) @@ -57,38 +58,45 @@ def test_cme(self): def test_cme_reuse(self): """Test reuse""" # Start with no operator or aux_operators, give via compute method - algo = NumPyMinimumEigensolver() - result = algo.compute_minimum_eigenvalue(operator=self.qubit_op) + with self.assertWarns(DeprecationWarning): + algo = NumPyMinimumEigensolver() + result = algo.compute_minimum_eigenvalue(operator=self.qubit_op) self.assertEqual(result.eigenvalue.dtype, np.float64) self.assertAlmostEqual(result.eigenvalue, -1.85727503) self.assertIsNone(result.aux_operator_eigenvalues) # Add aux_operators and go again - result = algo.compute_minimum_eigenvalue( - operator=self.qubit_op, aux_operators=self.aux_ops_list - ) + with self.assertWarns(DeprecationWarning): + result = algo.compute_minimum_eigenvalue( + operator=self.qubit_op, aux_operators=self.aux_ops_list + ) self.assertAlmostEqual(result.eigenvalue, -1.85727503 + 0j) self.assertEqual(len(result.aux_operator_eigenvalues), 2) np.testing.assert_array_almost_equal(result.aux_operator_eigenvalues[0], [2, 0]) np.testing.assert_array_almost_equal(result.aux_operator_eigenvalues[1], [0, 0]) # "Remove" aux_operators and go again - result = algo.compute_minimum_eigenvalue(operator=self.qubit_op, aux_operators=[]) + with self.assertWarns(DeprecationWarning): + result = algo.compute_minimum_eigenvalue(operator=self.qubit_op, aux_operators=[]) self.assertEqual(result.eigenvalue.dtype, np.float64) self.assertAlmostEqual(result.eigenvalue, -1.85727503) self.assertIsNone(result.aux_operator_eigenvalues) # Set aux_operators and go again - result = algo.compute_minimum_eigenvalue( - operator=self.qubit_op, aux_operators=self.aux_ops_list - ) + with self.assertWarns(DeprecationWarning): + result = algo.compute_minimum_eigenvalue( + operator=self.qubit_op, aux_operators=self.aux_ops_list + ) self.assertAlmostEqual(result.eigenvalue, -1.85727503 + 0j) self.assertEqual(len(result.aux_operator_eigenvalues), 2) np.testing.assert_array_almost_equal(result.aux_operator_eigenvalues[0], [2, 0]) np.testing.assert_array_almost_equal(result.aux_operator_eigenvalues[1], [0, 0]) # Finally just set one of aux_operators and main operator, remove aux_operators - result = algo.compute_minimum_eigenvalue(operator=self.aux_ops_list[0], aux_operators=[]) + with self.assertWarns(DeprecationWarning): + result = algo.compute_minimum_eigenvalue( + operator=self.aux_ops_list[0], aux_operators=[] + ) self.assertAlmostEqual(result.eigenvalue, 2 + 0j) self.assertIsNone(result.aux_operator_eigenvalues) @@ -100,10 +108,11 @@ def test_cme_filter(self): def criterion(x, v, a_v): return v >= -0.5 - algo = NumPyMinimumEigensolver(filter_criterion=criterion) - result = algo.compute_minimum_eigenvalue( - operator=self.qubit_op, aux_operators=self.aux_ops_list - ) + with self.assertWarns(DeprecationWarning): + algo = NumPyMinimumEigensolver(filter_criterion=criterion) + result = algo.compute_minimum_eigenvalue( + operator=self.qubit_op, aux_operators=self.aux_ops_list + ) self.assertAlmostEqual(result.eigenvalue, -0.22491125 + 0j) self.assertEqual(len(result.aux_operator_eigenvalues), 2) np.testing.assert_array_almost_equal(result.aux_operator_eigenvalues[0], [2, 0]) @@ -117,10 +126,11 @@ def test_cme_filter_empty(self): def criterion(x, v, a_v): return False - algo = NumPyMinimumEigensolver(filter_criterion=criterion) - result = algo.compute_minimum_eigenvalue( - operator=self.qubit_op, aux_operators=self.aux_ops_list - ) + with self.assertWarns(DeprecationWarning): + algo = NumPyMinimumEigensolver(filter_criterion=criterion) + result = algo.compute_minimum_eigenvalue( + operator=self.qubit_op, aux_operators=self.aux_ops_list + ) self.assertEqual(result.eigenvalue, None) self.assertEqual(result.eigenstate, None) self.assertEqual(result.aux_operator_eigenvalues, None) @@ -128,22 +138,25 @@ def criterion(x, v, a_v): @data(X, Y, Z) def test_cme_1q(self, op): """Test for 1 qubit operator""" - algo = NumPyMinimumEigensolver() - result = algo.compute_minimum_eigenvalue(operator=op) + with self.assertWarns(DeprecationWarning): + algo = NumPyMinimumEigensolver() + result = algo.compute_minimum_eigenvalue(operator=op) self.assertAlmostEqual(result.eigenvalue, -1) def test_cme_aux_ops_dict(self): """Test dictionary compatibility of aux_operators""" # Start with an empty dictionary - algo = NumPyMinimumEigensolver() - result = algo.compute_minimum_eigenvalue(operator=self.qubit_op, aux_operators={}) + with self.assertWarns(DeprecationWarning): + algo = NumPyMinimumEigensolver() + result = algo.compute_minimum_eigenvalue(operator=self.qubit_op, aux_operators={}) self.assertAlmostEqual(result.eigenvalue, -1.85727503 + 0j) self.assertIsNone(result.aux_operator_eigenvalues) # Add aux_operators dictionary and go again - result = algo.compute_minimum_eigenvalue( - operator=self.qubit_op, aux_operators=self.aux_ops_dict - ) + with self.assertWarns(DeprecationWarning): + result = algo.compute_minimum_eigenvalue( + operator=self.qubit_op, aux_operators=self.aux_ops_dict + ) self.assertAlmostEqual(result.eigenvalue, -1.85727503 + 0j) self.assertEqual(len(result.aux_operator_eigenvalues), 2) np.testing.assert_array_almost_equal(result.aux_operator_eigenvalues["aux_op1"], [2, 0]) @@ -151,7 +164,10 @@ def test_cme_aux_ops_dict(self): # Add None and zero operators and go again extra_ops = {"None_op": None, "zero_op": 0, **self.aux_ops_dict} - result = algo.compute_minimum_eigenvalue(operator=self.qubit_op, aux_operators=extra_ops) + with self.assertWarns(DeprecationWarning): + result = algo.compute_minimum_eigenvalue( + operator=self.qubit_op, aux_operators=extra_ops + ) self.assertAlmostEqual(result.eigenvalue, -1.85727503 + 0j) self.assertEqual(len(result.aux_operator_eigenvalues), 3) np.testing.assert_array_almost_equal(result.aux_operator_eigenvalues["aux_op1"], [2, 0]) @@ -163,8 +179,9 @@ def test_aux_operators_list(self): aux_op1 = PauliSumOp.from_list([("II", 2.0)]) aux_op2 = PauliSumOp.from_list([("II", 0.5), ("ZZ", 0.5), ("YY", 0.5), ("XX", -0.5)]) aux_ops = [aux_op1, aux_op2] - algo = NumPyMinimumEigensolver() - result = algo.compute_minimum_eigenvalue(operator=self.qubit_op, aux_operators=aux_ops) + with self.assertWarns(DeprecationWarning): + algo = NumPyMinimumEigensolver() + result = algo.compute_minimum_eigenvalue(operator=self.qubit_op, aux_operators=aux_ops) self.assertAlmostEqual(result.eigenvalue, -1.85727503 + 0j) self.assertEqual(len(result.aux_operator_eigenvalues), 2) # expectation values @@ -176,7 +193,10 @@ def test_aux_operators_list(self): # Go again with additional None and zero operators extra_ops = [*aux_ops, None, 0] - result = algo.compute_minimum_eigenvalue(operator=self.qubit_op, aux_operators=extra_ops) + with self.assertWarns(DeprecationWarning): + result = algo.compute_minimum_eigenvalue( + operator=self.qubit_op, aux_operators=extra_ops + ) self.assertAlmostEqual(result.eigenvalue, -1.85727503 + 0j) self.assertEqual(len(result.aux_operator_eigenvalues), 4) # expectation values @@ -194,8 +214,9 @@ def test_aux_operators_dict(self): aux_op1 = PauliSumOp.from_list([("II", 2.0)]) aux_op2 = PauliSumOp.from_list([("II", 0.5), ("ZZ", 0.5), ("YY", 0.5), ("XX", -0.5)]) aux_ops = {"aux_op1": aux_op1, "aux_op2": aux_op2} - algo = NumPyMinimumEigensolver() - result = algo.compute_minimum_eigenvalue(operator=self.qubit_op, aux_operators=aux_ops) + with self.assertWarns(DeprecationWarning): + algo = NumPyMinimumEigensolver() + result = algo.compute_minimum_eigenvalue(operator=self.qubit_op, aux_operators=aux_ops) self.assertAlmostEqual(result.eigenvalue, -1.85727503 + 0j) self.assertEqual(len(result.aux_operator_eigenvalues), 2) # expectation values @@ -207,7 +228,10 @@ def test_aux_operators_dict(self): # Go again with additional None and zero operators extra_ops = {**aux_ops, "None_operator": None, "zero_operator": 0} - result = algo.compute_minimum_eigenvalue(operator=self.qubit_op, aux_operators=extra_ops) + with self.assertWarns(DeprecationWarning): + result = algo.compute_minimum_eigenvalue( + operator=self.qubit_op, aux_operators=extra_ops + ) self.assertAlmostEqual(result.eigenvalue, -1.85727503 + 0j) self.assertEqual(len(result.aux_operator_eigenvalues), 3) # expectation values diff --git a/test/python/algorithms/test_phase_estimator.py b/test/python/algorithms/test_phase_estimator.py index 3153d87d7b79..2af6b902a7fc 100644 --- a/test/python/algorithms/test_phase_estimator.py +++ b/test/python/algorithms/test_phase_estimator.py @@ -61,9 +61,10 @@ def hamiltonian_pe( if backend is None: backend = qiskit.BasicAer.get_backend("statevector_simulator") quantum_instance = qiskit.utils.QuantumInstance(backend=backend, shots=10000) - phase_est = HamiltonianPhaseEstimation( - num_evaluation_qubits=num_evaluation_qubits, quantum_instance=quantum_instance - ) + with self.assertWarns(DeprecationWarning): + phase_est = HamiltonianPhaseEstimation( + num_evaluation_qubits=num_evaluation_qubits, quantum_instance=quantum_instance + ) result = phase_est.estimate( hamiltonian=hamiltonian, state_preparation=state_preparation, @@ -160,7 +161,8 @@ def _setup_from_bound(self, evolution, op_class): hamiltonian = hamiltonian.to_matrix_op() backend = qiskit.BasicAer.get_backend("statevector_simulator") qi = qiskit.utils.QuantumInstance(backend=backend, shots=10000) - phase_est = HamiltonianPhaseEstimation(num_evaluation_qubits=6, quantum_instance=qi) + with self.assertWarns(DeprecationWarning): + phase_est = HamiltonianPhaseEstimation(num_evaluation_qubits=6, quantum_instance=qi) result = phase_est.estimate( hamiltonian=hamiltonian, bound=bound, @@ -328,12 +330,14 @@ def one_phase( qi = qiskit.utils.QuantumInstance(backend=backend, shots=10000) if phase_estimator is None: phase_estimator = IterativePhaseEstimation - if phase_estimator == IterativePhaseEstimation: - p_est = IterativePhaseEstimation(num_iterations=num_iterations, quantum_instance=qi) - elif phase_estimator == PhaseEstimation: - p_est = PhaseEstimation(num_evaluation_qubits=6, quantum_instance=qi) - else: - raise ValueError("Unrecognized phase_estimator") + + with self.assertWarns(DeprecationWarning): + if phase_estimator == IterativePhaseEstimation: + p_est = IterativePhaseEstimation(num_iterations=num_iterations, quantum_instance=qi) + elif phase_estimator == PhaseEstimation: + p_est = PhaseEstimation(num_evaluation_qubits=6, quantum_instance=qi) + else: + raise ValueError("Unrecognized phase_estimator") result = p_est.estimate(unitary=unitary_circuit, state_preparation=state_preparation) phase = result.phase return phase @@ -407,9 +411,10 @@ def phase_estimation( if backend is None: backend = qiskit.BasicAer.get_backend("statevector_simulator") qi = qiskit.utils.QuantumInstance(backend=backend, shots=10000) - phase_est = PhaseEstimation( - num_evaluation_qubits=num_evaluation_qubits, quantum_instance=qi - ) + with self.assertWarns(DeprecationWarning): + phase_est = PhaseEstimation( + num_evaluation_qubits=num_evaluation_qubits, quantum_instance=qi + ) if construct_circuit: pe_circuit = phase_est.construct_circuit(unitary_circuit, state_preparation) result = phase_est.estimate_from_pe_circuit(pe_circuit, unitary_circuit.num_qubits) diff --git a/test/python/algorithms/test_qaoa.py b/test/python/algorithms/test_qaoa.py index 87e5a6050038..15dcc61ad753 100644 --- a/test/python/algorithms/test_qaoa.py +++ b/test/python/algorithms/test_qaoa.py @@ -92,9 +92,10 @@ def test_qaoa(self, w, prob, m, solutions, convert_to_matrix_op): if convert_to_matrix_op: qubit_op = qubit_op.to_matrix_op() - qaoa = QAOA(COBYLA(), prob, mixer=m, quantum_instance=self.statevector_simulator) + with self.assertWarns(DeprecationWarning): + qaoa = QAOA(COBYLA(), prob, mixer=m, quantum_instance=self.statevector_simulator) - result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) + result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) x = self._sample_most_likely(result.eigenstate) graph_solution = self._get_graph_solution(x) self.assertIn(graph_solution, solutions) @@ -126,9 +127,10 @@ def test_qaoa_qc_mixer(self, w, prob, solutions, convert_to_matrix_op): theta = Parameter("θ") mixer.rx(theta, range(num_qubits)) - qaoa = QAOA(optimizer, prob, mixer=mixer, quantum_instance=self.statevector_simulator) + with self.assertWarns(DeprecationWarning): + qaoa = QAOA(optimizer, prob, mixer=mixer, quantum_instance=self.statevector_simulator) - result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) + result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) x = self._sample_most_likely(result.eigenstate) graph_solution = self._get_graph_solution(x) self.assertIn(graph_solution, solutions) @@ -144,8 +146,9 @@ def test_qaoa_qc_mixer_many_parameters(self): theta = Parameter("θ" + str(i)) mixer.rx(theta, range(num_qubits)) - qaoa = QAOA(optimizer, reps=2, mixer=mixer, quantum_instance=self.statevector_simulator) - result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) + with self.assertWarns(DeprecationWarning): + qaoa = QAOA(optimizer, reps=2, mixer=mixer, quantum_instance=self.statevector_simulator) + result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) x = self._sample_most_likely(result.eigenstate) self.log.debug(x) graph_solution = self._get_graph_solution(x) @@ -160,8 +163,9 @@ def test_qaoa_qc_mixer_no_parameters(self): # just arbitrary circuit mixer.rx(np.pi / 2, range(num_qubits)) - qaoa = QAOA(COBYLA(), reps=1, mixer=mixer, quantum_instance=self.statevector_simulator) - result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) + with self.assertWarns(DeprecationWarning): + qaoa = QAOA(COBYLA(), reps=1, mixer=mixer, quantum_instance=self.statevector_simulator) + result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) # we just assert that we get a result, it is not meaningful. self.assertIsNotNone(result.eigenstate) @@ -170,8 +174,9 @@ def test_change_operator_size(self): qubit_op, _ = self._get_operator( np.array([[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]) ) - qaoa = QAOA(COBYLA(), 1, quantum_instance=self.statevector_simulator) - result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) + with self.assertWarns(DeprecationWarning): + qaoa = QAOA(COBYLA(), 1, quantum_instance=self.statevector_simulator) + result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) x = self._sample_most_likely(result.eigenstate) graph_solution = self._get_graph_solution(x) with self.subTest(msg="QAOA 4x4"): @@ -190,7 +195,8 @@ def test_change_operator_size(self): ) ) - result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) + with self.assertWarns(DeprecationWarning): + result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) x = self._sample_most_likely(result.eigenstate) graph_solution = self._get_graph_solution(x) with self.subTest(msg="QAOA 6x6"): @@ -209,14 +215,15 @@ def cb_callback(eval_count, parameters, mean, std): if eval_count == 1: first_pt = list(parameters) - qaoa = QAOA( - COBYLA(), - initial_point=init_pt, - callback=cb_callback, - quantum_instance=self.statevector_simulator, - ) + with self.assertWarns(DeprecationWarning): + qaoa = QAOA( + COBYLA(), + initial_point=init_pt, + callback=cb_callback, + quantum_instance=self.statevector_simulator, + ) - result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) + result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) x = self._sample_most_likely(result.eigenstate) graph_solution = self._get_graph_solution(x) @@ -246,18 +253,19 @@ def test_qaoa_initial_state(self, w, init_state): initial_state.initialize(init_state, initial_state.qubits) zero_init_state = QuantumCircuit(QuantumRegister(qubit_op.num_qubits, "q")) - qaoa_zero_init_state = QAOA( - optimizer=optimizer, - initial_state=zero_init_state, - initial_point=init_pt, - quantum_instance=self.statevector_simulator, - ) - qaoa = QAOA( - optimizer=optimizer, - initial_state=initial_state, - initial_point=init_pt, - quantum_instance=self.statevector_simulator, - ) + with self.assertWarns(DeprecationWarning): + qaoa_zero_init_state = QAOA( + optimizer=optimizer, + initial_state=zero_init_state, + initial_point=init_pt, + quantum_instance=self.statevector_simulator, + ) + qaoa = QAOA( + optimizer=optimizer, + initial_state=initial_state, + initial_point=init_pt, + quantum_instance=self.statevector_simulator, + ) zero_circuits = qaoa_zero_init_state.construct_circuit(init_pt, qubit_op) custom_circuits = qaoa.construct_circuit(init_pt, qubit_op) @@ -295,14 +303,18 @@ def test_qaoa_random_initial_point(self): rx.undirected_gnp_random_graph(5, 0.5, seed=algorithm_globals.random_seed) ) qubit_op, _ = self._get_operator(w) - qaoa = QAOA(optimizer=NELDER_MEAD(disp=True), reps=1, quantum_instance=self.qasm_simulator) - result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) + with self.assertWarns(DeprecationWarning): + qaoa = QAOA( + optimizer=NELDER_MEAD(disp=True), reps=1, quantum_instance=self.qasm_simulator + ) + result = qaoa.compute_minimum_eigenvalue(operator=qubit_op) self.assertLess(result.eigenvalue, -0.97) def test_qaoa_construct_circuit_update(self): """Test updating operators with QAOA construct_circuit""" - qaoa = QAOA() + with self.assertWarns(DeprecationWarning): + qaoa = QAOA() ref = qaoa.construct_circuit([0, 0], I ^ Z)[0] circ2 = qaoa.construct_circuit([0, 0], I ^ Z)[0] self.assertEqual(circ2, ref) @@ -313,11 +325,12 @@ def test_qaoa_construct_circuit_update(self): def test_optimizer_scipy_callable(self): """Test passing a SciPy optimizer directly as callable.""" - qaoa = QAOA( - optimizer=partial(scipy_minimize, method="Nelder-Mead", options={"maxiter": 2}), - quantum_instance=self.statevector_simulator, - ) - result = qaoa.compute_minimum_eigenvalue(Z) + with self.assertWarns(DeprecationWarning): + qaoa = QAOA( + optimizer=partial(scipy_minimize, method="Nelder-Mead", options={"maxiter": 2}), + quantum_instance=self.statevector_simulator, + ) + result = qaoa.compute_minimum_eigenvalue(Z) self.assertEqual(result.cost_function_evals, 4) def _get_operator(self, weight_matrix): diff --git a/test/python/algorithms/test_vqd.py b/test/python/algorithms/test_vqd.py index 2fb2a573bc98..8079a063ddf6 100644 --- a/test/python/algorithms/test_vqd.py +++ b/test/python/algorithms/test_vqd.py @@ -90,20 +90,21 @@ def setUp(self): def test_basic_aer_statevector(self): """Test the VQD on BasicAer's statevector simulator.""" wavefunction = self.ryrz_wavefunction - vqd = VQD( - k=2, - ansatz=wavefunction, - optimizer=COBYLA(), - quantum_instance=QuantumInstance( - BasicAer.get_backend("statevector_simulator"), - basis_gates=["u1", "u2", "u3", "cx", "id"], - coupling_map=[[0, 1]], - seed_simulator=algorithm_globals.random_seed, - seed_transpiler=algorithm_globals.random_seed, - ), - ) + with self.assertWarns(DeprecationWarning): + vqd = VQD( + k=2, + ansatz=wavefunction, + optimizer=COBYLA(), + quantum_instance=QuantumInstance( + BasicAer.get_backend("statevector_simulator"), + basis_gates=["u1", "u2", "u3", "cx", "id"], + coupling_map=[[0, 1]], + seed_simulator=algorithm_globals.random_seed, + seed_transpiler=algorithm_globals.random_seed, + ), + ) - result = vqd.compute_eigenvalues(operator=self.h2_op) + result = vqd.compute_eigenvalues(operator=self.h2_op) with self.subTest(msg="test eigenvalue"): np.testing.assert_array_almost_equal( @@ -123,14 +124,15 @@ def test_mismatching_num_qubits(self): """Ensuring circuit and operator mismatch is caught""" wavefunction = QuantumCircuit(1) optimizer = SLSQP(maxiter=50) - vqd = VQD( - k=1, - ansatz=wavefunction, - optimizer=optimizer, - quantum_instance=self.statevector_simulator, - ) - with self.assertRaises(AlgorithmError): - _ = vqd.compute_eigenvalues(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + vqd = VQD( + k=1, + ansatz=wavefunction, + optimizer=optimizer, + quantum_instance=self.statevector_simulator, + ) + with self.assertRaises(AlgorithmError): + _ = vqd.compute_eigenvalues(operator=self.h2_op) @data( (MatrixExpectation(), 1), @@ -142,7 +144,8 @@ def test_construct_circuit(self, expectation, num_circuits): """Test construct circuits returns QuantumCircuits and the right number of them.""" try: wavefunction = EfficientSU2(2, reps=1) - vqd = VQD(k=2, ansatz=wavefunction, expectation=expectation) + with self.assertWarns(DeprecationWarning): + vqd = VQD(k=2, ansatz=wavefunction, expectation=expectation) params = [0] * wavefunction.num_parameters circuits = vqd.construct_circuit(parameter=params, operator=self.h2_op) @@ -156,26 +159,28 @@ def test_construct_circuit(self, expectation, num_circuits): def test_missing_varform_params(self): """Test specifying a variational form with no parameters raises an error.""" circuit = QuantumCircuit(self.h2_op.num_qubits) - vqd = VQD( - k=1, ansatz=circuit, quantum_instance=BasicAer.get_backend("statevector_simulator") - ) - with self.assertRaises(RuntimeError): - vqd.compute_eigenvalues(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + vqd = VQD( + k=1, ansatz=circuit, quantum_instance=BasicAer.get_backend("statevector_simulator") + ) + with self.assertRaises(RuntimeError): + vqd.compute_eigenvalues(operator=self.h2_op) def test_basic_aer_qasm(self): """Test the VQD on BasicAer's QASM simulator.""" optimizer = COBYLA(maxiter=1000) wavefunction = self.ry_wavefunction - vqd = VQD( - ansatz=wavefunction, - optimizer=optimizer, - max_evals_grouped=1, - quantum_instance=self.qasm_simulator, - ) + with self.assertWarns(DeprecationWarning): + vqd = VQD( + ansatz=wavefunction, + optimizer=optimizer, + max_evals_grouped=1, + quantum_instance=self.qasm_simulator, + ) - # TODO benchmark this later. - result = vqd.compute_eigenvalues(operator=self.h2_op) + # TODO benchmark this later. + result = vqd.compute_eigenvalues(operator=self.h2_op) np.testing.assert_array_almost_equal( result.eigenvalues.real, self.h2_energy_excited, decimal=1 ) @@ -192,15 +197,16 @@ def test_with_aer_statevector(self): seed_simulator=algorithm_globals.random_seed, seed_transpiler=algorithm_globals.random_seed, ) - vqd = VQD( - k=2, - ansatz=wavefunction, - optimizer=optimizer, - max_evals_grouped=1, - quantum_instance=quantum_instance, - ) + with self.assertWarns(DeprecationWarning): + vqd = VQD( + k=2, + ansatz=wavefunction, + optimizer=optimizer, + max_evals_grouped=1, + quantum_instance=quantum_instance, + ) + result = vqd.compute_eigenvalues(operator=self.h2_op) - result = vqd.compute_eigenvalues(operator=self.h2_op) np.testing.assert_array_almost_equal( result.eigenvalues.real, self.h2_energy_excited, decimal=2 ) @@ -218,15 +224,15 @@ def test_with_aer_qasm(self): seed_transpiler=algorithm_globals.random_seed, ) - vqd = VQD( - k=2, - ansatz=wavefunction, - optimizer=optimizer, - expectation=PauliExpectation(), - quantum_instance=quantum_instance, - ) - - result = vqd.compute_eigenvalues(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + vqd = VQD( + k=2, + ansatz=wavefunction, + optimizer=optimizer, + expectation=PauliExpectation(), + quantum_instance=quantum_instance, + ) + result = vqd.compute_eigenvalues(operator=self.h2_op) np.testing.assert_array_almost_equal( result.eigenvalues.real, self.h2_energy_excited, decimal=1 @@ -246,15 +252,16 @@ def test_with_aer_qasm_snapshot_mode(self): seed_simulator=algorithm_globals.random_seed, seed_transpiler=algorithm_globals.random_seed, ) - vqd = VQD( - k=2, - ansatz=wavefunction, - optimizer=optimizer, - expectation=AerPauliExpectation(), - quantum_instance=quantum_instance, - ) + with self.assertWarns(DeprecationWarning): + vqd = VQD( + k=2, + ansatz=wavefunction, + optimizer=optimizer, + expectation=AerPauliExpectation(), + quantum_instance=quantum_instance, + ) - result = vqd.compute_eigenvalues(operator=self.test_op) + result = vqd.compute_eigenvalues(operator=self.test_op) np.testing.assert_array_almost_equal(result.eigenvalues.real, self.test_results, decimal=1) def test_callback(self): @@ -271,13 +278,14 @@ def store_intermediate_result(eval_count, parameters, mean, std, step): optimizer = COBYLA(maxiter=3) wavefunction = self.ry_wavefunction - vqd = VQD( - ansatz=wavefunction, - optimizer=optimizer, - callback=store_intermediate_result, - quantum_instance=self.qasm_simulator, - ) - vqd.compute_eigenvalues(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + vqd = VQD( + ansatz=wavefunction, + optimizer=optimizer, + callback=store_intermediate_result, + quantum_instance=self.qasm_simulator, + ) + vqd.compute_eigenvalues(operator=self.h2_op) self.assertTrue(all(isinstance(count, int) for count in history["eval_count"])) self.assertTrue(all(isinstance(mean, float) for mean in history["mean"])) @@ -298,39 +306,44 @@ def store_intermediate_result(eval_count, parameters, mean, std, step): def test_reuse(self): """Test re-using a VQD algorithm instance.""" - vqd = VQD(k=1) + with self.assertWarns(DeprecationWarning): + vqd = VQD(k=1) with self.subTest(msg="assert running empty raises AlgorithmError"): - with self.assertRaises(AlgorithmError): + with self.assertWarns(DeprecationWarning), self.assertRaises(AlgorithmError): _ = vqd.compute_eigenvalues(operator=self.h2_op) ansatz = TwoLocal(rotation_blocks=["ry", "rz"], entanglement_blocks="cz") vqd.ansatz = ansatz with self.subTest(msg="assert missing operator raises AlgorithmError"): - with self.assertRaises(AlgorithmError): + with self.assertWarns(DeprecationWarning), self.assertRaises(AlgorithmError): _ = vqd.compute_eigenvalues(operator=self.h2_op) vqd.expectation = MatrixExpectation() vqd.quantum_instance = self.statevector_simulator with self.subTest(msg="assert VQE works once all info is available"): - result = vqd.compute_eigenvalues(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + result = vqd.compute_eigenvalues(operator=self.h2_op) np.testing.assert_array_almost_equal(result.eigenvalues.real, self.h2_energy, decimal=2) operator = PrimitiveOp(np.array([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, 2, 0], [0, 0, 0, 3]])) with self.subTest(msg="assert minimum eigensolver interface works"): - result = vqd.compute_eigenvalues(operator=operator) + with self.assertWarns(DeprecationWarning): + result = vqd.compute_eigenvalues(operator=operator) self.assertAlmostEqual(result.eigenvalues.real[0], -1.0, places=5) def test_vqd_optimizer(self): """Test running same VQD twice to re-use optimizer, then switch optimizer""" - vqd = VQD( - k=2, - optimizer=SLSQP(), - quantum_instance=QuantumInstance(BasicAer.get_backend("statevector_simulator")), - ) + with self.assertWarns(DeprecationWarning): + vqd = VQD( + k=2, + optimizer=SLSQP(), + quantum_instance=QuantumInstance(BasicAer.get_backend("statevector_simulator")), + ) def run_check(): - result = vqd.compute_eigenvalues(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + result = vqd.compute_eigenvalues(operator=self.h2_op) np.testing.assert_array_almost_equal( result.eigenvalues.real, self.h2_energy_excited, decimal=3 ) @@ -347,14 +360,16 @@ def run_check(): @data(MatrixExpectation(), None) def test_backend_change(self, user_expectation): """Test that VQE works when backend changes.""" - vqd = VQD( - k=1, - ansatz=TwoLocal(rotation_blocks=["ry", "rz"], entanglement_blocks="cz"), - optimizer=SLSQP(maxiter=2), - expectation=user_expectation, - quantum_instance=BasicAer.get_backend("statevector_simulator"), - ) - result0 = vqd.compute_eigenvalues(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + vqd = VQD( + k=1, + ansatz=TwoLocal(rotation_blocks=["ry", "rz"], entanglement_blocks="cz"), + optimizer=SLSQP(maxiter=2), + expectation=user_expectation, + quantum_instance=BasicAer.get_backend("statevector_simulator"), + ) + with self.assertWarns(DeprecationWarning): + result0 = vqd.compute_eigenvalues(operator=self.h2_op) if user_expectation is not None: with self.subTest("User expectation kept."): self.assertEqual(vqd.expectation, user_expectation) @@ -362,7 +377,8 @@ def test_backend_change(self, user_expectation): vqd.quantum_instance = BasicAer.get_backend("qasm_simulator") # works also if no expectation is set, since it will be determined automatically - result1 = vqd.compute_eigenvalues(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + result1 = vqd.compute_eigenvalues(operator=self.h2_op) if user_expectation is not None: with self.subTest("Change backend with user expectation, it is kept."): @@ -373,33 +389,37 @@ def test_backend_change(self, user_expectation): def test_set_ansatz_to_none(self): """Tests that setting the ansatz to None results in the default behavior""" - vqd = VQD( - k=1, - ansatz=self.ryrz_wavefunction, - optimizer=L_BFGS_B(), - quantum_instance=self.statevector_simulator, - ) + with self.assertWarns(DeprecationWarning): + vqd = VQD( + k=1, + ansatz=self.ryrz_wavefunction, + optimizer=L_BFGS_B(), + quantum_instance=self.statevector_simulator, + ) vqd.ansatz = None self.assertIsInstance(vqd.ansatz, RealAmplitudes) def test_set_optimizer_to_none(self): """Tests that setting the optimizer to None results in the default behavior""" - vqd = VQD( - k=1, - ansatz=self.ryrz_wavefunction, - optimizer=L_BFGS_B(), - quantum_instance=self.statevector_simulator, - ) + with self.assertWarns(DeprecationWarning): + vqd = VQD( + k=1, + ansatz=self.ryrz_wavefunction, + optimizer=L_BFGS_B(), + quantum_instance=self.statevector_simulator, + ) vqd.optimizer = None self.assertIsInstance(vqd.optimizer, SLSQP) def test_aux_operators_list(self): """Test list-based aux_operators.""" wavefunction = self.ry_wavefunction - vqd = VQD(k=2, ansatz=wavefunction, quantum_instance=self.statevector_simulator) + with self.assertWarns(DeprecationWarning): + vqd = VQD(k=2, ansatz=wavefunction, quantum_instance=self.statevector_simulator) # Start with an empty list - result = vqd.compute_eigenvalues(self.h2_op, aux_operators=[]) + with self.assertWarns(DeprecationWarning): + result = vqd.compute_eigenvalues(self.h2_op, aux_operators=[]) np.testing.assert_array_almost_equal( result.eigenvalues.real, self.h2_energy_excited, decimal=2 ) @@ -409,7 +429,8 @@ def test_aux_operators_list(self): aux_op1 = PauliSumOp.from_list([("II", 2.0)]) aux_op2 = PauliSumOp.from_list([("II", 0.5), ("ZZ", 0.5), ("YY", 0.5), ("XX", -0.5)]) aux_ops = [aux_op1, aux_op2] - result = vqd.compute_eigenvalues(self.h2_op, aux_operators=aux_ops) + with self.assertWarns(DeprecationWarning): + result = vqd.compute_eigenvalues(self.h2_op, aux_operators=aux_ops) np.testing.assert_array_almost_equal( result.eigenvalues.real, self.h2_energy_excited, decimal=2 ) @@ -423,7 +444,8 @@ def test_aux_operators_list(self): # Go again with additional None and zero operators extra_ops = [*aux_ops, None, 0] - result = vqd.compute_eigenvalues(self.h2_op, aux_operators=extra_ops) + with self.assertWarns(DeprecationWarning): + result = vqd.compute_eigenvalues(self.h2_op, aux_operators=extra_ops) np.testing.assert_array_almost_equal( result.eigenvalues.real, self.h2_energy_excited, decimal=2 ) @@ -441,10 +463,12 @@ def test_aux_operators_list(self): def test_aux_operators_dict(self): """Test dictionary compatibility of aux_operators""" wavefunction = self.ry_wavefunction - vqd = VQD(ansatz=wavefunction, quantum_instance=self.statevector_simulator) + with self.assertWarns(DeprecationWarning): + vqd = VQD(ansatz=wavefunction, quantum_instance=self.statevector_simulator) # Start with an empty dictionary - result = vqd.compute_eigenvalues(self.h2_op, aux_operators={}) + with self.assertWarns(DeprecationWarning): + result = vqd.compute_eigenvalues(self.h2_op, aux_operators={}) np.testing.assert_array_almost_equal( result.eigenvalues.real, self.h2_energy_excited, decimal=2 ) @@ -454,7 +478,8 @@ def test_aux_operators_dict(self): aux_op1 = PauliSumOp.from_list([("II", 2.0)]) aux_op2 = PauliSumOp.from_list([("II", 0.5), ("ZZ", 0.5), ("YY", 0.5), ("XX", -0.5)]) aux_ops = {"aux_op1": aux_op1, "aux_op2": aux_op2} - result = vqd.compute_eigenvalues(self.h2_op, aux_operators=aux_ops) + with self.assertWarns(DeprecationWarning): + result = vqd.compute_eigenvalues(self.h2_op, aux_operators=aux_ops) self.assertEqual(len(result.eigenvalues), 2) self.assertEqual(len(result.eigenstates), 2) self.assertEqual(result.eigenvalues.dtype, np.complex128) @@ -470,7 +495,8 @@ def test_aux_operators_dict(self): # Go again with additional None and zero operators extra_ops = {**aux_ops, "None_operator": None, "zero_operator": 0} - result = vqd.compute_eigenvalues(self.h2_op, aux_operators=extra_ops) + with self.assertWarns(DeprecationWarning): + result = vqd.compute_eigenvalues(self.h2_op, aux_operators=extra_ops) self.assertEqual(len(result.eigenvalues), 2) self.assertEqual(len(result.eigenstates), 2) self.assertEqual(result.eigenvalues.dtype, np.complex128) @@ -490,28 +516,30 @@ def test_aux_operators_dict(self): def test_aux_operator_std_dev_pauli(self): """Test non-zero standard deviations of aux operators with PauliExpectation.""" wavefunction = self.ry_wavefunction - vqd = VQD( - ansatz=wavefunction, - expectation=PauliExpectation(), - initial_point=[ - 1.70256666, - -5.34843975, - -0.39542903, - 5.99477786, - -2.74374986, - -4.85284669, - 0.2442925, - -1.51638917, - ], - optimizer=COBYLA(maxiter=0), - quantum_instance=self.qasm_simulator, - ) + with self.assertWarns(DeprecationWarning): + vqd = VQD( + ansatz=wavefunction, + expectation=PauliExpectation(), + initial_point=[ + 1.70256666, + -5.34843975, + -0.39542903, + 5.99477786, + -2.74374986, + -4.85284669, + 0.2442925, + -1.51638917, + ], + optimizer=COBYLA(maxiter=0), + quantum_instance=self.qasm_simulator, + ) # Go again with two auxiliary operators aux_op1 = PauliSumOp.from_list([("II", 2.0)]) aux_op2 = PauliSumOp.from_list([("II", 0.5), ("ZZ", 0.5), ("YY", 0.5), ("XX", -0.5)]) aux_ops = [aux_op1, aux_op2] - result = vqd.compute_eigenvalues(self.h2_op, aux_operators=aux_ops) + with self.assertWarns(DeprecationWarning): + result = vqd.compute_eigenvalues(self.h2_op, aux_operators=aux_ops) self.assertEqual(len(result.aux_operator_eigenvalues), 2) # expectation values self.assertAlmostEqual(result.aux_operator_eigenvalues[0][0][0], 2.0, places=1) @@ -526,7 +554,8 @@ def test_aux_operator_std_dev_pauli(self): # Go again with additional None and zero operators aux_ops = [*aux_ops, None, 0] - result = vqd.compute_eigenvalues(self.h2_op, aux_operators=aux_ops) + with self.assertWarns(DeprecationWarning): + result = vqd.compute_eigenvalues(self.h2_op, aux_operators=aux_ops) self.assertEqual(len(result.aux_operator_eigenvalues[0]), 4) # expectation values self.assertAlmostEqual(result.aux_operator_eigenvalues[0][0][0], 2.0, places=1) @@ -547,23 +576,25 @@ def test_aux_operator_std_dev_pauli(self): def test_aux_operator_std_dev_aer_pauli(self): """Test non-zero standard deviations of aux operators with AerPauliExpectation.""" wavefunction = self.ry_wavefunction - vqd = VQD( - ansatz=wavefunction, - expectation=AerPauliExpectation(), - optimizer=COBYLA(maxiter=0), - quantum_instance=QuantumInstance( - backend=Aer.get_backend("qasm_simulator"), - shots=1, - seed_simulator=algorithm_globals.random_seed, - seed_transpiler=algorithm_globals.random_seed, - ), - ) + with self.assertWarns(DeprecationWarning): + vqd = VQD( + ansatz=wavefunction, + expectation=AerPauliExpectation(), + optimizer=COBYLA(maxiter=0), + quantum_instance=QuantumInstance( + backend=Aer.get_backend("qasm_simulator"), + shots=1, + seed_simulator=algorithm_globals.random_seed, + seed_transpiler=algorithm_globals.random_seed, + ), + ) # Go again with two auxiliary operators aux_op1 = PauliSumOp.from_list([("II", 2.0)]) aux_op2 = PauliSumOp.from_list([("II", 0.5), ("ZZ", 0.5), ("YY", 0.5), ("XX", -0.5)]) aux_ops = [aux_op1, aux_op2] - result = vqd.compute_eigenvalues(self.h2_op, aux_operators=aux_ops) + with self.assertWarns(DeprecationWarning): + result = vqd.compute_eigenvalues(self.h2_op, aux_operators=aux_ops) self.assertEqual(len(result.aux_operator_eigenvalues), 2) # expectation values self.assertAlmostEqual(result.aux_operator_eigenvalues[0][0][0], 2.0, places=1) @@ -576,7 +607,8 @@ def test_aux_operator_std_dev_aer_pauli(self): # Go again with additional None and zero operators aux_ops = [*aux_ops, None, 0] - result = vqd.compute_eigenvalues(self.h2_op, aux_operators=aux_ops) + with self.assertWarns(DeprecationWarning): + result = vqd.compute_eigenvalues(self.h2_op, aux_operators=aux_ops) self.assertEqual(len(result.aux_operator_eigenvalues[-1]), 4) # expectation values self.assertAlmostEqual(result.aux_operator_eigenvalues[0][0][0], 2.0, places=6) diff --git a/test/python/algorithms/test_vqe.py b/test/python/algorithms/test_vqe.py index 3e2d4f248955..c0711e408b7c 100644 --- a/test/python/algorithms/test_vqe.py +++ b/test/python/algorithms/test_vqe.py @@ -117,19 +117,19 @@ def setUp(self): def test_basic_aer_statevector(self): """Test the VQE on BasicAer's statevector simulator.""" wavefunction = self.ryrz_wavefunction - vqe = VQE( - ansatz=wavefunction, - optimizer=L_BFGS_B(), - quantum_instance=QuantumInstance( - BasicAer.get_backend("statevector_simulator"), - basis_gates=["u1", "u2", "u3", "cx", "id"], - coupling_map=[[0, 1]], - seed_simulator=algorithm_globals.random_seed, - seed_transpiler=algorithm_globals.random_seed, - ), - ) - - result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=wavefunction, + optimizer=L_BFGS_B(), + quantum_instance=QuantumInstance( + BasicAer.get_backend("statevector_simulator"), + basis_gates=["u1", "u2", "u3", "cx", "id"], + coupling_map=[[0, 1]], + seed_simulator=algorithm_globals.random_seed, + seed_transpiler=algorithm_globals.random_seed, + ), + ) + result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) with self.subTest(msg="test eigenvalue"): self.assertAlmostEqual(result.eigenvalue.real, self.h2_energy) @@ -147,10 +147,13 @@ def test_circuit_input(self): """Test running the VQE on a plain QuantumCircuit object.""" wavefunction = QuantumCircuit(2).compose(EfficientSU2(2)) optimizer = SLSQP(maxiter=50) - vqe = VQE( - ansatz=wavefunction, optimizer=optimizer, quantum_instance=self.statevector_simulator - ) - result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=wavefunction, + optimizer=optimizer, + quantum_instance=self.statevector_simulator, + ) + result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) self.assertAlmostEqual(result.eigenvalue.real, self.h2_energy, places=5) @data( @@ -163,7 +166,8 @@ def test_construct_circuit(self, expectation, num_circuits): """Test construct circuits returns QuantumCircuits and the right number of them.""" try: wavefunction = EfficientSU2(2, reps=1) - vqe = VQE(ansatz=wavefunction, expectation=expectation) + with self.assertWarns(DeprecationWarning): + vqe = VQE(ansatz=wavefunction, expectation=expectation) params = [0] * wavefunction.num_parameters circuits = vqe.construct_circuit(parameter=params, operator=self.h2_op) @@ -177,9 +181,12 @@ def test_construct_circuit(self, expectation, num_circuits): def test_missing_varform_params(self): """Test specifying a variational form with no parameters raises an error.""" circuit = QuantumCircuit(self.h2_op.num_qubits) - vqe = VQE(ansatz=circuit, quantum_instance=BasicAer.get_backend("statevector_simulator")) - with self.assertRaises(RuntimeError): - vqe.compute_minimum_eigenvalue(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=circuit, quantum_instance=BasicAer.get_backend("statevector_simulator") + ) + with self.assertRaises(RuntimeError): + vqe.compute_minimum_eigenvalue(operator=self.h2_op) @data( (SLSQP(maxiter=50), 5, 4), @@ -188,13 +195,14 @@ def test_missing_varform_params(self): @unpack def test_max_evals_grouped(self, optimizer, places, max_evals_grouped): """VQE Optimizers test""" - vqe = VQE( - ansatz=self.ryrz_wavefunction, - optimizer=optimizer, - max_evals_grouped=max_evals_grouped, - quantum_instance=self.statevector_simulator, - ) - result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=self.ryrz_wavefunction, + optimizer=optimizer, + max_evals_grouped=max_evals_grouped, + quantum_instance=self.statevector_simulator, + ) + result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) self.assertAlmostEqual(result.eigenvalue.real, self.h2_energy, places=places) def test_basic_aer_qasm(self): @@ -202,22 +210,24 @@ def test_basic_aer_qasm(self): optimizer = SPSA(maxiter=300, last_avg=5) wavefunction = self.ry_wavefunction - vqe = VQE( - ansatz=wavefunction, - optimizer=optimizer, - max_evals_grouped=1, - quantum_instance=self.qasm_simulator, - ) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=wavefunction, + optimizer=optimizer, + max_evals_grouped=1, + quantum_instance=self.qasm_simulator, + ) - # TODO benchmark this later. - result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) + # TODO benchmark this later. + result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) self.assertAlmostEqual(result.eigenvalue.real, -1.86823, places=2) def test_qasm_eigenvector_normalized(self): """Test VQE with qasm_simulator returns normalized eigenvector.""" wavefunction = self.ry_wavefunction - vqe = VQE(ansatz=wavefunction, quantum_instance=self.qasm_simulator) - result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + vqe = VQE(ansatz=wavefunction, quantum_instance=self.qasm_simulator) + result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) amplitudes = list(result.eigenstate.values()) self.assertAlmostEqual(np.linalg.norm(amplitudes), 1.0, places=4) @@ -234,14 +244,15 @@ def test_with_aer_statevector(self): seed_simulator=algorithm_globals.random_seed, seed_transpiler=algorithm_globals.random_seed, ) - vqe = VQE( - ansatz=wavefunction, - optimizer=optimizer, - max_evals_grouped=1, - quantum_instance=quantum_instance, - ) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=wavefunction, + optimizer=optimizer, + max_evals_grouped=1, + quantum_instance=quantum_instance, + ) - result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) + result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) self.assertAlmostEqual(result.eigenvalue.real, self.h2_energy, places=6) @unittest.skipUnless(has_aer(), "qiskit-aer doesn't appear to be installed.") @@ -257,14 +268,15 @@ def test_with_aer_qasm(self): seed_transpiler=algorithm_globals.random_seed, ) - vqe = VQE( - ansatz=wavefunction, - optimizer=optimizer, - expectation=PauliExpectation(), - quantum_instance=quantum_instance, - ) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=wavefunction, + optimizer=optimizer, + expectation=PauliExpectation(), + quantum_instance=quantum_instance, + ) - result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) + result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) self.assertAlmostEqual(result.eigenvalue.real, -1.86305, places=2) @@ -282,14 +294,15 @@ def test_with_aer_qasm_snapshot_mode(self): seed_simulator=algorithm_globals.random_seed, seed_transpiler=algorithm_globals.random_seed, ) - vqe = VQE( - ansatz=wavefunction, - optimizer=optimizer, - expectation=AerPauliExpectation(), - quantum_instance=quantum_instance, - ) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=wavefunction, + optimizer=optimizer, + expectation=AerPauliExpectation(), + quantum_instance=quantum_instance, + ) - result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) + result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) self.assertAlmostEqual(result.eigenvalue.real, self.h2_energy, places=6) @unittest.skipUnless(has_aer(), "qiskit-aer doesn't appear to be installed.") @@ -308,15 +321,16 @@ def test_with_gradient(self, optimizer): seed_simulator=algorithm_globals.random_seed, seed_transpiler=algorithm_globals.random_seed, ) - vqe = VQE( - ansatz=self.ry_wavefunction, - optimizer=optimizer, - gradient=Gradient(), - expectation=AerPauliExpectation(), - quantum_instance=quantum_instance, - max_evals_grouped=1000, - ) - vqe.compute_minimum_eigenvalue(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=self.ry_wavefunction, + optimizer=optimizer, + gradient=Gradient(), + expectation=AerPauliExpectation(), + quantum_instance=quantum_instance, + max_evals_grouped=1000, + ) + vqe.compute_minimum_eigenvalue(operator=self.h2_op) def test_with_two_qubit_reduction(self): """Test the VQE using TwoQubitReduction.""" @@ -341,7 +355,7 @@ def test_with_two_qubit_reduction(self): ) tapered_qubit_op = TwoQubitReduction(num_particles=2).convert(qubit_op) for simulator in [self.qasm_simulator, self.statevector_simulator]: - with self.subTest(f"Test for {simulator}."): + with self.subTest(f"Test for {simulator}."), self.assertWarns(DeprecationWarning): vqe = VQE( self.ry_wavefunction, SPSA(maxiter=300, last_avg=5), @@ -364,13 +378,14 @@ def store_intermediate_result(eval_count, parameters, mean, std): optimizer = COBYLA(maxiter=3) wavefunction = self.ry_wavefunction - vqe = VQE( - ansatz=wavefunction, - optimizer=optimizer, - callback=store_intermediate_result, - quantum_instance=self.qasm_simulator, - ) - vqe.compute_minimum_eigenvalue(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=wavefunction, + optimizer=optimizer, + callback=store_intermediate_result, + quantum_instance=self.qasm_simulator, + ) + vqe.compute_minimum_eigenvalue(operator=self.h2_op) self.assertTrue(all(isinstance(count, int) for count in history["eval_count"])) self.assertTrue(all(isinstance(mean, float) for mean in history["mean"])) @@ -380,38 +395,45 @@ def store_intermediate_result(eval_count, parameters, mean, std): def test_reuse(self): """Test re-using a VQE algorithm instance.""" - vqe = VQE() + with self.assertWarns(DeprecationWarning): + vqe = VQE() with self.subTest(msg="assert running empty raises AlgorithmError"): - with self.assertRaises(AlgorithmError): + with self.assertWarns(DeprecationWarning), self.assertRaises(AlgorithmError): _ = vqe.compute_minimum_eigenvalue(operator=self.h2_op) ansatz = TwoLocal(rotation_blocks=["ry", "rz"], entanglement_blocks="cz") vqe.ansatz = ansatz with self.subTest(msg="assert missing operator raises AlgorithmError"): - with self.assertRaises(AlgorithmError): + with self.assertWarns(DeprecationWarning), self.assertRaises(AlgorithmError): _ = vqe.compute_minimum_eigenvalue(operator=self.h2_op) vqe.expectation = MatrixExpectation() vqe.quantum_instance = self.statevector_simulator - with self.subTest(msg="assert VQE works once all info is available"): + with self.subTest(msg="assert VQE works once all info is available"), self.assertWarns( + DeprecationWarning + ): result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) self.assertAlmostEqual(result.eigenvalue.real, self.h2_energy, places=5) operator = PrimitiveOp(np.array([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, 2, 0], [0, 0, 0, 3]])) - with self.subTest(msg="assert minimum eigensolver interface works"): + with self.subTest(msg="assert minimum eigensolver interface works"), self.assertWarns( + DeprecationWarning + ): result = vqe.compute_minimum_eigenvalue(operator=operator) self.assertAlmostEqual(result.eigenvalue.real, -1.0, places=5) def test_vqe_optimizer(self): """Test running same VQE twice to re-use optimizer, then switch optimizer""" - vqe = VQE( - optimizer=SLSQP(), - quantum_instance=QuantumInstance(BasicAer.get_backend("statevector_simulator")), - ) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + optimizer=SLSQP(), + quantum_instance=QuantumInstance(BasicAer.get_backend("statevector_simulator")), + ) def run_check(): - result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + result = vqe.compute_minimum_eigenvalue(operator=self.h2_op) self.assertAlmostEqual(result.eigenvalue.real, -1.85727503, places=5) run_check() @@ -426,13 +448,14 @@ def run_check(): @data(MatrixExpectation(), None) def test_backend_change(self, user_expectation): """Test that VQE works when backend changes.""" - vqe = VQE( - ansatz=TwoLocal(rotation_blocks=["ry", "rz"], entanglement_blocks="cz"), - optimizer=SLSQP(maxiter=2), - expectation=user_expectation, - quantum_instance=BasicAer.get_backend("statevector_simulator"), - ) - result0 = vqe.compute_minimum_eigenvalue(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=TwoLocal(rotation_blocks=["ry", "rz"], entanglement_blocks="cz"), + optimizer=SLSQP(maxiter=2), + expectation=user_expectation, + quantum_instance=BasicAer.get_backend("statevector_simulator"), + ) + result0 = vqe.compute_minimum_eigenvalue(operator=self.h2_op) if user_expectation is not None: with self.subTest("User expectation kept."): self.assertEqual(vqe.expectation, user_expectation) @@ -440,7 +463,8 @@ def test_backend_change(self, user_expectation): vqe.quantum_instance = BasicAer.get_backend("qasm_simulator") # works also if no expectation is set, since it will be determined automatically - result1 = vqe.compute_minimum_eigenvalue(operator=self.h2_op) + with self.assertWarns(DeprecationWarning): + result1 = vqe.compute_minimum_eigenvalue(operator=self.h2_op) if user_expectation is not None: with self.subTest("Change backend with user expectation, it is kept."): @@ -464,16 +488,18 @@ def wrapped_run(circuits, **kwargs): wrapped_backend.run = partial(wrapped_run, callcount=callcount) - fidelity = QNSPSA.get_fidelity(ansatz, backend=wrapped_backend) + with self.assertWarns(DeprecationWarning): + fidelity = QNSPSA.get_fidelity(ansatz, backend=wrapped_backend) qnspsa = QNSPSA(fidelity, maxiter=5) - vqe = VQE( - ansatz=ansatz, - optimizer=qnspsa, - max_evals_grouped=100, - quantum_instance=wrapped_backend, - ) - _ = vqe.compute_minimum_eigenvalue(Z ^ Z) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=ansatz, + optimizer=qnspsa, + max_evals_grouped=100, + quantum_instance=wrapped_backend, + ) + _ = vqe.compute_minimum_eigenvalue(Z ^ Z) # 1 calibration + 1 stddev estimation + 1 initial blocking # + 5 (1 loss + 1 fidelity + 1 blocking) + 1 return loss + 1 VQE eval @@ -483,49 +509,56 @@ def wrapped_run(circuits, **kwargs): def test_set_ansatz_to_none(self): """Tests that setting the ansatz to None results in the default behavior""" - vqe = VQE( - ansatz=self.ryrz_wavefunction, - optimizer=L_BFGS_B(), - quantum_instance=self.statevector_simulator, - ) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=self.ryrz_wavefunction, + optimizer=L_BFGS_B(), + quantum_instance=self.statevector_simulator, + ) vqe.ansatz = None self.assertIsInstance(vqe.ansatz, RealAmplitudes) def test_set_optimizer_to_none(self): """Tests that setting the optimizer to None results in the default behavior""" - vqe = VQE( - ansatz=self.ryrz_wavefunction, - optimizer=L_BFGS_B(), - quantum_instance=self.statevector_simulator, - ) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=self.ryrz_wavefunction, + optimizer=L_BFGS_B(), + quantum_instance=self.statevector_simulator, + ) vqe.optimizer = None self.assertIsInstance(vqe.optimizer, SLSQP) def test_optimizer_scipy_callable(self): """Test passing a SciPy optimizer directly as callable.""" - vqe = VQE( - optimizer=partial(scipy_minimize, method="L-BFGS-B", options={"maxiter": 2}), - quantum_instance=self.statevector_simulator, - ) - result = vqe.compute_minimum_eigenvalue(Z) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + optimizer=partial(scipy_minimize, method="L-BFGS-B", options={"maxiter": 2}), + quantum_instance=self.statevector_simulator, + ) + result = vqe.compute_minimum_eigenvalue(Z) self.assertEqual(result.cost_function_evals, 20) def test_optimizer_callable(self): """Test passing a optimizer directly as callable.""" ansatz = RealAmplitudes(1, reps=1) - vqe = VQE( - ansatz=ansatz, optimizer=_mock_optimizer, quantum_instance=self.statevector_simulator - ) - result = vqe.compute_minimum_eigenvalue(Z) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=ansatz, + optimizer=_mock_optimizer, + quantum_instance=self.statevector_simulator, + ) + result = vqe.compute_minimum_eigenvalue(Z) self.assertTrue(np.all(result.optimal_point == np.zeros(ansatz.num_parameters))) def test_aux_operators_list(self): """Test list-based aux_operators.""" wavefunction = self.ry_wavefunction - vqe = VQE(ansatz=wavefunction, quantum_instance=self.statevector_simulator) + with self.assertWarns(DeprecationWarning): + vqe = VQE(ansatz=wavefunction, quantum_instance=self.statevector_simulator) - # Start with an empty list - result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=[]) + # Start with an empty list + result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=[]) self.assertAlmostEqual(result.eigenvalue.real, self.h2_energy, places=6) self.assertIsNone(result.aux_operator_eigenvalues) @@ -533,7 +566,8 @@ def test_aux_operators_list(self): aux_op1 = PauliSumOp.from_list([("II", 2.0)]) aux_op2 = PauliSumOp.from_list([("II", 0.5), ("ZZ", 0.5), ("YY", 0.5), ("XX", -0.5)]) aux_ops = [aux_op1, aux_op2] - result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=aux_ops) + with self.assertWarns(DeprecationWarning): + result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=aux_ops) self.assertAlmostEqual(result.eigenvalue.real, self.h2_energy, places=6) self.assertEqual(len(result.aux_operator_eigenvalues), 2) # expectation values @@ -545,7 +579,8 @@ def test_aux_operators_list(self): # Go again with additional None and zero operators extra_ops = [*aux_ops, None, 0] - result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=extra_ops) + with self.assertWarns(DeprecationWarning): + result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=extra_ops) self.assertAlmostEqual(result.eigenvalue.real, self.h2_energy, places=6) self.assertEqual(len(result.aux_operator_eigenvalues), 4) # expectation values @@ -562,10 +597,12 @@ def test_aux_operators_list(self): def test_aux_operators_dict(self): """Test dictionary compatibility of aux_operators""" wavefunction = self.ry_wavefunction - vqe = VQE(ansatz=wavefunction, quantum_instance=self.statevector_simulator) + with self.assertWarns(DeprecationWarning): + vqe = VQE(ansatz=wavefunction, quantum_instance=self.statevector_simulator) # Start with an empty dictionary - result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators={}) + with self.assertWarns(DeprecationWarning): + result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators={}) self.assertAlmostEqual(result.eigenvalue.real, self.h2_energy, places=6) self.assertIsNone(result.aux_operator_eigenvalues) @@ -573,7 +610,8 @@ def test_aux_operators_dict(self): aux_op1 = PauliSumOp.from_list([("II", 2.0)]) aux_op2 = PauliSumOp.from_list([("II", 0.5), ("ZZ", 0.5), ("YY", 0.5), ("XX", -0.5)]) aux_ops = {"aux_op1": aux_op1, "aux_op2": aux_op2} - result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=aux_ops) + with self.assertWarns(DeprecationWarning): + result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=aux_ops) self.assertAlmostEqual(result.eigenvalue.real, self.h2_energy, places=6) self.assertEqual(len(result.aux_operator_eigenvalues), 2) # expectation values @@ -585,7 +623,8 @@ def test_aux_operators_dict(self): # Go again with additional None and zero operators extra_ops = {**aux_ops, "None_operator": None, "zero_operator": 0} - result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=extra_ops) + with self.assertWarns(DeprecationWarning): + result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=extra_ops) self.assertAlmostEqual(result.eigenvalue.real, self.h2_energy, places=6) self.assertEqual(len(result.aux_operator_eigenvalues), 3) # expectation values @@ -601,18 +640,20 @@ def test_aux_operators_dict(self): def test_aux_operator_std_dev_pauli(self): """Test non-zero standard deviations of aux operators with PauliExpectation.""" wavefunction = self.ry_wavefunction - vqe = VQE( - ansatz=wavefunction, - expectation=PauliExpectation(), - optimizer=COBYLA(maxiter=0), - quantum_instance=self.qasm_simulator, - ) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=wavefunction, + expectation=PauliExpectation(), + optimizer=COBYLA(maxiter=0), + quantum_instance=self.qasm_simulator, + ) # Go again with two auxiliary operators aux_op1 = PauliSumOp.from_list([("II", 2.0)]) aux_op2 = PauliSumOp.from_list([("II", 0.5), ("ZZ", 0.5), ("YY", 0.5), ("XX", -0.5)]) aux_ops = [aux_op1, aux_op2] - result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=aux_ops) + with self.assertWarns(DeprecationWarning): + result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=aux_ops) self.assertEqual(len(result.aux_operator_eigenvalues), 2) # expectation values self.assertAlmostEqual(result.aux_operator_eigenvalues[0][0], 2.0, places=6) @@ -623,7 +664,8 @@ def test_aux_operator_std_dev_pauli(self): # Go again with additional None and zero operators aux_ops = [*aux_ops, None, 0] - result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=aux_ops) + with self.assertWarns(DeprecationWarning): + result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=aux_ops) self.assertEqual(len(result.aux_operator_eigenvalues), 4) # expectation values self.assertAlmostEqual(result.aux_operator_eigenvalues[0][0], 2.0, places=6) @@ -642,23 +684,25 @@ def test_aux_operator_std_dev_pauli(self): def test_aux_operator_std_dev_aer_pauli(self): """Test non-zero standard deviations of aux operators with AerPauliExpectation.""" wavefunction = self.ry_wavefunction - vqe = VQE( - ansatz=wavefunction, - expectation=AerPauliExpectation(), - optimizer=COBYLA(maxiter=0), - quantum_instance=QuantumInstance( - backend=Aer.get_backend("qasm_simulator"), - shots=1, - seed_simulator=algorithm_globals.random_seed, - seed_transpiler=algorithm_globals.random_seed, - ), - ) + with self.assertWarns(DeprecationWarning): + vqe = VQE( + ansatz=wavefunction, + expectation=AerPauliExpectation(), + optimizer=COBYLA(maxiter=0), + quantum_instance=QuantumInstance( + backend=Aer.get_backend("qasm_simulator"), + shots=1, + seed_simulator=algorithm_globals.random_seed, + seed_transpiler=algorithm_globals.random_seed, + ), + ) # Go again with two auxiliary operators aux_op1 = PauliSumOp.from_list([("II", 2.0)]) aux_op2 = PauliSumOp.from_list([("II", 0.5), ("ZZ", 0.5), ("YY", 0.5), ("XX", -0.5)]) aux_ops = [aux_op1, aux_op2] - result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=aux_ops) + with self.assertWarns(DeprecationWarning): + result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=aux_ops) self.assertEqual(len(result.aux_operator_eigenvalues), 2) # expectation values self.assertAlmostEqual(result.aux_operator_eigenvalues[0][0], 2.0, places=6) @@ -669,7 +713,8 @@ def test_aux_operator_std_dev_aer_pauli(self): # Go again with additional None and zero operators aux_ops = [*aux_ops, None, 0] - result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=aux_ops) + with self.assertWarns(DeprecationWarning): + result = vqe.compute_minimum_eigenvalue(self.h2_op, aux_operators=aux_ops) self.assertEqual(len(result.aux_operator_eigenvalues), 4) # expectation values self.assertAlmostEqual(result.aux_operator_eigenvalues[0][0], 2.0, places=6) @@ -703,10 +748,11 @@ def test_2step_transpile(self): optimizer = SPSA(maxiter=5, learning_rate=0.01, perturbation=0.01) - vqe = VQE(optimizer=optimizer, quantum_instance=quantum_instance) - _ = vqe.compute_minimum_eigenvalue(Z) + with self.assertWarns(DeprecationWarning): + vqe = VQE(optimizer=optimizer, quantum_instance=quantum_instance) + _ = vqe.compute_minimum_eigenvalue(Z) - with self.assertLogs(logger, level="INFO") as cm: + with self.assertLogs(logger, level="INFO") as cm, self.assertWarns(DeprecationWarning): _ = vqe.compute_minimum_eigenvalue(Z) expected = [ @@ -736,8 +782,9 @@ def test_construct_eigenstate_from_optpoint(self): quantum_instance = QuantumInstance( backend=BasicAer.get_backend("statevector_simulator"), basis_gates=["u3", "cx"] ) - vqe = VQE(optimizer=optimizer, quantum_instance=quantum_instance) - result = vqe.compute_minimum_eigenvalue(hamiltonian) + with self.assertWarns(DeprecationWarning): + vqe = VQE(optimizer=optimizer, quantum_instance=quantum_instance) + result = vqe.compute_minimum_eigenvalue(hamiltonian) optimal_circuit = vqe.ansatz.bind_parameters(result.optimal_point) self.assertTrue(Statevector(result.eigenstate).equiv(optimal_circuit)) diff --git a/test/python/algorithms/time_evolvers/test_pvqd.py b/test/python/algorithms/time_evolvers/test_pvqd.py index 70cb12520e84..55c7c0f45ba7 100644 --- a/test/python/algorithms/time_evolvers/test_pvqd.py +++ b/test/python/algorithms/time_evolvers/test_pvqd.py @@ -18,7 +18,7 @@ from ddt import data, ddt, unpack from qiskit import QiskitError -from qiskit.algorithms.evolvers import EvolutionProblem +from qiskit.algorithms.time_evolvers import TimeEvolutionProblem from qiskit.algorithms.optimizers import L_BFGS_B, SPSA, GradientDescent, OptimizerResult from qiskit.algorithms.state_fidelities import ComputeUncompute from qiskit.algorithms.time_evolvers.pvqd import PVQD @@ -96,7 +96,9 @@ def test_pvqd(self, hamiltonian_type, gradient, num_timesteps): optimizer=optimizer, num_timesteps=num_timesteps, ) - problem = EvolutionProblem(hamiltonian, time, aux_operators=[hamiltonian, self.observable]) + problem = TimeEvolutionProblem( + hamiltonian, time, aux_operators=[hamiltonian, self.observable] + ) result = pvqd.evolve(problem) self.assertTrue(len(result.fidelities) == 3) @@ -176,7 +178,7 @@ def test_invalid_num_timestep(self): optimizer=L_BFGS_B(), num_timesteps=0, ) - problem = EvolutionProblem( + problem = TimeEvolutionProblem( self.hamiltonian, time=0.01, aux_operators=[self.hamiltonian, self.observable] ) @@ -199,7 +201,7 @@ def test_initial_guess_and_observables(self): num_timesteps=10, initial_guess=initial_guess, ) - problem = EvolutionProblem( + problem = TimeEvolutionProblem( self.hamiltonian, time=0.1, aux_operators=[self.hamiltonian, self.observable] ) @@ -211,7 +213,7 @@ def test_initial_guess_and_observables(self): def test_zero_parameters(self): """Test passing an ansatz with zero parameters raises an error.""" - problem = EvolutionProblem(self.hamiltonian, time=0.02) + problem = TimeEvolutionProblem(self.hamiltonian, time=0.02) sampler = Sampler() fidelity_primitive = ComputeUncompute(sampler) @@ -230,7 +232,7 @@ def test_initial_state_raises(self): initial_state = QuantumCircuit(2) initial_state.x(0) - problem = EvolutionProblem( + problem = TimeEvolutionProblem( self.hamiltonian, time=0.02, initial_state=initial_state, @@ -252,7 +254,7 @@ def test_initial_state_raises(self): def test_aux_ops_raises(self): """Test passing auxiliary operators with no estimator raises an error.""" - problem = EvolutionProblem( + problem = TimeEvolutionProblem( self.hamiltonian, time=0.02, aux_operators=[self.hamiltonian, self.observable] ) @@ -321,7 +323,7 @@ def test_gradient_supported(self): estimator=estimator, optimizer=optimizer, ) - problem = EvolutionProblem(self.hamiltonian, time=0.01) + problem = TimeEvolutionProblem(self.hamiltonian, time=0.01) for circuit, expected_support in tests: with self.subTest(circuit=circuit, expected_support=expected_support): pvqd.ansatz = circuit