Topology System Reference
This reference documents the topology monitoring system that tracks revolutionary organization via percolation theory. For conceptual background, see Percolation Theory & Phase Transitions.
Overview
The topology system analyzes the solidarity subgraph to detect phase transitions
in organizational structure. It is implemented as a SimulationObserver
that receives state change notifications and computes topological metrics.
Key Components:
babylon.engine.topology_monitor- Observer and helper functionsbabylon.models.topology_metrics- Data models for metrics
Constants & Thresholds
Phase Detection
Constant |
Value |
Purpose |
|---|---|---|
|
0.1 |
Percolation ratio below this indicates atomized movement |
|
0.5 |
Crossing this threshold triggers phase shift detection |
|
2 |
If potential > actual × this, movement is brittle |
Liquidity Classification
Constant |
Value |
Purpose |
|---|---|---|
|
0.1 |
Minimum solidarity strength for sympathizer classification |
|
0.5 |
Minimum solidarity strength for cadre classification |
Resilience Testing
Constant |
Value |
Purpose |
|---|---|---|
|
0.2 |
Fraction of nodes removed in purge simulation (20%) |
|
0.4 |
Giant component must survive at 40% of original size |
Metrics
TopologySnapshot
The TopologySnapshot model captures metrics at each tick:
Field |
Type |
Description |
|---|---|---|
|
|
Simulation tick number |
|
|
Number of disconnected solidarity cells |
|
|
Size of largest connected component (L_max) |
|
|
Total social_class nodes in system |
|
|
L_max / total_nodes (range [0, 1]) |
|
|
Count of SOLIDARITY edges > 0.1 strength |
|
|
Count of SOLIDARITY edges > 0.5 strength |
|
|
actual/potential liquidity ratio [0, 1] (Sprint 3.3) |
|
|
Whether network survives purge test (None if not tested) |
ResilienceResult
The ResilienceResult model captures purge simulation output:
Field |
Type |
Description |
|---|---|---|
|
|
True if network survives simulated purge |
|
|
L_max before node removal |
|
|
L_max after removing nodes |
|
|
Fraction of nodes removed |
|
|
Required survival fraction |
|
|
RNG seed for reproducibility |
Functions
extract_solidarity_subgraph
- extract_solidarity_subgraph(G, min_strength=0.0)
Extract undirected solidarity network from WorldState graph.
- Parameters:
- Returns:
Undirected graph with only SOLIDARITY edges above threshold
- Return type:
nx.Graph[str]
Example:
from babylon.engine.topology_monitor import extract_solidarity_subgraph graph = state.to_graph() solidarity_graph = extract_solidarity_subgraph(graph, min_strength=0.1)
calculate_component_metrics
- calculate_component_metrics(solidarity_graph, total_social_classes)
Calculate connected component metrics for percolation analysis.
- Parameters:
- Returns:
Tuple of (num_components, max_component_size, percolation_ratio)
- Return type:
Example:
from babylon.engine.topology_monitor import ( extract_solidarity_subgraph, calculate_component_metrics, ) solidarity_graph = extract_solidarity_subgraph(graph) num_comp, l_max, ratio = calculate_component_metrics( solidarity_graph, total_social_classes=20 )
calculate_liquidity
- calculate_liquidity(G)
Calculate potential vs actual solidarity metrics.
- Parameters:
G (nx.DiGraph[str]) – Directed graph from
WorldState.to_graph()- Returns:
Tuple of (potential_liquidity, actual_liquidity)
- Return type:
Interpretation:
potential: Sympathizer network (edges > 0.1)actual: Cadre network (edges > 0.5)If
potential > actual * 2: Movement is broad but brittle
check_resilience
- check_resilience(G, removal_rate=0.2, survival_threshold=0.4, seed=None)
Test if solidarity network survives targeted node removal.
Simulates a “purge” scenario by removing a percentage of nodes and checking if the giant component survives.
- Parameters:
- Returns:
Result with is_resilient flag and metrics
- Return type:
Example:
from babylon.engine.topology_monitor import check_resilience result = check_resilience(graph, removal_rate=0.2, seed=42) if not result.is_resilient: print("Sword of Damocles: Network is fragile!")
TopologyMonitor Class
- class TopologyMonitor(resilience_test_interval=5, resilience_removal_rate=0.2, logger=None)
Observer tracking solidarity network condensation via percolation theory.
Implements
SimulationObserverprotocol.- Parameters:
resilience_test_interval (int) – Run resilience test every N ticks (0 = disabled)
resilience_removal_rate (float) – Fraction of nodes to remove in test
logger (logging.Logger | None) – Logger instance (default: module logger)
Configuration
Parameter |
Default |
Description |
|---|---|---|
|
5 |
Test resilience every N ticks (0 disables) |
|
0.2 |
Fraction of nodes removed in purge test |
Properties
- history: list[TopologySnapshot]
Returns copy of recorded snapshots (one per tick)
Lifecycle Hooks
- on_simulation_start(initial_state, config)
Called when simulation begins. Clears history and records initial snapshot.
- on_tick(previous_state, new_state)
Called after each tick. Records snapshot and logs narrative states.
- on_simulation_end(final_state)
Called when simulation ends. Logs summary statistics.
Event Emission (Sprint 3.3)
The TopologyMonitor emits PhaseTransitionEvent when percolation ratio
crosses threshold boundaries. Events are collected and injected into the next
tick’s WorldState.
Internal State:
Attribute |
Type |
Description |
|---|---|---|
|
|
Last known phase state |
|
|
Events awaiting collection |
Methods:
- _classify_phase(percolation_ratio, cadre_density=0.0)
Classify current phase state from percolation ratio and cadre density.
- get_pending_events()
Return and clear pending events list.
- Returns:
List of events awaiting injection
- Return type:
Phase States (4-Phase Model - Sprint 3.3):
State |
Threshold |
Political Meaning |
|---|---|---|
Gaseous |
|
Atomized leftism, no coordination capacity |
Transitional |
|
Emerging structure, vulnerable to disruption |
Liquid |
|
Mass movement formed, broad but lacks discipline |
Solid |
|
Vanguard party crystallized, iron discipline |
Narrative States
The monitor logs these narrative states based on metrics:
State |
Condition |
Log Message |
|---|---|---|
Gaseous |
|
“Movement is atomized” |
Liquid |
|
“Mass movement formed, lacks cadre discipline” |
Solid |
|
“Vanguard Party crystallized, iron discipline” |
Crystallization |
|
“Mass movement hardened into disciplined vanguard” |
Brittle |
|
“Movement is broad but brittle” |
Sword of Damocles |
|
“A purge would destroy the movement” |
Usage Example
from babylon.engine.simulation import Simulation
from babylon.engine.topology_monitor import TopologyMonitor
from babylon.models import WorldState, SimulationConfig
# Create initial state
state = WorldState(entities={...}, relationships=[...])
config = SimulationConfig()
# Create monitor
monitor = TopologyMonitor(resilience_test_interval=5)
# Create simulation with observer
sim = Simulation(state, config, observers=[monitor])
# Run simulation
for _ in range(10):
sim.step()
# Access metrics
for snapshot in monitor.history:
print(f"Tick {snapshot.tick}: p={snapshot.percolation_ratio:.2f}")
sim.end()
See Also
Percolation Theory & Phase Transitions - Conceptual explanation of percolation theory
Event System Architecture - Event system architecture
Event System Reference - Complete event type reference (includes PhaseTransitionEvent)
Imperial Rent - Related economic mechanics
babylon.engine.systems.solidarity- Solidarity transmission systembabylon.systems.formulas- Mathematical formulas