Artificial
rex.artificial.generate_graphs(nodes: Dict[str, BaseNode], ts_max: float, rng: jax.Array = None, num_episodes: int = 1) -> Graph
¤
Generate graphs based on the nodes, computation delays, and communication delays.
All nodes are assumed to have a rate and name attribute. Moreover, all nodes are assumed to run and communicate asynchronously. In other words, their timestamps are independent.
Parameters:
-
nodes
(Dict[str, BaseNode]
) –Dictionary of nodes.
-
ts_max
(float
) –Final time.
-
rng
(Array
, default:None
) –Random number generator.
-
num_episodes
(int
, default:1
) –Number of graphs to generate.
Returns:
-
Graph
–Graphs for each episode.
rex.artificial.augment_graphs(graphs: Graph, nodes: Dict[str, BaseNode], rng: jax.Array = None) -> Graph
¤
Augment graphs based on the nodes, computation delays, and communication delays.
With augmenting, the graphs are expanded with additional vertices and edges based on the provided nodes. Nodes not in graphs.vertices are added to the graphs according to the specified delay_dist. Edges between vertices are added for connections not present in graphs.edges.
Parameters:
-
graphs
(Graph
) –Graphs to augment.
-
nodes
(Dict[str, BaseNode]
) –Dictionary of nodes.
-
rng
(Array
, default:None
) –Random number generator.
Returns:
-
Graph
–Augmented graphs.
rex.base.Graph
¤
A computation graph data structure that holds the vertices and edges of a computation graph.
This data structure is used to represent the computation graph of a system. It holds the vertices and edges of the graph. The vertices represent consecutive step calls of nodes, and the edges represent the data flow between connected nodes.
Stateful edges must not be included in the edges, but are implicitly assumed. In other words, consecutive sequence numbers of the same node are assumed to be connected.
The graph should be directed and acyclic. Cycles are not allowed.
Attributes:
-
vertices
(Dict[str, Vertex]
) –A dictionary of vertices. The keys are the unique names of the node type, and the values are the vertices.
-
edges
(Dict[Tuple[str, str], Edge]
) –A dictionary of edges. The keys are of the form (n1, n2), where n1 and n2 are the unique names of the output and input nodes, respectively. The values are the edges.
__len__() -> int
¤
Get the number of episodes in the graph.
Returns:
-
int
–The number of episodes (i.e. the number of graphs if the graph is batched).
__getitem__(val: int) -> Graph
¤
In case the graph is batched, and holds the graphs of multiple episodes, this function returns the graph of a specific episode.
Parameters:
-
val
(int
) –The episode to get the graph of.
Returns:
-
Graph
–The graph of the specific episode.
stack(graphs_raw: List[Graph]) -> Graph
staticmethod
¤
filter(nodes: Dict[str, BaseNode], filter_edges: bool = True) -> Graph
¤
Filter the graph to only include the nodes and edges that are in the nodes dictionary.
Parameters:
-
nodes
(Dict[str, BaseNode]
) –A dictionary of nodes. The keys are the unique names of the nodes, and the values are the nodes.
-
filter_edges
(bool
, default:True
) –If True, only include the nodes that are connected to the nodes in the dictionary.
Returns:
-
Graph
–A new graph with only the nodes and edges that are in the nodes dictionary.
rex.base.Vertex
¤
A vertex data structure that holds the sequence numbers and timestamps of a node.
This data structure may be batched and hold data for multiple episodes. The last dimension represent the sequence numbers during the episode.
In case the timestamps are not available, set ts_start and ts_end to a dummy value (e.g. 0.0).
Ideally, for every vertex seq[i] there should be an edge with seq_out[i] for every connected node in the graph.
Attributes:
-
seq
(Union[int, Array]
) –The sequence number of the node. Should start at 0 and increase by 1 every step (no gaps).
-
ts_start
(Union[float, Array]
) –The start time of the computation of the node (i.e. when the node starts processing step 'seq').
-
ts_end
(Union[float, Array]
) –The end time of the computation of the node (i.e. when the node finishes processing step 'seq').
rex.base.Edge
¤
And edge data structure that holds the sequence numbers and timestamps of a connection.
This data structure may be batched and hold data for multiple episodes. The last dimension represent the data during the episode.
Given a message from node_out to node_in, the sequence number of the send message is seq_out. The message is received at node_in at time ts_recv. Seq_in is the sequence number of the call that node_in processes the message.
When there are outputs that were never received, set the seq_in to -1.
In case the received timestamps are not available, set ts_recv to a dummy value (e.g. 0.0).
Attributes:
-
seq_out
(Union[int, Array]
) –The sequence number of the message. Must be monotonically increasing.
-
seq_in
(Union[int, Array]
) –The sequence number of the call that the message is processed. Must be monotonically increasing.
-
ts_recv
(Union[float, Array]
) –The time the message is received at the input node. Must be monotonically increasing.