Node Class¶
The Forge Node class wraps around the igraph.Vertex
object that is initialized by the graphical encoding provided by the graph-core API.
forge.relay.graph.node.Node
¶
Node(graph: Graph, vertex: Union[Vertex, str])
A wrapper around igraph.Vertex
for graph-encoded Relay expressions.
The Node
class provides a simplified API for working with graph vertices
in the context of the Forge Graph
it belongs to. It represents a single
vertex and encapsulates metadata, relationships, and attributes of the graph.
Initializes a Node instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
The Forge graph to which this node belongs. |
required |
vertex
|
Union[Vertex, str]
|
The |
required |
Methods:
Name | Description |
---|---|
set_name |
Sets the name of the node. |
set_data |
Sets the data for the node. |
relay_var |
Expresses the node as a Relay variable. |
_find_ivertex |
Finds the igraph.Vertex by name. |
_init_node |
Initializes a node from an igraph.Vertex or its name. |
_out_iedges |
Retrieves the outgoing edges from the node. |
_iter_pred |
Iterates over predecessor nodes. |
_iter_succ |
Iterates over successor nodes. |
__repr__ |
Generates a string representation of the node. |
__getitem__ |
Retrieves a node attribute by key using |
__setitem__ |
Sets a node attribute by key using |
Attributes:
Name | Type | Description |
---|---|---|
graph |
Graph
|
|
name |
str
|
Retrieves the name of the node. |
type |
str
|
Retrieves the type of the node. |
shape |
Union[Tuple[int], List[Tuple[int]]]
|
Retrieves the shape(s) of the node's activation data. |
dtype |
Union[str, List[str]]
|
Retrieves the data type(s) of the node's activation data. |
size |
Union[Optional[int], List[Optional[int]]]
|
Retrieves the size(s) of the node's activation data. |
pred |
List[Node]
|
Retrieves the predecessor nodes in argument order. |
succ |
List[Node]
|
Retrieves the successor nodes. |
target_names |
List[str]
|
Retrieves the names of target nodes for outgoing edges. |
target_argidxs |
List[int]
|
Retrieves the argument indices for outgoing edges. |
target_details |
Tuple[Tuple[str, ...], Tuple[int, ...]]
|
Retrieves details of outgoing edges, including target names and argument indices. |
indegree |
int
|
Retrieves the in-degree of the node. |
outdegree |
int
|
Retrieves the out-degree of the node. |
activation |
ActivationMetaData
|
Retrieves the activation metadata of the node. |
input_index |
Optional[int]
|
Retrieves the input index of the node, if applicable. |
tuple_index |
Optional[int]
|
Retrieves the tuple index of the node, if applicable. |
op_name |
Optional[str]
|
Retrieves the name of the operator associated with the node, if applicable. |
op_attrs |
Optional[str]
|
Retrieves the attributes of the operator associated with the node, if applicable. |
op_type |
Optional[str]
|
Retrieves the type of the operator associated with the node, if applicable. |
layout |
Optional[str]
|
Retrieves the layout associated with the node, if applicable. |
calib |
Optional[CalibrationMetaData]
|
Retrieves the calibration metadata of the node, if applicable. |
data |
Optional[ndarray]
|
Retrieves the data associated with the node, if applicable. |
ivertex |
Vertex
|
Retrieves the underlying igraph.Vertex for this node. |
Attributes¶
name
property
¶
name: str
Retrieves the name of the node.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The name of the node. |
type
property
¶
type: str
Retrieves the type of the node.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The type of the node (e.g. Sink, Call, Constant). |
shape
property
¶
shape: Union[Tuple[int], List[Tuple[int]]]
Retrieves the shape(s) of the node's activation data.
Returns:
Type | Description |
---|---|
Union[Tuple[int], List[Tuple[int]]]
|
Union[Tuple[int], List[Tuple[int]]]: The shape or a list of shapes associated with the node. |
dtype
property
¶
dtype: Union[str, List[str]]
Retrieves the data type(s) of the node's activation data.
Returns:
Type | Description |
---|---|
Union[str, List[str]]
|
Union[str, List[str]]: The data type or a list of data types associated with the node. |
size
property
¶
size: Union[Optional[int], List[Optional[int]]]
Retrieves the size(s) of the node's activation data.
Returns:
Type | Description |
---|---|
Union[Optional[int], List[Optional[int]]]
|
Union[Optional[int], List[Optional[int]]]: The size or a list of sizes associated with the node. |
Note
- Size is the number of total elements, i.e. the reduced product of the shape
pred
property
¶
pred: List[Node]
Retrieves the predecessor nodes in argument order.
Returns:
Type | Description |
---|---|
List[Node]
|
List[Node]: A list of predecessor nodes in argument order. |
succ
property
¶
succ: List[Node]
Retrieves the successor nodes.
Returns:
Type | Description |
---|---|
List[Node]
|
List[Node]: A list of successor nodes. |
target_names
property
¶
target_names: List[str]
Retrieves the names of target nodes for outgoing edges.
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A list of target node names. |
target_argidxs
property
¶
target_argidxs: List[int]
Retrieves the argument indices for outgoing edges.
Returns:
Type | Description |
---|---|
List[int]
|
List[int]: A list of argument indices. |
target_details
property
¶
target_details: Tuple[Tuple[str, ...], Tuple[int, ...]]
Retrieves details of outgoing edges, including target names and argument indices.
Returns:
Type | Description |
---|---|
Tuple[Tuple[str, ...], Tuple[int, ...]]
|
Tuple[Tuple[str, ...], Tuple[int, ...]]: A tuple containing target names and argument indices. |
indegree
property
¶
indegree: int
Retrieves the in-degree of the node.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The number of incoming edges. |
outdegree
property
¶
outdegree: int
Retrieves the out-degree of the node.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The number of outgoing edges. |
activation
property
¶
activation: ActivationMetaData
Retrieves the activation metadata of the node.
Returns:
Name | Type | Description |
---|---|---|
ActivationMetaData |
ActivationMetaData
|
The activation metadata associated with the node. |
input_index
property
¶
input_index: Optional[int]
Retrieves the input index of the node, if applicable.
Returns:
Type | Description |
---|---|
Optional[int]
|
Optional[int]: The input index, or None if not applicable. |
tuple_index
property
¶
tuple_index: Optional[int]
Retrieves the tuple index of the node, if applicable.
Returns:
Type | Description |
---|---|
Optional[int]
|
Optional[int]: The tuple index, or None if not applicable. |
op_name
property
¶
op_name: Optional[str]
Retrieves the name of the operator associated with the node, if applicable.
Returns:
Type | Description |
---|---|
Optional[str]
|
Optional[str]: The operator name, or None if not applicable. |
op_attrs
property
¶
op_attrs: Optional[str]
Retrieves the attributes of the operator associated with the node, if applicable.
Returns:
Type | Description |
---|---|
Optional[str]
|
Optional[str]: The operator attributes, or None if not applicable. |
op_type
property
¶
op_type: Optional[str]
Retrieves the type of the operator associated with the node, if applicable.
Returns:
Type | Description |
---|---|
Optional[str]
|
Optional[str]: The operator type, or None if not applicable. |
layout
property
¶
layout: Optional[str]
Retrieves the layout associated with the node, if applicable.
Returns:
Type | Description |
---|---|
Optional[str]
|
Optional[str]: The layout, or None if not applicable. |
calib
property
¶
calib: Optional[CalibrationMetaData]
Retrieves the calibration metadata of the node, if applicable.
Returns:
Type | Description |
---|---|
Optional[CalibrationMetaData]
|
Optional[CalibrationMetaData]: The calibration metadata, or None if not applicable. |
data
property
¶
data: Optional[ndarray]
Retrieves the data associated with the node, if applicable.
Returns:
Type | Description |
---|---|
Optional[ndarray]
|
Optional[np.ndarray]: The data, or None if not applicable. |
ivertex
property
¶
ivertex: Vertex
Retrieves the underlying igraph.Vertex for this node.
Returns:
Type | Description |
---|---|
Vertex
|
igraph.Vertex: The underlying vertex. |
Functions¶
set_name
¶
set_name(name) -> None
Sets the name of the node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The new name for the node. |
required |
set_data
¶
set_data(data: ndarray) -> None
Sets the data for the node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
ndarray
|
The data to associate with the node. |
required |
relay_var
¶
relay_var() -> obj
Expresses the node as a Relay variable.
Returns:
Type | Description |
---|---|
obj
|
Relay.Var.obj: The Relay variable representation of the node. |
_find_ivertex
¶
_find_ivertex(name: str) -> Vertex
Finds the igraph.Vertex by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the vertex to find. |
required |
Returns:
Type | Description |
---|---|
Vertex
|
igraph.Vertex: The found vertex. |
_init_node
¶
_init_node(vertex: Union[Vertex, str]) -> Node
Initializes a node from an igraph.Vertex or its name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vertex
|
Union[Vertex, str]
|
The vertex or its name. |
required |
Returns:
Name | Type | Description |
---|---|---|
Node |
Node
|
The initialized Node. |
_out_iedges
¶
_out_iedges() -> List[Edge]
Retrieves the outgoing edges from the node.
Returns:
Type | Description |
---|---|
List[Edge]
|
List[igraph.Edge]: A list of outgoing edges. |
_iter_pred
¶
_iter_pred()
Iterates over predecessor nodes.
Returns:
Type | Description |
---|---|
Iterator[Node]: An iterator over predecessor nodes. |
_iter_succ
¶
_iter_succ()
Iterates over successor nodes.
Returns:
Type | Description |
---|---|
Iterator[Node]: An iterator over successor nodes. |
__repr__
¶
__repr__() -> str
Generates a string representation of the node.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A string describing the node. |
__getitem__
¶
__getitem__(key) -> Any
Retrieves a node attribute by key using igraph.Vertex
API syntax.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The key of the attribute. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The value of the attribute. |
__setitem__
¶
__setitem__(key, val) -> None
Sets a node attribute by key using igraph.Vertex
API syntax.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The key of the attribute. |
required |
val
|
Any
|
The value to set for the attribute. |
required |