Graph#
graph
module#
- class mmodel.graph.Graph(incoming_graph_data=None, **attr)[source]#
Bases:
DiGraph
,ReprMixin
Create model graphs.
mmodel.Graph inherits from networkx.DiGraph().
The class adds the “graph_module” and “node_type” attribute to the graph attribute. The factory method returns a copy of the dictionary. It is equivalent to
{"graph_module": "mmodel_graph", "node_type": Node}.copy()
when called.The additional graph operations are added: - add_grouped_edges and set_node_objects. - Method
add_grouped_edges
, cannot have both edges list. - Methodset_node_object
updates 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 group 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.
- deepcopy()[source]#
Deepcopy graph.
The
graph.copy
method is a shallow copy. Deepcopy creates a copy for the attributes dictionary. graph.copy<https://networkx.org/documentation/stable/reference/classes /generated/networkx.Graph.copy.html>_However, for subgraphs,
deepcopy
is incredibly inefficient because subgraph contains ‘_graph’, which stores the original graph. An alternative method is to copy the code from the copy method, but usedeepcopy
for 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.
- set_node_objects_from(node_objects: list)[source]#
Update the functions of existing nodes.
The method is the same as adding a node object.
- subgraph(nodes=None, inputs=None, outputs=None)[source]#
Extract subgraph by nodes, inputs, and output.
If multiple parameters are specified, the result is a union of the selection. 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.