Skip to content

Commit 95c1b2a

Browse files
author
fer
committed
Merge optimization/phase-3: 3.7× validation speedup + TNFR-aligned caching
PERFORMANCE ACHIEVEMENTS (73% reduction, 6.138s → 1.670s): - Fast diameter approximation: 46-111× speedup (O(N+M) vs O(N³)) - Cached eccentricity: 10× first call + ∞× cached (topological invariant) - Vectorized phase operations: NumPy broadcasting (2-3× faster) - Field caching: Perfect cache coherence (0.000s repeated calls) - Grammar early exit: 10-30% speedup on invalid sequences (optional) PARADIGM ALIGNMENT (All optimizations respect TNFR physics): - Eccentricity = structural invariant → automatic cache invalidation - Cache dependencies = structural coupling (graph_topology tracking) - Vectorization = coherent batch operations (circular topology preserved) - Read-only telemetry = no state mutation (all invariants preserved) IMPLEMENTATION (8 major optimizations): 1. UTC timestamp migration (future-proof) 2. Centralized field caching (TNFRHierarchicalCache integration) 3. Performance guardrails (5.8% overhead, < 8% target) 4. Validation aggregator (unified grammar + fields) 5. Fast diameter (2-sweep BFS heuristic) 6. Cached eccentricity (dependencies={'graph_topology'}) 7. Vectorized phases (NumPy broadcasting) 8. Grammar early exit (stop_on_first_error parameter) TESTING: 23/23 tests passing (fields, validation, grammar) DOCUMENTATION: Complete (OPTIMIZATION_PROGRESS.md, PROFILING_RESULTS.md) COMMITS: 8 commits (2cf122b...7ee5e1d) Physics: All optimizations preserve nodal equation semantics and canonical invariants. Cache respects ∂EPI/∂t = 0 when topology frozen. Refs: #phase-3, docs/OPTIMIZATION_PROGRESS.md
2 parents 43091df + 7ee5e1d commit 95c1b2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+14469
-283
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,17 @@ outputs/
4646
benchmarks/results/
4747
dist-test/
4848
test-env/
49+
examples/output/
4950

5051
# Large benchmark result files
5152
benchmarks/results/*_telemetry.jsonl
5253
benchmarks/results/phase_gradient_full_study.jsonl
5354
benchmarks/results/u6_aggressive_results.jsonl
5455
benchmarks/results/*_5000_*.jsonl
56+
57+
debug_scratch/
58+
*.tmp
59+
*.temp
60+
61+
# Type checking cache
62+
.mypy_cache/

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"git.ignoreLimitWarning": true
3+
}

.vscode/tasks.json

Lines changed: 112 additions & 129 deletions
Large diffs are not rendered by default.

CHANGELOG.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## [9.1.0] - 2025-11-14
6+
7+
### Added
8+
9+
- Phase 3 structural instrumentation:
10+
- `run_structural_validation` aggregator (grammar U1-U3 + field thresholds Φ_s, |∇φ|, K_φ, ξ_C, optional ΔΦ_s drift).
11+
- `compute_structural_health` with risk levels and recommendations.
12+
- `TelemetryEmitter` integration example (`examples/structural_health_demo.py`).
13+
- Performance guardrails: `PerformanceRegistry`, `perf_guard`, `compare_overhead`.
14+
- CLI: `scripts/structural_health_report.py` (on-demand health summaries).
15+
- Docs: README Phase 3 section, CONTRIBUTING instrumentation notes, `docs/STRUCTURAL_HEALTH.md`.
16+
- Glyph-aware grammar error factory (operator glyph → canonical name mapping).
17+
18+
### Tests
19+
20+
- Added unit tests for validation, health, grammar error factory, telemetry emitter, performance guardrails.
21+
22+
### Performance
23+
24+
- Validation instrumentation overhead ~5.8% (moderate workload) below 8% guardrail.
25+
26+
### Internal
27+
28+
- Optional `perf_registry` parameter in `run_structural_validation` (read-only timing).
29+
30+
### Deferred
31+
32+
- U4 bifurcation validation excluded pending dedicated handler reintroduction.
33+
34+
### Integrity
35+
36+
- All changes preserve TNFR canonical invariants (no EPI mutation; phase verification intact; read-only telemetry/validation).
37+
38+
## [9.0.2]
39+
40+
Previous release (see repository history) with foundational operators, unified grammar, metrics, and canonical field tetrad.
41+
42+
---
43+
**Reality is not made of things—it's made of resonance.**

CONTRIBUTING.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,29 @@ ruff check src/
126126
mypy src/tnfr/
127127
```
128128

129+
### 3a. Phase 3 Structural Instrumentation
130+
131+
If adding validation, health, or telemetry logic:
132+
133+
- Use `run_structural_validation` to produce a `ValidationReport`.
134+
- Derive `compute_structural_health(report)` for recommendations.
135+
- Include performance timing (pass `perf_registry=PerformanceRegistry()`).
136+
- Ensure added overhead ratio < 0.10 baseline (see perf tests).
137+
- Never mutate graph state inside validation / health functions.
138+
- Document physics traceability (why each threshold is used).
139+
140+
Telemetry additions must:
141+
142+
- Remain read-only (no operator side effects).
143+
- Export coherence (`coherence_total`), sense index, Φ_s, |∇φ|, K_φ, ξ_C.
144+
- Provide deterministic timestamps when seeds fixed.
145+
146+
Performance guardrails:
147+
148+
- Wrap optional expensive helpers with `perf_guard(label, registry)`.
149+
- Add/adjust tests under `tests/unit/performance/` for new instrumentation.
150+
- Avoid micro-optimizing at expense of clarity unless overhead > target.
151+
129152
### 4. Update Documentation
130153

131154
- Add docstrings to new functions/classes
@@ -241,25 +264,30 @@ from tnfr.utils import get_logger
241264
The TNFR codebase is organized into focused modules for maintainability and cognitive load reduction:
242265

243266
**Operators** (`tnfr.operators.*`):
267+
244268
- **Individual operator modules**: `emission.py`, `coherence.py`, etc. (13 operators)
245269
- **Base class**: `definitions_base.py` - Shared operator infrastructure
246270
- **Facade**: `definitions.py` - Backward-compatible imports
247271

248272
**Grammar** (`tnfr.operators.grammar.*`):
273+
249274
- **Constraint modules**: `u1_initiation_closure.py`, `u2_convergence_boundedness.py`, etc. (8 rules)
250275
- **Facade**: `grammar.py` - Unified validation interface
251276

252277
**Metrics** (`tnfr.metrics.*`):
278+
253279
- **Focused metrics**: `coherence.py`, `sense_index.py`, `phase_sync.py`, `telemetry.py`
254280
- **Facade**: `metrics.py` - Backward-compatible exports
255281

256282
**Adding New Code**:
283+
257284
- **New operator**: Add to appropriate operator file (e.g., `coupling.py` for coupling modifications)
258285
- **New metric**: Create new file in `tnfr.metrics/` or extend existing metric module
259286
- **New grammar rule**: Add to relevant constraint module or create new `uN_*.py` file
260287
- **Always update facades**: If adding new exports, add to facade files for backward compatibility
261288

262289
**Module Guidelines**:
290+
263291
- Keep files under 600 lines (ideally 200-400)
264292
- One primary concept per module
265293
- Use facade pattern for public APIs

LICENSE.md

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# MIT License
22

3-
Copyright (c) 2025 TNFR – Resonant Fractal Nature Theory
3+
## Copyright
4+
5+
Copyright (c) 2025 F. F. Martinez Gamo
6+
7+
ORCID: [0009-0007-6116-0613](https://orcid.org/0009-0007-6116-0613)
8+
9+
---
410

511
Permission is hereby granted, free of charge, to any person obtaining a copy
612
of this software and associated documentation files (the "Software"), to deal
@@ -12,10 +18,80 @@ furnished to do so, subject to the following conditions:
1218
The above copyright notice and this permission notice shall be included in all
1319
copies or substantial portions of the Software.
1420

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
**THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1622
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1723
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1824
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1925
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2026
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
27+
SOFTWARE.**
28+
29+
---
30+
31+
## Additional Information
32+
33+
### TNFR Python Engine
34+
35+
This software implements **Resonant Fractal Nature Theory (TNFR)**, a computational framework
36+
for modeling coherent patterns through resonance dynamics.
37+
38+
**Project**: TNFR-Python-Engine
39+
**Repository**: <https://github.com/fermga/TNFR-Python-Engine>
40+
**PyPI**: <https://pypi.org/project/tnfr/>
41+
**DOI**: [10.5281/zenodo.17602861](https://doi.org/10.5281/zenodo.17602861)
42+
43+
### Citation
44+
45+
If you use this software in your research, please cite:
46+
47+
```bibtex
48+
@software{tnfr_python_engine,
49+
author = {Martinez Gamo, F. F.},
50+
title = {TNFR-Python-Engine: Resonant Fractal Nature Theory Implementation},
51+
year = {2025},
52+
version = {9.0.2},
53+
doi = {10.5281/zenodo.17602861},
54+
url = {https://github.com/fermga/TNFR-Python-Engine}
55+
}
56+
```
57+
58+
See [CITATION.cff](CITATION.cff) for machine-readable citation metadata.
59+
60+
### Third-Party Dependencies
61+
62+
This software relies on the following open-source libraries:
63+
64+
- **NetworkX** - BSD-3-Clause License
65+
- **NumPy** - BSD-3-Clause License
66+
- **SciPy** - BSD-3-Clause License
67+
- **Matplotlib** (optional) - PSF License
68+
- **PyYAML** (optional) - MIT License
69+
70+
See `pyproject.toml` for the complete list of dependencies.
71+
72+
### Contributing
73+
74+
Contributions to TNFR Python Engine are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md)
75+
for guidelines.
76+
77+
By contributing to this project, you agree that your contributions will be licensed under
78+
the same MIT License that covers this project.
79+
80+
### Trademark Notice
81+
82+
"TNFR" and "Resonant Fractal Nature Theory" are terms associated with this theoretical
83+
framework. While the software implementation is provided under the MIT License, the
84+
theoretical framework itself is a scholarly work subject to academic attribution norms.
85+
86+
### Disclaimer
87+
88+
This software is provided for research and educational purposes. The theoretical framework
89+
of TNFR represents an alternative modeling paradigm and should be evaluated critically
90+
within appropriate academic and scientific contexts.
91+
92+
---
93+
94+
**For questions about licensing or usage, please contact the maintainers via**:
95+
96+
- GitHub Issues: <https://github.com/fermga/TNFR-Python-Engine/issues>
97+
- GitHub Discussions: <https://github.com/fermga/TNFR-Python-Engine/discussions>

0 commit comments

Comments
 (0)