tnfr 3.0.3__py3-none-any.whl → 8.5.0__py3-none-any.whl
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.
- tnfr/__init__.py +375 -56
- tnfr/__init__.pyi +33 -0
- tnfr/_compat.py +10 -0
- tnfr/_generated_version.py +34 -0
- tnfr/_version.py +49 -0
- tnfr/_version.pyi +7 -0
- tnfr/alias.py +723 -0
- tnfr/alias.pyi +108 -0
- tnfr/backends/__init__.py +354 -0
- tnfr/backends/jax_backend.py +173 -0
- tnfr/backends/numpy_backend.py +238 -0
- tnfr/backends/optimized_numpy.py +420 -0
- tnfr/backends/torch_backend.py +408 -0
- tnfr/cache.py +171 -0
- tnfr/cache.pyi +13 -0
- tnfr/cli/__init__.py +110 -0
- tnfr/cli/__init__.pyi +26 -0
- tnfr/cli/arguments.py +489 -0
- tnfr/cli/arguments.pyi +29 -0
- tnfr/cli/execution.py +914 -0
- tnfr/cli/execution.pyi +70 -0
- tnfr/cli/interactive_validator.py +614 -0
- tnfr/cli/utils.py +51 -0
- tnfr/cli/utils.pyi +7 -0
- tnfr/cli/validate.py +236 -0
- tnfr/compat/__init__.py +85 -0
- tnfr/compat/dataclass.py +136 -0
- tnfr/compat/jsonschema_stub.py +61 -0
- tnfr/compat/matplotlib_stub.py +73 -0
- tnfr/compat/numpy_stub.py +155 -0
- tnfr/config/__init__.py +224 -0
- tnfr/config/__init__.pyi +10 -0
- tnfr/config/constants.py +104 -0
- tnfr/config/constants.pyi +12 -0
- tnfr/config/defaults.py +54 -0
- tnfr/config/defaults_core.py +212 -0
- tnfr/config/defaults_init.py +33 -0
- tnfr/config/defaults_metric.py +104 -0
- tnfr/config/feature_flags.py +81 -0
- tnfr/config/feature_flags.pyi +16 -0
- tnfr/config/glyph_constants.py +31 -0
- tnfr/config/init.py +77 -0
- tnfr/config/init.pyi +8 -0
- tnfr/config/operator_names.py +254 -0
- tnfr/config/operator_names.pyi +36 -0
- tnfr/config/physics_derivation.py +354 -0
- tnfr/config/presets.py +83 -0
- tnfr/config/presets.pyi +7 -0
- tnfr/config/security.py +927 -0
- tnfr/config/thresholds.py +114 -0
- tnfr/config/tnfr_config.py +498 -0
- tnfr/constants/__init__.py +92 -0
- tnfr/constants/__init__.pyi +92 -0
- tnfr/constants/aliases.py +33 -0
- tnfr/constants/aliases.pyi +27 -0
- tnfr/constants/init.py +33 -0
- tnfr/constants/init.pyi +12 -0
- tnfr/constants/metric.py +104 -0
- tnfr/constants/metric.pyi +19 -0
- tnfr/core/__init__.py +33 -0
- tnfr/core/container.py +226 -0
- tnfr/core/default_implementations.py +329 -0
- tnfr/core/interfaces.py +279 -0
- tnfr/dynamics/__init__.py +238 -0
- tnfr/dynamics/__init__.pyi +83 -0
- tnfr/dynamics/adaptation.py +267 -0
- tnfr/dynamics/adaptation.pyi +7 -0
- tnfr/dynamics/adaptive_sequences.py +189 -0
- tnfr/dynamics/adaptive_sequences.pyi +14 -0
- tnfr/dynamics/aliases.py +23 -0
- tnfr/dynamics/aliases.pyi +19 -0
- tnfr/dynamics/bifurcation.py +232 -0
- tnfr/dynamics/canonical.py +229 -0
- tnfr/dynamics/canonical.pyi +48 -0
- tnfr/dynamics/coordination.py +385 -0
- tnfr/dynamics/coordination.pyi +25 -0
- tnfr/dynamics/dnfr.py +3034 -0
- tnfr/dynamics/dnfr.pyi +26 -0
- tnfr/dynamics/dynamic_limits.py +225 -0
- tnfr/dynamics/feedback.py +252 -0
- tnfr/dynamics/feedback.pyi +24 -0
- tnfr/dynamics/fused_dnfr.py +454 -0
- tnfr/dynamics/homeostasis.py +157 -0
- tnfr/dynamics/homeostasis.pyi +14 -0
- tnfr/dynamics/integrators.py +661 -0
- tnfr/dynamics/integrators.pyi +36 -0
- tnfr/dynamics/learning.py +310 -0
- tnfr/dynamics/learning.pyi +33 -0
- tnfr/dynamics/metabolism.py +254 -0
- tnfr/dynamics/nbody.py +796 -0
- tnfr/dynamics/nbody_tnfr.py +783 -0
- tnfr/dynamics/propagation.py +326 -0
- tnfr/dynamics/runtime.py +908 -0
- tnfr/dynamics/runtime.pyi +77 -0
- tnfr/dynamics/sampling.py +36 -0
- tnfr/dynamics/sampling.pyi +7 -0
- tnfr/dynamics/selectors.py +711 -0
- tnfr/dynamics/selectors.pyi +85 -0
- tnfr/dynamics/structural_clip.py +207 -0
- tnfr/errors/__init__.py +37 -0
- tnfr/errors/contextual.py +492 -0
- tnfr/execution.py +223 -0
- tnfr/execution.pyi +45 -0
- tnfr/extensions/__init__.py +205 -0
- tnfr/extensions/__init__.pyi +18 -0
- tnfr/extensions/base.py +173 -0
- tnfr/extensions/base.pyi +35 -0
- tnfr/extensions/business/__init__.py +71 -0
- tnfr/extensions/business/__init__.pyi +11 -0
- tnfr/extensions/business/cookbook.py +88 -0
- tnfr/extensions/business/cookbook.pyi +8 -0
- tnfr/extensions/business/health_analyzers.py +202 -0
- tnfr/extensions/business/health_analyzers.pyi +9 -0
- tnfr/extensions/business/patterns.py +183 -0
- tnfr/extensions/business/patterns.pyi +8 -0
- tnfr/extensions/medical/__init__.py +73 -0
- tnfr/extensions/medical/__init__.pyi +11 -0
- tnfr/extensions/medical/cookbook.py +88 -0
- tnfr/extensions/medical/cookbook.pyi +8 -0
- tnfr/extensions/medical/health_analyzers.py +181 -0
- tnfr/extensions/medical/health_analyzers.pyi +9 -0
- tnfr/extensions/medical/patterns.py +163 -0
- tnfr/extensions/medical/patterns.pyi +8 -0
- tnfr/flatten.py +262 -0
- tnfr/flatten.pyi +21 -0
- tnfr/gamma.py +354 -0
- tnfr/gamma.pyi +36 -0
- tnfr/glyph_history.py +377 -0
- tnfr/glyph_history.pyi +35 -0
- tnfr/glyph_runtime.py +19 -0
- tnfr/glyph_runtime.pyi +8 -0
- tnfr/immutable.py +218 -0
- tnfr/immutable.pyi +36 -0
- tnfr/initialization.py +203 -0
- tnfr/initialization.pyi +65 -0
- tnfr/io.py +10 -0
- tnfr/io.pyi +13 -0
- tnfr/locking.py +37 -0
- tnfr/locking.pyi +7 -0
- tnfr/mathematics/__init__.py +79 -0
- tnfr/mathematics/backend.py +453 -0
- tnfr/mathematics/backend.pyi +99 -0
- tnfr/mathematics/dynamics.py +408 -0
- tnfr/mathematics/dynamics.pyi +90 -0
- tnfr/mathematics/epi.py +391 -0
- tnfr/mathematics/epi.pyi +65 -0
- tnfr/mathematics/generators.py +242 -0
- tnfr/mathematics/generators.pyi +29 -0
- tnfr/mathematics/metrics.py +119 -0
- tnfr/mathematics/metrics.pyi +16 -0
- tnfr/mathematics/operators.py +239 -0
- tnfr/mathematics/operators.pyi +59 -0
- tnfr/mathematics/operators_factory.py +124 -0
- tnfr/mathematics/operators_factory.pyi +11 -0
- tnfr/mathematics/projection.py +87 -0
- tnfr/mathematics/projection.pyi +33 -0
- tnfr/mathematics/runtime.py +182 -0
- tnfr/mathematics/runtime.pyi +64 -0
- tnfr/mathematics/spaces.py +256 -0
- tnfr/mathematics/spaces.pyi +83 -0
- tnfr/mathematics/transforms.py +305 -0
- tnfr/mathematics/transforms.pyi +62 -0
- tnfr/metrics/__init__.py +79 -0
- tnfr/metrics/__init__.pyi +20 -0
- tnfr/metrics/buffer_cache.py +163 -0
- tnfr/metrics/buffer_cache.pyi +24 -0
- tnfr/metrics/cache_utils.py +214 -0
- tnfr/metrics/coherence.py +2009 -0
- tnfr/metrics/coherence.pyi +129 -0
- tnfr/metrics/common.py +158 -0
- tnfr/metrics/common.pyi +35 -0
- tnfr/metrics/core.py +316 -0
- tnfr/metrics/core.pyi +13 -0
- tnfr/metrics/diagnosis.py +833 -0
- tnfr/metrics/diagnosis.pyi +86 -0
- tnfr/metrics/emergence.py +245 -0
- tnfr/metrics/export.py +179 -0
- tnfr/metrics/export.pyi +7 -0
- tnfr/metrics/glyph_timing.py +379 -0
- tnfr/metrics/glyph_timing.pyi +81 -0
- tnfr/metrics/learning_metrics.py +280 -0
- tnfr/metrics/learning_metrics.pyi +21 -0
- tnfr/metrics/phase_coherence.py +351 -0
- tnfr/metrics/phase_compatibility.py +349 -0
- tnfr/metrics/reporting.py +183 -0
- tnfr/metrics/reporting.pyi +25 -0
- tnfr/metrics/sense_index.py +1203 -0
- tnfr/metrics/sense_index.pyi +9 -0
- tnfr/metrics/trig.py +373 -0
- tnfr/metrics/trig.pyi +13 -0
- tnfr/metrics/trig_cache.py +233 -0
- tnfr/metrics/trig_cache.pyi +10 -0
- tnfr/multiscale/__init__.py +32 -0
- tnfr/multiscale/hierarchical.py +517 -0
- tnfr/node.py +763 -0
- tnfr/node.pyi +139 -0
- tnfr/observers.py +255 -130
- tnfr/observers.pyi +31 -0
- tnfr/ontosim.py +144 -137
- tnfr/ontosim.pyi +28 -0
- tnfr/operators/__init__.py +1672 -0
- tnfr/operators/__init__.pyi +31 -0
- tnfr/operators/algebra.py +277 -0
- tnfr/operators/canonical_patterns.py +420 -0
- tnfr/operators/cascade.py +267 -0
- tnfr/operators/cycle_detection.py +358 -0
- tnfr/operators/definitions.py +4108 -0
- tnfr/operators/definitions.pyi +78 -0
- tnfr/operators/grammar.py +1164 -0
- tnfr/operators/grammar.pyi +140 -0
- tnfr/operators/hamiltonian.py +710 -0
- tnfr/operators/health_analyzer.py +809 -0
- tnfr/operators/jitter.py +272 -0
- tnfr/operators/jitter.pyi +11 -0
- tnfr/operators/lifecycle.py +314 -0
- tnfr/operators/metabolism.py +618 -0
- tnfr/operators/metrics.py +2138 -0
- tnfr/operators/network_analysis/__init__.py +27 -0
- tnfr/operators/network_analysis/source_detection.py +186 -0
- tnfr/operators/nodal_equation.py +395 -0
- tnfr/operators/pattern_detection.py +660 -0
- tnfr/operators/patterns.py +669 -0
- tnfr/operators/postconditions/__init__.py +38 -0
- tnfr/operators/postconditions/mutation.py +236 -0
- tnfr/operators/preconditions/__init__.py +1226 -0
- tnfr/operators/preconditions/coherence.py +305 -0
- tnfr/operators/preconditions/dissonance.py +236 -0
- tnfr/operators/preconditions/emission.py +128 -0
- tnfr/operators/preconditions/mutation.py +580 -0
- tnfr/operators/preconditions/reception.py +125 -0
- tnfr/operators/preconditions/resonance.py +364 -0
- tnfr/operators/registry.py +74 -0
- tnfr/operators/registry.pyi +9 -0
- tnfr/operators/remesh.py +1809 -0
- tnfr/operators/remesh.pyi +26 -0
- tnfr/operators/structural_units.py +268 -0
- tnfr/operators/unified_grammar.py +105 -0
- tnfr/parallel/__init__.py +54 -0
- tnfr/parallel/auto_scaler.py +234 -0
- tnfr/parallel/distributed.py +384 -0
- tnfr/parallel/engine.py +238 -0
- tnfr/parallel/gpu_engine.py +420 -0
- tnfr/parallel/monitoring.py +248 -0
- tnfr/parallel/partitioner.py +459 -0
- tnfr/py.typed +0 -0
- tnfr/recipes/__init__.py +22 -0
- tnfr/recipes/cookbook.py +743 -0
- tnfr/rng.py +178 -0
- tnfr/rng.pyi +26 -0
- tnfr/schemas/__init__.py +8 -0
- tnfr/schemas/grammar.json +94 -0
- tnfr/sdk/__init__.py +107 -0
- tnfr/sdk/__init__.pyi +19 -0
- tnfr/sdk/adaptive_system.py +173 -0
- tnfr/sdk/adaptive_system.pyi +21 -0
- tnfr/sdk/builders.py +370 -0
- tnfr/sdk/builders.pyi +51 -0
- tnfr/sdk/fluent.py +1121 -0
- tnfr/sdk/fluent.pyi +74 -0
- tnfr/sdk/templates.py +342 -0
- tnfr/sdk/templates.pyi +41 -0
- tnfr/sdk/utils.py +341 -0
- tnfr/secure_config.py +46 -0
- tnfr/security/__init__.py +70 -0
- tnfr/security/database.py +514 -0
- tnfr/security/subprocess.py +503 -0
- tnfr/security/validation.py +290 -0
- tnfr/selector.py +247 -0
- tnfr/selector.pyi +19 -0
- tnfr/sense.py +378 -0
- tnfr/sense.pyi +23 -0
- tnfr/services/__init__.py +17 -0
- tnfr/services/orchestrator.py +325 -0
- tnfr/sparse/__init__.py +39 -0
- tnfr/sparse/representations.py +492 -0
- tnfr/structural.py +705 -0
- tnfr/structural.pyi +83 -0
- tnfr/telemetry/__init__.py +35 -0
- tnfr/telemetry/cache_metrics.py +226 -0
- tnfr/telemetry/cache_metrics.pyi +64 -0
- tnfr/telemetry/nu_f.py +422 -0
- tnfr/telemetry/nu_f.pyi +108 -0
- tnfr/telemetry/verbosity.py +36 -0
- tnfr/telemetry/verbosity.pyi +15 -0
- tnfr/tokens.py +58 -0
- tnfr/tokens.pyi +36 -0
- tnfr/tools/__init__.py +20 -0
- tnfr/tools/domain_templates.py +478 -0
- tnfr/tools/sequence_generator.py +846 -0
- tnfr/topology/__init__.py +13 -0
- tnfr/topology/asymmetry.py +151 -0
- tnfr/trace.py +543 -0
- tnfr/trace.pyi +42 -0
- tnfr/tutorials/__init__.py +38 -0
- tnfr/tutorials/autonomous_evolution.py +285 -0
- tnfr/tutorials/interactive.py +1576 -0
- tnfr/tutorials/structural_metabolism.py +238 -0
- tnfr/types.py +775 -0
- tnfr/types.pyi +357 -0
- tnfr/units.py +68 -0
- tnfr/units.pyi +13 -0
- tnfr/utils/__init__.py +282 -0
- tnfr/utils/__init__.pyi +215 -0
- tnfr/utils/cache.py +4223 -0
- tnfr/utils/cache.pyi +470 -0
- tnfr/utils/callbacks.py +375 -0
- tnfr/utils/callbacks.pyi +49 -0
- tnfr/utils/chunks.py +108 -0
- tnfr/utils/chunks.pyi +22 -0
- tnfr/utils/data.py +428 -0
- tnfr/utils/data.pyi +74 -0
- tnfr/utils/graph.py +85 -0
- tnfr/utils/graph.pyi +10 -0
- tnfr/utils/init.py +821 -0
- tnfr/utils/init.pyi +80 -0
- tnfr/utils/io.py +559 -0
- tnfr/utils/io.pyi +66 -0
- tnfr/utils/numeric.py +114 -0
- tnfr/utils/numeric.pyi +21 -0
- tnfr/validation/__init__.py +257 -0
- tnfr/validation/__init__.pyi +85 -0
- tnfr/validation/compatibility.py +460 -0
- tnfr/validation/compatibility.pyi +6 -0
- tnfr/validation/config.py +73 -0
- tnfr/validation/graph.py +139 -0
- tnfr/validation/graph.pyi +18 -0
- tnfr/validation/input_validation.py +755 -0
- tnfr/validation/invariants.py +712 -0
- tnfr/validation/rules.py +253 -0
- tnfr/validation/rules.pyi +44 -0
- tnfr/validation/runtime.py +279 -0
- tnfr/validation/runtime.pyi +28 -0
- tnfr/validation/sequence_validator.py +162 -0
- tnfr/validation/soft_filters.py +170 -0
- tnfr/validation/soft_filters.pyi +32 -0
- tnfr/validation/spectral.py +164 -0
- tnfr/validation/spectral.pyi +42 -0
- tnfr/validation/validator.py +1266 -0
- tnfr/validation/window.py +39 -0
- tnfr/validation/window.pyi +1 -0
- tnfr/visualization/__init__.py +98 -0
- tnfr/visualization/cascade_viz.py +256 -0
- tnfr/visualization/hierarchy.py +284 -0
- tnfr/visualization/sequence_plotter.py +784 -0
- tnfr/viz/__init__.py +60 -0
- tnfr/viz/matplotlib.py +278 -0
- tnfr/viz/matplotlib.pyi +35 -0
- tnfr-8.5.0.dist-info/METADATA +573 -0
- tnfr-8.5.0.dist-info/RECORD +353 -0
- tnfr-8.5.0.dist-info/entry_points.txt +3 -0
- tnfr-3.0.3.dist-info/licenses/LICENSE.txt → tnfr-8.5.0.dist-info/licenses/LICENSE.md +1 -1
- tnfr/constants.py +0 -183
- tnfr/dynamics.py +0 -543
- tnfr/helpers.py +0 -198
- tnfr/main.py +0 -37
- tnfr/operators.py +0 -296
- tnfr-3.0.3.dist-info/METADATA +0 -35
- tnfr-3.0.3.dist-info/RECORD +0 -13
- {tnfr-3.0.3.dist-info → tnfr-8.5.0.dist-info}/WHEEL +0 -0
- {tnfr-3.0.3.dist-info → tnfr-8.5.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
"""Canonical operator sequences and archetypal patterns from TNFR theory.
|
|
2
|
+
|
|
3
|
+
.. deprecated:: 0.2.0
|
|
4
|
+
This module is deprecated and will be removed in version 1.0.0.
|
|
5
|
+
Use :mod:`tnfr.operators.pattern_detection` instead, which provides unified
|
|
6
|
+
pattern detection with explicit U1-U4 grammar rule mappings.
|
|
7
|
+
|
|
8
|
+
For canonical sequences, this module remains the authoritative source.
|
|
9
|
+
For pattern detection, use the new unified module.
|
|
10
|
+
|
|
11
|
+
This module defines the 6 canonical archetypal sequences involving OZ (Dissonance)
|
|
12
|
+
as documented in "El pulso que nos atraviesa" (Table 2.5 - Glyphic structural typology).
|
|
13
|
+
|
|
14
|
+
These sequences represent validated structural patterns that can be reused across
|
|
15
|
+
different domains and applications while maintaining TNFR coherence and grammar.
|
|
16
|
+
|
|
17
|
+
References
|
|
18
|
+
----------
|
|
19
|
+
"El pulso que nos atraviesa", Table 2.5: Glyphic structural typology
|
|
20
|
+
Section 2.3.8: Complete examples
|
|
21
|
+
Section 2.3.5: Advanced glyphic writing (Glyphic macros)
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
import warnings
|
|
27
|
+
from typing import Dict, List, NamedTuple
|
|
28
|
+
|
|
29
|
+
# Issue deprecation warning on import
|
|
30
|
+
warnings.warn(
|
|
31
|
+
"canonical_patterns module is deprecated. "
|
|
32
|
+
"For pattern detection, use tnfr.operators.pattern_detection instead. "
|
|
33
|
+
"Canonical sequences remain available here for backward compatibility.",
|
|
34
|
+
DeprecationWarning,
|
|
35
|
+
stacklevel=2,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
from ..types import Glyph
|
|
39
|
+
from .grammar import StructuralPattern
|
|
40
|
+
|
|
41
|
+
__all__ = [
|
|
42
|
+
"CanonicalSequence",
|
|
43
|
+
"CANONICAL_SEQUENCES",
|
|
44
|
+
"BIFURCATED_BASE",
|
|
45
|
+
"BIFURCATED_COLLAPSE",
|
|
46
|
+
"THERAPEUTIC_PROTOCOL",
|
|
47
|
+
"THEORY_SYSTEM",
|
|
48
|
+
"FULL_DEPLOYMENT",
|
|
49
|
+
"MOD_STABILIZER",
|
|
50
|
+
# New variants unlocked by high → zero frequency transition
|
|
51
|
+
"CONTAINED_CRISIS",
|
|
52
|
+
"RESONANCE_PEAK_HOLD",
|
|
53
|
+
"MINIMAL_COMPRESSION",
|
|
54
|
+
"PHASE_LOCK",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class CanonicalSequence(NamedTuple):
|
|
59
|
+
"""Canonical operator sequence with theoretical metadata.
|
|
60
|
+
|
|
61
|
+
Represents a validated archetypal sequence from TNFR theory with
|
|
62
|
+
structural pattern classification, use cases, and domain context.
|
|
63
|
+
|
|
64
|
+
Attributes
|
|
65
|
+
----------
|
|
66
|
+
name : str
|
|
67
|
+
Unique identifier for the sequence (e.g., 'bifurcated_base')
|
|
68
|
+
glyphs : List[Glyph]
|
|
69
|
+
Ordered sequence of structural glyphs (AL, EN, IL, OZ, etc.)
|
|
70
|
+
pattern_type : StructuralPattern
|
|
71
|
+
Structural pattern classification from grammar
|
|
72
|
+
description : str
|
|
73
|
+
Detailed explanation of structural function
|
|
74
|
+
use_cases : List[str]
|
|
75
|
+
Concrete application scenarios
|
|
76
|
+
domain : str
|
|
77
|
+
Primary domain: 'general', 'biomedical', 'cognitive', 'social'
|
|
78
|
+
references : str
|
|
79
|
+
Theoretical grounding from TNFR documentation
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
name: str
|
|
83
|
+
glyphs: List[Glyph]
|
|
84
|
+
pattern_type: StructuralPattern
|
|
85
|
+
description: str
|
|
86
|
+
use_cases: List[str]
|
|
87
|
+
domain: str
|
|
88
|
+
references: str
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
# ============================================================================
|
|
92
|
+
# Bifurcated Patterns: OZ creates decision points
|
|
93
|
+
# ============================================================================
|
|
94
|
+
|
|
95
|
+
BIFURCATED_BASE = CanonicalSequence(
|
|
96
|
+
name="bifurcated_base",
|
|
97
|
+
glyphs=[Glyph.AL, Glyph.EN, Glyph.IL, Glyph.OZ, Glyph.ZHIR, Glyph.IL, Glyph.SHA],
|
|
98
|
+
pattern_type=StructuralPattern.BIFURCATED,
|
|
99
|
+
description=(
|
|
100
|
+
"Structural dissonance that generates bifurcation threshold. "
|
|
101
|
+
"The node can reorganize (ZHIR) or collapse to latency (NUL). "
|
|
102
|
+
"This pattern represents the creative resolution of dissonance "
|
|
103
|
+
"through transformative mutation. "
|
|
104
|
+
"Includes EN → IL (reception→coherence) for grammar validation."
|
|
105
|
+
),
|
|
106
|
+
use_cases=[
|
|
107
|
+
"Therapeutic intervention for emotional or cognitive blockages",
|
|
108
|
+
"Analysis of cultural crises or paradigms under tension",
|
|
109
|
+
"Design of systems with adaptive response to perturbations",
|
|
110
|
+
"Modeling of decision points in complex networks",
|
|
111
|
+
],
|
|
112
|
+
domain="general",
|
|
113
|
+
references="El pulso que nos atraviesa, Table 2.5, Section 2.3.4 (Bifurcation)",
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
BIFURCATED_COLLAPSE = CanonicalSequence(
|
|
117
|
+
name="bifurcated_collapse",
|
|
118
|
+
glyphs=[Glyph.AL, Glyph.EN, Glyph.IL, Glyph.OZ, Glyph.NUL, Glyph.IL, Glyph.SHA],
|
|
119
|
+
pattern_type=StructuralPattern.BIFURCATED,
|
|
120
|
+
description=(
|
|
121
|
+
"Alternative bifurcation path: dissonance leads to controlled collapse (NUL) "
|
|
122
|
+
"instead of mutation. Useful for structural reset when transformation "
|
|
123
|
+
"is not viable. The node returns to latency preserving potentiality. "
|
|
124
|
+
"Includes EN → IL (reception→coherence) for grammar validation."
|
|
125
|
+
),
|
|
126
|
+
use_cases=[
|
|
127
|
+
"Cognitive reset after informational overload",
|
|
128
|
+
"Strategic organizational disinvestment",
|
|
129
|
+
"Return to potentiality after failed exploration",
|
|
130
|
+
"Structural simplification facing unsustainable complexity",
|
|
131
|
+
],
|
|
132
|
+
domain="general",
|
|
133
|
+
references="El pulso que nos atraviesa, Section 2.3.3 (Bifurcation and mutation)",
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
# ============================================================================
|
|
138
|
+
# Therapeutic Protocol: Reorganization Ritual
|
|
139
|
+
# ============================================================================
|
|
140
|
+
|
|
141
|
+
THERAPEUTIC_PROTOCOL = CanonicalSequence(
|
|
142
|
+
name="therapeutic_protocol",
|
|
143
|
+
glyphs=[
|
|
144
|
+
Glyph.AL,
|
|
145
|
+
Glyph.EN,
|
|
146
|
+
Glyph.IL,
|
|
147
|
+
Glyph.OZ,
|
|
148
|
+
Glyph.ZHIR,
|
|
149
|
+
Glyph.IL,
|
|
150
|
+
Glyph.RA,
|
|
151
|
+
Glyph.IL,
|
|
152
|
+
Glyph.SHA,
|
|
153
|
+
],
|
|
154
|
+
pattern_type=StructuralPattern.THERAPEUTIC,
|
|
155
|
+
description=(
|
|
156
|
+
"Ritual or therapeutic protocol: symbolic emission (AL), stabilizing "
|
|
157
|
+
"reception (EN), initial coherence (IL), creative dissonance as "
|
|
158
|
+
"confrontation (OZ), subject mutation (ZHIR), stabilization of the "
|
|
159
|
+
"new form (IL), resonant propagation (RA), post-resonance stabilization (IL), "
|
|
160
|
+
"entry into latency (SHA). Personal or collective transformation cycle with "
|
|
161
|
+
"creative resolution and coherent frequency transitions."
|
|
162
|
+
),
|
|
163
|
+
use_cases=[
|
|
164
|
+
"Personal transformation or initiation ceremonies",
|
|
165
|
+
"Deep therapeutic restructuring sessions",
|
|
166
|
+
"Symbolic accompaniment of vital change processes",
|
|
167
|
+
"Collective or community healing rituals",
|
|
168
|
+
],
|
|
169
|
+
domain="biomedical",
|
|
170
|
+
references="El pulso que nos atraviesa, Ejemplo 3 (Sección 2.3.8)",
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
# ============================================================================
|
|
175
|
+
# Theory System: Epistemological Construction
|
|
176
|
+
# ============================================================================
|
|
177
|
+
|
|
178
|
+
THEORY_SYSTEM = CanonicalSequence(
|
|
179
|
+
name="theory_system",
|
|
180
|
+
glyphs=[
|
|
181
|
+
Glyph.AL,
|
|
182
|
+
Glyph.EN,
|
|
183
|
+
Glyph.IL,
|
|
184
|
+
Glyph.OZ,
|
|
185
|
+
Glyph.ZHIR,
|
|
186
|
+
Glyph.IL,
|
|
187
|
+
Glyph.THOL,
|
|
188
|
+
Glyph.SHA,
|
|
189
|
+
],
|
|
190
|
+
pattern_type=StructuralPattern.EDUCATIONAL,
|
|
191
|
+
description=(
|
|
192
|
+
"Emerging system of ideas or theory: initial emission (AL), information "
|
|
193
|
+
"reception (EN), stabilization (IL), conceptual dissonance or paradox (OZ), "
|
|
194
|
+
"mutation toward new paradigm (ZHIR), stabilization in coherent understanding (IL), "
|
|
195
|
+
"self-organization into theoretical system (THOL), integration into embodied "
|
|
196
|
+
"knowledge (SHA). Epistemological construction trajectory."
|
|
197
|
+
),
|
|
198
|
+
use_cases=[
|
|
199
|
+
"Design of epistemological frameworks or scientific paradigms",
|
|
200
|
+
"Construction of coherent theories in social sciences",
|
|
201
|
+
"Modeling of conceptual evolution in academic communities",
|
|
202
|
+
"Development of philosophical systems or worldviews",
|
|
203
|
+
],
|
|
204
|
+
domain="cognitive",
|
|
205
|
+
references="El pulso que nos atraviesa, Example 2 (Section 2.3.8)",
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
# ============================================================================
|
|
210
|
+
# Full Deployment: Complete Deployment
|
|
211
|
+
# ============================================================================
|
|
212
|
+
|
|
213
|
+
FULL_DEPLOYMENT = CanonicalSequence(
|
|
214
|
+
name="full_deployment",
|
|
215
|
+
glyphs=[
|
|
216
|
+
Glyph.AL,
|
|
217
|
+
Glyph.EN,
|
|
218
|
+
Glyph.IL,
|
|
219
|
+
Glyph.OZ,
|
|
220
|
+
Glyph.ZHIR,
|
|
221
|
+
Glyph.IL,
|
|
222
|
+
Glyph.RA,
|
|
223
|
+
Glyph.IL,
|
|
224
|
+
Glyph.SHA,
|
|
225
|
+
],
|
|
226
|
+
pattern_type=StructuralPattern.COMPLEX,
|
|
227
|
+
description=(
|
|
228
|
+
"Complete nodal reorganization trajectory: initiating emission (AL), "
|
|
229
|
+
"stabilizing reception (EN), initial coherence (IL), exploratory "
|
|
230
|
+
"dissonance (OZ), transformative mutation (ZHIR), coherent stabilization (IL), "
|
|
231
|
+
"resonant propagation (RA), post-resonance consolidation (IL), closure in latency (SHA). "
|
|
232
|
+
"Exhaustive structural reorganization sequence with coherent frequency transitions."
|
|
233
|
+
),
|
|
234
|
+
use_cases=[
|
|
235
|
+
"Complete organizational transformation processes",
|
|
236
|
+
"Radical innovation cycles with multiple phases",
|
|
237
|
+
"Deep and transformative learning trajectories",
|
|
238
|
+
"Systemic reorganization of communities or ecosystems",
|
|
239
|
+
],
|
|
240
|
+
domain="general",
|
|
241
|
+
references="El pulso que nos atraviesa, Table 2.5 (Complete deployment)",
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
# ============================================================================
|
|
246
|
+
# New Canonical Variants: Direct high → zero Termination
|
|
247
|
+
# Unlocked by frequency transition update allowing high → zero for SHA
|
|
248
|
+
# ============================================================================
|
|
249
|
+
|
|
250
|
+
CONTAINED_CRISIS = CanonicalSequence(
|
|
251
|
+
name="contained_crisis",
|
|
252
|
+
glyphs=[Glyph.AL, Glyph.EN, Glyph.IL, Glyph.OZ, Glyph.SHA],
|
|
253
|
+
pattern_type=StructuralPattern.THERAPEUTIC,
|
|
254
|
+
description=(
|
|
255
|
+
"Direct crisis containment: dissonance immediately preserved without processing. "
|
|
256
|
+
"OZ creates ΔNFR ↑ (tension, exploration), SHA immediately contains via νf → 0, "
|
|
257
|
+
"preserving tension in suspended state for later resolution. This is the canonical "
|
|
258
|
+
"'contained dissonance' pattern: trauma held safely, conflict postponed, tension "
|
|
259
|
+
"preserved. Essential for trauma first response, emergency pause, and protective freeze "
|
|
260
|
+
"when immediate processing would overwhelm the system."
|
|
261
|
+
),
|
|
262
|
+
use_cases=[
|
|
263
|
+
"Trauma containment (immediate safety response without processing)",
|
|
264
|
+
"Crisis management (pause before system overwhelm)",
|
|
265
|
+
"Strategic hold (preserve tension for optimal timing)",
|
|
266
|
+
"Protective freeze (contain instability temporarily)",
|
|
267
|
+
"Emergency stop (halt exploration when risk detected)",
|
|
268
|
+
],
|
|
269
|
+
domain="therapeutic",
|
|
270
|
+
references=(
|
|
271
|
+
"SHA Grammar Validation Issue: OZ → SHA as valid therapeutic pattern. "
|
|
272
|
+
"Frequency transition update: high → zero for containment/termination."
|
|
273
|
+
),
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
RESONANCE_PEAK_HOLD = CanonicalSequence(
|
|
277
|
+
name="resonance_peak_hold",
|
|
278
|
+
glyphs=[Glyph.AL, Glyph.EN, Glyph.IL, Glyph.RA, Glyph.SHA],
|
|
279
|
+
pattern_type=StructuralPattern.RESONATE,
|
|
280
|
+
description=(
|
|
281
|
+
"Peak state preservation: amplified resonance frozen at maximum coherence. "
|
|
282
|
+
"RA amplifies network coherence (high C(t), increased νf), SHA suspends dynamics "
|
|
283
|
+
"(νf → 0) while preserving peak state, creating 'resonance memory'. Used for "
|
|
284
|
+
"flow state capture, optimal pattern preservation, and network snapshots. The "
|
|
285
|
+
"amplified coherence is held in latent form for later reactivation without decay."
|
|
286
|
+
),
|
|
287
|
+
use_cases=[
|
|
288
|
+
"Flow state preservation (hold peak performance)",
|
|
289
|
+
"Peak coherence memory (capture optimal synchronization)",
|
|
290
|
+
"Network snapshot (freeze synchronized state)",
|
|
291
|
+
"Resonance consolidation (lock amplified pattern)",
|
|
292
|
+
"Optimal moment capture (preserve heightened state)",
|
|
293
|
+
],
|
|
294
|
+
domain="cognitive",
|
|
295
|
+
references=(
|
|
296
|
+
"Frequency transition update: high → zero enables direct RA → SHA termination. "
|
|
297
|
+
"Memory consolidation pattern for peak states."
|
|
298
|
+
),
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
MINIMAL_COMPRESSION = CanonicalSequence(
|
|
302
|
+
name="minimal_compression",
|
|
303
|
+
glyphs=[Glyph.AL, Glyph.EN, Glyph.IL, Glyph.NUL, Glyph.SHA],
|
|
304
|
+
pattern_type=StructuralPattern.COMPRESS,
|
|
305
|
+
description=(
|
|
306
|
+
"Compressed latency: structure reduced to essential form and preserved. "
|
|
307
|
+
"NUL concentrates EPI to core (contraction, high νf), SHA immediately freezes "
|
|
308
|
+
"minimal form (νf → 0), creating efficient storage. Distills pattern to fundamentals "
|
|
309
|
+
"then preserves in latent state. Used for information compression, core essence "
|
|
310
|
+
"extraction, and efficient memory storage of essential structure only."
|
|
311
|
+
),
|
|
312
|
+
use_cases=[
|
|
313
|
+
"Information compression (minimal viable form)",
|
|
314
|
+
"Core essence extraction (distill to fundamentals)",
|
|
315
|
+
"Efficient storage (compact representation)",
|
|
316
|
+
"Essential pattern hold (preserve only critical structure)",
|
|
317
|
+
"Minimal memory (reduce before suspend)",
|
|
318
|
+
],
|
|
319
|
+
domain="cognitive",
|
|
320
|
+
references=(
|
|
321
|
+
"Frequency transition update: high → zero enables direct NUL → SHA termination. "
|
|
322
|
+
"Compression-then-freeze pattern for efficient storage."
|
|
323
|
+
),
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
PHASE_LOCK = CanonicalSequence(
|
|
327
|
+
name="phase_lock",
|
|
328
|
+
glyphs=[Glyph.AL, Glyph.EN, Glyph.IL, Glyph.OZ, Glyph.ZHIR, Glyph.SHA],
|
|
329
|
+
pattern_type=StructuralPattern.BIFURCATED,
|
|
330
|
+
description=(
|
|
331
|
+
"Phase transition hold: mutation immediately locked without stabilization. "
|
|
332
|
+
"OZ creates bifurcation threshold (ΔNFR ↑), ZHIR pivots phase θ (high νf), "
|
|
333
|
+
"SHA immediately locks new phase (νf → 0) before potential regression. Preserves "
|
|
334
|
+
"transformed state in latent form, preventing return to previous configuration. "
|
|
335
|
+
"Used for identity consolidation, paradigm shift memory, and transformation lock. "
|
|
336
|
+
"Simpler than full ZHIR → IL → SHA when immediate preservation desired."
|
|
337
|
+
),
|
|
338
|
+
use_cases=[
|
|
339
|
+
"Identity shift hold (lock new configuration)",
|
|
340
|
+
"Phase memory (preserve transformed state)",
|
|
341
|
+
"Mutation consolidation (hold before integration)",
|
|
342
|
+
"Paradigm capture (freeze new perspective)",
|
|
343
|
+
"Transformation lock (prevent regression)",
|
|
344
|
+
],
|
|
345
|
+
domain="cognitive",
|
|
346
|
+
references=(
|
|
347
|
+
"Frequency transition update: high → zero enables direct ZHIR → SHA termination. "
|
|
348
|
+
"Immediate phase lock pattern without intermediate stabilization."
|
|
349
|
+
),
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
# ============================================================================
|
|
354
|
+
# MOD_STABILIZER: Reusable Glyphic Macro
|
|
355
|
+
# ============================================================================
|
|
356
|
+
|
|
357
|
+
MOD_STABILIZER = CanonicalSequence(
|
|
358
|
+
name="mod_stabilizer",
|
|
359
|
+
glyphs=[
|
|
360
|
+
Glyph.REMESH,
|
|
361
|
+
Glyph.EN,
|
|
362
|
+
Glyph.IL,
|
|
363
|
+
Glyph.OZ,
|
|
364
|
+
Glyph.ZHIR,
|
|
365
|
+
Glyph.IL,
|
|
366
|
+
Glyph.REMESH,
|
|
367
|
+
],
|
|
368
|
+
pattern_type=StructuralPattern.EXPLORE,
|
|
369
|
+
description=(
|
|
370
|
+
"MOD_STABILIZER: glyphic macro for controlled transformation. "
|
|
371
|
+
"Activates recursivity (REMESH), receives current state (EN), stabilizes (IL), "
|
|
372
|
+
"introduces controlled dissonance (OZ), mutates structure (ZHIR), stabilizes "
|
|
373
|
+
"new form (IL), closes with recursivity (REMESH). Reusable as "
|
|
374
|
+
"modular subunit within more complex sequences. Represents the "
|
|
375
|
+
"minimal pattern of exploration-transformation-consolidation with complete "
|
|
376
|
+
"grammar validation (EN → IL) and recursive closure."
|
|
377
|
+
),
|
|
378
|
+
use_cases=[
|
|
379
|
+
"Safe transformation module for composition",
|
|
380
|
+
"Reusable component in complex sequences",
|
|
381
|
+
"Encapsulated creative resolution pattern",
|
|
382
|
+
"Building block for T'HOL (self-organization)",
|
|
383
|
+
],
|
|
384
|
+
domain="general",
|
|
385
|
+
references="El pulso que nos atraviesa, Section 2.3.5 (Glyphic macros)",
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
# ============================================================================
|
|
390
|
+
# Registry of All Canonical Sequences
|
|
391
|
+
# ============================================================================
|
|
392
|
+
|
|
393
|
+
CANONICAL_SEQUENCES: Dict[str, CanonicalSequence] = {
|
|
394
|
+
seq.name: seq
|
|
395
|
+
for seq in [
|
|
396
|
+
BIFURCATED_BASE,
|
|
397
|
+
BIFURCATED_COLLAPSE,
|
|
398
|
+
THERAPEUTIC_PROTOCOL,
|
|
399
|
+
THEORY_SYSTEM,
|
|
400
|
+
FULL_DEPLOYMENT,
|
|
401
|
+
MOD_STABILIZER,
|
|
402
|
+
# New variants unlocked by high → zero frequency transition
|
|
403
|
+
CONTAINED_CRISIS,
|
|
404
|
+
RESONANCE_PEAK_HOLD,
|
|
405
|
+
MINIMAL_COMPRESSION,
|
|
406
|
+
PHASE_LOCK,
|
|
407
|
+
]
|
|
408
|
+
}
|
|
409
|
+
"""Registry of all canonical operator sequences.
|
|
410
|
+
|
|
411
|
+
Maps sequence names to their full CanonicalSequence definitions. This registry
|
|
412
|
+
provides programmatic access to validated archetypal patterns from TNFR theory.
|
|
413
|
+
|
|
414
|
+
Examples
|
|
415
|
+
--------
|
|
416
|
+
>>> from tnfr.operators.canonical_patterns import CANONICAL_SEQUENCES
|
|
417
|
+
>>> seq = CANONICAL_SEQUENCES["bifurcated_base"]
|
|
418
|
+
>>> print(f"{seq.name}: {' → '.join(g.value for g in seq.glyphs)}")
|
|
419
|
+
bifurcated_base: AL → IL → OZ → ZHIR → SHA
|
|
420
|
+
"""
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"""Cascade detection and analysis for THOL self-organization.
|
|
2
|
+
|
|
3
|
+
Provides tools to detect, measure, and analyze emergent cascades in
|
|
4
|
+
TNFR networks where THOL bifurcations propagate through coupled nodes.
|
|
5
|
+
|
|
6
|
+
TNFR Canonical Principle
|
|
7
|
+
-------------------------
|
|
8
|
+
From "El pulso que nos atraviesa" (TNFR Manual, §2.2.10):
|
|
9
|
+
|
|
10
|
+
"THOL actúa como modulador central de plasticidad. Es el glifo que
|
|
11
|
+
permite a la red reorganizar su topología sin intervención externa.
|
|
12
|
+
Su activación crea bucles de aprendizaje resonante, trayectorias de
|
|
13
|
+
reorganización emergente, estabilidad dinámica basada en coherencia local."
|
|
14
|
+
|
|
15
|
+
This module implements cascade detection: when THOL bifurcations propagate
|
|
16
|
+
through phase-aligned neighbors, creating chains of emergent reorganization.
|
|
17
|
+
|
|
18
|
+
Performance Optimization
|
|
19
|
+
------------------------
|
|
20
|
+
CASCADE DETECTION CACHING: `detect_cascade()` uses TNFR's canonical caching
|
|
21
|
+
infrastructure (`@cache_tnfr_computation`) to avoid recomputing cascade state.
|
|
22
|
+
The cache is automatically invalidated when THOL propagations change, ensuring
|
|
23
|
+
coherence while enabling O(1) lookups for repeated queries.
|
|
24
|
+
|
|
25
|
+
Cache key depends on: graph identity + propagation history + cascade config.
|
|
26
|
+
This provides significant performance improvement for large networks (>1000 nodes)
|
|
27
|
+
where cascade detection is called frequently (e.g., in `self_organization_metrics`).
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
from __future__ import annotations
|
|
31
|
+
|
|
32
|
+
from collections import deque
|
|
33
|
+
from typing import TYPE_CHECKING, Any
|
|
34
|
+
|
|
35
|
+
if TYPE_CHECKING:
|
|
36
|
+
from ..types import NodeId, TNFRGraph
|
|
37
|
+
|
|
38
|
+
__all__ = [
|
|
39
|
+
"detect_cascade",
|
|
40
|
+
"measure_cascade_radius",
|
|
41
|
+
"invalidate_cascade_cache",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# Import cache utilities for performance optimization
|
|
46
|
+
try:
|
|
47
|
+
from ..utils.cache import cache_tnfr_computation, CacheLevel
|
|
48
|
+
_CACHING_AVAILABLE = True
|
|
49
|
+
except ImportError: # pragma: no cover - defensive import for testing
|
|
50
|
+
_CACHING_AVAILABLE = False
|
|
51
|
+
# Dummy decorator if caching unavailable
|
|
52
|
+
def cache_tnfr_computation(level, dependencies, cost_estimator=None):
|
|
53
|
+
def decorator(func):
|
|
54
|
+
return func
|
|
55
|
+
return decorator
|
|
56
|
+
|
|
57
|
+
class CacheLevel: # type: ignore
|
|
58
|
+
DERIVED_METRICS = "derived_metrics"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _estimate_cascade_cost(G: TNFRGraph) -> float:
|
|
62
|
+
"""Estimate computational cost for cascade detection.
|
|
63
|
+
|
|
64
|
+
Used by cache eviction policy to prioritize expensive computations.
|
|
65
|
+
Cost is proportional to number of propagation events to process.
|
|
66
|
+
"""
|
|
67
|
+
propagations = G.graph.get("thol_propagations", [])
|
|
68
|
+
# Base cost + cost per propagation event
|
|
69
|
+
return 1.0 + len(propagations) * 0.1
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@cache_tnfr_computation(
|
|
73
|
+
level=CacheLevel.DERIVED_METRICS,
|
|
74
|
+
dependencies={'thol_propagations', 'cascade_config'},
|
|
75
|
+
cost_estimator=_estimate_cascade_cost,
|
|
76
|
+
)
|
|
77
|
+
def detect_cascade(G: TNFRGraph) -> dict[str, Any]:
|
|
78
|
+
"""Detect if THOL triggered a propagation cascade in the network.
|
|
79
|
+
|
|
80
|
+
A cascade is defined as a chain reaction where:
|
|
81
|
+
1. Node A bifurcates (THOL)
|
|
82
|
+
2. Sub-EPI propagates to coupled neighbors
|
|
83
|
+
3. Neighbors' EPIs increase, potentially triggering their own bifurcations
|
|
84
|
+
4. Process continues across ≥3 nodes
|
|
85
|
+
|
|
86
|
+
**Performance**: This function uses TNFR's canonical cache infrastructure
|
|
87
|
+
to avoid recomputing cascade state. First call builds cache (O(P × N_prop)),
|
|
88
|
+
subsequent calls are O(1) hash lookups. Cache automatically invalidates
|
|
89
|
+
when `thol_propagations` or `cascade_config` dependencies change.
|
|
90
|
+
|
|
91
|
+
Parameters
|
|
92
|
+
----------
|
|
93
|
+
G : TNFRGraph
|
|
94
|
+
Graph with THOL propagation history
|
|
95
|
+
|
|
96
|
+
Returns
|
|
97
|
+
-------
|
|
98
|
+
dict
|
|
99
|
+
Cascade analysis containing:
|
|
100
|
+
- is_cascade: bool (True if cascade detected)
|
|
101
|
+
- affected_nodes: set of NodeIds involved
|
|
102
|
+
- cascade_depth: maximum propagation chain length
|
|
103
|
+
- total_propagations: total number of propagation events
|
|
104
|
+
- cascade_coherence: average coupling strength in cascade
|
|
105
|
+
|
|
106
|
+
Notes
|
|
107
|
+
-----
|
|
108
|
+
TNFR Principle: Cascades emerge when network phase coherence enables
|
|
109
|
+
propagation across multiple nodes, creating collective self-organization.
|
|
110
|
+
|
|
111
|
+
Caching Strategy:
|
|
112
|
+
- Cache level: DERIVED_METRICS (mid-persistence)
|
|
113
|
+
- Dependencies: 'thol_propagations' (propagation history),
|
|
114
|
+
'cascade_config' (threshold parameters)
|
|
115
|
+
- Invalidation: Automatic when dependencies change
|
|
116
|
+
- Cost: Proportional to number of propagation events
|
|
117
|
+
|
|
118
|
+
For networks with >1000 nodes and frequent cascade queries, caching
|
|
119
|
+
provides significant speedup (~100x for cached calls).
|
|
120
|
+
|
|
121
|
+
Examples
|
|
122
|
+
--------
|
|
123
|
+
>>> # Network with cascade
|
|
124
|
+
>>> analysis = detect_cascade(G)
|
|
125
|
+
>>> analysis["is_cascade"]
|
|
126
|
+
True
|
|
127
|
+
>>> analysis["cascade_depth"]
|
|
128
|
+
4 # Propagated through 4 levels
|
|
129
|
+
>>> len(analysis["affected_nodes"])
|
|
130
|
+
7 # 7 nodes affected
|
|
131
|
+
"""
|
|
132
|
+
propagations = G.graph.get("thol_propagations", [])
|
|
133
|
+
|
|
134
|
+
if not propagations:
|
|
135
|
+
return {
|
|
136
|
+
"is_cascade": False,
|
|
137
|
+
"affected_nodes": set(),
|
|
138
|
+
"cascade_depth": 0,
|
|
139
|
+
"total_propagations": 0,
|
|
140
|
+
"cascade_coherence": 0.0,
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
# Build propagation graph
|
|
144
|
+
affected_nodes = set()
|
|
145
|
+
for prop in propagations:
|
|
146
|
+
affected_nodes.add(prop["source_node"])
|
|
147
|
+
for target, _ in prop["propagations"]:
|
|
148
|
+
affected_nodes.add(target)
|
|
149
|
+
|
|
150
|
+
# Compute cascade depth (longest propagation chain)
|
|
151
|
+
# For now, approximate as number of propagation events
|
|
152
|
+
cascade_depth = len(propagations)
|
|
153
|
+
|
|
154
|
+
# Total propagations
|
|
155
|
+
total_props = sum(len(p["propagations"]) for p in propagations)
|
|
156
|
+
|
|
157
|
+
# Get cascade minimum nodes from config
|
|
158
|
+
cascade_min_nodes = int(G.graph.get("THOL_CASCADE_MIN_NODES", 3))
|
|
159
|
+
|
|
160
|
+
# Cascade = affects ≥ cascade_min_nodes
|
|
161
|
+
is_cascade = len(affected_nodes) >= cascade_min_nodes
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
"is_cascade": is_cascade,
|
|
165
|
+
"affected_nodes": affected_nodes,
|
|
166
|
+
"cascade_depth": cascade_depth,
|
|
167
|
+
"total_propagations": total_props,
|
|
168
|
+
"cascade_coherence": 0.0, # TODO: compute from coupling strengths
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def measure_cascade_radius(G: TNFRGraph, source_node: NodeId) -> int:
|
|
173
|
+
"""Measure propagation radius from bifurcation source.
|
|
174
|
+
|
|
175
|
+
Parameters
|
|
176
|
+
----------
|
|
177
|
+
G : TNFRGraph
|
|
178
|
+
Graph with propagation history
|
|
179
|
+
source_node : NodeId
|
|
180
|
+
Origin node of cascade
|
|
181
|
+
|
|
182
|
+
Returns
|
|
183
|
+
-------
|
|
184
|
+
int
|
|
185
|
+
Number of nodes reached by propagation (hop distance)
|
|
186
|
+
|
|
187
|
+
Notes
|
|
188
|
+
-----
|
|
189
|
+
Uses BFS to trace propagation paths from source.
|
|
190
|
+
|
|
191
|
+
Examples
|
|
192
|
+
--------
|
|
193
|
+
>>> # Linear cascade: 0 -> 1 -> 2 -> 3
|
|
194
|
+
>>> radius = measure_cascade_radius(G, source_node=0)
|
|
195
|
+
>>> radius
|
|
196
|
+
3 # Reached 3 hops from source
|
|
197
|
+
"""
|
|
198
|
+
propagations = G.graph.get("thol_propagations", [])
|
|
199
|
+
|
|
200
|
+
# Build propagation edges from this source
|
|
201
|
+
prop_edges = []
|
|
202
|
+
for prop in propagations:
|
|
203
|
+
if prop["source_node"] == source_node:
|
|
204
|
+
for target, _ in prop["propagations"]:
|
|
205
|
+
prop_edges.append((source_node, target))
|
|
206
|
+
|
|
207
|
+
if not prop_edges:
|
|
208
|
+
return 0
|
|
209
|
+
|
|
210
|
+
# BFS to measure radius
|
|
211
|
+
visited = {source_node}
|
|
212
|
+
queue = deque([(source_node, 0)]) # (node, distance)
|
|
213
|
+
max_distance = 0
|
|
214
|
+
|
|
215
|
+
while queue:
|
|
216
|
+
current, dist = queue.popleft()
|
|
217
|
+
max_distance = max(max_distance, dist)
|
|
218
|
+
|
|
219
|
+
for src, tgt in prop_edges:
|
|
220
|
+
if src == current and tgt not in visited:
|
|
221
|
+
visited.add(tgt)
|
|
222
|
+
queue.append((tgt, dist + 1))
|
|
223
|
+
|
|
224
|
+
return max_distance
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def invalidate_cascade_cache() -> int:
|
|
228
|
+
"""Invalidate cached cascade detection results across all graphs.
|
|
229
|
+
|
|
230
|
+
This function should be called when THOL propagations are added or
|
|
231
|
+
cascade configuration parameters change. It triggers automatic cache
|
|
232
|
+
invalidation via the dependency tracking system.
|
|
233
|
+
|
|
234
|
+
Returns
|
|
235
|
+
-------
|
|
236
|
+
int
|
|
237
|
+
Number of cache entries invalidated.
|
|
238
|
+
|
|
239
|
+
Notes
|
|
240
|
+
-----
|
|
241
|
+
TNFR Caching: Uses canonical `invalidate_by_dependency()` mechanism.
|
|
242
|
+
Dependencies invalidated: 'thol_propagations', 'cascade_config'.
|
|
243
|
+
|
|
244
|
+
This function is typically not needed explicitly, as cache invalidation
|
|
245
|
+
happens automatically when G.graph["thol_propagations"] is modified.
|
|
246
|
+
However, it's provided for manual cache management in edge cases.
|
|
247
|
+
|
|
248
|
+
Examples
|
|
249
|
+
--------
|
|
250
|
+
>>> # Add new propagations
|
|
251
|
+
>>> G.graph["thol_propagations"].append(new_propagation)
|
|
252
|
+
>>> # Cache invalidates automatically, but can force if needed
|
|
253
|
+
>>> invalidate_cascade_cache() # doctest: +SKIP
|
|
254
|
+
2 # Invalidated 2 cache entries
|
|
255
|
+
"""
|
|
256
|
+
if not _CACHING_AVAILABLE:
|
|
257
|
+
return 0
|
|
258
|
+
|
|
259
|
+
try:
|
|
260
|
+
from ..utils.cache import get_global_cache
|
|
261
|
+
cache = get_global_cache()
|
|
262
|
+
count = 0
|
|
263
|
+
count += cache.invalidate_by_dependency('thol_propagations')
|
|
264
|
+
count += cache.invalidate_by_dependency('cascade_config')
|
|
265
|
+
return count
|
|
266
|
+
except (ImportError, AttributeError): # pragma: no cover
|
|
267
|
+
return 0
|