pyBabyMaker.dag_resolver¶
This module provides general variable dependency resolution.
To be more technical, this is a Directed Acyclic Graph (DAG) resolver. I decided traverse the DAG tree in a depth-first manner, so there’s no laziness involved.
-
class
pyBabyMaker.dag_resolver.Node(name: str, scope: Optional[str] = None, type: Optional[str] = None, expr: Optional[str] = None, literal: Optional[str] = None, parent: Optional[pyBabyMaker.dag_resolver.Node] = None, children: List[pyBabyMaker.dag_resolver.Node] = <factory>, input: bool = False, output: bool = True)¶ Store a node in a DAG.
-
__eq__(other)¶ Return self==value.
-
__repr__()¶ Return repr(self).
-
fake¶ Return a boolean indicating if this Node represents a fake variable.
A fake variable means that this is used to hold some expression to be resolved, e.g. a boolean expression in an if statement, but the expression doesn’t need to be defined.
-
fname¶ Return the fullname of the variable, including a scope prefix.
-
rval¶ Substitute variables in resolved rvalue with the resolved variable names.
Suppose
a -> calc_a, andb -> rename_b, then a rvalue ofa+b -> calc_a+rename_b.
-
-
class
pyBabyMaker.dag_resolver.Variable(name: str, type: Optional[str] = None, rvals: List[str] = <factory>, literal: Optional[str] = None, input: bool = False, output: bool = True)¶ Store a raw variable to be resolved. Note that by design we allow multiple possible rvalues.
This class is stateful only when used as an iterator.
-
__repr__()¶ Return repr(self).
-
terminal¶ Return a boolean indicating if the variable is terminal, which means that it is considered to be resolved directly
-
-
pyBabyMaker.dag_resolver.find_parent_fnames(var)¶ Find full names of parents, recursively.
These names will be forbidden in the subsequent resolution to make sure there’s no back branch in the constructed DAG.
-
pyBabyMaker.dag_resolver.fname_formatter(scope, name)¶ Full name formatter.
-
pyBabyMaker.dag_resolver.propagate_io_attr(var, node)¶ Make sure the ‘input’ and ‘output’ attrs are the same between var and node.
-
pyBabyMaker.dag_resolver.resolve_scope(scope, scopes, ordering, **kwargs)¶ Resolve all variables in a scope
-
pyBabyMaker.dag_resolver.resolve_var(var, scope, scopes, ordering, parent=None, resolved_vars=None, resolved_vars_mutable=None, skip_names=None, postprocess=<function propagate_io_attr>)¶ Resolve a single variable traversing on scopes with a given ordering.
This is the main function that is responsible for DAG node resolution. Read this with care!
-
pyBabyMaker.dag_resolver.resolve_vars_in_scope(vars, scope, scopes, ordering, resolved_vars=None, **kwargs)¶ Resolve specified variables in scopes.