Skip to content

Graph Utilities

graph

Functions to build the dependency graph of the parameters.

Functions

add_dependencies_to_graph

add_dependencies_to_graph(graph: DiGraph, dependencies: set[str], parameter_name: str) -> None

Add dependencies of a parameter to the graph.

Parameters:

Name Type Description Default
graph DiGraph

Dependency graph.

required
dependencies set[str]

A set of dependencies.

required
parameter_name str

Parameter name.

required

build_dependency_graph

build_dependency_graph(parameters_config: dict[str, Any]) -> DiGraph

Build a dependency graph.

Build a directed graph here:

  • nodes = parameter names
  • edge A → B means: "to compute/sample B, you need A first"

Parameters:

Name Type Description Default
parameters_config dict[str, Any]

A dictionary of parameters.

required

Returns:

Type Description
DiGraph

A DiGraph for topological sort.

extract_dependencies_from_spec

extract_dependencies_from_spec(spec: dict[str, Any]) -> set[str]

Recursively find all @references in a parameter spec (handles nested dicts/lists).

Parameters:

Name Type Description Default
spec dict[str, Any]

A dictionary of specification.

required

Returns:

Type Description
set[str]

A set of @references.

extract_references

extract_references(expr: str) -> set[str]

Very simple parser to find all @references in a string expression.

Example: "@m1 * @q + 5" → ['m1', 'q']

Parameters:

Name Type Description Default
expr str

Expression.

required

Returns:

Type Description
set[str]

A set of variables names (without the @).

extract_sampler_dependencies

extract_sampler_dependencies(sampler_spec: dict[str, Any]) -> set[str]

Extract the dependencies of the sampler.

Parameters:

Name Type Description Default
sampler_spec dict[str, Any]

Specifications of the sampler.

required

Returns:

Type Description
set[str]

A set of dependencies.

extract_transform_dependencies

extract_transform_dependencies(transform: str | dict[str, Any]) -> set[str]

Extract the dependencies of transform.

Parameters:

Name Type Description Default
transform str | dict[str, Any]

Expression or dictionary of transform.

required

Returns:

Type Description
set[str]

Dependencies of transform.