Skip to content

Cellular Sheaves & Network Cohomology (algebrax.topology.sheaf)

A Cellular Sheaf \(\mathcal{F}\) over a 1-dimensional cell complex (graph) \(G = (V, E)\) generalizes scalar graph Laplacians to heterogeneous vector stalks with linear restriction maps. Every vertex \(v \in V\) is assigned a vector stalk \(\mathcal{F}(v) = \mathbb{R}^{d_v}\), every edge \(e \in E\) is assigned an edge stalk \(\mathcal{F}(e) = \mathbb{R}^{d_e}\), and each incident vertex-edge pair has a linear restriction map:

\[\rho_{v \trianglelefteq e}: \mathcal{F}(v) \to \mathcal{F}(e)\]

Sheaf Coboundary (\(\delta_{\mathcal{F}}\)) & Sheaf Laplacian (\(L_{\mathcal{F}}\))

  1. Sheaf Coboundary Operator (\(\delta_{\mathcal{F}}: C^0(G; \mathcal{F}) \to C^1(G; \mathcal{F})\)): Measures local disagreement across edge stalks: $\((\delta_{\mathcal{F}} x)_{e = (u, v)} = \rho_{v \trianglelefteq e} x_v - \rho_{u \trianglelefteq e} x_u\)$
  2. Sheaf Laplacian (\(L_{\mathcal{F}} = \delta_{\mathcal{F}}^\top \delta_{\mathcal{F}}\)) & Dirichlet Energy: A symmetric positive semi-definite linear operator indexed by product keys (vertex, dim_idx) whose quadratic form measures total network disagreement: $\(E_{\mathcal{F}}(x) = \frac{1}{2} \|\delta_{\mathcal{F}} x\|_2^2 = \frac{1}{2} \langle x, L_{\mathcal{F}} x \rangle \ge 0\)$

Sheaf Cohomology (\(H^0\), \(H^1\)) & Euler–Poincaré Characteristic

Both global_sections_dimension(tol=1e-9, field=None) and first_cohomology_dimension(tol=1e-9, field=None) delegate to algebrax.matrix.rank, honoring caller tol in floating-point regimes and supporting exact cohomology over any Field[V] (such as StandardField(Fraction) or ModularField(p)):

  • 0-th Sheaf Cohomology / Global Sections (global_sections_dimension): A 0-cochain \(x \in C^0(G; \mathcal{F})\) is a global section if neighbors agree across every edge (\(\delta_{\mathcal{F}} x = 0 \iff L_{\mathcal{F}} x = 0\)): $\(\dim H^0(G; \mathcal{F}) = \dim \ker \delta_{\mathcal{F}} = \sum_{v \in V} d_v - \operatorname{rank}(\delta_{\mathcal{F}})\)$
  • 1-st Sheaf Cohomology / Obstructions (first_cohomology_dimension): Measures the dimension of edge-stalk obstructions (holonomy / frustration) that cannot be realized as coboundaries of 0-cochains: $\(\dim H^1(G; \mathcal{F}) = \dim \operatorname{coker} \delta_{\mathcal{F}} = \sum_{e \in E} d_e - \operatorname{rank}(\delta_{\mathcal{F}})\)$
  • Euler–Poincaré Characteristic (euler_characteristic): Satisfies the exact topological invariance law independent of the restriction maps \(\rho\): $\(\chi(G; \mathcal{F}) = \dim C^0(G; \mathcal{F}) - \dim C^1(G; \mathcal{F}) = \dim H^0(G; \mathcal{F}) - \dim H^1(G; \mathcal{F})\)$

Python Example: Holonomy, Diffusion & Harmonic Extension

import math
from algebrax.topology import (
    CellularSheaf,
    sheaf_diffusion,
    sheaf_harmonic_extension,
    sheaf_laplacian,
)

# 1. Constant Sheaf: strict generalization of graph Laplacians
graph = {0: {1: 1.0}, 1: {0: 1.0, 2: 2.0}, 2: {1: 2.0}}
constant_sheaf = CellularSheaf.constant(graph, stalk_dim=1)
l_sheaf = sheaf_laplacian(constant_sheaf)
print('Constant Sheaf dim H^0:', constant_sheaf.global_sections_dimension())  # -> 1

# 2. Orthogonal Connection Sheaf on a 3-cycle (SO(2) rotation frames)
rot = lambda theta: [[math.cos(theta), -math.sin(theta)], [math.sin(theta), math.cos(theta)]]
ident = [[1.0, 0.0], [0.0, 1.0]]

# Flat bundle: rotation angles sum to 0 -> dim H^0 = 2, dim H^1 = 2
sheaf_flat = CellularSheaf()
sheaf_flat.add_edge(0, 1, dim=2, rho_u=rot(math.pi / 3), rho_v=ident)
sheaf_flat.add_edge(1, 2, dim=2, rho_u=rot(math.pi / 6), rho_v=ident)
sheaf_flat.add_edge(0, 2, dim=2, rho_u=rot(math.pi / 2), rho_v=ident)
print('Flat bundle H^0, H^1:', sheaf_flat.global_sections_dimension(), sheaf_flat.first_cohomology_dimension())
# -> 2, 2

# Frustrated cycle (discrete Mobius bundle): holonomy = -I -> dim H^0 = 0, dim H^1 = 0
sheaf_frustrated = CellularSheaf()
sheaf_frustrated.add_edge(0, 1, dim=2, rho_u=ident, rho_v=ident)
sheaf_frustrated.add_edge(1, 2, dim=2, rho_u=ident, rho_v=ident)
sheaf_frustrated.add_edge(0, 2, dim=2, rho_u=rot(math.pi), rho_v=ident)
print(
    'Frustrated bundle H^0, H^1:',
    sheaf_frustrated.global_sections_dimension(),
    sheaf_frustrated.first_cohomology_dimension(),
)
# -> 0, 0
assert sheaf_flat.euler_characteristic() == sheaf_frustrated.euler_characteristic() == 0

#3. Sheaf Harmonic Extension (Dirichlet Boundary Value Problem)
path_sheaf = CellularSheaf()
path_sheaf.add_edge(0, 1, dim=1, rho_u=1.0, rho_v=1.0)
path_sheaf.add_edge(1, 2, dim=1, rho_u=1.0, rho_v=1.0)
path_sheaf.add_edge(2, 3, dim=1, rho_u=1.0, rho_v=1.0)

harmonic_state = sheaf_harmonic_extension(
    path_sheaf,
    boundary_values={(0, 0): 0.0, (3, 0): 3.0},
    boundary_vertices={0, 3},
)
print('Harmonic extension:', harmonic_state)
# -> {(0, 0): 0.0, (3, 0): 3.0, (1, 0): 1.0, (2, 0): 2.0}

Functorial Sheaves & Categorical DEC (FunctorialSheaf, ConstantSheaf)

Following Justin Curry's categorical sheaf theory, every regular cell complex \(K\) induces a face-inclusion poset category \(\mathbf{Poset}(K)\) (CellPosetCategory), and a cellular sheaf is a functor \(\mathcal{F}: \mathbf{Poset}(K) \to \mathbf{Mat}(\mathbb{R})\) (FunctorialSheaf).

Standard Discrete Exterior Calculus (DEC) is identically the special case of cellular sheaf theory for the Constant Rank-1 Sheaf \(\underline{\mathbb{R}}\) (ConstantSheaf): - Its degree-\(k\) sheaf coboundary \(\delta^k\) (build_sheaf_coboundary_matrix) equals the DEC exterior derivative \(d_k = \partial_{k+1}^\top\). - Its degree-\(k\) Hodge–Sheaf Laplacian \(L_k = (\delta^k)^\top \delta^k + \delta^{k-1} (\delta^{k-1})^\top\) (build_sheaf_laplacian) equals the DEC Hodge Laplacian \(\Delta_k\).

from algebrax.topology import (
    ConstantSheaf,
    SimplicialComplex,
    build_sheaf_coboundary_matrix,
    build_sheaf_laplacian,
)
from algebrax.verification import verify_coboundary_nilpotency

sc = SimplicialComplex([(0, 1, 2), (0, 1, 3), (0, 2, 3), (1, 2, 3)])
const_sheaf = ConstantSheaf.from_simplicial_complex(sc)

assert verify_coboundary_nilpotency(const_sheaf, k=0)
l1 = build_sheaf_laplacian(const_sheaf, k=1)

Discrete Fiber Bundles & Gauge Connections (algebrax.topology.bundle)

When every vertex stalk has identical fiber dimension \(d\) and every edge restriction map is an orthogonal transformation \(\rho(u, v) \in O(d)\) (or \(SO(d)\)), the cellular sheaf specializes to a Discrete Vector Bundle with Orthogonal Gauge Connection (DiscreteOrthogonalConnection): - Parallel Transport & Wilson Loop Holonomy: transport_path(path) and compute_face_holonomy(connection, face) evaluate path-ordered transport and discrete curvature around 2-faces (is_flat_bundle). - Connection Laplacian (\(L_\nabla = D \otimes I_d - A_\rho\)): build_connection_laplacian(connection, adjacency) constructs the sparse block operator for angular synchronization, pose-graph SLAM, and cryo-EM orientation recovery, and connection.to_sheaf() embeds the bundle into a CellularSheaf. - Gauge Covariance: apply_gauge_transformation and verify_gauge_covariance verify \(L_{\nabla'} = \mathbf{G} L_\nabla \mathbf{G}^\top\) under local vertex frame rotations \(g_u \in O(d)\).