§
    º³ÙgÆ  ã                  ó”   — d Z ddlm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 dd	lmZ dd
lmZ 	 ddd„Z	 	 	 ddd„Zd„ Zd„ Zd„ ZdS ) z
Random state generation.
é    )Úannotations)ÚLiteralN)Údefault_rng)ÚQiskitError)Úrandom_unitaryé   )ÚStatevector)ÚDensityMatrixÚdimsúint | tupleÚseedú int | np.random.Generator | NoneÚreturnr	   c                óÄ  — |€t           j                             ¦   «         }n1t          |t           j        j        ¦  «        r|}nt          |¦  «        }t          j        | ¦  «        }|                     |¦  «                             t          ¦  «        }|d|                     |¦  «        z  z  }|t           j	         
                    |¦  «        z  }t          || ¬¦  «        S )a~  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>`__.
    Nù              ð?©r   )ÚnpÚrandomr   Ú
isinstanceÚ	GeneratorÚprodÚstandard_normalÚastypeÚcomplexÚlinalgÚnormr	   )r   r   ÚrngÚdimÚvecs        úW/granary/edev/quantum/lib/python3.11/site-packages/qiskit/quantum_info/states/random.pyÚrandom_statevectorr!      s¿   € ð( €|ÝŒi×#Ò#Ñ%Ô%ˆˆÝ	�D�"œ)Ô-Ñ	.Ô	.ð  Øˆˆå˜$ÑÔˆå
Œ'�$‰-Œ-€CØ
×
Ò
˜cÑ
"Ô
"×
)Ò
)­'Ñ
2Ô
2€CØˆ2�×#Ò# CÑ(Ô(Ñ(Ñ(€CØ�2Œ9�>Š>˜#ÑÔÑ€CÝ�s Ð&Ñ&Ô&Ð&ó    úHilbert-SchmidtÚrankú
int | NoneÚmethodú#Literal['Hilbert-Schmidt', 'Bures']r
   c                óØ   — t          j        | ¦  «        }|€|}|dk    rt          |||¦  «        }n*|dk    rt          |||¦  «        }nt	          d|› �¦  «        ‚t          || ¬¦  «        S )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.
    Nr#   ÚBureszError: unrecognized method r   )r   r   Ú_random_density_hsÚ_random_density_buresr   r
   )r   r$   r&   r   r   Úrhos         r    Úrandom_density_matrixr-   ?   s‚   € õ2 Œ'�$‰-Œ-€CØ€|ØˆàÐ"Ò"Ð"Ý   d¨DÑ1Ô1ˆˆØ	�7Ò	Ð	Ý# C¨¨tÑ4Ô4ˆˆåÐ@¸Ð@Ð@ÑAÔAÐAÝ˜ 4Ð(Ñ(Ô(Ð(r"   c                ó  — |€t           j                             ¦   «         }n1t          |t           j        j        ¦  «        r|}nt          |¦  «        }|                     | |f¬¦  «        |                     | |f¬¦  «        dz  z   }|S )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.
    N)Úsizer   )r   r   r   r   r   Únormal)ÚnrowÚncolr   r   Úginibres        r    Ú_ginibre_matrixr4   e   s�   € ð €|ÝŒi×#Ò#Ñ%Ô%ˆˆÝ	�D�"œ)Ô-Ñ	.Ô	.ð  Øˆˆå˜$ÑÔˆà�jŠj˜t T˜lˆjÑ+Ô+¨c¯jªj¸tÀT¸l¨jÑ.KÔ.KÈbÑ.PÑP€GØ€Nr"   c                óª   — t          | ||¦  «        }|                     |                     ¦   «         j        ¦  «        }|t	          j        |¦  «        z  S )ak  
    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.
    )r4   ÚdotÚconjÚTr   Útrace)r   r$   r   Úmats       r    r*   r*   |   sC   € õ ˜#˜t TÑ
*Ô
*€CØ
�'Š'�#—(’(‘*”*”,Ñ
Ô
€CØ•”˜#‘”ÑÐr"   c                ó&  — t          j        | ¦  «        t          | |¬¦  «        j        z   }|                     t          | ||¦  «        ¦  «        }|                     |                     ¦   «         j        ¦  «        }|t          j        |¦  «        z  S )aW  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   Údatar6   r4   r7   r8   r9   )r   r$   r   Údensityr:   s        r    r+   r+   Ž   sq   € õ Œf�S‰kŒk�N¨3°TÐ:Ñ:Ô:Ô?Ñ?€GØ
�+Š+•o c¨4°Ñ6Ô6Ñ
7Ô
7€CØ
�'Š'�#—(’(‘*”*”,Ñ
Ô
€CØ•”˜#‘”ÑÐr"   )N)r   r   r   r   r   r	   )Nr#   N)
r   r   r$   r%   r&   r'   r   r   r   r
   )Ú__doc__Ú
__future__r   Útypingr   Únumpyr   Únumpy.randomr   Úqiskit.exceptionsr   Ú$qiskit.quantum_info.operators.randomr   Ústatevectorr	   Údensitymatrixr
   r!   r-   r4   r*   r+   © r"   r    ú<module>rI      s  ððð ð #Ð "Ð "Ð "Ð "Ð "Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ø $Ð $Ð $Ð $Ð $Ð $à )Ð )Ð )Ð )Ð )Ð )Ø ?Ð ?Ð ?Ð ?Ð ?Ð ?Ø $Ð $Ð $Ð $Ð $Ð $Ø (Ð (Ð (Ð (Ð (Ð (ð AEð'ð 'ð 'ð 'ð 'ðH Ø2CØ-1ð	#)ð #)ð #)ð #)ð #)ðLð ð ð.ð ð ð$ð ð ð ð r"   