Skip to content
This repository was archived by the owner on Dec 7, 2021. It is now read-only.

Commit be137b6

Browse files
authored
Fix QFT deprecations in HHL test (#934)
* improve IQFT depr warnings, add filters * fix style
1 parent 5fe97a7 commit be137b6

File tree

3 files changed

+45
-21
lines changed

3 files changed

+45
-21
lines changed

qiskit/aqua/circuits/phase_estimation_circuit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def __init__(
8181

8282
# cannot check for IQFT type due to circular import
8383
if not isinstance(iqft, QuantumCircuit):
84-
warnings.warn('The qiskit.aqua.components.iqfts.IQFT module is deprecated as of 0.7.0 '
84+
warnings.warn('Providing a qiskit.aqua.components.iqfts.IQFT module to the '
85+
'PhaseEstimationCircuit is deprecated as of 0.7.0 '
8586
'and will be removed no earlier than 3 months after the release. '
8687
'You should pass a QuantumCircuit instead, see '
8788
'qiskit.circuit.library.QFT and the .inverse() method.',

qiskit/aqua/components/eigs/eigs_qpe.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ def __init__(self,
7272
self._operator = op_converter.to_weighted_pauli_operator(operator)
7373

7474
if isinstance(iqft, IQFT):
75-
warnings.warn('The qiskit.aqua.components.iqfts.IQFT module is deprecated as of 0.7.0 '
76-
'and will be removed no earlier than 3 months after the release. '
75+
warnings.warn('Providing a qiskit.aqua.components.iqfts.IQFT module as `iqft` argument '
76+
'to HHL is deprecated as of 0.7.0 and will be removed no earlier than '
77+
'3 months after the release. '
7778
'You should pass a QuantumCircuit instead, see '
7879
'qiskit.circuit.library.QFT and the .inverse() method.',
7980
DeprecationWarning, stacklevel=2)
@@ -87,8 +88,9 @@ def __init__(self,
8788
self._negative_evals = negative_evals
8889

8990
if ne_qfts and any(isinstance(ne_qft, IQFT) for ne_qft in ne_qfts):
90-
warnings.warn('The qiskit.aqua.components.iqfts.IQFT module is deprecated as of 0.7.0 '
91-
'and will be removed no earlier than 3 months after the release. '
91+
warnings.warn('Providing a qiskit.aqua.components.iqfts.IQFT module in the `ne_qft` '
92+
'argument to HHL is deprecated as of 0.7.0 and will be removed no '
93+
'earlier than 3 months after the release. '
9294
'You should pass a QuantumCircuit instead, see '
9395
'qiskit.circuit.library.QFT and the .inverse() method.',
9496
DeprecationWarning, stacklevel=2)
@@ -125,7 +127,7 @@ def get_scaling(self):
125127
return self._evo_time
126128

127129
def construct_circuit(self, mode, register=None):
128-
""" Construct the eigenvalues estimation using the PhaseEstimationCircuit
130+
"""Construct the eigenvalues estimation using the PhaseEstimationCircuit
129131
130132
Args:
131133
mode (str): construction mode, 'matrix' not supported

test/aqua/test_hhl.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def tearDown(self):
5353
def _create_eigs(matrix, num_ancillae, negative_evals, use_circuit_library=True):
5454
# Adding an additional flag qubit for negative eigenvalues
5555
ne_qfts = [None, None]
56+
if not use_circuit_library:
57+
warnings.filterwarnings('ignore', category=DeprecationWarning)
58+
5659
if negative_evals:
5760
num_ancillae += 1
5861
if use_circuit_library:
@@ -65,25 +68,27 @@ def _create_eigs(matrix, num_ancillae, negative_evals, use_circuit_library=True)
6568
else:
6669
iqft = StandardIQFTS(num_ancillae)
6770

68-
return EigsQPE(MatrixOperator(matrix=matrix),
69-
iqft,
70-
num_time_slices=1,
71-
num_ancillae=num_ancillae,
72-
expansion_mode='suzuki',
73-
expansion_order=2,
74-
evo_time=None,
75-
negative_evals=negative_evals,
76-
ne_qfts=ne_qfts)
71+
eigs_qpe = EigsQPE(MatrixOperator(matrix=matrix),
72+
iqft,
73+
num_time_slices=1,
74+
num_ancillae=num_ancillae,
75+
expansion_mode='suzuki',
76+
expansion_order=2,
77+
evo_time=None,
78+
negative_evals=negative_evals,
79+
ne_qfts=ne_qfts)
80+
81+
if not use_circuit_library:
82+
warnings.filterwarnings('always', category=DeprecationWarning)
83+
84+
return eigs_qpe
7785

7886
@data([[0, 1], False], [[1, 0], False], [[1, 0.1], False], [[1, 1], False], [[1, 10], False],
7987
[[0, 1], True], [[1, 0], True], [[1, 0.1], True], [[1, 1], True], [[1, 10], True])
8088
@unpack
8189
def test_hhl_diagonal(self, vector, use_circuit_library):
8290
""" hhl diagonal test """
8391
self.log.debug('Testing HHL simple test in mode Lookup with statevector simulator')
84-
if not use_circuit_library:
85-
# ignore deprecation warnings from QFTs
86-
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
8792

8893
matrix = [[1, 0], [0, 1]]
8994

@@ -108,9 +113,13 @@ def test_hhl_diagonal(self, vector, use_circuit_library):
108113

109114
algo = HHL(matrix, vector, truncate_powerdim, truncate_hermitian, eigs,
110115
init_state, reci, num_q, num_a, orig_size)
116+
if not use_circuit_library:
117+
warnings.filterwarnings('ignore', category=DeprecationWarning)
111118
hhl_result = algo.run(QuantumInstance(BasicAer.get_backend('statevector_simulator'),
112119
seed_simulator=aqua_globals.random_seed,
113120
seed_transpiler=aqua_globals.random_seed))
121+
if not use_circuit_library:
122+
warnings.filterwarnings('always', category=DeprecationWarning)
114123

115124
hhl_solution = hhl_result['solution']
116125
hhl_normed = hhl_solution / np.linalg.norm(hhl_solution)
@@ -124,9 +133,6 @@ def test_hhl_diagonal(self, vector, use_circuit_library):
124133
self.log.debug('fidelity HHL to algebraic: %s', fidelity)
125134
self.log.debug('probability of result: %s', hhl_result["probability_result"])
126135

127-
if not use_circuit_library:
128-
warnings.filterwarnings(action="always", category=DeprecationWarning)
129-
130136
@data([[-1, 0], False], [[0, -1], False], [[-1, -1], False],
131137
[[-1, 0], True], [[0, -1], True], [[-1, -1], True])
132138
@unpack
@@ -157,9 +163,14 @@ def test_hhl_diagonal_negative(self, vector, use_circuit_library):
157163

158164
algo = HHL(matrix, vector, truncate_powerdim, truncate_hermitian, eigs,
159165
init_state, reci, num_q, num_a, orig_size)
166+
if not use_circuit_library:
167+
warnings.filterwarnings('ignore', category=DeprecationWarning)
160168
hhl_result = algo.run(QuantumInstance(BasicAer.get_backend('statevector_simulator'),
161169
seed_simulator=aqua_globals.random_seed,
162170
seed_transpiler=aqua_globals.random_seed))
171+
if not use_circuit_library:
172+
warnings.filterwarnings('always', category=DeprecationWarning)
173+
163174
hhl_solution = hhl_result['solution']
164175
hhl_normed = hhl_solution / np.linalg.norm(hhl_solution)
165176

@@ -201,9 +212,12 @@ def test_hhl_diagonal_longdivison(self, vector):
201212

202213
algo = HHL(matrix, vector, truncate_powerdim, truncate_hermitian, eigs,
203214
init_state, reci, num_q, num_a, orig_size)
215+
warnings.filterwarnings('ignore', category=DeprecationWarning)
204216
hhl_result = algo.run(QuantumInstance(BasicAer.get_backend('statevector_simulator'),
205217
seed_simulator=aqua_globals.random_seed,
206218
seed_transpiler=aqua_globals.random_seed))
219+
warnings.filterwarnings('always', category=DeprecationWarning)
220+
207221
hhl_solution = hhl_result['solution']
208222
hhl_normed = hhl_solution / np.linalg.norm(hhl_solution)
209223

@@ -246,9 +260,11 @@ def test_hhl_diagonal_qasm(self, vector):
246260

247261
algo = HHL(matrix, vector, truncate_powerdim, truncate_hermitian, eigs,
248262
init_state, reci, num_q, num_a, orig_size)
263+
warnings.filterwarnings('ignore', category=DeprecationWarning)
249264
hhl_result = algo.run(QuantumInstance(BasicAer.get_backend('qasm_simulator'), shots=1000,
250265
seed_simulator=aqua_globals.random_seed,
251266
seed_transpiler=aqua_globals.random_seed))
267+
warnings.filterwarnings('always', category=DeprecationWarning)
252268
hhl_solution = hhl_result['solution']
253269
hhl_normed = hhl_solution / np.linalg.norm(hhl_solution)
254270

@@ -339,6 +355,7 @@ def test_hhl_negative_eigs(self):
339355
hhl_result = algo.run(QuantumInstance(BasicAer.get_backend('statevector_simulator'),
340356
seed_simulator=aqua_globals.random_seed,
341357
seed_transpiler=aqua_globals.random_seed))
358+
342359
hhl_solution = hhl_result["solution"]
343360
hhl_normed = hhl_solution / np.linalg.norm(hhl_solution)
344361

@@ -380,9 +397,12 @@ def test_hhl_random_hermitian(self):
380397

381398
algo = HHL(matrix, vector, truncate_powerdim, truncate_hermitian, eigs,
382399
init_state, reci, num_q, num_a, orig_size)
400+
warnings.filterwarnings('ignore', category=DeprecationWarning)
383401
hhl_result = algo.run(QuantumInstance(BasicAer.get_backend('statevector_simulator'),
384402
seed_simulator=aqua_globals.random_seed,
385403
seed_transpiler=aqua_globals.random_seed))
404+
warnings.filterwarnings('always', category=DeprecationWarning)
405+
386406
hhl_solution = hhl_result['solution']
387407
hhl_normed = hhl_solution / np.linalg.norm(hhl_solution)
388408

@@ -426,6 +446,7 @@ def test_hhl_non_hermitian(self):
426446
hhl_result = algo.run(QuantumInstance(BasicAer.get_backend('statevector_simulator'),
427447
seed_simulator=aqua_globals.random_seed,
428448
seed_transpiler=aqua_globals.random_seed))
449+
429450
hhl_solution = hhl_result['solution']
430451
hhl_normed = hhl_solution / np.linalg.norm(hhl_solution)
431452
# compare result

0 commit comments

Comments
 (0)