U
    L?h9                     @   s  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 d dlmZmZmZmZ d dlmZmZ d dlmZm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l m!Z!m"Z"m#Z#m$Z$m%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. edege dggZ/eddgddggZ0edgeggZ1G dd deZ2G dd deZ3G dd deZ4G dd deZ5e2dZ6e3dZ7e4d Z8e5d!Z9e7ee1fee7e1fe6e1fee6ee1fe8e/fee8ee/fee6e7e1e1j: fee8e9ee/e0fe8d e/d fe8e9 de8  e/e0 de/  fee8e9e/e0 e0e/  fee8e9e/e0 e0e/  fee7e6e1j:e1 d  fgZ;d"d# Z<d$d% Z=ed&Z>d'd( Z?d)d* Z@ed+d,d-gid.ZAd/d0 ZBd1d2 ZCe'd3ZDe)d3ZEe(d4ZFd5d6 ZGd7d8 ZHd9d: ZId;S )<    )FloatIInteger)Matrix)import_module)skip)Dagger)	representrep_innerproductrep_expectationenumerate_states)BraKet)OperatorOuterProduct)TensorProduct)matrix_tensor_product)
Commutator)AntiCommutator)InnerProduct)numpy_ndarrayscipy_sparse_matrixto_numpyto_scipy_sparseto_sympy)XKetXOpXBra)qapply)operators_to_state)raises            c                   @   s(   e Zd Zedd Zdd Zdd ZdS )AKetc                 C   s   t S N)ABraself r*   \/var/www/html/venv/lib/python3.8/site-packages/sympy/physics/quantum/tests/test_represent.py
dual_class   s    zAKet.dual_classc                 K   s   | j d|S N)N_represent_AOpr)   optionsr*   r*   r+   _represent_default_basis#   s    zAKet._represent_default_basisc                 K   s   t S r&   )Avecr)   basisr1   r*   r*   r+   r/   &   s    zAKet._represent_AOpN)__name__
__module____qualname__classmethodr,   r2   r/   r*   r*   r*   r+   r%      s   
r%   c                   @   s   e Zd Zedd ZdS )r'   c                 C   s   t S r&   )r%   r(   r*   r*   r+   r,   ,   s    zABra.dual_classN)r6   r7   r8   r9   r,   r*   r*   r*   r+   r'   *   s   r'   c                   @   s   e Zd Zdd Zdd ZdS )AOpc                 K   s   | j d|S r-   r.   r0   r*   r*   r+   r2   3   s    zAOp._represent_default_basisc                 K   s   t S r&   )Amatr4   r*   r*   r+   r/   6   s    zAOp._represent_AOpNr6   r7   r8   r2   r/   r*   r*   r*   r+   r:   1   s   r:   c                   @   s   e Zd Zdd Zdd ZdS )BOpc                 K   s   | j d|S r-   r.   r0   r*   r*   r+   r2   <   s    zBOp._represent_default_basisc                 K   s   t S r&   )Bmatr4   r*   r*   r+   r/   ?   s    zBOp._represent_AOpNr<   r*   r*   r*   r+   r=   :   s   r=   aABc                  C   s8   t D ].} t| d tdd}t| d }||kstqd S )Nr   Zsympyr5   formatr!   )_testsr	   r@   r   AssertionErrortestlhsrhsr*   r*   r+   test_format_sympyc   s    rJ   c                   C   sL   t tdtdkstt tdtdks0tt dt dt ksHtd S )Nr!         ?)r	   r   rE   r   r   r*   r*   r*   r+   test_scalar_sympyj   s    rL   numpyc                  C   s`   t std tD ]J} t| d tdd}t| d }t|trN||k sZt	q||kst	qd S )Nnumpy not installed.r   rM   rB   r!   )
npr   rD   r	   r@   r   
isinstancer   allrE   rF   r*   r*   r+   test_format_numpys   s    
rR   c                   C   sX   t std ttddddks$tttddddks<ttdt dddksTtd S )NrN   r!   rM   rC   rK         ?      ?)rO   r   r	   r   rE   r   r   r*   r*   r*   r+   test_scalar_numpy   s
    rU   scipyfromlistsparse)Zimport_kwargsc                  C   sx   t std tstd tD ]V} t| d tdd}t| d }t|trft j	
||  dksrtq||kstqd S )NrN   scipy not installed.r   scipy.sparserB   r!   g        )rO   r   rV   rD   r	   r@   r   rP   r   ZlinalgZnormZtodenserE   rF   r*   r*   r+   test_format_scipy_sparse   s    
r[   c                   C   sd   t std tstd ttddddks0tttddddksHttdt dddks`td S )NrN   rY   r!   rZ   rS   rK   rT   )rO   r   rV   r	   r   rE   r   r   r*   r*   r*   r+   test_scalar_scipy_sparse   s    r\   xXc                   C   sN   t tttdt kstt ttttd ks<ttt	dd  d S )NZx_1c                   S   s   t tS r&   )r
   x_opr*   r*   r*   r+   <lambda>       z*test_innerprod_represent.<locals>.<lambda>)
r
   x_ketr   r   ZdoitrE   x_brar   r    	TypeErrorr*   r*   r*   r+   test_innerprod_represent   s    re   c                  C   s:   t ttdd} ttt| d jt | d  ks6td S )Nr!   r"   r   )r   r   r_   r   r   ZdualrE   )Z
basis_ketsr*   r*   r+   test_operator_represent   s    rf   c                  C   sP   t d} t| ddt dgks"tt| dddgt dt dt dgksLtd S )NZfoor!   Zfoo_1r"   r$   Zfoo_2Zfoo_4)r   r   rE   )rG   r*   r*   r+   test_enumerate_states   s     rg   N)JZsympy.core.numbersr   r   r   Zsympy.matrices.denser   Zsympy.externalr   Zsympy.testing.pytestr   Zsympy.physics.quantum.daggerr   Zsympy.physics.quantum.representr	   r
   r   r   Zsympy.physics.quantum.stater   r   Zsympy.physics.quantum.operatorr   r   Z#sympy.physics.quantum.tensorproductr   r   Z sympy.physics.quantum.commutatorr   Z$sympy.physics.quantum.anticommutatorr   Z"sympy.physics.quantum.innerproductr   Z!sympy.physics.quantum.matrixutilsr   r   r   r   r   Zsympy.physics.quantum.cartesianr   r   r   Zsympy.physics.quantum.qapplyr   Z!sympy.physics.quantum.operatorsetr   r    r;   r>   r3   r%   r'   r:   r=   kbr@   rA   HrD   rJ   rL   rO   rR   rU   rV   r[   r\   rb   rc   r_   re   rf   rg   r*   r*   r*   r+   <module>   sp   		

	
