diff --git a/qiskit/aqua/circuits/phase_estimation_circuit.py b/qiskit/aqua/circuits/phase_estimation_circuit.py index 9be2de1b21..ad1b2507c7 100644 --- a/qiskit/aqua/circuits/phase_estimation_circuit.py +++ b/qiskit/aqua/circuits/phase_estimation_circuit.py @@ -81,7 +81,8 @@ def __init__( # cannot check for IQFT type due to circular import if not isinstance(iqft, QuantumCircuit): - warnings.warn('The qiskit.aqua.components.iqfts.IQFT module is deprecated as of 0.7.0 ' + warnings.warn('Providing a qiskit.aqua.components.iqfts.IQFT module to the ' + 'PhaseEstimationCircuit is deprecated as of 0.7.0 ' 'and will be removed no earlier than 3 months after the release. ' 'You should pass a QuantumCircuit instead, see ' 'qiskit.circuit.library.QFT and the .inverse() method.', diff --git a/qiskit/aqua/components/eigs/eigs_qpe.py b/qiskit/aqua/components/eigs/eigs_qpe.py index 46d76f94e1..cb786176e8 100644 --- a/qiskit/aqua/components/eigs/eigs_qpe.py +++ b/qiskit/aqua/components/eigs/eigs_qpe.py @@ -72,8 +72,9 @@ def __init__(self, self._operator = op_converter.to_weighted_pauli_operator(operator) if isinstance(iqft, IQFT): - warnings.warn('The qiskit.aqua.components.iqfts.IQFT module is deprecated as of 0.7.0 ' - 'and will be removed no earlier than 3 months after the release. ' + warnings.warn('Providing a qiskit.aqua.components.iqfts.IQFT module as `iqft` argument ' + 'to HHL is deprecated as of 0.7.0 and will be removed no earlier than ' + '3 months after the release. ' 'You should pass a QuantumCircuit instead, see ' 'qiskit.circuit.library.QFT and the .inverse() method.', DeprecationWarning, stacklevel=2) @@ -87,8 +88,9 @@ def __init__(self, self._negative_evals = negative_evals if ne_qfts and any(isinstance(ne_qft, IQFT) for ne_qft in ne_qfts): - warnings.warn('The qiskit.aqua.components.iqfts.IQFT module is deprecated as of 0.7.0 ' - 'and will be removed no earlier than 3 months after the release. ' + warnings.warn('Providing a qiskit.aqua.components.iqfts.IQFT module in the `ne_qft` ' + 'argument to HHL is deprecated as of 0.7.0 and will be removed no ' + 'earlier than 3 months after the release. ' 'You should pass a QuantumCircuit instead, see ' 'qiskit.circuit.library.QFT and the .inverse() method.', DeprecationWarning, stacklevel=2) @@ -125,7 +127,7 @@ def get_scaling(self): return self._evo_time def construct_circuit(self, mode, register=None): - """ Construct the eigenvalues estimation using the PhaseEstimationCircuit + """Construct the eigenvalues estimation using the PhaseEstimationCircuit Args: mode (str): construction mode, 'matrix' not supported diff --git a/test/aqua/test_hhl.py b/test/aqua/test_hhl.py index 040b428783..87941c3618 100644 --- a/test/aqua/test_hhl.py +++ b/test/aqua/test_hhl.py @@ -53,6 +53,9 @@ def tearDown(self): def _create_eigs(matrix, num_ancillae, negative_evals, use_circuit_library=True): # Adding an additional flag qubit for negative eigenvalues ne_qfts = [None, None] + if not use_circuit_library: + warnings.filterwarnings('ignore', category=DeprecationWarning) + if negative_evals: num_ancillae += 1 if use_circuit_library: @@ -65,15 +68,20 @@ def _create_eigs(matrix, num_ancillae, negative_evals, use_circuit_library=True) else: iqft = StandardIQFTS(num_ancillae) - return EigsQPE(MatrixOperator(matrix=matrix), - iqft, - num_time_slices=1, - num_ancillae=num_ancillae, - expansion_mode='suzuki', - expansion_order=2, - evo_time=None, - negative_evals=negative_evals, - ne_qfts=ne_qfts) + eigs_qpe = EigsQPE(MatrixOperator(matrix=matrix), + iqft, + num_time_slices=1, + num_ancillae=num_ancillae, + expansion_mode='suzuki', + expansion_order=2, + evo_time=None, + negative_evals=negative_evals, + ne_qfts=ne_qfts) + + if not use_circuit_library: + warnings.filterwarnings('always', category=DeprecationWarning) + + return eigs_qpe @data([[0, 1], False], [[1, 0], False], [[1, 0.1], False], [[1, 1], False], [[1, 10], False], [[0, 1], True], [[1, 0], True], [[1, 0.1], True], [[1, 1], True], [[1, 10], True]) @@ -81,9 +89,6 @@ def _create_eigs(matrix, num_ancillae, negative_evals, use_circuit_library=True) def test_hhl_diagonal(self, vector, use_circuit_library): """ hhl diagonal test """ self.log.debug('Testing HHL simple test in mode Lookup with statevector simulator') - if not use_circuit_library: - # ignore deprecation warnings from QFTs - warnings.filterwarnings(action="ignore", category=DeprecationWarning) matrix = [[1, 0], [0, 1]] @@ -108,9 +113,13 @@ def test_hhl_diagonal(self, vector, use_circuit_library): algo = HHL(matrix, vector, truncate_powerdim, truncate_hermitian, eigs, init_state, reci, num_q, num_a, orig_size) + if not use_circuit_library: + warnings.filterwarnings('ignore', category=DeprecationWarning) hhl_result = algo.run(QuantumInstance(BasicAer.get_backend('statevector_simulator'), seed_simulator=aqua_globals.random_seed, seed_transpiler=aqua_globals.random_seed)) + if not use_circuit_library: + warnings.filterwarnings('always', category=DeprecationWarning) hhl_solution = hhl_result['solution'] hhl_normed = hhl_solution / np.linalg.norm(hhl_solution) @@ -124,9 +133,6 @@ def test_hhl_diagonal(self, vector, use_circuit_library): self.log.debug('fidelity HHL to algebraic: %s', fidelity) self.log.debug('probability of result: %s', hhl_result["probability_result"]) - if not use_circuit_library: - warnings.filterwarnings(action="always", category=DeprecationWarning) - @data([[-1, 0], False], [[0, -1], False], [[-1, -1], False], [[-1, 0], True], [[0, -1], True], [[-1, -1], True]) @unpack @@ -157,9 +163,14 @@ def test_hhl_diagonal_negative(self, vector, use_circuit_library): algo = HHL(matrix, vector, truncate_powerdim, truncate_hermitian, eigs, init_state, reci, num_q, num_a, orig_size) + if not use_circuit_library: + warnings.filterwarnings('ignore', category=DeprecationWarning) hhl_result = algo.run(QuantumInstance(BasicAer.get_backend('statevector_simulator'), seed_simulator=aqua_globals.random_seed, seed_transpiler=aqua_globals.random_seed)) + if not use_circuit_library: + warnings.filterwarnings('always', category=DeprecationWarning) + hhl_solution = hhl_result['solution'] hhl_normed = hhl_solution / np.linalg.norm(hhl_solution) @@ -201,9 +212,12 @@ def test_hhl_diagonal_longdivison(self, vector): algo = HHL(matrix, vector, truncate_powerdim, truncate_hermitian, eigs, init_state, reci, num_q, num_a, orig_size) + warnings.filterwarnings('ignore', category=DeprecationWarning) hhl_result = algo.run(QuantumInstance(BasicAer.get_backend('statevector_simulator'), seed_simulator=aqua_globals.random_seed, seed_transpiler=aqua_globals.random_seed)) + warnings.filterwarnings('always', category=DeprecationWarning) + hhl_solution = hhl_result['solution'] hhl_normed = hhl_solution / np.linalg.norm(hhl_solution) @@ -246,9 +260,11 @@ def test_hhl_diagonal_qasm(self, vector): algo = HHL(matrix, vector, truncate_powerdim, truncate_hermitian, eigs, init_state, reci, num_q, num_a, orig_size) + warnings.filterwarnings('ignore', category=DeprecationWarning) hhl_result = algo.run(QuantumInstance(BasicAer.get_backend('qasm_simulator'), shots=1000, seed_simulator=aqua_globals.random_seed, seed_transpiler=aqua_globals.random_seed)) + warnings.filterwarnings('always', category=DeprecationWarning) hhl_solution = hhl_result['solution'] hhl_normed = hhl_solution / np.linalg.norm(hhl_solution) @@ -339,6 +355,7 @@ def test_hhl_negative_eigs(self): hhl_result = algo.run(QuantumInstance(BasicAer.get_backend('statevector_simulator'), seed_simulator=aqua_globals.random_seed, seed_transpiler=aqua_globals.random_seed)) + hhl_solution = hhl_result["solution"] hhl_normed = hhl_solution / np.linalg.norm(hhl_solution) @@ -380,9 +397,12 @@ def test_hhl_random_hermitian(self): algo = HHL(matrix, vector, truncate_powerdim, truncate_hermitian, eigs, init_state, reci, num_q, num_a, orig_size) + warnings.filterwarnings('ignore', category=DeprecationWarning) hhl_result = algo.run(QuantumInstance(BasicAer.get_backend('statevector_simulator'), seed_simulator=aqua_globals.random_seed, seed_transpiler=aqua_globals.random_seed)) + warnings.filterwarnings('always', category=DeprecationWarning) + hhl_solution = hhl_result['solution'] hhl_normed = hhl_solution / np.linalg.norm(hhl_solution) @@ -426,6 +446,7 @@ def test_hhl_non_hermitian(self): hhl_result = algo.run(QuantumInstance(BasicAer.get_backend('statevector_simulator'), seed_simulator=aqua_globals.random_seed, seed_transpiler=aqua_globals.random_seed)) + hhl_solution = hhl_result['solution'] hhl_normed = hhl_solution / np.linalg.norm(hhl_solution) # compare result