From 80a05f74c1617d58596b1a11c1d9de9d155ae365 Mon Sep 17 00:00:00 2001 From: Shion Fukuzawa Date: Thu, 30 Mar 2023 14:59:32 -0700 Subject: [PATCH 1/4] Fixed IQAE bug mentioned in issue 9280 --- qiskit/algorithms/phase_estimators/ipe.py | 2 +- ...se-estimation-bugfix-b676ffc23cea8251.yaml | 4 +++ .../python/algorithms/test_phase_estimator.py | 30 ++++++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml diff --git a/qiskit/algorithms/phase_estimators/ipe.py b/qiskit/algorithms/phase_estimators/ipe.py index 17f5312ebb5e..9d2f6e1417ca 100644 --- a/qiskit/algorithms/phase_estimators/ipe.py +++ b/qiskit/algorithms/phase_estimators/ipe.py @@ -118,7 +118,7 @@ def construct_circuit( # For example, it may be desirable to compute the power via Trotterization, if # we are doing Trotterization anyway. unitary_power = unitary.power(2 ** (k - 1)).control() - qc = qc.compose(unitary_power, list(range(1, unitary.num_qubits + 1)) + [0]) + qc = qc.compose(unitary_power, [unitary.num_qubits] + list(range(0, unitary.num_qubits))) qc.p(omega, phase_register[0]) # hadamard on phase_register[0] qc.h(phase_register[0]) diff --git a/releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml b/releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml new file mode 100644 index 000000000000..ada7126be175 --- /dev/null +++ b/releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + Fixed a bug where the iterative phase estimation algorithm was generating the wrong circuit, causing the algorithm to fail for simple cases. Refer to `#9280 https://github.com/Qiskit/qiskit-terra/issues/9280` for more details. \ No newline at end of file diff --git a/test/python/algorithms/test_phase_estimator.py b/test/python/algorithms/test_phase_estimator.py index 3386bd5c1b87..a061acf4f974 100644 --- a/test/python/algorithms/test_phase_estimator.py +++ b/test/python/algorithms/test_phase_estimator.py @@ -28,7 +28,18 @@ ) import qiskit from qiskit import QuantumCircuit -from qiskit.opflow import H, X, Y, Z, I, StateFn, PauliTrotterEvolution, MatrixEvolution, PauliSumOp +from qiskit.opflow import ( + H, + X, + Y, + Z, + I, + T, + StateFn, + PauliTrotterEvolution, + MatrixEvolution, + PauliSumOp, +) from qiskit.test import slow_test @@ -515,6 +526,23 @@ def test_qpe_RZ_sampler(self, state_preparation, expected_phase, phase_estimator ) self.assertEqual(phase, expected_phase) + @data( + ((X ^ X).to_circuit(), 0.25, IterativePhaseEstimation), + ((I ^ X).to_circuit(), 0.125, IterativePhaseEstimation), + ((X ^ X).to_circuit(), 0.25, PhaseEstimation), + ((I ^ X).to_circuit(), 0.125, PhaseEstimation), + ) + @unpack + def test_qpe_two_qubit_unitary(self, state_preparation, expected_phase, phase_estimator): + """two qubit unitary T ^ T""" + unitary_circuit = (T ^ T).to_circuit() + phase = self.one_phase_sampler( + unitary_circuit, + state_preparation, + phase_estimator, + ) + self.assertEqual(phase, expected_phase) + def test_check_num_iterations_sampler(self): """test check for num_iterations greater than zero""" unitary_circuit = QuantumCircuit(1).compose(XGate()) From c1c68fda1e9b1bcae4010c180d60e175b6f45677 Mon Sep 17 00:00:00 2001 From: Shion Fukuzawa Date: Sun, 2 Apr 2023 11:11:56 +0900 Subject: [PATCH 2/4] Update releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml Co-authored-by: Julien Gacon --- .../iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml b/releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml index ada7126be175..78829444dfc7 100644 --- a/releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml +++ b/releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml @@ -1,4 +1,5 @@ --- fixes: - | - Fixed a bug where the iterative phase estimation algorithm was generating the wrong circuit, causing the algorithm to fail for simple cases. Refer to `#9280 https://github.com/Qiskit/qiskit-terra/issues/9280` for more details. \ No newline at end of file + Fixed a bug where :class:`.IterativePhaseEstimation` was generating the wrong circuit, causing the + algorithm to fail for simple cases. Fixed `#9280 https://github.com/Qiskit/qiskit-terra/issues/9280`__. \ No newline at end of file From 95bc2569bc1bb67d80bba494dd776ab2f926b4a2 Mon Sep 17 00:00:00 2001 From: Shion Fukuzawa Date: Sun, 2 Apr 2023 09:17:36 -0700 Subject: [PATCH 3/4] Added new line to release notes --- .../iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml b/releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml index ada7126be175..9c55cfae4fb7 100644 --- a/releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml +++ b/releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml @@ -1,4 +1,4 @@ --- fixes: - | - Fixed a bug where the iterative phase estimation algorithm was generating the wrong circuit, causing the algorithm to fail for simple cases. Refer to `#9280 https://github.com/Qiskit/qiskit-terra/issues/9280` for more details. \ No newline at end of file + Fixed a bug where the iterative phase estimation algorithm was generating the wrong circuit, causing the algorithm to fail for simple cases. Refer to `#9280 https://github.com/Qiskit/qiskit-terra/issues/9280` for more details. From bf64b1606c8622ffc30492df0d99f1d1b87db1bb Mon Sep 17 00:00:00 2001 From: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Date: Tue, 4 Apr 2023 14:17:41 -0400 Subject: [PATCH 4/4] Update releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> --- .../iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml b/releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml index ea7b1777199e..aab00dcc106f 100644 --- a/releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml +++ b/releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml @@ -2,4 +2,4 @@ fixes: - | Fixed a bug where :class:`.IterativePhaseEstimation` was generating the wrong circuit, causing the - algorithm to fail for simple cases. Fixed `#9280 https://github.com/Qiskit/qiskit-terra/issues/9280`__. + algorithm to fail for simple cases. Fixed `#9280 `__.