BCConfig#

class ray.rllib.algorithms.bc.bc.BCConfig(algo_class=None)[source]#

Bases: MARWILConfig

Defines a configuration class from which a new BC Algorithm can be built

Examples

>>> from pathlib import Path
>>> import gymnasium as gym
>>> from ray.rllib.algorithms.bc import BCConfig
>>> # Get the path to the CartPole data in the rllib folder.
>>> base_path = Path(__file__).parents[2]
>>> data_path = base_path / "offline/tests/data/cartpole/cartpole-v1_large"
>>> config = BCConfig().training(lr=0.00001, gamma=0.99)
>>> # Set the observation and action spaces of the data.
>>> env = gym.make("CartPole-v1")
>>> config = config.environment(
...     observation_space=env.observation_space,
...     action_space=env.action_space,
... )
>>> config = config.offline_data(
...     input_=[data_path.as_posix()],
...     # Run exactly one update per training iteration.
...     dataset_num_iters_per_learner=1,
... )
>>> # Build an Algorithm object from the config and run 1 training iteration.
>>> algo = config.build()
>>> _ = algo.train()
>>> from ray.rllib.algorithms.bc import BCConfig
>>> from ray import tune
>>> config = BCConfig()
>>> # Print out some default values.
>>> print(config.beta)
0.0
>>> # Update the config object.
>>> _ = config.training(lr=tune.grid_search([0.001, 0.0001]))
>>> # Set the config object's data path.
>>> _ = config.offline_data(
...     input_=[data_path.as_posix()],
...     dataset_num_iters_per_learner=1,
... )
>>> # Set the observation and action spaces of the data.
>>> _ = config.environment(
...     observation_space=env.observation_space,
...     action_space=env.action_space,
... )
>>> # Use to_dict() to get the old-style python config dict
>>> # when running with tune.
>>> print("[ignore]"); results = tune.Tuner(
...     "BC",
...     param_space=config.to_dict(),
...     # Run one trial at a time so each trial's offline data
...     # pipeline can get the CPUs it needs.
...     tune_config=tune.TuneConfig(max_concurrent_trials=1),
...     run_config=tune.RunConfig(stop={"training_iteration": 1}),
... ).fit()
[ignore]...
>>> results.num_errors
0
get_default_rl_module_spec() → RLModuleSpec | MultiRLModuleSpec[source]#

Returns the RLModule spec to use for this algorithm.

Override this method in the subclass to return the RLModule spec, given the input framework.

Returns:

The RLModuleSpec (or MultiRLModuleSpec) to use for this algorithm’s RLModule.

Return type:

RLModuleSpec | MultiRLModuleSpec

validate() → None[source]#

Validates all values in this config.