Repository: Qiskit/qiskit-optimization
Pull request #499 (2023-04-26 07:01:37)

Deprecates Opflow and `QuantumInstance`
<!--
⚠️ If you do not respect this template, your pull request will be closed.
⚠️ Your pull request title should be short detailed and understandable for all.
⚠️ Also, please add it in the CHANGELOG file under Unreleased section.
⚠️ If your pull request fixes an open issue, please link to the issue.

✅ I have added the tests to cover my changes.
✅ I have updated the documentation accordingly.
✅ I have read the CONTRIBUTING document.
-->

### Summary

This PR deprecates Opflow and `QuantumInstance` related parts.
This PR also refactors some codes to suppress Opflow/QuantumInstance deprecation warnings by using SparsePauliOp and `self.assertWarns` as much as possible.

https://github.com/Qiskit/qiskit-terra/pull/10030 is also necessary to suppress more opflow deprecation warnings because `QAOA` currently converts `SparsePauliOp` into Opflow internally.


### Details and comments




coveralls: ## Pull Request Test Coverage Report for [Build 4806245182](https://coveralls.io/builds/59332662)

* **17** of **17**   **(100.0%)**  changed or added relevant lines in **3** files are covered.
* **3** unchanged lines in **1** file lost coverage.
* Overall coverage decreased (**-0.005%**) to **92.165%**

---


|  Files with Coverage Reduction | New Missed Lines | % |
| :-----|--------------|--: |
| [qiskit_optimization/algorithms/grover_optimizer.py](https://coveralls.io/builds/59332662/source?filename=qiskit_optimization%2Falgorithms%2Fgrover_optimizer.py#L118) | 3 | 93.66% |
<!-- | **Total:** | **3** |  | -->

|  Totals | [![Coverage Status](https://coveralls.io/builds/59332662/badge)](https://coveralls.io/builds/59332662) |
| :-- | --: |
| Change from base [Build 4805115199](https://coveralls.io/builds/59327206): |  -0.005% |
| Covered Lines: | 4364 |
| Relevant Lines: | 4735 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/qiskit_optimization/algorithms/grover_optimizer.py b/qiskit_optimization/algorithms/grover_optimizer.py
index f77da7e..80acf99 100644
--- a/qiskit_optimization/algorithms/grover_optimizer.py
+++ b/qiskit_optimization/algorithms/grover_optimizer.py
@@ -1,6 +1,6 @@
 # This code is part of Qiskit.
 #
-# (C) Copyright IBM 2020, 2022.
+# (C) Copyright IBM 2020, 2023.
 #
 # This code is licensed under the Apache License, Version 2.0. You may
 # obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -14,7 +14,6 @@
 
 import logging
 import math
-import warnings
 from copy import deepcopy
 from typing import Dict, List, Optional, Union, cast
 
@@ -28,16 +27,21 @@ from qiskit.providers import Backend
 from qiskit.quantum_info import partial_trace
 from qiskit.utils import QuantumInstance, algorithm_globals
 
-from ..converters.quadratic_program_to_qubo import QuadraticProgramConverter, QuadraticProgramToQubo
-from ..exceptions import QiskitOptimizationError
-from ..problems import Variable
-from ..problems.quadratic_program import QuadraticProgram
-from .optimization_algorithm import (
+from qiskit_optimization.algorithms.optimization_algorithm import (
     OptimizationAlgorithm,
     OptimizationResult,
     OptimizationResultStatus,
     SolutionSample,
 )
+from qiskit_optimization.converters import QuadraticProgramConverter, QuadraticProgramToQubo
+from qiskit_optimization.deprecation import (
+    DeprecatedType,
+    deprecate_method,
+    deprecate_property,
+    warn_deprecated,
+)
+from qiskit_optimization.exceptions import QiskitOptimizationError
+from qiskit_optimization.problems import QuadraticProgram, Variable
 
 logger = logging.getLogger(__name__)
 
@@ -82,51 +86,35 @@ class GroverOptimizer(OptimizationAlgorithm):
         if quantum_instance is not None and sampler is not None:
             raise ValueError("Only one of quantum_instance or sampler can be passed, not both!")
 
-        self._quantum_instance = None  # type: Optional[QuantumInstance]
-        if quantum_instance is not None:
-            warnings.warn(
-                "The quantum_instance argument has been superseded by the sampler argument. "
-                "This argument will be deprecated in a future release and subsequently "
-                "removed after that.",
-                category=PendingDeprecationWarning,
-                stacklevel=2,
+        if quantum_instance:
+            warn_deprecated(
+                "0.6.0",
+                old_type=DeprecatedType.ARGUMENT,
+                old_name="quantum_instance",
+                new_type=DeprecatedType.ARGUMENT,
+                new_name="sampler",
             )
-            with warnings.catch_warnings():
-                warnings.simplefilter("ignore", category=PendingDeprecationWarning)
-                self.quantum_instance = quantum_instance
-
+        self._quantum_instance = quantum_instance  # type: Optional[QuantumInstance]
         self._sampler = sampler
 
     @property
+    @deprecate_property("0.6.0")
     def quantum_instance(self) -> QuantumInstance:
         """The quantum instance to run the circuits.
 
         Returns:
             The quantum instance used in the algorithm.
         """
-        warnings.warn(
-            "The quantum_instance argument has been superseded by the sampler argument. "
-            "This argument will be deprecated in a future release and subsequently "
-            "removed after that.",
-            category=PendingDeprecationWarning,
-            stacklevel=2,
-        )
         return self._quantum_instance
 
     @quantum_instance.setter
+    @deprecate_method("0.6.0")
     def quantum_instance(self, quantum_instance: Union[Backend, QuantumInstance]) -> None:
         """Set the quantum instance used to run the circuits.
 
         Args:
             quantum_instance: The quantum instance to be used in the algorithm.
         """
-        warnings.warn(
-            "The GroverOptimizer.quantum_instance setter is pending deprecation. "
-            "This property will be deprecated in a future release and subsequently "
-            "removed after that.",
-            category=PendingDeprecationWarning,
-            stacklevel=2,
-        )
         if isinstance(quantum_instance, Backend):
             self._quantum_instance = QuantumInstance(quantum_instance)
         else:
diff --git a/qiskit_optimization/algorithms/minimum_eigen_optimizer.py b/qiskit_optimization/algorithms/minimum_eigen_optimizer.py
index d1b9526..8230fc8 100644
--- a/qiskit_optimization/algorithms/minimum_eigen_optimizer.py
+++ b/qiskit_optimization/algorithms/minimum_eigen_optimizer.py
@@ -19,13 +19,13 @@ from qiskit.algorithms.minimum_eigen_solvers import (
     MinimumEigensolverResult as LegacyMinimumEigensolverResult,
 )
 from qiskit.algorithms.minimum_eigensolvers import (
+    VQE,
     NumPyMinimumEigensolver,
     NumPyMinimumEigensolverResult,
     SamplingMinimumEigensolver,
     SamplingMinimumEigensolverResult,
-    VQE,
 )
-from qiskit.opflow import OperatorBase, PauliOp, PauliSumOp
+from qiskit.quantum_info import SparsePauliOp
 
 from ..converters.quadratic_program_to_qubo import QuadraticProgramConverter, QuadraticProgramToQubo
 from ..exceptions import QiskitOptimizationError
@@ -222,13 +222,13 @@ class MinimumEigenOptimizer(OptimizationAlgorithm):
         problem_ = self._convert(problem, self._converters)
 
         # construct operator and offset
-        operator, offset = problem_.to_ising(opflow=True)
+        operator, offset = problem_.to_ising(opflow=False)
 
         return self._solve_internal(operator, offset, problem_, problem)
 
     def _solve_internal(
         self,
-        operator: OperatorBase,
+        operator: SparsePauliOp,
         offset: float,
         converted_problem: QuadraticProgram,
         original_problem: QuadraticProgram,
@@ -236,11 +236,15 @@ class MinimumEigenOptimizer(OptimizationAlgorithm):
         # only try to solve non-empty Ising Hamiltonians
         eigen_result: Optional[MinimumEigensolverResult] = None
         if operator.num_qubits > 0:
-            # NumPyEigensolver does not accept PauliOp but PauliSumOp
-            if isinstance(operator, PauliOp):
-                operator = PauliSumOp.from_list([(operator.primitive.to_label(), operator.coeff)])
             # approximate ground state of operator using min eigen solver
-            eigen_result = self._min_eigen_solver.compute_minimum_eigenvalue(operator)
+            if isinstance(self._min_eigen_solver, LegacyMinimumEigensolver):
+                from qiskit.opflow import PauliSumOp
+
+                eigen_result = self._min_eigen_solver.compute_minimum_eigenvalue(
+                    PauliSumOp(operator)
+                )
+            else:
+                eigen_result = self._min_eigen_solver.compute_minimum_eigenvalue(operator)
             # analyze results
             raw_samples = None
             if eigen_result.eigenstate is not None:
diff --git a/qiskit_optimization/algorithms/optimization_algorithm.py b/qiskit_optimization/algorithms/optimization_algorithm.py
index d67c9b7..68ee6c2 100644
--- a/qiskit_optimization/algorithms/optimization_algorithm.py
+++ b/qiskit_optimization/algorithms/optimization_algorithm.py
@@ -1,6 +1,6 @@
 # This code is part of Qiskit.
 #
-# (C) Copyright IBM 2020, 2022.
+# (C) Copyright IBM 2020, 2023.
 #
 # This code is licensed under the Apache License, Version 2.0. You may
 # obtain a copy of this license in the LICENSE.txt file in the root directory
diff --git a/qiskit_optimization/algorithms/warm_start_qaoa_optimizer.py b/qiskit_optimization/algorithms/warm_start_qaoa_optimizer.py
index 6c41b9d..7e586cb 100644
--- a/qiskit_optimization/algorithms/warm_start_qaoa_optimizer.py
+++ b/qiskit_optimization/algorithms/warm_start_qaoa_optimizer.py
@@ -311,7 +311,7 @@ class WarmStartQAOAOptimizer(MinimumEigenOptimizer):
         pre_solutions = opt_result.samples[:num_pre_solutions]
 
         # construct operator and offset
-        operator, offset = converted_problem.to_ising(opflow=True)
+        operator, offset = converted_problem.to_ising(opflow=False)
 
         results: List[MinimumEigenOptimizationResult] = []
         for pre_solution in pre_solutions:
diff --git a/qiskit_optimization/applications/optimization_application.py b/qiskit_optimization/applications/optimization_application.py
index 32aae00..963e2a0 100644
--- a/qiskit_optimization/applications/optimization_application.py
+++ b/qiskit_optimization/applications/optimization_application.py
@@ -1,6 +1,6 @@
 # This code is part of Qiskit.
 #
-# (C) Copyright IBM 2018, 2022.
+# (C) Copyright IBM 2018, 2023.
 #
 # This code is licensed under the Apache License, Version 2.0. You may
 # obtain a copy of this license in the LICENSE.txt file in the root directory
diff --git a/qiskit_optimization/translators/ising.py b/qiskit_optimization/translators/ising.py
index 52cdf39..5ebd5af 100644
--- a/qiskit_optimization/translators/ising.py
+++ b/qiskit_optimization/translators/ising.py
@@ -184,9 +184,9 @@ def from_ising(
         warn(
             "The `qubit_op` argument can currently accept Opflow operators (`OperatorBase` type), "
             "but have been superseded by Qiskit Terra quantum_info `BaseOperators` such as "
-            "`SparsePauliOp`. Opflow operator support will be deprecated in a future release "
+            "`SparsePauliOp`. Opflow operators have been deprecated in Qiskit Terra 0.24.0 "
             "and subsequently removed after that.",
-            category=PendingDeprecationWarning,
+            category=DeprecationWarning,
             stacklevel=2,
         )
     if isinstance(qubit_op, PauliSumOp):
diff --git a/releasenotes/notes/deprecate-opflow-0c472adf38939a5c.yaml b/releasenotes/notes/deprecate-opflow-0c472adf38939a5c.yaml
new file mode 100644
index 0000000..10c13fc
--- /dev/null
+++ b/releasenotes/notes/deprecate-opflow-0c472adf38939a5c.yaml
@@ -0,0 +1,13 @@
+---
+deprecations:
+  - |
+    The ``quantum_instance`` argument of :class:`~qiskit_optimization.algorithms.GroverOptimizer`'s constructor
+    and :meth:`~qiskit_optimization.algorithms.GroverOptimizer.quantum_instance` property have been deprecated
+    and will be removed in a future release.
+    Using ``QuantumInstance`` is superseded by ``Sampler``.
+    See `QuantumInstance Migration <https://qisk.it/qi_migration>`__.
+  - |
+    The ``qubit_op`` argument of :func:`~qiskit_optimization.translators.from_ising`
+    can currently accept Opflow operators.
+    But they have been deprecated in Qiskit Terra 0.24.0 and will be removed in a future release.
+    See `Opflow Migration <https://qisk.it/opflow_migration>`__.


Test patch:
diff --git a/test/algorithms/legacy/test_min_eigen_optimizer.py b/test/algorithms/legacy/test_min_eigen_optimizer.py
index f017409..83a1a2b 100644
--- a/test/algorithms/legacy/test_min_eigen_optimizer.py
+++ b/test/algorithms/legacy/test_min_eigen_optimizer.py
@@ -108,7 +108,8 @@ class TestMinEigenOptimizer(QiskitOptimizationTestCase):
             # get minimum eigen solver
             min_eigen_solver = self.min_eigen_solvers[min_eigen_solver_name]
             if backend:
-                min_eigen_solver.quantum_instance = BasicAer.get_backend(backend)
+                with self.assertWarns(DeprecationWarning):
+                    min_eigen_solver.quantum_instance = BasicAer.get_backend(backend)
 
             # construct minimum eigen optimizer
             min_eigen_optimizer = MinimumEigenOptimizer(min_eigen_solver)
@@ -379,26 +380,29 @@ class TestMinEigenOptimizer(QiskitOptimizationTestCase):
         if subroutine == "vqe":
             ry_ansatz = TwoLocal(5, "ry", "cz", reps=3, entanglement="full")
             initial_point = np.random.default_rng(42).random(ry_ansatz.num_parameters)
-            solver = VQEClient(
-                ansatz=ry_ansatz,
-                optimizer=optimizer,
-                initial_point=initial_point,
-                backend=backend,
-                provider=FakeVQERuntimeProvider(),
-            )
+            with self.assertWarns(DeprecationWarning):
+                solver = VQEClient(
+                    ansatz=ry_ansatz,
+                    optimizer=optimizer,
+                    initial_point=initial_point,
+                    backend=backend,
+                    provider=FakeVQERuntimeProvider(),
+                )
         else:
             reps = 2
             initial_point = np.random.default_rng(42).random(2 * reps)
-            solver = QAOAClient(
-                optimizer=optimizer,
-                reps=reps,
-                initial_point=initial_point,
-                backend=backend,
-                provider=FakeQAOARuntimeProvider(),
-            )
+            with self.assertWarns(DeprecationWarning):
+                solver = QAOAClient(
+                    optimizer=optimizer,
+                    reps=reps,
+                    initial_point=initial_point,
+                    backend=backend,
+                    provider=FakeQAOARuntimeProvider(),
+                )
 
         opt = MinimumEigenOptimizer(solver)
-        result = opt.solve(self.op_ordering)
+        with self.assertWarns(DeprecationWarning):
+            result = opt.solve(self.op_ordering)
         self.assertIsInstance(result, MinimumEigenOptimizationResult)
 
 
diff --git a/test/algorithms/test_grover_optimizer.py b/test/algorithms/test_grover_optimizer.py
index 173adde..5571908 100644
--- a/test/algorithms/test_grover_optimizer.py
+++ b/test/algorithms/test_grover_optimizer.py
@@ -1,6 +1,6 @@
 # This code is part of Qiskit.
 #
-# (C) Copyright IBM 2020, 2022.
+# (C) Copyright IBM 2020, 2023.
 #
 # This code is licensed under the Apache License, Version 2.0. You may
 # obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -18,8 +18,9 @@ from test import QiskitOptimizationTestCase
 import numpy as np
 from ddt import data, ddt
 from docplex.mp.model import Model
-from qiskit.utils import QuantumInstance, algorithm_globals, optionals
 from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver
+from qiskit.utils import QuantumInstance, algorithm_globals, optionals
+
 from qiskit_optimization.algorithms import (
     GroverOptimizer,
     MinimumEigenOptimizer,
@@ -47,16 +48,18 @@ class TestGroverOptimizer(QiskitOptimizationTestCase):
         from qiskit_aer import Aer
         from qiskit_aer.primitives import Sampler
 
-        self.sv_simulator = QuantumInstance(
-            Aer.get_backend("aer_simulator_statevector"),
-            seed_simulator=921,
-            seed_transpiler=200,
-        )
-        self.qasm_simulator = QuantumInstance(
-            Aer.get_backend("aer_simulator"),
-            seed_simulator=123,
-            seed_transpiler=123,
-        )
+        with self.assertWarns(DeprecationWarning):
+            self.sv_simulator = QuantumInstance(
+                Aer.get_backend("aer_simulator_statevector"),
+                seed_simulator=921,
+                seed_transpiler=200,
+            )
+        with self.assertWarns(DeprecationWarning):
+            self.qasm_simulator = QuantumInstance(
+                Aer.get_backend("aer_simulator"),
+                seed_simulator=123,
+                seed_transpiler=123,
+            )
         self.sampler = Sampler(run_options={"seed_simulator": 123})
         self.n_iter = 8
 
@@ -65,21 +68,19 @@ class TestGroverOptimizer(QiskitOptimizationTestCase):
     ):
         """Prepare GroverOptimizer."""
         if simulator == "statevector":
-            with self.assertWarns(PendingDeprecationWarning):
-                grover_optimizer = GroverOptimizer(
-                    num_value_qubits=num_value_qubits,
-                    num_iterations=num_iterations,
-                    converters=converters,
-                    quantum_instance=self.sv_simulator,
-                )
+            grover_optimizer = GroverOptimizer(
+                num_value_qubits=num_value_qubits,
+                num_iterations=num_iterations,
+                converters=converters,
+                quantum_instance=self.sv_simulator,
+            )
         elif simulator == "qasm":
-            with self.assertWarns(PendingDeprecationWarning):
-                grover_optimizer = GroverOptimizer(
-                    num_value_qubits=num_value_qubits,
-                    num_iterations=num_iterations,
-                    converters=converters,
-                    quantum_instance=self.qasm_simulator,
-                )
+            grover_optimizer = GroverOptimizer(
+                num_value_qubits=num_value_qubits,
+                num_iterations=num_iterations,
+                converters=converters,
+                quantum_instance=self.qasm_simulator,
+            )
         else:
             grover_optimizer = GroverOptimizer(
                 num_value_qubits=num_value_qubits,
@@ -117,7 +118,11 @@ class TestGroverOptimizer(QiskitOptimizationTestCase):
         grover_optimizer = self._prepare_grover_optimizer(
             num_value_qubits=1, num_iterations=1, simulator=simulator
         )
-        results = grover_optimizer.solve(op)
+        if simulator == "sampler":
+            results = grover_optimizer.solve(op)
+        else:
+            with self.assertWarns(DeprecationWarning):
+                results = grover_optimizer.solve(op)
         np.testing.assert_array_almost_equal(results.x, [0, 0])
         self.assertEqual(results.fval, 0.0)
         self.assertAlmostEqual(results.fval, results.intermediate_fval)
@@ -137,7 +142,11 @@ class TestGroverOptimizer(QiskitOptimizationTestCase):
         grover_optimizer = self._prepare_grover_optimizer(
             num_value_qubits=4, num_iterations=self.n_iter, simulator=simulator
         )
-        results = grover_optimizer.solve(op)
+        if simulator == "sampler":
+            results = grover_optimizer.solve(op)
+        else:
+            with self.assertWarns(DeprecationWarning):
+                results = grover_optimizer.solve(op)
         self.validate_results(op, results)
 
         self.assertIsNotNone(results.operation_counts)
@@ -159,7 +168,11 @@ class TestGroverOptimizer(QiskitOptimizationTestCase):
         grover_optimizer = self._prepare_grover_optimizer(
             num_value_qubits=4, num_iterations=self.n_iter, simulator=simulator
         )
-        results = grover_optimizer.solve(op)
+        if simulator == "sampler":
+            results = grover_optimizer.solve(op)
+        else:
+            with self.assertWarns(DeprecationWarning):
+                results = grover_optimizer.solve(op)
         self.validate_results(op, results)
 
     @data("statevector", "qasm", "sampler")
@@ -181,7 +194,11 @@ class TestGroverOptimizer(QiskitOptimizationTestCase):
         grover_optimizer = self._prepare_grover_optimizer(
             num_value_qubits=6, num_iterations=self.n_iter, simulator=simulator
         )
-        results = grover_optimizer.solve(op)
+        if simulator == "sampler":
+            results = grover_optimizer.solve(op)
+        else:
+            with self.assertWarns(DeprecationWarning):
+                results = grover_optimizer.solve(op)
         self.validate_results(op, results)
 
     @data("statevector", "qasm", "sampler")
@@ -201,7 +218,11 @@ class TestGroverOptimizer(QiskitOptimizationTestCase):
         grover_optimizer = self._prepare_grover_optimizer(
             num_value_qubits=4, num_iterations=self.n_iter, simulator=simulator
         )
-        results = grover_optimizer.solve(op)
+        if simulator == "sampler":
+            results = grover_optimizer.solve(op)
+        else:
+            with self.assertWarns(DeprecationWarning):
+                results = grover_optimizer.solve(op)
         self.validate_results(op, results)
 
         # a list of converters
@@ -239,7 +260,11 @@ class TestGroverOptimizer(QiskitOptimizationTestCase):
         )
         opt_sol = 1
         success = OptimizationResultStatus.SUCCESS
-        results = grover_optimizer.solve(op)
+        if simulator == "sampler":
+            results = grover_optimizer.solve(op)
+        else:
+            with self.assertWarns(DeprecationWarning):
+                results = grover_optimizer.solve(op)
         self.assertEqual(len(results.samples), 8)
         self.assertEqual(len(results.raw_samples), 32)
         self.assertAlmostEqual(sum(s.probability for s in results.samples), 1)
@@ -271,7 +296,11 @@ class TestGroverOptimizer(QiskitOptimizationTestCase):
         grover_optimizer = self._prepare_grover_optimizer(
             num_value_qubits=3, num_iterations=self.n_iter, simulator=simulator
         )
-        results = grover_optimizer.solve(op)
+        if simulator == "sampler":
+            results = grover_optimizer.solve(op)
+        else:
+            with self.assertWarns(DeprecationWarning):
+                results = grover_optimizer.solve(op)
         self.assertEqual(results.fval, opt_sol)
         np.testing.assert_array_almost_equal(results.x, [0, 1])
         self.assertEqual(results.status, success)
diff --git a/test/algorithms/test_min_eigen_optimizer.py b/test/algorithms/test_min_eigen_optimizer.py
index e404b25..42fb0b1 100644
--- a/test/algorithms/test_min_eigen_optimizer.py
+++ b/test/algorithms/test_min_eigen_optimizer.py
@@ -18,7 +18,7 @@ from test.runtime.fake_vqeruntime import FakeQAOARuntimeProvider, FakeVQERuntime
 
 import numpy as np
 from ddt import data, ddt, unpack
-from qiskit.algorithms.minimum_eigensolvers import QAOA, NumPyMinimumEigensolver, SamplingVQE, VQE
+from qiskit.algorithms.minimum_eigensolvers import QAOA, VQE, NumPyMinimumEigensolver, SamplingVQE
 from qiskit.algorithms.optimizers import COBYLA, SPSA
 from qiskit.circuit.library import TwoLocal
 from qiskit.primitives import Estimator, Sampler
@@ -370,7 +370,8 @@ class TestMinEigenOptimizer(QiskitOptimizationTestCase):
             )
 
         opt = MinimumEigenOptimizer(solver)
-        result = opt.solve(self.op_ordering)
+        with self.assertWarns(DeprecationWarning):
+            result = opt.solve(self.op_ordering)
         self.assertIsInstance(result, MinimumEigenOptimizationResult)
 
     @data(FakeArmonk, FakeArmonkV2)
@@ -384,7 +385,8 @@ class TestMinEigenOptimizer(QiskitOptimizationTestCase):
 
         solver = VQEClient(ansatz, optimizer, initial_point, provider, backend)
         opt = MinimumEigenOptimizer(solver)
-        result = opt.solve(self.op_ordering)
+        with self.assertWarns(DeprecationWarning):
+            result = opt.solve(self.op_ordering)
         self.assertIsInstance(result, MinimumEigenOptimizationResult)
 
 
diff --git a/test/converters/test_converters.py b/test/converters/test_converters.py
index d651977..92e0f1c 100644
--- a/test/converters/test_converters.py
+++ b/test/converters/test_converters.py
@@ -18,7 +18,7 @@ from test.optimization_test_case import QiskitOptimizationTestCase
 import numpy as np
 from docplex.mp.model import Model
 from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver
-from qiskit.opflow import I, Z
+from qiskit.quantum_info import SparsePauliOp
 
 import qiskit_optimization.optionals as _optionals
 from qiskit_optimization import QiskitOptimizationError, QuadraticProgram
@@ -33,17 +33,19 @@ from qiskit_optimization.converters import (
 from qiskit_optimization.problems import Constraint, Variable
 from qiskit_optimization.translators import from_docplex_mp
 
-QUBIT_OP_MAXIMIZE_SAMPLE = (
-    -199999.5 * (I ^ I ^ I ^ Z)
-    + -399999.5 * (I ^ I ^ Z ^ I)
-    + -599999.5 * (I ^ Z ^ I ^ I)
-    + -799999.5 * (Z ^ I ^ I ^ I)
-    + 100000 * (I ^ I ^ Z ^ Z)
-    + 150000 * (I ^ Z ^ I ^ Z)
-    + 300000 * (I ^ Z ^ Z ^ I)
-    + 200000 * (Z ^ I ^ I ^ Z)
-    + 400000 * (Z ^ I ^ Z ^ I)
-    + 600000 * (Z ^ Z ^ I ^ I)
+QUBIT_OP_MAXIMIZE_SAMPLE = SparsePauliOp.from_list(
+    [
+        ("IIIZ", -199999.5),
+        ("IIZI", -399999.5),
+        ("IZII", -599999.5),
+        ("ZIII", -799999.5),
+        ("IIZZ", 100000),
+        ("IZIZ", 150000),
+        ("IZZI", 300000),
+        ("ZIIZ", 200000),
+        ("ZIZI", 400000),
+        ("ZZII", 600000),
+    ]
 )
 OFFSET_MAXIMIZE_SAMPLE = 1149998
 
@@ -397,7 +399,7 @@ class TestConverters(QiskitOptimizationTestCase):
         op.linear_constraint(linear, Constraint.Sense.EQ, 3, "sum1")
         penalize = LinearEqualityToPenalty(penalty=1e5)
         op2 = penalize.convert(op)
-        qubitop, offset = op2.to_ising(opflow=True)
+        qubitop, offset = op2.to_ising(opflow=False)
         self.assertEqual(qubitop, QUBIT_OP_MAXIMIZE_SAMPLE)
         self.assertEqual(offset, OFFSET_MAXIMIZE_SAMPLE)
 
diff --git a/test/problems/test_quadratic_program.py b/test/problems/test_quadratic_program.py
index 4f0e49c..f706618 100644
--- a/test/problems/test_quadratic_program.py
+++ b/test/problems/test_quadratic_program.py
@@ -1,6 +1,6 @@
 # This code is part of Qiskit.
 #
-# (C) Copyright IBM 2020, 2022.
+# (C) Copyright IBM 2020, 2023.
 #
 # This code is licensed under the Apache License, Version 2.0. You may
 # obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -18,7 +18,7 @@ from os import path
 from test.optimization_test_case import QiskitOptimizationTestCase
 
 from docplex.mp.model import DOcplexException
-from qiskit.opflow import PauliSumOp
+from qiskit.quantum_info import SparsePauliOp
 
 import qiskit_optimization.optionals as _optionals
 from qiskit_optimization import INFINITY, QiskitOptimizationError, QuadraticProgram
@@ -1003,7 +1003,7 @@ class TestQuadraticProgram(QiskitOptimizationTestCase):
         """Test QuadraticProgramElement when QuadraticProgram is loaded from an external source"""
         with self.subTest("from_ising"):
             q_p = QuadraticProgram()
-            q_p.from_ising(PauliSumOp.from_list([("IZ", 1), ("ZZ", 2)]))
+            q_p.from_ising(SparsePauliOp.from_list([("IZ", 1), ("ZZ", 2)]))
             self.assertEqual(id(q_p.objective.quadratic_program), id(q_p))
             for elem in q_p.variables:
                 self.assertEqual(id(elem.quadratic_program), id(q_p))
diff --git a/test/translators/test_ising.py b/test/translators/test_ising.py
index f9652a1..14d68ef 100644
--- a/test/translators/test_ising.py
+++ b/test/translators/test_ising.py
@@ -12,6 +12,7 @@
 
 """Test from_ising and to_ising"""
 
+from contextlib import nullcontext
 from test.optimization_test_case import QiskitOptimizationTestCase
 
 import numpy as np
@@ -29,15 +30,22 @@ from qiskit_optimization.translators import from_ising, to_ising
 class TestIsingTranslator(QiskitOptimizationTestCase):
     """Test from_ising and to_ising"""
 
-    @staticmethod
-    def op_from_list(lst, opflow):
+    def op_from_list(self, lst, opflow):
         """generate an operator from a list"""
         if opflow:
-            return PauliSumOp.from_list(lst)
+            with self.assertWarns(DeprecationWarning):
+                return PauliSumOp.from_list(lst)
         else:
             return SparsePauliOp.from_list(lst)
 
-    @data(True, False)
+    def assert_deprecation_warning(self, opflow: bool):
+        """assert deprecation warning if opflow is used"""
+        if opflow:
+            return self.assertWarns(DeprecationWarning)
+        else:
+            return nullcontext()
+
+    @data(True, False, None)
     def test_to_ising(self, opflow):
         """test to_ising"""
 
@@ -48,8 +56,12 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
             q_p.binary_var(name="x")
             q_p.binary_var(name="y")
             q_p.minimize(linear={"x": 1}, quadratic={("x", "y"): 1})
-            op, offset = to_ising(q_p, opflow)
-            self.assertIsInstance(op, OperatorBase if opflow else BaseOperator)
+            with self.assert_deprecation_warning(opflow in [None, True]):
+                op, offset = to_ising(q_p, opflow)
+            if opflow in [None, True]:
+                self.assertIsInstance(op, OperatorBase)
+            else:
+                self.assertIsInstance(op, BaseOperator)
             op_ref = SparsePauliOp.from_list([("ZI", -0.25), ("IZ", -0.75), ("ZZ", 0.25)])
             np.testing.assert_allclose(op.to_matrix(), op_ref.to_matrix())
             self.assertAlmostEqual(offset, 0.75)
@@ -61,13 +73,17 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
             q_p.binary_var(name="x")
             q_p.binary_var(name="y")
             q_p.maximize(linear={"x": 1}, quadratic={("x", "y"): 1})
-            op, offset = to_ising(q_p, opflow)
-            self.assertIsInstance(op, OperatorBase if opflow else BaseOperator)
+            with self.assert_deprecation_warning(opflow in [None, True]):
+                op, offset = to_ising(q_p, opflow)
+            if opflow in [None, True]:
+                self.assertIsInstance(op, OperatorBase)
+            else:
+                self.assertIsInstance(op, BaseOperator)
             op_ref = SparsePauliOp.from_list([("ZI", 0.25), ("IZ", 0.75), ("ZZ", -0.25)])
             np.testing.assert_allclose(op.to_matrix(), op_ref.to_matrix())
             self.assertAlmostEqual(offset, -0.75)
 
-    @data(True, False)
+    @data(True, False, None)
     def test_to_ising2(self, opflow):
         """test to_ising 2"""
 
@@ -78,8 +94,12 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
             q_p.binary_var(name="x")
             q_p.binary_var(name="y")
             q_p.minimize(constant=1, linear={"x": -2, "y": -2}, quadratic={("x", "y"): 4})
-            op, offset = to_ising(q_p, opflow)
-            self.assertIsInstance(op, OperatorBase if opflow else BaseOperator)
+            with self.assert_deprecation_warning(opflow in [None, True]):
+                op, offset = to_ising(q_p, opflow)
+            if opflow in [None, True]:
+                self.assertIsInstance(op, OperatorBase)
+            else:
+                self.assertIsInstance(op, BaseOperator)
             op_ref = SparsePauliOp.from_list([("ZZ", 1.0)])
             np.testing.assert_allclose(op.to_matrix(), op_ref.to_matrix())
             self.assertAlmostEqual(offset, 0.0)
@@ -91,8 +111,12 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
             q_p.binary_var(name="x")
             q_p.binary_var(name="y")
             q_p.maximize(constant=1, linear={"x": -2, "y": -2}, quadratic={("x", "y"): 4})
-            op, offset = to_ising(q_p, opflow)
-            self.assertIsInstance(op, OperatorBase if opflow else BaseOperator)
+            with self.assert_deprecation_warning(opflow in [None, True]):
+                op, offset = to_ising(q_p, opflow)
+            if opflow in [None, True]:
+                self.assertIsInstance(op, OperatorBase)
+            else:
+                self.assertIsInstance(op, BaseOperator)
             op_ref = SparsePauliOp.from_list([("ZZ", -1.0)])
             np.testing.assert_allclose(op.to_matrix(), op_ref.to_matrix())
             self.assertAlmostEqual(offset, 0.0)
@@ -104,7 +128,8 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
         # subject to: x, y \in {0, 1}
         op = self.op_from_list([("ZI", -0.25), ("IZ", -0.75), ("ZZ", 0.25)], opflow)
         with self.subTest("linear: True"):
-            q_p = from_ising(op, 0.75, linear=True)
+            with self.assert_deprecation_warning(opflow):
+                q_p = from_ising(op, 0.75, linear=True)
             self.assertEqual(q_p.get_num_vars(), op.num_qubits)
             self.assertEqual(q_p.get_num_linear_constraints(), 0)
             self.assertEqual(q_p.get_num_quadratic_constraints(), 0)
@@ -113,7 +138,8 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
             np.testing.assert_allclose(q_p.objective.quadratic.to_array(), [[0, 1], [0, 0]])
 
         with self.subTest("linear: False"):
-            q_p = from_ising(op, 0.75, linear=False)
+            with self.assert_deprecation_warning(opflow):
+                q_p = from_ising(op, 0.75, linear=False)
             self.assertEqual(q_p.get_num_vars(), op.num_qubits)
             self.assertEqual(q_p.get_num_linear_constraints(), 0)
             self.assertEqual(q_p.get_num_quadratic_constraints(), 0)
@@ -128,7 +154,8 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
         # subject to: x, y \in {0, 1}
         op = self.op_from_list([("ZZ", 1)], opflow)
         with self.subTest("linear: True"):
-            q_p = from_ising(op, 0, linear=True)
+            with self.assert_deprecation_warning(opflow):
+                q_p = from_ising(op, 0, linear=True)
             self.assertEqual(q_p.get_num_vars(), op.num_qubits)
             self.assertEqual(q_p.get_num_linear_constraints(), 0)
             self.assertEqual(q_p.get_num_quadratic_constraints(), 0)
@@ -137,7 +164,8 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
             np.testing.assert_allclose(q_p.objective.quadratic.to_array(), [[0, 4], [0, 0]])
 
         with self.subTest("linear: False"):
-            q_p = from_ising(op, 0, linear=False)
+            with self.assert_deprecation_warning(opflow):
+                q_p = from_ising(op, 0, linear=False)
             self.assertEqual(q_p.get_num_vars(), op.num_qubits)
             self.assertEqual(q_p.get_num_linear_constraints(), 0)
             self.assertEqual(q_p.get_num_quadratic_constraints(), 0)
@@ -150,28 +178,31 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
         """test from_ising with invalid Pauli terms"""
         with self.assertRaises(QiskitOptimizationError):
             op = self.op_from_list([("IX", 1)], opflow)
-            _ = from_ising(op, 0)
+            with self.assert_deprecation_warning(opflow):
+                _ = from_ising(op, 0)
 
         with self.assertRaises(QiskitOptimizationError):
             op = self.op_from_list([("IY", 1)], opflow)
-            _ = from_ising(op, 0)
+            with self.assert_deprecation_warning(opflow):
+                _ = from_ising(op, 0)
 
         with self.assertRaises(QiskitOptimizationError):
             op = self.op_from_list([("ZZZ", 1)], opflow)
-            _ = from_ising(op, 0)
+            with self.assert_deprecation_warning(opflow):
+                _ = from_ising(op, 0)
 
         with self.assertRaises(QiskitOptimizationError):
             op = self.op_from_list([("IZ", 1j)], opflow)
-            _ = from_ising(op, 0)
+            with self.assert_deprecation_warning(opflow):
+                _ = from_ising(op, 0)
 
     @data(True, False)
     def test_pauli_I_Z(self, opflow):
         """test from_ising and to_ising with Pauli I and Z"""
         with self.subTest("0 * I, linear=False"):
-            if opflow:
-                q_p = from_ising(SparsePauliOp("I", 0), linear=False)
-            else:
-                q_p = from_ising(0 * I, linear=False)
+            with self.assert_deprecation_warning(opflow):
+                operator = 0 * I if opflow else SparsePauliOp("I", 0)
+                q_p = from_ising(operator, linear=False)
             self.assertEqual(q_p.get_num_vars(), 1)
             self.assertEqual(q_p.get_num_linear_constraints(), 0)
             self.assertEqual(q_p.get_num_quadratic_constraints(), 0)
@@ -179,15 +210,15 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
             np.testing.assert_allclose(q_p.objective.linear.to_array(), [0])
             np.testing.assert_allclose(q_p.objective.quadratic.to_array(), [[0]])
 
-            op, offset = to_ising(q_p, opflow=True)
+            with self.assert_deprecation_warning(opflow):
+                op, offset = to_ising(q_p, opflow=opflow)
             np.testing.assert_allclose(op.to_matrix(), np.zeros((2, 2)))
             self.assertAlmostEqual(offset, 0)
 
         with self.subTest("0 * I, linear=True"):
-            if opflow:
-                q_p = from_ising(SparsePauliOp("I", 0), linear=True)
-            else:
-                q_p = from_ising(0 * I, linear=True)
+            with self.assert_deprecation_warning(opflow):
+                operator = 0 * I if opflow else SparsePauliOp("I", 0)
+                q_p = from_ising(operator, linear=True)
             self.assertEqual(q_p.get_num_vars(), 1)
             self.assertEqual(q_p.get_num_linear_constraints(), 0)
             self.assertEqual(q_p.get_num_quadratic_constraints(), 0)
@@ -195,15 +226,15 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
             np.testing.assert_allclose(q_p.objective.linear.to_array(), [0])
             np.testing.assert_allclose(q_p.objective.quadratic.to_array(), [[0]])
 
-            op, offset = to_ising(q_p, opflow=True)
+            with self.assert_deprecation_warning(opflow):
+                op, offset = to_ising(q_p, opflow=opflow)
             np.testing.assert_allclose(op.to_matrix(), np.zeros((2, 2)))
             self.assertAlmostEqual(offset, 0)
 
         with self.subTest("2 * I, linear=False"):
-            if opflow:
-                q_p = from_ising(SparsePauliOp("I", 2), linear=False)
-            else:
-                q_p = from_ising(2 * I, linear=False)
+            with self.assert_deprecation_warning(opflow):
+                operator = 2 * I if opflow else SparsePauliOp("I", 2)
+                q_p = from_ising(operator, linear=False)
             self.assertEqual(q_p.get_num_vars(), 1)
             self.assertEqual(q_p.get_num_linear_constraints(), 0)
             self.assertEqual(q_p.get_num_quadratic_constraints(), 0)
@@ -211,15 +242,15 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
             np.testing.assert_allclose(q_p.objective.linear.to_array(), [0])
             np.testing.assert_allclose(q_p.objective.quadratic.to_array(), [[0]])
 
-            op, offset = to_ising(q_p, opflow=True)
+            with self.assert_deprecation_warning(opflow):
+                op, offset = to_ising(q_p, opflow=opflow)
             np.testing.assert_allclose(op.to_matrix(), np.zeros((2, 2)))
             self.assertAlmostEqual(offset, 2)
 
         with self.subTest("2 * I, linear=True"):
-            if opflow:
-                q_p = from_ising(SparsePauliOp("I", 2), linear=True)
-            else:
-                q_p = from_ising(2 * I, linear=True)
+            with self.assert_deprecation_warning(opflow):
+                operator = 2 * I if opflow else SparsePauliOp("I", 2)
+                q_p = from_ising(operator, linear=True)
             self.assertEqual(q_p.get_num_vars(), 1)
             self.assertEqual(q_p.get_num_linear_constraints(), 0)
             self.assertEqual(q_p.get_num_quadratic_constraints(), 0)
@@ -227,15 +258,15 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
             np.testing.assert_allclose(q_p.objective.linear.to_array(), [0])
             np.testing.assert_allclose(q_p.objective.quadratic.to_array(), [[0]])
 
-            op, offset = to_ising(q_p, opflow=True)
+            with self.assert_deprecation_warning(opflow):
+                op, offset = to_ising(q_p, opflow=opflow)
             np.testing.assert_allclose(op.to_matrix(), np.zeros((2, 2)))
             self.assertAlmostEqual(offset, 2)
 
         with self.subTest("Z, linear=False"):
-            if opflow:
-                q_p = from_ising(Pauli("Z"), linear=False)
-            else:
-                q_p = from_ising(Z, linear=False)
+            with self.assert_deprecation_warning(opflow):
+                operator = Z if opflow else Pauli("Z")
+                q_p = from_ising(operator, linear=False)
             self.assertEqual(q_p.get_num_vars(), 1)
             self.assertEqual(q_p.get_num_linear_constraints(), 0)
             self.assertEqual(q_p.get_num_quadratic_constraints(), 0)
@@ -243,15 +274,15 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
             np.testing.assert_allclose(q_p.objective.linear.to_array(), [0])
             np.testing.assert_allclose(q_p.objective.quadratic.to_array(), [[-2]])
 
-            op, offset = to_ising(q_p, opflow=True)
-            np.testing.assert_allclose(op.to_matrix(), Z.to_matrix())
+            with self.assert_deprecation_warning(opflow):
+                op, offset = to_ising(q_p, opflow=opflow)
+            np.testing.assert_allclose(op.to_matrix(), operator.to_matrix())
             self.assertAlmostEqual(offset, 0)
 
         with self.subTest("Z, linear=True"):
-            if opflow:
-                q_p = from_ising(Pauli("Z"), linear=True)
-            else:
-                q_p = from_ising(Z, linear=True)
+            with self.assert_deprecation_warning(opflow):
+                operator = Z if opflow else Pauli("Z")
+                q_p = from_ising(operator, linear=True)
             self.assertEqual(q_p.get_num_vars(), 1)
             self.assertEqual(q_p.get_num_linear_constraints(), 0)
             self.assertEqual(q_p.get_num_quadratic_constraints(), 0)
@@ -259,15 +290,15 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
             np.testing.assert_allclose(q_p.objective.linear.to_array(), [-2])
             np.testing.assert_allclose(q_p.objective.quadratic.to_array(), [[0]])
 
-            op, offset = to_ising(q_p, opflow=True)
-            np.testing.assert_allclose(op.to_matrix(), Z.to_matrix())
+            with self.assert_deprecation_warning(opflow):
+                op, offset = to_ising(q_p, opflow=opflow)
+            np.testing.assert_allclose(op.to_matrix(), operator.to_matrix())
             self.assertAlmostEqual(offset, 0)
 
         with self.subTest("3 * II, linear=False"):
-            if opflow:
-                q_p = from_ising(SparsePauliOp("II", 3), linear=False)
-            else:
-                q_p = from_ising(3 * I ^ I, linear=False)
+            with self.assert_deprecation_warning(opflow):
+                operator = 3 * I ^ I if opflow else SparsePauliOp("II", 3)
+                q_p = from_ising(operator, linear=False)
             self.assertEqual(q_p.get_num_vars(), 2)
             self.assertEqual(q_p.get_num_linear_constraints(), 0)
             self.assertEqual(q_p.get_num_quadratic_constraints(), 0)
@@ -275,15 +306,15 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
             np.testing.assert_allclose(q_p.objective.linear.to_array(), [0, 0])
             np.testing.assert_allclose(q_p.objective.quadratic.to_array(), [[0, 0], [0, 0]])
 
-            op, offset = to_ising(q_p, opflow=True)
+            with self.assert_deprecation_warning(opflow):
+                op, offset = to_ising(q_p, opflow=opflow)
             np.testing.assert_allclose(op.to_matrix(), np.zeros((4, 4)))
             self.assertAlmostEqual(offset, 3)
 
         with self.subTest("3 * II, linear=True"):
-            if opflow:
-                q_p = from_ising(SparsePauliOp("II", 3), linear=True)
-            else:
-                q_p = from_ising(3 * I ^ I, linear=True)
+            with self.assert_deprecation_warning(opflow):
+                operator = 3 * I ^ I if opflow else SparsePauliOp("II", 3)
+                q_p = from_ising(operator, linear=True)
             self.assertEqual(q_p.get_num_vars(), 2)
             self.assertEqual(q_p.get_num_linear_constraints(), 0)
             self.assertEqual(q_p.get_num_quadratic_constraints(), 0)
@@ -291,15 +322,15 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
             np.testing.assert_allclose(q_p.objective.linear.to_array(), [0, 0])
             np.testing.assert_allclose(q_p.objective.quadratic.to_array(), [[0, 0], [0, 0]])
 
-            op, offset = to_ising(q_p, opflow=True)
+            with self.assert_deprecation_warning(opflow):
+                op, offset = to_ising(q_p, opflow=opflow)
             np.testing.assert_allclose(op.to_matrix(), np.zeros((4, 4)))
             self.assertAlmostEqual(offset, 3)
 
         with self.subTest("IZ, linear=False"):
-            if opflow:
-                q_p = from_ising(Pauli("IZ"), linear=False)
-            else:
-                q_p = from_ising(I ^ Z, linear=False)
+            with self.assert_deprecation_warning(opflow):
+                operator = I ^ Z if opflow else Pauli("IZ")
+                q_p = from_ising(operator, linear=False)
             self.assertEqual(q_p.get_num_vars(), 2)
             self.assertEqual(q_p.get_num_linear_constraints(), 0)
             self.assertEqual(q_p.get_num_quadratic_constraints(), 0)
@@ -307,15 +338,15 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
             np.testing.assert_allclose(q_p.objective.linear.to_array(), [0, 0])
             np.testing.assert_allclose(q_p.objective.quadratic.to_array(), [[-2, 0], [0, 0]])
 
-            op, offset = to_ising(q_p, opflow=True)
-            np.testing.assert_allclose(op.to_matrix(), (I ^ Z).to_matrix())
+            with self.assert_deprecation_warning(opflow):
+                op, offset = to_ising(q_p, opflow=opflow)
+            np.testing.assert_allclose(op.to_matrix(), operator.to_matrix())
             self.assertAlmostEqual(offset, 0)
 
         with self.subTest("IZ, linear=True"):
-            if opflow:
-                q_p = from_ising(Pauli("IZ"), linear=True)
-            else:
-                q_p = from_ising(I ^ Z, linear=True)
+            with self.assert_deprecation_warning(opflow):
+                operator = I ^ Z if opflow else Pauli("IZ")
+                q_p = from_ising(operator, linear=True)
             self.assertEqual(q_p.get_num_vars(), 2)
             self.assertEqual(q_p.get_num_linear_constraints(), 0)
             self.assertEqual(q_p.get_num_quadratic_constraints(), 0)
@@ -323,8 +354,9 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
             np.testing.assert_allclose(q_p.objective.linear.to_array(), [-2, 0])
             np.testing.assert_allclose(q_p.objective.quadratic.to_array(), [[0, 0], [0, 0]])
 
-            op, offset = to_ising(q_p, opflow=True)
-            np.testing.assert_allclose(op.to_matrix(), (I ^ Z).to_matrix())
+            with self.assert_deprecation_warning(opflow):
+                op, offset = to_ising(q_p, opflow=opflow)
+            np.testing.assert_allclose(op.to_matrix(), operator.to_matrix())
             self.assertAlmostEqual(offset, 0)
 
     @data(True, False)
@@ -332,30 +364,34 @@ class TestIsingTranslator(QiskitOptimizationTestCase):
         """test to_ising with problems without variables"""
         with self.subTest("empty problem"):
             q_p = QuadraticProgram()
-            op, offset = to_ising(q_p, opflow)
+            with self.assert_deprecation_warning(opflow):
+                op, offset = to_ising(q_p, opflow)
             np.testing.assert_allclose(op.to_matrix(), np.zeros((2, 2)))
             self.assertAlmostEqual(offset, 0)
 
         with self.subTest("min 3"):
             q_p = QuadraticProgram()
             q_p.minimize(constant=3)
-            op, offset = to_ising(q_p, opflow)
+            with self.assert_deprecation_warning(opflow):
+                op, offset = to_ising(q_p, opflow)
             np.testing.assert_allclose(op.to_matrix(), np.zeros((2, 2)))
             self.assertAlmostEqual(offset, 3)
 
         with self.subTest("max -1"):
             q_p = QuadraticProgram()
             q_p.maximize(constant=-1)
-            op, offset = to_ising(q_p, opflow)
+            with self.assert_deprecation_warning(opflow):
+                op, offset = to_ising(q_p, opflow)
             np.testing.assert_allclose(op.to_matrix(), np.zeros((2, 2)))
             self.assertAlmostEqual(offset, 1)
 
     def test_warning(self):
         """Test warning message"""
         q_p = QuadraticProgram()
-        with self.assertWarns(UserWarning):
+        with self.assertWarns((UserWarning, DeprecationWarning)):
             _ = to_ising(q_p)
 
-        op = PauliSumOp.from_list([("Z", 1)])
-        with self.assertWarns(PendingDeprecationWarning):
+        with self.assertWarns(DeprecationWarning):
+            op = PauliSumOp.from_list([("Z", 1)])
+        with self.assertWarns(DeprecationWarning):
             _ = from_ising(op)