On this page

Graph

linnet_py Class

Graph(*, name: Optional[str] = None, global_data: Optional[GlobalData] = None, codec: Optional[DotCodec] = None, render_config: RenderConfig | None = None, node_store: NodeStore = NodeStore.Vec)

An owned topology with arbitrary element data and typed rendering configuration.

Constructor

#

Parameters

NameTypeDefaultDescription
nameOptional[str]None—
global_dataOptional[GlobalData]None—
codecOptional[DotCodec]None—
render_configRenderConfig | NoneNone—
node_storeNodeStoreNodeStore.Vec—

Member details

name

Property · read-only
#
name: Optional[str]

No description is available for this member.

global_data

Property · read/write
## setter
global_data: GlobalData

No description is available for this member.

Setter

global_data: GlobalData
Parameters
NameTypeDefaultDescription
valueGlobalData——

render_config

Property · read/write
## setter
render_config: RenderConfig

No description is available for this member.

Setter

render_config: RenderConfig
Parameters
NameTypeDefaultDescription
valueRenderConfig——

n_nodes

Property · read-only
#
n_nodes: int

No description is available for this member.

n_edges

Property · read-only
#
n_edges: int

No description is available for this member.

n_half_edges

Property · read-only
#
n_half_edges: int

No description is available for this member.

node_store

Property · read-only
#
node_store: NodeStore

Return the node-storage strategy used by this graph.

__len__

Method
#
__len__() -> int

No description is available for this member.

to_node_store

Method
#
to_node_store(node_store: NodeStore) -> Graph

Copy this graph into another node-storage strategy.

Parameters

NameTypeDefaultDescription
node_storeNodeStore——

node

Method
#
node(key: int | str) -> Node

No description is available for this member.

Parameters

NameTypeDefaultDescription
keyint | str——

edge

Method
#
edge(key: int | str) -> Edge

No description is available for this member.

Parameters

NameTypeDefaultDescription
keyint | str——

half_edge

Method
#
half_edge(index: int) -> HalfEdge

No description is available for this member.

Parameters

NameTypeDefaultDescription
indexint——

nodes

Method
#
nodes() -> list[Node]

No description is available for this member.

edges

Method
#
edges() -> list[Edge]

No description is available for this member.

half_edges

Method
#
half_edges() -> list[HalfEdge]

No description is available for this member.

reorder_nodes

Method
#
reorder_nodes(order: Sequence[int]) -> None

No description is available for this member.

Parameters

NameTypeDefaultDescription
orderSequence[int]——

reorder_edges

Method
#
reorder_edges(order: Sequence[int]) -> None

No description is available for this member.

Parameters

NameTypeDefaultDescription
orderSequence[int]——

reverse_edge

Method
#
reverse_edge(key: int | str) -> None

No description is available for this member.

Parameters

NameTypeDefaultDescription
keyint | str——

map

Method
#
map(*, node: Callable[[Node], Any] | None = None, edge: Callable[[Edge], Any] | None = None, source: Callable[[HalfEdge], Any] | None = None, sink: Callable[[HalfEdge], Any] | None = None) -> Graph

No description is available for this member.

Parameters

NameTypeDefaultDescription
nodeCallable[[Node], Any] | NoneNone—
edgeCallable[[Edge], Any] | NoneNone—
sourceCallable[[HalfEdge], Any] | NoneNone—
sinkCallable[[HalfEdge], Any] | NoneNone—

from_dot

Class method
#
from_dot(source: str, codec: DotCodec, *, node_store: NodeStore = NodeStore.Vec) -> Graph

No description is available for this member.

Parameters

NameTypeDefaultDescription
sourcestr——
codecDotCodec——
node_storeNodeStoreNodeStore.Vec—

from_dot_set

Class method
#
from_dot_set(source: str, codec: DotCodec, *, node_store: NodeStore = NodeStore.Vec) -> list[Graph]

No description is available for this member.

Parameters

NameTypeDefaultDescription
sourcestr——
codecDotCodec——
node_storeNodeStoreNodeStore.Vec—

from_dot_file

Class method
#
from_dot_file(path: str | os.PathLike[str], codec: DotCodec, *, node_store: NodeStore = NodeStore.Vec) -> Graph

No description is available for this member.

Parameters

NameTypeDefaultDescription
pathstr | os.PathLike[str]——
codecDotCodec——
node_storeNodeStoreNodeStore.Vec—

to_dot

Method
#
to_dot(codec: Optional[DotCodec] = None) -> str

No description is available for this member.

Parameters

NameTypeDefaultDescription
codecOptional[DotCodec]None—

prepare_render

Method
#
prepare_render(*, config: RenderConfig | None = None) -> PreparedRender

Stage one render so its exact Typst source and compiled output stay correlated.

Parameters

NameTypeDefaultDescription
configRenderConfig | NoneNone—

render

Method
#
render(output: str | os.PathLike[str], *, config: RenderConfig | None = None) -> pathlib.Path

No description is available for this member.

Parameters

NameTypeDefaultDescription
outputstr | os.PathLike[str]——
configRenderConfig | NoneNone—

to_svg

Method
#
to_svg(*, config: RenderConfig | None = None) -> str

No description is available for this member.

Parameters

NameTypeDefaultDescription
configRenderConfig | NoneNone—

_repr_svg_

Method
#
_repr_svg_() -> str

No description is available for this member.

full_subgraph

Method
#
full_subgraph() -> Subgraph

No description is available for this member.

empty_subgraph

Method
#
empty_subgraph() -> Subgraph

No description is available for this member.

subgraph

Method
#
subgraph(*, nodes: Sequence[int | str] = ..., edges: Sequence[int | str] = ..., half_edges: Sequence[int] = ...) -> Subgraph

No description is available for this member.

Parameters

NameTypeDefaultDescription
nodesSequence[int | str]runtime default—
edgesSequence[int | str]runtime default—
half_edgesSequence[int]runtime default—

filter

Method
#
filter(*, node: Callable[[Node], bool] | None = None, edge: Callable[[Edge], bool] | None = None, half_edge: Callable[[HalfEdge], bool] | None = None) -> Subgraph

No description is available for this member.

Parameters

NameTypeDefaultDescription
nodeCallable[[Node], bool] | NoneNone—
edgeCallable[[Edge], bool] | NoneNone—
half_edgeCallable[[HalfEdge], bool] | NoneNone—

nodes_of

Method
#
nodes_of(subgraph: Subgraph) -> list[Node]

No description is available for this member.

Parameters

NameTypeDefaultDescription
subgraphSubgraph——

edges_of

Method
#
edges_of(subgraph: Subgraph) -> list[Edge]

No description is available for this member.

Parameters

NameTypeDefaultDescription
subgraphSubgraph——

half_edges_of

Method
#
half_edges_of(subgraph: Subgraph) -> list[HalfEdge]

No description is available for this member.

Parameters

NameTypeDefaultDescription
subgraphSubgraph——

internal_boundary

Method
#
internal_boundary(subgraph: Subgraph) -> Subgraph

Return selected half-edges that lie on the selection's internal boundary.

Parameters

NameTypeDefaultDescription
subgraphSubgraph——

boundary

Method
#
boundary(subgraph: Subgraph) -> Subgraph

Return all boundary half-edges incident to nodes touched by the selection.

Parameters

NameTypeDefaultDescription
subgraphSubgraph——

external_half_edges

Method
#
external_half_edges() -> Subgraph

Return dangling/external half-edges as a composable structural selection.

connected_components

Method
#
connected_components(subgraph: Optional[Subgraph] = None) -> list[Subgraph]

No description is available for this member.

Parameters

NameTypeDefaultDescription
subgraphOptional[Subgraph]None—

count_connected_components

Method
#
count_connected_components(subgraph: Optional[Subgraph] = None) -> int

No description is available for this member.

Parameters

NameTypeDefaultDescription
subgraphOptional[Subgraph]None—

is_connected

Method
#
is_connected(subgraph: Optional[Subgraph] = None) -> bool

No description is available for this member.

Parameters

NameTypeDefaultDescription
subgraphOptional[Subgraph]None—

cyclomatic_number

Method
#
cyclomatic_number(subgraph: Optional[Subgraph] = None) -> int

No description is available for this member.

Parameters

NameTypeDefaultDescription
subgraphOptional[Subgraph]None—

is_reachable

Method
#
is_reachable(source: Node | int | str, target: Node | int | str, *, subgraph: Optional[Subgraph] = None, direction: DirectionBasis = DirectionBasis.Underlying) -> bool

Test directed reachability within an optional structural selection.

Both endpoints must belong to the selected subgraph; otherwise this raises ValueError.

Parameters

NameTypeDefaultDescription
sourceNode | int | str——
targetNode | int | str——
subgraphOptional[Subgraph]None—
directionDirectionBasisDirectionBasis.Underlying—

topological_order

Method
#
topological_order(*, subgraph: Optional[Subgraph] = None, direction: DirectionBasis = DirectionBasis.Underlying) -> list[Node]

Return a deterministic topological order for the selected directed graph.

Explicitly selected zero-crown nodes appear first in ascending graph order.

Parameters

NameTypeDefaultDescription
subgraphOptional[Subgraph]None—
directionDirectionBasisDirectionBasis.Underlying—

transitive_reduction

Method
#
transitive_reduction(*, direction: DirectionBasis = DirectionBasis.Underlying) -> Graph

Return a new graph with directionally redundant DAG edges removed.

Parameters

NameTypeDefaultDescription
directionDirectionBasisDirectionBasis.Underlying—

depth_first_traverse

Method
#
depth_first_traverse(root: int | str, *, subgraph: Optional[Subgraph] = None, include: Optional[int] = None) -> TraversalTree

No description is available for this member.

Parameters

NameTypeDefaultDescription
rootint | str——
subgraphOptional[Subgraph]None—
includeOptional[int]None—

breadth_first_traverse

Method
#
breadth_first_traverse(root: int | str, *, subgraph: Optional[Subgraph] = None, include: Optional[int] = None) -> TraversalTree

No description is available for this member.

Parameters

NameTypeDefaultDescription
rootint | str——
subgraphOptional[Subgraph]None—
includeOptional[int]None—

bridges

Method
#
bridges(subgraph: Optional[Subgraph] = None) -> Subgraph

No description is available for this member.

Parameters

NameTypeDefaultDescription
subgraphOptional[Subgraph]None—

cycle_basis

Method
#
cycle_basis(subgraph: Optional[Subgraph] = None) -> tuple[list[Cycle], Subgraph]

No description is available for this member.

Parameters

NameTypeDefaultDescription
subgraphOptional[Subgraph]None—

all_spanning_forests

Method
#
all_spanning_forests(subgraph: Optional[Subgraph] = None) -> list[Subgraph]

No description is available for this member.

Parameters

NameTypeDefaultDescription
subgraphOptional[Subgraph]None—

all_bonds

Method
#
all_bonds(*, subgraph: Optional[Subgraph] = None, min_size: Optional[int] = None, max_size: Optional[int] = None) -> list[Subgraph]

Enumerate inclusion-minimal cutsets with an inclusive boundary-size range.

Bounds default to [1, unbounded]; min_size=0 is rejected because a bond is non-empty.

Parameters

NameTypeDefaultDescription
subgraphOptional[Subgraph]None—
min_sizeOptional[int]None—
max_sizeOptional[int]None—

find_bond

Method
#
find_bond(*, subgraph: Optional[Subgraph] = None, min_size: Optional[int] = None, max_size: Optional[int] = None) -> Optional[Subgraph]

Find one native inclusion-minimal cutset within an inclusive size range.

Parameters

NameTypeDefaultDescription
subgraphOptional[Subgraph]None—
min_sizeOptional[int]None—
max_sizeOptional[int]None—

all_cycles

Method
#
all_cycles(*, max_results: int, subgraph: Optional[Subgraph] = None) -> list[Cycle]

Enumerate circuits only when the complete cycle-space candidate count fits the bound.

max_results bounds all non-empty combinations of a cycle basis, not only the combinations that ultimately form circuits.

Parameters

NameTypeDefaultDescription
max_resultsint——
subgraphOptional[Subgraph]None—

tadpoles

Method
#
tadpoles(externals: Sequence[Node | int | str]) -> list[Subgraph]

Enumerate tadpole components after identifying a non-empty terminal node set.

Parameters

NameTypeDefaultDescription
externalsSequence[Node | int | str]——

all_cuts

Method
#
all_cuts(source: Sequence[int | str], target: Sequence[int | str]) -> list[CutPartition]

Enumerate all native separating partitions between two disjoint, non-empty node groups.

Parameters

NameTypeDefaultDescription
sourceSequence[int | str]——
targetSequence[int | str]——

add_node

Method
#
add_node(spec: NodeSpec) -> Node

Append one declarative node and return its fresh live view.

Parameters

NameTypeDefaultDescription
specNodeSpec——

add_edge

Method
#
add_edge(spec: EdgeSpec) -> Edge

Append one declarative internal or dangling edge and return its fresh live view.

Parameters

NameTypeDefaultDescription
specEdgeSpec——

split_edge

Method
#
split_edge(at: _HalfEdgeTarget, replacement: EdgeValue, *, name: Optional[str] = None, orientation: Orientation = Orientation.Default) -> tuple[Edge, Edge]

Split a paired edge at one half-edge, preserving the opposite edge value.

Parameters

NameTypeDefaultDescription
at_HalfEdgeTarget——
replacementEdgeValue——
nameOptional[str]None—
orientationOrientationOrientation.Default—

connect

Method
#
connect(source: _HalfEdgeTarget, sink: _HalfEdgeTarget, replacement: EdgeValue, *, name: Optional[str] = None, orientation: Orientation = Orientation.Default) -> Edge

Connect two dangling half-edges; the first becomes the source endpoint.

Parameters

NameTypeDefaultDescription
source_HalfEdgeTarget——
sink_HalfEdgeTarget——
replacementEdgeValue——
nameOptional[str]None—
orientationOrientationOrientation.Default—

concretize

Method
#
concretize(subgraph: Subgraph) -> Graph

Copy a structural subgraph into an independent graph.

Parameters

NameTypeDefaultDescription
subgraphSubgraph——

extract

Method
#
extract(subgraph: Subgraph) -> Graph

Remove a structural subgraph and return it as an independent graph.

Parameters

NameTypeDefaultDescription
subgraphSubgraph——

delete

Method
#
delete(subgraph: Subgraph) -> None

Delete a structural subgraph.

Parameters

NameTypeDefaultDescription
subgraphSubgraph——

contract

Method
#
contract(subgraph: Subgraph, replacement: NodeValue, *, name: Optional[str] = None) -> None

Contract a non-empty subgraph into one replacement node.

Parameters

NameTypeDefaultDescription
subgraphSubgraph——
replacementNodeValue——
nameOptional[str]None—

append

Method
#
append(other: Graph) -> Graph

Append another graph without matching dangling half-edges.

Parameters

NameTypeDefaultDescription
otherGraph——

append_mut

Method
#
append_mut(other: Graph) -> None

Append another graph in place without matching dangling half-edges.

Parameters

NameTypeDefaultDescription
otherGraph——

join

Method
#
join(other: Graph, *, matching: Callable[[HalfEdge, HalfEdge], bool], merge: Callable[[HalfEdge, HalfEdge], tuple[Flow, Orientation, str | None, EdgeValue]]) -> Graph

Join dangling half-edges selected by Python callbacks.

Parameters

NameTypeDefaultDescription
otherGraph——
matchingCallable[[HalfEdge, HalfEdge], bool]——
mergeCallable[[HalfEdge, HalfEdge], tuple[Flow, Orientation, str | None, EdgeValue]]——

join_mut

Method
#
join_mut(other: Graph, *, matching: Callable[[HalfEdge, HalfEdge], bool], merge: Callable[[HalfEdge, HalfEdge], tuple[Flow, Orientation, str | None, EdgeValue]]) -> None

Join another graph in place while leaving the other graph unchanged.

Parameters

NameTypeDefaultDescription
otherGraph——
matchingCallable[[HalfEdge, HalfEdge], bool]——
mergeCallable[[HalfEdge, HalfEdge], tuple[Flow, Orientation, str | None, EdgeValue]]——

__repr__

Method
#
__repr__() -> str

No description is available for this member.