Graph#
graph module#
- class mmodel.graph.Graph(incoming_graph_data=None, **attr)[source]#
Bases:
DiGraph,ReprMixinCreate model graphs.
mmodel.Graph inherits from networkx.DiGraph().
The class adds the “graph_module” and “node_type” attributes to the graph. The factory method returns a copy of the dictionary. It is equivalent to
{"graph_module": "mmodel", "node_type": Node}.copy()when called.The following additional graph operations are added:
add_grouped_edges and add_node_objects
Method
add_node_objectupdates nodes with the node callable “func” and output.
- add_edge(u_of_edge, v_of_edge, **attr)[source]#
Modify add_edge to update the edge attribute in the end.
- add_grouped_edge(u, v)[source]#
Add linked edge.
For mmodel, a grouped edge (u, v) allows u or v to be a list of nodes. A grouped edge represents one or several nodes flowing into one node.
- add_node_objects_from(node_objects: list)[source]#
Update the functions of existing nodes.
This method is equivalent to adding node objects individually.
- deepcopy()[source]#
Deepcopy graph.
The
graph.copymethod is a shallow copy. Deepcopy creates a copy of the attributes dictionary. graph.copy<https://networkx.org/documentation/stable/reference/classes /generated/networkx.Graph.copy.html>_However, for subgraphs,
deepcopyis incredibly inefficient because the subgraph contains ‘_graph’, which stores the original graph. An alternative method is to copy the code from the copy method, but usedeepcopyfor the items.The parser is redefined in the new graph.
- graph_attr_dict_factory()#
D.copy() -> a shallow copy of D
- property grouped_edges#
Return grouped edges based on the graph.
- subgraph(nodes=None, inputs=None, outputs=None)[source]#
Extract subgraph by nodes, inputs, and outputs.
If multiple parameters are specified, the result is a union of the selections. The subgraph is a deep copy of the original graph. The behavior is different from the parent class method, where the subgraph returns a view of the original graph.