tnfr 4.5.1__tar.gz → 4.5.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of tnfr might be problematic. Click here for more details.

Files changed (244) hide show
  1. tnfr-4.5.2/PKG-INFO +379 -0
  2. tnfr-4.5.2/README.md +344 -0
  3. {tnfr-4.5.1 → tnfr-4.5.2}/pyproject.toml +46 -43
  4. tnfr-4.5.2/src/tnfr/__init__.py +91 -0
  5. tnfr-4.5.2/src/tnfr/alias.py +546 -0
  6. tnfr-4.5.2/src/tnfr/cache.py +578 -0
  7. tnfr-4.5.2/src/tnfr/callback_utils.py +388 -0
  8. tnfr-4.5.2/src/tnfr/cli/__init__.py +75 -0
  9. tnfr-4.5.2/src/tnfr/cli/arguments.py +177 -0
  10. tnfr-4.5.2/src/tnfr/cli/execution.py +288 -0
  11. tnfr-4.5.2/src/tnfr/cli/utils.py +36 -0
  12. tnfr-4.5.2/src/tnfr/collections_utils.py +300 -0
  13. tnfr-4.5.2/src/tnfr/config.py +32 -0
  14. tnfr-4.5.2/src/tnfr/constants/__init__.py +174 -0
  15. tnfr-4.5.2/src/tnfr/constants/core.py +159 -0
  16. tnfr-4.5.2/src/tnfr/constants/init.py +31 -0
  17. tnfr-4.5.2/src/tnfr/constants/metric.py +110 -0
  18. tnfr-4.5.2/src/tnfr/constants_glyphs.py +98 -0
  19. tnfr-4.5.2/src/tnfr/dynamics/__init__.py +658 -0
  20. tnfr-4.5.2/src/tnfr/dynamics/dnfr.py +733 -0
  21. tnfr-4.5.2/src/tnfr/dynamics/integrators.py +267 -0
  22. tnfr-4.5.2/src/tnfr/dynamics/sampling.py +31 -0
  23. tnfr-4.5.2/src/tnfr/execution.py +201 -0
  24. tnfr-4.5.2/src/tnfr/flatten.py +283 -0
  25. tnfr-4.5.2/src/tnfr/gamma.py +341 -0
  26. tnfr-4.5.2/src/tnfr/glyph_history.py +290 -0
  27. tnfr-4.5.2/src/tnfr/grammar.py +344 -0
  28. tnfr-4.5.2/src/tnfr/graph_utils.py +84 -0
  29. tnfr-4.5.2/src/tnfr/helpers/__init__.py +71 -0
  30. tnfr-4.5.2/src/tnfr/helpers/numeric.py +87 -0
  31. tnfr-4.5.2/src/tnfr/immutable.py +178 -0
  32. tnfr-4.5.2/src/tnfr/import_utils.py +228 -0
  33. tnfr-4.5.2/src/tnfr/initialization.py +197 -0
  34. tnfr-4.5.2/src/tnfr/io.py +246 -0
  35. tnfr-4.5.2/src/tnfr/json_utils.py +162 -0
  36. tnfr-4.5.2/src/tnfr/locking.py +37 -0
  37. tnfr-4.5.2/src/tnfr/logging_utils.py +116 -0
  38. tnfr-4.5.2/src/tnfr/metrics/__init__.py +41 -0
  39. tnfr-4.5.2/src/tnfr/metrics/coherence.py +829 -0
  40. tnfr-4.5.2/src/tnfr/metrics/common.py +151 -0
  41. tnfr-4.5.2/src/tnfr/metrics/core.py +101 -0
  42. tnfr-4.5.2/src/tnfr/metrics/diagnosis.py +234 -0
  43. tnfr-4.5.2/src/tnfr/metrics/export.py +137 -0
  44. tnfr-4.5.2/src/tnfr/metrics/glyph_timing.py +189 -0
  45. tnfr-4.5.2/src/tnfr/metrics/reporting.py +148 -0
  46. tnfr-4.5.2/src/tnfr/metrics/sense_index.py +120 -0
  47. tnfr-4.5.2/src/tnfr/metrics/trig.py +181 -0
  48. tnfr-4.5.2/src/tnfr/metrics/trig_cache.py +109 -0
  49. tnfr-4.5.2/src/tnfr/node.py +257 -0
  50. tnfr-4.5.2/src/tnfr/observers.py +159 -0
  51. tnfr-4.5.2/src/tnfr/ontosim.py +140 -0
  52. tnfr-4.5.2/src/tnfr/operators/__init__.py +420 -0
  53. tnfr-4.5.2/src/tnfr/operators/jitter.py +203 -0
  54. tnfr-4.5.2/src/tnfr/operators/remesh.py +485 -0
  55. tnfr-4.5.2/src/tnfr/presets.py +60 -0
  56. tnfr-4.5.2/src/tnfr/rng.py +254 -0
  57. tnfr-4.5.2/src/tnfr/selector.py +210 -0
  58. tnfr-4.5.2/src/tnfr/sense.py +353 -0
  59. tnfr-4.5.2/src/tnfr/structural.py +329 -0
  60. tnfr-4.5.2/src/tnfr/tokens.py +60 -0
  61. tnfr-4.5.2/src/tnfr/trace.py +369 -0
  62. tnfr-4.5.2/src/tnfr/types.py +44 -0
  63. tnfr-4.5.2/src/tnfr/validators.py +84 -0
  64. tnfr-4.5.2/src/tnfr/value_utils.py +59 -0
  65. tnfr-4.5.2/src/tnfr.egg-info/PKG-INFO +379 -0
  66. tnfr-4.5.2/src/tnfr.egg-info/SOURCES.txt +204 -0
  67. tnfr-4.5.2/src/tnfr.egg-info/requires.txt +15 -0
  68. tnfr-4.5.2/tests/test_accumulate_cos_sin.py +27 -0
  69. tnfr-4.5.2/tests/test_add_edge_callbacks.py +11 -0
  70. tnfr-4.5.2/tests/test_add_edge_errors.py +26 -0
  71. tnfr-4.5.2/tests/test_add_edge_networkx.py +55 -0
  72. tnfr-4.5.2/tests/test_add_edge_versions.py +28 -0
  73. tnfr-4.5.2/tests/test_alias_accessor_usage.py +143 -0
  74. tnfr-4.5.2/tests/test_alias_get_default.py +10 -0
  75. tnfr-4.5.2/tests/test_alias_get_strict.py +26 -0
  76. tnfr-4.5.2/tests/test_alias_helpers_threadsafe.py +19 -0
  77. tnfr-4.5.2/tests/test_alias_iterable.py +43 -0
  78. tnfr-4.5.2/tests/test_alias_sequence.py +22 -0
  79. tnfr-4.5.2/tests/test_alias_set_error.py +10 -0
  80. tnfr-4.5.2/tests/test_cache_helpers.py +46 -0
  81. tnfr-4.5.2/tests/test_callback_errors_limit.py +32 -0
  82. {tnfr-4.5.1 → tnfr-4.5.2}/tests/test_canon.py +16 -8
  83. tnfr-4.5.2/tests/test_cli.py +418 -0
  84. tnfr-4.5.2/tests/test_cli_flatten_tokens.py +6 -0
  85. tnfr-4.5.2/tests/test_cli_history.py +100 -0
  86. tnfr-4.5.2/tests/test_cli_sanity.py +100 -0
  87. tnfr-4.5.2/tests/test_coherence_cache.py +65 -0
  88. tnfr-4.5.2/tests/test_collect_attr_generators.py +18 -0
  89. tnfr-4.5.2/tests/test_compute_Si_numpy_usage.py +54 -0
  90. tnfr-4.5.2/tests/test_compute_coherence.py +73 -0
  91. tnfr-4.5.2/tests/test_compute_theta_trig.py +22 -0
  92. tnfr-4.5.2/tests/test_config_apply.py +88 -0
  93. tnfr-4.5.2/tests/test_count_glyphs.py +28 -0
  94. tnfr-4.5.2/tests/test_defaults_integrity.py +22 -0
  95. tnfr-4.5.2/tests/test_diagnosis_state.py +13 -0
  96. tnfr-4.5.2/tests/test_dnfr_cache.py +233 -0
  97. tnfr-4.5.2/tests/test_dnfr_hooks.py +41 -0
  98. tnfr-4.5.2/tests/test_dnfr_precompute.py +74 -0
  99. tnfr-4.5.2/tests/test_dynamics_benchmark.py +23 -0
  100. tnfr-4.5.2/tests/test_dynamics_helpers.py +129 -0
  101. tnfr-4.5.2/tests/test_dynamics_run.py +74 -0
  102. tnfr-4.5.2/tests/test_dynamics_vectorized.py +39 -0
  103. tnfr-4.5.2/tests/test_edge_cases.py +74 -0
  104. tnfr-4.5.2/tests/test_edge_version_cache.py +122 -0
  105. tnfr-4.5.2/tests/test_edge_version_cache_limit.py +13 -0
  106. tnfr-4.5.2/tests/test_ensure_callbacks.py +94 -0
  107. tnfr-4.5.2/tests/test_ensure_collection.py +100 -0
  108. tnfr-4.5.2/tests/test_ensure_history_trim_performance.py +28 -0
  109. tnfr-4.5.2/tests/test_export_metrics.py +93 -0
  110. tnfr-4.5.2/tests/test_flatten_structure.py +52 -0
  111. tnfr-4.5.2/tests/test_freeze.py +55 -0
  112. tnfr-4.5.2/tests/test_gamma.py +360 -0
  113. tnfr-4.5.2/tests/test_get_attr_default.py +62 -0
  114. tnfr-4.5.2/tests/test_get_attr_strict.py +41 -0
  115. tnfr-4.5.2/tests/test_get_rng.py +31 -0
  116. tnfr-4.5.2/tests/test_get_rng_threadsafe.py +27 -0
  117. tnfr-4.5.2/tests/test_glyph_helpers.py +25 -0
  118. tnfr-4.5.2/tests/test_glyph_history_dict.py +114 -0
  119. tnfr-4.5.2/tests/test_glyph_history_windowing.py +277 -0
  120. tnfr-4.5.2/tests/test_grammar.py +196 -0
  121. tnfr-4.5.2/tests/test_history.py +23 -0
  122. tnfr-4.5.2/tests/test_history_counter.py +54 -0
  123. tnfr-4.5.2/tests/test_history_heap_cleanup.py +58 -0
  124. tnfr-4.5.2/tests/test_history_maxlen.py +119 -0
  125. tnfr-4.5.2/tests/test_history_methods.py +31 -0
  126. tnfr-4.5.2/tests/test_history_series.py +54 -0
  127. tnfr-4.5.2/tests/test_import_utils.py +149 -0
  128. tnfr-4.5.2/tests/test_initialization.py +81 -0
  129. tnfr-4.5.2/tests/test_inject_defaults_tuple.py +16 -0
  130. tnfr-4.5.2/tests/test_integrators.py +102 -0
  131. tnfr-4.5.2/tests/test_invariants.py +105 -0
  132. tnfr-4.5.2/tests/test_invoke_callbacks.py +40 -0
  133. tnfr-4.5.2/tests/test_is_immutable.py +156 -0
  134. tnfr-4.5.2/tests/test_json_utils.py +161 -0
  135. tnfr-4.5.2/tests/test_kahan_sum.py +26 -0
  136. tnfr-4.5.2/tests/test_knn_edges.py +32 -0
  137. tnfr-4.5.2/tests/test_list_mean.py +18 -0
  138. tnfr-4.5.2/tests/test_local_phase_sync.py +29 -0
  139. tnfr-4.5.2/tests/test_locking.py +25 -0
  140. tnfr-4.5.2/tests/test_logging_module.py +71 -0
  141. tnfr-4.5.2/tests/test_logging_threadsafe.py +58 -0
  142. tnfr-4.5.2/tests/test_make_rng.py +52 -0
  143. tnfr-4.5.2/tests/test_make_rng_threadsafe.py +45 -0
  144. tnfr-4.5.2/tests/test_merge_and_normalize_weights.py +23 -0
  145. tnfr-4.5.2/tests/test_metrics.py +310 -0
  146. tnfr-4.5.2/tests/test_min_max_range.py +14 -0
  147. tnfr-4.5.2/tests/test_missing_dependency_error_cache.py +13 -0
  148. {tnfr-4.5.1 → tnfr-4.5.2}/tests/test_nav.py +12 -11
  149. tnfr-4.5.2/tests/test_neighbor_phase_mean_missing_trig.py +89 -0
  150. tnfr-4.5.2/tests/test_neighbor_phase_mean_no_graph.py +45 -0
  151. tnfr-4.5.2/tests/test_neighbor_phase_mean_performance.py +47 -0
  152. tnfr-4.5.2/tests/test_neighbors_map_cache.py +17 -0
  153. tnfr-4.5.2/tests/test_node_all_nodes.py +24 -0
  154. tnfr-4.5.2/tests/test_node_from_graph_threadsafe.py +29 -0
  155. tnfr-4.5.2/tests/test_node_offset.py +24 -0
  156. tnfr-4.5.2/tests/test_node_sample.py +137 -0
  157. tnfr-4.5.2/tests/test_node_set_checksum.py +111 -0
  158. tnfr-4.5.2/tests/test_node_state_extra.py +8 -0
  159. tnfr-4.5.2/tests/test_node_weights.py +56 -0
  160. tnfr-4.5.2/tests/test_normalize_callback_entry.py +30 -0
  161. tnfr-4.5.2/tests/test_normalize_weights.py +118 -0
  162. tnfr-4.5.2/tests/test_numeric_helpers.py +39 -0
  163. tnfr-4.5.2/tests/test_observers.py +240 -0
  164. tnfr-4.5.2/tests/test_operator_factors.py +117 -0
  165. tnfr-4.5.2/tests/test_operators.py +217 -0
  166. tnfr-4.5.2/tests/test_optional_import.py +23 -0
  167. tnfr-4.5.2/tests/test_parse_tokens_errors.py +35 -0
  168. tnfr-4.5.2/tests/test_parse_toml.py +27 -0
  169. tnfr-4.5.2/tests/test_preparar_red.py +15 -0
  170. tnfr-4.5.2/tests/test_prepare_dnfr_data_performance.py +37 -0
  171. tnfr-4.5.2/tests/test_program.py +313 -0
  172. tnfr-4.5.2/tests/test_public_api.py +28 -0
  173. tnfr-4.5.2/tests/test_push_glyph.py +34 -0
  174. tnfr-4.5.2/tests/test_read_structured_file_errors.py +192 -0
  175. tnfr-4.5.2/tests/test_recent_glyph.py +49 -0
  176. tnfr-4.5.2/tests/test_register_callback.py +115 -0
  177. tnfr-4.5.2/tests/test_remesh.py +106 -0
  178. {tnfr-4.5.1 → tnfr-4.5.2}/tests/test_remesh_community.py +19 -5
  179. tnfr-4.5.2/tests/test_rng_base_seed.py +126 -0
  180. tnfr-4.5.2/tests/test_rng_for_step.py +44 -0
  181. tnfr-4.5.2/tests/test_safe_write.py +79 -0
  182. tnfr-4.5.2/tests/test_scenarios.py +40 -0
  183. tnfr-4.5.2/tests/test_selector_norms.py +36 -0
  184. tnfr-4.5.2/tests/test_selector_utils.py +136 -0
  185. tnfr-4.5.2/tests/test_sense.py +140 -0
  186. tnfr-4.5.2/tests/test_set_attr_error.py +10 -0
  187. tnfr-4.5.2/tests/test_si_helpers.py +110 -0
  188. tnfr-4.5.2/tests/test_stable_json.py +26 -0
  189. {tnfr-4.5.1 → tnfr-4.5.2}/tests/test_structural.py +46 -4
  190. tnfr-4.5.2/tests/test_topological_remesh.py +141 -0
  191. tnfr-4.5.2/tests/test_trace.py +149 -0
  192. tnfr-4.5.2/tests/test_trig_cache_reuse.py +74 -0
  193. tnfr-4.5.2/tests/test_update_tg_node.py +39 -0
  194. tnfr-4.5.2/tests/test_update_tg_performance.py +88 -0
  195. tnfr-4.5.2/tests/test_validate_aliases.py +30 -0
  196. tnfr-4.5.2/tests/test_validate_window.py +17 -0
  197. tnfr-4.5.2/tests/test_validators.py +120 -0
  198. tnfr-4.5.2/tests/test_value_utils.py +31 -0
  199. {tnfr-4.5.1 → tnfr-4.5.2}/tests/test_vf_coherencia.py +12 -6
  200. tnfr-4.5.2/tests/test_vf_dnfr_max_update.py +73 -0
  201. tnfr-4.5.2/tests/test_warn_failure_emit.py +62 -0
  202. tnfr-4.5.1/PKG-INFO +0 -221
  203. tnfr-4.5.1/README.md +0 -194
  204. tnfr-4.5.1/src/tnfr/__init__.py +0 -90
  205. tnfr-4.5.1/src/tnfr/cli.py +0 -322
  206. tnfr-4.5.1/src/tnfr/config.py +0 -41
  207. tnfr-4.5.1/src/tnfr/constants.py +0 -277
  208. tnfr-4.5.1/src/tnfr/dynamics.py +0 -814
  209. tnfr-4.5.1/src/tnfr/gamma.py +0 -127
  210. tnfr-4.5.1/src/tnfr/grammar.py +0 -155
  211. tnfr-4.5.1/src/tnfr/helpers.py +0 -264
  212. tnfr-4.5.1/src/tnfr/main.py +0 -47
  213. tnfr-4.5.1/src/tnfr/metrics.py +0 -597
  214. tnfr-4.5.1/src/tnfr/node.py +0 -202
  215. tnfr-4.5.1/src/tnfr/observers.py +0 -169
  216. tnfr-4.5.1/src/tnfr/ontosim.py +0 -140
  217. tnfr-4.5.1/src/tnfr/operators.py +0 -525
  218. tnfr-4.5.1/src/tnfr/presets.py +0 -28
  219. tnfr-4.5.1/src/tnfr/program.py +0 -176
  220. tnfr-4.5.1/src/tnfr/scenarios.py +0 -34
  221. tnfr-4.5.1/src/tnfr/sense.py +0 -200
  222. tnfr-4.5.1/src/tnfr/structural.py +0 -201
  223. tnfr-4.5.1/src/tnfr/trace.py +0 -134
  224. tnfr-4.5.1/src/tnfr/types.py +0 -18
  225. tnfr-4.5.1/src/tnfr/validators.py +0 -38
  226. tnfr-4.5.1/src/tnfr.egg-info/PKG-INFO +0 -221
  227. tnfr-4.5.1/src/tnfr.egg-info/SOURCES.txt +0 -47
  228. tnfr-4.5.1/src/tnfr.egg-info/requires.txt +0 -1
  229. tnfr-4.5.1/tests/test_cli_sanity.py +0 -12
  230. tnfr-4.5.1/tests/test_edge_cases.py +0 -30
  231. tnfr-4.5.1/tests/test_gamma.py +0 -20
  232. tnfr-4.5.1/tests/test_grammar.py +0 -69
  233. tnfr-4.5.1/tests/test_history.py +0 -15
  234. tnfr-4.5.1/tests/test_history_series.py +0 -27
  235. tnfr-4.5.1/tests/test_integrators.py +0 -36
  236. tnfr-4.5.1/tests/test_invariants.py +0 -89
  237. tnfr-4.5.1/tests/test_program.py +0 -17
  238. tnfr-4.5.1/tests/test_remesh.py +0 -50
  239. tnfr-4.5.1/tests/test_validators.py +0 -38
  240. {tnfr-4.5.1 → tnfr-4.5.2}/LICENSE.md +0 -0
  241. {tnfr-4.5.1 → tnfr-4.5.2}/setup.cfg +0 -0
  242. {tnfr-4.5.1 → tnfr-4.5.2}/src/tnfr.egg-info/dependency_links.txt +0 -0
  243. {tnfr-4.5.1 → tnfr-4.5.2}/src/tnfr.egg-info/entry_points.txt +0 -0
  244. {tnfr-4.5.1 → tnfr-4.5.2}/src/tnfr.egg-info/top_level.txt +0 -0
tnfr-4.5.2/PKG-INFO ADDED
@@ -0,0 +1,379 @@
1
+ Metadata-Version: 2.4
2
+ Name: tnfr
3
+ Version: 4.5.2
4
+ Summary: Modular structural-based dynamics on networks.
5
+ Author: fmg
6
+ License: MIT
7
+ Project-URL: Homepage, https://pypi.org/project/tnfr/
8
+ Project-URL: Repository, https://github.com/fermga/Teoria-de-la-naturaleza-fractal-resonante-TNFR-
9
+ Project-URL: GPT, https://chatgpt.com/g/g-67abc78885a88191b2d67f94fd60dc97-tnfr-teoria-de-la-naturaleza-fractal-resonante
10
+ Keywords: TNFR,complex systems,fractals,resonance,networks,structural dynamics,structural analysis
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Intended Audience :: Science/Research
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE.md
23
+ Requires-Dist: networkx>=2.6
24
+ Requires-Dist: cachetools>=5
25
+ Provides-Extra: numpy
26
+ Requires-Dist: numpy>=1.24; extra == "numpy"
27
+ Provides-Extra: yaml
28
+ Requires-Dist: pyyaml>=6.0; extra == "yaml"
29
+ Provides-Extra: orjson
30
+ Requires-Dist: orjson>=3; extra == "orjson"
31
+ Provides-Extra: test
32
+ Requires-Dist: pytest>=7; extra == "test"
33
+ Requires-Dist: pydocstyle>=6; extra == "test"
34
+ Dynamic: license-file
35
+
36
+ # TNFR Python Engine
37
+
38
+ Engine for **modeling, simulation and measurement** of multiscale structural coherence through **structural operators** (emission, reception, coherence, dissonance, coupling, resonance, silence, expansion, contraction, self‑organization, mutation, transition, recursivity).
39
+
40
+ ---
41
+
42
+ ## What is `tnfr`?
43
+
44
+ `tnfr` is a Python library to **operate with form**: build nodes, couple them into networks, and **modulate their coherence** over time using structural operators. It does not describe “things”; it **activates processes**. Its theoretical basis is the *Teoria de la Naturaleza Fractal Resonante (TNFR)*, which understands reality as **networks of coherence** that persist because they **resonate**.
45
+
46
+ In practical terms, `tnfr` lets you:
47
+
48
+ * Model **Resonant Fractal Nodes (NFR)** with parameters for **frequency** (νf), **phase** (θ), and **form** (EPI). Use the ASCII constants `VF_KEY` and `THETA_KEY` to reference these attributes programmatically; the Unicode names remain available as aliases.
49
+ * Apply **structural operators** to start, stabilize, propagate, or reconfigure coherence.
50
+ * **Simulate** nodal dynamics with discrete/continuous integrators.
51
+ * **Measure** global coherence C(t), nodal gradient ΔNFR, and the **Sense Index** (Si).
52
+ * **Visualize** states and trajectories (coupling matrices, C(t) curves, graphs).
53
+
54
+ A form emerges and persists when **internal reorganization** (ΔNFR) **resonates** with the node’s **frequency** (νf).
55
+
56
+ ## Quick start
57
+
58
+ ### Desde Python
59
+
60
+ ```python
61
+ from tnfr import create_nfr, run_sequence
62
+ from tnfr.structural import (
63
+ Emision,
64
+ Recepcion,
65
+ Coherencia,
66
+ Resonancia,
67
+ Silencio,
68
+ )
69
+ from tnfr.metrics.common import compute_coherence
70
+ from tnfr.metrics.sense_index import compute_Si
71
+
72
+ G, nodo = create_nfr("A", epi=0.2, vf=1.0, theta=0.0)
73
+ ops = [Emision(), Recepcion(), Coherencia(), Resonancia(), Silencio()]
74
+ run_sequence(G, nodo, ops)
75
+
76
+ C, delta_nfr_medio, depi_medio = compute_coherence(G, return_means=True)
77
+ si_por_nodo = compute_Si(G)
78
+ print(f"C(t)={C:.3f}, ΔNFR̄={delta_nfr_medio:.3f}, dEPI/dt̄={depi_medio:.3f}, Si={si_por_nodo[nodo]:.3f}")
79
+ ```
80
+
81
+ La secuencia respeta la ecuación nodal porque `create_nfr` inicializa el nodo con su **νf** y fase, y `run_sequence` valida la gramática TNFR antes de aplicar los operadores en el orden provisto. Tras cada operador invoca el gancho `compute_delta_nfr` del grafo para recalcular únicamente **ΔNFR** (por defecto usa `dnfr_epi_vf_mixed`, que mezcla EPI y νf sin alterar la fase). La fase solo cambiará si los propios operadores la modifican o si se ejecutan pasos dinámicos posteriores (por ejemplo `tnfr.dynamics.step` o `coordinate_global_local_phase`). Cuando necesites sincronización de fase automática, utiliza el ciclo de dinámica completo (`tnfr.dynamics.step`/`tnfr.dynamics.run`) o invoca explícitamente los coordinadores de fase después de `run_sequence`. Esa telemetría permite medir **C(t)** y **Si**, adelantando lo que se desarrolla en [Key concepts (operational summary)](#key-concepts-operational-summary) y [Main metrics](#main-metrics).
82
+
83
+ ### Desde la línea de comandos
84
+
85
+ Archivo `secuencia.json`:
86
+
87
+ ```json
88
+ [
89
+ "emision",
90
+ "recepcion",
91
+ "coherencia",
92
+ "resonancia",
93
+ "silencio"
94
+ ]
95
+ ```
96
+
97
+ ```bash
98
+ tnfr sequence --nodes 1 --sequence-file secuencia.json --save-history historia.json
99
+ ```
100
+
101
+ El subcomando `sequence` carga la trayectoria canónica del archivo JSON, ejecuta los operadores con la gramática oficial y actualiza **νf**, **ΔNFR** y fase usando los mismos ganchos que la API de Python. Al finalizar se vuelcan en `historia.json` las series de **C(t)**, **ΔNFR** medio y **Si**, que amplían las secciones sobre [operadores estructurales](#key-concepts-operational-summary) y [métricas](#main-metrics).
102
+
103
+ ---
104
+
105
+ ## Installation
106
+
107
+ ```bash
108
+ pip install tnfr
109
+ ```
110
+ * https://pypi.org/project/tnfr/
111
+ * Requires **Python ≥ 3.9**.
112
+ * Install extras:
113
+ * NumPy: `pip install tnfr[numpy]`
114
+ * YAML: `pip install tnfr[yaml]`
115
+ * orjson (faster JSON serialization): `pip install tnfr[orjson]`
116
+ * All: `pip install tnfr[numpy,yaml,orjson]`
117
+ * When `orjson` is unavailable the engine falls back to Python's built-in
118
+ `json` module.
119
+
120
+ ### Optional imports with cache
121
+
122
+ Use ``tnfr.cached_import`` to load optional dependencies and cache the result
123
+ via a process-wide LRU cache. Missing modules (or attributes) yield ``None``
124
+ without triggering repeated imports. The helper records failures and emits a
125
+ single warning per module to keep logs tidy. When optional packages are
126
+ installed at runtime call ``prune_failed_imports`` to clear the consolidated
127
+ failure/warning registry before retrying:
128
+
129
+ ```python
130
+ from tnfr import cached_import, prune_failed_imports
131
+
132
+ np = cached_import("numpy")
133
+ safe_load = cached_import("yaml", "safe_load")
134
+
135
+ # provide a shared cache with an explicit lock
136
+ from cachetools import TTLCache
137
+ import threading
138
+
139
+ cache = TTLCache(32, 60)
140
+ lock = threading.Lock()
141
+ cached_import("numpy", cache=cache, lock=lock)
142
+
143
+ # clear caches after installing a dependency at runtime
144
+ cached_import.cache_clear()
145
+ prune_failed_imports()
146
+ ```
147
+
148
+ ## Tests
149
+
150
+ Run the test suite from the project root using the helper script, which sets
151
+ the necessary `PYTHONPATH` and mirrors the checks described in
152
+ [`CONTRIBUTING.md`](CONTRIBUTING.md):
153
+
154
+ ```bash
155
+ ./scripts/run_tests.sh
156
+ ```
157
+
158
+ The script sequentially executes `pydocstyle`, `pytest` under `coverage`, the
159
+ coverage summary, and `vulture --min-confidence 80 src tests`. Avoid running
160
+ `pytest` directly or executing the script from other directories, as the
161
+ environment may be misconfigured and imports will fail. To pass additional
162
+ flags to `pytest`, append them after `--`, for example:
163
+
164
+ ```bash
165
+ ./scripts/run_tests.sh -- -k coherence
166
+ ```
167
+
168
+ ## Locking policy
169
+
170
+ The engine centralises reusable process-wide locks in
171
+ `tnfr.locking`. Modules obtain named locks via `locking.get_lock()` and
172
+ use the returned `threading.Lock` in their own critical sections. This
173
+ avoids scattering `threading.Lock` instances across the codebase and
174
+ ensures that shared resources are synchronised consistently.
175
+ Module-level caches or global state should always use these named
176
+ locks; only short-lived objects may instantiate ad-hoc locks directly
177
+ when they are not shared.
178
+
179
+ ---
180
+
181
+ ## Callback error handling
182
+
183
+ Callback errors are stored in a ring buffer attached to the graph. The
184
+ buffer retains at most the last 100 errors by default, but the limit can be
185
+ adjusted at runtime via ``tnfr.callback_utils.callback_manager.set_callback_error_limit``
186
+ and inspected with ``tnfr.callback_utils.callback_manager.get_callback_error_limit``.
187
+
188
+ ---
189
+
190
+ ## Helper utilities API
191
+
192
+ `tnfr.helpers` bundles a compact set of public helpers that stay stable across
193
+ releases. They provide ergonomic access to the most common preparation steps
194
+ when orchestrating TNFR experiments.
195
+
196
+ ### Collections and numeric helpers
197
+
198
+ * ``ensure_collection(it, *, max_materialize=...)`` — materialize potentially
199
+ lazy iterables once, enforcing a configurable limit to keep simulations
200
+ bounded.
201
+ * ``clamp(x, a, b)`` and ``clamp01(x)`` — restrict scalars to safe ranges for
202
+ operator parameters.
203
+ * ``kahan_sum_nd(values, dims)`` — numerically stable accumulators used to
204
+ track coherence magnitudes across long trajectories (use ``dims=1`` for
205
+ scalars, ``dims=2`` for paired values, etc.).
206
+ * ``angle_diff(a, b)`` — compute minimal angular differences (radians) to
207
+ compare structural phases.
208
+
209
+ ### Historial de operadores estructurales
210
+
211
+ * ``push_glyph(nd, glyph, window)`` — registra la aplicación de un operador en el
212
+ historial del nodo respetando la ventana configurada.
213
+ * ``recent_glyph(nd, glyph, window)`` — comprueba si un operador específico
214
+ aparece en el historial reciente de un nodo.
215
+ * ``ensure_history(G)`` — prepare the graph-level history container with the
216
+ appropriate bounds.
217
+ * ``last_glyph(nd)`` — inspecciona el último operador emitido por un nodo.
218
+ * ``count_glyphs(G, window=None, *, last_only=False)`` — agrega el uso de
219
+ operadores estructurales en la red ya sea desde todo el historial o una
220
+ ventana limitada.
221
+
222
+ ### Graph caches and ΔNFR invalidation
223
+
224
+ * ``cached_node_list(G)`` — lazily cache a stable tuple of node identifiers,
225
+ respecting opt-in sorted ordering.
226
+ * ``ensure_node_index_map(G)`` / ``ensure_node_offset_map(G)`` — expose cached
227
+ index and offset mappings for graphs that need to project nodes to arrays.
228
+ * ``node_set_checksum(G, nodes=None, *, presorted=False, store=True)`` —
229
+ produce deterministic BLAKE2b hashes to detect topology changes.
230
+ * ``stable_json(obj)`` — render deterministic JSON strings suited for hashing
231
+ and reproducible logs.
232
+ * ``get_graph(obj)`` / ``get_graph_mapping(G, key, warn_msg)`` — normalise
233
+ access to graph-level metadata regardless of wrappers.
234
+ * ``EdgeCacheManager`` together with ``edge_version_cache``,
235
+ ``cached_nodes_and_A`` and ``edge_version_update`` encapsulate the edge
236
+ version cache. ``increment_edge_version`` bumps the version manually for
237
+ imperative workflows.
238
+ * ``mark_dnfr_prep_dirty(G)`` — invalidate precomputed ΔNFR preparation when
239
+ mutating edges outside the cache helpers.
240
+
241
+ ---
242
+
243
+ ## Why TNFR (in 60 seconds)
244
+
245
+ * **From objects to coherences:** you model **processes** that hold, not fixed entities.
246
+ * **Operators instead of rules:** you compose **structural operators** (e.g., *emission*, *coherence*, *dissonance*) to **build trajectories**.
247
+ * **Operational fractality:** the same pattern works for **ideas, teams, tissues, narratives**; the scales change, **the logic doesn’t**.
248
+
249
+ ---
250
+
251
+ ## Key concepts (operational summary)
252
+
253
+ * **Node (NFR):** a unit that persists because it **resonates**. Parameterized by **νf** (frequency), **θ** (phase), and **EPI** (coherent form).
254
+ * **Structural operators** - functions that reorganize the network:
255
+
256
+ * **Emission** (start), **Reception** (open), **Coherence** (stabilize), **Dissonance** (creative tension), **Coupling** (synchrony), **Resonance** (propagate), **Silence** (latency), **Expansion**, **Contraction**, **Self‑organization**, **Mutation**, **Transition**, **Recursivity**.
257
+ * **Magnitudes:**
258
+
259
+ * **C(t):** global coherence.
260
+ * **ΔNFR:** nodal gradient (need for reorganization).
261
+ * **νf:** structural frequency (Hz\_str).
262
+ * **Si:** sense index (ability to generate stable shared coherence).
263
+
264
+ ---
265
+
266
+ ## Typical workflow
267
+
268
+ 1. **Model** your system as a network: nodes (agents, ideas, tissues, modules) and couplings.
269
+ 2. **Select** a **trajectory of operators** aligned with your goal (e.g., *start → couple → stabilize*).
270
+ 3. **Simulate** the dynamics: number of steps, step size, tolerances.
271
+ 4. **Measure**: C(t), ΔNFR, Si; identify bifurcations and collapses.
272
+ 5. **Iterate** with controlled **dissonance** to open mutations without losing form.
273
+
274
+ ---
275
+
276
+ ## Main metrics
277
+
278
+ * `coherence(traj) → C(t)`: global stability; higher values indicate sustained form.
279
+ * `gradient(state) → ΔNFR`: local demand for reorganization (high = risk of collapse/bifurcation).
280
+ * `sense_index(traj) → Si`: proxy for **structural sense** (capacity to generate shared coherence) combining **νf**, phase, and topology.
281
+
282
+ ## Topological remeshing
283
+
284
+ Use ``tnfr.operators.apply_topological_remesh`` (``from tnfr.operators import apply_topological_remesh``)
285
+ to reorganize connectivity based on nodal EPI similarity while preserving
286
+ graph connectivity. Modes:
287
+
288
+ - ``"knn"`` – connect each node to its ``k`` nearest neighbours (with optional
289
+ rewiring).
290
+ - ``"mst"`` – retain only a minimum spanning tree.
291
+ - ``"community"`` – collapse modular communities and reconnect them by
292
+ similarity.
293
+
294
+ All modes ensure connectivity by adding a base MST.
295
+
296
+ ---
297
+
298
+ ## History configuration
299
+
300
+ Recorded series are stored under `G.graph['history']`. Set `HISTORY_MAXLEN` in
301
+ the graph (or override the default) to keep only the most recent entries. The
302
+ value must be non‑negative; negative values raise ``ValueError``. When the
303
+ limit is positive the library uses bounded `deque` objects and removes the
304
+ least populated series when the number of history keys grows beyond the limit.
305
+
306
+ ### Random node sampling
307
+
308
+ To reduce costly comparisons the engine stores a per‑step random subset of
309
+ node ids under `G.graph['_node_sample']`. Operators may use this to avoid
310
+ scanning the whole network. Sampling is skipped automatically when the graph
311
+ has fewer than **50 nodes**, in which case all nodes are included.
312
+
313
+ ### Jitter RNG cache
314
+
315
+ `random_jitter` uses an LRU cache of `random.Random` instances keyed by `(seed, node)`.
316
+ `JITTER_CACHE_SIZE` controls the maximum number of cached generators (default: `256`);
317
+ when the limit is exceeded the least‑recently used entry is discarded. Increase it for
318
+ large graphs or heavy jitter usage, or lower it to save memory.
319
+
320
+ To adjust the number of cached jitter sequences used for deterministic noise,
321
+ obtain the manager with ``get_jitter_manager`` before calling ``setup``:
322
+
323
+ ```python
324
+ from tnfr.operators import get_jitter_manager
325
+
326
+ manager = get_jitter_manager()
327
+ # Resize cache to keep only 512 entries
328
+ manager.max_entries = 512
329
+
330
+ # or in a single call that also clears previous counters
331
+ manager.setup(max_entries=512)
332
+ ```
333
+
334
+ ``setup`` preserves the current size unless a new ``max_entries`` value is
335
+ supplied. Custom sizes persist across subsequent ``setup`` calls, and
336
+ ``max_entries`` assignments take effect immediately.
337
+
338
+ ### Edge version tracking
339
+
340
+ Wrap sequences of edge mutations with `edge_version_update(G)` so the edge
341
+ version increments on entry and exit. This keeps caches and structural logs
342
+ aligned with the network's evolution.
343
+
344
+ ### Defaults injection performance
345
+
346
+ `inject_defaults` evita copias profundas cuando los valores son inmutables (números,
347
+ cadenas, tuplas). Solo se usa `copy.deepcopy` para estructuras mutables, reduciendo
348
+ el costo de inicializar grafos con parámetros por defecto.
349
+
350
+ ---
351
+
352
+ ## Trained GPT
353
+
354
+ https://chatgpt.com/g/g-67abc78885a88191b2d67f94fd60dc97-tnfr-teoria-de-la-naturaleza-fractal-resonante
355
+
356
+ ---
357
+
358
+ ## Changelog
359
+
360
+ * Removed deprecated alias `sigma_vector_global`; use `sigma_vector_from_graph` instead.
361
+ * Removed legacy `tnfr.program` alias; import programming helpers from `tnfr.execution`.
362
+ * Stopped re-exporting ``CallbackSpec`` and ``apply_topological_remesh`` at the
363
+ package root; import them via ``tnfr.trace`` and ``tnfr.operators``.
364
+
365
+ ---
366
+
367
+ ## MIT License
368
+
369
+ Copyright (c) 2025 TNFR - Teoría de la naturaleza fractral resonante
370
+
371
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
372
+
373
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
374
+
375
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
376
+
377
+ ---
378
+
379
+ If you use `tnfr` in research or projects, please cite the TNFR conceptual framework and link to the PyPI package.