20 Lab 04 — Build a Cellular Sheaf
Anchor chapter: Chapter 4 — Cellular Sheaves on Graphs.
Goal. Construct the discourse sheaf on a 3-vertex path graph (Hansen–Ghrist Example 1.1), compute all global sections, and verify that \(\delta\) is injective.
Implement the cellular sheaf data structure (stalks, restriction maps, coboundary matrix) from scratch. Construct the three-agent discourse sheaf, the constant sheaf on a cycle, and the path sheaf of Example 4.5. For each sheaf: compute the coboundary matrix \(\delta\) explicitly, evaluate the total discrepancy \(\|\delta x\|^2\) for several random cochains, and search numerically for global sections by minimizing the discrepancy. This lab is the foundation for the sheaf Laplacian (Ch. 5) and the neural sheaf construction (Ch. 7).
This lab requires only NumPy, Matplotlib, and NetworkX, loaded automatically via Pyodide. Code cells run directly in the page via WebAssembly — no local Python installation needed.
Prefer a local Jupyter environment? Download lab-04-build-a-sheaf.ipynb
20.1 Setup
20.2 1. Build the object
A cellular sheaf \(\mathcal{F}\) on a graph \(G = (V, E)\) assigns a vector space \(\mathcal{F}(v)\) to each vertex, a vector space \(\mathcal{F}(e)\) to each edge, and a linear restriction map \(\mathcal{F}_{v \trianglelefteq e} : \mathcal{F}(v) \to \mathcal{F}(e)\) for each incident vertex–edge pair. The coboundary map \(\delta : C^0 \to C^1\) sends a 0-cochain \((x_v)_{v \in V}\) to the 1-cochain whose value on an oriented edge \(e = (u, v)\) is \((\delta x)_e = \mathcal{F}_{v \trianglelefteq e}\, x_v - \mathcal{F}_{u \trianglelefteq e}\, x_u\). Global sections are 0-cochains with \(\delta x = 0\).
20.3 2. Verify a theorem / run an experiment
We compute the null space of \(\delta\) (the space of global sections) using scipy.linalg.null_space. For the discourse sheaf, the global sections are cochains where every agent agrees on its projected coordinate; we expect a 2-dimensional space (each agent can freely choose the coordinate not constrained by any edge). We also evaluate \(\|\delta x\|^2\) for 20 random cochains to confirm that the minimum is 0 and is achieved only in the null space.
20.4 Exercises
Global section dimension. For the discourse sheaf on a path of length \(n\) (with alternating x-projection and y-projection edges), what is \(\dim \ker \delta\)? Verify your formula numerically for \(n = 2, 3, 4, 5\).
Constant sheaf cohomology. For the constant \(\mathbb{R}^1\) sheaf on a connected graph \(G\), \(\ker \delta = \mathbb{R}^1\) (one global section: the constant cochain). Verify this for a cycle \(C_5\), a path \(P_4\), and the complete graph \(K_4\).
Injectivity check. A sheaf is called flasque if \(\delta\) is injective (no non-trivial global sections). Construct a flasque sheaf on the 3-vertex path by choosing restriction maps so that \(\ker \delta = \{0\}\), and verify numerically.
Sheaf morphism. Define a morphism \(\phi : \mathcal{F} \to \mathcal{G}\) between two sheaves on the same graph as a collection of linear maps \(\phi_v : \mathcal{F}(v) \to \mathcal{G}(v)\) and \(\phi_e : \mathcal{F}(e) \to \mathcal{G}(e)\) that commute with the restriction maps. Implement this and verify that \(\delta_\mathcal{G} \circ \phi_0 = \phi_1 \circ \delta_\mathcal{F}\) for a concrete example.