tnfr 6.0.0__py3-none-any.whl → 7.0.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 +50 -5
- tnfr/__init__.pyi +0 -7
- tnfr/_compat.py +0 -1
- tnfr/_generated_version.py +34 -0
- tnfr/_version.py +44 -2
- tnfr/alias.py +14 -13
- tnfr/alias.pyi +5 -37
- tnfr/cache.py +9 -729
- tnfr/cache.pyi +8 -224
- tnfr/callback_utils.py +16 -31
- tnfr/callback_utils.pyi +3 -29
- tnfr/cli/__init__.py +17 -11
- tnfr/cli/__init__.pyi +0 -21
- tnfr/cli/arguments.py +175 -14
- tnfr/cli/arguments.pyi +5 -11
- tnfr/cli/execution.py +434 -48
- tnfr/cli/execution.pyi +14 -24
- tnfr/cli/utils.py +20 -3
- tnfr/cli/utils.pyi +5 -5
- tnfr/config/__init__.py +2 -1
- tnfr/config/__init__.pyi +2 -0
- tnfr/config/feature_flags.py +83 -0
- tnfr/config/init.py +1 -1
- tnfr/config/operator_names.py +1 -14
- tnfr/config/presets.py +6 -26
- tnfr/constants/__init__.py +10 -13
- tnfr/constants/__init__.pyi +10 -22
- tnfr/constants/aliases.py +31 -0
- tnfr/constants/core.py +4 -3
- tnfr/constants/init.py +1 -1
- tnfr/constants/metric.py +3 -3
- tnfr/dynamics/__init__.py +64 -10
- tnfr/dynamics/__init__.pyi +3 -4
- tnfr/dynamics/adaptation.py +79 -13
- tnfr/dynamics/aliases.py +10 -9
- tnfr/dynamics/coordination.py +77 -35
- tnfr/dynamics/dnfr.py +575 -274
- tnfr/dynamics/dnfr.pyi +1 -10
- tnfr/dynamics/integrators.py +47 -33
- tnfr/dynamics/integrators.pyi +0 -1
- tnfr/dynamics/runtime.py +489 -129
- tnfr/dynamics/sampling.py +2 -0
- tnfr/dynamics/selectors.py +101 -62
- tnfr/execution.py +15 -8
- tnfr/execution.pyi +5 -25
- tnfr/flatten.py +7 -3
- tnfr/flatten.pyi +1 -8
- tnfr/gamma.py +22 -26
- tnfr/gamma.pyi +0 -6
- tnfr/glyph_history.py +37 -26
- tnfr/glyph_history.pyi +1 -19
- tnfr/glyph_runtime.py +16 -0
- tnfr/glyph_runtime.pyi +9 -0
- tnfr/immutable.py +20 -15
- tnfr/immutable.pyi +4 -7
- tnfr/initialization.py +5 -7
- tnfr/initialization.pyi +1 -9
- tnfr/io.py +6 -305
- tnfr/io.pyi +13 -8
- tnfr/mathematics/__init__.py +81 -0
- tnfr/mathematics/backend.py +426 -0
- tnfr/mathematics/dynamics.py +398 -0
- tnfr/mathematics/epi.py +254 -0
- tnfr/mathematics/generators.py +222 -0
- tnfr/mathematics/metrics.py +119 -0
- tnfr/mathematics/operators.py +233 -0
- tnfr/mathematics/operators_factory.py +71 -0
- tnfr/mathematics/projection.py +78 -0
- tnfr/mathematics/runtime.py +173 -0
- tnfr/mathematics/spaces.py +247 -0
- tnfr/mathematics/transforms.py +292 -0
- tnfr/metrics/__init__.py +10 -10
- tnfr/metrics/coherence.py +123 -94
- tnfr/metrics/common.py +22 -13
- tnfr/metrics/common.pyi +42 -11
- tnfr/metrics/core.py +72 -14
- tnfr/metrics/diagnosis.py +48 -57
- tnfr/metrics/diagnosis.pyi +3 -7
- tnfr/metrics/export.py +3 -5
- tnfr/metrics/glyph_timing.py +41 -31
- tnfr/metrics/reporting.py +13 -6
- tnfr/metrics/sense_index.py +884 -114
- tnfr/metrics/trig.py +167 -11
- tnfr/metrics/trig.pyi +1 -0
- tnfr/metrics/trig_cache.py +112 -15
- tnfr/node.py +400 -17
- tnfr/node.pyi +55 -38
- tnfr/observers.py +111 -8
- tnfr/observers.pyi +0 -15
- tnfr/ontosim.py +9 -6
- tnfr/ontosim.pyi +0 -5
- tnfr/operators/__init__.py +529 -42
- tnfr/operators/__init__.pyi +14 -0
- tnfr/operators/definitions.py +350 -18
- tnfr/operators/definitions.pyi +0 -14
- tnfr/operators/grammar.py +760 -0
- tnfr/operators/jitter.py +28 -22
- tnfr/operators/registry.py +7 -12
- tnfr/operators/registry.pyi +0 -2
- tnfr/operators/remesh.py +38 -61
- tnfr/rng.py +17 -300
- tnfr/schemas/__init__.py +8 -0
- tnfr/schemas/grammar.json +94 -0
- tnfr/selector.py +3 -4
- tnfr/selector.pyi +1 -1
- tnfr/sense.py +22 -24
- tnfr/sense.pyi +0 -7
- tnfr/structural.py +504 -21
- tnfr/structural.pyi +41 -18
- tnfr/telemetry/__init__.py +23 -1
- tnfr/telemetry/cache_metrics.py +226 -0
- tnfr/telemetry/nu_f.py +423 -0
- tnfr/telemetry/nu_f.pyi +123 -0
- tnfr/tokens.py +1 -4
- tnfr/tokens.pyi +1 -6
- tnfr/trace.py +20 -53
- tnfr/trace.pyi +9 -37
- tnfr/types.py +244 -15
- tnfr/types.pyi +200 -14
- tnfr/units.py +69 -0
- tnfr/units.pyi +16 -0
- tnfr/utils/__init__.py +107 -48
- tnfr/utils/__init__.pyi +80 -11
- tnfr/utils/cache.py +1705 -65
- tnfr/utils/cache.pyi +370 -58
- tnfr/utils/chunks.py +104 -0
- tnfr/utils/chunks.pyi +21 -0
- tnfr/utils/data.py +95 -5
- tnfr/utils/data.pyi +8 -17
- tnfr/utils/graph.py +2 -4
- tnfr/utils/init.py +31 -7
- tnfr/utils/init.pyi +4 -11
- tnfr/utils/io.py +313 -14
- tnfr/{helpers → utils}/numeric.py +50 -24
- tnfr/utils/numeric.pyi +21 -0
- tnfr/validation/__init__.py +92 -4
- tnfr/validation/__init__.pyi +77 -17
- tnfr/validation/compatibility.py +79 -43
- tnfr/validation/compatibility.pyi +4 -6
- tnfr/validation/grammar.py +55 -133
- tnfr/validation/grammar.pyi +37 -8
- tnfr/validation/graph.py +138 -0
- tnfr/validation/graph.pyi +17 -0
- tnfr/validation/rules.py +161 -74
- tnfr/validation/rules.pyi +55 -18
- tnfr/validation/runtime.py +263 -0
- tnfr/validation/runtime.pyi +31 -0
- tnfr/validation/soft_filters.py +170 -0
- tnfr/validation/soft_filters.pyi +37 -0
- tnfr/validation/spectral.py +159 -0
- tnfr/validation/spectral.pyi +46 -0
- tnfr/validation/syntax.py +28 -139
- tnfr/validation/syntax.pyi +7 -4
- tnfr/validation/window.py +39 -0
- tnfr/validation/window.pyi +1 -0
- tnfr/viz/__init__.py +9 -0
- tnfr/viz/matplotlib.py +246 -0
- {tnfr-6.0.0.dist-info → tnfr-7.0.0.dist-info}/METADATA +63 -19
- tnfr-7.0.0.dist-info/RECORD +185 -0
- {tnfr-6.0.0.dist-info → tnfr-7.0.0.dist-info}/licenses/LICENSE.md +1 -1
- tnfr/constants_glyphs.py +0 -16
- tnfr/constants_glyphs.pyi +0 -12
- tnfr/grammar.py +0 -25
- tnfr/grammar.pyi +0 -13
- tnfr/helpers/__init__.py +0 -151
- tnfr/helpers/__init__.pyi +0 -66
- tnfr/helpers/numeric.pyi +0 -12
- tnfr/presets.py +0 -15
- tnfr/presets.pyi +0 -7
- tnfr/utils/io.pyi +0 -10
- tnfr/utils/validators.py +0 -130
- tnfr/utils/validators.pyi +0 -19
- tnfr-6.0.0.dist-info/RECORD +0 -157
- {tnfr-6.0.0.dist-info → tnfr-7.0.0.dist-info}/WHEEL +0 -0
- {tnfr-6.0.0.dist-info → tnfr-7.0.0.dist-info}/entry_points.txt +0 -0
- {tnfr-6.0.0.dist-info → tnfr-7.0.0.dist-info}/top_level.txt +0 -0
tnfr/telemetry/nu_f.pyi
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections import deque
|
|
4
|
+
from collections.abc import MutableMapping
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Any, Mapping, Sequence
|
|
7
|
+
|
|
8
|
+
from ..types import GraphLike
|
|
9
|
+
|
|
10
|
+
__all__ = (
|
|
11
|
+
"NuFWindow",
|
|
12
|
+
"NuFSnapshot",
|
|
13
|
+
"NuFTelemetryAccumulator",
|
|
14
|
+
"ensure_nu_f_telemetry",
|
|
15
|
+
"record_nu_f_window",
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class NuFWindow:
|
|
21
|
+
reorganisations: int
|
|
22
|
+
duration: float
|
|
23
|
+
start: float | None = ...
|
|
24
|
+
end: float | None = ...
|
|
25
|
+
|
|
26
|
+
def __post_init__(self) -> None: ...
|
|
27
|
+
|
|
28
|
+
@classmethod
|
|
29
|
+
def from_bounds(cls, reorganisations: int, start: float, end: float) -> NuFWindow: ...
|
|
30
|
+
|
|
31
|
+
def as_payload(self) -> Mapping[str, float | int | None]: ...
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class NuFSnapshot:
|
|
36
|
+
windows: Sequence[NuFWindow]
|
|
37
|
+
total_reorganisations: int
|
|
38
|
+
total_duration: float
|
|
39
|
+
rate_hz_str: float | None
|
|
40
|
+
rate_hz: float | None
|
|
41
|
+
variance_hz_str: float | None
|
|
42
|
+
variance_hz: float | None
|
|
43
|
+
confidence_level: float | None
|
|
44
|
+
ci_lower_hz_str: float | None
|
|
45
|
+
ci_upper_hz_str: float | None
|
|
46
|
+
ci_lower_hz: float | None
|
|
47
|
+
ci_upper_hz: float | None
|
|
48
|
+
|
|
49
|
+
def as_payload(self) -> dict[str, Any]: ...
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class NuFTelemetryAccumulator:
|
|
53
|
+
_windows: deque[NuFWindow]
|
|
54
|
+
|
|
55
|
+
def __init__(
|
|
56
|
+
self,
|
|
57
|
+
*,
|
|
58
|
+
confidence_level: float = ...,
|
|
59
|
+
history_limit: int | None = ...,
|
|
60
|
+
window_limit: int | None = ...,
|
|
61
|
+
graph: GraphLike | MutableMapping[str, Any] | None = ...,
|
|
62
|
+
) -> None: ...
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def confidence_level(self) -> float: ...
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def history_limit(self) -> int | None: ...
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def window_limit(self) -> int | None: ...
|
|
72
|
+
|
|
73
|
+
def attach_graph(
|
|
74
|
+
self, graph: GraphLike | MutableMapping[str, Any] | None
|
|
75
|
+
) -> None: ...
|
|
76
|
+
|
|
77
|
+
def record_window(
|
|
78
|
+
self,
|
|
79
|
+
window: NuFWindow,
|
|
80
|
+
*,
|
|
81
|
+
graph: GraphLike | MutableMapping[str, Any] | None = ...,
|
|
82
|
+
) -> NuFSnapshot: ...
|
|
83
|
+
|
|
84
|
+
def record_counts(
|
|
85
|
+
self,
|
|
86
|
+
reorganisations: int,
|
|
87
|
+
duration: float,
|
|
88
|
+
*,
|
|
89
|
+
start: float | None = ...,
|
|
90
|
+
end: float | None = ...,
|
|
91
|
+
graph: GraphLike | MutableMapping[str, Any] | None = ...,
|
|
92
|
+
) -> NuFSnapshot: ...
|
|
93
|
+
|
|
94
|
+
def reset(self) -> None: ...
|
|
95
|
+
|
|
96
|
+
def snapshot(
|
|
97
|
+
self,
|
|
98
|
+
*,
|
|
99
|
+
graph: GraphLike | MutableMapping[str, Any] | None = ...,
|
|
100
|
+
) -> NuFSnapshot: ...
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def ensure_nu_f_telemetry(
|
|
104
|
+
graph: GraphLike,
|
|
105
|
+
*,
|
|
106
|
+
confidence_level: float | None = ...,
|
|
107
|
+
history_limit: int | None = ...,
|
|
108
|
+
window_limit: int | None = ...,
|
|
109
|
+
) -> NuFTelemetryAccumulator: ...
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def record_nu_f_window(
|
|
113
|
+
graph: GraphLike,
|
|
114
|
+
reorganisations: int,
|
|
115
|
+
duration: float,
|
|
116
|
+
*,
|
|
117
|
+
start: float | None = ...,
|
|
118
|
+
end: float | None = ...,
|
|
119
|
+
confidence_level: float | None = ...,
|
|
120
|
+
history_limit: int | None = ...,
|
|
121
|
+
window_limit: int | None = ...,
|
|
122
|
+
) -> NuFSnapshot: ...
|
|
123
|
+
|
tnfr/tokens.py
CHANGED
|
@@ -6,10 +6,7 @@ from dataclasses import dataclass
|
|
|
6
6
|
from enum import Enum, auto
|
|
7
7
|
from typing import Any, Iterable, Optional, Sequence, Union
|
|
8
8
|
|
|
9
|
-
from .types import Glyph,
|
|
10
|
-
|
|
11
|
-
Node = NodeId
|
|
12
|
-
#: Alias maintained for backwards compatibility with historical token helpers.
|
|
9
|
+
from .types import Glyph, Node
|
|
13
10
|
|
|
14
11
|
|
|
15
12
|
@dataclass(slots=True)
|
tnfr/tokens.pyi
CHANGED
|
@@ -4,36 +4,31 @@ from dataclasses import dataclass
|
|
|
4
4
|
from enum import Enum
|
|
5
5
|
from typing import Iterable, Optional, Sequence
|
|
6
6
|
|
|
7
|
-
from .types import Glyph, NodeId
|
|
8
7
|
from ._compat import TypeAlias
|
|
8
|
+
from .types import Glyph, NodeId
|
|
9
9
|
|
|
10
10
|
__all__: tuple[str, ...]
|
|
11
11
|
|
|
12
12
|
Node: TypeAlias = NodeId
|
|
13
13
|
|
|
14
|
-
|
|
15
14
|
@dataclass(slots=True)
|
|
16
15
|
class WAIT:
|
|
17
16
|
steps: int = 1
|
|
18
17
|
|
|
19
|
-
|
|
20
18
|
@dataclass(slots=True)
|
|
21
19
|
class TARGET:
|
|
22
20
|
nodes: Optional[Iterable[Node]] = None
|
|
23
21
|
|
|
24
|
-
|
|
25
22
|
@dataclass(slots=True)
|
|
26
23
|
class THOL:
|
|
27
24
|
body: Sequence["Token"]
|
|
28
25
|
repeat: int = 1
|
|
29
26
|
force_close: Optional[Glyph] = None
|
|
30
27
|
|
|
31
|
-
|
|
32
28
|
Token: TypeAlias = Glyph | WAIT | TARGET | THOL | str
|
|
33
29
|
|
|
34
30
|
THOL_SENTINEL: object
|
|
35
31
|
|
|
36
|
-
|
|
37
32
|
class OpTag(Enum):
|
|
38
33
|
TARGET = ...
|
|
39
34
|
WAIT = ...
|
tnfr/trace.py
CHANGED
|
@@ -8,18 +8,16 @@ structures as immutable snapshots.
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
10
|
import warnings
|
|
11
|
-
|
|
12
|
-
from typing import Any, Callable, Protocol, NamedTuple, TypedDict, cast
|
|
13
11
|
from collections.abc import Iterable, Mapping
|
|
14
12
|
from types import MappingProxyType
|
|
13
|
+
from typing import Any, Callable, NamedTuple, Protocol, cast
|
|
15
14
|
|
|
16
15
|
from .constants import TRACE
|
|
17
|
-
from .glyph_history import
|
|
18
|
-
from .utils import cached_import, get_graph_mapping, is_non_string_sequence
|
|
16
|
+
from .glyph_history import append_metric, count_glyphs, ensure_history
|
|
19
17
|
from .metrics.sense_index import _normalise_si_sensitivity_mapping
|
|
20
18
|
from .telemetry.verbosity import (
|
|
21
|
-
TelemetryVerbosity,
|
|
22
19
|
TELEMETRY_VERBOSITY_DEFAULT,
|
|
20
|
+
TelemetryVerbosity,
|
|
23
21
|
)
|
|
24
22
|
from .types import (
|
|
25
23
|
SigmaVector,
|
|
@@ -28,19 +26,18 @@ from .types import (
|
|
|
28
26
|
TraceFieldFn,
|
|
29
27
|
TraceFieldMap,
|
|
30
28
|
TraceFieldRegistry,
|
|
29
|
+
TraceMetadata,
|
|
30
|
+
TraceSnapshot,
|
|
31
31
|
)
|
|
32
|
+
from .utils import cached_import, get_graph_mapping, is_non_string_sequence
|
|
32
33
|
|
|
33
34
|
|
|
34
35
|
class _KuramotoFn(Protocol):
|
|
35
|
-
def __call__(self, G: TNFRGraph) -> tuple[float, float]:
|
|
36
|
-
...
|
|
36
|
+
def __call__(self, G: TNFRGraph) -> tuple[float, float]: ...
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
class _SigmaVectorFn(Protocol):
|
|
40
|
-
def __call__(
|
|
41
|
-
self, G: TNFRGraph, weight_mode: str | None = None
|
|
42
|
-
) -> SigmaVector:
|
|
43
|
-
...
|
|
40
|
+
def __call__(self, G: TNFRGraph, weight_mode: str | None = None) -> SigmaVector: ...
|
|
44
41
|
|
|
45
42
|
|
|
46
43
|
class CallbackSpec(NamedTuple):
|
|
@@ -50,29 +47,6 @@ class CallbackSpec(NamedTuple):
|
|
|
50
47
|
func: Callable[..., Any]
|
|
51
48
|
|
|
52
49
|
|
|
53
|
-
class TraceMetadata(TypedDict, total=False):
|
|
54
|
-
"""Metadata captured by trace field functions."""
|
|
55
|
-
|
|
56
|
-
gamma: Mapping[str, Any]
|
|
57
|
-
grammar: Mapping[str, Any]
|
|
58
|
-
selector: str | None
|
|
59
|
-
dnfr_weights: Mapping[str, Any]
|
|
60
|
-
si_weights: Mapping[str, Any]
|
|
61
|
-
si_sensitivity: Mapping[str, Any]
|
|
62
|
-
callbacks: Mapping[str, list[str] | None]
|
|
63
|
-
thol_open_nodes: int
|
|
64
|
-
kuramoto: Mapping[str, float]
|
|
65
|
-
sigma: Mapping[str, float]
|
|
66
|
-
glyphs: Mapping[str, int]
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
class TraceSnapshot(TraceMetadata, total=False):
|
|
70
|
-
"""Trace snapshot stored in the history."""
|
|
71
|
-
|
|
72
|
-
t: float
|
|
73
|
-
phase: str
|
|
74
|
-
|
|
75
|
-
|
|
76
50
|
class TraceFieldSpec(NamedTuple):
|
|
77
51
|
"""Declarative specification for a trace field producer."""
|
|
78
52
|
|
|
@@ -153,9 +127,7 @@ kuramoto_R_psi: _KuramotoFn = cast(
|
|
|
153
127
|
)
|
|
154
128
|
|
|
155
129
|
|
|
156
|
-
def _sigma_fallback(
|
|
157
|
-
G: TNFRGraph, _weight_mode: str | None = None
|
|
158
|
-
) -> SigmaVector:
|
|
130
|
+
def _sigma_fallback(G: TNFRGraph, _weight_mode: str | None = None) -> SigmaVector:
|
|
159
131
|
"""Return a null sigma vector regardless of ``_weight_mode``."""
|
|
160
132
|
|
|
161
133
|
return {"x": 0.0, "y": 0.0, "mag": 0.0, "angle": 0.0, "n": 0}
|
|
@@ -187,7 +159,7 @@ def _trace_setup(
|
|
|
187
159
|
dict[str, Any] | None,
|
|
188
160
|
str | None,
|
|
189
161
|
]:
|
|
190
|
-
"""
|
|
162
|
+
"""Prepare common configuration for trace snapshots.
|
|
191
163
|
|
|
192
164
|
Returns the active configuration, capture set, history and key under
|
|
193
165
|
which metadata will be stored. If tracing is disabled returns
|
|
@@ -212,9 +184,7 @@ def _callback_names(
|
|
|
212
184
|
if isinstance(callbacks, Mapping):
|
|
213
185
|
callbacks = callbacks.values()
|
|
214
186
|
return [
|
|
215
|
-
cb.name
|
|
216
|
-
if cb.name is not None
|
|
217
|
-
else str(getattr(cb.func, "__name__", "fn"))
|
|
187
|
+
cb.name if cb.name is not None else str(getattr(cb.func, "__name__", "fn"))
|
|
218
188
|
for cb in callbacks
|
|
219
189
|
]
|
|
220
190
|
|
|
@@ -223,7 +193,7 @@ EMPTY_MAPPING: Mapping[str, Any] = MappingProxyType({})
|
|
|
223
193
|
|
|
224
194
|
|
|
225
195
|
def mapping_field(G: TNFRGraph, graph_key: str, out_key: str) -> TraceMetadata:
|
|
226
|
-
"""
|
|
196
|
+
"""Copy mappings from ``G.graph`` into trace output."""
|
|
227
197
|
mapping = get_graph_mapping(
|
|
228
198
|
G, graph_key, f"G.graph[{graph_key!r}] is not a mapping; ignoring"
|
|
229
199
|
)
|
|
@@ -259,9 +229,7 @@ def _new_trace_meta(
|
|
|
259
229
|
# -------------------------
|
|
260
230
|
|
|
261
231
|
|
|
262
|
-
def _trace_capture(
|
|
263
|
-
G: TNFRGraph, phase: str, fields: TraceFieldMap
|
|
264
|
-
) -> None:
|
|
232
|
+
def _trace_capture(G: TNFRGraph, phase: str, fields: TraceFieldMap) -> None:
|
|
265
233
|
"""Capture ``fields`` for ``phase`` and store the snapshot.
|
|
266
234
|
|
|
267
235
|
A :class:`TraceSnapshot` is appended to the configured history when
|
|
@@ -292,19 +260,21 @@ def _trace_capture(
|
|
|
292
260
|
TRACE_FIELDS: TraceFieldRegistry = {}
|
|
293
261
|
|
|
294
262
|
|
|
295
|
-
def register_trace_field(
|
|
296
|
-
phase: str, name: str, func: TraceFieldFn
|
|
297
|
-
) -> None:
|
|
263
|
+
def register_trace_field(phase: str, name: str, func: TraceFieldFn) -> None:
|
|
298
264
|
"""Register ``func`` to populate trace field ``name`` during ``phase``."""
|
|
299
265
|
|
|
300
266
|
TRACE_FIELDS.setdefault(phase, {})[name] = func
|
|
301
267
|
|
|
302
268
|
|
|
303
269
|
def gamma_field(G: TNFRGraph) -> TraceMetadata:
|
|
270
|
+
"""Expose γ-field metadata stored under ``G.graph['GAMMA']``."""
|
|
271
|
+
|
|
304
272
|
return mapping_field(G, "GAMMA", "gamma")
|
|
305
273
|
|
|
306
274
|
|
|
307
275
|
def grammar_field(G: TNFRGraph) -> TraceMetadata:
|
|
276
|
+
"""Expose canonical grammar metadata for trace emission."""
|
|
277
|
+
|
|
308
278
|
return mapping_field(G, "GRAMMAR_CANON", "grammar")
|
|
309
279
|
|
|
310
280
|
|
|
@@ -500,9 +470,7 @@ TRACE_FIELD_SPECS: tuple[TraceFieldSpec, ...] = (
|
|
|
500
470
|
)
|
|
501
471
|
|
|
502
472
|
TRACE_VERBOSITY_PRESETS = {
|
|
503
|
-
level.value: tuple(
|
|
504
|
-
spec.name for spec in TRACE_FIELD_SPECS if level in spec.tiers
|
|
505
|
-
)
|
|
473
|
+
level.value: tuple(spec.name for spec in TRACE_FIELD_SPECS if level in spec.tiers)
|
|
506
474
|
for level in TelemetryVerbosity
|
|
507
475
|
}
|
|
508
476
|
|
|
@@ -516,8 +484,7 @@ for spec in TRACE_FIELD_SPECS:
|
|
|
516
484
|
|
|
517
485
|
|
|
518
486
|
def register_trace(G: TNFRGraph) -> None:
|
|
519
|
-
"""Enable before/after-step snapshots and dump operational metadata
|
|
520
|
-
to history.
|
|
487
|
+
"""Enable before/after-step snapshots and dump operational metadata to history.
|
|
521
488
|
|
|
522
489
|
Trace snapshots are stored as :class:`TraceSnapshot` entries in
|
|
523
490
|
``G.graph['history'][TRACE.history_key]`` with:
|
tnfr/trace.pyi
CHANGED
|
@@ -1,68 +1,40 @@
|
|
|
1
|
-
from typing import Any, Callable, NamedTuple, TypedDict
|
|
2
1
|
from collections.abc import Iterable, Mapping
|
|
2
|
+
from typing import Any, Callable, NamedTuple
|
|
3
3
|
|
|
4
|
-
from .types import
|
|
4
|
+
from .types import (
|
|
5
|
+
TNFRGraph,
|
|
6
|
+
TraceFieldFn,
|
|
7
|
+
TraceFieldMap,
|
|
8
|
+
TraceFieldRegistry,
|
|
9
|
+
TraceMetadata,
|
|
10
|
+
TraceSnapshot,
|
|
11
|
+
)
|
|
5
12
|
|
|
6
13
|
__all__: tuple[str, ...]
|
|
7
14
|
|
|
8
15
|
def __getattr__(name: str) -> Any: ...
|
|
9
16
|
|
|
10
|
-
|
|
11
17
|
class CallbackSpec(NamedTuple):
|
|
12
18
|
name: str | None
|
|
13
19
|
func: Callable[..., Any]
|
|
14
20
|
|
|
15
|
-
|
|
16
|
-
class TraceMetadata(TypedDict, total=False):
|
|
17
|
-
gamma: Mapping[str, Any]
|
|
18
|
-
grammar: Mapping[str, Any]
|
|
19
|
-
selector: str | None
|
|
20
|
-
dnfr_weights: Mapping[str, Any]
|
|
21
|
-
si_weights: Mapping[str, Any]
|
|
22
|
-
si_sensitivity: Mapping[str, Any]
|
|
23
|
-
callbacks: Mapping[str, list[str] | None]
|
|
24
|
-
thol_open_nodes: int
|
|
25
|
-
kuramoto: Mapping[str, float]
|
|
26
|
-
sigma: Mapping[str, float]
|
|
27
|
-
glyphs: Mapping[str, int]
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class TraceSnapshot(TraceMetadata, total=False):
|
|
31
|
-
t: float
|
|
32
|
-
phase: str
|
|
33
|
-
|
|
34
|
-
|
|
35
21
|
kuramoto_R_psi: Callable[[TNFRGraph], tuple[float, float]]
|
|
36
22
|
TRACE_FIELDS: TraceFieldRegistry
|
|
37
23
|
|
|
38
24
|
def _callback_names(
|
|
39
25
|
callbacks: Mapping[str, CallbackSpec] | Iterable[CallbackSpec],
|
|
40
26
|
) -> list[str]: ...
|
|
41
|
-
|
|
42
27
|
def mapping_field(G: TNFRGraph, graph_key: str, out_key: str) -> TraceMetadata: ...
|
|
43
|
-
|
|
44
28
|
def _trace_capture(G: TNFRGraph, phase: str, fields: TraceFieldMap) -> None: ...
|
|
45
|
-
|
|
46
29
|
def register_trace_field(phase: str, name: str, func: TraceFieldFn) -> None: ...
|
|
47
|
-
|
|
48
30
|
def gamma_field(G: TNFRGraph) -> TraceMetadata: ...
|
|
49
|
-
|
|
50
31
|
def grammar_field(G: TNFRGraph) -> TraceMetadata: ...
|
|
51
|
-
|
|
52
32
|
def dnfr_weights_field(G: TNFRGraph) -> TraceMetadata: ...
|
|
53
|
-
|
|
54
33
|
def selector_field(G: TNFRGraph) -> TraceMetadata: ...
|
|
55
|
-
|
|
56
34
|
def si_weights_field(G: TNFRGraph) -> TraceMetadata: ...
|
|
57
|
-
|
|
58
35
|
def callbacks_field(G: TNFRGraph) -> TraceMetadata: ...
|
|
59
|
-
|
|
60
36
|
def thol_state_field(G: TNFRGraph) -> TraceMetadata: ...
|
|
61
|
-
|
|
62
37
|
def kuramoto_field(G: TNFRGraph) -> TraceMetadata: ...
|
|
63
|
-
|
|
64
38
|
def sigma_field(G: TNFRGraph) -> TraceMetadata: ...
|
|
65
|
-
|
|
66
39
|
def glyph_counts_field(G: TNFRGraph) -> TraceMetadata: ...
|
|
67
|
-
|
|
68
40
|
def register_trace(G: TNFRGraph) -> None: ...
|