quantify_scheduler.helpers.collections

Helpers for various collections.

Module Contents

Functions

make_hash(→ int)

Makes a hash from a dictionary, list, tuple or set to any level, that contains

without(→ dict)

Utility that copies a dictionary excluding a specific list of keys.

find_inner_dicts_containing_key(→ List[dict])

Generates a list of the first dictionaries encountered that contain a certain key,

find_all_port_clock_combinations(→ List[Tuple[str, str]])

Generates a list with all port and clock combinations found in a dictionary with

find_port_clock_path(→ list | None)

Finds the path to a port-clock combination in a nested dictionary.

make_hash(obj: Any) int[source]

Makes a hash from a dictionary, list, tuple or set to any level, that contains only other hashable types (including any lists, tuples, sets, and dictionaries).

From: https://stackoverflow.com/questions/5884066/hashing-a-dictionary

Parameters

obj – Input collection.

Returns

Hash.

without(dict_in: dict, keys: list) dict[source]

Utility that copies a dictionary excluding a specific list of keys.

Parameters
  • dict_in – Input dictionary.

  • keys – List of keys to exclude.

Returns

Filtered dictionary.

find_inner_dicts_containing_key(d: dict, key: Any) List[dict][source]

Generates a list of the first dictionaries encountered that contain a certain key, in a complicated dictionary with nested dictionaries or Iterables.

This is achieved by recursively traversing the nested structures until the key is found, which is then appended to a list.

Parameters
  • d – The dictionary to traverse.

  • key – The key to search for.

Returns

A list containing all the inner dictionaries containing the specified key.

find_all_port_clock_combinations(d: dict) List[Tuple[str, str]][source]

Generates a list with all port and clock combinations found in a dictionary with nested structures. Traversing the dictionary is done using the find_inner_dicts_containing_key function.

Parameters

d – The dictionary to traverse.

Returns

A list containing tuples representing the port and clock combinations found in the dictionary.

find_port_clock_path(hardware_config: dict, port: str, clock: str) list | None[source]

Finds the path to a port-clock combination in a nested dictionary.

Parameters
  • hardware_config – The (nested) hardware config dictionary to loop over.

  • port – The port to find.

  • clock – The clock to find.

Returns

A list representing the keys to the port-clock combination in the hardware config. If the port-clock location is in a list, the list index is also included in this path.