2019-01-03 15:15:36 +08:00
|
|
|
import os
|
2021-12-10 09:41:29 +01:00
|
|
|
from typing import Optional, TYPE_CHECKING
|
2019-01-03 15:15:36 +08:00
|
|
|
|
2019-01-23 21:27:26 -08:00
|
|
|
from ray.rllib.utils.annotations import PublicAPI
|
2022-06-11 15:10:39 +02:00
|
|
|
from ray.rllib.utils.typing import AlgorithmConfigDict
|
2021-11-01 10:59:53 +01:00
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from ray.rllib.evaluation.sampler import SamplerInput
|
2021-12-10 09:41:29 +01:00
|
|
|
from ray.rllib.evaluation.rollout_worker import RolloutWorker
|
2018-12-12 13:57:48 -08:00
|
|
|
|
|
|
|
|
2019-01-23 21:27:26 -08:00
|
|
|
@PublicAPI
|
2020-01-02 17:42:13 -08:00
|
|
|
class IOContext:
|
2021-11-01 10:59:53 +01:00
|
|
|
"""Class containing attributes to pass to input/output class constructors.
|
2018-12-12 13:57:48 -08:00
|
|
|
|
2021-11-01 10:59:53 +01:00
|
|
|
RLlib auto-sets these attributes when constructing input/output classes,
|
|
|
|
such as InputReaders and OutputWriters.
|
2018-12-12 13:57:48 -08:00
|
|
|
"""
|
|
|
|
|
2019-01-23 21:27:26 -08:00
|
|
|
@PublicAPI
|
2020-07-27 14:01:17 -07:00
|
|
|
def __init__(
|
|
|
|
self,
|
2021-11-01 10:59:53 +01:00
|
|
|
log_dir: Optional[str] = None,
|
2022-06-11 15:10:39 +02:00
|
|
|
config: Optional[AlgorithmConfigDict] = None,
|
2020-07-27 14:01:17 -07:00
|
|
|
worker_index: int = 0,
|
2021-12-10 09:41:29 +01:00
|
|
|
worker: Optional["RolloutWorker"] = None,
|
|
|
|
):
|
2021-11-01 10:59:53 +01:00
|
|
|
"""Initializes a IOContext object.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
log_dir: The logging directory to read from/write to.
|
2022-06-11 15:10:39 +02:00
|
|
|
config: The Algorithm's main config dict.
|
2022-06-01 11:27:54 -07:00
|
|
|
worker_index: When there are multiple workers created, this
|
2021-11-01 10:59:53 +01:00
|
|
|
uniquely identifies the current worker. 0 for the local
|
|
|
|
worker, >0 for any of the remote workers.
|
2021-12-10 09:41:29 +01:00
|
|
|
worker: The RolloutWorker object reference.
|
2021-11-01 10:59:53 +01:00
|
|
|
"""
|
2019-01-03 15:15:36 +08:00
|
|
|
self.log_dir = log_dir or os.getcwd()
|
|
|
|
self.config = config or {}
|
2018-12-12 13:57:48 -08:00
|
|
|
self.worker_index = worker_index
|
2019-06-03 06:49:24 +08:00
|
|
|
self.worker = worker
|
2018-12-12 13:57:48 -08:00
|
|
|
|
2019-01-23 21:27:26 -08:00
|
|
|
@PublicAPI
|
2021-11-01 10:59:53 +01:00
|
|
|
def default_sampler_input(self) -> Optional["SamplerInput"]:
|
|
|
|
"""Returns the RolloutWorker's SamplerInput object, if any.
|
|
|
|
|
|
|
|
Returns None if the RolloutWorker has no SamplerInput. Note that local
|
|
|
|
workers in case there are also one or more remote workers by default
|
|
|
|
do not create a SamplerInput object.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The RolloutWorkers' SamplerInput object or None if none exists.
|
|
|
|
"""
|
2019-06-03 06:49:24 +08:00
|
|
|
return self.worker.sampler
|
2021-07-10 18:05:25 -04:00
|
|
|
|
|
|
|
@property
|
2022-05-21 15:05:07 -07:00
|
|
|
@PublicAPI
|
2021-07-10 18:05:25 -04:00
|
|
|
def input_config(self):
|
|
|
|
return self.config.get("input_config", {})
|
2022-01-26 07:00:46 -08:00
|
|
|
|
|
|
|
@property
|
2022-05-21 15:05:07 -07:00
|
|
|
@PublicAPI
|
2022-01-26 07:00:46 -08:00
|
|
|
def output_config(self):
|
|
|
|
return self.config.get("output_config", {})
|