o
    +< i  ã                	   @   sD  d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZmZmZ G dd„ dƒZed	ed
d	ƒddZeƒ Ze de
ddgddggƒ¡ e de
ddgddggƒ¡ e de
ddgddggƒ¡ e de
ddgddggƒ¡ e de
ddgddggƒ¡ e de
ddgddggƒ¡ e de
de gedggƒ¡ e de
ddgdd
ggƒ¡ e de
ddgdeggƒ¡ e de
ddgdeee d ƒggƒ¡ e dee
ddgdd
ggƒ ¡ e de
ddgdd
ggƒ¡ e de
g d¢g d¢g d¢g d¢gƒ¡ e d ee
ddgdd
ggƒ ¡ e d!e
edgde ggƒ¡ d"S )#z7A cache for storing small matrices in multiple formats.é    )ÚIÚRationalÚpi)ÚPow)Úexp)ÚMatrix)Úto_sympyÚto_numpyÚto_scipy_sparsec                   @   sJ   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )ÚMatrixCachea  A cache for small matrices in different formats.

    This class takes small matrices in the standard ``sympy.Matrix`` format,
    and then converts these to both ``numpy.matrix`` and
    ``scipy.sparse.csr_matrix`` matrices. These matrices are then stored for
    future recovery.
    Úcomplexc                 C   s   i | _ || _d S ©N)Ú_cacheÚdtype)Úselfr   © r   ú\/home/app/PyTorch/.pytorch/lib/python3.10/site-packages/sympy/physics/quantum/matrixcache.pyÚ__init__   s   
zMatrixCache.__init__c                 C   sp   z|   ||¡ W n	 ty   Y nw z|  ||¡ W n	 ty#   Y nw z	|  ||¡ W dS  ty7   Y dS w )zìCache a matrix by its name.

        Parameters
        ----------
        name : str
            A descriptive name for the matrix, like "identity2".
        m : list of lists
            The raw matrix data as a SymPy Matrix.
        N)Ú_sympy_matrixÚImportErrorÚ_numpy_matrixÚ_scipy_sparse_matrix©r   ÚnameÚmr   r   r   Úcache_matrix   s   
ÿÿÿzMatrixCache.cache_matrixc                 C   s,   | j  ||f¡}|dur|S td||f ƒ‚)a  Get a cached matrix by name and format.

        Parameters
        ----------
        name : str
            A descriptive name for the matrix, like "identity2".
        format : str
            The format desired ('sympy', 'numpy', 'scipy.sparse')
        Nz3Matrix with name %s and format %s is not available.)r   ÚgetÚNotImplementedError©r   r   Úformatr   r   r   r   Ú
get_matrix1   s   
ÿÿzMatrixCache.get_matrixc                 C   s   || j ||f< d S r   )r   r   r   r   r   Ú_store_matrixC   s   zMatrixCache._store_matrixc                 C   s   |   |dt|ƒ¡ d S )NZsympy)r!   r   r   r   r   r   r   F   s   zMatrixCache._sympy_matrixc                 C   ó    t || jd}|  |d|¡ d S )N©r   Únumpy)r	   r   r!   r   r   r   r   r   I   s   zMatrixCache._numpy_matrixc                 C   r"   )Nr#   zscipy.sparse)r
   r   r!   r   r   r   r   r   M   s   z MatrixCache._scipy_sparse_matrixN)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r    r!   r   r   r   r   r   r   r   r      s    
r   é   éÿÿÿÿF)ÚevaluateZeye2é   Zop11Zop00Zop10Zop01ÚXÚYÚZÚSÚTé   ÚHZHsqrt2ZSWAP)r,   r   r   r   )r   r   r,   r   )r   r,   r   r   )r   r   r   r,   ZZXZZYN)r(   Zsympy.core.numbersr   r   r   Zsympy.core.powerr   Z&sympy.functions.elementary.exponentialr   Zsympy.matrices.denser   Z!sympy.physics.quantum.matrixutilsr   r	   r
   r   Z	sqrt2_invZmatrix_cacher   r   r   r   r   Ú<module>   s4    G(  ÿ "