eta_ctrl.common.common module

eta_ctrl.common.common.deserialize_net_arch(net_arch: Sequence[Mapping[str, Any]], in_features: int, device: th.device | str = 'auto') th.nn.Sequential[source]

Deserialize_net_arch can take a list of dictionaries describing a sequential torch network and deserialize it by instantiating the corresponding classes.

An example for a possible net_arch would be:

[{"layer": "Linear", "out_features": 60},
 {"activation_func": "Tanh"},
 {"layer": "Linear", "out_features": 60},
 {"activation_func": "Tanh"}]

One key of the dictionary should be either ‘layer’, ‘activation_func’ or ‘process’. If the ‘layer’ key is present, a layer from the torch.nn module is instantiated, if the ‘activation_func’ key is present, the value will be instantiated as an activation function from torch.nn. If the key ‘process’ is present, the value will be interpreted as a data processor from eta_ctrl.common.processors.

All other keys of each dictionary will be used as keyword parameters to the instantiation of the layer, activation function or processor.

Only the number of input features for the first layer must be specified (using the ‘in_features’) parameter. The function will then automatically determine the number of input features for all other layers in the sequential network.

Parameters:
  • net_arch – List of dictionaries describing the network architecture.

  • in_features – Number of input features for the first layer.

  • device – Torch device to use for training the network.

Returns:

Sequential torch network.

eta_ctrl.common.common.is_vectorized(env: BaseEnv | VecEnv | VecNormalize | None) bool[source]

Check if an environment is vectorized.

Parameters:

env – The environment to check.

eta_ctrl.common.common.is_closed(env: BaseEnv | VecEnv | VecNormalize | None) bool[source]

Check whether an environment has been closed.

Parameters:

env – The environment to check.

eta_ctrl.common.common.episode_results_path(series_results_path: Path, run_name: str, episode: int, env_id: int = 1) pathlib.Path[source]

Generate a filepath which can be used for storing episode results of a specific environment as a csv file.

Name is of the format: ThisRun_001_01.csv (run name _ episode number _ environment id .csv)

Parameters:
  • series_results_path – Path for results of the series of optimization runs.

  • run_name – Name of the optimization run.

  • episode – Number of the episode the environment is working on.

  • env_id – Identification of the environment.

eta_ctrl.common.common.episode_name_string(run_name: str, episode: int, env_id: int = 1) str[source]

Generate a name which can be used to pre or postfix files from a specific episode and run of an environment.

Name is of the format: ThisRun_001_01 (run name _ episode number _ environment id)

Parameters:
  • run_name – Name of the optimization run.

  • episode – Number of the episode the environment is working on.

  • env_id – Identification of the environment.