Bulk Operations
Bulk and structural graph operations live in annnet.core._Ops.
Use G.ops for graph-owned copy, extraction, reversal, memory, and incidence
helpers. Direct imports from underscore modules follow the
internal API policy.
annnet.core._Ops.Operations
Topology materialization and graph-copy operations (mixed into AnnNet).
Functions
edge_subgraph
Create a subgraph containing only a specified subset of edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edges
|
Iterable[str] | Iterable[int]
|
Edge identifiers or edge indices to retain. |
required |
Returns:
| Type | Description |
|---|---|
AnnNet
|
Subgraph containing selected edges and their incident nodes. |
Notes
Hyperedges are supported and retain all member nodes.
subgraph
Create a node-induced subgraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
Iterable[str]
|
Node identifiers to retain. |
required |
Returns:
| Type | Description |
|---|---|
AnnNet
|
Subgraph containing only the specified nodes and their internal edges. |
Notes
For hyperedges, all member nodes must be included to retain the edge.
extract_subgraph
Create a subgraph based on node and/or edge filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
Iterable[str] | None
|
Node IDs to include. If None, no node filtering is applied. |
None
|
edges
|
Iterable[str] | Iterable[int] | None
|
Edge IDs or indices to include. If None, no edge filtering is applied. |
None
|
Returns:
| Type | Description |
|---|---|
AnnNet
|
Filtered subgraph. |
Notes
This is a convenience method that delegates to subgraph() and
edge_subgraph() internally.
merge
Take every element of other that this graph does not hold.
This is the in-place union, and it is what G |= H runs. The graph on
the left is the answer wherever the two disagree: an element both graphs
hold keeps the attributes it has here, and only an element this graph
does not hold arrives with the attributes of other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
AnnNet
|
The graph to take from. It is not changed. |
required |
Returns:
| Type | Description |
|---|---|
AnnNet
|
This graph. |
union
Return a graph holding every element of this graph and of other.
Where the two disagree about one element, this graph is the answer. See
:meth:merge, which is the same operation without the copy.
intersection
Return a graph holding the elements that both graphs hold.
An edge survives only when every node it names does, so an edge both graphs hold is dropped when one of its endpoints is not shared.
difference
Return a graph holding the elements other does not hold.
An edge survives only when every node it names does, so an edge that keeps its own id loses its place when an endpoint goes.
symmetric_difference
Return a graph holding the elements exactly one of the two holds.
reverse
Return a new graph with all directed edges reversed.
Returns:
| Type | Description |
|---|---|
AnnNet
|
A new |
Behavior
- Binary edges: direction is flipped by swapping source and target.
- Directed hyperedges:
headandtailsets are swapped. - Undirected edges/hyperedges: unaffected.
- Edge attributes and metadata are preserved.
Notes
- This operation does not modify the original graph.
- If the graph is undirected (
self.directed == False), the result is identical to the original. - For mixed graphs (directed + undirected edges), only the directed ones are reversed.
subgraph_from_slice
Create a subgraph induced by a single slice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slice_id
|
str
|
Slice identifier. |
required |
resolve_slice_weights
|
bool
|
If True, use per-slice edge weights when available. |
True
|
Returns:
| Type | Description |
|---|---|
AnnNet
|
Subgraph containing the slice nodes and edges. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the slice does not exist. |
copy
Deep copy of the entire AnnNet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
history
|
bool
|
If True, copy the mutation history and snapshot timeline. If False, the new graph starts with a clean history. |
False
|
Returns:
| Type | Description |
|---|---|
AnnNet
|
A new graph with full structural and attribute fidelity. |
Notes
O(N) Python, O(nnz) matrix; this path is optimized for speed.
memory_usage
Approximate total memory usage in bytes.
Returns:
| Type | Description |
|---|---|
int
|
Estimated bytes for the incidence matrix, dictionaries, and attribute DFs. |
get_node_incidence_matrix_as_lists
Materialize the node–edge incidence structure as Python lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
(bool, optional(default=False))
|
|
False
|
Returns:
| Type | Description |
|---|---|
dict[str, list]
|
A mapping from |
Notes
- Internally uses the sparse incidence matrix
self._matrix, which is stored as a SciPy CSR (compressed sparse row) matrix or similar. - The incidence matrix
Mis defined as:- Rows: nodes
- Columns: edges
- Entry
M[i, j]non-zero ⇨ nodeiis incident to edgej.
- This is a convenient method when you want a native-Python structure for downstream use (e.g., exporting, iterating, or visualization).
node_incidence_matrix
Return the node–edge incidence matrix in sparse or dense form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
(bool, optional(default=False))
|
If |
False
|
sparse
|
(bool, optional(default=False))
|
|
False
|
Returns:
| Type | Description |
|---|---|
csr_matrix | ndarray
|
The node–edge incidence matrix |
Notes
- If
values=False, the returned matrix is binarized before returning. - Use
sparse=Truefor large graphs to avoid memory blowups. - This is the canonical low-level structure that most algorithms (e.g., spectral clustering, Laplacian construction, hypergraph analytics) rely on.