This README is the centralized entry point for the Operators module. It consolidates the essential references and avoids redundant documentation. All content is in English.
AGENTS.md (invariants, operator taxonomy) and UNIFIED_GRAMMAR_RULES.md (U1–U6)TNFR.pdf §1–2)src/tnfr/mathematics/README.mdsrc/tnfr/physics/README.mddefinitions.pygrammar.py, unified_grammar.pypreconditions/, postconditions/registry.py, canonical_patterns.pyUM/RAfrom tnfr.operators.definitions import Coherence, Dissonance, Resonance
from tnfr.operators.grammar import validate_resonant_coupling, apply_sequence
seq = [Coherence(), Dissonance(intensity=0.2), Coherence()]
apply_sequence(G, node, seq) # Preserves U1–U4 contractsOperators are auto-registered via reflective discovery (discover_operators())
and may declare explicit intent using the @structural_operator decorator:
from tnfr.operators.definitions_base import Operator
from tnfr.operators.registry import structural_operator
from tnfr.types import Glyph
@structural_operator
class MyOperator(Operator):
name = "my_operator"
glyph = Glyph.AL # choose canonical glyph or leave None for non-glyph ops
def __call__(self, G, node, **kw):
super().__call__(G, node, **kw)
# structural transformation via grammar already appliedIdempotent: multiple imports or hot-reloads never duplicate registry entries.
All operator subclasses also auto-register via the optional metaclass
OperatorMetaAuto attached to the base Operator. This is physics-neutral:
it does not alter glyph semantics. You can opt out by setting
__register__ = False on a subclass (rare; mainly for abstract helpers).
Decorator + metaclass together remain safe; duplicate registrations are silently ignored.
Operator registry telemetry is available via:
from tnfr.operators.registry import get_operator_cache_stats
stats = get_operator_cache_stats()
print(stats)
# {'registrations': 13, 'soft_invalidations': 2, 'hard_invalidations': 0,
# 'last_invalidation_ts': 1731552000.123, 'current_count': 13}Grammar-level LRU cache statistics (for memoized validation helpers) via:
from tnfr.operators.grammar import get_grammar_cache_stats
gstats = get_grammar_cache_stats()Interactive development reload:
python scripts/tnfr_ops_reload.py # soft reload
python scripts/tnfr_ops_reload.py --hard # hard reload (drops registry)
python scripts/tnfr_ops_reload.py --stats # show stats onlyOutput includes registry before/after, invalidation mode, operator names, and grammar cache metrics in JSON form.
Use invalidate_operator_cache() for development hot-reload after editing
operator source files:
from tnfr.operators.registry import invalidate_operator_cache, OPERATORS
stats = invalidate_operator_cache(hard=False) # soft: preserves existing mapping
print(stats) # {'count': 13, 'cleared': 0}
# Hard reset (drops existing registry first):
invalidate_operator_cache(hard=True)Soft invalidation clears the discovery flag and re-runs reflection.
Hard invalidation also empties OPERATORS before re-population.
Telemetry fields updated:
soft_invalidations / hard_invalidationslast_invalidation_ts (ISO available in CLI helper)registrations (unique successful registrations)tests/test_operator_registry_consistency.py enforces:
OPERATORS_CORE_OPERATORS removed)tests/ for coherence monotonicity, bifurcation handlers, and propagation.This module README links to canonical sources and implementation files. It intentionally avoids duplicating theoretical content already covered in AGENTS.md, UNIFIED_GRAMMAR_RULES.md, and the mathematics/physics READMEs.