def test_class_alias(self, mock_warning): class MyClass(object): """My docstring.""" init_args = [] def __init__(self, arg): MyClass.init_args.append(arg) deprecated_cls = deprecation.deprecated_alias("deprecated.cls", "real.cls", MyClass) print(deprecated_cls.__name__) print(deprecated_cls.__module__) print(deprecated_cls.__doc__) MyClass("test") self.assertEqual(0, mock_warning.call_count) deprecated_cls("deprecated") self.assertEqual(1, mock_warning.call_count) # Make sure the error points to the right file. self.assertRegexpMatches(mock_warning.call_args[0][1], r"deprecation_test\.py:") deprecated_cls("deprecated again") self.assertEqual(1, mock_warning.call_count) self.assertEqual(["test", "deprecated", "deprecated again"], MyClass.init_args) # Check __init__ signature matches for doc generation. self.assertEqual( tf_inspect.getfullargspec(MyClass.__init__), tf_inspect.getfullargspec(deprecated_cls.__init__))
def test_class_alias(self, mock_warning): class MyClass(object): """My docstring.""" init_args = [] def __init__(self, arg): MyClass.init_args.append(arg) deprecated_cls = deprecation.deprecated_alias("deprecated.cls", "real.cls", MyClass) print(deprecated_cls.__name__) print(deprecated_cls.__module__) print(deprecated_cls.__doc__) MyClass("test") self.assertEqual(0, mock_warning.call_count) deprecated_cls("deprecated") self.assertEqual(1, mock_warning.call_count) # Make sure the error points to the right file. self.assertRegexpMatches(mock_warning.call_args[0][1], r"deprecation_test\.py:") deprecated_cls("deprecated again") self.assertEqual(1, mock_warning.call_count) self.assertEqual(["test", "deprecated", "deprecated again"], MyClass.init_args)
def test_function_alias(self, mock_warning): deprecated_func = deprecation.deprecated_alias("deprecated.func", "real.func", logging.error) logging.error("fake error logged") self.assertEqual(0, mock_warning.call_count) deprecated_func("FAKE ERROR!") self.assertEqual(1, mock_warning.call_count) # Make sure the error points to the right file. self.assertRegexpMatches(mock_warning.call_args[0][1], r"deprecation_test\.py:") deprecated_func("ANOTHER FAKE ERROR!") self.assertEqual(1, mock_warning.call_count)
def test_function_alias(self, mock_warning): deprecated_func = deprecation.deprecated_alias("deprecated.func", "real.func", logging.error) logging.error("fake error logged") self.assertEqual(0, mock_warning.call_count) deprecated_func("FAKE ERROR!") self.assertEqual(1, mock_warning.call_count) # Make sure the error points to the right file. self.assertRegexpMatches(mock_warning.call_args[0][1], r"deprecation_test\.py:") deprecated_func("ANOTHER FAKE ERROR!") self.assertEqual(1, mock_warning.call_count)
from typing import Text from tensorflow.python.util import deprecation # pylint: disable=g-direct-tensorflow-import from tfx import types from tfx.types import channel_utils from tfx.types import standard_artifacts def external_input(uri: Text) -> types.Channel: """Helper function to declare external input. Args: uri: external path. Returns: input channel. """ instance = standard_artifacts.ExternalArtifact() instance.uri = uri return channel_utils.as_channel([instance]) csv_input = deprecation.deprecated_alias( deprecated_name='csv_input', name='external_input', func_or_class=external_input) tfrecord_input = deprecation.deprecated_alias( deprecated_name='tfrecord_input', name='external_input', func_or_class=external_input)
# Lint as: python2, python3 # Copyright 2020 Google LLC. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Stub for pre-rename `tfx.dsl.components.base.base_node`.""" # TODO(b/149535307): Remove __future__ imports from __future__ import absolute_import from __future__ import division from __future__ import print_function from tfx.dsl.components.base import base_node from tensorflow.python.util import deprecation # pylint: disable=g-direct-tensorflow-import BaseNode = deprecation.deprecated_alias( # pylint: disable=invalid-name deprecated_name='tfx.components.base.base_node.BaseNode', name='tfx.dsl.components.base.base_node.BaseNode', func_or_class=base_node.BaseNode)
# Lint as: python2, python3 # Copyright 2019 Google LLC. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Deprecated definition of Airflow TFX runner.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function from tfx.orchestration.airflow import airflow_dag_runner from tensorflow.python.util import deprecation # pylint: disable=g-direct-tensorflow-import AirflowDAGRunner = deprecation.deprecated_alias( # pylint: disable=invalid-name deprecated_name='airflow_runner.AirflowDAGRunner', name='airflow_dag_runner.AirflowDagRunner', func_or_class=airflow_dag_runner.AirflowDagRunner)
This module and all its submodules are deprecated. See [contrib/learn/README.md](https://www.tensorflow.org/code/tensorflow/contrib/learn/README.md) for migration instructions. """ from __future__ import absolute_import from __future__ import division from __future__ import print_function from tensorflow.python.training import basic_session_run_hooks from tensorflow.python.util.deprecation import deprecated_alias # pylint: disable=invalid-name LoggingTensorHook = deprecated_alias( 'tf.contrib.learn.basic_session_run_hooks.LoggingTensorHook', 'tf.train.LoggingTensorHook', basic_session_run_hooks.LoggingTensorHook) StopAtStepHook = deprecated_alias( 'tf.contrib.learn.basic_session_run_hooks.StopAtStepHook', 'tf.train.StopAtStepHook', basic_session_run_hooks.StopAtStepHook) CheckpointSaverHook = deprecated_alias( 'tf.contrib.learn.basic_session_run_hooks.CheckpointSaverHook', 'tf.train.CheckpointSaverHook', basic_session_run_hooks.CheckpointSaverHook) StepCounterHook = deprecated_alias( 'tf.contrib.learn.basic_session_run_hooks.StepCounterHook', 'tf.train.StepCounterHook', basic_session_run_hooks.StepCounterHook) NanLossDuringTrainingError = deprecated_alias( 'tf.contrib.learn.basic_session_run_hooks.NanLossDuringTrainingError', 'tf.train.NanLossDuringTrainingError', basic_session_run_hooks.NanLossDuringTrainingError)
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Stub for pre-rename `tfx.dsl.components.base.base_executor`.""" # TODO(b/149535307): Remove __future__ imports from __future__ import absolute_import from __future__ import division from __future__ import print_function from tfx.dsl.components.base import base_executor from tensorflow.python.util import deprecation # pylint: disable=g-direct-tensorflow-import BaseExecutor = deprecation.deprecated_alias( # pylint: disable=invalid-name deprecated_name='tfx.components.base.base_executor.BaseExecutor', name='tfx.dsl.components.base.base_executor.BaseExecutor', func_or_class=base_executor.BaseExecutor) EmptyExecutor = deprecation.deprecated_alias( # pylint: disable=invalid-name deprecated_name='tfx.components.base.base_executor.EmptyExecutor', name='tfx.dsl.components.base.base_executor.EmptyExecutor', func_or_class=base_executor.EmptyExecutor)
# Copyright 2019 Google LLC. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Deprecated definition of Kubeflow TFX runner.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function from tensorflow.python.util import deprecation # pylint: disable=g-direct-tensorflow-import from tfx.orchestration.kubeflow import kubeflow_dag_runner KubeflowRunner = deprecation.deprecated_alias( # pylint: disable=invalid-name deprecated_name='runner.KubeflowRunner', name='kubeflow_dag_runner.KubeflowDagRunner', func_or_class=kubeflow_dag_runner.KubeflowDagRunner) KubeflowRunnerConfig = deprecation.deprecated_alias( # pylint: disable=invalid-name deprecated_name='runner.KubeflowRunnerConfig', name='kubeflow_dag_runner.KubeflowDagRunnerConfig', func_or_class=kubeflow_dag_runner.KubeflowDagRunnerConfig)
# Lint as: python2, python3 # Copyright 2020 Google LLC. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Stub for pre-rename `tfx.dsl.components.base.base_driver`.""" # TODO(b/149535307): Remove __future__ imports from __future__ import absolute_import from __future__ import division from __future__ import print_function from tfx.dsl.components.base import base_driver from tensorflow.python.util import deprecation # pylint: disable=g-direct-tensorflow-import BaseDriver = deprecation.deprecated_alias( # pylint: disable=invalid-name deprecated_name='tfx.components.base.base_driver.BaseDriver', name='tfx.dsl.components.base.base_driver.BaseDriver', func_or_class=base_driver.BaseDriver)
class KubeflowV2DagRunner(tfx_runner.TfxRunner): """Kubeflow V2 pipeline runner. Builds a pipeline job spec in json format based on TFX pipeline DSL object. """ def __init__(self, config: KubeflowV2DagRunnerConfig, output_dir: Optional[Text] = None, output_filename: Optional[Text] = None): """Constructs an KubeflowV2DagRunner for compiling pipelines. Args: config: An KubeflowV2DagRunnerConfig object to specify runtime configuration when running the pipeline in Kubeflow. output_dir: An optional output directory into which to output the pipeline definition files. Defaults to the current working directory. output_filename: An optional output file name for the pipeline definition file. The file output format will be a JSON-serialized PipelineJob pb message. Defaults to 'pipeline.json'. """ if not isinstance(config, KubeflowV2DagRunnerConfig): raise TypeError( 'config must be type of KubeflowV2DagRunnerConfig.') super(KubeflowV2DagRunner, self).__init__() self._config = config self._output_dir = output_dir or os.getcwd() self._output_filename = output_filename or 'pipeline.json' def run(self, pipeline: tfx_pipeline.Pipeline, parameter_values: Optional[Dict[Text, Any]] = None, write_out: Optional[bool] = True) -> Dict[Text, Any]: """Compiles a pipeline DSL object into pipeline file. Args: pipeline: TFX pipeline object. parameter_values: mapping from runtime parameter names to its values. write_out: set to True to actually write out the file to the place designated by output_dir and output_filename. Otherwise return the JSON-serialized pipeline job spec. Returns: Returns the JSON pipeline job spec. Raises: RuntimeError: if trying to write out to a place occupied by an existing file. """ # TODO(b/166343606): Support user-provided labels. # TODO(b/169095387): Deprecate .run() method in favor of the unified API # client. display_name = (self._config.display_name or pipeline.pipeline_info.pipeline_name) pipeline_spec = pipeline_builder.PipelineBuilder( tfx_pipeline=pipeline, default_image=self._config.default_image, default_commands=self._config.default_commands).build() pipeline_spec.sdk_version = version.__version__ pipeline_spec.schema_version = _SCHEMA_VERSION runtime_config = pipeline_builder.RuntimeConfigBuilder( pipeline_info=pipeline.pipeline_info, parameter_values=parameter_values).build() with telemetry_utils.scoped_labels( {telemetry_utils.LABEL_TFX_RUNNER: 'kubeflow_v2'}): result = pipeline_pb2.PipelineJob( display_name=display_name or pipeline.pipeline_info.pipeline_name, labels=telemetry_utils.get_labels_dict(), runtime_config=runtime_config) result.pipeline_spec.update(json_format.MessageToDict(pipeline_spec)) pipeline_json_dict = json_format.MessageToDict(result) if write_out: if fileio.exists( self._output_dir) and not fileio.isdir(self._output_dir): raise RuntimeError('Output path: %s is pointed to a file.' % self._output_dir) if not fileio.exists(self._output_dir): fileio.makedirs(self._output_dir) fileio.open(os.path.join(self._output_dir, self._output_filename), 'wb').write( json.dumps(pipeline_json_dict, sort_keys=True)) return pipeline_json_dict compile = deprecation.deprecated_alias(deprecated_name='compile', name='run', func_or_class=run)
# Copyright 2019 Google LLC. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Deprecated definition of runner to start TFX training jobs on CMLE.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function from tensorflow.python.util import deprecation # pylint: disable=g-direct-tensorflow-import from tfx.extensions.google_cloud_ai_platform import runner start_cmle_training = deprecation.deprecated_alias( deprecated_name='cmle_runner.start_cmle_training', name='runner.start_aip_training', func_or_class=runner.start_aip_training) deploy_model_for_cmle_serving = deprecation.deprecated_alias( deprecated_name='cmle_runner.deploy_model_for_cmle_serving', name='runner.deploy_model_for_aip_prediction', func_or_class=runner.deploy_model_for_aip_prediction)
from tfx.components.trainer import fn_args_utils from tfx.components.util import udf_utils from tfx.dsl.components.base import base_executor from tfx.dsl.io import fileio from tfx.types import artifact_utils from tfx.utils import io_utils from tfx.utils import json_utils from tfx.utils import path_utils from tensorflow.python.lib.io import file_io # pylint: disable=g-direct-tensorflow-import from tensorflow.python.util import deprecation # pylint: disable=g-direct-tensorflow-import from tensorflow_metadata.proto.v0 import schema_pb2 TrainerFnArgs = deprecation.deprecated_alias( # pylint: disable=invalid-name deprecated_name='tfx.components.trainer.executor.TrainerFnArgs', name='tfx.components.trainer.fn_args_utils.FnArgs', func_or_class=fn_args_utils.FnArgs) def _all_files_pattern(file_pattern: Text) -> Text: return os.path.join(file_pattern, '*') def _is_chief(): """Returns true if this is run in the master (chief) of training cluster.""" tf_config = json.loads(os.environ.get(constants.TF_CONFIG_ENV) or '{}') # If non distributed mode, current process should always behave as chief. if not tf_config or not tf_config.get('cluster', {}): return True
] with tf.control_dependencies(assertions): root, value_at_root, num_iterations, _, _ = tf.while_loop( cond=_should_continue, body=_body, loop_vars=(position, value_at_position, num_iterations, step, finished)) return RootSearchResults(estimated_root=root, objective_at_estimated_root=value_at_root, num_iterations=num_iterations) secant_root = deprecation.deprecated_alias('tfp.math.secant_root', 'tfp.math.find_root_secant', find_root_secant) def _structure_broadcasting_where(c, x, y): """Selects elements from two structures using a shared condition `c`.""" return tf.nest.map_structure(lambda xp, yp: tf.where(c, xp, yp), x, y) def find_root_chandrupatla(objective_fn, low, high, position_tolerance=1e-8, value_tolerance=0., max_iterations=50, stopping_policy_fn=tf.reduce_all,
This module and all its submodules are deprecated. See [contrib/learn/README.md](https://www.tensorflow.org/code/tensorflow/contrib/learn/README.md) for migration instructions. """ from __future__ import absolute_import from __future__ import division from __future__ import print_function from tensorflow.python.training import basic_session_run_hooks from tensorflow.python.util.deprecation import deprecated_alias # pylint: disable=invalid-name LoggingTensorHook = deprecated_alias( 'tf.contrib.learn.basic_session_run_hooks.LoggingTensorHook', 'tf.train.LoggingTensorHook', basic_session_run_hooks.LoggingTensorHook) StopAtStepHook = deprecated_alias( 'tf.contrib.learn.basic_session_run_hooks.StopAtStepHook', 'tf.train.StopAtStepHook', basic_session_run_hooks.StopAtStepHook) CheckpointSaverHook = deprecated_alias( 'tf.contrib.learn.basic_session_run_hooks.CheckpointSaverHook', 'tf.train.CheckpointSaverHook', basic_session_run_hooks.CheckpointSaverHook) StepCounterHook = deprecated_alias( 'tf.contrib.learn.basic_session_run_hooks.StepCounterHook', 'tf.train.StepCounterHook', basic_session_run_hooks.StepCounterHook) NanLossDuringTrainingError = deprecated_alias( 'tf.contrib.learn.basic_session_run_hooks.NanLossDuringTrainingError',
# Lint as: python2, python3 # Copyright 2020 Google LLC. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Stub for pre-rename `tfx.dsl.components.base.base_component`.""" # TODO(b/149535307): Remove __future__ imports from __future__ import absolute_import from __future__ import division from __future__ import print_function from tfx.dsl.components.base import base_component from tensorflow.python.util import deprecation # pylint: disable=g-direct-tensorflow-import BaseComponent = deprecation.deprecated_alias( # pylint: disable=invalid-name deprecated_name='tfx.components.base.base_component.BaseComponent', name='tfx.dsl.components.base.base_component.BaseComponent', func_or_class=base_component.BaseComponent)
# Lint as: python3 # Copyright 2019 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Collection of functions to compute properties of forwards.""" from tf_quant_finance.rates.analytics import forwards from tensorflow.python.util import deprecation # pylint: disable=g-direct-tensorflow-import forward_rates_from_yields = deprecation.deprecated_alias( 'tff.rates.forwards.forward_rates_from_yields', 'tff.rates.analytics.forwards.forward_rates_from_yields', forwards.forward_rates_from_yields) yields_from_forward_rates = deprecation.deprecated_alias( 'tff.rates.forwards.yields_from_forward_rates', 'tff.rates.analytics.forwards.yields_from_forward_rates', forwards.yields_from_forward_rates) __all__ = ['forward_rates_from_yields', 'yields_from_forward_rates']
# Copyright 2019 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Collection of functions to compute properties of cashflows.""" from tf_quant_finance.rates.analytics import cashflows from tensorflow.python.util import deprecation # pylint: disable=g-direct-tensorflow-import pv_from_yields = deprecation.deprecated_alias( 'tff.rates.cashflows.pv_from_yields', 'tff.rates.analytics.cashflows.pv_from_yields', cashflows.pv_from_yields) yields_from_pv = deprecation.deprecated_alias( 'tff.rates.cashflows.yields_from_pv', 'tff.rates.analytics.cashflows.yields_from_pv', cashflows.yields_from_pv) __all__ = ['pv_from_yields', 'yields_from_pv']
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Stub for pre-rename `tfx.dsl.components.base.executor_spec`.""" # TODO(b/149535307): Remove __future__ imports from __future__ import absolute_import from __future__ import division from __future__ import print_function from tfx.dsl.components.base import executor_spec from tensorflow.python.util import deprecation # pylint: disable=g-direct-tensorflow-import ExecutorSpec = deprecation.deprecated_alias( # pylint: disable=invalid-name deprecated_name='tfx.components.base.executor_spec.ExecutorSpec', name='tfx.dsl.components.base.executor_spec.ExecutorSpec', func_or_class=executor_spec.ExecutorSpec) ExecutorClassSpec = deprecation.deprecated_alias( # pylint: disable=invalid-name deprecated_name='tfx.components.base.executor_spec.ExecutorClassSpec', name='tfx.dsl.components.base.executor_spec.ExecutorClassSpec', func_or_class=executor_spec.ExecutorClassSpec) ExecutorContainerSpec = deprecation.deprecated_alias( # pylint: disable=invalid-name deprecated_name='tfx.components.base.executor_spec.ExecutorContainerSpec', name='tfx.dsl.components.base.executor_spec.ExecutorContainerSpec', func_or_class=executor_spec.ExecutorContainerSpec)