
    z	i                        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  SSKJr  \(       a  SSK
Jr   " S S\5      r\" \5        g)z1
Chi-matrix representation of a Quantum Channel.
    )annotationsN)TYPE_CHECKING)_numpy_compat)QuantumCircuit)Instruction)QiskitError)QuantumChannel)Choi)SuperOp)_to_chi)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$ )Chi(   u  Pauli basis Chi-matrix representation of a quantum channel.

The Chi-matrix representation of an :math:`n`-qubit quantum channel
:math:`\mathcal{E}` is a matrix :math:`\chi` such that the evolution of a
:class:`~qiskit.quantum_info.DensityMatrix` :math:`\rho` is given by

.. math::

    \mathcal{E}(ρ) = \frac{1}{2^n} \sum_{i, j} \chi_{i,j} P_i ρ P_j

where :math:`[P_0, P_1, ..., P_{4^{n}-1}]` is the :math:`n`-qubit Pauli basis in
lexicographic order. It is related to the :class:`Choi` representation by a change
of basis of the Choi-matrix into the Pauli basis. The :math:`\frac{1}{2^n}`
in the definition above is a normalization factor that arises from scaling the
Pauli basis to make it orthonormal.

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  pVXV:w  a  [        S5      eU(       a  [        R                  " U5      nU(       a  [        R                  " U5      nUc'  Uc$  [        [        R                  " U5      5      nXX-  nOUc  UW-  nOUc  UW-  nWW-  U: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 quantum channel Chi-matrix 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 Chi-matrix.

Additional Information:
    If the input or output dimensions are None, they will be
    automatically determined from the input data. The Chi matrix
    representation is only valid for N-qubit channels.
)dtypezInvalid Chi-matrix input.Nz#Invalid shape for Chi-matrix input._channel_repOperator   z#Input is not an n-qubit Chi matrix.)
num_qubits)
isinstancelistnpndarrayasarraycomplexshaper   prodintmathsqrtr   r   r   _init_instruction_init_transformerdimgetattrr   _data
input_dimsoutput_dimslog2super__init__)selfdatar)   r*   chi_matdim_ldim_r	input_dim
output_dimrepr   	__class__s              c/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/quantum_info/operators/channel/chi.pyr-   Chi.__init__A   s   0 dT2::.//jjW5G"==LE~!"=>>GGJ/	WWZ0
"z'9 5!12
!/	#!Z/	$"i/
:%.!"GHH /
 $ =>> 006 --d3$(HH!I$
;Cc::yEG!!__.
""..09-.
j=I%)@CDD8    c                l    U R                   R                  n[        R                  " U R                   XS9$ )N)r   copy)r/   r   r   array)r.   r   r;   s      r7   	__array__Chi.__array__   s$    		xx		::r9   c                ^    U R                   U R                  U R                   U R                  4$ )z%Return the shape for bipartite matrix)
_input_dim_output_dimr.   s    r7   _bipartite_shapeChi._bipartite_shape   s'     !1!14??DDTDTUUr9   c                6    [        U 5      R                  X5      $ N)r   _evolve)r.   stateqargss      r7   rG   Chi._evolve   s    t}$$U22r9   c                F    [        [        U 5      R                  5       5      $ rF   )r   r
   	conjugaterB   s    r7   rL   Chi.conjugate   s     4:'')**r9   c                F    [        [        U 5      R                  5       5      $ rF   )r   r
   	transposerB   s    r7   rO   Chi.transpose   s    4:'')**r9   c                F    [        [        U 5      R                  5       5      $ rF   )r   r
   adjointrB   s    r7   rR   Chi.adjoint   s    4:%%'((r9   c                    Uc  [        USS 5      nUb"  [        [        U 5      R                  XUS95      $ [        [	        U 5      R                  XS95      $ )NrI   )rI   front)rU   )r'   r   r   composer
   )r.   otherrI   rU   s       r7   rV   Chi.compose   sY    =E7D1Ewt},,Uu,MNN 4:%%e%9::r9   c                d    [        U[        5      (       d  [        U5      nU R                  X5      $ rF   r   r   _tensorr.   rW   s     r7   tensor
Chi.tensor   s'    %%%JE||D((r9   c                d    [        U[        5      (       d  [        U5      nU R                  X5      $ rF   rZ   r\   s     r7   expand
Chi.expand   s'    %%%JE||E((r9   c                    [         R                  " U5      nUR                  R                  UR                  5      Ul        [        R
                  " UR                  UR                  5      Ul        U$ rF   )_copyr;   	_op_shaper]   r   kronr(   r/   )clsabrets       r7   r[   Chi._tensor   sH    jjm**1;;7GGAGGQVV,	
r9    )NN)r/   zLQuantumCircuit | circuit.instruction.Instruction | BaseOperator | np.ndarrayr)   int | tuple | Noner*   rl   rF   )NF)rW   r   rI   zlist | NonerU   boolreturnr   )rW   r   rn   r   )__name__
__module____qualname____firstlineno____doc__r-   r   COPY_ONLY_IF_NEEDEDr=   propertyrC   rG   rL   rO   rR   rV   r]   r`   classmethodr[   __static_attributes____classcell__)r6   s   @r7   r   r   (   s    6 *.*.	D9ZD9 'D9 (	D9 D9L #)J)J ; V V3++);)
)
  r9   r   ) rs   
__future__r   r;   rc   r"   typingr   numpyr   qiskitr   qiskit.circuit.quantumcircuitr   qiskit.circuit.instructionr   qiskit.exceptionsr   5qiskit.quantum_info.operators.channel.quantum_channelr	   *qiskit.quantum_info.operators.channel.choir
   -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   rk   r9   r7   <module>r      sX    #        8 2 ) P ; A I A DS. Sn  r9   