graph_algorithms
pytorch_symbolic.graph_algorithms
check_for_missing_inputs
check_for_missing_inputs(used_nodes: Set[SymbolicData], inputs: Tuple[SymbolicData, ...] | List[SymbolicData])
Check if there exist nodes which require input from outside of the graph.
It is forbidden, as it doesn't make sense.
Example of such violation::
x1 = Input(shape=(32,))
x2 = Input(shape=(32,))
x3 = x1 + x2
model = SymbolicModel(inputs=x1, outputs=x3)
Model cannot execute defined operations unless x2
is given, because x3
requires it.
figure_out_nodes_between
figure_out_nodes_between(inputs: Tuple[SymbolicData, ...] | List[SymbolicData] | None = None, outputs: Tuple[SymbolicData, ...] | List[SymbolicData] | None = None) -> Set[SymbolicData]
Returns intersection of predecessors tree of outputs and succesors tree of inputs.
draw_graph
draw_graph(*, model: SymbolicModel | None = None, inputs: Iterable[SymbolicData] | SymbolicData | None = None, outputs: Iterable[SymbolicData] | SymbolicData | None = None, node_text_func: Callable[[SymbolicData], str] | None = None, edge_text_func: Callable[[nn.Module], str] | None = None, node_text_namespace: Dict[str, Any] | None = None, rotate_graph: bool = False, rotate_labels: bool = False, show: bool = False, figsize = None)
Plot graph of the computations, nodes being placeholder variables and nn.Modules being edges.
This is not suitable for large graphs or large neural networks. This is a simple tool that was designed to demonstrate that Pytorch Symbolic creates sensible graphs that are nice to visualize.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
SymbolicModel | None
|
A SymbolicModel to be plotted. This or |
None
|
inputs |
Iterable[SymbolicData] | SymbolicData | None
|
Input in the graph of Symbolic computations. This or |
None
|
outputs |
Iterable[SymbolicData] | SymbolicData | None
|
Output in the graph of Symbolic computations. This or |
None
|
node_text_func |
Callable[[SymbolicData], str] | None
|
A function that returns text that will be written on Nodes. |
None
|
edge_text_func |
Callable[[nn.Module], str] | None
|
A function that returns text that will be written on Edges. |
None
|
node_text_namespace |
Dict[str, Any] | None
|
If used with |
None
|
rotate_labels |
bool
|
If True, text on edges will be rotated in the direction of the arrow. |
False
|
rotate_graph |
bool
|
If True, the consecutive layers will be shown to the right, instead of downwards. |
False
|
show |
bool
|
Call matplotlib.pyplot.show |
False
|
sort_graph_and_check_DAG
Sort graph topologically.
Wikipedia: In graph theory, a topological sort or topological ordering of a directed acyclic graph (DAG) is a linear ordering of its nodes in which each node comes before all nodes to which it has outbound edges. Every DAG has one or more topological sorts.