node_functions module
Full Documentation for hippynn.graphs.nodes.base.node_functions module.
Click here for a summary page.
Here we define some of the core operations for Nodes in the directed acyclic graph associated with a computation.
- exception NodeAmbiguityError[source]
Bases:
NodeOperationError
- exception NodeNotFound[source]
Bases:
NodeOperationError
- find_relatives(node_or_nodes, constraint_key, ancestors=True, descendants=True, why_desc='<purpose not specified>')[source]
- Parameters:
node_or_nodes – a node or iterable of nodes to start the search.
constraint_key –
callable to filter nodes by or
type spec to be used with isinstance.
ancestors – whether to search ancestors of the node set
descendants – whether to search descendants of the node set
why_desc – If a node cannot be found satisfying the constraint, raise an error with this message.
- Returns:
set of nodes related to this node that obey a constraint
- find_unique_relative(node_or_nodes, constraint, ancestor_fallback=True, why_desc='<purpose not specified>')[source]
Look for a unique parent or child node type in the graph connected to the starting node.
- Parameters:
node_or_nodes – a node or iterable of nodes to start the search.
constraint –
callable to filter nodes by or
type to be used with isinstance.
ancestor_fallback – This sets whether or not a unique relative in only the ancestors is acceptable. If set to true, and multiple nodes are found, the search will be run again with only the ancestors of the initial node set.
why_desc – specification of error message
- Returns:
Node compatible with constraint.
Note
If no node is found, a NodeNotFoundError is rasied. If more than one node is found, a NodeambiguityError is raised.
- get_connected_nodes(node_set, ancestors=True, descendants=True)[source]
Recursively return nodes connected to the specified node_set.
Nodes in the supplied set are included in the output.
- Parameters:
node_set – iterable collection of nodes (list, tuple, set,…)
ancestors – whether to search ancestors of the node set
descendants – whether to search descendants of the node set
- Returns:
set of nodes with some relationship to the input set.
- is_in_loss_graph(node_or_nodes, why_desc='<purpose not specified>')[source]
Decide if a node or collection of nodes is in the loss graph.
(If not, they are in the model graph) (If neither, raise NodeAmbiguityError)
Warning
If you call this function, it ought to be on a set of nodes assumed in the same graph. If not, be prepared for the case that the question was malformed (mixture) and so
NodeAmbiguityErroris raised.- Parameters:
node_or_nodes – a node or iterable of nodes to examine.
why_desc – optional specification of error message clarifying reason why this was requested.
- Returns:
boolean