
    BVh                     @   d Z ddlZddlZddlZddlZddlZ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 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 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 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# 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* ddl$m+Z+ dd l$m,Z, dd!l-m.Z. dd"l-m/Z/ dd#l0m1Z2 dd$l3m4Z4 dd%l5m6Z6 dd&l7m8Z8 dd'l7m9Z9 dd(l7m:Z: dd)l;m<Z< d* Z= G d+ d,e(j|                        Z? G d- d.e?      Z@ G d/ d0e?      ZA G d1 d2e'j                        ZCd3 ZD G d4 d5e:j                        ZE G d6 d7e,j                        ZGd8 ZHdNd9ZId: ZJdOd;ZKdPd=ZLd> ZM e<d?g @      dQdB       ZNdC ZOdD ZP e<dE      dNdF       ZQdAdd< ej                         fdGZS e<dHg @      dRdI       ZT e<dHg@      	 	 	 	 dSdJ       ZU e<dKg@      	 	 	 	 	 dTdL       ZV e<dKg @      dRdM       ZW eG       ZXy)UzDThis module contains the user- and codegen-facing API for AutoGraph.    N)	operators)utils)asserts)break_statements)
call_trees)conditional_expressions)continue_statements)control_flow)
directives)	functions)lists)logical_expressions)return_statements)slices)	variables)ag_ctx)	converter)function_wrappers)unsupported_features_checker)
conversion)special_functions)py_builtins)anno)cfg)error_utils)errors)inspect_utils)origin_info)
qual_names)
transpiler)activity)reaching_definitions)
ag_logging)tf_method_target)errors_impl)tf_decorator)
tf_inspect)tf_stack)	tf_exportc                  Z    t        t        j                  j                  dd            dkD  S )NAUTOGRAPH_STRICT_CONVERSION0r   )intosenvironget     T/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/autograph/impl/api.py#is_autograph_strict_conversion_moder4   B   s"    	RZZ^^93?	@1	DDr2   c                       e Zd ZdZy)AutoGraphErrorz(Base class for all AutoGraph exceptions.N__name__
__module____qualname____doc__r1   r2   r3   r6   r6   L   s    0r2   r6   c                       e Zd ZdZy)ConversionErrorz%Raised during the conversion process.Nr7   r1   r2   r3   r=   r=   Q   s    -r2   r=   c                       e Zd ZdZy)StagingErrorzDRaised during the staging (i.e. Python execution) of converted code.Nr7   r1   r2   r3   r?   r?   V   s    Lr2   r?   c                   "     e Zd ZdZ fdZ xZS )_ErrorMetadataz2AutoGraph-specific error metadata. See base class.c                 >   t        |      }t        |t        j                        rrt	        j
                  |j                        }| j                         }t        |j                        }|dk(  r ||j                  |j                  ||j                        S |t        j                  t        t         t"        t        j$                  t        j&                  fv r || j                               S t(        t*        | [  |      }||S t#        | j                               S )N)selfnode_defopmessage)type
issubclassr%   OpErrorr'   getfullargspec__init__get_messagetupleargsrD   rE   experimental_payloadsr   	PyCTErrorr6   r=   r?   InaccessibleTensorErrorOperatorNotAllowedInGraphErrorsuperrA   create_exception)rC   source_errorpreferred_typeinit_argspecrF   	init_argsexc	__class__s          r3   rT   z_ErrorMetadata.create_exception^   s    ,'N.+"5"56  ..~/F/FGl  "g))*i 
;	;l33\__g*@@B 	B 
F,,no(+*M*M'FFH 
H D,,.//

6|
DC
j ((*++r2   )r8   r9   r:   r;   rT   __classcell__rZ   s   @r3   rA   rA   [   s    :, ,r2   rA   c                 b   t        | d      ryt        | dd      }|j                  }|@t        j                  dd|d       dj                  | j                  j                  |       }nd}t        j                  t        j                         d	         dd }t        ||||t              | _        y)
z:Augments an error with the metadata necessary for rewrite.ag_pass_throughNag_error_metadata   z Caught error in user callable %sTexc_infoz{}: {}   )hasattrgetattrag_source_maplogginglogformatrZ   r8   	traceback
extract_tbsysrb   rA   __file__r_   )efmetadata
source_maprF   cause_tbs         r3   _attach_error_metadatars   }   s    Q!"
Q+T2(*KK5q4Hooakk22A6GG!!#,,."34QR8(&x7J'/1!r2   c                   (     e Zd ZdZ fdZd Z xZS )StackTraceMapperz1Remaps generated code to code it originated from.c                 R    t         |           |j                  | _        d | _        y N)rS   rK   rf   _source_map_cached_map)rC   converted_fnrZ   s     r3   rK   zStackTraceMapper.__init__   s&    	G#11D Dr2   c                    | j                   | j                   S | j                  j                         }i }| j                  j	                         D ]U  \  }}|j
                  j                  |j
                  j                  |j                  f||j                  |j                  f<   W |j	                         D ]  \  }}|\  }}}	t        j                  ||      }
|
| j                  v rJ| j                  |
   }|j
                  j                  |j
                  j                  |j                  f||<   {|||<    || _         |S )N)filenamelineno)ry   parentget_effective_source_maprx   itemslocr|   r}   function_namer   LineLocation)rC   
parent_mapeffective_source_mapr   originkeyvaluer|   r}   _	value_locs              r3   r   z)StackTraceMapper.get_effective_source_map   s:   #557J''--/ PV:@**:M:M:@**:K:K:@:N:N:PCLL#**56P
 !&&( *
U!h**HVLi	d&&	&!!),%+ZZ%8%8&**:K:K%+%9%9%;S! %*S!* ,Dr2   )r8   r9   r:   r;   rK   r   r[   r\   s   @r3   ru   ru      s    9 r2   ru   c                   D     e Zd ZdZ fdZ fdZd Zd Zd Zd Z	 xZ
S )PyToTFz%The TensorFlow AutoGraph transformer.c                 8    t         t        |           d | _        y rw   )rS   r   rK   _extra_locals)rC   rZ   s    r3   rK   zPyToTF.__init__   s    	&$ "Dr2   c                 0    dt         t        |   |      z   S )Ntf__)rS   r   get_transformed_name)rC   noderZ   s     r3   r   zPyToTF.get_transformed_name   s    E&$<TBBBr2   c                    | j                   Jt        j                  j                  dd       }t        j                  j                  |      }|j                  j                  t        j                  t              j                         t        j                  |_        t        j                  |_        t        j                  |_        t         |_        t"        j$                  |_        t"        j&                  |_        |j                  j                  t(        j                         |j                  j                  t*        j                         d|i| _         | j                   S )N	autographag__)r   	importlib	machinery
ModuleSpecutilmodule_from_spec__dict__updateinspect	getmoduler   r   ConversionOptionsSTANDARD_OPTIONSSTDFeaturer   r   FunctionScopewith_function_scoper   r   )rC   module_specag_internals      r3   get_extra_localszPyToTF.get_extra_locals   s    ! ''22;EkNN33K@k!!'"3"3F";"D"DE&/&A&Ak#!22ko%--kk"3"A"Ak(9(M(Mk% !!"3"<"<=!!)"4"45"K0dr2   c                     |j                   S rw   options)rC   ctxs     r3   get_caching_keyzPyToTF.get_caching_key   s    ;;r2   c                 F   t        j                  |      }t        j                  |      }t	        j                  ||d       }t        j                  |||      }t        j                  |t        j                  j                  t        j                  j                  i       |S rw   )r   buildr   resolver!   r"   r   dupStaticDEFINITIONSORIG_DEFINITIONS)rC   r   r   graphss       r3   initial_analysiszPyToTF.initial_analysis   s{    YYt_Fd#DD#t,D''c6:DHHKK##T[[%A%A	
 Kr2   c                    t        j                  |       | j                  ||      }t        j                  ||      }t        j                  ||      }t        j                  ||      }|j                  j                  j                  t        j                  j                        rt        j                  ||      }t        j                  ||      }t        j                  ||      }|j                  j                  j                  t        j                  j                         r,t#        j                  ||      }t%        j                  ||      }t'        j                  ||      }t)        j                  ||      }t+        j                  ||      }t-        j                  ||      }t/        j                  ||      }|S rw   )r   verifyr   r   	transformr   r   userr   usesr   r   ASSERT_STATEMENTSr   r	   r   LISTSr   r   r   r
   r   r   r   )rC   r   r   s      r3   transform_astzPyToTF.transform_ast   sY    ''-  s+DtS)Dc*D%%dC0D
xxY..@@AtS)d ((s3D&&tS1D
xxY..445__T3'ddC(dc*D!!$,D",,T37D((s3DtS)DKr2   )r8   r9   r:   r;   rK   r   r   r   r   r   r[   r\   s   @r3   r   r      s%    -C.r2   r   c                     t        | d      st        d      t        j                  | |      \  }}}t        |d      rJ t        |d      rJ ||_        ||_        |S )zApplies AutoGraph to entity.__code__zCannot apply autograph to a function that doesn't expose a __code__ object. If this is a @tf.function, try passing f.python_function instead.	ag_modulerf   )rd   
ValueError_TRANSPILERr   r   rf   )entityprogram_ctxtransformedmodulerq   s        r3   _convert_actualr     ss     
	$
 ? @ @ %0$9$9&+$N!+vz[+..	.[/22	2 +(+	r2   c                 |    t        j                  |       rt        | j                  d|       | S t        | d|       | S Nautograph_info__)r   ismethodsetattr__func__)r   extrass     r3   autograph_artifactr     s<    fFOO/8 
- F&/	-r2   c                     t        | d      S r   )rd   )r   s    r3   is_autograph_artifactr   #  s    	+	,,r2   c                 
   t        j                  dd| ||       ||t        d      |j                  }t	        j
                  | |      r&t        j                  dd|        t        | |||d      S t        j                         j                  t        j                  j                  k(  r&t        j                  dd|        t        | |||d      S t        |       r%t        j                  dd	|        t        | |||      S t        | t        j                        r}i }| j                   | j                   j#                         }||j%                  |       | j&                  |z   }t        j                  d
d| ||       t)        | j*                  ||||      S t-        j.                  |       r| t0        u rt3        j4                  | ||      S | t6        u rt3        j8                  | ||      S | t:        u rt3        j<                  |      S | t>        u rt3        j@                  |      S |r t3        jB                  |       |i |S  t3        jB                  |       | S t	        jD                  |       rt        | |||      S |jF                  s#t	        jH                  |       rt        | |||      S |jJ                  st        | |||      S 	 tM        jN                  |       stM        jP                  |       r@| }|}tS        | dd      }	|	t        |	tT        jV                        r|	jX                  }	|	f|z   }nXt[        | d      r3t[        | j\                  d      r| j\                  j^                  }| f|z   }n| }ta        dtc        |       z        t[        |d      s%t        j                  dd|       t        | |||      S t[        |jj                  d      r>|jj                  jl                  dk(  r%t        j                  dd|       t        | |||      S 	 to        jp                  |      }ts        ||      }t        jt                  d      rtw        |||       ty        |      5  t{        j|                         5  	 |	 ||i |}n || }ddd       ddd       S # td        $ r=}
t        j                  ddd       tg               r ti        | ||||
      cY d}
~
S d}
~
ww xY w# td        $ r=}
t        j                  dd|d       tg               r ti        | ||||
      cY d}
~
S d}
~
ww xY w# td        $ r}
t        |
|        d}
~
ww xY w# 1 sw Y   xY w# 1 sw Y   S xY w)a  Converts a function call inline.

  For internal use only.

  Note: The argument list is optimized for readability of generated code, which
  may look like this:

    ag__.converted_call(f, (arg1, arg2), None, fscope)
    ag__.converted_call(f, (), dict(arg1=val1, **kwargs), fscope)
    ag__.converted_call(f, (arg1, arg2) + varargs, dict(**kwargs), lscope)

  Args:
    f: The function to convert.
    args: Tuple, the original positional arguments of f
    kwargs: Optional[Dict], the original keyword arguments of f
    caller_fn_scope: Optional[function_wrappers.FunctionScope], the function
      scope of the converted function in which this call was originally made.
    options: Optional[converter.ConversionOptions], conversion options. If not
      specified, the value of caller_fn_scope.callopts is used. Either options
      or caller_fn_scope must be present.

  Returns:
    Any, the result of executing a possibly-converted `f` with the given
      arguments.
  r`   z/Converted call: %s
    args: %s
    kwargs: %s
Nz3either caller_fn_scope or options must have a valuerc   zAllowlisted %s: from cacheFz1Allowlisted: %s: AutoGraph is disabled in contextz+Permanently allowed: %s: AutoGraph artifact   z)Forwarding call of partial %s with
%s
%s
)caller_fn_scoper   __self__rZ   __call__zunknown callable type "%s"zError transforming entity %sTra   r   z'Permanently allowed: %s: native bindingco_filenamez<string>z-Permanently allowed: %s: dynamic code (exec?)r   )@rg   rh   r   calloptsr   is_in_allowlist_cache_call_unconvertedr   control_status_ctxstatusStatusDISABLEDr   
isinstance	functoolspartialkeywordscopyr   rN   converted_callfuncr   	isbuiltinevalr   eval_in_original_contextrS   super_in_original_contextglobalsglobals_in_original_contextlocalslocals_in_original_contextoverload_ofis_unsupporteduser_requestedis_allowlistedinternal_convert_user_coder   r   
isfunctionre   r$   TfMethodTargettargetrd   rZ   r   NotImplementedErrorrG   	Exceptionr4   _fall_back_unconvertedr   r   r   ProgramContextr   has_verbosity_log_callargsru   r(   CurrentModuleFilterrs   )ro   rN   kwargsr   r   
new_kwargsnew_argstarget_entityeffective_argsf_selfrn   r   converted_fresults                 r3   r   r   '  s   4 
++aEq$ _LMM&&G%%a1KK/3Qfgu== ''6==+A+AAKKFJQfgu==1KK@!DQfg66 9$$%Jzz::??$jvv}HKKA1h	'  QDy11!T?KKEz221dOLLG|44_EEF{33ODD'[$$Q'888'[$$Q'..q!Qfg66			J$=$=a$@Qfg66 
	+	+Qfg66?g003mnq*d+f		f.==>==& ^3	K	 WQ[[*%E
 kk**mtd{n m <tAw FGG 

	+KK<mLQfg66&&6**j8KKBQfg66	?**7;K!-=KQK8 $ h&B&B&D 		n77n-  
-K 
 ?KK1=4P*,!!T67A>>	?* 
 ?KK1=4P*,!!T67A>>	?  Q,   
-s   CR AS U2U4T(U	S2SSS	T%(2T T% T%(	U1T>>UUU	UUTc                     |rt        j                  | |       t        j                  |       r@t	        | j
                  t        j                        r| j
                  j                  ||      S | | |i |S  | | S )z>Calls the original function without converting with AutoGraph.)	r   cache_allowlistedr   r   r   r   r$   r   call)ro   rN   r   r   update_caches        r3   r   r     sl      G,q-<<=::??4((df	
D/r2   c                 n   d}t        |t        j                        r)t        j                  r|t        j                  || d|       nct        |t        j                        r/t        j                  | |      s3t        j                  || d|       nd}t        j                  || ||       t        | |||      S )zAFalls back to calling the function unconverted, in case of error.zAutoGraph could not transform %s and will run it as-is.
%sCause: %s
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert zPlease report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output.
)r   r   InaccessibleSourceCodeErrorr   INSPECT_SOURCE_SUPPORTEDrg   warningUnsupportedLanguageElementErrorr   r   r   )ro   rN   r   r   rY   warning_templatefile_bug_messages          r3   r   r     s    3  V778&&oo&2s3#v==>++Aw7oo&2s3	%  OO$a)93?	1dFG	44r2   z!__internal__.autograph.tf_convert)v1Fc                    t        |       r| S | }t        j                  |       \  }} |j                  t        j
                  j                  k(  rt        d||      }nt|j                  t        j
                  j                  k(  rt        }nF|j                  t        j
                  j                  k(  r|rt        d||      }nt        }nJ d        ||       }|rt        j                  || |      }t        |      S )a  Decorator that applies AutoGraph to a function.

  Use in internal APIs.

  This API is suitable for high order functions internal to the TensorFlow API,
  and more generally any function to which AutoGraph is not applied.

  Guidance: `convert` was a decorator meant for use directly by developers, but
  most of today's uses go through `tf.function`. `tf_convert` is to be called
  from high order functions internal to TF. By default, all the internal
  TensorFlow functions are skipped when AutoGraph processes the code. This may
  lead to user-supplied functions to be incorrectly skipped as well.
  `tf_convert` helps avoid that. See the following example for more details.

  ```
  =====tf_internal_module.py=====

  def unconverted(input_fn):
    return input_fn()

  def converted(input_fn):
    return tf.__internal__.autograph.tf_convert(
       input_fn, ctx=tf.__internal__.autograph.control_status_ctx())()

  ======user_module.py======

  @tf.function
  def foo(input_fn)
    return unconverted(input_fn)

  @tf.function
  def bar(input_fn)
    return converted(input_fn)

  @tf.function(autograph=False)
  def baz(input_fn)
    return converted(input_fn)
  ```

  The `foo` method above will execute the `input_fn` without autograph
  conversion, while the `bar` method will run an autographed `input_fn`. The
  `baz` method will run an unconverted `input_fn`, since `tf_convert` respect
  the control status context.

  Note that both methods in `tf_internal_module` are skipped by autograph when
  tracing the `tf.function`. The configuration of whether a module/package
  should be skipped by autograph is controlled in
  tensorflow/python/autograph/core/config.py.

  Args:
    f: Callable.
    ctx: ag_ctx.ControlStatusCtx, the Autograph context in which `f` is used.
    convert_by_default: bool, whether to use AutoGraph when the context doesn't
      specify.
    user_requested: bool, whether to ignore the conversion allowlist. See
      ConversionOptions.user_requested.

  Returns:
    Either `f or the converted version of `f`.
  T)	recursiver   conversion_ctxz(This switch contains all possible cases!)r   r&   unwrapr   r   r   ENABLEDconvertr   do_not_convertUNSPECIFIED'call_with_unspecified_conversion_statusrewrapr   )ro   r   convert_by_defaultr   	f_wrapper
decoratorswrapper_factorywrappers           r3   
tf_convertr!    s    ~ 1H)%%a(-*a 	ZZ6==(((~cKO
zzV]]+++$O
zzV]]...Mo @o<<<5A'!!)Q8G	G	$$r2   c                       fd}t        j                         st        j                         rt        j                  |       }t        |      S )zGDecorator that resets the conversion context to the unspecified status.c                      t        j                  t         j                  j                        5   | i |cd d d        S # 1 sw Y   y xY wN)r   )r   ControlStatusCtxr   r  rN   r   r   s     r3   r   z8call_with_unspecified_conversion_status.<locals>.wrapperR  s=    		 	 (A(A	B #4"6"# # #   AA)r   r   r   r   update_wrapperr   r   r   s   ` r3   r  r  O  sB    # !1!1$!7&&w5G	G	$$r2   c                 l   t        j                  dd| | j                         t        j                  dd| | j                         |t	        j
                  | g|i |}nt	        j
                  | g| }dj                  d |j                         D              }t        j                  dd| |       y)zLogging helper.rc   zDefaults of %s : %szKW defaults of %s : %sN
c              3   F   K   | ]  \  }}d j                  ||        yw)z
    {}: {}N)ri   ).0kvs      r3   	<genexpr>z _log_callargs.<locals>.<genexpr>f  s&      !>$(Aql!Q!>s   !zCalling %s with
%s
)rg   rh   __defaults____kwdefaults__r'   getcallargsjoinr   )ro   rN   r   callargsformatted_callargss        r3   r   r   \  s    	++a&1>>:	++a)1a.>.>?%%a9$9&9H%%a/$/Hyy !>,4NN,<!> >	++a(!-?@r2   z%autograph.experimental.do_not_convertc                       t         S  fd}t        j                         st        j                         rt	        j
                  |       }t        |      S )a}  Decorator that suppresses the conversion of a function.

  Args:
    func: function to decorate.

  Returns:
    If `func` is not None, returns a `Callable` which is equivalent to
    `func`, but is not converted by AutoGraph.
    If `func` is None, returns a decorator that, when invoked with a
    single `func` argument, returns a `Callable` equivalent to the
    above case.
  c                      t        j                  t         j                  j                        5   | i |cd d d        S # 1 sw Y   y xY wr$  )r   r%  r   r   r&  s     r3   r   zdo_not_convert.<locals>.wrapper  s=    		 	 (>(>	? #4"6"# # #r'  )r  r   r   r   r   r(  r   r)  s   ` r3   r  r  p  sO     
\# !1!1$!7&&w5G	G	$$r2   c                       fd}|S )a  Decorator that compiles a function to use TensorFlow ops.

  The decorator is dynamic - it recompiles the target whenever the decorated
  function is called. This means the parameter values are known at conversion.
  It also means that repeated calls with different types of parameters will be
  correctly processed.

  Args:
    recursive: bool, whether to recursively convert any functions or classes
      that the converted function may use.
    optional_features: converted.Feature, allows toggling optional or
      experimental features. When set to None, only the core features are
      enabled.
    user_requested: bool, whether this is a function that the user explicitly
      asked to be converted. See ConversionOptions.user_requested.
    conversion_ctx: Optional ag_ctx.ControlStatusCtx, the Autograph context in
      which `f` is used.

  Returns:
    Callable, a decorator that converts the given function into an equivalent
    function that uses TensorFlow ops.
  c                       fd}t        j                         st        j                         rt        j                  |       }t        j                   |      }t        |      S )zDecorator implementation.c                      t        j                        }	 5  t        | ||      cddd       S # 1 sw Y   yxY w# t        $ r-}t	        |d      r|j
                  j                  |       d}~ww xY w)z.Wrapper that calls the converted version of f.r  r   optional_featuresr   Nr_   )r   r   r   r   rd   r_   to_exception)	rN   r   r   rn   r  ro   r=  r  r   s	       r3   r   z+convert.<locals>.decorator.<locals>.wrapper  s    ++'-/g 	B4A	B 	B 	B 1)*##003
3
	s.   A 6	A ?A A 	A8(A33A8)r   r   r   r   r(  r&   make_decoratorr   )ro   r   decorated_wrapperr  r=  r  r   s   `  r3   	decoratorzconvert.<locals>.decorator  s[      ! 0 0 3((!4g$33Aw?/00r2   r1   )r  r=  r   r  rA  s   ```` r3   r  r    s    610 
r2   zautograph.to_graphc           
      v   	 t        j                  t        j                  |d|            }t        t	        | |            S # t
        t        t        t        t        f$ rW}t        j                  dd| d       t        dj                  | |j                  j                  t!        |                  d}~ww xY w)	a  Converts a Python entity into a TensorFlow graph.

  Also see: `tf.autograph.to_code`, `tf.function`.

  Unlike `tf.function`, `to_graph` is a low-level transpiler that converts
  Python code to TensorFlow graph code. It does not implement any caching,
  variable management or create any actual ops, and is best used where greater
  control over the generated TensorFlow graph is desired. Another difference
  from `tf.function` is that `to_graph` will not wrap the graph into a
  TensorFlow function or a Python callable. Internally, `tf.function` uses
  `to_graph`.

  Example usage:

  >>> def f(x):
  ...   if x > 0:
  ...     y = x * x
  ...   else:
  ...     y = -x
  ...   return y
  ...
  >>> converted_f = to_graph(f)
  >>> x = tf.constant(2)
  >>> converted_f(x)  # converted_foo is like a TensorFlow Op.
  <tf.Tensor: shape=(), dtype=int32, numpy=4>

  Supported Python entities include:
    * functions
    * classes
    * object methods

  Functions are converted into new functions with converted code.

  Classes are converted by generating a new class whose methods use converted
  code.

  Methods are converted into unbound function that have an additional first
  argument called `self`.

  For a tutorial, see the
  [tf.function and AutoGraph guide](https://www.tensorflow.org/guide/function).
  For more detailed information, see the
  [AutoGraph reference documentation](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/autograph/g3doc/reference/index.md).

  Args:
    entity: Python callable or class to convert.
    recursive: Whether to recursively convert any functions that the converted
      function may call.
    experimental_optional_features: `None`, a tuple of, or a single
      `tf.autograph.experimental.Feature` value.

  Returns:
    Same as `entity`, the converted Python function or class.

  Raises:
    ValueError: If the entity could not be converted.
  Tr<  r   r`   zError converting %sra   zconverting {}: {}: {}N)r   r   r   r   r   r   AttributeErrorKeyError	NameErrorAssertionErrorrg   errorr=   ri   rZ   r8   str)r   r  experimental_optional_featuresr   rn   s        r3   to_graphrJ    s    v
/**++<>?K
 ofkBCC
nh	>	J /MM!*FTB
188$$c!f. / //s   A A B8!AB33B8c                 "    ~~t        | ||      S )a  Converts a Python entity into a TensorFlow graph.

  Also see: `tf.autograph.to_code`, `tf.function`.

  Unlike `tf.function`, `to_graph` is a low-level transpiler that converts
  Python code to TensorFlow graph code. It does not implement any caching,
  variable management or create any actual ops, and is best used where greater
  control over the generated TensorFlow graph is desired. Another difference
  from `tf.function` is that `to_graph` will not wrap the graph into a
  TensorFlow function or a Python callable. Internally, `tf.function` uses
  `to_graph`.

  _Example Usage_

  ```python
    def foo(x):
      if x > 0:
        y = x * x
      else:
        y = -x
      return y

    converted_foo = to_graph(foo)

    x = tf.constant(1)
    y = converted_foo(x)  # converted_foo is a TensorFlow Op-like.
    assert is_tensor(y)
  ```

  Supported Python entities include:
    * functions
    * classes
    * object methods

  Functions are converted into new functions with converted code.

  Classes are converted by generating a new class whose methods use converted
  code.

  Methods are converted into unbound function that have an additional first
  argument called `self`.

  Args:
    entity: Python callable or class to convert.
    recursive: Whether to recursively convert any functions that the converted
      function may call.
    arg_values: Deprecated.
    arg_types: Deprecated.
    experimental_optional_features: `None`, a tuple of, or a single
      `tf.autograph.experimental.Feature` value.

  Returns:
    Same as `entity`, the converted Python function or class.

  Raises:
    ValueError: If the entity could not be converted.
  r  rI  )rJ  )r   r  
arg_values	arg_typesrI  s        r3   to_graph_v1rO    s#    ~ 	%C
E Er2   zautograph.to_codec                 $    ~~~t        | ||      S )a  Returns the source code generated by AutoGraph, as a string.

  Example usage:

  >>> def f(x):
  ...   if x < 0:
  ...     x = -x
  ...   return x
  >>> tf.autograph.to_code(f)
  "...def tf__f(x):..."

  Also see: `tf.autograph.to_graph`.

  Note: If a function has been decorated with `tf.function`, pass its
  underlying Python function, rather than the callable that `tf.function
  creates:

  >>> @tf.function
  ... def f(x):
  ...   if x < 0:
  ...     x = -x
  ...   return x
  >>> tf.autograph.to_code(f.python_function)
  "...def tf__f(x):..."

  Args:
    entity: Python callable or class.
    recursive: Whether to recursively convert any functions that the converted
      function may call.
    arg_values: Deprecated.
    arg_types: Deprecated.
    indentation: Deprecated.
    experimental_optional_features: `None`, a tuple of, or a single
      `tf.autograph.experimental.Feature` value.

  Returns:
    The converted code as string.
  rL  )to_code)r   r  rM  rN  indentationrI  s         r3   
to_code_v1rS  R  s&    Z 	%C
E Er2   c                 n    t        j                  t        | ||            }t        j                  |      S )ap  Returns the source code generated by AutoGraph, as a string.

  Example usage:

  >>> def f(x):
  ...   if x < 0:
  ...     x = -x
  ...   return x
  >>> tf.autograph.to_code(f)
  "...def tf__f(x):..."

  Also see: `tf.autograph.to_graph`.

  Note: If a function has been decorated with `tf.function`, pass its
  underlying Python function, rather than the callable that `tf.function
  creates:

  >>> @tf.function
  ... def f(x):
  ...   if x < 0:
  ...     x = -x
  ...   return x
  >>> tf.autograph.to_code(f.python_function)
  "...def tf__f(x):..."

  Args:
    entity: Python callable or class to convert.
    recursive: Whether to recursively convert any functions that the converted
      function may call.
    experimental_optional_features: `None`, a tuple of, or a single
      `tf.autograph.experimental.Feature` value.

  Returns:
    The converted code as string.
  rL  )r'   	getsourcerJ  textwrapdedent)r   r  rI  sources       r3   rQ  rQ    s9    J 
)GIJ&
 
	  r2   rw   )NN)T)TF)TN)TNNN)TNNz  N)Yr;   r   r   r   r.   rl   rV  rj   tensorflow.python.autographr   r   &tensorflow.python.autograph.convertersr   r   r   r   r	   r
   r   r   r   r   r   r   r    tensorflow.python.autograph.corer   r   r   r    tensorflow.python.autograph.implr    tensorflow.python.autograph.langr   %tensorflow.python.autograph.operatorsr    tensorflow.python.autograph.pyctr   r   r   r   r   r   r   r    0tensorflow.python.autograph.pyct.static_analysisr!   r"   !tensorflow.python.autograph.utilsr#   rg   ,tensorflow.python.eager.polymorphic_functionr$   tensorflow.python.frameworkr%   tensorflow.python.utilr&   r'   r(    tensorflow.python.util.tf_exportr)   r4   rP   r6   r=   r?   ErrorMetadataBaserA   rs   ru   PyToPyr   r   r   r   r   r   r   r!  r  r   r  NullCtxr  rJ  rO  rS  rQ  r   r1   r2   r3   <module>ri     s(   K    	 
   1 - : C = J F ? = < 8 F D 9 < 3 6 > I 7 > = 1 0 8 3 : 8 7 7 E Q C I 3 / - + 6EV%% 
n 
> 
,[22 ,D1(! x00 ! RGZ GT.-Wt5< .26^% 7^%B
%A( 23% 4%6 ")6>>+3n B'D/ (D/N #$%/3	CE &CEL "#$.22E %2Ej 2&)! ')!X hr2   