
    z	i                        S r SSKJ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S jjr   S         SS jjrS rS rS rg)z
Random state generation.
    )annotations)LiteralN)default_rng)QiskitError)random_unitary   )Statevector)DensityMatrixc                   Uc  [         R                  R                  5       nO7[        U[         R                  R                  5      (       a  UnO[        U5      n[         R
                  " U 5      nUR                  U5      R                  [        5      nUSUR                  U5      -  -  nU[         R                  R                  U5      -  n[        X@S9$ )aN  Generator a random Statevector.

The statevector is sampled from the uniform distribution. This is the measure
induced by the Haar measure on unitary matrices.

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

Returns:
    Statevector: the random statevector.

Reference:
    K. Zyczkowski and H. Sommers (2001), "Induced measures in the space of mixed quantum states",
    `J. Phys. A: Math. Gen. 34 7111 <https://arxiv.org/abs/quant-ph/0012101>`__.
              ?dims)nprandomr   
isinstance	Generatorprodstandard_normalastypecomplexlinalgnormr	   )r   seedrngdimvecs        [/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/quantum_info/states/random.pyrandom_statevectorr      s    ( |ii##%	D"))--	.	.$
''$-C


c
"
)
)'
2C2##C(((C299>>#Cs&&    c                    [         R                  " U 5      nUc  UnUS:X  a  [        XAU5      nO!US:X  a  [        XAU5      nO[	        SU 35      e[        XPS9$ )a|  Generator a random DensityMatrix.

Args:
    dims (int or tuple): the dimensions of the DensityMatrix.
    rank (int or None): Optional, the rank of the density matrix.
                        The default value is full-rank.
    method (string): Optional. The method to use.
        'Hilbert-Schmidt': (Default) sample from the Hilbert-Schmidt metric.
        'Bures': sample from the Bures metric.
    seed (int or np.random.Generator): Optional. Set a fixed seed or
                                       generator for RNG.

Returns:
    DensityMatrix: the random density matrix.

Raises:
    QiskitError: if the method is not valid.
Hilbert-SchmidtBureszError: unrecognized method r   )r   r   _random_density_hs_random_density_buresr   r
   )r   rankmethodr   r   rhos         r   random_density_matrixr(   ?   sb    2 ''$-C|"" D1	7	#Ct47x@AA((r   c                    Uc  [         R                  R                  5       nO7[        U[         R                  R                  5      (       a  UnO[        U5      nUR                  X4S9UR                  X4S9S-  -   nU$ )a]  Return a normally distributed complex random matrix.

Args:
    nrow (int): number of rows in output matrix.
    ncol (int): number of columns in output matrix.
    seed(int or np.random.Generator): default rng.

Returns:
    ndarray: A complex rectangular matrix where each real and imaginary
        entry is sampled from the normal distribution.
)sizer   )r   r   r   r   r   normal)nrowncolr   r   ginibres        r   _ginibre_matrixr/   e   so     |ii##%	D"))--	.	.$jjtlj+cjjtlj.Kb.PPGNr   c                    [        XU5      nUR                  UR                  5       R                  5      nU[        R
                  " U5      -  $ )aG  
Generate a random density matrix from the Hilbert-Schmidt metric.

Args:
    dim (int): the dimensions of the density matrix.
    rank (int or None): the rank of the density matrix. The default
        value is full-rank.
    seed (int or np.random.Generator): default rng.

Returns:
    ndarray: rho (N,N)  a density matrix.
)r/   dotconjTr   trace)r   r%   r   mats       r   r#   r#   |   s;     #T
*C
''#((*,,
C#r   c                   [         R                  " U 5      [        XS9R                  -   nUR	                  [        XU5      5      nUR	                  UR                  5       R                  5      nU[         R                  " U5      -  $ )a7  Generate a random density matrix from the Bures metric.

Args:
    dim (int): the length of the density matrix.
    rank (int or None): the rank of the density matrix. The default
        value is full-rank.
    seed (int or np.random.Generator): default rng.

Returns:
    ndarray: rho (N,N) a density matrix.
)r   )	r   eyer   datar1   r/   r2   r3   r4   )r   r%   r   densityr5   s        r   r$   r$      sa     ffSkN3:???G
++oc6
7C
''#((*,,
C#r   )N)r   int | tupler    int | np.random.Generator | Nonereturnr	   )Nr!   N)
r   r:   r%   z
int | Noner&   z#Literal['Hilbert-Schmidt', 'Bures']r   r;   r<   r
   )__doc__
__future__r   typingr   numpyr   numpy.randomr   qiskit.exceptionsr   $qiskit.quantum_info.operators.randomr   statevectorr	   densitymatrixr
   r   r(   r/   r#   r$    r   r   <module>rG      s    #   $ ) ? $ ( AE'
'=''H 2C-1	#)
#)
#) 0#) +	#)
 #)L.$r   