Shortcuts

ding.config

Config

class ding.config.Config(cfg_dict: dict | None = None, cfg_text: str | None = None, filename: str | None = None)[source]
Overview:

Base class for config.

Interface:

__init__, file_to_dict

Property:

cfg_dict

__init__(cfg_dict: dict | None = None, cfg_text: str | None = None, filename: str | None = None) None[source]
Overview:

Init method. Create config including dict type config and text type config.

Arguments:
  • cfg_dict (Optional[dict]): dict type config

  • cfg_text (Optional[str]): text type config

  • filename (Optional[str]): config file name

static _file_to_dict(filename: str) Tuple[dict, str][source]
Overview:

Read config file and convert the config file to dict type config and text type config.

Arguments:
  • filename (Optional[str]): config file name.

Returns:
  • cfg_dict (Optional[dict]): dict type config

  • cfg_text (Optional[str]): text type config

static file_to_dict(filename: str) Config[source]
Overview:

Read config file and create config.

Arguments:
  • filename (Optional[str]): config file name.

Returns:
  • cfg_dict (Config): config class

read_config

ding.config.read_config(path: str) Tuple[dict, dict][source]
Overview:

Read configuration from a file path(now only support python file). And select some proper parts.

Arguments:
  • path (str): Path of configuration file

Returns:
  • cfg (Tuple[dict, dict]): A collection(tuple) of configuration dict, divided into main_config and create_cfg two parts.

save_config

ding.config.save_config(config_: dict, path: str, type_: str = 'py', save_formatted: bool = False) None[source]
Overview:

save configuration to python file or yaml file

Arguments:
  • config (dict): Config dict

  • path (str): Path of target yaml or target python file

  • type (str): If type is yaml , save configuration to yaml file. If type is py , save configuration to python file.

  • save_formatted (bool): If save_formatted is true, save formatted config to path. Formatted config can be read by serial_pipeline directly.

compile_config

ding.config.compile_config(cfg: ~easydict.EasyDict, env_manager: type | None = None, policy: type | None = None, learner: type = <class 'ding.worker.learner.base_learner.BaseLearner'>, collector: type | None = None, evaluator: type = <class 'ding.worker.collector.interaction_serial_evaluator.InteractionSerialEvaluator'>, buffer: type | None = None, env: type | None = None, reward_model: type | None = None, world_model: type | None = None, seed: int = 0, auto: bool = False, create_cfg: dict | None = None, save_cfg: bool = True, save_path: str = 'total_config.py', renew_dir: bool = True) EasyDict[source]
Overview:

Combine the input config information with other input information. Compile config to make it easy to be called by other programs

Arguments:
  • cfg (EasyDict): Input config dict which is to be used in the following pipeline

  • env_manager (type): Env_manager class which is to be used in the following pipeline

  • policy (type): Policy class which is to be used in the following pipeline

  • learner (type): Input learner class, defaults to BaseLearner

  • collector (type): Input collector class, defaults to BaseSerialCollector

  • evaluator (type): Input evaluator class, defaults to InteractionSerialEvaluator

  • buffer (type): Input buffer class, defaults to IBuffer

  • env (type): Environment class which is to be used in the following pipeline

  • reward_model (type): Reward model class which aims to offer various and valuable reward

  • seed (int): Random number seed

  • auto (bool): Compile create_config dict or not

  • create_cfg (dict): Input create config dict

  • save_cfg (bool): Save config or not

  • save_path (str): Path of saving file

  • renew_dir (bool): Whether to new a directory for saving config.

Returns:
  • cfg (EasyDict): Config after compiling