benchmarl.models.ModelConfig

class ModelConfig[source]

Bases: ABC

Dataclass representing a Model configuration. This should be overridden by implemented models. Implementors should:

  1. add configuration parameters for their algorithm

  2. implement all abstract methods

get_model(input_spec: CompositeSpec, output_spec: CompositeSpec, agent_group: str, input_has_agent_dim: bool, n_agents: int, centralised: bool, share_params: bool, device: device | str | int, action_spec: CompositeSpec) Model[source]

Creates the model from the config.

Parameters:
  • input_spec (CompositeSpec) – the input spec of the model

  • output_spec (CompositeSpec) – the output spec of the model

  • agent_group (str) – the name of the agent group the model is for

  • n_agents (int) – the number of agents this module is for

  • device (str) – the mdoel’s device

  • input_has_agent_dim (bool) – This tells the model if the input will have a multi-agent dimension or not. For example, the input of policies will always have this set to true, but critics that use a global state have this set to false as the state is shared by all agents

  • centralised (bool) – This tells the model if it has full observability. This will always be true when self.input_has_agent_dim==False, but in cases where the input has the agent dimension, this parameter is used to distinguish between a decentralised model (where each agent’s data is processed separately) and a centralized model, where the model pools all data together

  • share_params (bool) – This tells the model if it should have only one set of parameters or a different set of parameters for each agent. This is independent of the other options as it is possible to have different parameters for centralized critics with global input.

  • action_spec (CompositeSpec) – The action spec of the environment

Returns: the Model

abstract static associated_class()[source]

The associated Model class

process_env_fun(env_fun: Callable[[], EnvBase]) Callable[[], EnvBase][source]

This function can be used to wrap env_fun :param env_fun: a function that takes no args and creates an enviornment :type env_fun: callable

Returns: a function that takes no args and creates an enviornment

classmethod get_from_yaml(path: str | None = None)[source]

Load the model configuration from yaml

Parameters:

path (str, optional) – The full path of the yaml file to load from. If None, it will default to benchmarl/conf/model/layers/self.associated_class().__name__

Returns: the loaded AlgorithmConfig