
    z	i                    t    S r SSKJr  SSKJrJrJr  SSKJr  SSK	J
r
   " S S\5      r S
       SS jjrg	)zPhase estimation circuit.    )annotations)QuantumCircuitQuantumRegisterGate)deprecate_func)QFTc                  `   ^  \ rS rSrSr\" SSSS9  S	         S
U 4S jjj5       rSrU =r$ )PhaseEstimation   u  Phase Estimation circuit.

In the Quantum Phase Estimation (QPE) algorithm [1, 2, 3], the Phase Estimation circuit is used
to estimate the phase :math:`\phi` of an eigenvalue :math:`e^{2\pi i\phi}` of a unitary operator
:math:`U`, provided with the corresponding eigenstate :math:`|\psi\rangle`.
That is

.. math::

    U|\psi\rangle = e^{2\pi i\phi} |\psi\rangle

This estimation (and thereby this circuit) is a central routine to several well-known
algorithms, such as Shor's algorithm or Quantum Amplitude Estimation.

References:

[1] Kitaev, A. Y. (1995). Quantum measurements and the Abelian Stabilizer Problem. 1–22.
`quant-ph/9511026 <http://arxiv.org/abs/quant-ph/9511026>`_

[2] Michael A. Nielsen and Isaac L. Chuang. 2011.
Quantum Computation and Quantum Information: 10th Anniversary Edition (10th ed.).
Cambridge University Press, New York, NY, USA.

[3] Qiskit
`textbook <https://github.com/Qiskit/textbook/blob/main/notebooks/ch-algorithms/
quantum-phase-estimation.ipynb>`_

z2.1z4Use qiskit.circuit.library.phase_estimation instead.zin Qiskit 3.0)sinceadditional_msgremoval_timelinec                  > [        US5      n[        UR                  S5      n[        XVUS9nUc  [        USSS9R	                  5       nUR                  U5        [        U5       H;  nUR                  UR                  SU-  5      R                  5       U/USS -   SS	9  M=     UR                  X5SS SS	9  [        T	U ],  " UR                  S
UR                  06  U R                  UR                  5       U R                  SS	9  g)a  
Args:
    num_evaluation_qubits: The number of evaluation qubits.
    unitary: The unitary operation :math:`U` which will be repeated and controlled.
    iqft: A inverse Quantum Fourier Transform, per default the inverse of
        :class:`~qiskit.circuit.library.QFT` is used. Note that the QFT should not include
        the usual swaps!
    name: The name of the circuit.

.. note::

    The inverse QFT should not include a swap of the qubit order.

Reference Circuit:

.. plot::
    :alt: Diagram illustrating the previously described circuit.

    from qiskit.circuit import QuantumCircuit
    from qiskit.circuit.library import PhaseEstimation
    from qiskit.visualization.library import _generate_circuit_library_visualization
    unitary = QuantumCircuit(2)
    unitary.x(0)
    unitary.y(1)
    circuit = PhaseEstimation(3, unitary)
    _generate_circuit_library_visualization(circuit)
evalqnameNTF)inversedo_swaps   qubitsinplacer   )r   
num_qubitsr   r   reverse_bitshrangecomposepowercontrolsuper__init__qregsr   to_gater   )
selfnum_evaluation_qubitsunitaryiqftr   qr_evalqr_statecircuitj	__class__s
            a/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/phase_estimation.pyr"   PhaseEstimation.__init__4   s    N ""7@"7#5#5s; ><,dUKXXZD		',-AOOGMM!Q$/7791#QRBS]aOb . 	QZ>'--;gll;W__&t{{DI     )NQPE)
r&   intr'   r   r(   zQuantumCircuit | Noner   strreturnNone)	__name__
__module____qualname____firstlineno____doc__r   r"   __static_attributes____classcell__)r-   s   @r.   r
   r
      si    : M( '+1J"1J  1J $	1J
 1J 
1J
1Jr0   r
   c                   SSK JnJn  [        U S5      n[        UR                  S5      n[        XVUS9nUR                  U5        [        U 5       H;  nUR                  UR                  SU-  5      R                  5       U/USS -   SS	9  M=     UR                  U" U 5      R                  5       USS 5        [        [        [        U 5      5      5      n	UR                  U" U	5      USS 5        U$ )
u  Phase Estimation circuit.

In the Quantum Phase Estimation (QPE) algorithm [1, 2, 3], the Phase Estimation circuit is used
to estimate the phase :math:`\phi` of an eigenvalue :math:`e^{2\pi i\phi}` of a unitary operator
:math:`U`, provided with the corresponding eigenstate :math:`|\psi\rangle`.
That is

.. math::

    U|\psi\rangle = e^{2\pi i\phi} |\psi\rangle

This estimation (and thereby this circuit) is a central routine to several well-known
algorithms, such as Shor's algorithm or Quantum Amplitude Estimation.

Args:
    num_evaluation_qubits: The number of evaluation qubits.
    unitary: The unitary operation :math:`U` which will be repeated and controlled. This
        can either be a :class:`.QuantumCircuit` or a :class:`.Gate`. Passing gates can often
        be more performant, as it allows calling optimized control and power subroutines.
    name: The name of the output circuit.

Reference Circuit:

.. plot::
   :alt: A phase estimation circuit.
   :include-source:

   from qiskit.circuit.library import phase_estimation, PauliEvolutionGate
   from qiskit.quantum_info import SparsePauliOp

   hamiltonian = SparsePauliOp(["ZZ", "IX", "XI"])
   evo = PauliEvolutionGate(hamiltonian, time=0.1)  # implements exp(-itH)

   circuit = phase_estimation(3, evo)  # QPE for the evolution operator
   circuit.draw("mpl")

References:

[1] Kitaev, A. Y. (1995). Quantum measurements and the Abelian Stabilizer Problem. 1–22.
`quant-ph/9511026 <http://arxiv.org/abs/quant-ph/9511026>`_

[2] Michael A. Nielsen and Isaac L. Chuang. 2011.
Quantum Computation and Quantum Information: 10th Anniversary Edition (10th ed.).
Cambridge University Press, New York, NY, USA.

[3] Qiskit `textbook <https://github.com/Qiskit/textbook/blob/main/notebooks/ch-algorithms/
quantum-phase-estimation.ipynb>`_

r   )PermutationGateQFTGater   r   r   r   NTr   )qiskit.circuit.libraryr?   r@   r   r   r   r   r   r   r   r    appendr   listreversed)
r&   r'   r   r?   r@   r)   r*   r+   r,   reversal_patterns
             r.   phase_estimationrF   m   s    n @3V<Gw1137HWT:GIIg()ad+335qcHQK>OY]^ * NN70199;WQZHHU+@%ABCNN?#34gajANr0   N)r2   )r&   r3   r'   zQuantumCircuit | Gater   r4   r5   r   )r;   
__future__r   qiskit.circuitr   r   r   qiskit.utils.deprecationr   rA   r   r
   rF   r1   r0   r.   <module>rJ      s]      " @ @ 3 &TJn TJt GG"G G 	Gr0   