gops module

Full Documentation for hippynn.graphs.gops module. Click here for a summary page.

Graph Operations (“gops”) that process or transform a set of nodes.

exception GraphInconsistency[source]

Bases: NodeOperationError

check_evaluation_order(evaluation_outputs_list, evaluation_inputs_list)[source]

Validate an evaluation order.

Parameters:
  • evaluation_outputs_list

  • evaluation_inputs_list

Returns:

Make sure that back-links in the graph are correct. Raises GraphInconsistency if the graph is not consistent. All connected nodes to the node set are analyzed. The links are consistent if each pair of child->parent has a corresponding link parent<-child.

Parameters:

node_set – iterable of nodes to check

Raises:

GraphInconsistency – if the graph is not consistent.

Returns:

True

compute_evaluation_order(all_nodes)[source]

Computes the evaluation order for forward computation.

Parameters:

all_nodes – The nodes to compute

Returns:

outputs_list, inputs_list Outputs list is the node to evaluate next, which is fed the inputs in the corresponding entry of inputs_list

copy_subgraph(required_nodes, assume_inputed, tag=None)[source]

Copy a subgraph for the required nodes. Doesn’t copy the modules. Returns copies of the specified nodes, linked implicitly to copies of their parents.

If assume_inputted is not empty, this will result in partially disconnected nodes. As such, we recommend running check_link_consistency after you have finished your graph-level operations.

Parameters:
  • required_nodes – output nodes of the computation

  • assume_inputed – nodes whose parents we will not include in the copy (these will be left dangling)

  • tag – a string to preprend to the resulting node’s names.

Returns:

new_required, new_subgraph new_required: a list containing the new copies of required_nodes in the new subgraph.

new_subgraph: a list containing new copies of all nodes in the subgraph.

get_subgraph(required_nodes)[source]

Get the subgraph associated with some target (required) nodes.

Parameters:

required_nodes – the nodes to compute

Returns:

a list of nodes involved in the computation of the required nodes.

merge_children(start_nodes)[source]

Merge the children of some seed nodes if those children are identical.

This function changes a graph in-place.

Parameters:

start_nodes

Returns:

child_nodes: the merged children, post merge

merge_children_recursive(start_nodes)[source]

Merge children of some seed nodes if they are identical computations, and apply to future children until no more merges can be performed.

This function changes a graph in-place.

Parameters:

start_nodes

Returns:

Merged nodes.

replace_node(old_node, new_node, disconnect_old=False)[source]
Parameters:
  • old_node – Node to replace

  • new_node – Node to insert

  • disconnect_old – If True, remove the old node connections from the graph.

Replaces the children of old node with new node. Effectively, this just means going to the children and swapping out their parents to point to the new node. Ignores the children of old node that are parents of the new node in order to prevent cycles in the graph.

If disconnect_old, remove references to the old node – it will become unusable.

Warning

This function changes the graph structure in-place. As such, if this function raises an error, it may result in a corrupted graph state.

Warning

This function will try to coerce index states where possible. If the index types of the nodes are not listed, the index state will not be modified. If they are incompatible, this means that the graph will not function correctly.

Returns:

None

replace_node_with_constant(node, value, name=None)[source]
search_by_name(nodes, name_or_dbname)[source]

Look for a unique related node with a given db_name or name. The db_name will be given higher precedence.

Parameters:
  • nodes – starting point for search

  • name_or_dbname – name or dbname for node search

Returns:

node that matches criterion

Raises NodeAmbiguityError if more than one node found Raises NodeNotFoundError if no nodes found