RustworkxAdapter

RustworkxAdapter()

Default adapter for OmkGraph.

Implementation note: This adapter uses Rustworkx’s PyDiGraph as the underlying graph structure. OmkObjects and OmkEdges are registered by the string form of their id with their Rustworkx integer ids in bidirectional indices. OmkGraph users supply OmkObjects and OmkEdges (usually directly, but in some cases by their id), and the adapter handles the conversion to Rustworkx integer ids internally. (Users should not need to interact with Rustworkx integer ids directly.)

OmkObjects and OmkEdges are the payload for PyDiGraph’s nodes and edges, respectively.

Attributes

Name Description
graph

Methods

Name Description
__init__
add_node Add a node to the graph.
add_edge Add an edge from source to target to the graph.
remove_node Remove a node (and its incident edges) from the graph.
remove_edge Remove an edge from the graph.
get_node Return the node with the given id, or None if there is no such node.
get_edge Return the edge of the given type from source to target; raises GraphError if there is none.
filter_edges Returns a list of all edges for which filter_function(edge) returns True.
filter_nodes Returns a list of all nodes for which filter_function(node) returns True.
get_edge_endpoints Return the source and target nodes of the given edge as a tuple (source, target).
get_source_of_edge Return the source node of the given edge.
get_target_of_edge Return the target node of the given edge.
has_node Return True if node is present in the graph.
has_edge Return True if an edge (optionally of the given type) exists from source to target.
num_nodes Return the total number of nodes in the graph.
num_edges Return the total number of edges in the graph.
nodes Iterate over nodes, optionally filtered by node_type and/or predicate.
edges Iterate over edges, optionally filtered by edge_type and/or predicate.
edges_between Iterate over edges from source to target, optionally filtered by edge_type.
successors Iterate over nodes reachable from node via an outgoing edge, optionally filtered.
predecessors Iterate over nodes that have an outgoing edge to node, optionally filtered.
get_next Return the next node connected by an edge of type NEXT from the given node, if it exists.
get_previous Return the previous node connected by an edge of type NEXT to the given node, if it exists.
neighbors Iterate over all nodes adjacent to node (predecessors and successors), optionally filtered.
out_edges Iterate over edges originating from node, optionally filtered by edge_type.
in_edges Iterate over edges terminating at node, optionally filtered by edge_type.
incident_edges Iterate over all edges touching node (incoming and outgoing), optionally filtered by edge_type.
degree Return the total number of edges incident to node.
in_degree Return the number of edges terminating at node.
out_degree Return the number of edges originating from node.

__init__

__init__()

add_node

add_node(node: OmkObject)

Add a node to the graph.

Does nothing if the node (by id) is already present.

add_edge

add_edge(source: OmkObject, target: OmkObject, edge: OmkEdge)

Add an edge from source to target to the graph.

Raises an exception if there is already an edge of the same type between source and target. Raises an exception if edge_type is NEXT and source already has an outgoing edge of type NEXT, or target already has an incoming one (a line is a chain: one NEXT in, one NEXT out).

remove_node

remove_node(node: OmkObject)

Remove a node (and its incident edges) from the graph.

Raises an exception if the node does not exist.

remove_edge

remove_edge(edge: OmkEdge)

Remove an edge from the graph.

get_node

get_node(node_id: UUID | str)

Return the node with the given id, or None if there is no such node.

get_edge

get_edge(source: OmkObject, target: OmkObject, edge_type: EdgeType)

Return the edge of the given type from source to target; raises GraphError if there is none.

filter_edges

filter_edges(filter_function: Callable[[OmkEdge], bool])

Returns a list of all edges for which filter_function(edge) returns True.

filter_nodes

filter_nodes(filter_function: Callable[[OmkObject], bool])

Returns a list of all nodes for which filter_function(node) returns True.

get_edge_endpoints

get_edge_endpoints(edge: OmkEdge)

Return the source and target nodes of the given edge as a tuple (source, target).

get_source_of_edge

get_source_of_edge(edge: OmkEdge)

Return the source node of the given edge.

get_target_of_edge

get_target_of_edge(edge: OmkEdge)

Return the target node of the given edge.

has_node

has_node(node: OmkObject)

Return True if node is present in the graph.

has_edge

has_edge(
    source: OmkObject,
    target: OmkObject,
    edge_type: EdgeType | None = None,
)

Return True if an edge (optionally of the given type) exists from source to target.

num_nodes

num_nodes()

Return the total number of nodes in the graph.

num_edges

num_edges()

Return the total number of edges in the graph.

nodes

nodes(
    node_type: type[OmkObject] | None = None,
    predicate: Callable[[OmkObject], bool] | None = None,
)

Iterate over nodes, optionally filtered by node_type and/or predicate.

edges

edges(
    edge_type: EdgeType | None = None,
    predicate: Callable[[OmkEdge], bool] | None = None,
)

Iterate over edges, optionally filtered by edge_type and/or predicate.

edges_between

edges_between(
    source: OmkObject,
    target: OmkObject,
    edge_type: EdgeType | None = None,
)

Iterate over edges from source to target, optionally filtered by edge_type.

successors

successors(
    node: OmkObject,
    node_type: type[OmkObject] | None = None,
    edge_type: EdgeType | None = None,
    predicate: Callable[[OmkObject], bool] | None = None,
)

Iterate over nodes reachable from node via an outgoing edge, optionally filtered.

predecessors

predecessors(
    node: OmkObject,
    node_type: type[OmkObject] | None = None,
    edge_type: EdgeType | None = None,
    predicate: Callable[[OmkObject], bool] | None = None,
)

Iterate over nodes that have an outgoing edge to node, optionally filtered.

get_next

get_next(node: OmkObject)

Return the next node connected by an edge of type NEXT from the given node, if it exists.

get_previous

get_previous(node: OmkObject)

Return the previous node connected by an edge of type NEXT to the given node, if it exists.

neighbors

neighbors(
    node: OmkObject,
    node_type: type[OmkObject] | None = None,
    edge_type: EdgeType | None = None,
    predicate: Callable[[OmkObject], bool] | None = None,
)

Iterate over all nodes adjacent to node (predecessors and successors), optionally filtered.

out_edges

out_edges(node: OmkObject, edge_type: EdgeType | None = None)

Iterate over edges originating from node, optionally filtered by edge_type.

in_edges

in_edges(node: OmkObject, edge_type: EdgeType | None = None)

Iterate over edges terminating at node, optionally filtered by edge_type.

incident_edges

incident_edges(node: OmkObject, edge_type: EdgeType | None = None)

Iterate over all edges touching node (incoming and outgoing), optionally filtered by edge_type.

degree

degree(node: OmkObject)

Return the total number of edges incident to node.

in_degree

in_degree(node: OmkObject)

Return the number of edges terminating at node.

out_degree

out_degree(node: OmkObject)

Return the number of edges originating from node.