
    Vh*                     n   d dl 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
mZmZ 	 d dlZedefd       ZdefdZd	eddfd
ZdefdZdeddfdZdefdZddZedd       Z G d de      Z ee j6                  e   e      e j6                  e<    e       rdnda e       rdayday# e$ r dZY w xY w)    N)contextmanager)	lru_cache)Any)__allow_nonbracketed_mutationContextProp
PropModulereturnc                      t         duS )a  Return a bool indicating if opt_einsum is currently available.

    You must install opt-einsum in order for torch to automatically optimize einsum. To
    make opt-einsum available, you can install it along with torch: ``pip install torch[opt-einsum]``
    or by itself: ``pip install opt-einsum``. If the package is installed, torch will import
    it automatically and use it accordingly. Use this function to check whether opt-einsum
    was installed and properly imported by torch.
    N_opt_einsum     R/home/dcms/DCMS/lib/python3.12/site-packages/torch/backends/opt_einsum/__init__.pyis_availabler      s     d""r   c                      t         S )zNReturn the opt_einsum package if opt_einsum is currently available, else None.r   r   r   r   get_opt_einsumr      s    r   _enabledc                 >    t               s| rt        d|  d      | ay )Nz5opt_einsum is not available, so setting `enabled` to z will not reap the benefits of calculating an optimal path for einsum. torch.einsum will fall back to contracting from left to right. To enable this optimal path calculation, please install opt-einsum.)r   
ValueErrorenabled)r   s    r   _set_enabledr   #   s/    >hCH: N6 6
 	
 Gr   c                      t         S N)r   r   r   r   _get_enabledr   /   s    Nr   	_strategyc                     t               st        d|  d      t        st        d|  d      | dvrt        d|        | ay )Nz6opt_einsum is not available, so setting `strategy` to z will not be meaningful. torch.einsum will bypass path calculation and simply contract from left to right. Please install opt_einsum or unset `strategy`.z6opt_einsum is not enabled, so setting a `strategy` to z will not be meaningful. torch.einsum will bypass path calculation and simply contract from left to right. Please set `enabled` to `True` as well or unset `strategy`.)autogreedyoptimalzH`strategy` must be one of the following: [auto, greedy, optimal] but is )r   r   r   strategy)r   s    r   _set_strategyr!   3   sw    >DYK P= =
 	

 DYK PJ J
 	

 55VW`Vab
 	
 Hr   c                      t         S r   )r    r   r   r   _get_strategyr#   H   s    Or   c                 j    t         t               sd nt        f}| t        |        |t	        |       |S r   )r   r   r    r   r!   )r   r   
orig_flagss      r   	set_flagsr&   L   s4    |~48DJXi r   c              #     K   t               5  t        | |      }d d d        	 d  t               5  t          d d d        y # 1 sw Y   *xY w# 1 sw Y   y xY w# t               5  t          d d d        w # 1 sw Y   w xY wxY wwr   )r   r&   )r   r    r%   s      r   flagsr(   U   s     	&	( 2w1
2# +, 	#z"	# 	#2 2	# 	#*, 	#z"	# 	# 	#s_   BABA 
B	A	BABABB&	A8/	B8B=BBc                   \     e Zd Z fdZ eee      ada e	       r ee
e      a xZS  xZS )OptEinsumModulec                 &    t         |   ||       y r   )super__init__)selfmname	__class__s      r   r-   zOptEinsumModule.__init__g   s    D!r   N)__name__
__module____qualname__r-   r   r   r   r   r    r   r#   r!   __classcell__)r1   s   @r   r*   r*   f   s1    " ,5GH~}m< r   r*   TFr   )NN)syswarnings
contextlibr   	functoolsr   
_lru_cachetypingr   torch.backendsr   r   r   
opt_einsumr   ImportErrorboolr   r   r   r   strr!   r#   r&   r(   r*   modulesr2   r   r    r   r   r   <module>rB      s    
  % -  Q Q$
 	#d 	# 	# 
	4 	D 	d S T *s  # # 	=j 	= (H(=xHH .$e!^6U  Ks   B* *B43B4