Graph#
graph
module#
- class mmodel.graph.Graph(incoming_graph_data=None, **attr)[source]#
Bases:
DiGraph
Create model graphs.
mmodel.Graph inherits from networkx.DiGraph(), which has all DiGraph methods.
The class adds the “type” attribute to the graph attribute. The factory method returns a copy of the dictionary. It is equivalent to
{"type": "mmodel_graph"}.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. - The method adds callable signature ‘sig’ to the node attribute.- 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
- 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.