Skip to content

Commit

Permalink
Fixed IQAE bug mentioned in issue 9280 (#9887)
Browse files Browse the repository at this point in the history
* Fixed IQAE bug mentioned in issue 9280

* Update releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml

Co-authored-by: Julien Gacon <[email protected]>

* Added new line to release notes

* Update releasenotes/notes/iterative-phase-estimation-bugfix-b676ffc23cea8251.yaml

Co-authored-by: Elena Peña Tapia <[email protected]>

---------

Co-authored-by: Julien Gacon <[email protected]>
Co-authored-by: Steve Wood <[email protected]>
Co-authored-by: Elena Peña Tapia <[email protected]>
  • Loading branch information
4 people authored Apr 5, 2023
1 parent 2b8c093 commit 2bb15ed
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion qiskit/algorithms/phase_estimators/ipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
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>`__.
30 changes: 29 additions & 1 deletion test/python/algorithms/test_phase_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 2bb15ed

Please sign in to comment.