σ
    Σz	i<  γ            	       σT    S r SSKrSSKJr  SSKJr  SSKJr   SS\	S\
S\S	\4S
 jjrg)z1Compute the sum of two qubit registers using QFT.ι    N)ΪQuantumCircuit)ΪQuantumRegister)ΪQFTGateΪnum_state_qubitsΪkindΪ	annotatedΪreturnc           	      σ@   US:X  a  [        S5      eU S:  a  [        S5      e[        U SS9n[        U SS9nX4/nUS:X  a  [        SS	S9nUR                  U5        [        U6 nUS
:X  a  USS O
USS WSS -   nUS
:X  a  U OU S-   n	[	        U	5      n
UR                  X¨SS 5        [        U 5       HH  n[        X-
  5       H4  n[        R                  SU-  -  nUR                  XΣU   XU-   )    5        M6     MJ     UR                  U
R                  US9USS 5        U$ )uC  A circuit that uses QFT to perform in-place addition on two qubit registers.

For registers with :math:`n` qubits, the QFT adder can perform addition modulo
:math:`2^n` (with ``kind="fixed"``) or ordinary addition by adding a carry qubits (with
``kind="half"``). The fixed adder uses :math:`(3n^2 - n)/2` :class:`.CPhaseGate` operators,
with an additional :math:`n` for the half adder.

As an example, a non-fixed_point QFT adder circuit that performs addition on two 2-qubit sized
registers is as follows:

.. parsed-literal::

    a_0: ββββββββββ βββββββ βββββββββ ββββββββββββββββββββββββββββββββββ
                  β      β        β
    a_1: ββββββββββΌβββββββΌβββββββββΌβββββββββ βββββββ ββββββββββββββββββ
         ββββββββ β      β        βP(Ο/4)  β      βP(Ο/2) βββββββββββ
    b_0: β€0     βββΌβββββββΌβββββββββ βββββββββΌβββββββ ββββββββ€0        β
         β      β β      βP(Ο/2)           βP(Ο)          β         β
    b_1: β€1 Qft βββΌβββββββ ββββββββββββββββββ βββββββββββββββ€1 qft_dg β
         β      β βP(Ο)                                   β         β
   cout: β€2     βββ ββββββββββββββββββββββββββββββββββββββββ€2        β
         ββββββββ                                         βββββββββββ

Args:
    num_state_qubits: The number of qubits in either input register for
        state :math:`|a\rangle` or :math:`|b\rangle`. The two input
        registers must have the same number of qubits.
    kind: The kind of adder, can be ``"half"`` for a half adder or
        ``"fixed"`` for a fixed-sized adder. A half adder contains a carry-out to represent
        the most-significant bit, but the fixed-sized adder doesn't and hence performs
        addition modulo ``2 ** num_state_qubits``.
    annotated: If ``True``, creates appropriate control and inverse operations as
        ``AnnotatedOperation`` objects.

References:

[1] T. G. Draper, Addition on a Quantum Computer, 2000.
`arXiv:quant-ph/0008033 <https://arxiv.org/pdf/quant-ph/0008033.pdf>`_

[2] Ruiz-Perez et al., Quantum arithmetic with the Quantum Fourier Transform, 2017.
`arXiv:1411.5949 <https://arxiv.org/pdf/1411.5949.pdf>`_

[3] Vedral et al., Quantum Networks for Elementary Arithmetic Operations, 1995.
`arXiv:quant-ph/9511018 <https://arxiv.org/pdf/quant-ph/9511018.pdf>`_

Ϊfullz@The DraperQFTAdder only supports 'half' and 'fixed' as ``kind``.ι   z(The number of qubits must be at least 1.Ϊa)ΪnameΪbΪhalfΪcoutΪfixedNι   )r   )
Ϊ
ValueErrorr   Ϊappendr   r   ΪrangeΪnpΪpiΪcpΪinverse)r   r   r   Ϊqr_aΪqr_bΪqr_listΪqr_zΪcircuitΪqr_sumΪnum_sumΪqftΪjΪkΪlams                 Ϊm/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/synthesis/arithmetic/adders/draper_qft_adder.pyΪadder_qft_d00r'      s;   πd v~άΠ[Σ\Π\ΰ!ΣάΠCΣDΠDδΠ+°#Ρ6DάΠ+°#Ρ6DΨlGΰv~άq vΡ.ΨtΤτ gΠ&Gπ  T!W¨T±!¨W°tΉA°wΡ->FΨ"&¨'£/ΡΠ7GΘ!Ρ7KGτ 'Σ
CΨNN3q	Τ"δΠ#Φ$άw{Φ#Aά%%1a4.Cπ JJs G V°!©e¨HΡ%5Φ6σ $ρ %π NN3;;¨;Π3°VΉA°YΤ?ΰNσ    )r   F)Ϊ__doc__Ϊnumpyr   Ϊqiskit.circuit.quantumcircuitr   Ϊqiskit.circuitr   Ϊ#qiskit.circuit.library.basis_changer   ΪintΪstrΪboolr'   © r(   r&   Ϊ<module>r2      sG   πρ 8γ ε 8έ *έ 7π BGρUΨπUΨ!$πUΨ:>πUΰφUr(   