config.config

config

Config

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

Base class for config.

Interface:

__init__, file_to_dict

Property:

cfg_dict

__init__(cfg_dict: Optional[dict] = None, cfg_text: Optional[str] = None, filename: Optional[str] = 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)ding.config.config.Config[source]
Overview:

Read config file and create config.

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

Returns:
  • cfg_dict (Config): config class

read_config_yaml

ding.config.config.read_config_yaml(path: str)easydict.EasyDict[source]
Overview:

read configuration from path

Arguments:
  • path (str): Path of source yaml

Returns:
  • (EasyDict): Config data from this file with dict type

save_config_yaml

ding.config.config.save_config_yaml(config_: dict, path: str)NoReturn[source]
Overview:

save configuration to path

Arguments:
  • config (dict): Config dict

  • path (str): Path of target yaml

save_config_py

ding.config.config.save_config_py(config_: dict, path: str)NoReturn[source]
Overview:

save configuration to python file

Arguments:
  • config (dict): Config dict

  • path (str): Path of target yaml

read_config

ding.config.config.read_config(cfg: str, direct: bool = False)Tuple[dict, dict][source]
Overview:

read configuration from python file

Arguments:
  • cfg (str): Path of python file

  • direct (bool): Read config directly if direct is true or divide config into main_config, create_config and system_config if direct is false

Returns:
  • cfg (Tuple[dict, dict]): Config dict, such as [main_config, create_config, system_config] or main_config, create_config, system_config

save_config

ding.config.config.save_config(config_: dict, path: str, type_: str = 'py', save_formatted: bool = False)NoReturn[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.config.compile_config(cfg: easydict.EasyDict, env_manager: Optional[type] = None, policy: Optional[type] = None, learner: type = <class 'ding.worker.learner.base_learner.BaseLearner'>, collector: Optional[type] = None, evaluator: type = <class 'ding.worker.collector.base_serial_evaluator.BaseSerialEvaluator'>, buffer: Optional[type] = None, env: Optional[type] = None, reward_model: Optional[type] = None, seed: int = 0, auto: bool = False, create_cfg: Optional[dict] = None, save_cfg: bool = True, save_path: str = 'total_config.py')easydict.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 BaseSerialEvaluator

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

  • 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

Returns:
  • cfg (EasyDict): Config after compiling

compile_config_parallel

ding.config.config.compile_config_parallel(cfg: easydict.EasyDict, create_cfg: easydict.EasyDict, system_cfg: easydict.EasyDict, seed: int = 0, save_cfg: bool = True, save_path: str = 'total_config.py', platform: str = 'local', coordinator_host: Optional[str] = None, learner_host: Optional[str] = None, collector_host: Optional[str] = None, coordinator_port: Optional[int] = None, learner_port: Optional[int] = None, collector_port: Optional[int] = None)easydict.EasyDict[source]
Overview:

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

Arguments:
  • cfg (EasyDict): Input main config dict

  • create_cfg (dict): Input create config dict, including type parameters, such as environment type

  • system_cfg (dict): Input system config dict, including system parameters, such as file path, communication mode, use multiple GPUs or not

  • seed (int): Random number seed

  • save_cfg (bool): Save config or not

  • save_path (str): Path of saving file

  • platform (str): Where to run the program, ‘local’ or ‘slurm’

  • coordinator_host (Optional[str]): Input coordinator’s host when platform is slurm

  • learner_host (Optional[str]): Input learner’s host when platform is slurm

  • collector_host (Optional[str]): Input collector’s host when platform is slurm

Returns:
  • cfg (EasyDict): Config after compiling