IdManager
Full path:
schola.core.utils.id_manager.IdManager
A class to manage the mapping between nested and flattened ids.
IdManager(ids, agent_types = None)Parameters
-
ids(List) - A nested list of lists of ids to manage, index in the list is first id, second id is stored in the second list. -
agent_types(dict) - Optional per-agent type metadata, either {env_id:{agent_id: type}}or a list aligned with ids indices.
Methods
init
__init__(ids, agent_types = None)Parameters
-
ids(List) -
agent_types(Dict)
agent_types_for_env
agent_types_for_env(env_id)Get the agent type mapping for one managed environment.
Parameters
env_id(int)
flatten_dict_of_dicts
flatten_dict_of_dicts(nested_id_dict, default = None)Flatten a dictionary of nested ids into a list of values.
Parameters
-
nested_id_dict(Dict) - The dictionary to flatten. -
default(Optional) - The default value to use if a key is not found, by default None.
flatten_list_of_dicts
flatten_list_of_dicts(nested_id_list, default = None)Flatten a list of dictionaries with nested ids into a single list.
Parameters
-
nested_id_list(List) - A list of dictionaries to flatten, where the list index represents the first id and dictionary keys represent the second ids. -
default(Optional) - The default value to use if a key is not found, by default None.
get_agent_type
get_agent_type(env_id, agent_id)Get one agent’s type, or an empty string when it has no type metadata.
Parameters
-
env_id(int) -
agent_id(str)
get_flattened_id
get_flattened_id(first_id, second_id)Get the flattened id from a nested id.
Parameters
-
first_id(int) - The first id. -
second_id(int) - The second id.
get_nested_id
get_nested_id(flat_id)Get the nested id from a flattened id.
Parameters
flat_id(int) - The flattened id to convert.
nest_list_to_dict_of_dicts
nest_list_to_dict_of_dicts(id_list, default = None)Nest a list of values, indexed by flattened id, into a dictionary of nested ids.
Parameters
-
id_list(List) - The list of values to convert into a nested dictionary. -
default(Optional) - The default value to use if a key is not found, by default None.
partial_get
partial_get(first_id)Get the second ids for a given first id.
Parameters
first_id(int) - The first id to get the second ids for.
Attributes
ids
ids : List[List[int]]The nested list of lists of ids to manage.
agent_types
agent_typesNested mapping of environment IDs to agent IDs to optional agent types.
id_list
id_listList of nested ids, for lookups from flattened id to nested ids.
id_map
id_mapList of dictionaries mapping nested ids to flattened ids.
num_envs
num_envsNumber of top-level environments (length of ids).
num_ids
num_idsThe number of ids managed by the IdManager.