§
    º³Ùgj  ã                  ó¢   — d Z ddlmZ ddlZddlmZ ddlmZ ddl	m
Z
mZ ddlmZ dd	lmZmZmZ  e¦   «         Zddd„Z	 ddd„Z	 	 	 	 ddd„ZdS )z%
Methods to create random operators.
é    )ÚannotationsN)Údefault_rng)ÚQiskitError)ÚOperatorÚStinespringé   )Úrandom_cnotdihedral)Úrandom_cliffordÚrandom_pauliÚrandom_pauli_listÚdimsúint | tupleÚseedú int | np.random.Generator | Nonec                ó  — |€t           }n1t          |t          j        j        ¦  «        r|}nt          |¦  «        }t          j        | ¦  «        }ddlm} |j	         
                    ||¬¦  «        }t          || | ¬¦  «        S )ak  Return a random unitary Operator.

    The operator is sampled from the unitary Haar measure.

    Args:
        dims (int or tuple): the input dimensions of the Operator.
        seed (int or np.random.Generator): Optional. Set a fixed seed or
                                           generator for RNG.

    Returns:
        Operator: a unitary operator.
    Nr   ©Ústats©Úrandom_state©Ú
input_dimsÚoutput_dims)ÚDEFAULT_RNGÚ
isinstanceÚnpÚrandomÚ	Generatorr   ÚprodÚscipyr   Úunitary_groupÚrvsr   )r   r   r   Údimr   Úmats         úZ/granary/edev/quantum/lib/python3.11/site-packages/qiskit/quantum_info/operators/random.pyÚrandom_unitaryr%       sŠ   € ð €|Ý"ˆˆÝ	�D�"œ)Ô-Ñ	.Ô	.ð )Øˆˆå" 4Ñ(Ô(ˆå
Œ'�$‰-Œ-€CØÐÐÐÐÐà
Ô
×
!Ò
! #°LÐ
!Ñ
AÔ
A€CÝ�C D°dÐ;Ñ;Ô;Ð;ó    FÚ	tracelessÚboolc                óŒ  — |€t           }n1t          |t          j        j        ¦  «        r|}nt          |¦  «        }t          j        | ¦  «        }ddlm} |rt          j	        ||ft          ¬¦  «        }nGt          j        |j                             d||¬¦  «                             t          ¦  «        ¦  «        }||dz
  z  dz  }|j                             d||¬¦  «        }|j                             d||¬¦  «        }	t          j        |d	¦  «        \  }
}|d
|	z  z   ||
|f<   |d
|	z  z
  |||
f<   t!          || | ¬¦  «        S )a$  Return a random hermitian Operator.

    The operator is sampled from Gaussian Unitary Ensemble.

    Args:
        dims (int or tuple): the input dimension of the Operator.
        traceless (bool): Optional. If True subtract diagonal entries to
                          return a traceless hermitian operator
                          (Default: False).
        seed (int or np.random.Generator): Optional. Set a fixed seed or
                                           generator for RNG.

    Returns:
        Operator: a Hermitian operator.
    Nr   r   )Údtyper   )ÚscaleÚsizer   é   g      à?éÿÿÿÿy              ð?r   )r   r   r   r   r   r   r   r   r   ÚzerosÚcomplexÚdiagÚnormr!   ÚastypeÚtril_indicesr   )r   r'   r   Úrngr"   r   r#   Únum_trilÚ	real_trilÚ	imag_trilÚrowsÚcolss               r$   Úrandom_hermitianr;   ;   sQ  € ð$ €|ÝˆˆÝ	�D�"œ)Ô-Ñ	.Ô	.ð  Øˆˆå˜$ÑÔˆõ Œ'�$‰-Œ-€CØÐÐÐÐÐàð [ÝŒh˜˜S�z­Ð1Ñ1Ô1ˆˆõ Œg�e”j—n’n¨1°3ÀS�nÑIÔI×PÒPÕQXÑYÔYÑZÔZˆð �s˜Q‘w‘ AÑ%€HØ”
—’ S¨xÀc�ÑJÔJ€IØ”
—’ S¨xÀc�ÑJÔJ€Iå”  bÑ)Ô)�J€Dˆ$Ø! B¨¡NÑ2€CˆˆtˆÑØ! B¨¡NÑ2€CˆˆtˆÑÝ�C D°dÐ;Ñ;Ô;Ð;r&   r   úint | tuple | Noner   Úrankú
int | Nonec                ó~  — | €|€t          d¦  «        ‚| €|} n|€| }t          j        | ¦  «        }t          j        |¦  «        }|�	|||z  k    r||z  }|dk     rt          d|› d�¦  «        ‚ddlm} |j                             t          ||z  |¦  «        |¬¦  «        }t          |dd…d|…f         | |¬	¦  «        S )
a¡  Return a random CPTP quantum channel.

    This constructs the Stinespring operator for the quantum channel by
    sampling a random isometry from the unitary Haar measure.

    Args:
        input_dims (int or tuple): the input dimension of the channel.
        output_dims (int or tuple): the input dimension of the channel.
        rank (int): Optional. The rank of the quantum channel Choi-matrix.
        seed (int or np.random.Generator): Optional. Set a fixed seed or
                                           generator for RNG.

    Returns:
        Stinespring: a quantum channel operator.

    Raises:
        QiskitError: if rank or dimensions are invalid.
    NzHNo dimensions specified: input_dims and output_dims cannot both be None.r   zRank z must be greater than 0.r   r   r   r   )	r   r   r   r   r   r    r!   Úmaxr   )r   r   r=   r   Úd_inÚd_outr   Úunitarys           r$   Úrandom_quantum_channelrD   i   s  € ð2 Ð˜kÐ1ÝØVñ
ô 
ð 	
ð ÐØ ˆ
ˆ
Ø	Ð	Ø ˆåŒ7�:ÑÔ€DÝŒG�KÑ Ô €Eð €|�t˜d U™lÒ*Ð*Ø�e‰|ˆØˆa‚x€xÝÐ@ $Ð@Ð@Ð@ÑAÔAÐAØÐÐÐÐÐð Ô!×%Ò%¥c¨$°©,¸Ñ&=Ô&=ÈDÐ%ÑQÔQ€Gõ �w˜q˜q˜q % 4 %˜xÔ(°ZÈ[ÐYÑYÔYÐYr&   )N)r   r   r   r   )FN)r   r   r'   r(   r   r   )NNNN)r   r<   r   r<   r=   r>   r   r   )Ú__doc__Ú
__future__r   Únumpyr   Únumpy.randomr   Úqiskit.exceptionsr   Úqiskit.quantum_info.operatorsr   r   Údihedral.randomr	   Úsymplectic.randomr
   r   r   r   r%   r;   rD   © r&   r$   ú<module>rN      s  ððð ð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø $Ð $Ð $Ð $Ð $Ð $à )Ð )Ð )Ð )Ð )Ð )Ø ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?ð 1Ð 0Ð 0Ð 0Ð 0Ð 0Ø OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ Oàˆk‰mŒm€ð<ð <ð <ð <ð <ð8 Z^ð+<ð +<ð +<ð +<ð +<ð^ &*Ø&*ØØ-1ð	1Zð 1Zð 1Zð 1Zð 1Zð 1Zð 1Zr&   