Merge commit 'd803bfe2b1fe7f5e219e50ac20d6801a0a58ac75' as 'vendor/ruvector'
This commit is contained in:
231
vendor/ruvector/examples/mincut/time_crystal/README.md
vendored
Normal file
231
vendor/ruvector/examples/mincut/time_crystal/README.md
vendored
Normal file
@@ -0,0 +1,231 @@
|
||||
# Time Crystal Coordination Patterns
|
||||
|
||||
## What Are Time Crystals?
|
||||
|
||||
Time crystals are a fascinating state of matter first proposed by Nobel laureate Frank Wilczek in 2012 and experimentally realized in 2016. Unlike regular crystals that have repeating patterns in *space* (like the atomic structure of diamond), time crystals have repeating patterns in *time*.
|
||||
|
||||
### Key Properties of Time Crystals:
|
||||
|
||||
1. **Periodic Motion**: They oscillate between states perpetually
|
||||
2. **No Energy Required**: Motion continues without external energy input (in their ground state)
|
||||
3. **Broken Time-Translation Symmetry**: The system's state changes periodically even though the laws governing it don't change
|
||||
4. **Quantum Coherence**: The pattern is stable and resists perturbations
|
||||
|
||||
## Time Crystals in Swarm Coordination
|
||||
|
||||
This example translates time crystal physics into swarm coordination patterns. Instead of atoms oscillating, we have **network topologies** that transform periodically:
|
||||
|
||||
```
|
||||
Ring → Star → Mesh → Ring → Star → Mesh → ...
|
||||
```
|
||||
|
||||
### Why This Matters for Coordination:
|
||||
|
||||
1. **Self-Sustaining Patterns**: The swarm maintains rhythmic behavior without external control
|
||||
2. **Predictable Dynamics**: Other systems can rely on the periodic nature
|
||||
3. **Resilient Structure**: The pattern self-heals when perturbed
|
||||
4. **Efficient Resource Use**: No continuous energy input needed to maintain organization
|
||||
|
||||
## How This Example Works
|
||||
|
||||
### Phase Cycle
|
||||
|
||||
The example implements a 9-phase cycle:
|
||||
|
||||
| Phase | Topology | MinCut | Description |
|
||||
|-------|----------|--------|-------------|
|
||||
| Ring | Ring | 2 | Each agent connected to 2 neighbors |
|
||||
| StarFormation | Transition | ~2 | Transitioning from ring to star |
|
||||
| Star | Star | 1 | Central hub with spokes |
|
||||
| MeshFormation | Transition | ~6 | Increasing connectivity |
|
||||
| Mesh | Complete | 11 | All agents interconnected |
|
||||
| MeshDecay | Transition | ~6 | Reducing to star |
|
||||
| StarReformation | Transition | ~2 | Returning to star |
|
||||
| RingReformation | Transition | ~2 | Rebuilding ring |
|
||||
| RingStable | Ring | 2 | Stabilized ring structure |
|
||||
|
||||
### Minimum Cut as Structure Verification
|
||||
|
||||
The **minimum cut** (mincut) serves as a "structural fingerprint" for each phase:
|
||||
|
||||
- **Ring topology**: MinCut = 2 (break any two adjacent edges)
|
||||
- **Star topology**: MinCut = 1 (disconnect any spoke)
|
||||
- **Mesh topology**: MinCut = n-1 (disconnect any single node)
|
||||
|
||||
By continuously monitoring mincut values, we can:
|
||||
1. Verify the topology is correct
|
||||
2. Detect structural degradation ("melting")
|
||||
3. Trigger self-healing when patterns break
|
||||
|
||||
### Code Structure
|
||||
|
||||
```rust
|
||||
struct TimeCrystalSwarm {
|
||||
graph: DynamicGraph, // Current topology
|
||||
current_phase: Phase, // Where we are in the cycle
|
||||
tick: usize, // Time counter
|
||||
mincut_history: Vec<f64>, // Track pattern over time
|
||||
stability: f64, // Health metric (0-1)
|
||||
}
|
||||
|
||||
impl TimeCrystalSwarm {
|
||||
fn tick(&mut self) {
|
||||
// 1. Measure current mincut
|
||||
// 2. Verify it matches expected value
|
||||
// 3. Update stability score
|
||||
// 4. Detect melting if stability drops
|
||||
// 5. Advance to next phase
|
||||
// 6. Rebuild topology for new phase
|
||||
}
|
||||
|
||||
fn crystallize(&mut self, cycles: usize) {
|
||||
// Run multiple full cycles to establish pattern
|
||||
}
|
||||
|
||||
fn restabilize(&mut self) {
|
||||
// Self-healing when pattern breaks
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Running the Example
|
||||
|
||||
```bash
|
||||
# From the repository root
|
||||
cargo run --example mincut/time_crystal/main
|
||||
|
||||
# Or compile and run
|
||||
rustc examples/mincut/time_crystal/main.rs \
|
||||
--edition 2021 \
|
||||
--extern ruvector_mincut=target/debug/libruvector_mincut.rlib \
|
||||
-o time_crystal
|
||||
|
||||
./time_crystal
|
||||
```
|
||||
|
||||
### Expected Output
|
||||
|
||||
```
|
||||
❄️ Crystallizing time pattern over 3 cycles...
|
||||
|
||||
═══ Cycle 1 ═══
|
||||
Tick 1 | Phase: StarFormation | MinCut: 2.0 (expected 2.0) ✓
|
||||
Tick 2 | Phase: Star | MinCut: 1.0 (expected 1.0) ✓
|
||||
Tick 3 | Phase: MeshFormation | MinCut: 5.5 (expected 5.5) ✓
|
||||
...
|
||||
|
||||
Periodicity: ✓ VERIFIED | Stability: 98.2%
|
||||
|
||||
═══ Cycle 2 ═══
|
||||
...
|
||||
```
|
||||
|
||||
## Applications
|
||||
|
||||
### 1. Autonomous Agent Networks
|
||||
- Agents periodically switch between communication patterns
|
||||
- No central coordinator needed
|
||||
- Self-organizing task allocation
|
||||
|
||||
### 2. Load Balancing
|
||||
- Periodic topology changes distribute load
|
||||
- Ring phase: sequential processing
|
||||
- Star phase: centralized coordination
|
||||
- Mesh phase: parallel collaboration
|
||||
|
||||
### 3. Byzantine Fault Tolerance
|
||||
- Rotating topologies prevent single points of failure
|
||||
- Periodic restructuring limits attack windows
|
||||
- Mincut monitoring detects compromised nodes
|
||||
|
||||
### 4. Energy-Efficient Coordination
|
||||
- Topology changes require no continuous power
|
||||
- Nodes "coast" through phase transitions
|
||||
- Wake-sleep cycles synchronized to crystal period
|
||||
|
||||
## Key Concepts
|
||||
|
||||
### Crystallization
|
||||
The process of establishing the periodic pattern. Initial cycles may show instability as the system "learns" the rhythm.
|
||||
|
||||
### Melting
|
||||
Loss of periodicity due to:
|
||||
- Network failures
|
||||
- External interference
|
||||
- Resource exhaustion
|
||||
- Random perturbations
|
||||
|
||||
The system detects melting when `stability < 0.5` and triggers restabilization.
|
||||
|
||||
### Stability Score
|
||||
An exponential moving average of how well actual mincuts match expected values:
|
||||
|
||||
```rust
|
||||
stability = 0.9 * stability + 0.1 * (is_match ? 1.0 : 0.0)
|
||||
```
|
||||
|
||||
- 100%: Perfect crystal
|
||||
- 70-100%: Stable oscillations
|
||||
- 50-70%: Degraded but functional
|
||||
- <50%: Melting, needs restabilization
|
||||
|
||||
### Periodicity Verification
|
||||
Compares mincut values across cycles:
|
||||
|
||||
```rust
|
||||
for i in 0..PERIOD {
|
||||
current_value = mincut_history[n - i]
|
||||
previous_cycle = mincut_history[n - i - PERIOD]
|
||||
|
||||
if abs(current_value - previous_cycle) < threshold {
|
||||
periodic = true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Extensions
|
||||
|
||||
### 1. Multi-Crystal Coordination
|
||||
Run multiple time crystals with different periods that occasionally synchronize.
|
||||
|
||||
### 2. Adaptive Periods
|
||||
Adjust `CRYSTAL_PERIOD` based on network conditions.
|
||||
|
||||
### 3. Hierarchical Crystals
|
||||
Nest time crystals at different scales:
|
||||
- Fast oscillations: individual agent behavior
|
||||
- Medium oscillations: team coordination
|
||||
- Slow oscillations: system-wide reorganization
|
||||
|
||||
### 4. Phase-Locked Loops
|
||||
Synchronize multiple swarms by locking their phases.
|
||||
|
||||
## References
|
||||
|
||||
### Physics
|
||||
- Wilczek, F. (2012). "Quantum Time Crystals". Physical Review Letters.
|
||||
- Yao, N. Y., et al. (2017). "Discrete Time Crystals: Rigidity, Criticality, and Realizations". Physical Review Letters.
|
||||
|
||||
### Graph Theory
|
||||
- Stoer, M., Wagner, F. (1997). "A Simple Min-Cut Algorithm". Journal of the ACM.
|
||||
- Karger, D. R. (2000). "Minimum Cuts in Near-Linear Time". Journal of the ACM.
|
||||
|
||||
### Distributed Systems
|
||||
- Lynch, N. A. (1996). "Distributed Algorithms". Morgan Kaufmann.
|
||||
- Olfati-Saber, R., Murray, R. M. (2004). "Consensus Problems in Networks of Agents". IEEE Transactions on Automatic Control.
|
||||
|
||||
## License
|
||||
|
||||
MIT License - See repository root for details.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions welcome! Areas for improvement:
|
||||
- Additional topology patterns (tree, grid, hypercube)
|
||||
- Quantum-inspired coherence metrics
|
||||
- Real-world deployment examples
|
||||
- Performance optimizations for large swarms
|
||||
|
||||
---
|
||||
|
||||
**Note**: This is a conceptual demonstration. Real time crystals are quantum mechanical systems. This example uses classical graph theory to capture the *spirit* of periodic, autonomous organization.
|
||||
Reference in New Issue
Block a user