SSGF (Self-Stabilizing Gauge Field)¶
The SSGF subsystem implements a two-timescale geometry control engine. It treats the coupling matrix $ (the "geometry") as a dynamic carrier field that self-organizes to minimize the free energy of the phase dynamics.
Gauged PGBO (Phase-Geometry Bidirectional Observer)¶
The Gauged PGBO is the primary observer for SSGF integration. It measures the alignment between the current phase-coherence manifold and the geometric coupling field $.
Unlike standard observers that measure linear correlation, the Gauged PGBO computes a scalar curvature proxy based on the rank-2 metric tensor {\mu\nu}$:
936898 h_{ij} = W_{ij} \cos(\theta_j - \theta_i) 936898
The curvature proxy $ represents how much the phase embedding "stretches" the underlying geometry:
936898 K_g = \frac{\sum_{i,j} h_{ij}}{\sum_{i,j} |W_{ij}|} 936898
Features¶
- Curvature Detection: High $ indicates that the geometry is tightly wrapped around highly coherent phase clusters.
- Topological Feedback: Provides the mathematical basis for Phase \(\rightarrow\) Geometry \(\rightarrow\) Phase bidirectional coupling.
- Metric Invariants: Measures the structural integrity of the synchronization manifold.
pgbo ¶
Phase-Geometry Bidirectional Observer for validated alignment snapshots.
PGBO records coherence, SSGF costs, phase-geometry alignment, and a scalar
gauge-curvature proxy for each observed phase/coupling pair. Cost weights,
phase vectors, and coupling matrices are validated before observation so
history contains only dimensionally consistent snapshots. The observer stores
diagnostics and step counters only; it does not mutate the supplied phase or
geometry arrays.
Classes¶
PGBOSnapshot
dataclass
¶
PGBOSnapshot(
R: float,
psi: float,
costs: SSGFCosts,
phase_geometry_alignment: float,
gauge_curvature: float,
step: int,
)
Observation from the Phase-Geometry Bidirectional Observer at one timestep.
PGBO ¶
Phase-Geometry Bidirectional Observer.
Monitors the alignment between phase dynamics (Kuramoto state) and geometry (SSGF carrier W). Computes a scalar curvature proxy based on the rank-2 metric tensor h_{mu nu}. This represents the structural coupling between the phase-manifold and the underlying physical space.
The bidirectionality
- Phases -> Cost -> Gradient -> Geometry (forward control)
- Geometry -> Coupling -> Phases (backward influence)
PGBO observes the emergence of curvature as synchronization patterns stretch or curve the geometric coupling field W.
Source code in src/scpn_phase_orchestrator/ssgf/pgbo.py
Attributes¶
history
property
¶
Methods:¶
observe ¶
Compute coherence, SSGF costs, and phase-geometry alignment.
Parameters¶
phases : FloatArray Current phase vector theta_i. W : FloatArray Current geometric coupling matrix W_ij.
Returns¶
PGBOSnapshot A PGBOSnapshot containing order parameter R, Psi, SSGF costs, and the gauge curvature proxy.
Source code in src/scpn_phase_orchestrator/ssgf/pgbo.py
alignment_trend ¶
Mean alignment over last window observations.
Parameters¶
window : int Sliding-window length.
Returns¶
float Mean alignment over last window observations.
Raises¶
ValueError If the inputs are invalid or inconsistent.
Source code in src/scpn_phase_orchestrator/ssgf/pgbo.py
Functions:¶
Topological Integration Observable (p_h1)¶
Measures the H1 persistent homology of the delay-embedded phase dynamics. It acts as a topological-integration gate, allowing higher-level director logic to engage only when topological integration exceeds the \(\tau_{h1} > 0.72\) threshold.
Features¶
- Vietoris-Rips Filtration: Computes max $ lifetimes using the
ripseralgorithm (or Rust-native streaming PH). - Complexity Gating: Prevents the supervisor from acting on chaotic or topologically incoherent noise.
topological_integration ¶
Topological Integration Observable over phase-history windows.
The observer accumulates copied phase snapshots, delay-embeds recent history,
and computes H1 persistence through ripser when available. Without ripser
it falls back to a PLV approximation that preserves the same public state shape
but not the same topological guarantee. The scalar p_h1 is a
dynamical-structure measure — the persistence of first-homology loops in the
phase point cloud — and nothing more: it does not assert phenomenology, perform
actuation, or make safety-critical decisions by itself.
Classes¶
TopologicalIntegrationState
dataclass
¶
One observation: p_h1 score, the integration gate, and the method.
TopologicalIntegrationObserver ¶
TopologicalIntegrationObserver(
tau_h1: float = _TAU_H1,
embed_dim: int = 3,
embed_delay: int = 1,
window_size: int = 50,
beta: float = 8.0,
)
Topological Integration Observable.
Delay-embeds multichannel phase signals, computes H1 persistent homology via
a Vietoris-Rips filtration, squashes the maximum loop lifetime to [0, 1]
with a logistic, and opens an integration gate at p_h1 > tau_h1.
The default threshold tau_h1 = 0.72 is set for the metastable
R ~ 0.4-0.8 regime, where persistent first-homology loops are most
pronounced — full synchrony (R > 0.95) collapses the point cloud and
incoherence (R < 0.2) fills it uniformly, and neither produces a dominant
persistent 1-cycle. This is a topological-structure measure, not a claim
about consciousness or phenomenology.
Source code in src/scpn_phase_orchestrator/ssgf/topological_integration.py
Attributes¶
tau_h1
property
¶
Methods:¶
observe ¶
Add a phase snapshot and compute the observable if enough history.
Parameters¶
phases : FloatArray
Oscillator phases in radians, shape (N,).
Returns¶
TopologicalIntegrationState The p_h1 score, integration gate, loop lifetime, and method.
Raises¶
TypeError If an argument has the wrong type. ValueError If the inputs are invalid or inconsistent.
Source code in src/scpn_phase_orchestrator/ssgf/topological_integration.py
SSGF Costs¶
Computes the energy functional {total}$ that drives the geometric minimization:
- C1 (Sync Deficit): - R$
- C2 (Spectral Gap): hBc\lambda_2(L(W))$ (maximizing algebraic connectivity)
- C3 (Sparsity): $ regularizer on $
- C4 (Symmetry): Deviation from = W^T$
Boundary contract: compute_ssgf_costs rejects boolean aliases,
complex-valued aliases, non-finite payloads, non-vector phases, non-square
coupling matrices, invalid weights, and inconsistent optional Rust return
tuples before accepting a cost snapshot. The direct PyO3 Rust binding applies
the same finite-shape and non-negative-weight checks before entering the Rust
cost kernel, so malformed buffers fail with ValueError instead of a kernel
panic.
costs ¶
Validated SSGF total-cost terms for phase and coupling geometry states.
compute_ssgf_costs combines synchronization deficit, spectral gap,
sparsity, and symmetry terms into a weighted objective. The public entry point
rejects boolean, non-numeric, non-finite, non-vector phase inputs, non-square
or non-finite coupling matrices, and invalid weight tuples before dispatching
to Rust or Python. This keeps accelerated and fallback paths aligned on the
same physical dimensions and cost semantics.
Classes¶
SSGFCosts
dataclass
¶
SSGFCosts(
c1_sync: float,
c2_spectral_gap: float,
c3_sparsity: float,
c4_symmetry: float,
u_total: float,
)
Individual SSGF cost terms plus the weighted total objective.
Functions:¶
compute_ssgf_costs ¶
compute_ssgf_costs(
W: FloatArray,
phases: FloatArray,
weights: tuple[float, ...] = (1.0, 0.5, 0.1, 0.1),
) -> SSGFCosts
Compute SSGF cost terms for geometry W given current phases.
C1: 1 - R (synchronization deficit) C2: -λ₂(L(W)) (negative algebraic connectivity — maximize λ₂) C3: ||W||₁ / N² (sparsity regularizer — prevent dense coupling) C4: ||W - W^T||_F / N (symmetry deviation)
U_total = w1·C1 + w2·C2 + w3·C3 + w4·C4
Parameters¶
W : FloatArray
Weight matrix.
phases : FloatArray
Oscillator phases in radians, shape (N,).
weights : tuple[float, ...]
The weights.
Returns¶
SSGFCosts SSGF cost terms for geometry W given current phases.
Raises¶
ValueError If the inputs are invalid or inconsistent. RuntimeError If the operation fails.
Source code in src/scpn_phase_orchestrator/ssgf/costs.py
Closure Diagnostics¶
Closure helpers track whether geometry and phase updates remain inside the configured SSGF stability envelope.
closure ¶
Cybernetic closure loop connecting observed phases to SSGF geometry updates.
The closure observes the current phase vector, evaluates total SSGF costs,
asks the carrier to descend through a cost callback, then decodes the next
coupling matrix for feedback into phase dynamics. The module mutates only the
injected GeometryCarrier and its local convergence bookkeeping; phase inputs
are passed through to the cost layer where dimensional and finite-value checks
are enforced.
Classes¶
ClosureState
dataclass
¶
One L16 closure cycle result: cost before/after and convergence.
CyberneticClosure ¶
CyberneticClosure(
carrier: GeometryCarrier,
cost_weights: tuple[float, ...] = (1.0, 0.5, 0.1, 0.1),
max_steps: int = 0,
)
L16 → L1 feedback loop with Lyapunov stability guarantee.
The closure cycle: 1. Observe phases (L1-L15 state) 2. Compute SSGF costs 3. Update geometry carrier z via gradient on U_total 4. Decode new coupling W from z 5. Feed W back to the phase dynamics (L1)
The loop is a strange loop (Hofstadter): geometry → dynamics → cost → gradient → geometry. Lyapunov stability: U_total is non-increasing under gradient descent on z, guaranteeing convergence.
This is the computational implementation. Whether it constitutes a "strange loop" in the philosophical sense is a theoretical claim outside the scope of this module.
Source code in src/scpn_phase_orchestrator/ssgf/closure.py
Attributes¶
carrier
property
¶
The geometry carrier whose latent vector z is updated by the closure.
Returns¶
GeometryCarrier The geometry carrier whose latent vector z is updated by the closure.
Methods:¶
step ¶
One closure cycle: observe → cost → gradient → new W.
Returns (new_W, closure_state).
Parameters¶
phases : FloatArray
Oscillator phases in radians, shape (N,).
Returns¶
tuple[FloatArray, ClosureState] One closure cycle: observe → cost → gradient → new W.
Raises¶
TypeError If an argument has the wrong type. ValueError If the inputs are invalid or inconsistent.
Source code in src/scpn_phase_orchestrator/ssgf/closure.py
run ¶
Run n outer steps, return final W and history.
Parameters¶
phases : FloatArray
Oscillator phases in radians, shape (N,).
n_outer_steps : int
Number of outer optimisation steps.
Returns¶
tuple[FloatArray, list[ClosureState]] N outer steps, return final W and history.
Raises¶
TypeError If an argument has the wrong type. ValueError If the inputs are invalid or inconsistent.
Source code in src/scpn_phase_orchestrator/ssgf/closure.py
Functions:¶
Free-Energy Terms¶
Variational free-energy primitives shared by the SSGF monitors and predictive supervisor paths.
free_energy ¶
Free-energy helpers for SSGF stochastic geometry diagnostics.
This module provides Langevin perturbation, Boltzmann weighting, and effective temperature estimation for latent geometry cost histories. It preserves stable edge semantics: non-positive temperature or time step returns an unchanged copy for Langevin noise, zero-temperature Boltzmann evaluation is explicit, and short or near-zero cost histories report zero effective temperature. Optional Rust kernels mirror those public contracts.
Functions:¶
add_langevin_noise ¶
add_langevin_noise(
z: FloatArray,
temperature: float,
dt: float,
rng: Generator | None = None,
) -> FloatArray
Add Langevin stochastic noise to a z-space vector.
z_new = z + sqrt(2·T·dt) · η, η ~ N(0, I)
Models thermal fluctuations in the SSGF geometry space, enabling escape from local minima during stochastic optimisation.
Gardiner 2009, Stochastic Methods, §4.3.
Parameters¶
z : FloatArray
Complex Ott-Antonsen order parameter.
temperature : float
Annealing temperature.
dt : float
Integration step size.
rng : np.random.Generator | None
NumPy random generator, or None.
Returns¶
FloatArray Add Langevin stochastic noise to a z-space vector.
Source code in src/scpn_phase_orchestrator/ssgf/free_energy.py
boltzmann_weight ¶
Boltzmann factor exp(-U/T) for a given total energy and temperature.
Clamps exponent to [-700, 700] to avoid over/underflow. Returns 1.0 at T=0 if U=0, else 0.0 for U>0 at T=0.
Parameters¶
u_total : float Total exogenous input. temperature : float Annealing temperature.
Returns¶
float Boltzmann factor exp(-U/T) for a given total energy and temperature.
Source code in src/scpn_phase_orchestrator/ssgf/free_energy.py
effective_temperature ¶
Estimate effective temperature from cost fluctuations.
T_eff = Var(U) / (2 · )
Based on the fluctuation-dissipation relation: in equilibrium, the variance of energy is proportional to T² C_V, and for a single degree of freedom ~ T/2.
Returns 0.0 if the cost series is constant or too short.
Parameters¶
costs_history : FloatArray Per-iteration cost history.
Returns¶
float Effective temperature from cost fluctuations.
Source code in src/scpn_phase_orchestrator/ssgf/free_energy.py
Architecture & Theory¶
The SSGF (Self-Stabilizing Gauge Field) framework is built upon the theoretical foundation of treating synchronization as a field-theoretic phenomenon. In this view, the coupling matrix \(W_{ij}\) is not a static set of parameters but a dynamic carrier field that mediates interactions between oscillators.
The Two-Timescale Engine¶
SPO implements SSGF as a two-timescale system: 1. Fast Scale (\(\\theta\)): Phase dynamics evolve according to the standard UPDE/Kuramoto equations. 2. Slow Scale (\(W\)): The geometry evolves to minimize a free energy functional \(U_{total}(W, \\theta)\).
The coupling is bidirectional: phases align based on \(W\) (Fast Scale), and \(W\) adapts to the observed alignment of phases (Slow Scale). This creates a self-stabilizing feedback loop that spontaneously discovers topologies optimal for the current dynamical task.
Variational Free Energy Minimization¶
The geometric evolution is driven by the gradient of the free energy: $$ \dot{W}{ij} = -\eta \frac{\partial U $$}}{\partial W_{ij}
where \(\eta\) is the geometric learning rate. The functional \(U_{total}\) includes terms for synchronization, spectral connectivity, sparsity, and symmetry, as detailed in `scpn_phase_orchestrator.ssgf.costs`.
Gauge Curvature in Synchronization¶
The concept of a Gauge-Theoretic metric in synchronization was pioneered to address the limitation of linear correlation measures. When we map the phases \(\\theta_i\) to a point cloud in a delay-embedded space, the "distance" between oscillators is not merely their index separation but their phase divergence.
The Metric Tensor $h_{\mu¶
u}$
By defining the metric tensor \(h_{ij} = W_{ij} \cos( heta_j - heta_i)\), we treat the coupling strengths as the "volume" or "density" of connections, and the phase cosine as the "stretching factor."
If \(\\theta_i \\approx \\theta_j\), then \(\cos \\approx 1\), and the metric volume is preserved. If \(\\theta_i\) and \(\\theta_j\) are out of phase, the metric volume collapses toward zero (or becomes negative), indicating a high-curvature region of the manifold.
Curvature Proxy \(K_g\)¶
The scalar curvature proxy \(K_g\) implemented in `PGBO` provides a single number representing the "flatness" of the synchronization manifold. A flat manifold (\(K_g \\approx 1\)) implies that the physical coupling topology \(W\) perfectly matches the phase alignment \(\\theta\). Lower values (or high gradients in \(K_g\)) signal the presence of Topological Defects or Chimera States.
Technical Reference: PGBO Snapshot¶
The `PGBOSnapshot` dataclass returns the following telemetry for every observation:
- `R`: Global order parameter.
- `psi`: Mean global phase.
- `costs`: A breakdown of the four SSGF cost terms (Sync, Spectral, Sparsity, Symmetry).
- `phase_geometry_alignment`: The legacy linear correlation between phase diffs and \(W_{ij}\).
- `gauge_curvature`: The new rank-2 tensor curvature proxy.
- `step`: The current simulation step index.
Usage Example: Closed-Loop Geometry Control¶
from scpn_phase_orchestrator.ssgf.pgbo import PGBO
from scpn_phase_orchestrator.upde.engine import UPDEEngine
# Initialize observer and engine
pgbo = PGBO()
engine = UPDEEngine(n_oscillators=32, dt=0.01)
# Main Loop
for step in range(1000):
# Step phases
phases = engine.step(phases, omegas, W, zeta, psi, alpha)
# Observe phase-geometry alignment
snapshot = pgbo.observe(phases, W)
# Adaptive control based on curvature
if snapshot.gauge_curvature < 0.6:
# Manifold is collapsing/stretching too much
# Adjust geometry learning rate or modulator
modulator = 2.0
else:
modulator = 0.5
Integration with Layer 16 Director¶
In the full SCPN stack, the SSGF curvature metrics are exported to the Layer 16 Director, which uses them to calculate the global Geometric Coherence Index (GCI). When \(K_g\) drops below critical levels, the director triggers a "Geometry Reset" or shifts the regime of the `ActiveInferenceAgent`.
The Gauged PGBO thus serves as the sensory organ for the topological stability of the entire intelligence system.
SSGF Cost Terms: Detailed Breakdown¶
Each cost term in `SSGFCosts` represents a distinct architectural pressure on the evolution of the geometry \(W\).
C1: Synchronization Deficit (\(1 - R\))¶
The primary pressure is to achieve coherence. If the oscillators are desynchronized, \(R\) is low, and \(C1\) is high. This pressure drives the geometry toward configurations that foster phase-locking.
C2: Negative Spectral Gap (\(-\lambda_2(L(W))\))¶
In graph theory, the second smallest eigenvalue of the Laplacian matrix, \(\lambda_2\), is known as the Algebraic Connectivity or the Fiedler Value. It measures how difficult it is to partition a graph into two disconnected components.
By minimizing \(C2\) (and thus maximizing \(\lambda_2\)), the SSGF engine ensures that the coupling topology is globally integrated. It prevents the emergence of fragmented islands that would otherwise desynchronize the system.
C3: Sparsity (\(||W||_1 / N^2\))¶
A fully connected network (all-to-all) is computationally expensive and biologically unrealistic. The \(L_1\) regularizer \(C3\) acts as a "cost of cabling." It forces the engine to achieve the target synchronization using the minimum number of connections. This pressure spontaneously generates Small-World or Hierarchical topologies.
C4: Symmetry Deviation (\(||W - W^T||_F / N\))¶
Physical coupling in most natural systems (gap junctions, power lines) is symmetric. \(C4\) enforces this symmetry by penalizing directed couplings. In certain domains (e.g., neural information flow), this weight may be reduced to allow for directed causal interactions.
Topological Integration Gate: Implementation Details¶
The `TopologicalIntegrationObserver` implements persistent homology using the Vietoris-Rips filtration. This is a topological method that captures the "holes" in the point-cloud embedding of the phases.
Why H1 Persistence?¶
While \(H_0\) (connected components) measures simple clusters, \(H_1\) (one-dimensional holes) measures cycles. Synchronization is a cyclical phenomenon. The presence of long-lived \(H_1\) cycles in the phase space indicates that the network has formed a stable, integrated topological loop — a persistent first-homology cycle within the SCPN framework.
The 0.72 Threshold¶
The threshold $ au_{h1} = 0.72$ is derived from empirical studies of metastable synchronization. Below 0.72, the cycles are transient and noisy. Above 0.72, the topological structure is resilient enough to support higher-order cognitive processing or stable control logic.
Summary of Metric Parity (Rust vs Python)¶
The following table summarizes the implementation status of SSGF metrics across the two backends.
| Metric | Python (`src/`) | Rust (`spo-kernel`) | Notes |
|---|---|---|---|
| Order Parameter R | Full | Full | 7.3us (Rust) vs 45us (Py) |
| SSGF Costs | Full | Planned | Crucial for real-time W evolution |
| Gauged PGBO | Full | Full | Curvature proxy implementation |
| Topological integration (H1) | Full | In Progress | Moving to streaming Rust engine |
| Plasticity (Hebbian) | Full | Full | Sub-microsecond inner loop |
| Geometry Carrier | Full | Full | softplus decode (Python NumPy faster for N>16) |
| Ethical Cost (C15) | Full | Full | SEC + CBF, 5.7x at N=8, Jacobi eigenvalues |
Future Roadmap: SSGF v2.0¶
The next phase of SSGF development will focus on the Self-Stabilizing Gauge Field (SSGF) Hardware Kernel. This will offload the entirety of the free energy minimization to an FPGA-based solver, enabling nanosecond-scale geometry adaptation for high-frequency plasma control and quantum error correction.
- Metric Evolution: Moving from scalar curvature proxies to full tensor-field gradients.
- Geometric Jitter: Adding stochastic noise to the W-evolution to escape local minima in the free energy landscape.
- Layer 12 Coupling: Synchronizing the SSGF geometry across distributed nodes in the Gaian mesh.
Troubleshooting & Diagnostics¶
Integrating SSGF into a domain simulation can be mathematically delicate due to the bidirectional feedback between phases and geometry.
Common Issue: Geometry Explosion¶
If the geometric coupling values \(W_{ij}\) increase toward infinity, it usually indicates that the Sparsity Weight (\(w_3\)) is too low relative to the Sync Weight (\(w_1\)).
Solution: Increase \(w_3\) in `SSGFCosts` or implement a hard saturation limit using the `ImprintModel`.
Common Issue: Curvature Collapse (\(K_g < 0\))¶
If the Gauged PGBO reports negative curvature, the phase manifold has become topologically inverted — the geometry is actively pushing oscillators away from their natural synchronization targets.
Solution: Check for Phase Lags (\(\\alpha\)) that are inconsistent with the geometry \(W\). High transport delays without compensatory lag-modeling in the engine will cause curvature collapse.
Diagnostic: Spectral Gap Monitoring¶
Always monitor the `c2_spectral_gap` term. If \(\\lambda_2\) drops to zero, the network has fragmented into disconnected components. The `RegimeManager` should be configured to trigger a "Topological Recovery" action when this occurs.
Configuration Reference: SSGF Weights¶
The `SSGFCosts` constructor takes a `weights` tuple that defines the priority of geometric evolution.
| Parameter | Meaning | Default | Impact |
|---|---|---|---|
| `w1_sync` | Synchronization deficit pressure | 1.0 | Higher values force rapid sync at the cost of topology. |
| `w2_spectral` | Global integration pressure | 0.5 | Critical for preventing network fragmentation. |
| `w3_sparse` | L1 sparsity pressure | 0.1 | Controls the "cabling cost" and hierarchy depth. |
| `w4_symmetry` | Reciprocity pressure | 0.1 | Ensures \(W\) remains close to a symmetric manifold. |
Technical Appendix: Metric Tensor Derivation¶
The derivation of the synchronization metric tensor \(h_{\\mu\\nu}\) follows the logic of embedding the N-dimensional torus \(T^N\) into a higher-dimensional Euclidean space.
Let \(\\mathbf{X}_i = [\\cos \\theta_i, \\sin \\theta_i]\) be the coordinate of the \(i\)-th oscillator on the unit circle. The pairwise Euclidean distance is \(d_{ij}^2 = 2 - 2 \\cos(\\theta_j - \\theta_i)\).
The SSGF framework treats the coupling strength \(W_{ij}\) as the Gauge Field Connection that modifies the local metric. The effective distance on the synchronization manifold is weighted by the interaction strength, leading to the definition of \(h_{ij}\) used in the PGBO curvature calculation.
Benchmarking SSGF Metrics¶
The following performance benchmarks were measured on a reference Linux workstation (Intel Core i5-11600K @ 3.90GHz).
| Metric | N=32 | N=256 | N=1024 |
|---|---|---|---|
| Cost Computation (Py) | 120us | 1.2ms | 8.5ms |
| PGBO Curvature (Py) | 85us | 0.9ms | 6.2ms |
| Hebbian Plasticity (Rust) | 0.8us | 15us | 145us |
| Sparse UPDE Step (Rust) | 4.2us | 42us | 210us |
These results demonstrate that while the observers (PGBO) are sufficiently fast in Python for monitoring, the inner integration and plasticity loop MUST remain in the Rust kernel to maintain sub-millisecond control frequencies at high N.