DGraph
DGraph
DGraph(data: 'DGData', device: str | device = 'cpu')
Dynamic Graph object providing a view over a DGStorage backend.
This class allows efficient slicing, batching, and materialization of temporal/dynamic graph data. It exposes properties for node and edge counts, features, timestamps, and supports device placement for tensors.
Parameters:
-
data(DGData) –The source DGData object to construct the dynamic graph view.
-
device(str | device, default:'cpu') –The device to place tensors on. Defaults to 'cpu'.
Raises:
-
TypeError–If
datais not a DGData instance.
Note
- Slicing operations (
slice_eventsorslice_time) return a newDGraphview sharing the underlying storage; they do not copy data unless explicitly materialized viamaterialize(). - Cached properties (e.g.,
num_nodes,edges,static_node_x) are computed on first access and then stored. Modifying the underlying storage does not automatically invalidate these cached values. materialize()returns dense tensors for src, dst, time, and optionally dynamic node and edge features. This operation may be memory-intensive for large graphs.slice_eventsuses event indices (position in chronological order), whileslice_timeuses timestamp values. Forslice_time, the end_time is exclusive but internally adjusted to include events at end_time - 1.num_nodescounts the maximum node ID in the slice + 1; this may differ from the number of nodes in the underlying DGData if slicing excludes some nodes.static_node_xshape is(num_nodes_global, d_node_static)and is independent of slices, whereasnode_xreflects the current slice.- Operations such as
.to(device)or slicing create views; data is not copied unless explicitly materialized.
Methods:
-
materialize–Materialize the current DGraph slice into a dense
DGBatch. -
num_edge_events–The total number of edge events in the dynamic graph.
-
num_events–The total number of events encountered over the dynamic graph.
-
num_node_events–The total number of node events in the dynamic graph.
-
num_node_labels–The total number of node labels in the dynamic graph.
-
num_nodes–The total number of unique nodes encountered over the dynamic graph.
-
num_timestamps–The total number of unique timestamps encountered over the dynamic graph.
-
slice_events–Return a new DGraph view sliced by event indices (end_idx exclusive).
-
slice_time–Return a new DGraph view sliced by timestamps (end_time exclusive).
-
to–Return a copy of the DGraph view on a different device.
Attributes:
-
edge_dst(Tensor) –The edge dst tensor over the dynamic graph.
-
edge_src(Tensor) –The edge src tensor over the dynamic graph.
-
edge_time(Tensor) –The timestamps associated with the edge events over the dynamic graph.
-
edge_type(Optional[Tensor]) –The aggregated edge type over the dynamic graph.
-
edge_x(Optional[Tensor]) –The aggregated edge features over the dynamic graph.
-
edge_x_dim(Optional[int]) –Edge feature dimension or None if not Node features on the Graph.
-
end_time(Optional[int]) –The end time of the dynamic graph. None, if the graph is empty.
-
node_type(Optional[Tensor]) –If node types exist, returns a dense Tensor(num_nodes_global).
-
node_x(Optional[Tensor]) –The aggregated dynamic node features over the dynamic graph.
-
node_x_dim(Optional[int]) –Dynamic Node feature dimension or None if not Node features on the Graph.
-
node_x_nids(Tensor) –The node ids for associated with the node events over the dynamic graph.
-
node_x_time(Tensor) –The timestamps associated with the node events over the dynamic graph.
-
node_y(Optional[Tensor]) –The aggregated dynamic node labels over the dynamic graph.
-
node_y_dim(Optional[int]) –Dynamic Node label feature dimension or None if no Node labels on the Graph.
-
node_y_nids(Tensor) –The node ids for associated with the node labels over the dynamic graph.
-
node_y_time(Tensor) –The timestamps associated with the node labels over the dynamic graph.
-
start_time(Optional[int]) –The start time of the dynamic graph. None if the graph is empty.
-
static_node_x(Optional[Tensor]) –If static node features exist, returns a dense Tensor(num_nodes_global x d_node_static).
-
static_node_x_dim(Optional[int]) –Static Node feature dimension or None if not Node features on the Graph.
Source code in tgm/core/graph.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
edge_dst
property
edge_dst: Tensor
The edge dst tensor over the dynamic graph.
edge_src
property
edge_src: Tensor
The edge src tensor over the dynamic graph.
edge_time
property
edge_time: Tensor
The timestamps associated with the edge events over the dynamic graph.
edge_type
property
edge_type: Optional[Tensor]
The aggregated edge type over the dynamic graph.
If edge type exist, returns a tensor of shape (T x V x V).
edge_x
property
edge_x: Optional[Tensor]
The aggregated edge features over the dynamic graph.
If edge features exist, returns a tensor of shape (T x V x V x d_edge).
edge_x_dim
cached
property
Edge feature dimension or None if not Node features on the Graph.
end_time
cached
property
The end time of the dynamic graph. None, if the graph is empty.
node_type
property
node_type: Optional[Tensor]
If node types exist, returns a dense Tensor(num_nodes_global).
Note
- num_nodes_global is the global number of nodes from the underlying DGData and it will be independent of the slice.
node_x
property
node_x: Optional[Tensor]
The aggregated dynamic node features over the dynamic graph.
If dynamic node features exist, returns a Tensor.sparse_coo_tensor(T x V x d_node_dynamic).
node_x_dim
cached
property
Dynamic Node feature dimension or None if not Node features on the Graph.
node_x_nids
property
node_x_nids: Tensor
The node ids for associated with the node events over the dynamic graph.
node_x_time
property
node_x_time: Tensor
The timestamps associated with the node events over the dynamic graph.
node_y
property
node_y: Optional[Tensor]
The aggregated dynamic node labels over the dynamic graph.
If dynamic node labels exist, returns a Tensor.sparse_coo_tensor(T x V x d_node_label).
node_y_dim
cached
property
Dynamic Node label feature dimension or None if no Node labels on the Graph.
node_y_nids
property
node_y_nids: Tensor
The node ids for associated with the node labels over the dynamic graph.
node_y_time
property
node_y_time: Tensor
The timestamps associated with the node labels over the dynamic graph.
start_time
cached
property
The start time of the dynamic graph. None if the graph is empty.
static_node_x
property
static_node_x: Optional[Tensor]
If static node features exist, returns a dense Tensor(num_nodes_global x d_node_static).
Note
- num_nodes_global is the global number of nodes from the underlying DGData and it will be independent of the slice.
static_node_x_dim
cached
property
Static Node feature dimension or None if not Node features on the Graph.
materialize
Materialize the current DGraph slice into a dense DGBatch.
Parameters:
-
materialize_features(bool, default:True) –If True, includes dynamic node features, node IDs/times, and edge features. Defaults to True.
Returns:
-
DGBatch(DGBatch) –A batch containing src, dst, timestamps, and optionally features from the current slice.
Source code in tgm/core/graph.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
num_edge_events
num_edge_events() -> int
The total number of edge events in the dynamic graph.
Source code in tgm/core/graph.py
213 214 215 216 | |
num_events
num_events() -> int
The total number of events encountered over the dynamic graph.
Source code in tgm/core/graph.py
223 224 225 226 | |
num_node_events
num_node_events() -> int
The total number of node events in the dynamic graph.
Source code in tgm/core/graph.py
203 204 205 206 | |
num_node_labels
num_node_labels() -> int
The total number of node labels in the dynamic graph.
Source code in tgm/core/graph.py
208 209 210 211 | |
num_nodes
num_nodes() -> int
The total number of unique nodes encountered over the dynamic graph.
Source code in tgm/core/graph.py
197 198 199 200 201 | |
num_timestamps
num_timestamps() -> int
The total number of unique timestamps encountered over the dynamic graph.
Source code in tgm/core/graph.py
218 219 220 221 | |
slice_events
Return a new DGraph view sliced by event indices (end_idx exclusive).
Parameters:
-
start_idx(int, default:None) –Starting event index.
-
end_idx(int, default:None) –Ending event index (exclusive).
Raises:
-
ValueError–If start_idx > end_idx.
Source code in tgm/core/graph.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
slice_time
Return a new DGraph view sliced by timestamps (end_time exclusive).
Parameters:
-
start_time(int, default:None) –Starting timestamp.
-
end_time(int, default:None) –Ending timestamp (exclusive).
Raises:
-
ValueError–If start_time > end_time.
Source code in tgm/core/graph.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
to
Return a copy of the DGraph view on a different device.
Parameters:
-
device(str | device) –The target device.
Returns:
-
DGraph(DGraph) –A new view on the specified device.
Source code in tgm/core/graph.py
169 170 171 172 173 174 175 176 177 178 179 180 181 | |