The TNFR SDK provides an intuitive, production-ready interface for creating, evolving, and analyzing Resonant Fractal Networks with complete theoretical fidelity. 90% less code, 100% of the power.
from tnfr.sdk import TNFR
# One-line network creation and evolution
results = TNFR.create(20).random(0.3).evolve(5).results()
print(f'Coherence: {results.coherence:.3f}')
# Template-based approach
molecule = TNFR.template('molecule').auto_optimize()
print(molecule.summary())
# Ultra-compact with alias
from tnfr.sdk import T
net = T.create(10).complete().evolve(3)PHILOSOPHY: Maximum power, minimum complexity.
Instant network creation with zero boilerplate:
from tnfr.sdk import TNFR
# Topology builders (chainable)
ring = TNFR.create(10).ring() # Ring topology
star = TNFR.create(15).star() # Star topology
random = TNFR.create(20).random(0.3) # Random connections
complete = TNFR.create(6).complete() # All-to-all
# Templates for common patterns
molecule = TNFR.template('molecule') # Molecular structure
small_net = TNFR.template('small') # 5-node ring
large_net = TNFR.template('large') # 50-node random
# Evolution and optimization
net.evolve(5) # TNFR dynamics
net.auto_optimize() # Self-optimization
# Metrics and analysis
result = net.results() # All metrics
coherence = net.coherence() # Just coherence
summary = net.summary() # One-line overviewfrom tnfr.sdk import T # Ultra-short alias
# Everything in one line
result = T.create(8).complete().evolve(2).results()
# Quick checks
if net.results().is_coherent():
print("✅ Network is stable!")
# Comparison
comparison = TNFR.compare(net1, net2, net3)
print(f"Winner: {comparison['best']['name']}")7.5% reduction |
| **Learning Curve** | Steep | Gentle | Intuitive methods |
| **Import Complexity** | Multiple imports | Single import | Simplified |
| **Readability** | Technical | Natural English | Self-documenting |
| **Power** | Full TNFR | Full TNFR | No loss |
| **Performance** | Same | Same | Maintained |
## 🔄 Migration Guide
**OLD WAY (Complex):**
```python
from tnfr.sdk import TNFRNetwork
network = TNFRNetwork("test")
network.add_nodes(20, vf_range=(0.5, 2.0))
network.connect_nodes(0.3, "small_world")
network.apply_sequence("basic_activation", repeat=3)
results = network.measure()NEW WAY (Simple):
from tnfr.sdk import TNFR
results = TNFR.create(20).random(0.3).evolve(3).results()Backward Compatibility: Old API still works! New code should use TNFR class. print(f"Density: {network.get_density():.3f}") print(f"Avg degree: {network.get_average_degree():.2f}")
cloned = network.clone()
data = network.export_to_dict()
network.reset()
### Advanced Examples
```python
# Molecular simulation
molecule = (TNFR.template('molecule')
.evolve(10)
.auto_optimize())
if molecule.results().is_stable():
print("Molecule is stable!")
# Social network analysis
social_nets = {
'family': TNFR.create(6).complete(),
'friends': TNFR.create(15).ring().random(0.2),
'community': TNFR.create(50).random(0.1)
}
for name, net in social_nets.items():
evolved = net.evolve(5)
print(f"{name}: {evolved.summary()}")
# Network comparison
comparison = TNFR.compare(*social_nets.values())
print(f"Most coherent: {comparison['best']['name']}")For backward compatibility, the old API is still available:
Pre-configured templates for common use cases:
from tnfr.sdk import TNFRTemplates
# Social network dynamics
social_results = TNFRTemplates.social_network_simulation(
people=50,
connections_per_person=6,
simulation_steps=20,
random_seed=42
)
# Neural network modeling
neural_results = TNFRTemplates.neural_network_model(
neurons=100,
connectivity=0.15,
activation_cycles=30
)
# Ecosystem dynamics
ecosystem_results = TNFRTemplates.ecosystem_dynamics(
species=25,
evolution_steps=50
)
# Creative process modeling
creative_results = TNFRTemplates.creative_process_model(
ideas=15,
development_cycles=12
)
# Organizational networks
org_results = TNFRTemplates.organizational_network(
agents=40,
coordination_steps=25
)Builder patterns for standard experiments:
from tnfr.sdk import TNFRExperimentBuilder
# Small-world network study
sw_results = TNFRExperimentBuilder.small_world_study(
nodes=50,
rewiring_prob=0.1,
steps=10
)
# Synchronization analysis
sync_results = TNFRExperimentBuilder.synchronization_study(
nodes=30,
coupling_strength=0.5,
steps=20
)
# Topology comparison
comparison = TNFRExperimentBuilder.compare_topologies(
node_count=40,
steps=10
)
for topology, results in comparison.items():
print(f"{topology}: C(t) = {results.coherence:.3f}")
# Phase transition study
transition = TNFRExperimentBuilder.phase_transition_study(
nodes=50,
coupling_levels=5
)
# Resilience testing
resilience = TNFRExperimentBuilder.resilience_study(
nodes=40,
initial_steps=10,
perturbation_steps=5,
recovery_steps=10
)from tnfr.sdk import (
compare_networks,
compute_network_statistics,
format_comparison_table,
)
# Create multiple networks
results1 = TNFRNetwork("net1").add_nodes(20).connect_nodes(0.3).measure()
results2 = TNFRNetwork("net2").add_nodes(20).connect_nodes(0.5).measure()
# Compare
comparison = compare_networks({"net1": results1, "net2": results2})
print(format_comparison_table(comparison))
# Extended statistics
stats = compute_network_statistics(results1)
print(f"Coherence: {stats['coherence']:.3f}")
print(f"Avg Si: {stats['avg_si']:.3f} ± {stats['std_si']:.3f}")
print(f"Range: [{stats['min_si']:.3f}, {stats['max_si']:.3f}]")from tnfr.sdk import export_to_json, import_from_json
# Export network
network = TNFRNetwork("test").add_nodes(10).connect_nodes(0.3)
export_to_json(network, "network.json")
# Import data
data = import_from_json("network.json")
print(f"Loaded: {data['name']} with {data['metadata']['nodes']} nodes")from tnfr.sdk import suggest_sequence_for_goal
# Get recommendations
seq, desc = suggest_sequence_for_goal("stabilize")
print(f"Goal: stabilize")
print(f"Sequence: {seq}")
print(f"Description: {desc}")
# Use directly
network = TNFRNetwork().add_nodes(15).connect_nodes(0.3)
network.apply_sequence(seq, repeat=5)All sequences follow TNFR grammar rules and maintain canonical invariants:
Each SDK feature derives from specific theoretical foundations:
| SDK Method | Physics | Theory Document |
|---|---|---|
TNFR.create(n).ring() | Network topology, nodal equation | FUNDAMENTAL_THEORY.md |
.tetrad() → TetradSnapshot | Φ_s, |∇φ|, K_φ, ξ_C | EXTENDED_FIELDS_AND_DERIVED_QUANTITIES.md |
.conservation() → ConservationReport | Noether charge, Lyapunov stability | STRUCTURAL_CONSERVATION_THEOREM.md |
.evolve_grammar_aware(steps) | U1–U6 proactive enforcement | UNIFIED_GRAMMAR_RULES.md |
.integrity_check() → IntegrityReport | 13/13 operator postconditions | STRUCTURAL_STABILITY_AND_DYNAMICS.md |
.tensor_invariants() | Energy density ℰ, topological charge 𝒬 | EXTENDED_FIELDS_AND_DERIVED_QUANTITIES.md |
.emergent_fields() | Chirality χ, symmetry breaking 𝒮 | EXTENDED_FIELDS_AND_DERIVED_QUANTITIES.md |
.telemetry() | C(t), Si, phase, νf | FUNDAMENTAL_THEORY.md |
.auto_optimize() | Gradient descent on structural manifold | AGENTS.md § Self-Optimizing Dynamics |
TNFR.analyze(net) | Comprehensive structural analysis | APPLIED_STRUCTURAL_ANALYSIS.md |
Theory hub: theory/README.md — all 12 theory documents with SDK pointers
Examples: examples/README.md — 30+ executable demonstrations with SDK links
Primary reference: AGENTS.md — complete TNFR theoretical framework
Glossary: theory/GLOSSARY.md — canonical terminology definitions
basic_activation: [emission, reception, coherence, resonance, silence]
stabilization: [emission, reception, coherence, resonance, recursivity]
creative_mutation: [emission, dissonance, reception, coherence, mutation, resonance, silence]
network_sync: [emission, reception, coherence, coupling, resonance, silence]
exploration: [emission, dissonance, reception, coherence, resonance, transition]
consolidation: [recursivity, reception, coherence, resonance, silence]
The NetworkResults dataclass provides structured access to metrics:
results = network.measure()
# Direct access
print(f"Coherence: {results.coherence}")
print(f"Avg νf: {results.avg_vf} Hz_str")
print(f"Avg Phase: {results.avg_phase} rad")
# Node-level metrics
for node_id, si in results.sense_indices.items():
print(f"{node_id}: Si = {si:.3f}")
# Convert to dict
data = results.to_dict()
# Human-readable summary
print(results.summary())All SDK components maintain full TNFR theoretical fidelity:
Type stubs (.pyi files) are provided for better IDE support:
from tnfr.sdk import TNFRNetwork, NetworkResults
# Full type hints and autocomplete
network: TNFRNetwork = TNFRNetwork("typed")
results: NetworkResults = network.add_nodes(10).measure()See examples/sdk_example.py for comprehensive usage demonstrations.
All SDK components are thoroughly tested:
pytest tests/unit/sdk/ -vFor detailed documentation on TNFR theory and canonical implementation:
AGENTS.md for TNFR fundamentalstnfr.pdf for complete theoretical frameworkARCHITECTURE.md for system architecture and SDK integrationWhen extending the SDK, maintain TNFR canonicity:
See repository LICENSE file.