Skip to content

Commit

Permalink
suppress opflow deprecation of a legacy test
Browse files Browse the repository at this point in the history
  • Loading branch information
t-imamichi committed Apr 26, 2023
1 parent b5870a6 commit 078ab0b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion qiskit_optimization/algorithms/grover_optimizer.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion qiskit_optimization/algorithms/optimization_algorithm.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 4 additions & 1 deletion qiskit_optimization/runtime/vqe_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""The Qiskit Optimization VQE Runtime Client."""


import warnings
from typing import Any, Callable, Dict, List, Optional, Union

import numpy as np
Expand Down Expand Up @@ -79,7 +80,9 @@ def __init__(
"here: https://qisk.it/algo_migration#vqe"
),
)
super().__init__()
with warnings.catch_warnings():
warnings.simplefilter("ignore")
super().__init__()
if optimizer is None:
optimizer = SPSA(maxiter=300)

Expand Down
36 changes: 20 additions & 16 deletions test/algorithms/legacy/test_min_eigen_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ def test_min_eigen_optimizer(self, config):
# 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)
Expand Down Expand Up @@ -379,26 +380,29 @@ def test_runtime(self, subroutine):
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)


Expand Down
2 changes: 1 addition & 1 deletion test/algorithms/test_grover_optimizer.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/problems/test_quadratic_program.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 078ab0b

Please sign in to comment.