Skip to content

yaml

YAML configuration parsing for sync graph setup.

Functions:

  • clock_tree_to_digraph

    Transform a tree-shaped dict of clock IDs to a digraph.

  • get_subtree

    Get a required key from a dict, raising ValueError if missing.

  • parse_diff_thresholds

    Parse a diff thresholds dictionary into a DiffThresholds object.

  • parse_unit

    Parse and validate a time unit string.

  • to_config

    Parse a thresholds dictionary into a Config object.

  • to_sync_graph_args

    Parse a YAML config dict into SyncGraph constructor arguments.

clock_tree_to_digraph

clock_tree_to_digraph(clock_tree: dict) -> DiGraph

Transform a tree-shaped dict of clock IDs to a digraph.

Examples:

>>> tree = {"main.sys": {"sub.sys": {"other.sys"}}}
>>> G = clock_tree_to_digraph(tree)
>>> G  # main.sys -> sub.sys -> other.sys

Parameters:

  • clock_tree (dict) –

    one or multiple trees of clock IDs.

Returns:

  • DiGraph

    nx.DiGraph: The parsed, valid graph

get_subtree

get_subtree(
    d: dict, key: str, typ: type, yaml_path: str = ""
) -> Any

Get a required key from a dict, raising ValueError if missing.

Parameters:

  • d (dict) –

    The dictionary to get the key from.

  • key (str) –

    The required key.

  • typ (type) –

    The expected type of the value.

  • yaml_path (str, default: '' ) –

    The YAML path from the root to the current dict, for better error messages.

Raises:

  • ValueError

    If the key is not present in the dict.

Returns:

  • Any

    The value at the specified key, cast to the expected type.

parse_diff_thresholds

parse_diff_thresholds(
    diff_thresholds: dict,
) -> DiffThresholds

Parse a diff thresholds dictionary into a DiffThresholds object.

parse_unit

parse_unit(unit: str) -> Literal['ns', 'us', 'ms']

Parse and validate a time unit string.

Parameters:

  • unit (str) –

    Time unit string to parse.

Raises:

  • ValueError

    If unit is not 'ns', 'us', or 'ms'.

Returns:

  • Literal['ns', 'us', 'ms']

    The validated unit literal.

to_config

to_config(thresholds: dict) -> Config

Parse a thresholds dictionary into a Config object.

to_sync_graph_args

to_sync_graph_args(
    yaml_config: dict,
) -> tuple[Config, DiGraph]

Parse a YAML config dict into SyncGraph constructor arguments.

Parameters:

  • yaml_config (dict) –

    The parsed YAML configuration dictionary.

Returns:

  • tuple[Config, DiGraph]

    A tuple of (config, reference_graph) for SyncGraph initialization.