
    z	ij                        S 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
Jr  SSKJr  SS	KJrJrJr  \" 5       rSSS
 jjr S     SS jjr    S       SS jjrg)z%
Methods to create random operators.
    )annotationsN)default_rng)QiskitError)OperatorStinespring   )random_cnotdihedral)random_cliffordrandom_paulirandom_pauli_listc                   Uc  [         nO7[        U[        R                  R                  5      (       a  UnO[        U5      n[        R                  " U 5      nSSKJn  UR                  R                  X2S9n[        XPU S9$ )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.
r   statsrandom_state
input_dimsoutput_dims)DEFAULT_RNG
isinstancenprandom	Generatorr   prodscipyr   unitary_grouprvsr   )dimsseedr   dimr   mats         ^/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/quantum_info/operators/random.pyrandom_unitaryr#       sj     |"	D"))--	.	."4(
''$-C



!
!#
!
ACCd;;    c                t   Uc  [         nO7[        U[        R                  R                  5      (       a  UnO[        U5      n[        R                  " U 5      nSSKJn  U(       a  [        R                  " XD4[        S9nOA[        R                  " UR                  R                  SXCS9R                  [        5      5      nXDS-
  -  S-  nUR                  R                  SXsS9nUR                  R                  SXsS9n	[        R                  " US5      u  pUS	U	-  -   XjU4'   US	U	-  -
  XkU
4'   [!        X`U S
9$ )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.
r   r   )dtyper   )scalesizer      g      ?y              ?r   )r   r   r   r   r   r   r   r   r   zeroscomplexdiagnormr   astypetril_indicesr   )r   	tracelessr   rngr    r   r!   num_tril	real_tril	imag_trilrowscolss               r"   random_hermitianr8   ;   s   $ |	D"))--	.	.$ ''$-Chhz1 ggejjnn13nIPPQXYZ QwA%H

SxJI

SxJIb)JD!BN2Ct!BN2CtCd;;r$   c                X   U c  Uc  [        S5      eU c  Un OUc  U n[        R                  " U 5      n[        R                  " U5      nUb  X$U-  :  a  XE-  nUS:  a  [        SU S35      eSSKJn  UR
                  R                  [        X%-  U5      US9n[        USS2SU24   XS	9$ )
am  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   rankr   d_ind_outr   unitarys           r"   random_quantum_channelr?   i   s    2 k1V
 	
  
		 77:DGGK E |tUl*|axE$'?@AA !!%%c$,&=D%QG wq%4%x(ZYYr$   )N)r   int | tupler    int | np.random.Generator | None)FN)r   r@   r1   boolr   rA   )NNNN)r   int | tuple | Noner   rC   r;   z
int | Noner   rA   )__doc__
__future__r   numpyr   numpy.randomr   qiskit.exceptionsr   qiskit.quantum_info.operatorsr   r   dihedral.randomr	   symplectic.randomr
   r   r   r   r#   r8   r?    r$   r"   <module>rM      s    #  $ ) ? 1 O Om<8 Z^+<
+<"&+<6V+<^ &*&*-1	1Z"1Z#1Z 1Z +	1Zr$   