Skip to content

Commit

Permalink
[Data] Deprecate set_progress_bars (ray-project#43575)
Browse files Browse the repository at this point in the history
set_progress_bars is obsolete, and the recommended way to configure the progress bar is through the DataContext. To avoid having multiple ways to do the same thing, this PR deprecates set_progress_bars.

Signed-off-by: Balaji Veeramani <balaji@anyscale.com>
  • Loading branch information
bveeramani authored and hebiao064 committed Mar 12, 2024
1 parent 2907f24 commit 625bc56
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
11 changes: 9 additions & 2 deletions python/ray/data/_internal/progress_bar.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import threading
import warnings
from typing import Any, List, Optional

import ray
from ray.experimental import tqdm_ray
from ray.types import ObjectRef
from ray.util.annotations import PublicAPI
from ray.util.annotations import Deprecated

try:
import tqdm
Expand All @@ -19,7 +20,7 @@
_canceled_threads_lock = threading.Lock()


@PublicAPI
@Deprecated
def set_progress_bars(enabled: bool) -> bool:
"""Set whether progress bars are enabled.
Expand All @@ -33,6 +34,12 @@ def set_progress_bars(enabled: bool) -> bool:
"""
from ray.data import DataContext

warnings.warn(
"`set_progress_bars` is deprecated. Set "
"`ray.data.DataContext.get_current().enable_progress_bars` instead.",
DeprecationWarning,
)

ctx = DataContext.get_current()
old_value = ctx.enable_progress_bars
ctx.enable_progress_bars = enabled
Expand Down
6 changes: 6 additions & 0 deletions python/ray/data/tests/test_progress_bar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import functools

import pytest
from pytest import fixture

import ray
Expand All @@ -15,6 +16,11 @@ def enable_tqdm_ray(request):
context.use_ray_tqdm = original_use_ray_tqdm


def test_set_progress_bars_is_deprecated():
with pytest.warns(DeprecationWarning):
ray.data.set_progress_bars(True)


def test_progress_bar(enable_tqdm_ray):
total = 10
# Used to record the total value of the bar at close
Expand Down
2 changes: 1 addition & 1 deletion rllib/examples/learner/train_w_bc_finetune_w_ppo.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def train_ppo_agent_from_checkpointed_module(
if __name__ == "__main__":
ray.init()

ray.data.set_progress_bars(False)
ray.data.DataContext.get_current().enable_progress_bars = False

# You can use Ray Data to load a dataset from pandas or from a JSON file.
# The columns of the dataset are ["obs", "actions"].
Expand Down
2 changes: 1 addition & 1 deletion rllib/offline/dataset_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def __init__(self, ds: ray.data.Dataset, ioctx: Optional[IOContext] = None):
self._dataset = ds
self.count = None if not self._dataset else self._dataset.count()
# do this to disable the ray data stdout logging
ray.data.set_progress_bars(enabled=False)
ray.data.DataContext.get_current().enable_progress_bars = False

# the number of steps to return per call to next()
self.batch_size = self._ioctx.config.get("train_batch_size", 1)
Expand Down

0 comments on commit 625bc56

Please sign in to comment.