Skip to content

IdManager

Full path: schola.core.utils.id_manager.IdManager

schola.core.utils.id_manager.IdManager

IdManager

IdManager(ids)

Bases: object

A class to manage the mapping between nested and flattened ids.

Parameters

ids (List[List[int]]) : A nested list of lists of ids to manage, index in the list is first id, second id is stored in the second list.

ids

ids

The nested list of lists of ids to manage.

Type

  • List[List[int]]

Methods

ItemDescription
init
flatten_dict_of_dictsFlatten a dictionary of nested ids into a list of values.
flatten_list_of_dictsFlatten a list of dictionaries with nested ids into a single list.
get_flattened_idGet the flattened id from a nested id.
get_nested_idGet the nested id from a flattened id.
nest_list_to_dict_of_dictsNest a list of values, indexed by flattened id, into a dictionary of nested ids.
partial_getGet the second ids for a given first id.

Attributes

ItemDescription
id_listList of nested ids, for lookups from flattened id to nested ids.
id_mapList of dictionaries mapping nested ids to flattened ids.
num_envs
num_idsThe number of ids managed by the IdManager.

init

__init__(ids)

Parameters

ids (List[List[str]])


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[int, Dict[int, T]]) : The dictionary to flatten.

default (Optional[T], optional) : The default value to use if a key is not found, by default None.

Returns

A flattened list of the values found in the dictionary.

Return type: List[T]


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[Dict[str, T]]) : A list of dictionaries to flatten, where the list index represents the first id and dictionary keys represent the second ids.

default (Optional[T], optional) : The default value to use if a key is not found, by default None.

Returns

A flattened list of the values found in the nested structure. Ordered by UID.

Return type: List[T]


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.

Returns

The flattened id.

Return type: int


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.

Returns

The nested id.

Return type: Tuple[int,int]


id_list

id_list: List[Tuple[int, str]]

List of nested ids, for lookups from flattened id to nested ids.


id_map

id_map: List[Dict[str, int]]

List of dictionaries mapping nested ids to flattened ids.


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[T]) : The list of values to convert into a nested dictionary.

default (Optional[T], optional) : The default value to use if a key is not found, by default None.

Returns

A nested dictionary of the values in id_list or default if values are missing.

Return type: Dict[int, Dict[int, T]]


num_envs

num_envs: int

num_ids

num_ids: int

The number of ids managed by the IdManager.


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.

Returns

The second ids for the given first id.

Return type: List[int]