
    z	i6                        S r SSKJr  SSKJr  SSKrSSKJr  SSKJ	r	  SSK
Jr  SSKJr   " S	 S
\	5      r " S S\5      r " S S\5      rg)zPhase Gate.    )annotations)expN)ControlledGate)Gate)ParameterValueType)StandardGatec                     ^  \ rS rSrSr\R                  rSSU 4S jjjrS r	    S       SU 4S jjjr
SSS jjrSS jrSSS jjrS	 rS
rU =r$ )	PhaseGate   u  Single-qubit rotation about the Z axis.

This is a diagonal gate. It can be implemented virtually in hardware
via framechanges (i.e. at zero error and duration).

Can be applied to a :class:`~qiskit.circuit.QuantumCircuit`
with the :meth:`~qiskit.circuit.QuantumCircuit.p` method.

Circuit symbol:

.. code-block:: text

         ┌──────┐
    q_0: ┤ P(θ) ├
         └──────┘

Matrix representation:

.. math::

    P(\theta) =
        \begin{pmatrix}
            1 & 0 \\
            0 & e^{i\theta}
        \end{pmatrix}

Examples:

    .. math::

        P(\theta = \pi) = Z

    .. math::

        P(\theta = \pi/2) = S

    .. math::

        P(\theta = \pi/4) = T

.. seealso::

    :class:`~qiskit.circuit.library.standard_gates.RZGate`:
    This gate is equivalent to RZ up to a phase factor.

        .. math::

            P(\theta) = e^{i{\theta}/2} RZ(\theta)

    Reference for virtual Z gate implementation:
    `1612.00858 <https://arxiv.org/abs/1612.00858>`_
c                (   > [         TU ]  SSU/US9  g)zQ
Args:
    theta: The rotation angle.
    label: An optional label for the gate.
p   labelN)super__init__)selfthetar   	__class__s      a/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/standard_gates/p.pyr   PhaseGate.__init__P   s     	a%6    c                    SSK Jn  UR                  [        R                  R                  U R                  5      SU R                  S9U l        gzDefault definitionr   )QuantumCircuitT)legacy_qubitsnameN)	qiskit.circuitr   _from_circuit_datar   Phase_get_definitionparamsr   
definitionr   r   s     r   _definePhaseGate._defineX   sC     	2 );;..t{{;4VZV_V_ < 
r   c                2  > U(       d:  US:X  a4  [        U R                  S   X#S9nU R                  UR                  l        U$ U(       d=  Uc:  US:  a4  [	        U R                  S   XS9nU R                  UR                  l        U$ [
        TU ]  UUUUS9nU$ )a  Return a (multi-)controlled-Phase gate.

Args:
    num_ctrl_qubits: number of control qubits.
    label: An optional label for the gate [Default: ``None``]
    ctrl_state: control state expressed as integer,
        string (e.g. ``'110'``), or ``None``. If ``None``, use all 1s.
    annotated: indicates whether the controlled gate should be implemented
        as an annotated gate. If ``None``, this is handled as ``False``.

Returns:
    ControlledGate: controlled version of this gate.
r   r   )r   
ctrl_stater   num_ctrl_qubitsr   r(   	annotated)
CPhaseGater"   r   	base_gateMCPhaseGater   controlr   r*   r   r(   r+   gater   s         r   r/   PhaseGate.controle   s    ( _1dkk!nEQD#'::DNN   z1o6It{{1~LD#'::DNN   7? /%#	 # D r   c                4    [        U R                  S   * 5      $ )a  Return inverted Phase gate (:math:`Phase(\lambda)^{\dagger} = Phase(-\lambda)`)

Args:
    annotated: when set to ``True``, this is typically used to return an
        :class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
        :class:`.Gate`. However, for this class this argument is ignored as the inverse
        of this gate is always another :class:`.PGate` with an inverse parameter value.

Returns:
    PGate: inverse gate.
r   )r
   r"   r   r+   s     r   inversePhaseGate.inverse   s     $++a.))r   c                    USL a  [        S5      e[        U R                  S   5      n[        R                  " SS/S[        SU-  5      //US9$ )z(Return a numpy.array for the Phase gate.F9unable to avoid copy while creating an array as requestedr   r                 ?dtype)
ValueErrorfloatr"   numpyarrayr   )r   r;   copylams       r   	__array__PhaseGate.__array__   sN    5=XYYDKKN#{{QFQBH$67uEEr   c                8    U R                   u  n[        X-  5      $ N)r"   r
   r   exponentr+   r   s       r   powerPhaseGate.power   s    ;;)**r   c                P    [        U[        5      (       a  U R                  U5      $ gNF)
isinstancer
   _compare_parametersr   others     r   __eq__PhaseGate.__eq__   s#    eY''++E22r   r#   rE   )r   r   r   
str | Noner   NNNr*   intr   rS   r(   str | int | Noner+   zbool | NoneFr+   boolNNrG   r=   r+   rZ   )__name__
__module____qualname____firstlineno____doc__r   r    _standard_gater   r%   r/   r5   rB   rH   rP   __static_attributes____classcell__r   s   @r   r
   r
      s~    3j "''N7 7
  ! '+!%!! ! %	!
 ! !F*F+ r   r
   c                     ^  \ rS rSrSr\R                  r  SSS.     SU 4S jjjjrS r	    S       SU 4S jjjr
SSS jjrSS	 jrSSS
 jjrS rSrU =r$ )r,      u  Controlled-Phase gate.

This is a diagonal and symmetric gate that induces a
phase on the state of the target qubit, depending on the control state.

Can be applied to a :class:`~qiskit.circuit.QuantumCircuit`
with the :meth:`~qiskit.circuit.QuantumCircuit.cp` method.

Circuit symbol:

.. code-block:: text


    q_0: ─■──
          │θ
    q_1: ─■──


Matrix representation:

.. math::

    CPhase =
        I \otimes |0\rangle\langle 0| + P \otimes |1\rangle\langle 1| =
        \begin{pmatrix}
            1 & 0 & 0 & 0 \\
            0 & 1 & 0 & 0 \\
            0 & 0 & 1 & 0 \\
            0 & 0 & 0 & e^{i\theta}
        \end{pmatrix}

.. seealso::

    :class:`~qiskit.circuit.library.standard_gates.CRZGate`:
    Due to the global phase difference in the matrix definitions
    of Phase and RZ, CPhase and CRZ are different gates with a relative
    phase difference.
N_base_labelc               <   > [         TU ]  SSU/SUU[        XS9S9  g)zCreate new CPhase gate.cp   r   r   r*   r   r(   r-   Nr   r   r
   )r   r   r   r(   ri   r   s        r   r   CPhaseGate.__init__   s3     	G!9 	 	
r   c                    SSK Jn  UR                  [        R                  R                  U R                  5      SU R                  S9U l        gr   )	r   r   r   r   CPhaser!   r"   r   r#   r$   s     r   r%   CPhaseGate._define   sC     	2 );;//<DW[W`W` < 
r   c                   > U(       d;  Uc8  [        U R                  S   US-   US9nU R                  UR                  l        U$ [        TU ]  UUUUS9nU$ )  Controlled version of this gate.

Args:
    num_ctrl_qubits: number of control qubits.
    label: An optional label for the gate [Default: ``None``]
    ctrl_state: control state expressed as integer,
        string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
    annotated: indicates whether the controlled gate should be implemented
        as an annotated gate. If ``None``, this is handled as ``False``.

Returns:
    ControlledGate: controlled version of this gate.
r   r   r*   r   r)   )r.   r"   r   r-   r   r/   r0   s         r   r/   CPhaseGate.control   si    ( Z/t{{1~QR?RZ_`D#'::DNN   7? /%#	 # D r   c                F    [        U R                  S   * U R                  S9$ )zRReturn inverted CPhase gate (:math:`CPhase(\lambda)^{\dagger} = CPhase(-\lambda)`)r   )r(   )r,   r"   r(   r4   s     r   r5   CPhaseGate.inverse  s    4;;q>/dooFFr   c           	        USL a  [        S5      e[        S[        U R                  S   5      -  5      nU R                  (       a#  [
        R                  " / SQ/ SQ/ SQSSSU//US9$ [
        R                  " / SQ/ SQSSUS// S	Q/US9$ )
z)Return a numpy.array for the CPhase gate.Fr8   r9   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   r:   )r   r   r   r   )r<   r   r=   r"   r(   r>   r?   )r   r;   r@   eiths       r   rB   CPhaseGate.__array__  s    5=XYY2dkk!n--.??;;|\Aq!T?KSX  {{L,AtQV^cddr   c                8    U R                   u  n[        X-  5      $ rE   )r"   r,   rF   s       r   rH   CPhaseGate.power"  s    ;;(*++r   c                    [        U[        5      (       a1  U R                  U5      =(       a    U R                  UR                  :H  $ grK   )rL   r,   rM   r(   rN   s     r   rP   CPhaseGate.__eq__&  s7    eZ((++E2Zt%JZJZ7ZZr   rR   r[   )r   r   r   rS   r(   rW   rT   rU   rX   rY   r\   )r]   r^   r_   r`   ra   r   rq   rb   r   r%   r/   r5   rB   rH   rP   rc   rd   re   s   @r   r,   r,      s    %N "((N
 !'+	
 
!
 
 %	
 
&
"  ! '+!%  %	
  @G	e, r   r,   c                     ^  \ rS rSrSr  SSS.       SU 4S jjjjrS r    S       SU 4S jjjrSSS jjrS	 r	S
r
U =r$ )r.   i,  u  Multi-controlled-Phase gate.

This is a diagonal and symmetric gate that induces a
phase on the state of the target qubit, depending on the state of the control qubits.

Can be applied to a :class:`~qiskit.circuit.QuantumCircuit`
with the :meth:`~qiskit.circuit.QuantumCircuit.mcp` method.

Circuit symbol:

.. code-block:: text

        q_0: ───■────
                │
                .
                │
    q_(n-1): ───■────
             ┌──┴───┐
        q_n: ┤ P(λ) ├
             └──────┘

.. seealso::

    :class:`~qiskit.circuit.library.standard_gates.CPhaseGate`:
    The singly-controlled-version of this gate.
Nrh   c               B   > [         TU ]  SUS-   U/UUU[        XS9S9  g)zCreate new MCPhase gate.mcphaser   r   rm   Nrn   )r   rA   r*   r   r(   ri   r   s         r   r   MCPhaseGate.__init__H  s8     	aE+!7 	 	
r   c                f   SSK JnJn  U" U R                  S5      nU" X0R                  S9nU R
                  S:X  a  UR                  U R                  S   S5        U R
                  S:X  a!  UR                  U R                  S   SS5        OU R                  S   n[        [        U R
                  5      5      nU R
                  nUn[        U R
                  5       H*  n	UR                  USU	-  -  XhSS9  UR                  5       nM,     UR                  USU R
                  -  -  U5        X@l        g )	Nr   )r   QuantumRegisterq)r   r   rl   F)use_basis_gates)r   r   r   
num_qubitsr   r*   r   r"   rk   listrangemcrzpopr#   )
r   r   r   qrqcrA   
q_controlsq_target
new_targetks
             r   r%   MCPhaseGate._define\  s    BT__c2BYY/1$DDQ#1$EE$++a.!Q'++a.CeD$8$89:J++H!J4//0q!tjeT'^^-
 1 DD4///0*=r   c                   > U(       dD  UcA  [        U R                  S   XR                  -   US9nU R                  UR                  l        U$ [
        TU ]  UUUUS9nU$ )rt   r   ru   r)   )r.   r"   r*   r   r-   r   r/   r0   s         r   r/   MCPhaseGate.controlu  sr    ( Z/A /2F2F FD
 $(::DNN   7? /%#	 # D r   c                \    [        U R                  S   * U R                  U R                  S9$ )zUReturn inverted MCPhase gate (:math:`MCPhase(\lambda)^{\dagger} = MCPhase(-\lambda)`)r   )r*   r(   )r.   r"   r*   r(   r4   s     r   r5   MCPhaseGate.inverse  s*    [[^OT-A-Adoo
 	
r   c                    [        U[        5      =(       aQ    U R                  UR                  :H  =(       a1    U R                  UR                  :H  =(       a    U R	                  U5      $ rE   )rL   r.   r*   r(   rM   rN   s     r   rP   MCPhaseGate.__eq__  sV    uk* 0$$(=(==05#3#330 ((/		
r   rR   r[   )rA   r   r*   rV   r   rS   r(   rW   rT   rU   rX   rY   )r]   r^   r_   r`   ra   r   r%   r/   r5   rP   rc   rd   re   s   @r   r.   r.   ,  s    > !'+
 

 
 	

 %
 
(6  ! '+!%"" " %	"
 " "H

 
r   r.   )ra   
__future__r   cmathr   r>   qiskit.circuit.controlledgater   qiskit.circuit.gater   "qiskit.circuit.parameterexpressionr   qiskit._accelerate.circuitr   r
   r,   r.    r   r   <module>r      sK     "   8 $ A 3L L^B BJy
. y
r   