Version: 0.0.3.5
Status: Complete theoretical framework grounded in the nodal equation
Authority: the nodal equation ∂EPI/∂t = νf·ΔNFR(t) and the structural-field tetrad
Quality: Production-ready test suite
This document provides guidelines for contributing to the TNFR (Resonant Fractal Nature Theory) project. TNFR constitutes a computational framework for modeling complex systems through coherent patterns and resonance dynamics.
All contributions must maintain theoretical consistency. Requirements:
from tnfr.constants.canonical import * for the structural and operational constants (only π is a genuine structural scale).We are committed to providing a welcoming and inclusive environment for all contributors, regardless of background, identity, or experience level.
Expected behavior:
Unacceptable behavior:
Instances of unacceptable behavior may be reported to the project maintainers. All complaints will be reviewed and investigated promptly and fairly.
# Install from PyPI (stable release)
pip install tnfr[viz,dev]
# Or clone for development
git clone https://github.com/fermga/TNFR-Python-Engine.git
cd TNFR-Python-Engine
pip install -e .[dev]
# Verify installation
python -c "from tnfr.constants.canonical import PI, U6_STRUCTURAL_POTENTIAL_LIMIT; print(f'π={PI:.6f}, U6 Φ_s bound={U6_STRUCTURAL_POTENTIAL_LIMIT:.6f}')"All development must utilize theoretically derived canonical constants:
from tnfr.constants.canonical import *
# Correct: Use canonical constants
threshold = HIGH_COHERENCE_THRESHOLD # π/(π+1) ≈ 0.7585 (emergent high-coherence gate)
# Incorrect: Arbitrary numerical values
threshold = 0.75 # Lacks theoretical foundationFork and clone the repository:
git clone https://github.com/YOUR_USERNAME/TNFR-Python-Engine.git
cd TNFR-Python-EngineCreate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activateInstall in development mode:
pip install -e ".[dev-minimal]"Install pre-commit hooks (optional but recommended):
pre-commit installVerify installation:
pytest tests/examples/test_u6_sequential_demo.pygit checkout -b feature/your-feature-name
# or
git checkout -b fix/issue-descriptionBranch naming conventions:
feature/ - New functionalityfix/ - Bug fixesdocs/ - Documentation improvementsrefactor/ - Code restructuring without behavior changestest/ - Test additions or improvementsperf/ - Performance optimizations# Run smoke tests (fast validation)
make smoke-tests # Unix/Linux
.\make.cmd smoke-tests # Windows
# Run full test suite
pytest
# Check code quality
ruff check src/
mypy src/tnfr/If adding validation, health, or telemetry logic:
run_structural_validation to produce a ValidationReport.compute_structural_health(report) for recommendations.perf_registry=PerformanceRegistry()).Telemetry additions must:
coherence_total), sense index, Φ_s, |∇φ|, K_φ, ξ_C.Performance guardrails:
perf_guard(label, registry).tests/unit/performance/ for new instrumentation.See Pull Request Process below.
Before contributing, familiarize yourself with AGENTS.md - the canonical guide for TNFR development.
All contributions must preserve these invariants:
def should_implement(feature):
"""Decision framework for TNFR changes."""
if weakens_tnfr_fidelity(feature):
return False # Reject, even if "cleaner"
if not maps_to_operators(feature):
return False # Must map or be new operator
if violates_invariants(feature):
return False # Hard constraint
if not derivable_from_physics(feature):
return False # No organizational convenience ≠ physical necessity
if not testable(feature):
return False # No untestable magic
return True # Implement with full documentation# Linting
ruff check src/
# Type checking
mypy src/tnfr/
# Formatting (if using black)
black src/ --line-length 100snake_casePascalCaseUPPER_SNAKE_CASE_leading_underscore# Standard library
from __future__ import annotations
import sys
from pathlib import Path
from typing import Optional, List, Dict
# Third-party
import networkx as nx
import numpy as np
# TNFR modules
from tnfr.operators.definitions import Emission, Coherence
from tnfr.metrics.coherence import compute_coherence
from tnfr.utils import get_loggerThe TNFR codebase is organized into focused modules for maintainability and cognitive load reduction:
Operators (tnfr.operators.*):
emission.py, coherence.py, etc. (13 operators)definitions_base.py - Shared operator infrastructuredefinitions.py - Backward-compatible importsGrammar (tnfr.operators.grammar.*):
u1_initiation_closure.py, u2_convergence_boundedness.py, etc. (8 rules)grammar.py - Unified validation interfaceMetrics (tnfr.metrics.*):
coherence.py, sense_index.py, phase_sync.py, telemetry.pymetrics.py - Backward-compatible exportsAdding New Code:
coupling.py for coupling modifications)tnfr.metrics/ or extend existing metric moduleuN_*.py fileModule Guidelines:
def test_coherence_monotonicity():
"""Coherence operator must not decrease C(t)."""
G = nx.erdos_renyi_graph(20, 0.3)
initialize_network(G)
C_before = compute_coherence(G)
apply_operator(G, node, Coherence())
C_after = compute_coherence(G)
assert C_after >= C_before, "Coherence must not decrease"test_<function_name> - Unit teststest_<feature>_<scenario> - Integration teststest_invariant_<invariant_name> - Invariant verification# Smoke tests (fast)
make smoke-tests
# Full suite
pytest
# Specific module
pytest tests/unit/operators/
# With coverage
pytest --cov=src/tnfr --cov-report=htmlUse Google style docstrings:
def apply_operator(G: nx.Graph, node: int, operator: Operator) -> None:
"""Apply a structural operator to a network node.
Args:
G: NetworkX graph representing TNFR network
node: Node identifier to apply operator to
operator: Structural operator instance (AL, EN, IL, etc.)
Raises:
ValueError: If node not in graph
GrammarViolation: If operator application violates grammar
Examples:
>>> G = nx.erdos_renyi_graph(10, 0.3)
>>> apply_operator(G, 0, Emission())
>>> apply_operator(G, 0, Coherence())
"""All contributions must include:
All project documentation MUST be written in English. This requirement is absolute and applies to:
Non-English text (including Spanish) is only permitted when:
In those cases the surrounding explanatory context MUST still be in English.
Rationale:
Enforcement:
Examples:
Compliant:
Added bifurcation benchmark sweeping OZ intensity and mutation thresholds.
Non-compliant:
Añadido benchmark de bifurcación con parámetros OZ.
If you need help translating, open a draft PR early and request assistance rather than merging mixed-language content.
By contributing you agree to maintain English as the sole canonical language for all project artifacts.
If adding features, update:
make smoke-tests)ruff check)## Description
[Clear description of what this PR does]
## Motivation
[Why is this change needed? What problem does it solve?]
## TNFR Alignment
- [ ] Preserves all 6 canonical invariants
- [ ] Maps to structural operators (specify which)
- [ ] Derivable from TNFR physics (reference [theory/TNFR.pdf](theory/TNFR.pdf) or [theory/UNIFIED_GRAMMAR_RULES.md](theory/UNIFIED_GRAMMAR_RULES.md))
- [ ] Maintains reproducibility (seeds, determinism)
## Testing
- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Examples demonstrate usage
- [ ] All tests pass locally
## Documentation
- [ ] Docstrings added/updated
- [ ] README updated (if needed)
- [ ] Examples added (if new feature)
- [ ] Physics rationale documented
## Checklist
- [ ] Code follows style guidelines
- [ ] Self-review completed
- [ ] No unintended files committed
- [ ] Branch name follows conventions
- [ ] Commit messages are descriptive
## Affected Components
[List modules/files modified]
## Breaking Changes
[List any breaking changes, or write "None"]
## Additional Notes
[Any other context, screenshots, or information]If proposing a new operator:
Template:
## Proposed Operator: [Name]
### Physical Basis
[How it emerges from TNFR physics]
### Nodal Equation Impact
∂EPI/∂t = ... [specific form]
### Contracts
- Pre: [conditions required]
- Post: [guaranteed effects]
### Grammar Classification
[Generator? Closure? Stabilizer? Destabilizer? etc.]
### Tests
- [List specific test requirements]If proposing new grammar rules:
If a change "prettifies the code" but weakens TNFR fidelity, it is NOT accepted.
If a change strengthens structural coherence and paradigm traceability, GO AHEAD.