
    BVh                         d Z ddlZddlZddlmZ ddlmZ ddlm	Z	  ej                  ddd      Zd	Zdad
 ZddZ e         e	d      d        Z e	d      ej"                  d               Zy)zUtilities for API compatibility between TensorFlow release versions.

See [Version
Compatibility](https://tensorflow.org/guide/version_compat#backward_forward)
    N)
tf_logging)tf_contextlib)	tf_exporti        #TF_FORWARD_COMPATIBILITY_DELTA_DAYSc                     | dz  |dz  z  |z  S )N	   r    yearmonthdays      O/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/compat/compat.py_date_to_date_numberr   %   s    
!)
	#c	))    c                 .   | r| }nCt         }t        j                  t              }|r"|t	        j
                  t        |            z  }|t         k  rt        j                  d|z         yt        |j                  |j                  |j                        ay)z?Update the base date to compare in forward_compatible function.)dayszeTrying to set the forward compatibility date to the past date %s. This will be ignored by TensorFlow.N)_FORWARD_COMPATIBILITY_HORIZONosgetenv*_FORWARD_COMPATIBILITY_DELTA_DAYS_VAR_NAMEdatetime	timedeltaintloggingwarningr   r   r   r   "_FORWARD_COMPATIBILITY_DATE_NUMBER)date_to_overridedate
delta_dayss      r   )_update_forward_compatibility_date_numberr"   )   s    
 D)DEFJ
h  c*o66d	**OO DGKM N
';
iiTXX('$r   zcompat.forward_compatiblec                 *    t         t        | ||      kD  S )a8  Return true if the forward compatibility window has expired.

  See [Version
  compatibility](https://www.tensorflow.org/guide/versions#backward_and_partial_forward_compatibility).

  Forward-compatibility refers to scenarios where the producer of a TensorFlow
  model (a GraphDef or SavedModel) is compiled against a version of the
  TensorFlow library newer than what the consumer was compiled against. The
  "producer" is typically a Python program that constructs and trains a model
  while the "consumer" is typically another program that loads and serves the
  model.

  TensorFlow has been supporting a 3 week forward-compatibility window for
  programs compiled from source at HEAD.

  For example, consider the case where a new operation `MyNewAwesomeAdd` is
  created with the intent of replacing the implementation of an existing Python
  wrapper - `tf.add`.  The Python wrapper implementation should change from
  something like:

  ```python
  def add(inputs, name=None):
    return gen_math_ops.add(inputs, name)
  ```

  to:

  ```python
  from tensorflow.python.compat import compat

  def add(inputs, name=None):
    if compat.forward_compatible(year, month, day):
      # Can use the awesome new implementation.
      return gen_math_ops.my_new_awesome_add(inputs, name)
    # To maintain forward compatibility, use the old implementation.
    return gen_math_ops.add(inputs, name)
  ```

  Where `year`, `month`, and `day` specify the date beyond which binaries
  that consume a model are expected to have been updated to include the
  new operations. This date is typically at least 3 weeks beyond the date
  the code that adds the new operation is committed.

  Args:
    year:  A year (e.g., 2018). Must be an `int`.
    month: A month (1 <= month <= 12) in year. Must be an `int`.
    day:   A day (1 <= day <= 31, or 30, or 29, or 28) in month. Must be an
      `int`.

  Returns:
    True if the caller can expect that serialized TensorFlow graphs produced
    can be consumed by programs that are compiled with the TensorFlow library
    source code after (year, month, day).
  )r   r   r   s      r   forward_compatibler$   A   s!    p 
,.B
E3/ 
 r   z$compat.forward_compatibility_horizonc              #      K   	 t        t        j                  | ||             d t                y# t                w xY ww)az  Context manager for testing forward compatibility of generated graphs.

  See [Version
  compatibility](https://www.tensorflow.org/guide/versions#backward_and_partial_forward_compatibility).

  To ensure forward compatibility of generated graphs (see `forward_compatible`)
  with older binaries, new features can be gated with:

  ```python
  if compat.forward_compatible(year=2018, month=08, day=01):
    generate_graph_with_new_features()
  else:
    generate_graph_so_older_binaries_can_consume_it()
  ```

  However, when adding new features, one may want to unittest it before
  the forward compatibility window expires. This context manager enables
  such tests. For example:

  ```python
  from tensorflow.python.compat import compat

  def testMyNewFeature(self):
    with compat.forward_compatibility_horizon(2018, 08, 02):
       # Test that generate_graph_with_new_features() has an effect
  ```

  Args:
    year:  A year (e.g., 2018). Must be an `int`.
    month: A month (1 <= month <= 12) in year. Must be an `int`.
    day:   A day (1 <= day <= 31, or 30, or 29, or 28) in month. Must be an
      `int`.

  Yields:
    Nothing.
  N)r"   r   r    r   s      r   forward_compatibility_horizonr&   }   s1     N0-hmmD%.MN	-/-/s   A$3 A?A)N)__doc__r   r   tensorflow.python.platformr   r   tensorflow.python.utilr    tensorflow.python.util.tf_exportr   r    r   r   r   r   r"   r$   contextmanagerr&   r   r   r   <module>r,      s     	 < 0 6 "/tQ!: -R *%) "*'* * + &'8 (8v 12)0  3)0r   