Skip to content
Snippets Groups Projects

Add show_graphview funcionality.

Merged Iryna de Albuquerque Silva requested to merge idealbuq/aidge_core:dev into dev
All threads resolved!
1 file
+ 17
17
Compare changes
  • Side-by-side
  • Inline
+ 17
17
@@ -4,18 +4,18 @@ import builtins
@@ -4,18 +4,18 @@ import builtins
import aidge_core
import aidge_core
import numpy as np
import numpy as np
def dfs(graph, node, visited_nodes, sorted_nodes) -> None:
def dfs(graph : aidge_core.GraphView, node : aidge_core.Node, visited_nodes : list[aidge_core.Node], sorted_nodes : list[aidge_core.Node]) -> None:
"""
"""
Performs the depth-first search algorithm for topological sorting.
Performs the depth-first search algorithm for topological sorting.
:param graph: An unsorted GraphView of Aidge
:param graph: An unsorted GraphView of Aidge.
:type graph: aidge_core.GraphView
:type graph: aidge_core.GraphView
:param node: The GraphView's Node that is being treated
:param node: The GraphView's Node that is being treated.
:type node: aidge_core.Node
:type node: aidge_core.Node
:param visited_nodes: List of nodes that have already been visited.
:param visited_nodes: List of nodes that have already been visited.
:type visited_nodes: list
:type visited_nodes: list[aidge_core.Node]
:param sorted_nodes: List of nodes that have already been sorted.
:param sorted_nodes: List of nodes that have already been sorted.
:type sorted_nodes: list
:type sorted_nodes: list[aidge_core.Node]
"""
"""
node_children = node.get_children()
node_children = node.get_children()
@@ -44,14 +44,14 @@ def dfs(graph, node, visited_nodes, sorted_nodes) -> None:
@@ -44,14 +44,14 @@ def dfs(graph, node, visited_nodes, sorted_nodes) -> None:
return None
return None
def topological_sort(graph : aidge_core.GraphView) -> list:
def topological_sort(graph : aidge_core.GraphView) -> list[aidge_core.Node]:
"""
"""
Performs topological sorting by applying depth-first search algorithm recursively.
Performs topological sorting by applying depth-first search algorithm recursively.
:param graph: An unsorted GraphView of Aidge
:param graph: An unsorted GraphView of Aidge.
:type graph: aidge_core.GraphView
:type graph: aidge_core.GraphView
:return: A list with the GraphView's sorted nodes.
:return: A list with the GraphView's sorted nodes.
:rtype: list
:rtype: list[aidge_core.Node]
"""
"""
input_nodes = graph.get_input_nodes()
input_nodes = graph.get_input_nodes()
@@ -66,14 +66,14 @@ def topological_sort(graph : aidge_core.GraphView) -> list:
@@ -66,14 +66,14 @@ def topological_sort(graph : aidge_core.GraphView) -> list:
return sorted_nodes
return sorted_nodes
def retrieve_operator_attrs(node : aidge_core.Node) -> dict:
def retrieve_operator_attrs(node : aidge_core.Node) -> dict[str, int, float, bool, None]:
"""
"""
Returns the dictionary containing the attributes of a given Node.
Returns the dictionary containing the attributes of a given Node.
:param graph: A Node in the list of sorted nodes.
:param graph: A Node in the list of sorted nodes.
:type graph: aidge_core.Node
:type graph: aidge_core.Node
:return: A dictionary with the Node's attributes.
:return: A dictionary with the Node's attributes.
:rtype: dict
:rtype: dict[str, int, float, bool, None]
"""
"""
if node.get_operator().attr is not None:
if node.get_operator().attr is not None:
node_attr_dict = node.get_operator().attr.dict()
node_attr_dict = node.get_operator().attr.dict()
@@ -86,7 +86,7 @@ def retrieve_operator_attrs(node : aidge_core.Node) -> dict:
@@ -86,7 +86,7 @@ def retrieve_operator_attrs(node : aidge_core.Node) -> dict:
return node_attr_dict
return node_attr_dict
def create_dict(sorted_nodes : list, write_trainable_params_ext : bool, write_trainable_params_embed : bool, params_file_format : str, path_trainable_params : str) -> dict:
def create_dict(sorted_nodes : list[aidge_core.Node], write_trainable_params_ext : bool, write_trainable_params_embed : bool, params_file_format : str, path_trainable_params : str) -> dict[str, int, float, bool, None]:
"""
"""
Creates a dictionary to store the information of a given sorted GraphView.
Creates a dictionary to store the information of a given sorted GraphView.
@@ -102,7 +102,7 @@ def create_dict(sorted_nodes : list, write_trainable_params_ext : bool, write_tr
@@ -102,7 +102,7 @@ def create_dict(sorted_nodes : list, write_trainable_params_ext : bool, write_tr
:type path_trainable_params: str
:type path_trainable_params: str
:return: A dictionary with the GraphView description.
:return: A dictionary with the GraphView description.
:rtype: dict
:rtype: dict[str, int, float, bool, None]
"""
"""
graphview_dict = {'graph': []}
graphview_dict = {'graph': []}
@@ -215,14 +215,14 @@ def create_dict(sorted_nodes : list, write_trainable_params_ext : bool, write_tr
@@ -215,14 +215,14 @@ def create_dict(sorted_nodes : list, write_trainable_params_ext : bool, write_tr
return graphview_dict
return graphview_dict
def write_dict_json(graphview_dict : dict, json_path : str) -> None:
def write_dict_json(graphview_dict : dict[str, int, float, bool, None], json_path : str) -> None:
"""
"""
Writes dictionary containing GraphView description to a JSON file.
Writes dictionary containing GraphView description to a JSON file.
:param graphview_dict: A dictionary with the GraphView description.
:param graphview_dict: A dictionary with the GraphView description.
:type graphview_dict: dict
:type graphview_dict: dict[str, int, float, bool, None]
:param json_path: Path to write JSON file.
:param json_path: Path to write JSON file.
:type json_path: str.
:type json_path: str
"""
"""
with open(json_path, 'w') as fp:
with open(json_path, 'w') as fp:
@@ -234,10 +234,10 @@ def gview_to_json(gview : aidge_core.GraphView, json_path : str, write_trainable
@@ -234,10 +234,10 @@ def gview_to_json(gview : aidge_core.GraphView, json_path : str, write_trainable
"""
"""
Generates the description for a GraphView in the JSON format.
Generates the description for a GraphView in the JSON format.
:param graph: A GraphView of Aidge
:param graph: A GraphView of Aidge.
:type graph: aidge_core.GraphView
:type graph: aidge_core.GraphView
:param json_path: Path to write JSON file.
:param json_path: Path to write JSON file.
:type json_path: str.
:type json_path: str
:param write_trainable_params_ext: Whether or not to write the eventual trainable parameters of the Nodes in an external file.
:param write_trainable_params_ext: Whether or not to write the eventual trainable parameters of the Nodes in an external file.
:type write_trainable_params_ext: bool
:type write_trainable_params_ext: bool
:param write_trainable_params_embed: Whether or not to write the eventual trainable parameters of the Nodes in the same file as the dict (embed).
:param write_trainable_params_embed: Whether or not to write the eventual trainable parameters of the Nodes in the same file as the dict (embed).
Loading