agenticraft_foundation.topology.laplacian¶
Laplacian matrix analysis — spectral decomposition, algebraic connectivity (\(\lambda_2\)), and consensus convergence bounds.
Graph Laplacian analysis for network topology optimization.
This module provides spectral analysis tools for understanding and optimizing distributed system topologies based on graph-theoretic principles.
Key concepts: - Algebraic Connectivity (λ₂): Second smallest eigenvalue of Laplacian - Fiedler Vector: Eigenvector corresponding to λ₂ - Consensus Convergence: T = O(n log n / λ₂)
References: - Fiedler, M. (1973). Algebraic connectivity of graphs. - Olfati-Saber, R. (2006). Flocking for multi-agent dynamic systems.
TopologyType
¶
Bases: str, Enum
Common network topology types.
Node
dataclass
¶
A node in the network graph.
| ATTRIBUTE | DESCRIPTION |
|---|---|
id |
Unique identifier
TYPE:
|
neighbors |
Set of neighbor node IDs
TYPE:
|
weight |
Optional weight for weighted graphs
TYPE:
|
metadata |
Additional node metadata
TYPE:
|
Edge
dataclass
¶
An edge in the network graph.
| ATTRIBUTE | DESCRIPTION |
|---|---|
source |
Source node ID
TYPE:
|
target |
Target node ID
TYPE:
|
weight |
Edge weight (default 1.0)
TYPE:
|
LaplacianAnalysis
dataclass
¶
Results of Laplacian spectral analysis.
| ATTRIBUTE | DESCRIPTION |
|---|---|
num_nodes |
Number of nodes in the graph
TYPE:
|
num_edges |
Number of edges in the graph
TYPE:
|
algebraic_connectivity |
Second smallest eigenvalue (λ₂)
TYPE:
|
spectral_gap |
Gap between λ₁ and λ₂
TYPE:
|
fiedler_vector |
Eigenvector for λ₂ (maps node ID to value)
TYPE:
|
eigenvalues |
All eigenvalues in ascending order
TYPE:
|
consensus_bound |
Upper bound on consensus convergence time
TYPE:
|
diameter_estimate |
Estimated graph diameter from spectral properties
TYPE:
|
bottleneck_edges |
Edges with high Fiedler values (potential bottlenecks)
TYPE:
|
suggested_edges |
Suggested edges to add for improved connectivity
TYPE:
|
is_connected |
Whether the graph is connected
TYPE:
|
summary()
¶
Generate human-readable summary.
NetworkGraph
¶
Network graph for topology analysis.
Provides methods for building and analyzing network topologies using graph Laplacian spectral analysis.
node_count
property
¶
Number of nodes.
edge_count
property
¶
Number of edges.
__init__()
¶
Initialize empty graph.
add_node(node_id, weight=1.0, **metadata)
¶
Add a node to the graph.
| PARAMETER | DESCRIPTION |
|---|---|
node_id
|
Unique node identifier
TYPE:
|
weight
|
Node weight
TYPE:
|
**metadata
|
Additional metadata
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Node
|
The created Node |
add_edge(source, target, weight=1.0, bidirectional=True)
¶
Add an edge to the graph.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
Source node ID
TYPE:
|
target
|
Target node ID
TYPE:
|
weight
|
Edge weight
TYPE:
|
bidirectional
|
If True, add edge in both directions
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Edge
|
The created Edge |
remove_node(node_id)
¶
Remove a node and all its edges.
| PARAMETER | DESCRIPTION |
|---|---|
node_id
|
Node to remove
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if node was removed |
get_node(node_id)
¶
Get a node by ID.
get_nodes()
¶
Get all nodes.
get_edges()
¶
Get all edges.
analyze()
¶
Perform spectral analysis on the graph.
| RETURNS | DESCRIPTION |
|---|---|
LaplacianAnalysis
|
LaplacianAnalysis with spectral properties |
create_ring(n, node_prefix='node')
classmethod
¶
Create a ring topology.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of nodes
TYPE:
|
node_prefix
|
Prefix for node IDs
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NetworkGraph
|
NetworkGraph with ring topology |
create_complete(n, node_prefix='node')
classmethod
¶
Create a complete (fully connected) topology.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of nodes
TYPE:
|
node_prefix
|
Prefix for node IDs
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NetworkGraph
|
NetworkGraph with complete topology |
create_star(n, node_prefix='node')
classmethod
¶
Create a star topology.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of nodes (including center)
TYPE:
|
node_prefix
|
Prefix for node IDs
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NetworkGraph
|
NetworkGraph with star topology |
create_mesh(rows, cols, node_prefix='node')
classmethod
¶
Create a 2D mesh/grid topology.
| PARAMETER | DESCRIPTION |
|---|---|
rows
|
Number of rows
TYPE:
|
cols
|
Number of columns
TYPE:
|
node_prefix
|
Prefix for node IDs
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NetworkGraph
|
NetworkGraph with mesh topology |
analyze_consensus_time(graph, epsilon=0.01)
¶
Estimate consensus convergence time.
For linear consensus protocols, convergence time is bounded by: T = O(log(1/ε) / λ₂)
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
Network graph to analyze
TYPE:
|
epsilon
|
Convergence tolerance
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Estimated convergence time |
compare_topologies(topologies)
¶
Compare multiple network topologies.
| PARAMETER | DESCRIPTION |
|---|---|
topologies
|
Dictionary mapping topology name to graph
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, LaplacianAnalysis]
|
Dictionary mapping topology name to analysis |
optimal_topology_for_consensus(n, max_edges=None)
¶
Find optimal topology for consensus with edge budget.
If unconstrained, complete graph is optimal (λ₂ = n). With edge constraints, we optimize for maximum λ₂.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of nodes
TYPE:
|
max_edges
|
Maximum number of edges (None = unconstrained)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[NetworkGraph, LaplacianAnalysis]
|
Tuple of (optimal graph, analysis) |