
    z	in                        S r SSKJr  SSKrSSK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	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  \(       a  SSK
Jr   " S S\5      r\" \5        g)zB
Pauli Transfer Matrix (PTM) representation of a Quantum Channel.
    )annotationsN)TYPE_CHECKING)_numpy_compat)QuantumCircuit)Instruction)QiskitError)QuantumChannel)SuperOp)_to_ptm)generate_apidocs)BaseOperator)circuitc                     ^  \ rS rSrSr  S     SU 4S jjjrS\R                  4S jr\	S 5       r
SS jrS rS	 rS
 rSSS jjrSS jrSS jr\S 5       rSrU =r$ )PTM'   a  Pauli Transfer Matrix (PTM) representation of a Quantum Channel.

The PTM representation of an :math:`n`-qubit quantum channel
:math:`\mathcal{E}` is an :math:`n`-qubit :class:`SuperOp` :math:`R`
defined with respect to vectorization in the Pauli basis instead of
column-vectorization. The elements of the PTM :math:`R` are
given by

.. math::

    R_{i,j} = \frac{1}{2^n} \mbox{Tr}\left[P_i \mathcal{E}(P_j) \right]

where :math:`[P_0, P_1, ..., P_{4^{n}-1}]` is the :math:`n`-qubit Pauli basis in
lexicographic order.

Evolution of a :class:`~qiskit.quantum_info.DensityMatrix`
:math:`\rho` with respect to the PTM is given by

.. math::

    |\mathcal{E}(\rho)\rangle\!\rangle_P = S_P |\rho\rangle\!\rangle_P

where :math:`|A\rangle\!\rangle_P` denotes vectorization in the Pauli basis
:math:`\langle i | A\rangle\!\rangle_P = \sqrt{\frac{1}{2^n}} \mbox{Tr}[P_i A]`.

See reference [1] for further details.

References:
    1. C.J. Wood, J.D. Biamonte, D.G. Cory, *Tensor networks and graphical calculus
       for open quantum systems*, Quant. Inf. Comp. 15, 0579-0811 (2015).
       `arXiv:1111.6950 [quant-ph] <https://arxiv.org/abs/1111.6950>`_
Nc                  > [        U[        [        R                  45      (       a  [        R                  " U[
        S9nUR                  u  pVU(       a  [        R                  " U5      nO[        [        R                  " U5      5      nU(       a  [        R                  " U5      nO[        [        R                  " U5      5      nUS-  U:w  d  US-  U:w  d  Xx:w  a  [        S5      eO[        U[        [        45      (       a  [        R                  " U5      nOU R!                  U5      nUR"                  u  px[%        USS5      n	['        XR(                  Xx5      nUc  UR+                  5       nUc  UR-                  5       n[        [        R.                  " U5      5      n
SU
-  U:w  d  Xx:w  a  [        S5      e[0        TU ]e  XJS9  g)	a  Initialize a PTM quantum channel operator.

Args:
    data: data to initialize superoperator.
    input_dims: the input subsystem dimensions.
    output_dims: the output subsystem dimensions.

Raises:
    QiskitError: if input data is not an N-qubit channel or
                 cannot be initialized as a PTM.

Additional Information:
    If the input or output dimensions are None, they will be
    automatically determined from the input data. The PTM
    representation is only valid for N-qubit channels.
)dtype   zInvalid shape for PTM matrix._channel_repOperatorNz.Input is not an n-qubit Pauli transfer matrix.)
num_qubits)
isinstancelistnpndarrayasarraycomplexshapeprodintmathsqrtr   r   r   r
   _init_instruction_init_transformerdimgetattrr   _data
input_dimsoutput_dimslog2super__init__)selfdatar(   r)   ptmdoutdin	input_dim
output_dimrepr   	__class__s              c/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/quantum_info/operators/channel/ptm.pyr,   PTM.__init__I   ss   0 dT2::.//**T1C		IDGGJ/			#/	WWZ0
 41
1}$	1(;y?V!"ABB @W
 $ =>> 006 --d3$(HH!I$
;C#zz9AC!!__.
""..09-.
j=I%)@NOO4    c                v    Uc  U R                   R                  OUn[        R                  " U R                   XS9$ )N)r   copy)r.   r   r   array)r-   r   r:   s      r6   	__array__PTM.__array__   s*    #(=		exx		::r8   c                ^    U R                   U R                   U R                  U R                  4$ )z%Return the shape for bipartite matrix)_output_dim
_input_dimr-   s    r6   _bipartite_shapePTM._bipartite_shape   s'       $"2"2DOOT__UUr8   c                6    [        U 5      R                  X5      $ N)r
   _evolve)r-   stateqargss      r6   rF   PTM._evolve   s    t}$$U22r8   c                F    [        [        U 5      R                  5       5      $ rE   )r   r
   	conjugaterA   s    r6   rK   PTM.conjugate   s     74=**,--r8   c                F    [        [        U 5      R                  5       5      $ rE   )r   r
   	transposerA   s    r6   rN   PTM.transpose   s    74=**,--r8   c                F    [        [        U 5      R                  5       5      $ rE   )r   r
   adjointrA   s    r6   rQ   PTM.adjoint   s    74=((*++r8   c                   Uc  [        USS 5      nUb"  [        [        U 5      R                  XUS95      $ [	        U[        5      (       d  [        U5      nU R
                  R                  UR
                  X#5      nUR                  5       nUR                  5       nU(       a,  [        R                  " U R                  UR                  5      nO+[        R                  " UR                  U R                  5      n[        XuU5      nXHl        U$ )NrH   )rH   front)r&   r   r
   composer   	_op_shapedims_rdims_lr   dotr'   r.   )	r-   otherrH   rT   	new_shaper(   r)   r.   rets	            r6   rU   PTM.compose   s    =E7D1Ewt},,Uu,MNN %%%JENN**5??EI	%%'
&&(66$**ejj1D66%**djj1D$K0!
r8   c                d    [        U[        5      (       d  [        U5      nU R                  X5      $ rE   r   r   _tensorr-   rZ   s     r6   tensor
PTM.tensor   s'    %%%JE||D((r8   c                d    [        U[        5      (       d  [        U5      nU R                  X5      $ rE   r_   ra   s     r6   expand
PTM.expand   s'    %%%JE||E((r8   c                    [         R                  " U5      nUR                  R                  UR                  5      Ul        [        R
                  " UR                  UR                  5      Ul        U$ rE   )_copyr:   rV   rb   r   kronr'   r.   )clsabr\   s       r6   r`   PTM._tensor   sH    jjm**1;;7GGAGGQVV,	
r8    )NN)r.   zLQuantumCircuit | circuit.instruction.Instruction | BaseOperator | np.ndarrayr(   int | tuple | Noner)   ro   rE   )NF)rZ   r   rH   zlist | NonerT   boolreturnr   )rZ   r   rq   r   )__name__
__module____qualname____firstlineno____doc__r,   r   COPY_ONLY_IF_NEEDEDr<   propertyrB   rF   rK   rN   rQ   rU   rb   re   classmethodr`   __static_attributes____classcell__)r5   s   @r6   r   r   '   s    H *.*.	>5Z>5 '>5 (	>5 >5@ #)J)J ; V V3..,()
)
  r8   r   )rv   
__future__r   r:   rh   r!   typingr   numpyr   qiskitr   qiskit.circuit.quantumcircuitr   qiskit.circuit.instructionr   qiskit.exceptionsr   5qiskit.quantum_info.operators.channel.quantum_channelr	   -qiskit.quantum_info.operators.channel.superopr
   5qiskit.quantum_info.operators.channel.transformationsr   $qiskit.quantum_info.operators.mixinsr   +qiskit.quantum_info.operators.base_operatorr   r   r   rn   r8   r6   <module>r      sU    #        8 2 ) P A I A Da. aJ  r8   