unienv_interface.space.spaces.graph¶
GraphInstance
dataclass
¶
GraphInstance(n_nodes: BArrayType, n_edges: Optional[BArrayType] = None, nodes_features: Optional[BArrayType] = None, edges_features: Optional[BArrayType] = None, edges: Optional[BArrayType] = None)
Bases: Generic[BArrayType]
n_edges
class-attribute
instance-attribute
¶
n_edges: Optional[BArrayType] = None
Number of edges in the graph, shape (*batch_shape) or None if no edges are present.
nodes_features
class-attribute
instance-attribute
¶
nodes_features: Optional[BArrayType] = None
Node features, shape (batch_shape, max(n_nodes), node_feature_space.shape) if node_feature_space is not None, otherwise None.
edges_features
class-attribute
instance-attribute
¶
edges_features: Optional[BArrayType] = None
Edge features, shape (batch_shape, max(n_edges), edge_feature_space.shape) if edge_feature_space is not None, otherwise None.
edges
class-attribute
instance-attribute
¶
edges: Optional[BArrayType] = None
Edges in the graph, shape (*batch_shape, max(n_edges), 2) where each edge is represented by a pair of node indices, or None if no edges are present.
GraphSpace
¶
GraphSpace(backend: ComputeBackend[BArrayType, BDeviceType, BDtypeType, BRNGType], node_feature_space: Optional[BoxSpace[BArrayType, BDeviceType, BDtypeType, BRNGType]], edge_feature_space: Optional[BoxSpace[BArrayType, BDeviceType, BDtypeType, BRNGType]] = None, is_edge: bool = False, min_nodes: int = 1, max_nodes: Optional[int] = None, min_edges: int = 1, max_edges: Optional[int] = None, batch_shape: Sequence[int] = (), device: Optional[BDeviceType] = None)
Bases: Space[GraphInstance[BArrayType], BDeviceType, BDtypeType, BRNGType], Generic[BArrayType, BDeviceType, BDtypeType, BRNGType]
node_feature_space
instance-attribute
¶
node_feature_space = node_feature_space if (device is None or node_feature_space is None) else to(device=device)
edge_feature_space
instance-attribute
¶
edge_feature_space = edge_feature_space if (device is None or edge_feature_space is None) else to(device=device)
shape
property
¶
shape: tuple[int, ...] | None
Return the shape of the space as an immutable property.
to
¶
to(backend: Optional[ComputeBackend] = None, device: Optional[Union[BDeviceType, Any]] = None) -> Union[GraphSpace[BArrayType, BDeviceType, BDtypeType, BRNGType], GraphSpace]
contains
¶
contains(x: GraphInstance[BArrayType]) -> bool
Return boolean specifying if x is a valid member of this space.
get_repr
¶
get_repr(abbreviate=False, include_backend=True, include_device=True, include_dtype=True)
abbr_device
staticmethod
¶
abbr_device(spaces: Iterable[Space[Any, _SpaceBDeviceT, _SpaceBDTypeT, _SpaceBDRNGT]]) -> Optional[_SpaceBDeviceT]
Return the shared device across spaces, or None if mixed/empty.