
    z	i$                    x    S r SSKJ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\5      rg)z'Linearly-controlled X, Y or Z rotation.    )annotations)Optional)QuantumRegisterQuantumCircuitGate)CircuitError   )FunctionalPauliRotationsc                     ^  \ rS rSrSr     S           SU 4S jjjr\SS j5       r\R                  SS j5       r\SS j5       r	\	R                  SS j5       r	SS jr
SSS	 jjrU 4S
 jrSrU =r$ )LinearPauliRotations   u  Linearly-controlled X, Y or Z rotation.

For a register of state qubits :math:`|x\rangle`, a target qubit :math:`|0\rangle` and the
basis ``'Y'`` this circuit acts as:

.. code-block:: text

        q_0: ─────────────────────────■───────── ... ──────────────────────
                                      │
                                      .
                                      │
    q_(n-1): ─────────────────────────┼───────── ... ───────────■──────────
              ┌────────────┐  ┌───────┴───────┐       ┌─────────┴─────────┐
        q_n: ─┤ RY(offset) ├──┤ RY(2^0 slope) ├  ...  ┤ RY(2^(n-1) slope) ├
              └────────────┘  └───────────────┘       └───────────────────┘

This can for example be used to approximate linear functions, with :math:`a =` ``slope``:math:`/2`
and :math:`b =` ``offset``:math:`/2` and the basis ``'Y'``:

.. math::

    |x\rangle |0\rangle \mapsto \cos(ax + b)|x\rangle|0\rangle + \sin(ax + b)|x\rangle |1\rangle

Since for small arguments :math:`\sin(x) \approx x` this operator can be used to approximate
linear functions.
c                V   > [         TU ]  XUS9  SU l        SU l        X l        X0l        g)a!  
Args:
    num_state_qubits: The number of qubits representing the state :math:`|x\rangle`.
    slope: The slope of the controlled rotation.
    offset: The offset of the controlled rotation.
    basis: The type of Pauli rotation ('X', 'Y', 'Z').
    name: The name of the circuit object.
)num_state_qubitsbasisnameN)super__init___slope_offsetslopeoffset)selfr   r   r   r   r   	__class__s         r/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/arithmetic/linear_pauli_rotations.pyr   LinearPauliRotations.__init__5   s4      	*:dS  
    c                    U R                   $ )a  The multiplicative factor in the rotation angle of the controlled rotations.

The rotation angles are ``slope * 2^0``, ``slope * 2^1``, ... , ``slope * 2^(n-1)`` where
``n`` is the number of state qubits.

Returns:
    The rotation angle common in all controlled rotations.
)r   r   s    r   r   LinearPauliRotations.slopeO   s     {{r   c                j    U R                   b  XR                   :w  a  U R                  5         Xl         gg)zcSet the multiplicative factor of the rotation angles.

Args:
    The slope of the rotation angles.
N)r   _invalidate)r   r   s     r   r   r   [   s-     ;;%;;"6K #7r   c                    U R                   $ )zThe angle of the single qubit offset rotation on the target qubit.

Before applying the controlled rotations, a single rotation of angle ``offset`` is
applied to the target qubit.

Returns:
    The offset angle.
)r   r   s    r   r   LinearPauliRotations.offsetf   s     ||r   c                j    U R                   b  XR                   :w  a  U R                  5         Xl         gg)ziSet the angle for the offset rotation on the target qubit.

Args:
    offset: The offset rotation angle.
N)r   r!   )r   r   s     r   r   r#   r   s-     <<6\\#9!L $:r   c                Z    / U l         U(       a  [        USS9n[        SSS9nX#/U l         gg)zSet the number of state qubits.

Note that this changes the underlying quantum register, if the number of state qubits
changes.

Args:
    num_state_qubits: The new number of qubits.
stater   r	   targetN)qregsr   )r   r   qr_state	qr_targets       r   _reset_registers%LinearPauliRotations._reset_registers}   s6     
&'7gFH'9I".DJ	 r   c                    SnU R                   c  SnU(       a  [        S5      eU R                  U R                   S-   :  a%  SnU(       a  [        SU R                   S-    S35      eU$ )z,Check if the current configuration is valid.TFz&The number of qubits has not been set.r	   z0Not enough qubits in the circuit, need at least .)r   AttributeError
num_qubitsr   )r   raise_on_failurevalids      r   _check_configuration)LinearPauliRotations._check_configuration   su      (E$%MNN??T22Q66E"F,,q014 
 r   c                   > U R                   (       a  g[        TU ]	  5         [        U R                  U R
                  U R                  U R                  5      nU R                  XR                  5        g)z(If not already built, build the circuit.N)
	_is_builtr   _buildLinearPauliRotationsGater   r   r   r   appendqubits)r   gater   s     r   r8   LinearPauliRotations._build   sL    >>'(=(=tzz4;;X\XbXbcD++&r   )r   r   r   r)   r   )Nr	   r   YLinRot)r   Optional[int]r   floatr   rA   r   strr   rB   returnNone)rC   rA   )r   rA   rC   rD   )r   rA   rC   rD   )r   r@   rC   rD   )T)r2   boolrC   rE   )__name__
__module____qualname____firstlineno____doc__r   propertyr   setterr   r,   r4   r8   __static_attributes____classcell__r   s   @r   r   r      s    : +/'  	
   
 4 	 	 \\    	 	 ]]" "/"&' 'r   r   c                  X   ^  \ rS rSrSr    S           SU 4S jjjrS rSrU =r$ )r9      u  Linearly-controlled X, Y or Z rotation.

For a register of state qubits :math:`|x\rangle`, a target qubit :math:`|0\rangle` and the
basis ``'Y'`` this circuit acts as:

.. parsed-literal::

        q_0: ─────────────────────────■───────── ... ──────────────────────
                                      │
                                      .
                                      │
    q_(n-1): ─────────────────────────┼───────── ... ───────────■──────────
              ┌────────────┐  ┌───────┴───────┐       ┌─────────┴─────────┐
        q_n: ─┤ RY(offset) ├──┤ RY(2^0 slope) ├  ...  ┤ RY(2^(n-1) slope) ├
              └────────────┘  └───────────────┘       └───────────────────┘

This can for example be used to approximate linear functions, with :math:`a =` ``slope``:math:`/2`
and :math:`b =` ``offset``:math:`/2` and the basis ``'Y'``:

.. math::

    |x\rangle |0\rangle \mapsto \cos(ax + b)|x\rangle|0\rangle + \sin(ax + b)|x\rangle |1\rangle

Since for small arguments :math:`\sin(x) \approx x` this operator can be used to approximate
linear functions.
c                n   > [         TU ]  SUS-   / US9  X l        X0l        UR	                  5       U l        g)a  
Args:
    num_state_qubits: The number of qubits representing the state :math:`|x\rangle`.
    slope: The slope of the controlled rotation.
    offset: The offset of the controlled rotation.
    basis: The type of Pauli rotation ('X', 'Y', 'Z').
    label: The label of the gate.
LinPauliRotr	   )labelN)r   r   r   r   lowerr   )r   r   r   r   r   rT   r   s         r   r   !LinearPauliRotationsGate.__init__   s8      	(81(<bN
[[]
r   c                   [        U R                  U R                  S9nUR                  S U R                  S-
   nUR                  S   nU R                  S:X  a  UR                  U R                  U5        OIU R                  S:X  a  UR                  U R                  U5        OUR                  U R                  U5        [        U5       H  u  pEU R                  S:X  a+  UR                  U R                  [        SU5      -  XS5        M@  U R                  S:X  a+  UR                  U R                  [        SU5      -  XS5        M{  UR                  U R                  [        SU5      -  XS5        M     Xl        g )Nr'   r	   xy   )r   r1   r   r;   r   rxr   ryrz	enumeratecrxr   powcrycrz
definition)r   circuitr*   r+   iq_is         r   _define LinearPauliRotationsGate._define   s    tyyA >>"7DOOa$78NN2&	::JJt{{I.ZZ3JJt{{I.JJt{{I.)FAzzS DJJQ2CCs"DJJQ2CCDJJQ2CC * "r   )r   rd   r   r   )r	   r   r>   N)r   intr   rA   r   rA   r   rB   rT   z
str | NonerC   rD   )	rF   rG   rH   rI   rJ   r   rh   rM   rN   rO   s   @r   r9   r9      sd    <  ## # 	#
 # # 
# #*" "r   r9   N)rJ   
__future__r   typingr   qiskit.circuitr   r   r   qiskit.circuit.exceptionsr   functional_pauli_rotationsr
   r   r9    r   r   <module>rq      s:    . "  @ @ 2 @O'3 O'dG"t G"r   