Skip to content

Commit 07db027

Browse files
author
TNFR AI Agent
committed
Consolidate engine contracts and repository maintenance
Unify represented-real admission across standard and optimized execution, operators and Mutation histories. Preserve raw REMESH callback evidence, centralize finite reduction arithmetic and correct spectral diagnostics. Consolidate cache and arithmetic CLI owners, align public SDK exports and strict atomic report I/O, and repair standalone primality packaging. Retire unused benchmark/grammar helpers and redundant automation. Correct example claims, preserve code during documentation staging and guard generated paths. Validation: 7468 routine engine/API tests passed, 38 skipped, plus 2 passing subtests. Affected mathematical, packaging, CLI and maintenance checks pass; 2969 internal references and strict MkDocs build pass. Final pinned Black and isort hooks, flake8 and whitespace checks pass. The final formatting changes preserve the validated Python AST. Research queue, model-law scope and frozen evidence remain unchanged. Routine validation does not replay the complete historical research inventory.
1 parent 4ba8823 commit 07db027

83 files changed

Lines changed: 2065 additions & 2386 deletions

File tree

Some content is hidden

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

‎.github/WORKFLOWS.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ not establish current GitHub run health, branch protection or enabled secrets.
1515
| [pip-audit.yml](workflows/pip-audit.yml) | Push/PR to main/master, Monday 05:00 UTC and manual invocation. Audits the installed core, test-all and serialization environment; captures available reports and fails when the JSON audit fails. |
1616
| [pypi-zenodo.yml](workflows/pypi-zenodo.yml) | Published GitHub release or manual invocation. Builds and checks distributions; publishes on release or when the existing manual force-publish input is true. |
1717
| [lint-workflows.yml](workflows/lint-workflows.yml) | Filtered workflow/script changes on PRs and pushes to main. Searches for unsupported Bandit SARIF invocation; this is not a general Actions schema linter. |
18-
| [code-review.yml](workflows/code-review.yml) | PR opened, synchronized or reopened on main. Advisory Black/mypy checks and an automated PR comment; no external code-review service is implemented. |
1918
| [copilot-setup-steps.yml](workflows/copilot-setup-steps.yml) | Manual invocation or edits to its own workflow. Installs a Python 3.11 development/test environment and verifies importability. |
2019

2120
The default pytest selection is the routine engine/API gate and excludes slow
@@ -78,6 +77,11 @@ verify a DOI. No GitHub/PyPI/Zenodo settings are inferred from this file.
7877

7978
## Retired automation
8079

80+
The former `code-review.yml` job and reminder-only pre-commit hook are retired.
81+
Black and advisory mypy already have maintained owners in `ci.yml`; repeating
82+
them in another environment and posting an automatic PR comment added no
83+
independent review coverage. The main CI gates retain their existing scope.
84+
8185
The test consolidation removed `tests.yml`, which repeated the complete SDK
8286
suite on Python 3.11 already included in `ci.yml`. The main matrix retains the
8387
SDK assertions, environment checks and JUnit/coverage reporting.

‎.github/workflows/code-review.yml‎

Lines changed: 0 additions & 67 deletions
This file was deleted.

‎.github/workflows/docs.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ on:
1717
- 'src/tnfr/_version.py'
1818
- 'scripts/check_documentation.py'
1919
- 'scripts/prepare_docs.py'
20+
- 'scripts/clean_repository.py'
2021
- 'scripts/verify_internal_references.py'
2122
- '.github/workflows/docs.yml'
2223
pull_request:
@@ -35,6 +36,7 @@ on:
3536
- 'src/tnfr/_version.py'
3637
- 'scripts/check_documentation.py'
3738
- 'scripts/prepare_docs.py'
39+
- 'scripts/clean_repository.py'
3840
- 'scripts/verify_internal_references.py'
3941
- '.github/workflows/docs.yml'
4042
workflow_dispatch: {}

‎.pre-commit-config.yaml‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ repos:
1717
files: ^src/tnfr/
1818
- repo: local
1919
hooks:
20-
- id: code-review-check
21-
name: Code review quality check
22-
entry: bash -c 'echo "Remember to run code review before committing significant changes (make lint test)" && exit 0'
23-
language: system
24-
pass_filenames: false
25-
stages: [pre-commit]
2620
- id: check-bandit-format
2721
name: Check for invalid bandit -f sarif usage
2822
entry: bash -c 'if grep -r "bandit.*-f sarif" .github/workflows/ scripts/ --exclude=lint-workflows.yml 2>/dev/null; then echo "ERROR - bandit does not support SARIF format. Use -f json instead."; exit 1; fi'

‎ARCHITECTURE.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ boundary, not a measured speedup. Other state/configuration dependencies remain
1818
part of each consumer's key or explicit invalidation contract. Graph views use
1919
fresh computations; concurrent mutation during a read is unsupported.
2020

21+
LRU storage and callback handling have one implementation in
22+
[`utils/unified_cache.py`](src/tnfr/utils/unified_cache.py). The historical
23+
`InstrumentedLRUCache` and `ManagedLRUCache` names remain aliases in `utils.cache`;
24+
graph invalidation and persistence retain their separate responsibilities.
25+
2126
## Implementation owners
2227

2328
| Concern | Source of truth |
@@ -35,6 +40,8 @@ fresh computations; concurrent mutation during a read is unsupported.
3540
| Nodal integration | [`integrators.py`](src/tnfr/dynamics/integrators.py) |
3641
| Runtime invocation ordinals | [`_runtime_steps.py`](src/tnfr/_runtime_steps.py); separate from physical time, operator counts and retained metric samples |
3742
| Represented-real scalar admission | [`_exact_time.py`](src/tnfr/_exact_time.py), reused by clocks, phases, rates and operator gates |
43+
| Signed scalar EPI admission | [`types.py`](src/tnfr/types.py), validating raw scalars and serialized components before BEPI coercion; shared by standard and optimized execution |
44+
| Finite matrix products, differences and norms for reductions | [`physics/_finite_linear_algebra.py`](src/tnfr/physics/_finite_linear_algebra.py); quotient and morphism checks preserve finite-range failures |
3845
| Active acceleration history and detached evidence | [`nodal_equation.py`](src/tnfr/operators/nodal_equation.py), `observe_structural_acceleration` |
3946
| Optional THOL preconditions and threshold resolution | [`preconditions/self_organization.py`](src/tnfr/operators/preconditions/self_organization.py), [`_thol_config.py`](src/tnfr/operators/_thol_config.py) |
4047
| Public THOL birth proposals | [`self_organization.py`](src/tnfr/operators/self_organization.py) |
@@ -49,6 +56,7 @@ fresh computations; concurrent mutation during a read is unsupported.
4956
| Validated relational transit | [`physics/relational_transit.py`](src/tnfr/physics/relational_transit.py); exact reflected ODE enclosure using shared rational intervals, Taylor derivatives and signed-diagonal comparison; read-only proof computation, not live engine evolution |
5057
| Coherence and equilibrium kernel | [`common.py`](src/tnfr/metrics/common.py) |
5158
| Public high-level API | [`sdk/simple.py`](src/tnfr/sdk/simple.py) |
59+
| JSON report I/O | [`sdk/utils.py`](src/tnfr/sdk/utils.py); strict decoding and atomic export, also used by the CLI and fluent `save()` |
5260

5361
These are implementation responsibilities. The [documentation ownership map](docs/README.md)
5462
identifies the single maintained guide for each responsibility.

‎benchmarks/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ The source inventory is discoverable without starting any experiment:
3333
rg --files benchmarks -g '*.py'
3434
```
3535

36+
The retained graph-preparation helper serves the curvature safety illustration.
37+
Unused generic CLI scaffolding and handwritten grammar validators are removed;
38+
use each instrument's actual CLI and the shared engine grammar/executor owners.
39+
3640
## Reuse the mechanism appropriate to the question
3741

3842
- [Local relational composition](relational_local_composition.py) checks exact

‎benchmarks/benchmark_utils.py‎

Lines changed: 10 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Benchmark Utilities for TNFR Research
22
==========================================
33
4-
Shared utilities for creating valid TNFR graphs, generating grammar-compliant
5-
operator sequences, and running experiments.
4+
Shared supplied-graph preparation for the curvature safety illustration.
5+
Operator admission and execution belong to the production engine.
66
77
Status: RESEARCH - Support infrastructure for validation experiments
88
"""
@@ -15,7 +15,6 @@
1515
# Import TNFR core
1616
import sys
1717
from pathlib import Path
18-
from typing import Any, List
1918

2019
import networkx as nx
2120

@@ -31,21 +30,6 @@
3130
VF_PRIMARY,
3231
inject_defaults,
3332
)
34-
from tnfr.operators.definitions import (
35-
Coherence,
36-
Contraction,
37-
Coupling,
38-
Dissonance,
39-
Emission,
40-
Expansion,
41-
Mutation,
42-
Reception,
43-
Recursivity,
44-
Resonance,
45-
SelfOrganization,
46-
Silence,
47-
Transition,
48-
)
4933

5034

5135
def create_tnfr_topology(topology: str, n_nodes: int, seed: int) -> nx.Graph:
@@ -65,8 +49,6 @@ def create_tnfr_topology(topology: str, n_nodes: int, seed: int) -> nx.Graph:
6549
nx.Graph
6650
Graph with TNFR defaults injected but nodes not yet initialized
6751
"""
68-
random.seed(seed)
69-
7052
if topology == "ring":
7153
G = nx.cycle_graph(n_nodes)
7254
elif topology == "scale_free":
@@ -102,14 +84,15 @@ def create_tnfr_topology(topology: str, n_nodes: int, seed: int) -> nx.Graph:
10284

10385
# Inject TNFR defaults into graph
10486
inject_defaults(G)
87+
G.graph["RANDOM_SEED"] = seed
10588

10689
return G
10790

10891

10992
def initialize_tnfr_nodes(
11093
G: nx.Graph,
11194
nu_f: float = 1.0,
112-
epi_range: tuple[float, float] = (0.2, 0.8), # FIXED: Within [-1, 1]
95+
epi_range: tuple[float, float] = (0.2, 0.8),
11396
seed: int = 42,
11497
) -> None:
11598
"""Initialize node attributes with proper TNFR primary keys.
@@ -121,143 +104,20 @@ def initialize_tnfr_nodes(
121104
nu_f : float
122105
Structural frequency (νf) for all nodes
123106
epi_range : tuple[float, float]
124-
(min, max) for random EPI initialization (must be in [-1, 1])
107+
(min, max) for the supplied signed scalar EPI initialization
125108
seed : int
126109
Random seed
127110
"""
128-
random.seed(seed)
111+
rng = random.Random(seed)
129112

130113
for node in G.nodes:
131-
G.nodes[node][EPI_PRIMARY] = random.uniform(*epi_range)
114+
G.nodes[node][EPI_PRIMARY] = rng.uniform(*epi_range)
132115
G.nodes[node][VF_PRIMARY] = nu_f
133-
G.nodes[node][THETA_PRIMARY] = random.uniform(0.0, 2 * math.pi)
134-
G.nodes[node][DNFR_PRIMARY] = random.uniform(0.01, 0.05)
116+
G.nodes[node][THETA_PRIMARY] = rng.uniform(0.0, 2 * math.pi)
117+
G.nodes[node][DNFR_PRIMARY] = rng.uniform(0.01, 0.05)
135118
# NOTE: Do NOT add legacy aliases ('phase', 'delta_nfr')
136119
# The fields.py module will find the correct aliases automatically
137120
# Adding redundant aliases causes desync issues
138121

139122

140-
def generate_grammar_valid_sequence(
141-
sequence_type: str,
142-
intensity: float = 1.0,
143-
) -> List[Any]:
144-
"""Generate operator sequences that comply with TNFR grammar (U1-U4).
145-
146-
All sequences:
147-
- Start with generator (U1a): Emission, Transition, or Recursivity
148-
- End with closure (U1b): Silence, Transition, Recursivity, or Dissonance
149-
- Include stabilizers after destabilizers (U2)
150-
- Respect canonical flow compatibility matrix
151-
152-
Parameters
153-
----------
154-
sequence_type : str
155-
'RA_dominated' (resonance-heavy), 'OZ_heavy' (dissonance-heavy),
156-
'balanced' (mixed)
157-
intensity : float
158-
Multiplier for sequence length (1.0 = baseline)
159-
160-
Returns
161-
-------
162-
List
163-
List of operator instances forming a valid sequence
164-
"""
165-
base_length = max(3, int(intensity * 5))
166-
167-
if sequence_type == "RA_dominated":
168-
# Resonance/coupling focused sequence
169-
# Pattern: AL → IL → (RA → IL)* → SHA
170-
seq = [Emission(), Coherence()]
171-
n_resonance = max(1, int(base_length * 0.5))
172-
for _ in range(n_resonance):
173-
seq.extend([Resonance(), Coherence()])
174-
seq.append(Silence())
175-
176-
elif sequence_type == "OZ_heavy":
177-
# Dissonance-heavy sequence with required stabilizers
178-
# Pattern: AL → (OZ → IL)* → (VAL → THOL) → SHA
179-
seq = [Emission()]
180-
n_dissonance = max(1, int(base_length * 0.4))
181-
for _ in range(n_dissonance):
182-
seq.extend([Dissonance(), Coherence()])
183-
# Add expansion with self-organization (U2: destabilizer needs stabilizer)
184-
seq.extend([Dissonance(), Expansion(), SelfOrganization(), Coherence()])
185-
seq.append(Silence())
186-
187-
elif sequence_type == "balanced":
188-
# Mix of operators maintaining grammar compliance
189-
# Pattern: AL → IL → (OZ → IL → RA → IL)* → SHA
190-
seq = [Emission(), Coherence()]
191-
n_cycles = max(1, int(base_length * 0.3))
192-
for _ in range(n_cycles):
193-
seq.extend([Dissonance(), Coherence(), Resonance(), Coherence()])
194-
seq.append(Silence())
195-
196-
else:
197-
raise ValueError(f"Unknown sequence type: {sequence_type}")
198-
199-
return seq
200-
201-
202-
# Validation: Ensure sequences comply with grammar
203-
def validate_sequence_grammar(sequence: List[Any]) -> tuple[bool, str]:
204-
"""Validate that a sequence complies with TNFR grammar rules.
205-
206-
Checks:
207-
- U1a: Starts with generator (AL, NAV, REMESH)
208-
- U1b: Ends with closure (SHA, NAV, REMESH, OZ)
209-
- U2: Destabilizers (OZ, VAL, ZHIR) followed by stabilizers (IL, THOL)
210-
211-
Parameters
212-
----------
213-
sequence : List
214-
List of operator instances
215-
216-
Returns
217-
-------
218-
tuple[bool, str]
219-
(is_valid, error_message)
220-
"""
221-
if not sequence:
222-
return False, "Empty sequence"
223-
224-
# Map operators to their names
225-
op_names = [op.__class__.__name__ for op in sequence]
226-
227-
# U1a: Generator check
228-
generators = {"Emission", "Transition", "Recursivity"}
229-
if op_names[0] not in generators:
230-
return False, f"Must start with generator, got {op_names[0]}"
231-
232-
# U1b: Closure check
233-
closures = {"Silence", "Transition", "Recursivity", "Dissonance"}
234-
if op_names[-1] not in closures:
235-
return False, f"Must end with closure, got {op_names[-1]}"
236-
237-
# U2: Destabilizer → Stabilizer check
238-
destabilizers = {"Dissonance", "Expansion", "Mutation"}
239-
stabilizers = {"Coherence", "SelfOrganization"}
240-
241-
for i, op_name in enumerate(op_names):
242-
if op_name in destabilizers:
243-
# Look ahead for stabilizer within next 3 operators
244-
found_stabilizer = False
245-
for j in range(i + 1, min(i + 4, len(op_names))):
246-
if op_names[j] in stabilizers:
247-
found_stabilizer = True
248-
break
249-
if not found_stabilizer:
250-
return (
251-
False,
252-
f"Destabilizer {op_name} at position {i} needs stabilizer within 3 ops",
253-
)
254-
255-
return True, "Valid"
256-
257-
258-
__all__ = [
259-
"create_tnfr_topology",
260-
"initialize_tnfr_nodes",
261-
"generate_grammar_valid_sequence",
262-
"validate_sequence_grammar",
263-
]
123+
__all__ = ["create_tnfr_topology", "initialize_tnfr_nodes"]

0 commit comments

Comments
 (0)