Graph#
Node#
The Node class is used to form a node in a graph. In Aidge, there is no “edge” object per se, as the references to parent and child nodes are contained in the node. There is no graph container in Aidge: connected nodes intrinsically form a graph.
- class aidge_core.Node#
- __init__(self: aidge_core.aidge_core.Node, op: aidge_core.aidge_core.Operator, name: str = '') None #
- add_child(*args, **kwargs)#
Overloaded function.
add_child(self: aidge_core.aidge_core.Node, other_node: aidge_core.aidge_core.Node, out_id: int = 0, other_in_id: int = 65535) -> None
Link another Node to an output of the current Node.
- param other_node:
Pointer to the other Node that will be given as a child to the current Node
- type other_node:
- param out_id:
ID of the output of the current Node to connect to the other Node. (If Node has 1 output max ID is 0). Default to 0.
- type out_id:
int
- param other_in_id:
ID of the input of the other Node to connect to the current Node (If the node is a Mul op it has 2 input then Max ID is 1).Default to the first available data input.
- type other_in_id:
int
add_child(self: aidge_core.aidge_core.Node, other_graph: Aidge::GraphView, out_id: int = 0, other_in_id: object = None) -> None
Link a Node from a specific
aidge_core.GraphView
to the current Node.- param other_view:
Pointer to the
aidge_core.GraphView
whose content should be linked to the current Node.- type other_view:
- param out_id:
ID of the current Node output to connect to the other Node. Default to 0.
- type out_id:
int
- param other_in_id:
Pair of Node and input connection ID for specifying the connection. If the
aidge_core.GraphView
whose content is linked has only one input Node, then it defaults to the first available data input ID of this Node.- type other_in_id:
tuple[:py:class: Node, int]
- attributes(self: aidge_core.aidge_core.Node) aidge_core.aidge_core.DynamicAttributes #
- Returns:
The attributes of the Node
- Return type:
aidge_core.DynamicAttributes
- clone(self: aidge_core.aidge_core.Node) aidge_core.aidge_core.Node #
Clone the Node and its
aidge_core.Operator
. The new Node has no connection.- Returns:
The new cloned Node
- Return type:
- create_unique_name(self: aidge_core.aidge_core.Node, base_name: str) str #
Given a base name, generate a new name which is unique in all the
aidge_core.GraphView
containing this node.If the provided base_name is not yet used, it will be used as is else, the returned name will be “name_X” name being the value provided by the base_name argument and X the smaller integer allowing name uniqueness.
- Parameters:
base_name (str) – proposed name for the node.
- Returns:
A name that is not used in any of the Node’s
aidge_core.GraphView
- Return type:
str
- get_children(self: aidge_core.aidge_core.Node) set[aidge_core.aidge_core.Node] #
Get the set of children Nodes linked to the current Node. The returned set does not include unconnected outputs. Node that are several times child of this one (several of its input come from this Node) appear only once
- Returns:
The set of children of the Node
- Return type:
Set{Node}
- get_nb_inputs(self: aidge_core.aidge_core.Node) int #
Gives the number of inputs of the Node.
- Returns:
The number of inputs of the Node
- Return type:
int
- get_nb_outputs(self: aidge_core.aidge_core.Node) int #
Gives the number of outputs of the Node.
- Returns:
the number our outputs of the Node
- Return type:
int
- get_operator(self: aidge_core.aidge_core.Node) aidge_core.aidge_core.Operator #
Get the
aidge_core.Operator
held by the Node.- Returns:
The Node’s
aidge_core.Operator
- Return type:
- get_ordered_children(self: aidge_core.aidge_core.Node) list[list[aidge_core.aidge_core.Node]] #
Get all children of the node The parent vector size matches the number of outputs of the node. Each sub-vector size will match the number of children connected to the n-th output (i.e. if 3 nodes are connected to the 3rd output parent_vec[2].size() == 3).
:return:The list (main list,size=number of outputs) of lists (one per output of the Node) of children :rtype: List[List[Node]]
- get_parent(self: aidge_core.aidge_core.Node, in_id: int) aidge_core.aidge_core.Node #
Get the pointer to parent of the specified input index. This pointer is nullptr if no parent is linked to that input.
- Returns:
The parent of the specified input
- Return type:
- get_parents(self: aidge_core.aidge_core.Node) list[aidge_core.aidge_core.Node] #
Get the list of parent Nodes. Each input can only be linked to one Node. If an input has no linked node, the associated parent is None
- Returns:
The list of parent Nodes
- Return type:
List[Node]
- input(self: aidge_core.aidge_core.Node, in_id: int) tuple[aidge_core.aidge_core.Node, int] #
Get the parent Node and the associated output index connected to the specified input of the current Node.
- Parameters:
in_id (int) – input index of the current Node object.
- Returns:
The parent Node and the corresponding output index of the specified input of the current Node. When an input is not linked to any parent, the default value is (None, 65535)
- Return type:
tuple[Node, int]
- input_category(self: aidge_core.aidge_core.Node, idx: int) aidge_core.aidge_core.InputCategory #
Category of a specific input (Data or Param, optional or not). Data inputs exclude inputs expecting parameters (weights or bias).
- Returns:
The inputCategory of the idx-th input of the Node
- Return type:
InputCategory
- input_name(*args, **kwargs)#
Overloaded function.
input_name(self: aidge_core.aidge_core.Node, in_id: int) -> str
Get the name of the in_id-th input of the Node.
Here is the logic used to get the input name:
If the node has a parent, use parent.output_name()
If the input is Optional, return “” to be ONNX compliant
If the node as a defined input name for the inquired input use it
Create a name with the pattern: {self.name()}_in{in_id}
Warning
No exception is thrown if parent.output_name is different than node.input_name, instead a warning is logged
- param in_id:
input index.
- type in_id:
int
- return:
i-th connection name.
- rtype:
str
input_name(self: aidge_core.aidge_core.Node, in_id: int, newName: str) -> str
Update the name of the in_id-th input of the Node.
- param in_id:
input index.
- type in_id:
int
- param newName:
input index of the current Node object.
- type newName:
str
- return:
i-th connection new name.
- rtype:
str
- inputs(self: aidge_core.aidge_core.Node) list[tuple[aidge_core.aidge_core.Node, int]] #
Get ordered list of parent Node and the associated output index connected to the current Node’s inputs.
- Returns:
List of connections. When an input is not linked to any parent, the default value is (None, default_index)
- Return type:
list[tuple[:py:class: Node, int]]
- inputs_names(self: aidge_core.aidge_core.Node) list[str] #
Get ordered list of the current Node’s inputs name. Names can be changed
- Returns:
List of connections names.
- Return type:
list[str]
- name(self: aidge_core.aidge_core.Node) str #
Return the name of the Node.
Warning
name is not mandatory for Nodes and may be empty.
- Returns:
The name of the Node
- Return type:
string
- output(self: aidge_core.aidge_core.Node, out_id: int) list[tuple[aidge_core.aidge_core.Node, int]] #
Get a list of the children Node for a specific output and the associated input index connected to it.
- Parameters:
out_id (int) – input index of the current Node object.
- Returns:
List of Nodes and their inputs that are connected to the specified output. When an input is not linked to any parent, the default value is (None, default_index)
- Return type:
list[tuple[Node, int]]
- output_name(*args, **kwargs)#
Overloaded function.
output_name(self: aidge_core.aidge_core.Node, out_id: int) -> str
Get the name of an output connection of the Node object.
- param out_id:
input index of the current Node object.
- type out_id:
int
- return:
i-th connection name.
- rtype:
str
output_name(self: aidge_core.aidge_core.Node, out_id: int, newName: str) -> str
Update the output name of the Node object.
- param out_id:
input index of the current Node object.
- type out_id:
int
- param newName:
new output name
- type newName:
str
- return:
i-th connection new output name
- rtype:
str
- outputs(self: aidge_core.aidge_core.Node) list[list[tuple[aidge_core.aidge_core.Node, int]]] #
Get, for each output of the Node, a list of the children Node and the associated input index connected to it. The parent list size matches the number of outputs of the node. Each sub-list size will match the number of children connected to the n-th output (i.e. if 3 nodes are connected to the 3rd output parent_list[2].size() == 3).
- Returns:
List of a list of connections. When an output is not linked to any child, its list a empty.
- Return type:
list[list[tuple[Node, int]]]
- outputs_names(self: aidge_core.aidge_core.Node) list[str] #
Get a list of the children Node for the name of its outputs.
- Returns:
i-th connection list name.
- Return type:
list[str]
- set_name(self: aidge_core.aidge_core.Node, name: str) None #
Set the Node name.
Warning
Undefined behavior if an other Node possess teh same name inside the same
aidge_core.GraphView
, name uniqueness is not guaranteed by design (names being optional). To ensure generating a unique name, refer toaidge_core.Node.create_unique_name()
.- Parameters:
name (str) – New name for the node.
- type(self: aidge_core.aidge_core.Node) str #
- Returns:
the type of the Node’s
aidge_core.Operator
- Return type:
string
-
class Node : public std::enable_shared_from_this<Node>#
Object carrying the topological information of the computational graph. A Node contains :
mAttrs : the attributes of the Node. If one of them is a name, it should be unique among all other Node name
mViews: a set of pointers to GraphView instances including this Node instance
mOperator: a pointer to the Operator associated to the node
mParents: a vector of parent nodes, which are its inputs
mIdOutParents: a vector of indexes, corresponding to the connected output index of the parent nodes.
mChildren: a vector of vector of children nodes, which lists, for each output of the Node, all its children.
mIdInChildren: a vector of vector of indexes, providing for each children nodes, the input index this node is connected to. The node can be connected to different input of the same child.
mForward: queue of forward propagation function
mBackward: queue of backward propagation function
Public Functions
-
Node() = delete#
-
virtual ~Node()#
-
inline void addBeforeForward(std::function<bool()> func)#
Add a lambda function that will be called before the operator’s Forward.
- Parameters:
std::function<bool()> – func: The function to add
-
inline void addAfterForward(std::function<bool()> func)#
Add a lambda function that will be called after the operator’s Forward.
- Parameters:
std::function<bool()> – func: The function to add
-
inline void addBeforeBackward(std::function<bool()> func)#
Add a lambda function that will be called before the operator’s Backward.
- Parameters:
std::function<bool()> – func: The function to add
-
inline void addAfterBackward(std::function<bool()> func)#
Add a lambda function that will be called after the operator’s Backward.
- Parameters:
std::function<bool()> – func: The function to add
-
Connector operator()(const std::vector<Connector> &ctors)#
Method to enable the functional declaration of a graph using an ordered set of Connectors. With this method, the node will register itself to the connector and return a new connector that contains the list of nodes that have been called.
Warning
length of ctors must be lower than the number of inputs of the Node
- Parameters:
std::vector<Connector> – ctors: Ordered Aidge::Connector linking their associated Node to the input of the current Node with the same index.
- Returns:
-
inline std::shared_ptr<DynamicAttributes> attributes() const#
Returns the attributes of the Node.
- Returns:
std::shared_ptr<DynamicAttributes>: The DynamicAttributes of the Node.
-
inline std::string name() const noexcept#
Returns the name of the Node.
Warning
name is not mandatory and may be empty.
- Returns:
std::string: The Name of the Node
-
void setName(const std::string &name)#
Set the Node’s Name.
Warning
Undefined behaviour when several Nodes have the same name, use Node::createUniqueName to avoid complications.
- Parameters:
std::string – name: New name for the node.
-
std::string createUniqueName(std::string name)#
Given the parameter name generate a new name which is unique in all the GraphView which contains this Node.
if the provided name is not yet used, it will be used as is else, the returned name will be “name_X” name being the value provided by the name argument and X the smaller integer allowing name uniqueness.
- Parameters:
std::string – name: Base name to make unique.
- Returns:
std::string A name not used in any of the GraphView which contains this node.
-
inline std::string type() const#
Type of the Node’s operator.
- Returns:
std::string the type of the Node’s operator
-
bool valid() const#
Whether or not every input of the Node are linked to a Parent.
- Returns:
bool: True if every input of the Node are linked to a Parent, false otherwise.
-
std::vector<std::pair<NodePtr, IOIndex_t>> dataInputs() const#
Returns the input parents of the Node.
When an input is not linked to any Parent, the pair is <nullptr, gk_IODefaultIndex>. Data inputs exclude inputs expecting parameters (weights or bias).
- Returns:
std::vector<std::pair<std::shared_ptr<Node>, IOIndex_t>> : List of the pairs <Parent, output ID of the Parent> of the Node’s inputs.
-
std::vector<std::pair<NodePtr, IOIndex_t>> inputs() const#
Returns the inputs of the Node.
When an input is not linked to any Parent, the pair is <nullptr, gk_IODefaultIndex>. As opposed to dataInputs(), inputs() includes parent nodes containing parameters (e.g. weights or biases)
- Returns:
std::vector<std::pair<std::shared_ptr<Node>, IOIndex_t>> : List of the pairs <Parent, output ID of the Parent> of the Node’s inputs.
-
std::vector<std::string> inputsNames() const#
Return a vector of the name of the inputs of the Node The vector has the same order of the Node inputs.
- Returns:
std::vector<std::string>
-
std::pair<std::shared_ptr<Node>, IOIndex_t> input(const IOIndex_t inID) const#
Accessor of <parent_node, parent_node_output> linked to the inID-th input input of this node. If the input is not linked to any Parent, the pair is <nullptr, gk_IODefaultIndex>.
- Parameters:
IOIndex_t – inID : the ID of the input we want to know the parent of
- Returns:
std::pair<std::shared_ptr<Node>, IOIndex_t>: The pair <Parent, output ID of the Parent> of the Node’s inID-th input.
-
std::string inputName(const IOIndex_t inID) const#
Return the name of the inId-th input of the Node. Here is the logic used to get the input name:
If the node has a parent, use parent.outputName()
If the input is Optional, return “” to be ONNX compliant
If the node as a mInputName for the inquired input use it
Create a name with the pattern: {this->name()}_in{inID}
Warning
No exception is thrown if parent.outputName is different than node.inputName, instead a warning is logged
- Parameters:
inID –
- Returns:
std::string
-
std::string inputName(const IOIndex_t inID, const std::string &newName)#
Update the name of the inId-th input of the Node.
- Parameters:
inID –
newName –
- Returns:
std::string the updated name
-
inline IOIndex_t getFirstFreeDataInput() const#
Get the lowest index in the InputData Parent list equal to the nullptr (i.e. the ID of the first free data input). Data inputs exclude inputs expecting parameters (weights or bias). if there is no free input, will return gk_IODefaultIndex (max of uint16)
- Returns:
IOIndex_t: the index of the first free (parentless) data input.
-
IOIndex_t getNbFreeDataInputs() const#
Returns the number of free data inputs of the Node (i.e. data inputs that are not linked to an other node)
Note
Node cannot run until all of its mandatory inputs are filled
- Returns:
IOIndex_t: the number of free (parentless) data inputs
-
std::vector<std::vector<std::pair<NodePtr, IOIndex_t>>> outputs() const#
Returns the outputs of the Node.
The parent vector size matches the number of outputs of the node. Each sub-vector size will match the number of children connected to the n-th output (i.e. if 3 nodes are connected to the 3rd output parent_vec[3].size() == 3).
-
std::vector<std::string> outputsNames() const#
Return a vector of the name of the output of the Node The vector has the same order of the Node outputs.
- Returns:
std::vector<std::string>
-
std::vector<std::pair<NodePtr, IOIndex_t>> output(IOIndex_t outId) const#
Lists Nodes and input ids of children linked to specified output of the Node.
-
std::string outputName(IOIndex_t outId) const#
Return the name of the outId-th output of the Node.
- Parameters:
outId –
- Returns:
std::string
-
std::string outputName(IOIndex_t outId, const std::string &newName)#
Update the name of the outId-th output of the Node.
- Parameters:
outId –
newName –
- Returns:
std::string
-
inline IOIndex_t nbInputs() const noexcept#
Number of inputs, including both data and learnable parameters.
ex: [data, data, weight, bias] => 4
-
inline InputCategory inputCategory(IOIndex_t idx) const#
Returns the category of a specific input (Data or Param, optional or not). Data inputs exclude inputs expecting parameters (weights or bias).
ex: with [datatype1, datatype2, weight, bias], inputCategory(1) returns datatype2
- Parameters:
IOIndex_t – idx: The index of the input for which we determine the category.
- Returns:
InputCategory: the category of the specified input
-
inline bool parentIsBackEdge(IOIndex_t idx) const#
Returns whether the given node parent index is a back edge A back edge is an edge from a Node to one of its ancestor.
- Parameters:
IOIndex_t – idx!: Index of the Node’s connection we want to test
- Returns:
bool: True if the operator defines it as a back edge, False otherwise
-
IOIndex_t nbValidInputs() const#
Number of inputs linked to a Parent’s output.
Warning
Unconnected Inputs will throw errors when compiling graph.
- Returns:
IOIndex_t: The number of inputs that have a parent.
-
IOIndex_t nbValidOutputs() const#
Number of outputs linked to a Child’s input.
each output ID are counted once. So if two Nodes are connected to the 0-th output they will count as one valid output.
- Returns:
IOIndex_t: The number of outputs that have at least a child.
Add a GraphView pointer to the list of GraphView containing the current Node.
- Parameters:
std::shared_ptr<GraphView> – graphPtr Weak pointer to GraphView to add to the list.
Remove the reference of this Node to the GraphView passed as argument.
Warning
This function does not remove the reference of the GraphView to the Node. As such, this function is used in other function and should be not used as is by an user
- Parameters:
std::shared_ptr<GraphView> – graphPtr: Pointer to GraphView to remove from the list.
-
void addChild(const NodePtr &otherNode, const IOIndex_t outId = IOIndex_t(0), IOIndex_t otherInId = gk_IODefaultIndex)#
Link an other Node to an output of the current Node.
Note
otherNode shared_ptr is passed by reference in order to be able to detect possible dangling connection situations in debug using ref counting.
Link an input Node from a specific GraphView to the current Node.
- Parameters:
std::shared_ptr<GraphView> – otherView: Pointer to the GraphView whose content should be linked to the current Node.
IOIndex_t – outId: ID of the output Tensor to connect to the other Node. Default to 0.
std::pair<NodePtr, IOIndex_t> – otherInId: Pair of pointer to Node and Tensor ID for specifying the connection. Default pair is (nullptr, gk_IODefaultIndex), leading to an exception.
-
std::vector<NodePtr> getParents() const#
Return the list of parent Nodes. Each input can only be linked to one Node. If an input has no linked node, the associated parent is nullptr.
- Returns:
std::vector<std::shared_ptr<Node>> The vector of parent Nodes
-
inline NodePtr &getParent(const IOIndex_t inId)#
Get the pointer to parent of the specified input index. This pointer is nullptr if no parent is linked.
- Parameters:
IOIndex_t – inId: Input index.
- Returns:
std::shared_ptr<Node>& the pointer to the parent of the specified input
-
std::set<NodePtr> getChildren() const#
Get the set of pointers to children Nodes linked to the current Node.
The returned set does not include any nullptr as an output. Node that are several times child of this one (several of its input come from this Node) appear only once
- Returns:
std::set<std::shared_ptr<Node>>> the set of children of the Node
-
std::vector<std::vector<NodePtr>> getOrderedChildren() const#
Get all children of the node.
The parent vector size matches the number of outputs of the node. Each sub-vector size will match the number of children connected to the n-th output (i.e. if 3 nodes are connected to the 3rd output parent_vec[2].size() == 3).
- Returns:
std::vector<std::vector<std::shared_ptr<Node>>> The vector (main vector,size=number of outputs) of vectors (one per output of the Node) of children
-
std::vector<NodePtr> getChildren(const IOIndex_t outId) const#
Get the list of children Nodes linked to the output at specified index.
- Parameters:
IOIndex_t – outId: Output index.
- Returns:
std::vector<std::shared_ptr<Node>> Vector of children of the outId-th output
-
bool removeChild(const NodePtr nodePtr, const IOIndex_t outId = 0)#
Remove registered child from children list of specified output if possible. If so, also remove current Node from child’s parent.
- Parameters:
NodePtr – nodePtr: to remove.
IOIndex_t – outId: Output index. Default 0.
- Returns:
bool True if Child found and removed for given output index, false otherwise
-
void resetConnections(bool includeLearnableParam = false)#
Remove every link between this Node and its parents and children.
- Parameters:
bool – includeLearnableParam: If False, connections with data and OptionalData are kept, if true, they are removed as well
Clone the current Node. The Operator attribute of the new Node is not copied but shared with the current Node. The new node has no connection.
- Returns:
NodePtr Pointer to the cloned Node
GraphView#
As the name suggests, a GraphView is not a graph container, but merely a “view” of some nodes in a graph. There can be multiple overlapping views of nodes in a graph. Nodes in a view do not have to form a single connected graph.
A GraphView is however more than just a set of nodes. It has the following features:
It keeps track of all its inputs and outputs (if the parent of a node is not in the GraphView, the node is an input node for the GraphView). Furthermore, the GraphView inputs/outputs are ordered, and the order is stable during insertion or deletion of nodes in the GraphView;
There is a root node in the GraphView (by default, the first node added to it), and nodes inside a GraphView can be ranked with a unique and deterministic order if the nodes form a single connected graph;
Some methods can be applied globally to the GraphView, like
setBackend()
.
- class aidge_core.GraphView#
- __init__(self: aidge_core.aidge_core.GraphView) None #
- add(*args, **kwargs)#
Overloaded function.
add(self: aidge_core.aidge_core.GraphView, other_node: aidge_core.aidge_core.Node, include_learnable_parameters: bool = True) -> None
Include a Node to the current GraphView object.
- param other_node:
Node to add
- type other_node:
Node
- param include_learnable_parameters:
include non-data inputs, like weights and biases, default True.
- type include_learnable_parameters:
bool, optional
add(self: aidge_core.aidge_core.GraphView, other_graph: aidge_core.aidge_core.GraphView, include_learnable_parameters: bool = True) -> bool
Include a GraphView to the current GraphView object.
- param other_graph:
GraphView to add
- type other_graph:
GraphView
- param include_learnable_parameters:
include non-data inputs, like weights and biases, default True.
- type include_learnable_parameters:
bool, optional
- add_child(self: aidge_core.aidge_core.GraphView, to_other_node: aidge_core.aidge_core.Node, from_out_node: aidge_core.aidge_core.Node = None, from_tensor: int = 0, to_tensor: int = 65535) None #
Include a Node to the current GraphView object.
- Parameters:
to_other_node (Node) – Node to add
from_out_node (Node) – Node inside the GraphView the new Node will be linked to (it will become a parent of the new Node). If the GraphView only has one output Node, then default to this Node.
from_tensor (int) – Output Tensor ID of the already included Node. Default to 0.
to_tensor (int) – Input Tensor ID of the new Node. Default to gk_IODefaultIndex, meaning first available data input for the Node.
- add_ordered_outputs(self: aidge_core.aidge_core.GraphView, outputs: list[tuple[aidge_core.aidge_core.Node, int]], pos: int = -1) None #
- compile(self: aidge_core.aidge_core.GraphView, backend: str, datatype: aidge_core.aidge_core.dtype, device: int = 0, dims: list[list[int]] = []) None #
Sets the GraphView ready for computation in four steps: 1 - Assert input Tensors’ datatype is compatible with each Operator’s datatype. If not, a conversion Operator is inserted. 2 - Assert input Tensors’ backend is compatible with each Operator’s backend. If not, add a Transmitter Operator. 3 - Assert data format (NCHW, NHWC, …) of each Operator’s input Tensor is compatible with the selected kernel. If not, add a Transpose Operator. 4 - Propagate Tensor dimensions through the consecutive Operators (forward dims).
- Parameters:
backend (str) – backend on which the graph will run
datatype (Aidge.DataType) – datatype of the graph
device (int) – backend device index
dims (List[List[Int]]) – input dimension to forward
- forward_dims(self: aidge_core.aidge_core.GraphView, dims: list[list[int]] = [], allow_data_dependency: bool = False) bool #
Compute and propagate Tensor dimensions through the GraphView.
This function computes dimensions of input/output Tensors for each of the Node’s associated Operator in the GraphView by propagating dimensions from inputs through the entire network. It handles:
Dimension propagation in dependency order
Cyclic dependencies (specifically for Memorize_Op)
Input dimension validation and setting
Optional vs mandatory inputs
Note#
Dimensions will be propagated through every Node regardless of if dims were previously forwarded or not.
The algorithm works in several phases:
- Input Dimension Setup:
Validates/sets provided input dimensions
Checks compatibility with existing tensors
- Connection Verification:
Ensures all node connections are valid
Verifies mandatory inputs are present
- Dimension Propagation:
Propagates dimensions through the graph in topological order
Detects and handles circular dependencies induced by Memorize_Op
Parameters#
- dimsList[List[int]], optional
Vector of dimension vectors for graph inputs. Empty by default.
- allow_data_dependencybool, optional
Whether to allow data-dependent dimension computation, by default False
Returns#
- bool
True if dimension propagation succeeded, False otherwise.
Examples#
>>> graph = GraphView() >>> # ... build graph ... >>> >>> # Forward with default empty dimensions >>> success = graph.forward_dims() >>> >>> # Forward with specific input dimensions >>> input_dims = [ ... [1, 3, 224, 224], # First input ... [1, 64, 112, 112] # Second input ... ] >>> success = graph.forward_dims(input_dims)
- forward_dtype(*args, **kwargs)#
Overloaded function.
forward_dtype(self: aidge_core.aidge_core.GraphView, dtypes: list[aidge_core.aidge_core.dtype] = []) -> bool
forward_dtype(self: aidge_core.aidge_core.GraphView, dtype: aidge_core.aidge_core.dtype) -> bool
- get_input_nodes(self: aidge_core.aidge_core.GraphView, filter: aidge_core.aidge_core.InputCategory = <InputCategory.All: 4294967295>) set[aidge_core.aidge_core.Node] #
Get set of input Nodes.
- Return type:
list[Node]
- get_node(self: aidge_core.aidge_core.GraphView, node_name: str) aidge_core.aidge_core.Node #
- get_nodes(self: aidge_core.aidge_core.GraphView) set[aidge_core.aidge_core.Node] #
- get_ordered_inputs(self: aidge_core.aidge_core.GraphView) list[tuple[aidge_core.aidge_core.Node, int]] #
- get_ordered_nodes(self: aidge_core.aidge_core.GraphView, reversed: bool = False) list[aidge_core.aidge_core.Node] #
Get ordered nodes for the graph view
- get_ordered_outputs(self: aidge_core.aidge_core.GraphView) list[tuple[aidge_core.aidge_core.Node, int]] #
- get_output_nodes(self: aidge_core.aidge_core.GraphView) set[aidge_core.aidge_core.Node] #
Get set of output Nodes.
- Return type:
list[Node]
- get_ranked_nodes(self: aidge_core.aidge_core.GraphView) tuple[list[aidge_core.aidge_core.Node], int] #
- get_ranked_nodes_name(self: aidge_core.aidge_core.GraphView, format: str, mark_non_unicity: bool = True) dict[aidge_core.aidge_core.Node, str] #
- in_view(*args, **kwargs)#
Overloaded function.
in_view(self: aidge_core.aidge_core.GraphView, arg0: aidge_core.aidge_core.Node) -> bool
in_view(self: aidge_core.aidge_core.GraphView, arg0: str) -> bool
- inputs(self: aidge_core.aidge_core.GraphView) list[tuple[aidge_core.aidge_core.Node, int]] #
- insert_parent(self: aidge_core.aidge_core.GraphView, child_node: aidge_core.aidge_core.Node, new_parent_node: aidge_core.aidge_core.Node, child_input_tensor_idx: int, new_parent_input_tensor_idx: int, new_parent_output_tensor_idx: int) None #
- log_outputs(self: aidge_core.aidge_core.GraphView, path: str) None #
- outputs(self: aidge_core.aidge_core.GraphView) list[list[tuple[aidge_core.aidge_core.Node, int]]] #
- static replace(*args, **kwargs)#
Overloaded function.
replace(old_graph: aidge_core.aidge_core.GraphView, new_graph: aidge_core.aidge_core.GraphView) -> bool
Replace the old set of Nodes in a GraphView with the new set of given Nodes in a GraphView if possible in every GraphView.
- param old_graph:
GraphView of Nodes actually connected in GraphViews.
- type old_graph:
GraphView
- param new_graph:
GraphView of Nodes with inner connections already taken care of.
- type new_graph:
GraphView
- return:
Whether any replacement has been made.
- rtype:
bool
replace(old_nodes: set[aidge_core.aidge_core.Node], new_nodes: set[aidge_core.aidge_core.Node]) -> bool
Replace the old set of Nodes with the new set of given Nodes if possible in every GraphView.
- param old_nodes:
Nodes actually connected in GraphViews.
- type old_nodes:
Node
- param new_nodes:
Nodes with inner connections already taken care of.
- type new_nodes:
Node
- return:
Whether any replacement has been made.
- rtype:
bool
- root_node(self: aidge_core.aidge_core.GraphView) aidge_core.aidge_core.Node #
- save(self: aidge_core.aidge_core.GraphView, path: str, verbose: bool = False, show_producers: bool = True) None #
Save the GraphView as a Mermaid graph in a .md file at the specified location.
- Parameters:
path (str) – save location
- set_backend(self: aidge_core.aidge_core.GraphView, backend: str, device: int = 0) None #
- set_dataformat(self: aidge_core.aidge_core.GraphView, dataformat: aidge_core.aidge_core.dformat) None #
- set_datatype(self: aidge_core.aidge_core.GraphView, datatype: aidge_core.aidge_core.dtype) None #
- set_name(self: aidge_core.aidge_core.GraphView, name: str) None #
- set_ordered_inputs(self: aidge_core.aidge_core.GraphView, inputs: list[tuple[aidge_core.aidge_core.Node, int]]) None #
- set_ordered_outputs(self: aidge_core.aidge_core.GraphView, outputs: list[tuple[aidge_core.aidge_core.Node, int]]) None #
- set_root_node(self: aidge_core.aidge_core.GraphView, node: aidge_core.aidge_core.Node) None #
-
class GraphView : public std::enable_shared_from_this<GraphView>#
Groupement of Nodes forming a computational graph on which properties and functions can easily and safely be applied or run.
Public Functions
-
inline GraphView(const std::string &name = "")#
-
const NodePtr operator[](const std::string &nodeName) const#
-
inline std::string name() const noexcept#
Name of the node.
- Returns:
std::string
-
inline void setName(const std::string &name)#
Set the node name.
Warning
Undefined behavior when several Nodes have the same name.
- Parameters:
name – New name for the node.
-
void setNodesName() const#
Set the name of every Node based on the current GraphView name in following form: “name_type#type-id”.
-
void save(const std::string &path, bool verbose = false, bool showProducers = true) const#
Save the GraphView as a Mermaid graph in a .md file at the specified location.
- Parameters:
path –
-
void logOutputs(const std::string &dirName) const#
-
inline NodePtr rootNode() const noexcept#
-
void setRootNode(NodePtr node)#
-
std::set<NodePtr> inputNodes(InputCategory filter = InputCategory::All) const#
Get reference to the set of input Nodes.
-
std::set<NodePtr> outputNodes() const#
Get reference to the set of output Nodes.
-
bool isInputNode(const NodePtr &nodePtr) const#
Assess if the given Node is an input Node of the GraphView object.
-
bool isOutputNode(const NodePtr &nodePtr) const#
Assess if the given Node is an output Node of the GraphView object.
-
void setOrderedInputs(const std::vector<std::pair<NodePtr, IOIndex_t>> &inputs)#
Specify the ordered list of inputs of the current GraphView. Any element that is not an actual graph input will trigger an error. Not all graph inputs need to be specified: missing inputs will be automatically appened at the end of the list. Duplicate inputs are not allowed.
Dummy inputs (nullptr) are allowed, but this will only be reflected in mInputNodes. All other functions (nbInputs(), inputs()) will not take it into account.
- Parameters:
inputs – List of std::pair<NodePtr, IOIndex_t>, the first element of the pair being the node inside the graph that is an input node of the graph, the second element of the pair being the input index of the node.
-
void setOrderedOutputs(const std::vector<std::pair<NodePtr, IOIndex_t>> &outputs)#
Specify the ordered list of outputs of the current GraphView. Any node inside the graph can be a graph output, regardless its output is already connected or not. Duplicate outputs are allowed. Not all graph outputs need to be specified: missing outputs will be automatically appened at the end of the list.
Dummy outputs (nullptr) are allowed, but this will only be reflected in mOutputNodes. All other functions (nbOutputs(), outputs()) will not take it into account.
- Parameters:
outputs – List of std::pair<NodePtr, IOIndex_t>, the first element of the pair being the node inside the graph that is an output node of the graph, the second element of the pair being the output index of the node.
-
void addOrderedOutputs(const std::vector<std::pair<NodePtr, IOIndex_t>> &outputs, int pos = -1)#
Specify additionnal graph outputs for the current GraphView, to be inserted a position.
- Parameters:
pos. – Any node inside the graph can be a graph output, regardless if its output is already connected or not. Duplicate outputs are allowed.
outputs – List of std::pair<NodePtr, IOIndex_t>, the first element of the pair being the node inside the graph that is an output node of the graph, the second element of the pair being the output index of the node.
pos – Insertion position in the ordered outputs list. If the position is not valid, outputs are appened at the end of the list.
-
std::vector<Aidge::NodePtr> getOrderedNodes(bool reversed = false) const#
Get a topological node order for an acyclic walk of the graph Graph cycles are broken on operator back edges such that resolution on single level lattice can be done in a single pass as it is the case generally for static resolution of Tensor shapes/datatypes. When reversed is true, gets a topological order on the reversed graph which is equivalent to a post-dfs order of the graph. The returned order is deterministic given the graph node set and the graph ordered output nodes. The output nodes connectivity must cover all nodes of the graph, otherwise a runtime exception is thrown. The returned order is biased toward left-to-right child order both for topological and post-dfs order.
- Parameters:
reversed – returns a topological order of the reversed graph
- Returns:
the ordered list of nodes
-
inline const std::vector<std::pair<NodePtr, IOIndex_t>> &getOrderedInputs() const noexcept#
Get inputs of the current GraphView with their associated id. The rank of the nodes are their rank in the vector.
- Returns:
const std::vector<std::pair<NodePtr, IOIndex_t>>&
-
inline const std::vector<std::pair<NodePtr, IOIndex_t>> &getOrderedOutputs() const noexcept#
Get outputs of the current GraphView with their associated id. The rank of the nodes are their rank in the vector.
- Returns:
const std::vector<std::pair<NodePtr, IOIndex_t>>&
-
std::vector<std::pair<NodePtr, IOIndex_t>> dataInputs() const#
List outside data input connections of the GraphView. Data inputs exclude inputs expecting parameters (weights or bias). The vector size is guaranteed to match the number of outside data inputs of the GraphView. If there is no external connection to a given input, a pair of nullptr and gk_IODefaultIndex is returned.
- Returns:
std::vector<std::pair<NodePtr, IOIndex_t>>
-
inline auto dataInputs(const std::string name) const#
List all dataInput connections (within and outside) of the specified GraphView node named “name”. Data inputs exclude inputs expecting parameters (weights or bias).
- Parameters:
name – Name of the Node.
- Returns:
std::vector<std::pair<NodePtr, IOIndex_t>>
-
std::vector<std::pair<NodePtr, IOIndex_t>> inputs() const#
List outside input connections of the GraphView. The vector size is guaranteed to match the number of outside inputs of the GraphView. If there is no external connection to a given input, a pair of nullptr and gk_IODefaultIndex is returned.
- Returns:
std::vector<std::pair<NodePtr, IOIndex_t>>
-
std::vector<std::pair<NodePtr, IOIndex_t>> inputs(const std::string &name) const#
List all input connections (within and outside) of the specified GraphView node named “name”.
- Returns:
std::vector<std::pair<NodePtr, IOIndex_t>>
-
std::vector<std::vector<std::pair<NodePtr, IOIndex_t>>> outputs() const#
List outside output connections of the GraphView. The vector size is guaranteed to match the number of outputs of the GraphView. If there is no connection to a given output, the corresponding sub-vector will be empty.
- Returns:
std::vector<std::pair<NodePtr, IOIndex_t>>
-
std::vector<std::vector<std::pair<NodePtr, IOIndex_t>>> outputs(const std::string &nodeName) const#
List all output connections (within and outside) of the specified GraphView node named “name”.
- Parameters:
nodeName – Name of the Node of which to show the output.
- Returns:
std::vector<std::vector<std::pair<NodePtr, IOIndex_t>>>
-
void compile(const std::string &backend = "cpu", const Aidge::DataType datatype = DataType::Float32, DeviceIdx_t device = 0, const std::vector<std::vector<DimSize_t>> dims = {})#
Assert Datatype, Backend, data format and dimensions along the GraphView are coherent. If not, apply the required transformations.
Sets the GraphView ready for computation in four steps: 1 - Assert input Tensors’ datatype is compatible with each Operator’s datatype. If not, a conversion Operator is inserted. 2 - Assert input Tensors’ backend is compatible with each Operator’s backend. If not, add a Transmitter Operator. 3 - Assert data format (NCHW, NHWC, …) of each Operator’s input Tensor is compatible with the selected kernel. If not, add a Transpose Operator. 4 - Propagate Tensor dimensions through the consecutive Operators(also named forward dims).
-
bool forwardDims(const std::vector<std::vector<DimSize_t>> &dims = {}, bool allowDataDependency = false)#
Compute and propagate Tensor dimensions through the GraphView.
This function computes dimensions of input/output Tensors for each of the Node’s associated Operator in the GraphView by propagating dimensions from inputs through the entire network. It handles:
Dimension propagation in dependency order
Cyclic dependencies (specifically for Memorize_Op)
Input dimension validation and setting
Optional vs mandatory inputs
The algorithm works in several phases:
Input Dimension Setup:
Validates/sets provided input dimensions
Checks compatibility with existing tensors
Connection Verification:
Ensures all node connections are valid
Verifies mandatory inputs are present
Dimension Propagation:
Propagates dimensions through the graph in topological order
Detects and handles circular dependencies induced by Memorize_Op
Example:
auto graph = std::make_shared<GraphView>(); // ... build graph ... // Forward with default empty dimensions bool success = graph->forwardDims(); // Forward with specific input dimensions std::vector<std::vector<DimSize_t>> inputDims = { {1, 3, 224, 224}, // First input {1, 64, 112, 112} // Second input }; success = graph->forwardDims(inputDims);
Note
Dimensions will be propagated through every Node regardless of if dims were previously forwarded or not;
- Parameters:
dims – Vector of dimension vectors for graph inputs. Empty by default.
allowDataDependency – Whether to allow data-dependent dimension computation. False by default.
- Returns:
true if dimension propagation succeeded, false otherwise.
-
bool forwardDType(const std::vector<DataType> &inputTypes = {})#
Helper function to compute and forward data type throughout the graph It will try to infer the best output datatype based on the input datatype which. To do so it will based itself on the
OperatorTensor::forwardDataType()
method. A generic version of this method is defined inOperatorTensor
and need to be override to account for special case.This method doesn’t substitute itself to the user changing manually the data type of operators but it is preferred to use over
GraphView::setDataType
.- Parameters:
inputTypes – A vector of data type, the order of the vector should be the same as the order of the inputs of the graph.
- Returns:
true if the function succeed to propagate datatype throughout the graph.
-
bool forwardDType(DataType inputType)#
Helper that call
bool forwardDType(const std::vector<DataType>& inputTypes = {})
.- Parameters:
inputType – Data type to set for each input of the graph. That will be forwarded.
- Returns:
true true if the function succeed to propagate data type throughout the graph.
-
void setBackend(const std::string &backend, const DeviceIdx_t device = 0) const#
Set the same backend for each Operator of the GraphView object’s Nodes.
-
void setDataType(const DataType &datatype) const#
Set the same data type for each Operator of the GraphView object’s Nodes.
-
void setDataFormat(const DataFormat &dataformat) const#
Set the same data format for each Operator of the GraphView object’s Nodes.
-
std::set<NodePtr> getParents() const#
Get the parents Nodes of inputNodes.
- Returns:
std::set<NodePtr>
-
std::vector<NodePtr> getParents(const std::string nodeName) const#
Get parents Nodes of the specified Node.
- Parameters:
nodeName – Name of the Node.
- Returns:
std::vector<NodePtr>
-
std::vector<std::vector<NodePtr>> getOrderedParents() const#
-
std::set<NodePtr> getChildren() const#
Get the children Nodes of outputNodes.
- Returns:
std::set<NodePtr>
-
std::vector<std::vector<NodePtr>> getChildren(const std::string nodeName) const#
Get children Nodes of the specified Node.
- Parameters:
nodeName – Name of the Node.
- Returns:
std::vector<std::vector<NodePtr>>
-
std::set<NodePtr> getChildren(const NodePtr otherNode) const#
-
inline const std::set<NodePtr> &getNodes() const noexcept#
Get the Nodes pointed to by the GraphView object.
- Returns:
std::set<NodePtr>
-
NodePtr getNode(const std::string &nodeName) const#
Get the operator with the corresponding name if it is in the GraphView.
- Parameters:
nodeName – Name of the node.
- Returns:
NodePtr returns a nullptr if the one asked for was not found.
-
std::pair<std::vector<NodePtr>, size_t> getRankedNodes() const#
Get the ranked list of nodes in the GraphView. Node ranking if performed the following:
The root node is put in the ranked list first (rank 1);
Then, its childs (in order of outputs) are added in the ranked list;
Then, its parents (in order of inputs) are added in the ranked list;
The childs and parents of the next node in the ranked list are then added to the list, and so on.
Any remaining nodes have no path to the root node and are added in arbitrary order. In this case, the ranking is not guaranteed to be unique.
If the ranking cannot be guaranteed to be unique, the second item indicates the rank from which unicity cannot be guaranteed.
- Returns:
std::pair<std::vector<NodePtr>, size_t> Pair with the list of ranked nodes and the size of the ranked sub-list where unicity is guaranteed.
-
std::map<NodePtr, std::string> getRankedNodesName(const std::string &format, bool markNonUnicity = true) const#
Get the nodes name according to the GraphView nodes ranking.
- Parameters:
format – The formatting string to be used with fmt::format(). The usable positional arguments are the following: {0} node name, {1} node type, {2} rank, {3} type rank
markNonUnicity – If true, non unique ranking is prefixed with “?”
- Returns:
std::map<NodePtr, std::string> A map with the corresponding names
-
void remove(NodePtr nodePtr, bool includeLearnableParam = true)#
Remove a Node from the current GraphView scope without affecting its connections.
- Parameters:
nodePtr – Node to remove
includeLearnableParam – Whether learnable parameters should also be removed. Default true.
-
void setInputId(IOIndex_t inID, IOIndex_t newNodeOutID)#
-
void add(NodePtr otherNode, bool includeLearnableParam = true)#
-
bool add(std::set<NodePtr> otherNodes, bool includeLearnableParam = true)#
Include a set of Nodes to the current GraphView object.
- Parameters:
otherNodes –
includeLearnableParam –
- Returns:
true if graph ordering is unique (meaning inputs/outputs order is well defined).
-
bool add(std::pair<NodePtr, std::set<NodePtr>> otherNodes, bool includeLearnableParam = true)#
Include a set of Nodes to the current GraphView object. The first element of the otherNodes pair is the start node and the second is the remaining nodes to add.
- Parameters:
otherNodes –
includeLearnableParam –
- Returns:
true if graph ordering is unique (meaning inputs/outputs order is well defined).
Include every Node inside another GraphView to the current GraphView.
- Parameters:
other_graph – GraphView containing the Nodes to include.
- Returns:
true if graph ordering is unique (meaning inputs/outputs order is well defined).
-
void addChild(NodePtr toOtherNode, NodePtr fromOutNode = nullptr, const IOIndex_t fromTensor = IOIndex_t(0), IOIndex_t toTensor = gk_IODefaultIndex)#
Include a Node in the current GraphView and link it to another already contained Node.
- Parameters:
toOtherNode – Pointer to the Node to add.
fromOutNode – Pointer to the already included Node the new Node will be linked to (it will become a parent of the new Node). If the GraphView only has one output Node, then default to this Node.
fromTensor – Output Tensor ID of the already included Node. Default to 0.
toTensor – Input Tensor ID of the new Node. Default to gk_IODefaultIndex, meaning first available data input for the Node.
-
inline void addChild(NodePtr toOtherNode, const std::string &fromOutNodeName, const IOIndex_t fromTensor = IOIndex_t(0), IOIndex_t toTensor = gk_IODefaultIndex)#
Include a Node in the current GraphView and link it to another already contained Node.
- Parameters:
toOtherNode – Pointer to the Node to add.
fromOutNodeName – Name of the already included Node the new Node will be linked to (it will become a parent of the new Node). As a name is optional, ensure such Node is in the GraphView or it will send back an error message.
fromTensor – Output Tensor ID of the already included Node. Default to 0.
toTensor – Input Tensor ID of the new Node. Default to gk_IODefaultIndex, meaning first available data input for the Node.
Include a GraphView content in the current GraphView and link the two sets by linking one Node from each GraphView.
- Parameters:
toOtherView – Pointer to the GraphView whose content should be added.
fromOutNode – Pair of pointer to Node and Tensor ID for specifying the connection. If the GraphView including the other one has only one output Node, then it defaults to the first output Tensor of this Node.
toNode – Pair of pointer to Node and Tensor ID for specifying the connection. If the GraphView whose content is included has only one input Node, then it defaults to the first available data input Tensor of this Node.
-
bool swap(Node &node, Node &otherNode)#
Swap two Node instances if possible.
- Parameters:
node –
otherNode –
- Returns:
true
- Returns:
false
-
void link(const std::string &name1_inID, const std::string &name2_outID)#
-
void insertParent(NodePtr childNode, NodePtr newParentNode, IOIndex_t childInputTensorIdx, IOIndex_t newParentInputTensorIdx, IOIndex_t newParentOutputTensorIdx)#
Insert a node (newParentNode) as a parent of the passed node (childNode).
- Parameters:
childNode – Node that gets a new parent.
newParentNode – Inserted Node.
childInputTensorIdx – Index of the input Tensor for the childNode linked to the inserted Node output.
newParentInputTensorIdx – Index of the input Tensor for the newParentNode linked to the former parent of childNode.
newParentOutputTensorIdx – Index of the output Tensor for the newParentNode linked to the childNode’s input Tensor.
Clone the GraphView with shared Operators. It is a new GraphView, with cloned Nodes, but the new Nodes refer to the same Operators as the original ones.
- Returns:
std::shared_ptr<GraphView>
Clone the GraphView with shared Producers. All the other Operators are copied.
- Returns:
std::shared_ptr<GraphView>
-
inline std::shared_ptr<GraphView> clone() const#
Clone the GraphView. Everything is cloned: Nodes and Operators.
- Returns:
std::shared_ptr<GraphView>
-
std::shared_ptr<GraphView> cloneCallback(NodePtr (*cloneNode)(NodePtr)) const#
Clone the current GraphView using a callback function for the Node cloning, allowing to specify how each Node should be cloned or replaced by another Node type, or removed (i.e. replaced by identity). When a Node is removed, the clone() method automatically finds the next valid parent in line, going backward in the graph and connects it if that makes sense without ambiguity (effectively treating the removed Node as an identity operation).
- Parameters:
cloneNode – Callback function to clone a node
- Returns:
std::shared_ptr<GraphView>
Public Static Functions
-
static bool replace(const std::set<NodePtr> &oldNodes, const std::set<NodePtr> &newNodes)#
Replace a set of Nodes in every available GraphView with a new set of Nodes if possible. Both sets should include all the necessary Producers.
There are 3 cases of replacement: Case 1: same number of input/output connections for oldNodes and newNodes sets.
input/output connections are replicated according to their IDs. Case 2: different number of input/output connections for oldNodes and newNodes sets.
only a single parent/child node for the newNodes set, every input/output is connected to it.
several parents/children nodes for newNodes set => impossible to know, return false Case 3: newNodes set is empty
same number of input/output connections in oldNodes, parents and children are linked according to these connections IDs
different number of input/output connections in oldNodes => return false Case 4: newNodes set has no input and one output, oldNodes has any input and one output
reconnect output
all input are disconnected
- Parameters:
oldNodes –
newNodes –
- Returns:
true replacement has been performed
- Returns:
false no replacement has been performed
-
inline GraphView(const std::string &name = "")#
It is possible to automatically generate a GraphView that encompasses all the connected nodes with a path to a given node with the getConnectedGraphView
function:
- aidge_core.get_connected_graph_view(arg0: aidge_core.aidge_core.Node) aidge_core.aidge_core.GraphView #
Graph helpers#
Graph helpers are pseudo-containers that allow you to quickly build a graph without explicit node connections, like the Sequential
container in PyTorch. One important difference with PyTorch is that they are only temporary builders, and do not form a structure in the returned graph. They return a GraphView.
- aidge_core.sequential(inputs: list[aidge_core.aidge_core.OpArgs], name: str = '') aidge_core.aidge_core.GraphView #
Usage example:
input_data = np.array([0, 1, 2, 3]).astype(np.float32)
input_tensor = aidge_core.Tensor(input_data)
graph_view = aidge_core.sequential([
aidge_core.Producer(input_tensor, "IN"),
aidge_core.FC(1, 50, name='FC0'),
aidge_core.FC(50, 50, name='FC1'),
aidge_core.FC(50, 10, name='FC2'),
])
-
std::shared_ptr<GraphView> Aidge::Sequential(std::vector<OpArgs> inputs, std::string name = "")#
Create a GraphView by linking every input with the next one in a sequential way. Nodes linked with the Sequential graph generation instructions must have a single output. Sequential(A, B, C) returns A–>B–>C.
Usage example:
auto input_tensor = std::make_shared<Tensor>(Array1D<float,4>{{0, 1, 2, 3}});
auto graph_view = Sequential({
Producer(input_tensor, "IN"),
FC(1, 50, false, "FC0"),
FC(50, 50, false, "FC1"),
FC(50, 10, false, "FC2")
})
- aidge_core.parallel(inputs: list[aidge_core.aidge_core.OpArgs], name: str = '') aidge_core.aidge_core.GraphView #
Usage example:
input_data = np.array([0, 1, 2, 3]).astype(np.float32)
input_tensor = aidge_core.Tensor(input_data)
graph_view = aidge_core.sequential([
aidge_core.Producer(input_tensor, "X"),
aidge_core.FC(1, 50, name='FC0'),
aidge_core.parallel([
aidge_core.FC(50, 50, name='FC1'),
aidge_core.FC(50, 50, name='FC3')
]),
aidge_core.Add(2, name='FC2'),
])
-
std::shared_ptr<GraphView> Aidge::Parallel(std::vector<OpArgs> inputs, std::string name = "")#
Creates a GraphView with provided Nodes without linking them.
Usage example:
auto g = Sequential({
Conv(1, 3, {3, 3}, "inputConv"),
Parallel({
Conv(3, 3, {1, 1}, "conv1.1"),
Conv(3, 3, {1, 1}, "conv1.2"),
Conv(3, 3, {1, 1}, "conv1.3")
}),
Add(3, "add1"),
Conv(3, 2, {1, 1}, "conv2"),
FC(18, 5, false, "out")
});
- aidge_core.residual(inputs: list[aidge_core.aidge_core.OpArgs], name: str = '') aidge_core.aidge_core.GraphView #
-
std::shared_ptr<GraphView> Aidge::Residual(std::vector<OpArgs> inputs, std::string name = "")#
Create a GraphView by linking every input with the next one in a sequential way. Finally the first element output is used as another input for the last element. Nodes linked with the Recursive graph generation instructions must have a single output. Recursive(A, B, C) returns A–>B–>C , A–>C.
Connector#
The Connector object enables you to build a graph in a functional style like you would often do in other DL frameworks. However, please note that doing so is just a way of building a graph, and does not result in any “eager” execution. Using an explicit Connector object is here to make that intent clear.
Additionally, it is possible to mix both graph helpers and functional Connector-based styles.
-
class Connector#
Object meant for simpler and more instrinctive user API.
example: Connector x(); x = Conv(…)(x); Connector y = Split(3)(x[0]); // Error! Cannot slice a Connector with one output only Connector y = Split(3)(x); CustomLayer cl(…); Connector z = cl(y) // Error! y has multiple outputs, must specify which one to use Connector z1 = cl(y[0]); Connector z2 = cl(y[1]); Connector z3 = cl(y[2]); x = Sum(…)(z1, z2, z3); GraphView g = x.generateGraph();
Usage example:
auto x = Connector();
auto y = Connector();
x = (*GenericOperator("Producer", 0, 0, 1))({});
y = (*GenericOperator("Producer", 0, 0, 1))({});
// Connect 5 successive convolution
for (int i = 0; i < 5; ++i) {
x = (*GenericOperator("Conv", 1, 0, 1))({x});
}
y = (*GenericOperator("ElemWise", 2, 0, 1))({y, x});
// Create a GraphView
auto g = generateGraph({y});
A GraphView can be obtained directly from the last Connector with the generateGraph
function.
- aidge_core.generate_graph(output_connectors: list[aidge_core.aidge_core.Connector]) aidge_core.aidge_core.GraphView #