molprop.pyg_molgraph.MultiGraphData
- class molprop.pyg_molgraph.MultiGraphData(x_size_dict=None, **kwargs)
Bases:
DataMethods
__init__Applies the function
func, either to all attributes or only the ones given in*args.Applies the in-place function
func, either to all attributes or only the ones given in*args.Performs cloning of tensors, either for all attributes or only the ones given in
*args.Sorts and removes duplicated entries from edge indices
edge_index.Concatenates
selfwith anotherdataobject.contains_isolated_nodescontains_self_loopsEnsures a contiguous memory layout, either for all attributes or only the ones given in
*args.Returns the edge indices in the
GraphStorein COO format.Copies attributes to CPU memory, either for all attributes or only the ones given in
*args.Returns the edge indices in the
GraphStorein CSC format.Returns the edge indices in the
GraphStorein CSR format.Copies attributes to CUDA memory, either for all attributes or only the ones given in
*args.debugDetaches attributes from the computation graph by creating a new tensor, either for all attributes or only the ones given in
*args.Detaches attributes from the computation graph, either for all attributes or only the ones given in
*args.Returns all edge-level tensor attribute names.
Returns the induced subgraph given by the edge indices
subset.Creates a
Dataobject from a dictionary.Generates and sets
n_idande_idattributes to assign each node and edge to a continuously ascending and unique ID.Returns all registered edge attributes.
Obtains all feature attributes stored in Data.
Synchronously obtains an
edge_indextuple from theGraphStore.Synchronously obtains a
tensorfrom theFeatureStore.Obtains the size of a tensor given its
TensorAttr, orNoneif the tensor does not exist.Returns
Trueif the graph contains isolated nodes.Returns
Trueif the graph contains self-loops.Returns
Trueif edge indicesedge_indexare sorted and do not contain duplicate entries.Returns
Trueif graph edges are directed.Returns
Trueif the object at keykeydenotes an edge-level tensor attribute.Returns
Trueif the object at keykeydenotes a node-level tensor attribute.Returns
Trueif edge indicesedge_indexare sorted.Returns
Trueiftimeis sorted.Returns
Trueif graph edges are undirected.Returns a list of all graph attribute names.
Synchronously obtains a list of tensors from the
FeatureStorefor each tensor associated with the attributes inattrs.Returns all node-level tensor attribute names.
Copies attributes to pinned memory, either for all attributes or only the ones given in
*args.Synchronously adds an
edge_indextuple to theGraphStore.Synchronously adds a
tensorto theFeatureStore.Ensures that the tensor memory is not reused for another tensor until all current work queued on
streamhas been completed, either for all attributes or only the ones given in*args.Synchronously deletes an
edge_indextuple from theGraphStore.Removes a tensor from the
FeatureStore.Tracks gradient computation, either for all attributes or only the ones given in
*args.Moves attributes to shared memory, either for all attributes or only the ones given in
*args.Returns the size of the adjacency matrix induced by the graph.
Returns a snapshot of
datato only hold events that occurred in period[start_time, end_time].Sorts edge indices
edge_indexand their corresponding edge features.Sorts data associated with
timeaccording totime.stores_asReturns the induced subgraph given by the node indices
subset.Performs tensor device conversion, either for all attributes or only the ones given in
*args.Returns a dictionary of stored key/value pairs.
Converts a
Dataobject to a heterogeneousHeteroDataobject.Returns a
NamedTupleof stored key/value pairs.Returns a snapshot of
datato only hold events that occurred up toend_time(inclusive ofedge_time).Updates the data object with the elements from another data object.
Updates a
tensorin theFeatureStorewith a new value.Validates the correctness of the data.
Returns a view of the
FeatureStoregiven a not yet fully-specifiedTensorAttr.- apply(func: Callable, *args: str)
Applies the function
func, either to all attributes or only the ones given in*args.
- apply_(func: Callable, *args: str)
Applies the in-place function
func, either to all attributes or only the ones given in*args.
- clone(*args: str)
Performs cloning of tensors, either for all attributes or only the ones given in
*args.
- coalesce() Self
Sorts and removes duplicated entries from edge indices
edge_index.
- concat(data: Self) Self
Concatenates
selfwith anotherdataobject. All values needs to have matching shapes at non-concat dimensions.
- contiguous(*args: str)
Ensures a contiguous memory layout, either for all attributes or only the ones given in
*args.
- coo(edge_types: List[Any] | None = None, store: bool = False) Tuple[Dict[Tuple[str, str, str], Tensor], Dict[Tuple[str, str, str], Tensor], Dict[Tuple[str, str, str], Tensor | None]]
Returns the edge indices in the
GraphStorein COO format.- Parameters:
edge_types (List[Any], optional) – The edge types of edge indices to obtain. If set to
None, will return the edge indices of all existing edge types. (default:None)store (bool, optional) – Whether to store converted edge indices in the
GraphStore. (default:False)
- cpu(*args: str)
Copies attributes to CPU memory, either for all attributes or only the ones given in
*args.
- csc(edge_types: List[Any] | None = None, store: bool = False) Tuple[Dict[Tuple[str, str, str], Tensor], Dict[Tuple[str, str, str], Tensor], Dict[Tuple[str, str, str], Tensor | None]]
Returns the edge indices in the
GraphStorein CSC format.- Parameters:
edge_types (List[Any], optional) – The edge types of edge indices to obtain. If set to
None, will return the edge indices of all existing edge types. (default:None)store (bool, optional) – Whether to store converted edge indices in the
GraphStore. (default:False)
- csr(edge_types: List[Any] | None = None, store: bool = False) Tuple[Dict[Tuple[str, str, str], Tensor], Dict[Tuple[str, str, str], Tensor], Dict[Tuple[str, str, str], Tensor | None]]
Returns the edge indices in the
GraphStorein CSR format.- Parameters:
edge_types (List[Any], optional) – The edge types of edge indices to obtain. If set to
None, will return the edge indices of all existing edge types. (default:None)store (bool, optional) – Whether to store converted edge indices in the
GraphStore. (default:False)
- cuda(device: int | str | None = None, *args: str, non_blocking: bool = False)
Copies attributes to CUDA memory, either for all attributes or only the ones given in
*args.
- detach(*args: str)
Detaches attributes from the computation graph by creating a new tensor, either for all attributes or only the ones given in
*args.
- detach_(*args: str)
Detaches attributes from the computation graph, either for all attributes or only the ones given in
*args.
- edge_attrs() List[str]
Returns all edge-level tensor attribute names.
- edge_subgraph(subset: Tensor) Self
Returns the induced subgraph given by the edge indices
subset. Will currently preserve all the nodes in the graph, even if they are isolated after subgraph computation.- Parameters:
subset (LongTensor or BoolTensor) – The edges to keep.
- classmethod from_dict(mapping: Dict[str, Any]) Self
Creates a
Dataobject from a dictionary.
- generate_ids()
Generates and sets
n_idande_idattributes to assign each node and edge to a continuously ascending and unique ID.
- get_all_edge_attrs() List[EdgeAttr]
Returns all registered edge attributes.
- get_all_tensor_attrs() List[TensorAttr]
Obtains all feature attributes stored in Data.
- get_edge_index(*args, **kwargs) Tuple[Tensor, Tensor]
Synchronously obtains an
edge_indextuple from theGraphStore.- Parameters:
*args – Arguments passed to
EdgeAttr.**kwargs – Keyword arguments passed to
EdgeAttr.
- Raises:
KeyError – If the
edge_indexcorresponding to the inputEdgeAttrwas not found.
- get_tensor(*args, convert_type: bool = False, **kwargs) Tensor | ndarray
Synchronously obtains a
tensorfrom theFeatureStore.- Parameters:
*args – Arguments passed to
TensorAttr.convert_type (bool, optional) – Whether to convert the type of the output tensor to the type of the attribute index. (default:
False)**kwargs – Keyword arguments passed to
TensorAttr.
- Raises:
ValueError – If the input
TensorAttris not fully specified.
- get_tensor_size(*args, **kwargs) Tuple[int, ...] | None
Obtains the size of a tensor given its
TensorAttr, orNoneif the tensor does not exist.
- has_isolated_nodes() bool
Returns
Trueif the graph contains isolated nodes.
- has_self_loops() bool
Returns
Trueif the graph contains self-loops.
- is_coalesced() bool
Returns
Trueif edge indicesedge_indexare sorted and do not contain duplicate entries.
- property is_cuda: bool
Returns
Trueif anytorch.Tensorattribute is stored on the GPU,Falseotherwise.
- is_directed() bool
Returns
Trueif graph edges are directed.
- is_edge_attr(key: str) bool
Returns
Trueif the object at keykeydenotes an edge-level tensor attribute.
- is_node_attr(key: str) bool
Returns
Trueif the object at keykeydenotes a node-level tensor attribute.
- is_sorted(sort_by_row: bool = True) bool
Returns
Trueif edge indicesedge_indexare sorted.- Parameters:
sort_by_row (bool, optional) – If set to
False, will require column-wise order/by destination node order ofedge_index. (default:True)
- is_sorted_by_time() bool
Returns
Trueiftimeis sorted.
- is_undirected() bool
Returns
Trueif graph edges are undirected.
- keys() List[str]
Returns a list of all graph attribute names.
- multi_get_tensor(attrs: List[TensorAttr], convert_type: bool = False) List[Tensor | ndarray]
Synchronously obtains a list of tensors from the
FeatureStorefor each tensor associated with the attributes inattrs.Note
The default implementation simply iterates over all calls to
get_tensor(). Implementor classes that can provide additional, more performant functionality are recommended to to override this method.- Parameters:
attrs (List[TensorAttr]) – A list of input
TensorAttrobjects that identify the tensors to obtain.convert_type (bool, optional) – Whether to convert the type of the output tensor to the type of the attribute index. (default:
False)
- Raises:
ValueError – If any input
TensorAttris not fully specified.
- node_attrs() List[str]
Returns all node-level tensor attribute names.
- property num_edge_features: int
Returns the number of features per edge in the graph.
- property num_edge_types: int
Returns the number of edge types in the graph.
- property num_edges: int
Returns the number of edges in the graph. For undirected graphs, this will return the number of bi-directional edges, which is double the amount of unique edges.
- property num_faces: int | None
Returns the number of faces in the mesh.
- property num_features: int
Returns the number of features per node in the graph. Alias for
num_node_features.
- property num_node_features: int
Returns the number of features per node in the graph.
- property num_node_types: int
Returns the number of node types in the graph.
- property num_nodes: int | None
Returns the number of nodes in the graph.
Note
The number of nodes in the data object is automatically inferred in case node-level attributes are present, e.g.,
data.x. In some cases, however, a graph may only be given without any node-level attributes. :pyg:`PyG` then guesses the number of nodes according toedge_index.max().item() + 1. However, in case there exists isolated nodes, this number does not have to be correct which can result in unexpected behavior. Thus, we recommend to set the number of nodes in your data object explicitly viadata.num_nodes = .... You will be given a warning that requests you to do so.
- pin_memory(*args: str)
Copies attributes to pinned memory, either for all attributes or only the ones given in
*args.
- put_edge_index(edge_index: Tuple[Tensor, Tensor], *args, **kwargs) bool
Synchronously adds an
edge_indextuple to theGraphStore. Returns whether insertion was successful.- Parameters:
edge_index (Tuple[torch.Tensor, torch.Tensor]) – The
edge_indextuple in a format specified inEdgeAttr.*args – Arguments passed to
EdgeAttr.**kwargs – Keyword arguments passed to
EdgeAttr.
- put_tensor(tensor: Tensor | ndarray, *args, **kwargs) bool
Synchronously adds a
tensorto theFeatureStore. Returns whether insertion was successful.- Parameters:
tensor (torch.Tensor or np.ndarray) – The feature tensor to be added.
*args – Arguments passed to
TensorAttr.**kwargs – Keyword arguments passed to
TensorAttr.
- Raises:
ValueError – If the input
TensorAttris not fully specified.
- record_stream(stream: Stream, *args: str)
Ensures that the tensor memory is not reused for another tensor until all current work queued on
streamhas been completed, either for all attributes or only the ones given in*args.
- remove_edge_index(*args, **kwargs) bool
Synchronously deletes an
edge_indextuple from theGraphStore. Returns whether deletion was successful.- Parameters:
*args – Arguments passed to
EdgeAttr.**kwargs – Keyword arguments passed to
EdgeAttr.
- remove_tensor(*args, **kwargs) bool
Removes a tensor from the
FeatureStore. Returns whether deletion was successful.- Parameters:
*args – Arguments passed to
TensorAttr.**kwargs – Keyword arguments passed to
TensorAttr.
- Raises:
ValueError – If the input
TensorAttris not fully specified.
- requires_grad_(*args: str, requires_grad: bool = True)
Tracks gradient computation, either for all attributes or only the ones given in
*args.
Moves attributes to shared memory, either for all attributes or only the ones given in
*args.
- size(dim: int | None = None) Tuple[int | None, int | None] | int | None
Returns the size of the adjacency matrix induced by the graph.
- snapshot(start_time: float | int, end_time: float | int, attr: str = 'time') Self
Returns a snapshot of
datato only hold events that occurred in period[start_time, end_time].
- sort(sort_by_row: bool = True) Self
Sorts edge indices
edge_indexand their corresponding edge features.- Parameters:
sort_by_row (bool, optional) – If set to
False, will sortedge_indexin column-wise order/by destination node. (default:True)
- sort_by_time() Self
Sorts data associated with
timeaccording totime.
- subgraph(subset: Tensor) Self
Returns the induced subgraph given by the node indices
subset.- Parameters:
subset (LongTensor or BoolTensor) – The nodes to keep.
- to(device: int | str, *args: str, non_blocking: bool = False)
Performs tensor device conversion, either for all attributes or only the ones given in
*args.
- to_dict() Dict[str, Any]
Returns a dictionary of stored key/value pairs.
- to_heterogeneous(node_type: Tensor | None = None, edge_type: Tensor | None = None, node_type_names: List[str] | None = None, edge_type_names: List[Tuple[str, str, str]] | None = None)
Converts a
Dataobject to a heterogeneousHeteroDataobject. For this, node and edge attributes are splitted according to the node-level and edge-level vectorsnode_typeandedge_type, respectively.node_type_namesandedge_type_namescan be used to give meaningful node and edge type names, respectively. That is, the node_type0is given bynode_type_names[0]. If theDataobject was constructed viato_homogeneous(), the object can be reconstructed without any need to pass in additional arguments.- Parameters:
node_type (torch.Tensor, optional) – A node-level vector denoting the type of each node. (default:
None)edge_type (torch.Tensor, optional) – An edge-level vector denoting the type of each edge. (default:
None)node_type_names (List[str], optional) – The names of node types. (default:
None)edge_type_names (List[Tuple[str, str, str]], optional) – The names of edge types. (default:
None)
- to_namedtuple() NamedTuple
Returns a
NamedTupleof stored key/value pairs.
- up_to(end_time: float | int) Self
Returns a snapshot of
datato only hold events that occurred up toend_time(inclusive ofedge_time).
- update(data: Self | Dict[str, Any]) Self
Updates the data object with the elements from another data object. Added elements will override existing ones (in case of duplicates).
- update_tensor(tensor: Tensor | ndarray, *args, **kwargs) bool
Updates a
tensorin theFeatureStorewith a new value. Returns whether the update was succesful.Note
Implementor classes can choose to define more efficient update methods; the default performs a removal and insertion.
- Parameters:
tensor (torch.Tensor or np.ndarray) – The feature tensor to be updated.
*args – Arguments passed to
TensorAttr.**kwargs – Keyword arguments passed to
TensorAttr.
- validate(raise_on_error: bool = True) bool
Validates the correctness of the data.
- view(*args, **kwargs) AttrView
Returns a view of the
FeatureStoregiven a not yet fully-specifiedTensorAttr.