Skip to content

Commit

Permalink
[RLlib] Removed deprecated code with error=True (ray-project#23916)
Browse files Browse the repository at this point in the history
  • Loading branch information
kouroshHakha authored Apr 15, 2022
1 parent bc558eb commit c38a295
Show file tree
Hide file tree
Showing 12 changed files with 2 additions and 137 deletions.
5 changes: 0 additions & 5 deletions rllib/agents/ars/ars.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from ray.rllib.env.env_context import EnvContext
from ray.rllib.policy.sample_batch import DEFAULT_POLICY_ID
from ray.rllib.utils.annotations import override
from ray.rllib.utils.deprecation import Deprecated
from ray.rllib.utils.torch_utils import set_torch_seed
from ray.rllib.utils.typing import TrainerConfigDict
from ray.rllib.utils import FilterManager
Expand Down Expand Up @@ -405,10 +404,6 @@ def compute_single_action(self, observation, *args, **kwargs):
return action[0], [], {}
return action[0]

@Deprecated(new="compute_single_action", error=True)
def compute_action(self, observation, *args, **kwargs):
return self.compute_single_action(observation, *args, **kwargs)

@override(Trainer)
def _sync_weights_to_workers(self, *, worker_set=None, workers=None):
# Broadcast the new policy weights to all evaluation workers.
Expand Down
35 changes: 0 additions & 35 deletions rllib/agents/bandit/tests/test_bandits.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import unittest

import ray
from ray import tune
import ray.rllib.agents.bandit.bandit as bandit
from ray.rllib.examples.env.bandit_envs_discrete import SimpleContextualBandit
from ray.rllib.utils.test_utils import check_train_results, framework_iterator
Expand Down Expand Up @@ -63,40 +62,6 @@ def test_bandit_lin_ucb_compilation(self):
self.assertTrue(results["episode_reward_mean"] == 10.0)
trainer.stop()

def test_deprecated_locations(self):
"""Tests, whether importing from old contrib dir fails gracefully.
Also checks for proper handling of tune.run("contrib/Lin...").
"""

def try_import_lints():
from ray.rllib.contrib.bandits.agents.lin_ts import LinTS # noqa

self.assertRaisesRegex(
DeprecationWarning, "has been deprecated. Use", try_import_lints
)

def try_import_linucb():
from ray.rllib.contrib.bandits.agents.lin_ucb import LinUCB # noqa

self.assertRaisesRegex(
DeprecationWarning, "has been deprecated. Use", try_import_linucb
)

def try_import_anything():
from ray.rllib.contrib.bandits.some_crazy_module import ( # noqa: F401
SomeCrazyClass,
)

self.assertRaisesRegex(
DeprecationWarning, "has been deprecated. Use", try_import_anything
)

# Assert that tune also raises an error.
self.assertRaises(ray.tune.error.TuneError, lambda: tune.run("contrib/LinTS"))

self.assertRaises(ray.tune.error.TuneError, lambda: tune.run("contrib/LinUCB"))


if __name__ == "__main__":
import pytest
Expand Down
6 changes: 0 additions & 6 deletions rllib/agents/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import traceback

from ray.rllib.contrib.registry import CONTRIBUTED_ALGORITHMS
from ray.rllib.utils.deprecation import Deprecated


def _import_a2c():
Expand Down Expand Up @@ -228,11 +227,6 @@ def get_trainer_class(alg: str, return_config=False) -> type:
return class_


@Deprecated(new="ray.rllib.agents.registry::get_trainer_class()", error=True)
def get_agent_class(alg: str) -> type:
return get_trainer_class(alg)


def _get_trainer_class(alg: str, return_config=False) -> type:
if alg in ALGORITHMS:
class_, config = ALGORITHMS[alg]()
Expand Down
9 changes: 0 additions & 9 deletions rllib/agents/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2719,11 +2719,6 @@ def __setstate__(self, state: dict):
if self.train_exec_impl is not None:
self.train_exec_impl.shared_metrics.get().restore(state["train_exec_impl"])

@staticmethod
@Deprecated(error=True)
def with_updates(*args, **kwargs):
pass

@DeveloperAPI
def _create_local_replay_buffer_if_necessary(
self, config: PartialTrainerConfigDict
Expand Down Expand Up @@ -3078,10 +3073,6 @@ def __repr__(self):
def compute_action(self, *args, **kwargs):
return self.compute_single_action(*args, **kwargs)

@Deprecated(new="Trainer.evaluate()", error=True)
def _evaluate(self) -> dict:
return self.evaluate()

@Deprecated(new="construct WorkerSet(...) instance directly", error=False)
def _make_workers(
self,
Expand Down
10 changes: 0 additions & 10 deletions rllib/agents/trainer_template.py

This file was deleted.

7 changes: 0 additions & 7 deletions rllib/contrib/bandits/__init__.py

This file was deleted.

14 changes: 2 additions & 12 deletions rllib/contrib/registry.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Registry of algorithm names for `rllib train --run=contrib/<alg_name>`"""

from ray.rllib.utils.deprecation import Deprecated


def _import_random_agent():
from ray.rllib.contrib.random_agent.random_agent import RandomAgent
Expand All @@ -27,21 +25,13 @@ def _import_alphazero():
def _import_bandit_lints():
from ray.rllib.agents.bandit.bandit import BanditLinTSTrainer

@Deprecated(old="contrib/LinTS", new="BanditLinTS", error=True)
class _DeprecatedBandit(BanditLinTSTrainer):
pass

return _DeprecatedBandit, BanditLinTSTrainer.get_default_config()
return BanditLinTSTrainer, BanditLinTSTrainer.get_default_config()


def _import_bandit_linucb():
from ray.rllib.agents.bandit.bandit import BanditLinUCBTrainer

@Deprecated(old="contrib/LinUCB", new="BanditLinUCB", error=True)
class _DeprecatedBandit(BanditLinUCBTrainer):
pass

return _DeprecatedBandit, BanditLinUCBTrainer.get_default_config()
return BanditLinUCBTrainer, BanditLinUCBTrainer.get_default_config()


CONTRIBUTED_ALGORITHMS = {
Expand Down
7 changes: 0 additions & 7 deletions rllib/examples/recsim_with_slateq.py

This file was deleted.

5 changes: 0 additions & 5 deletions rllib/tests/run_regression_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import ray
from ray.tune import run_experiments
from ray.rllib import _register_all
from ray.rllib.utils.deprecation import deprecation_warning

parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down Expand Up @@ -64,10 +63,6 @@
if __name__ == "__main__":
args = parser.parse_args()

# Error if deprecated --torch option used.
if args.torch:
deprecation_warning(old="--torch", new="--framework=torch", error=True)

# Bazel regression test mode: Get path to look for yaml files.
# Get the path or single file to use.
rllib_dir = Path(__file__).parent.parent
Expand Down
8 changes: 0 additions & 8 deletions rllib/utils/tf_ops.py

This file was deleted.

25 changes: 0 additions & 25 deletions rllib/utils/tf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import tree # pip install dm_tree
from typing import Any, Callable, List, Optional, Type, TYPE_CHECKING, Union

from ray.rllib.utils.deprecation import Deprecated
from ray.rllib.utils.framework import try_import_tf
from ray.rllib.utils.spaces.space_utils import get_base_struct_from_space
from ray.rllib.utils.typing import (
Expand All @@ -22,30 +21,6 @@
tf1, tf, tfv = try_import_tf()


@Deprecated(new="ray.rllib.utils.numpy.convert_to_numpy()", error=True)
def convert_to_non_tf_type(x: TensorStructType) -> TensorStructType:
"""Converts values in `stats` to non-Tensor numpy or python types.
Args:
x: Any (possibly nested) struct, the values in which will be
converted and returned as a new struct with all tf (eager) tensors
being converted to numpy types.
Returns:
A new struct with the same structure as `x`, but with all
values converted to non-tf Tensor types.
"""

# The mapping function used to numpyize torch Tensors.
def mapping(item):
if isinstance(item, (tf.Tensor, tf.Variable)):
return item.numpy()
else:
return item

return tree.map_structure(mapping, x)


def explained_variance(y: TensorType, pred: TensorType) -> TensorType:
"""Computes the explained variance for a pair of labels and predictions.
Expand Down
8 changes: 0 additions & 8 deletions rllib/utils/torch_ops.py

This file was deleted.

0 comments on commit c38a295

Please sign in to comment.