Skip to content

Commit 305969b

Browse files
pseudo-rnd-thoughtsMark Towers
andauthored
[rllib] Re-enable all RLlib doctests (#58974)
## Description The RLlib team is working on improving our testing position. Currently several files are excluded in our doctest. This PR moves to add testing for the whole project --------- Signed-off-by: Mark Towers <mark@anyscale.com> Signed-off-by: Mark Towers <mark.m.towers@gmail.com> Co-authored-by: Mark Towers <mark@anyscale.com>
1 parent 11d7ad4 commit 305969b

File tree

5 files changed

+27
-41
lines changed

5 files changed

+27
-41
lines changed

rllib/BUILD.bazel

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -72,36 +72,10 @@ doctest(
7272
"**/examples/**",
7373
"**/tests/**",
7474
"**/test_*.py",
75-
# Deprecated modules
76-
"utils/memory.py",
75+
# Deprecated stub files that raise ValueError on import.
7776
"offline/off_policy_estimator.py",
7877
"offline/estimators/feature_importance.py",
79-
# Missing imports
80-
"algorithms/dreamerv3/**",
81-
# FIXME: These modules contain broken examples that weren't previously
82-
# tested.
83-
"algorithms/algorithm_config.py",
84-
"core/distribution/torch/torch_distribution.py",
85-
"core/models/base.py",
86-
"core/models/specs/specs_base.py",
87-
"core/models/specs/specs_dict.py",
88-
"env/wrappers/pettingzoo_env.py",
89-
"evaluation/collectors/sample_collector.py",
90-
"evaluation/metrics.py",
91-
"evaluation/observation_function.py",
92-
"evaluation/postprocessing.py",
93-
"execution/buffers/mixin_replay_buffer.py",
94-
"models/catalog.py",
95-
"models/preprocessors.py",
96-
"models/repeated_values.py",
97-
"policy/rnn_sequencing.py",
98-
"utils/actor_manager.py",
99-
"utils/filter.py",
100-
"utils/from_config.py",
101-
"utils/metrics/window_stat.py",
102-
"utils/pre_checks/env.py",
103-
"utils/replay_buffers/multi_agent_mixin_replay_buffer.py",
104-
"utils/spaces/space_utils.py",
78+
"utils/memory.py",
10579
],
10680
),
10781
tags = ["team:rllib"],

rllib/algorithms/algorithm_config.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class AlgorithmConfig(_Config):
111111
.. testcode::
112112
113113
from ray.rllib.algorithms.ppo import PPOConfig
114-
from ray.rllib.algorithms.callbacks import MemoryTrackingCallbacks
114+
from ray.rllib.callbacks.callbacks import MemoryTrackingCallbacks
115115
# Construct a generic config object, specifying values within different
116116
# sub-categories, e.g. "training".
117117
config = (
@@ -6134,7 +6134,13 @@ class DifferentiableAlgorithmConfig(AlgorithmConfig):
61346134
61356135
.. testcode::
61366136
6137-
from ray.rllib.algorithm.algorithm_config import DifferentiableAlgorithmConfig
6137+
from ray.rllib.algorithms.algorithm_config import DifferentiableAlgorithmConfig
6138+
from ray.rllib.core.learner.differentiable_learner_config import (
6139+
DifferentiableLearnerConfig,
6140+
)
6141+
from ray.rllib.core.learner.torch.torch_differentiable_learner import (
6142+
TorchDifferentiableLearner,
6143+
)
61386144
# Construct a generic config for an algorithm that needs differentiable Learners.
61396145
config = (
61406146
DifferentiableAlgorithmConfig()
@@ -6143,15 +6149,14 @@ class DifferentiableAlgorithmConfig(AlgorithmConfig):
61436149
.learners(
61446150
differentiable_learner_configs=[
61456151
DifferentiableLearnerConfig(
6146-
DifferentiableTorchLearner,
6152+
TorchDifferentiableLearner,
61476153
lr=1e-4,
61486154
)
61496155
]
61506156
)
61516157
)
6152-
# Similar to `AlgorithmConfig` the config using differentiable Learners can be
6153-
# used to build a respective `Algorithm`.
6154-
algo = config.build()
6158+
# The config is then used to configure a MetaLearner, see
6159+
# `rllib/examples/algorithms/maml_lr_supervised_learning.py` for a full example.
61556160
61566161
61576162
"""

rllib/algorithms/dreamerv3/dreamerv3.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ class DreamerV3Config(AlgorithmConfig):
8383
algo = config.build()
8484
# algo.train()
8585
del algo
86-
87-
.. testoutput::
88-
:hide:
89-
90-
...
9186
"""
9287

9388
def __init__(self, algo_class=None):

rllib/core/models/base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ def __init__(self, config):
4141
def _forward(self, input_dict):
4242
return input_dict["obs"] * self.my_param
4343
44+
def get_num_parameters(self):
45+
return (0, 0)
46+
47+
def _set_to_dummy_weights(self, value_sequence=(-0.02, -0.01, 0.01, 0.02)):
48+
pass
49+
4450
4551
@dataclass
4652
class MyModelConfig(ModelConfig):
@@ -244,6 +250,12 @@ def _forward(self, input_dict, **kwargs):
244250
),
245251
}
246252
253+
def get_num_parameters(self):
254+
return (0, 0)
255+
256+
def _set_to_dummy_weights(self, value_sequence=(-0.02, -0.01, 0.01, 0.02)):
257+
pass
258+
247259
@dataclass
248260
class NumpyEncoderConfig(ModelConfig):
249261
factor: int = None

rllib/utils/actor_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ class FaultTolerantActorManager:
205205
206206
@ray.remote
207207
class MyActor:
208-
def apply(self, fn):
209-
return fn(self)
208+
def apply(self, func):
209+
return func(self)
210210
211211
def do_something(self):
212212
return True

0 commit comments

Comments
 (0)