OmniSafe Config#

Config(**kwargs)

Config class for storing hyperparameters.

Config#

OmniSafe use yaml file to store all the configurations. The configuration file is stored in omnisafe/configs. The configuration file is divided into several parts.

Take PPOLag as an example, the configuration file is as follows:

Config

Description

train_cfgs

Training configurations.

algo_cfgs

Algorithm configurations

logger_cfgs

Logger configurations

model_cfgs

Model configurations

lagrange_cfgs[Optional]

Lagrange configurations

Specifically, the train_cfgs is as follows:

Config

Description

Value

device

Device to use.

cuda or cpu

torch_threads

Number of threads to use.

16

vector_env_nums

Number of vectorized environments.

1

parallel

Number of parallel agent, similar to A3C.

1

total_steps

Total number of training steps.

1000000

Other configurations are similar to train_cfgs. You can refer to the omnisafe/configs for more details.

Documentation

class omnisafe.utils.config.Config(**kwargs)[source]#

Config class for storing hyperparameters.

OmniSafe uses a Config class to store all hyperparameters. OmniSafe store hyperparameters in a yaml file and load them into a Config object. Then the Config class will check the hyperparameters are valid, then pass them to the algorithm class.

Initialize Config.

__init__(**kwargs)[source]#

Initialize Config.

static dict2config(config_dict)[source]#

Convert dictionary to Config.

Parameters:

config_dict (dict) – dictionary to be converted.

Return type:

Config

recurisve_update(update_args)[source]#

Recursively update args.

Parameters:

update_args (Dict[str, Any]) – args to be updated.

Return type:

None

todict()[source]#

Convert Config to dictionary.

Return type:

dict

tojson()[source]#

Convert Config to json string.

Return type:

str

Model Config#

Documentation

class omnisafe.utils.config.ModelConfig(**kwargs)[source]#

Model config.

Initialize Config.

__init__(**kwargs)#

Initialize Config.

Common Method#

Documentation

omnisafe.utils.config.get_default_kwargs_yaml(algo, env_id, algo_type)[source]#

Get the default kwargs from yaml file.

Note

This function search the yaml file by the algorithm name and environment name. Make sure your new implemented algorithm or environment has the same name as the yaml file.

Parameters:
  • algo (str) – algorithm name.

  • env_id (str) – environment name.

Return type:

Config

Documentation

omnisafe.utils.config.check_all_configs(configs, algo_type)[source]#

Check all configs.

This function is used to check the configs.

Parameters:
  • configs (dict) – configs to be checked.

  • algo_type (str) – algorithm type.

Return type:

None

Documentation

omnisafe.utils.config.__check_algo_configs(configs, algo_type)[source]#

Check algorithm configs.

This function is used to check the algorithm configs.

Note

  • update_iters must be greater than 0 and must be int.

  • update_cycle must be greater than 0 and must be int.

  • batch_size must be greater than 0 and must be int.

  • target_kl must be greater than 0 and must be float.

  • entropy_coeff must be in [0, 1] and must be float.

  • gamma must be in [0, 1] and must be float.

  • cost_gamma must be in [0, 1] and must be float.

  • lam must be in [0, 1] and must be float.

  • lam_c must be in [0, 1] and must be float.

  • clip must be greater than 0 and must be float.

  • penalty_coeff must be greater than 0 and must be float.

  • reward_normalize must be bool.

  • cost_normalize must be bool.

  • obs_normalize must be bool.

  • kl_early_stop must be bool.

  • use_max_grad_norm must be bool.

  • use_cost must be bool.

  • max_grad_norm must be greater than 0 and must be float.

  • adv_estimation_method must be in [gae, v-trace, gae-rtg, plain].

  • standardized_rew_adv must be bool.

  • standardized_cost_adv must be bool.

Parameters:
  • configs (Config) – configs to be checked.

  • algo_type (str) – algorithm type.

Return type:

None

Documentation

omnisafe.utils.config.__check_logger_configs(configs, algo_type)[source]#

Check logger configs.

Return type:

None