a
    /Sic                     @   s   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
dddZd	Zdad
d ZdddZe  e	ddd Ze	dejdd ZdS )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        Z#TF_FORWARD_COMPATIBILITY_DELTA_DAYSc                 C   s   | d> |d> B |B S )N	       yearmonthdayr	   r	   [/var/www/html/django/DPS/env/lib/python3.9/site-packages/tensorflow/python/compat/compat.py_date_to_date_number%   s    r   c                 C   s`   | r
| }n&t }tt}|r0|tjt|d7 }|t k rJtd|  dS t	|j
|j|jadS )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)Zdate_to_overridedateZ
delta_daysr	   r	   r   )_update_forward_compatibility_date_number)   s    
r   zcompat.forward_compatiblec                 C   s   t t| ||kS )a   Return true if the forward compatibility window has expired.

  See [Version
  compatibility](https://tensorflow.org/guide/version_compat#backward_forward).

  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
   r	   r	   r   forward_compatibleA   s    8r   z$compat.forward_compatibility_horizonc                 c   s0   z"t t| || dV  W t   nt   0 dS )a{  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, date=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
   r	   r	   r   forward_compatibility_horizon}   s    'r   )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	   r   <module>   s    

;