
    z	io                       S r SSKJr  SSKrSSKJrJr  SSKrSSK	J
r
Jr  SSKJr  SSKJr  SSKJr  SS	KJrJrJrJr  SS
KJr  SSKJr  SSKJr  SSKJrJr  \(       a  SSK J!r!  SSK"J#r#  SSK$J%r%   " S S\5      r&\" \&5        g)z
N-qubit Pauli Operator Class
    )annotationsN)LiteralTYPE_CHECKING)InstructionQuantumCircuit)Barrier)Delay)	PauliGate)IGateXGateYGateZGate)QiskitError)generate_apidocs)ScalarOp)	BasePauli_count_yClifford)	PauliListTranspileLayoutc                    ^  \ rS rSrSrSr\R                  " S5      rSSSSS	.r	S5S6U 4S
 jjjr
\S 5       r\S 5       rS rS rS7S jr\S8S j5       rS rS9S jr\S:S j5       r\S 5       r\R.                  S 5       r\S 5       r\R.                  S 5       r\S 5       r\R.                  S 5       rS rS rS rS;S jrS<S jrS rS=S  jr S>S?S! jjr!S" r" S@         SAU 4S# jjjr#SBSCS$ jjr$SDU 4S% jjr%SDU 4S& jjr&U 4S' jr'U 4S( jr(U 4S) jr)U 4S* jr*U 4S+ jr+S5SEU 4S, jjjr,S5SFS- jjr-  SG       SHU 4S. jjjr.\/S/ 5       r0\S0 5       r1\S1 5       r2\S2 5       r3 S5     SIS3 jjr4S4r5U =r6$ )JPauli'   a  N-qubit Pauli operator.

This class represents an operator :math:`P` from the full :math:`n`-qubit
*Pauli* group

.. math::

    P = (-i)^{q} P_{n-1} \otimes ... \otimes P_{0}

where :math:`q\in \mathbb{Z}_4` and :math:`P_i \in \{I, X, Y, Z\}`
are single-qubit Pauli matrices:

.. math::

    I = \begin{pmatrix} 1 & 0  \\ 0 & 1  \end{pmatrix},
    X = \begin{pmatrix} 0 & 1  \\ 1 & 0  \end{pmatrix},
    Y = \begin{pmatrix} 0 & -i \\ i & 0  \end{pmatrix},
    Z = \begin{pmatrix} 1 & 0  \\ 0 & -1 \end{pmatrix}.

**Initialization**

A Pauli object can be initialized in several ways:

    ``Pauli(obj)``
        where ``obj`` is a Pauli string, ``Pauli`` or
        :class:`~qiskit.quantum_info.ScalarOp` operator, or a Pauli
        gate or :class:`~qiskit.QuantumCircuit` containing only
        Pauli gates.

    ``Pauli((z, x, phase))``
        where ``z`` and ``x`` are boolean ``numpy.ndarrays`` and ``phase`` is
        an integer in ``[0, 1, 2, 3]``.

    ``Pauli((z, x))``
        equivalent to ``Pauli((z, x, 0))`` with trivial phase.

**String representation**

An :math:`n`-qubit Pauli may be represented by a string consisting of
:math:`n` characters from ``['I', 'X', 'Y', 'Z']``, and optionally phase
coefficient in ``['', '-i', '-', 'i']``. For example: ``'XYZ'`` or
``'-iZIZ'``.

In the string representation qubit-0 corresponds to the right-most
Pauli character, and qubit-:math:`(n-1)` to the left-most Pauli
character. For example ``'XYZ'`` represents
:math:`X\otimes Y \otimes Z` with ``'Z'`` on qubit-0,
``'Y'`` on qubit-1, and ``'X'`` on qubit-2.

The string representation can be converted to a ``Pauli`` using the
class initialization (``Pauli('-iXYZ')``). A ``Pauli`` object can be
converted back to the string representation using the
:meth:`to_label` method or ``str(pauli)``.

.. note::

    Using ``str`` to convert a ``Pauli`` to a string will truncate the
    returned string for large numbers of qubits while :meth:`to_label`
    will return the full string with no truncation. The default
    truncation length is 50 characters. The default value can be
    changed by setting the class ``__truncate__`` attribute to an integer
    value. If set to ``0`` no truncation will be performed.

**Array Representation**

The internal data structure of an :math:`n`-qubit Pauli is two
length-:math:`n` boolean vectors :math:`z \in \mathbb{Z}_2^N`,
:math:`x \in \mathbb{Z}_2^N`, and an integer :math:`q \in \mathbb{Z}_4`
defining the Pauli operator

.. math::

    P = (-i)^{q + z\cdot x} Z^z \cdot X^x.

The :math:`k`-th qubit corresponds to the :math:`k`-th entry in the
:math:`z` and :math:`x` arrays

.. math::

    \begin{aligned}
    P &= P_{n-1} \otimes ... \otimes P_{0} \\
    P_k &= (-i)^{z[k] * x[k]} Z^{z[k]}\cdot X^{x[k]}
    \end{aligned}

where ``z[k] = P.z[k]``, ``x[k] = P.x[k]`` respectively.

The :math:`z` and :math:`x` arrays can be accessed and updated using
the :attr:`z` and :attr:`x` properties respectively. The phase integer
:math:`q` can be accessed and updated using the :attr:`phase` property.

**Matrix Operator Representation**

Pauli's can be converted to :math:`(2^n, 2^n)`
:class:`~qiskit.quantum_info.Operator` using the :meth:`to_operator` method,
or to a dense or sparse complex matrix using the :meth:`to_matrix` method.

**Data Access**

The individual qubit Paulis can be accessed and updated using the ``[]``
operator which accepts integer, lists, or slices for selecting subsets
of Paulis. Note that selecting subsets of Pauli's will discard the
phase of the current Pauli.

For example

.. plot::
   :include-source:
   :nofigs:

    from qiskit.quantum_info import Pauli

    P = Pauli('-iXYZ')

    print('P[0] =', repr(P[0]))
    print('P[1] =', repr(P[1]))
    print('P[2] =', repr(P[2]))
    print('P[:] =', repr(P[:]))
    print('P[::-1] =', repr(P[::-1]))
2   z)(?P<coeff>[+-]?1?[ij]?)(?P<pauli>[IXYZ]*)r            ) z-i-ic                v  > [        U[        5      (       a$  UR                  UR                  UR                  pCnO[        U[
        5      (       a-  [        U5      S;  a  [        S5      eU R                  " U6 u  p#nO[        U[        5      (       a  U R                  U5      u  p#nOe[        U[        5      (       a  U R                  U5      u  p#nO;[        U[        [        45      (       a  U R                  U5      u  p#nO[        S5      eUR                   S   S:w  a  [        S5      e["        TU ]I  X#U5        g)a  Initialize the Pauli.

When using the symplectic array input data both z and x arguments must
be provided, however the first (z) argument can be used alone for string
label, Pauli operator, or :class:`.ScalarOp` input data.

Args:
    data (str or tuple or Pauli or ScalarOp): input data for Pauli. If input is
        a tuple it must be of the form ``(z, x)`` or ``(z, x, phase)`` where
        ``z`` and ``x`` are boolean Numpy arrays, and phase is an integer from
        :math:`\mathbb{Z}_4`.
        If input is a string, it must be a concatenation of a phase and a Pauli string
        (e.g. ``'XYZ', '-iZIZ'``) where a phase string is a combination of at most three
        characters from ``['+', '-', '']``, ``['1', '']``, and ``['i', 'j', '']`` in this order,
        e.g. ``''``, ``'-1j'`` while a Pauli string is 1 or more
        characters of ``'I'``, ``'X'``, ``'Y'``, or ``'Z'``,
        e.g. ``'Z'``, ``'XIYY'``.

Raises:
    QiskitError: if input array is invalid shape.
)r   r   zNInvalid input tuple for Pauli, input tuple must be `(z, x, phase)` or `(z, x)`zInvalid input data for Pauli.r   r   zInput is not a single PauliN)
isinstancer   _z_x_phasetuplelenr   _from_arraystr_from_labelr   _from_scalar_opr   r   _from_circuitshapesuper__init__)selfdatabase_zbase_x
base_phase	__class__s        h/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/quantum_info/operators/symplectic/pauli.pyr1   Pauli.__init__   s   , dI&&)-$''4;;JFJe$$4y&!d  *.)9)94)@&FJc"")-)9)9$)?&FJh'')-)=)=d)C&FJ~{;<<)-););D)A&FJ=>> <<?a;<<4    c                    g)z,Unique string identifier for operation type.pauli r2   s    r8   name
Pauli.name   s     r:   c                    g)zNumber of classical bits.r   r=   r>   s    r8   
num_clbitsPauli.num_clbits   s     r:   c                *    SU R                  5        S3$ )zDisplay representation.zPauli('z'))__str__r>   s    r8   __repr__Pauli.__repr__   s    (++r:   c                    U R                   (       a<  U R                  U R                   :  a"  X R                   * S R                  5       nUS-   $ U R                  5       $ )zPrint representation.Nz...)__truncate__
num_qubitsto_label)r2   fronts     r8   rE   Pauli.__str__   sO    43D3D!D+++-.779E5= }}r:   c                l    USL a  [        S5      eU R                  5       nUc  U$ UR                  USS9$ )NFz9unable to avoid copy while creating an array as requested)copy)
ValueError	to_matrixastype)r2   dtyperO   arrs       r8   	__array__Pauli.__array__   s=    5=XYYnnmsFE)FFr:   c                $    [        U5      U l        g)zSet the max number of Pauli characters to display before truncation/

Args:
    val (int): the number of characters.

.. note::

    Truncation will be disabled if the truncation value is set to 0.
N)intrI   )clsvals     r8   set_truncationPauli.set_truncation   s     s8r:   c                P    [        U[        5      (       d  gU R                  U5      $ )zTest if two Paulis are equal.F)r$   r   _eqr2   others     r8   __eq__Pauli.__eq__   s     %++xxr:   c                &   [        U[        5      (       d   [        U5      n[        R                  " U R
                  UR
                  :H  5      =(       a-    [        R                  " U R                  UR                  :H  5      $ ! [         a     gf = f)zReturn True if Pauli's are equivalent up to group phase.

Args:
    other (Pauli): an operator object.

Returns:
    bool: True if the Pauli's are equivalent up to group phase.
F)r$   r   r   npallr%   r&   r_   s     r8   equivPauli.equiv   sl     %''e vvdgg)*Jrvvdgg6I/JJ  s   B 
BBc                &    SU R                  5       0$ )zReturn settings.r3   )rK   r>   s    r8   settingsPauli.settings  s     ((r:   c                    [         R                  " U R                  U R                  U R                  R                  S9-
  S5      S   $ )z.Return the group phase exponent for the Pauli.rS      r   )rd   modr'   r   rS   r>   s    r8   phasePauli.phase  s8     vvdkkDMM8I8IM$JJANqQQr:   c                    [         R                  " XR                  U R                  R                  S9-   S5      U R                  S S & g )Nrl   rm   )rd   rn   r   r'   rS   )r2   values     r8   ro   rp     s5     DKK<M<M(N NPQRAr:   c                     U R                   S   $ )zThe x vector for the Pauli.r   r&   r>   s    r8   xPauli.x#       wwqzr:   c                (    XR                   SS S 24'   g Nr   rt   r2   rZ   s     r8   ru   rv   (      1r:   c                     U R                   S   $ )zThe z vector for the Pauli.r   r%   r>   s    r8   zPauli.z,  rw   r:   c                (    XR                   SS S 24'   g ry   r}   rz   s     r8   r~   r   1  r{   r:   c                    U R                   $ )z)Return the number of qubits in the Pauli.)rJ   r>   s    r8   __len__Pauli.__len__9  s    r:   c                    [        U[        [        R                  45      (       a  U/n[	        U R
                  U   U R                  U   45      $ )z;Return the unsigned Pauli group Pauli for subset of qubits.)r$   rX   rd   integerr   r~   ru   )r2   qubitss     r8   __getitem__Pauli.__getitem__=  sA     fsBJJ/00XFdffVndffVn566r:   c                    [        U[        5      (       d  [        U5      nUR                  U R                  SU4'   UR                  U R
                  SU4'   U R                  UR                  -   U l        g)z(Update the Pauli for a subset of qubits.r   N)r$   r   r~   r%   ru   r&   r'   )r2   r   rr   s      r8   __setitem__Pauli.__setitem__D  sX    %''%LE"WW6	"WW6	kkELL0r:   c                F   [        U[        [        R                  45      (       a  U/n[	        U5      S:X  a,  [        U R                  U R                  U R                  45      $ [        U5      U R                  S-
  :  a(  [        S[        U5       SU R                  S-
   S35      e[	        U5      U R                  :X  a  [        S5      e[        R                  " U R                  USS9n[        R                  " U R                  USS9n[        X#U R                  45      $ )a  Return a Pauli with qubits deleted.

Args:
    qubits (int or list): qubits to delete from Pauli.

Returns:
    Pauli: the resulting Pauli with the specified qubits removed.

Raises:
    QiskitError: if ind is out of bounds for the array size or
                 number of qubits.
r   r   z1Qubit index is larger than the number of qubits (>).z!Cannot delete all qubits of Pauli)axis)r$   rX   rd   r   r)   r   r%   r&   ro   maxrJ   r   delete)r2   r   r~   ru   s       r8   r   Pauli.deleteM  s     fsBJJ/00XFv;!$''477DJJ788v;1,,K=$//A"5!6b:  v;$//)ABBIIdggvA.IIdggvA.aDJJ'((r:   c                   [        U[        5      (       d  [        U5      nU R                  UR                  -   n[        [        R                  " U[
        S9[        R                  " U[
        S945      n[        U[        [        R                  45      (       a5  UR                  S:X  a  U/nO![        [        XUR                  -   5      5      n[        U5      UR                  :w  a%  [        S[        U5       SUR                   S35      e[        U5      UR                  S-
  :  a(  [        S[        U5       SUR                  S-
   S35      e[        UR                  5       Vs/ s H  oUU;  d  M
  UPM     nnXU'   X$U'   U$ s  snf )	a  Insert a Pauli at specific qubit value.

Args:
    qubits (int or list): qubits index to insert at.
    value (Pauli): value to insert.

Returns:
    Pauli: the resulting Pauli with the entries inserted.

Raises:
    QiskitError: if the insertion qubits are invalid.
rl   r   zJNumber of indices does not match number of qubits for the inserted Pauli (z!=)z9Index is too larger for combined Pauli number of qubits (r   r   )r$   r   rJ   rd   zerosboolrX   r   listranger)   r   r   )r2   r   rr   
ret_qubitsretr"   self_qubitss          r8   insertPauli.inserti  se    %''%LE __u'7'77
RXXj5rxx
RV7WXYfsBJJ/001$ eFU5E5E,EFGv;%***''*6{m2e6F6F5GqJ  v;!++K=#..1"4!5R9 
 #("7K"7QF?q"7KKF
 Ls   (	F5Fc                4    [        U R                  5       5      $ )z-Make hashable based on string representation.)hashrK   r>   s    r8   __hash__Pauli.__hash__  s    DMMO$$r:   c                j    U R                  U R                  U R                  U R                  S   5      $ )zConvert a Pauli to a string label.

.. note::

    The difference between `to_label` and :meth:`__str__` is that
    the later will truncate the output for large numbers of qubits.

Returns:
    str: the Pauli string label.
r   )	_to_labelr~   ru   r'   r>   s    r8   rK   Pauli.to_label  s'     ~~dffdffdkk!n==r:   c                h    U R                  U R                  U R                  U R                  S   US9$ )zConvert to a Numpy array or sparse CSR matrix.

Args:
    sparse (bool): if True return sparse CSR matrices, otherwise
                   return dense Numpy arrays (default: False).

Returns:
    array: The Pauli matrix.
r   )sparse)
_to_matrixr~   ru   r'   )r2   r   s     r8   rQ   Pauli.to_matrix  s+     tvvtvvt{{1~fMMr:   c                   SSK Jn  U R                  U R                  U R                  U R
                  S   SSS9u  p#[        U5      S:X  a+  [        5       [        5       [        5       [        5       S.U   nO[        U5      nU(       d  U$ [        U R                  [        U 5      S9nU* U-  S	-  Ul        UR!                  U[#        U R                  5      5        UR%                  5       $ )
z%Convert to Pauli circuit instruction.r   )piFT)
full_groupreturn_phaser   )IXYZ)r?   r   )mathr   r   r~   ru   r'   r)   r   r   r   r   r
   r   rJ   r+   global_phaseappendr   to_instruction)r2   r   r<   ro   gatecircuits         r8   r   Pauli.to_instruction  s    ~~FFDFFDKKNu4 & 
 u:?uwUW57KERDU#DK s4yA %v{QtU4??34%%''r:   c           	        > Uc  [        USS5      n[        U[        5      (       d  [        U5      n[        [        TU ]  XX4S95      $ )a*  Return the operator composition with another Pauli.

Args:
    other (Pauli): a Pauli object.
    qargs (list or None): Optional, qubits to apply dot product
                          on (default: None).
    front (bool): If True compose using right operator multiplication,
                  instead of left multiplication [default: False].
    inplace (bool): If True update in-place (default: False).

Returns:
    Pauli: The composed Pauli.

Raises:
    QiskitError: if other cannot be converted to an operator, or has
                 incompatible dimensions for specified subsystems.

.. note::
    Composition (``&``) by default is defined as `left` matrix multiplication for
    matrix operators, while :meth:`dot` is defined as `right` matrix
    multiplication. That is that ``A & B == A.compose(B)`` is equivalent to
    ``B.dot(A)`` when ``A`` and ``B`` are of the same type.

    Setting the ``front=True`` kwarg changes this to `right` matrix
    multiplication and is equivalent to the :meth:`dot` method
    ``A.dot(B) == A.compose(B, front=True)``.
Nqargsr   rL   inplace)getattrr$   r   r0   compose)r2   r`   r   rL   r   r7   s        r8   r   Pauli.compose  sF    < =E7D1E%''%LEUW_Uu_VWWr:   c                $    U R                  XSUS9$ )a=  Return the right multiplied operator self * other.

Args:
    other (Pauli): an operator object.
    qargs (list or None): Optional, qubits to apply dot product
                          on (default: None).
    inplace (bool): If True update in-place (default: False).

Returns:
    Pauli: The operator self * other.
Tr   )r   )r2   r`   r   r   s       r8   dot	Pauli.dot  s     ||EdG|LLr:   c                t   > [        U[        5      (       d  [        U5      n[        [        TU ]  U5      5      $ N)r$   r   r0   tensorr2   r`   r7   s     r8   r   Pauli.tensor  -    %''%LEUW^E*++r:   c                t   > [        U[        5      (       d  [        U5      n[        [        TU ]  U5      5      $ r   )r$   r   r0   expandr   s     r8   r   Pauli.expand   r   r:   c                4   > [        [        TU ]	  U5      5      $ r   )r   r0   	_multiplyr   s     r8   r   Pauli._multiply  s    UW&u-..r:   c                2   > [        [        TU ]	  5       5      $ r   )r   r0   	conjugater2   r7   s    r8   r   Pauli.conjugate      UW&())r:   c                2   > [        [        TU ]	  5       5      $ r   )r   r0   	transposer   s    r8   r   Pauli.transpose  r   r:   c                2   > [        [        TU ]	  5       5      $ r   r   r0   adjointr   s    r8   r   Pauli.adjoint  s    UW_&''r:   c                2   > [        [        TU ]	  5       5      $ )z Return the inverse of the Pauli.r   r   s    r8   inversePauli.inverse  s    UW_&''r:   c                   > Uc  [        USS5      n[        U[        5      (       d  [        U5      n[        TU ]  XS9n[        U5      S:X  a  US   $ U$ )zReturn True if the Pauli commutes with other.

Args:
    other (Pauli or PauliList): another Pauli operator.
    qargs (list): qubits to apply dot product on (default: None).

Returns:
    bool: True if Pauli's commute, False if they anti-commute.
Nr   r   r   r   )r   r$   r   r   r0   commutesr)   )r2   r`   r   r   r7   s       r8   r   Pauli.commutes  sY     =E7D1E%++%LEgu2s8q=q6M
r:   c                H    [         R                  " U R                  XS95      $ )zReturn True if other Pauli anticommutes with self.

Args:
    other (Pauli): another Pauli operator.
    qargs (list): qubits to apply dot product on (default: None).

Returns:
    bool: True if Pauli's anticommute, False if they commute.
r   )rd   logical_notr   )r2   r`   r   s      r8   anticommutesPauli.anticommutes,  s     ~~dmmEm?@@r:   c                   > Uc  [        USS5      nSSKJn  [        U[        [
        [        U45      (       d  [	        U5      n[	        [        TU ]!  XUS95      $ )ul  Performs either Heisenberg (default) or Schrödinger picture
evolution of the Pauli by a Clifford and returns the evolved Pauli.

Schrödinger picture evolution can be chosen by passing parameter ``frame='s'``.
This option yields a faster calculation.

Heisenberg picture evolves the Pauli as :math:`P^\prime = C^\dagger.P.C`.

Schrödinger picture evolves the Pauli as :math:`P^\prime = C.P.C^\dagger`.

Args:
    other (Pauli or Clifford or QuantumCircuit): The Clifford operator to evolve by.
    qargs (list): a list of qubits to apply the Clifford to.
    frame (string): ``'h'`` for Heisenberg (default) or ``'s'`` for
        Schrödinger framework.

Returns:
    Pauli: the Pauli :math:`C^\dagger.P.C` (Heisenberg picture)
    or the Pauli :math:`C.P.C^\dagger` (Schrödinger picture).

Raises:
    QiskitError: if the Clifford number of qubits and qargs don't match.
Nr   r   r   )r   frame)	r   1qiskit.quantum_info.operators.symplectic.cliffordr   r$   r   r   r   r0   evolve)r2   r`   r   r   r   r7   s        r8   r   Pauli.evolve8  sU    : =E7D1E 	O%%nh!OPP%LEUW^Ee^DEEr:   c                   [         R                  R                  U 5      nUc  [        SU  S35      e[         R                  US   =(       d    SR                  SS5      R                  SS5      R                  SS	5         n[        R                  " US
   R                  S5      [        R                  S9SSS2   nU[        S5      :H  n[        R                  " U[        S5      :H  U5      R                  SS5      n[        R                  " U[        S5      :H  U5      R                  SS5      n[        R                  " U[        R                  " U5      -   S-  /[        S9nXeU4$ )zReturn the symplectic representation of Pauli string.

Args:
    label (str): the Pauli string label.

Returns:
    BasePauli: the BasePauli corresponding to the label.

Raises:
    QiskitError: if Pauli string is not valid.
NzPauli string label "z" is not valid.coeffr    1+jr"   r<   asciirl   r   r   r   r   rm   )r   _VALID_LABEL_PATTERN	fullmatchr   _CANONICAL_PHASE_LABELreplacerd   
frombufferencodeuint8ord
logical_orreshapearraycount_nonzerorX   )labelmatch_ro   pauli_bytesysr5   r4   r6   s           r8   r,   Pauli._from_labele  s6    ++55e<> 4UG?KLL,,G_"++C4<<S"EMMcSVW

 mmF7O$:$:7$C288TUYWYUYZCH${c#h6;CCArJ{c#h6;CCArJXX(8(8(< <AB#N
z))r:   c                R   UR                   c  [        U S35      e[        R                  " SUR                   4[        S9n[        R                  " SUR                   4[        S9n[        R
                  " U R                  UR                  5      [        X25      -   S[        S9nX#U4$ )z%Convert a ScalarOp to BasePauli data.z is not an N-qubit identityr   rl   rm   )
rJ   r   rd   r   r   rn   _phase_from_complexr   r   rX   )rY   opr4   r5   r6   s        r8   r-   Pauli._from_scalar_op  s     == $?@AA1bmm,D91bmm,D9VV##BHH-0HH!SV

 z))r:   c                V   [        U[        5      (       a  U R                  UR                  S   5      $ [        U[        5      (       aF  [
        R                  " S//5      [
        R                  " S//5      [
        R                  " S/5      4$ [        U[        5      (       aF  [
        R                  " S//5      [
        R                  " S//5      [
        R                  " S/5      4$ [        U[        5      (       aF  [
        R                  " S//5      [
        R                  " S//5      [
        R                  " S/5      4$ [        U[        5      (       aF  [
        R                  " S//5      [
        R                  " S//5      [
        R                  " S/5      4$ [        S5      e)z.Convert a Pauli instruction to BasePauli data.r   FTr   zInvalid Pauli instruction.)r$   r
   r,   paramsr   rd   r   r   r   r   r   )rY   instrs     r8   _from_pauli_instructionPauli._from_pauli_instruction  s,    eY''??5<<?33eU##88eWI&5'(;RXXqc]JJeU##88eWI&4&(:BHHaSMIIeU##88dVH%rxx$'9288QC=HHeU##88dVH%rxx%	':BHHaSMII677r:   c                   [        U[        [        [        [        [
        45      (       a  U R                  U5      $ [        U[        5      (       a1  UR                  c  [        SUR                   35      eUR                  n[        [        [        R                  " SUR                  4[         S9[        R                  " SUR                  4[         S9[        R                  " S["        S95      5      nUR$                  (       a@  U R'                  [        R(                  " S[+        UR$                  5      -  5      5      Ul        UR.                   H  nUR0                  (       a"  [        SUR2                  R                   35      e[        UR2                  [4        [6        45      (       a  M]  [        U R9                  UR2                  5      6 nUc  M  UR:                   Vs/ s H  oQR=                  U5      R>                  PM     nnURA                  XFS9nM     URB                  URD                  URF                  4$ s  snf )z*Convert a Pauli circuit to BasePauli data.zCannot apply Instruction: r   rl   y              ?z.Cannot apply instruction with classical bits: r   )$r$   r
   r   r   r   r   r	  r   
definitionr   r?   r   r   rd   r   rJ   r   rX   r   r  expfloatro   r3   clbits	operationr   r	   r.   r   find_bitindexr   r%   r&   r'   )rY   r  r   inner
next_instrtupr   s          r8   r.   Pauli._from_circuit  s    eiueDEE..u55e[))'!$>uzzl"KLL$$E !U--.d;!U--.d;#&
 //rE%BTBT<U7U0VWCI ZZE||!DU__EYEYDZ[  eoo/?@@&(9(9%//(JK
)BG,,O,3^^C066,EO++j+>C   vvsvvszz)) Ps   #$H?c                $  ^ SSK Jn  Uc  Uc  U R                  5       $ U R                  m[	        X5      (       a%  [        UR                  5      mUR                  5       nUb  UT:  a  [        SU ST S35      eUmUc  [        [        U R                  5      5      nOQ[        U4S jU 5       5      (       a  [        S5      e[        [        U5      5      [        U5      :w  a  [        S5      e[        U 5      " S	T-  5      nUR                  XS
9$ )a  Apply a transpiler layout to this :class:`~.quantum_info.Pauli`

Args:
    layout: Either a :class:`~.TranspileLayout`, a list of integers or None.
            If both layout and num_qubits are none, a copy of the operator is
            returned.
    num_qubits: The number of qubits to expand the operator to. If not
        provided then if ``layout`` is a :class:`~.TranspileLayout` the
        number of the transpiler output circuit qubits will be used by
        default. If ``layout`` is a list of integers the permutation
        specified will be applied without any expansion. If layout is
        None, the operator will be expanded to the given number of qubits.

Returns:
    A new :class:`~.quantum_info.Pauli` with the provided layout applied
r   r   z%The input num_qubits is too small, a z% qubit layout cannot be applied to a z qubit operatorc              3  D   >#    U  H  oS :  =(       d    UT:  v   M     g7f)r   Nr=   ).0ru   n_qubitss     r8   	<genexpr>%Pauli.apply_layout.<locals>.<genexpr>  s     :6aq5)AM)6s    z>Provided layout contains indices outside the number of qubits.z+Provided layout contains duplicate indices.r   r   )qiskit.transpiler.layoutr   rO   rJ   r$   r)   _output_qubit_listfinal_index_layoutr   r   r   anysettyper   )r2   layoutrJ   r   new_opr  s        @r8   apply_layoutPauli.apply_layout  s   & 	=>j099;??f..6445H..0F!H$!;J< H$$,:_>  "H>%01F:6:::!"bcc3v;3v;.!"OPPdC(N+~~d~11r:   )r'   r   )r3   z6str | tuple | Pauli | ScalarOp | QuantumCircuit | None)NN)rZ   rX   )r`   r   returnr   )r'  dict)r   
int | listr'  r   )r   r)  rr   r   r'  r   )r'  r+   )F)r   r   r'  z
np.ndarray)NFF)
r`   r   r   list | NonerL   r   r   r   r'  r   )NF)r`   r   r   r*  r   r   r'  r   )r`   r   r'  r   )r`   zPauli | PauliListr   r*  r'  r   )r`   r   r   r*  r'  r   )Nh)r`   z!Pauli | Clifford | QuantumCircuitr   r*  r   zLiteral['h', 's']r'  r   )r#  z"TranspileLayout | list[int] | NonerJ   z
int | Noner'  r   )7__name__
__module____qualname____firstlineno____doc__rI   recompiler   r   r1   propertyr?   rB   rF   rE   rU   classmethodr[   ra   rf   ri   ro   setterru   r~   r   r   r   r   r   r   rK   rQ   r   r   r   r   r   r   r   r   r   r   r   r   r   staticmethodr,   r-   r	  r.   r%  __static_attributes____classcell__)r7   s   @r8   r   r   '   s   vr L::&RS"#111=*5 *5X    ,G 
$ 
$K  ) ) R R
 \\S S   XX    XX 71)8&X%>
N(0 ]b"X"X#."X>B"XUY"X	"X "XHM,
,
/**(( &
A "#&	'F0'F 'F !	'F
 
'F 'FZ * *6 	* 	* 8 8 %* %*P TX+28+2FP+2	+2 +2r:   r   )'r0  
__future__r   r1  typingr   r   numpyrd   qiskit.circuitr   r   qiskit.circuit.barrierr   qiskit.circuit.delayr	   (qiskit.circuit.library.generalized_gatesr
   %qiskit.circuit.library.standard_gatesr   r   r   r   qiskit.exceptionsr   $qiskit.quantum_info.operators.mixinsr   'qiskit.quantum_info.operators.scalar_opr   3qiskit.quantum_info.operators.symplectic.base_paulir   r   r   r   3qiskit.quantum_info.operators.symplectic.pauli_listr   r  r   r   r=   r:   r8   <module>rF     s[    # 	 )  6 * & > L L ) A < SJM8H2I H2X  r:   