§
    ¹³Ùgk(  ã                   óJ  — d Z ddlmZ ddlmZmZ ddlZddlmZm	Z	 ddl
mZmZmZ ddlmZ ddlmZ d	d
lmZ d	dgddggZ ee¦  «         G d„ de¦  «        ¦   «         Z e	ed	¬¦  «         G d„ de¦  «        ¦   «         Z e	edd¬¦  «         G d„ de¦  «        ¦   «         ZdS )zZ, CZ and CCZ gates.é    )Úpi)ÚOptionalÚUnionN)Úwith_gate_arrayÚwith_controlled_gate_array)ÚSingletonGateÚSingletonControlledGateÚstdlib_singleton_key)ÚQuantumRegister)ÚStandardGateé   )Ú	PhaseGateéÿÿÿÿc            
       óÚ   ‡ — e Zd ZdZej        Zddddœdee         fˆ fd„Z	 e
¦   «         Zd„ Z	 	 	 	 dd
edee         deeeef                  defˆ fd„Zddefd„Zddedefd„Zd„ Zˆ xZS )ÚZGateuØ  The single-qubit Pauli-Z gate (:math:`\sigma_z`).

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

    **Matrix Representation:**

    .. math::

        Z = \begin{pmatrix}
                1 & 0 \\
                0 & -1
            \end{pmatrix}

    **Circuit symbol:**

    .. code-block:: text

             â”Œâ”€â”€â”€â”�
        q_0: â”¤ Z â”œ
             â””â”€â”€â”€â”˜

    Equivalent to a :math:`\pi` radian rotation about the Z axis.

    .. note::

        A global phase difference exists between the definitions of
        :math:`RZ(\pi)` and :math:`Z`.

        .. math::

            RZ(\pi) = \begin{pmatrix}
                        -i & 0 \\
                        0 & i
                      \end{pmatrix}
                    = -i Z

    The gate is equivalent to a phase flip.

    .. math::

        |0\rangle \rightarrow |0\rangle \\
        |1\rangle \rightarrow -|1\rangle
    NÚdt)ÚdurationÚunitÚlabelc                óV   •— t          ¦   «                              ddg |||¬¦  «         dS )zCreate new Z gate.Úzr   )r   r   r   N)ÚsuperÚ__init__)Úselfr   r   r   Ú	__class__s       €ú]/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/library/standard_gates/z.pyr   zZGate.__init__O   s.   ø€ å‰Œ×Ò˜˜a ¨5¸8È$ÐÑOÔOÐOÐOÐOó    c                 óæ   — ddl m} ddlm} t	          dd¦  «        } ||| j        ¬¦  «        } |t          ¦  «        |d         gg fg}|D ]\  }}}|                     |||¦  «         Œ|| _        d S )Nr   ©ÚQuantumCircuitr   )ÚU1GateÚq©Úname)	Úqiskit.circuit.quantumcircuitr    Úu1r!   r   r$   r   Ú_appendÚ
definition)	r   r    r!   r"   ÚqcÚrulesÚinstrÚqargsÚcargss	            r   Ú_definezZGate._defineU   s¢   € à@Ð@Ð@Ð@Ð@Ð@àÐÐÐÐÐå˜A˜sÑ#Ô#ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆØ�&�‘*”*˜q œt˜f bÐ)Ð*ˆØ#(ð 	,ð 	,ÑˆE�5˜%Ø�JŠJ�u˜e UÑ+Ô+Ð+Ð+àˆŒˆˆr   r   FÚnum_ctrl_qubitsÚ
ctrl_stateÚ	annotatedc                 ó’   •— |s|dk    rt          ||| j        ¬¦  «        }n%t          ¦   «                              ||||¬¦  «        }|S )a2  Return a (multi-)controlled-Z gate.

        One control returns a CZ 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.

        Returns:
            ControlledGate: controlled version of this gate.
        r   )r   r0   Ú_base_label)r/   r   r0   r1   )ÚCZGater   r   Úcontrol)r   r/   r   r0   r1   Úgater   s         €r   r5   zZGate.controlc   s^   ø€ ð, ð 	˜_°Ò1Ð1Ý °*È$Ì*ÐUÑUÔUˆDˆDå‘7”7—?’?Ø /ØØ%Ø#ð	 #ñ ô ˆDð ˆr   c                 ó   — t          ¦   «         S )aª  Return inverted Z gate (itself).

        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 this gate
                is self-inverse.

        Returns:
            ZGate: inverse gate (self-inverse).
        )r   ©r   r1   s     r   ÚinversezZGate.inverse„   s   € õ ‰wŒwˆr   Úexponentc                 ó:   — t          t          j        |z  ¦  «        S ©N)r   Únumpyr   )r   r:   r1   s      r   ÚpowerzZGate.power’   s   € Ý�œ HÑ,Ñ-Ô-Ð-r   c                 ó,   — t          |t          ¦  «        S r<   )Ú
isinstancer   ©r   Úothers     r   Ú__eq__zZGate.__eq__•   s   € Ý˜%¥Ñ'Ô'Ð'r   r<   )r   NNF©F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú_standard_gater   Ústrr   r
   Ú_singleton_lookup_keyr.   Úintr   Úboolr5   r9   Úfloatr>   rC   Ú__classcell__©r   s   @r   r   r      sY  ø€ € € € € ð+ð +ðZ "Ô'€NðPÀÈ4ð Pð Pð P˜h sœmð Pð Pð Pð Pð Pð Pð 1Ð0Ñ2Ô2Ððð ð ð   !Ø#Ø04Øðð àðð ˜Œ}ðð ˜U 3¨ 8œ_Ô-ð	ð
 ðð ð ð ð ð ðBð  ð ð ð ð ð.ð .˜eð .°ð .ð .ð .ð .ð(ð (ð (ð (ð (ð (ð (r   r   ©r/   c            	       ó¤   ‡ — e Zd ZdZej        Z	 	 dddddœdee         dee	ee
f                  fˆ fd„Z ed¬	¦  «        Zd
„ Zddefd„Zd„ Zˆ xZS )r4   u  Controlled-Z gate.

    This is a Clifford and symmetric gate.

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

    **Circuit symbol:**

    .. code-block:: text

        q_0: â”€â– â”€
              â”‚
        q_1: â”€â– â”€

    **Matrix representation:**

    .. math::

        CZ\ q_0, q_1 =
            I \otimes |0\rangle\langle 0| + Z \otimes |1\rangle\langle 1| =
            \begin{pmatrix}
                1 & 0 & 0 & 0 \\
                0 & 1 & 0 & 0 \\
                0 & 0 & 1 & 0 \\
                0 & 0 & 0 & -1
            \end{pmatrix}

    In the computational basis, this gate flips the phase of
    the target qubit if the control qubit is in the :math:`|1\rangle` state.
    Nr   ©r   r   r3   r   r0   c                óx   •— t          ¦   «                              ddg |d|t          |¬¦  «        ||¬¦	  «	         dS )zCreate new CZ gate.Úczé   r   ©r   ©r   r/   r0   Ú	base_gater   r   N©r   r   r   ©r   r   r0   r   r   r3   r   s         €r   r   zCZGate.__init__½   sV   ø€ õ 	‰Œ×ÒØØØØØØ!Ý +Ð.Ñ.Ô.ØØð 	ñ 
	
ô 
	
ð 
	
ð 
	
ð 
	
r   r   rQ   c                 ó@  — ddl m} ddlm} ddlm} t          dd¦  «        } ||| j        ¬¦  «        } |¦   «         |d         gg f |¦   «         |d         |d         gg f |¦   «         |d         gg fg}|D ]\  }}}	|                     |||	¦  «         Œ|| _	        d	S )
z3
        gate cz a,b { h b; cx a,b; h b; }
        r   r   r   ©ÚHGate)ÚCXGaterV   r"   r#   N)
r%   r    Úhr^   Úxr_   r   r$   r'   r(   )
r   r    r^   r_   r"   r)   r*   r+   r,   r-   s
             r   r.   zCZGate._defineÕ   sê   € ð
 	AÐ@Ð@Ð@Ð@Ð@àÐÐÐÐÐØÐÐÐÐÐå˜A˜sÑ#Ô#ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆØ�%‘'”'˜A˜aœD˜6 2Ð&¨¨©¬°A°a´D¸!¸A¼$°<ÀÐ(DÀuÀuÁwÄwÐQRÐSTÔQUÐPVÐXZÐF[Ð\ˆØ#(ð 	,ð 	,ÑˆE�5˜%Ø�JŠJ�u˜e UÑ+Ô+Ð+Ð+àˆŒˆˆr   Fr1   c                 ó,   — t          | j        ¬¦  «        S )a¬  Return inverted CZ gate (itself).

        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 this gate
                is self-inverse.

        Returns:
            CZGate: inverse gate (self-inverse).
        ©r0   )r4   r0   r8   s     r   r9   zCZGate.inverseç   s   € õ  ¤Ð1Ñ1Ô1Ð1r   c                 óL   — t          |t          ¦  «        o| j        |j        k    S r<   )r@   r4   r0   rA   s     r   rC   zCZGate.__eq__õ   s!   € Ý˜%¥Ñ(Ô(ÐP¨T¬_ÀÔ@PÒ-PÐPr   ©NNrD   )rE   rF   rG   rH   r   r4   rI   r   rJ   r   rL   r   r
   rK   r.   rM   r9   rC   rO   rP   s   @r   r4   r4   ™   sò   ø€ € € € € ðð ð@ "Ô(€Nð  $Ø04ð
ð
 ØØð
ð 
ð 
à˜Œ}ð
ð ˜U 3¨ 8œ_Ô-ð
ð 
ð 
ð 
ð 
ð 
ð, 1Ð0ÀÐCÑCÔCÐðð ð ð$2ð 2 ð 2ð 2ð 2ð 2ðQð Qð Qð Qð Qð Qð Qr   r4   rV   )é   )r/   Úcached_statesc            	       ó¤   ‡ — e Zd ZdZej        Z	 	 dddddœdee         dee	ee
f                  fˆ fd„Z ed¬	¦  «        Zd
„ Zddefd„Zd„ Zˆ xZS )ÚCCZGateu9  CCZ gate.

    This is a symmetric gate.

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

    **Circuit symbol:**

    .. code-block:: text

        q_0: â”€â– â”€
              â”‚
        q_1: â”€â– â”€
              â”‚
        q_2: â”€â– â”€

    **Matrix representation:**

    .. math::

        CCZ\ q_0, q_1, q_2 =
            I \otimes I \otimes |0\rangle\langle 0| + CZ \otimes |1\rangle\langle 1| =
            \begin{pmatrix}
                1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
                0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\
                0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\
                0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\
                0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\
                0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\
                0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\
                0 & 0 & 0 & 0 & 0 & 0 & 0 & -1
            \end{pmatrix}

    In the computational basis, this gate flips the phase of
    the target qubit if the control qubits are in the :math:`|11\rangle` state.
    Nr   rS   r   r0   c                óx   •— t          ¦   «                              ddg |d|t          |¬¦  «        ||¬¦	  «	         dS )zCreate new CCZ gate.Úcczrf   rV   rW   rX   NrZ   r[   s         €r   r   zCCZGate.__init__#  sV   ø€ õ 	‰Œ×ÒØØØØØØ!Ý +Ð.Ñ.Ô.ØØð 	ñ 
	
ô 
	
ð 
	
ð 
	
ð 
	
r   rV   rQ   c                 óN  — ddl m} ddlm} ddlm} t          dd¦  «        } ||| j        ¬¦  «        } |¦   «         |d	         gg f |¦   «         |d         |d         |d	         gg f |¦   «         |d	         gg fg}|D ]\  }}}	|                     |||	¦  «         Œ|| _	        d
S )z9
        gate ccz a,b,c { h c; ccx a,b,c; h c; }
        r   r   r   r]   )ÚCCXGaterf   r"   r#   rV   N)
r%   r    r`   r^   ra   rm   r   r$   r'   r(   )
r   r    r^   rm   r"   r)   r*   r+   r,   r-   s
             r   r.   zCCZGate._define;  sñ   € ð
 	AÐ@Ð@Ð@Ð@Ð@àÐÐÐÐÐØÐÐÐÐÐå˜A˜sÑ#Ô#ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆØ�%‘'”'˜A˜aœD˜6 2Ð&¨¨©¬°Q°q´T¸1¸Q¼4ÀÀ1ÄÐ4FÈÐ(KÈeÈeÉgÌgÐXYÐZ[ÔX\ÐW]Ð_aÐMbÐcˆØ#(ð 	,ð 	,ÑˆE�5˜%Ø�JŠJ�u˜e UÑ+Ô+Ð+Ð+àˆŒˆˆr   Fr1   c                 ó,   — t          | j        ¬¦  «        S )a®  Return inverted CCZ gate (itself).

        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 this gate
                is self-inverse.

        Returns:
            CCZGate: inverse gate (self-inverse).
        rc   )ri   r0   r8   s     r   r9   zCCZGate.inverseM  s   € õ  $¤/Ð2Ñ2Ô2Ð2r   c                 óL   — t          |t          ¦  «        o| j        |j        k    S r<   )r@   ri   r0   rA   s     r   rC   zCCZGate.__eq__[  s!   € Ý˜%¥Ñ)Ô)ÐQ¨d¬oÀÔAQÒ.QÐQr   re   rD   )rE   rF   rG   rH   r   ri   rI   r   rJ   r   rL   r   r
   rK   r.   rM   r9   rC   rO   rP   s   @r   ri   ri   ù   sò   ø€ € € € € ð$ð $ðL "Ô)€Nð  $Ø04ð
ð
 ØØð
ð 
ð 
à˜Œ}ð
ð ˜U 3¨ 8œ_Ô-ð
ð 
ð 
ð 
ð 
ð 
ð, 1Ð0ÀÐCÑCÔCÐðð ð ð$3ð 3 ð 3ð 3ð 3ð 3ðRð Rð Rð Rð Rð Rð Rr   ri   )rH   Úmathr   Útypingr   r   r=   Úqiskit.circuit._utilsr   r   Úqiskit.circuit.singletonr   r	   r
   Úqiskit.circuit.quantumregisterr   Úqiskit._accelerate.circuitr   Úpr   Ú_Z_ARRAYr   r4   ri   © r   r   ú<module>ry      sÊ  ðð Ð à Ð Ð Ð Ð Ð Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "à €€€à MÐ MÐ MÐ MÐ MÐ MÐ MÐ MØ aÐ aÐ aÐ aÐ aÐ aÐ aÐ aÐ aÐ aØ :Ð :Ð :Ð :Ð :Ð :Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3à Ð Ð Ð Ð Ð à�ˆF�Q˜�GÐ€ð €�ÑÔðw(ð w(ð w(ð w(ð w(ˆMñ w(ô w(ñ Ôðw(ðt Ð˜H°aÐ8Ñ8Ô8ð\Qð \Qð \Qð \Qð \QÐ$ñ \Qô \Qñ 9Ô8ð\Qð~ Ð˜H°aÀtÐLÑLÔLðbRð bRð bRð bRð bRÐ%ñ bRô bRñ MÔLðbRð bRð bRr   