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/cache.pyi
CHANGED
|
@@ -1,232 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import threading
|
|
3
|
-
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping
|
|
4
|
-
from dataclasses import dataclass
|
|
5
|
-
from typing import Any, ClassVar, Generic, Hashable, TypeVar
|
|
1
|
+
"""Compatibility stub removed; import from :mod:`tnfr.utils.cache` instead."""
|
|
6
2
|
|
|
7
|
-
from
|
|
3
|
+
from __future__ import annotations
|
|
8
4
|
|
|
9
|
-
from
|
|
5
|
+
from typing import NoReturn
|
|
10
6
|
|
|
11
|
-
__all__ =
|
|
12
|
-
"CacheManager",
|
|
13
|
-
"CacheCapacityConfig",
|
|
14
|
-
"CacheStatistics",
|
|
15
|
-
"InstrumentedLRUCache",
|
|
16
|
-
"ManagedLRUCache",
|
|
17
|
-
"prune_lock_mapping",
|
|
18
|
-
]
|
|
7
|
+
__all__ = ()
|
|
19
8
|
|
|
20
|
-
K = TypeVar("K", bound=Hashable)
|
|
21
|
-
V = TypeVar("V")
|
|
22
9
|
|
|
10
|
+
def __getattr__(name: str) -> NoReturn:
|
|
11
|
+
"""Indicate that :mod:`tnfr.cache` no longer exports cache helpers."""
|
|
23
12
|
|
|
24
|
-
@dataclass(frozen=True)
|
|
25
|
-
class CacheCapacityConfig:
|
|
26
|
-
default_capacity: int | None
|
|
27
|
-
overrides: dict[str, int | None]
|
|
28
13
|
|
|
14
|
+
def __dir__() -> tuple[str, ...]:
|
|
15
|
+
"""Return an empty set of exports to mirror the removed shim."""
|
|
29
16
|
|
|
30
|
-
@dataclass(frozen=True)
|
|
31
|
-
class CacheStatistics:
|
|
32
|
-
hits: int = ...
|
|
33
|
-
misses: int = ...
|
|
34
|
-
evictions: int = ...
|
|
35
|
-
total_time: float = ...
|
|
36
|
-
timings: int = ...
|
|
37
|
-
|
|
38
|
-
def merge(self, other: CacheStatistics) -> CacheStatistics: ...
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
class CacheManager:
|
|
42
|
-
_MISSING: ClassVar[object]
|
|
43
|
-
|
|
44
|
-
def __init__(
|
|
45
|
-
self,
|
|
46
|
-
storage: MutableMapping[str, Any] | None = ...,
|
|
47
|
-
*,
|
|
48
|
-
default_capacity: int | None = ...,
|
|
49
|
-
overrides: Mapping[str, int | None] | None = ...,
|
|
50
|
-
) -> None: ...
|
|
51
|
-
|
|
52
|
-
@staticmethod
|
|
53
|
-
def _normalise_capacity(value: int | None) -> int | None: ...
|
|
54
|
-
|
|
55
|
-
def register(
|
|
56
|
-
self,
|
|
57
|
-
name: str,
|
|
58
|
-
factory: Callable[[], Any],
|
|
59
|
-
*,
|
|
60
|
-
lock_factory: Callable[[], threading.Lock | threading.RLock] | None = ...,
|
|
61
|
-
reset: Callable[[Any], Any] | None = ...,
|
|
62
|
-
create: bool = ...,
|
|
63
|
-
) -> None: ...
|
|
64
|
-
|
|
65
|
-
def configure(
|
|
66
|
-
self,
|
|
67
|
-
*,
|
|
68
|
-
default_capacity: int | None | object = ...,
|
|
69
|
-
overrides: Mapping[str, int | None] | None = ...,
|
|
70
|
-
replace_overrides: bool = ...,
|
|
71
|
-
) -> None: ...
|
|
72
|
-
|
|
73
|
-
def configure_from_mapping(self, config: Mapping[str, Any]) -> None: ...
|
|
74
|
-
|
|
75
|
-
def export_config(self) -> CacheCapacityConfig: ...
|
|
76
|
-
|
|
77
|
-
def get_capacity(
|
|
78
|
-
self,
|
|
79
|
-
name: str,
|
|
80
|
-
*,
|
|
81
|
-
requested: int | None = ...,
|
|
82
|
-
fallback: int | None = ...,
|
|
83
|
-
use_default: bool = ...,
|
|
84
|
-
) -> int | None: ...
|
|
85
|
-
|
|
86
|
-
def has_override(self, name: str) -> bool: ...
|
|
87
|
-
|
|
88
|
-
def get_lock(self, name: str) -> threading.Lock | threading.RLock: ...
|
|
89
|
-
|
|
90
|
-
def names(self) -> Iterator[str]: ...
|
|
91
|
-
|
|
92
|
-
def get(self, name: str, *, create: bool = ...) -> Any: ...
|
|
93
|
-
|
|
94
|
-
def peek(self, name: str) -> Any: ...
|
|
95
|
-
|
|
96
|
-
def store(self, name: str, value: Any) -> None: ...
|
|
97
|
-
|
|
98
|
-
def update(
|
|
99
|
-
self,
|
|
100
|
-
name: str,
|
|
101
|
-
updater: Callable[[Any], Any],
|
|
102
|
-
*,
|
|
103
|
-
create: bool = ...,
|
|
104
|
-
) -> Any: ...
|
|
105
|
-
|
|
106
|
-
def clear(self, name: str | None = ...) -> None: ...
|
|
107
|
-
|
|
108
|
-
def increment_hit(
|
|
109
|
-
self,
|
|
110
|
-
name: str,
|
|
111
|
-
*,
|
|
112
|
-
amount: int = ...,
|
|
113
|
-
duration: float | None = ...,
|
|
114
|
-
) -> None: ...
|
|
115
|
-
|
|
116
|
-
def increment_miss(
|
|
117
|
-
self,
|
|
118
|
-
name: str,
|
|
119
|
-
*,
|
|
120
|
-
amount: int = ...,
|
|
121
|
-
duration: float | None = ...,
|
|
122
|
-
) -> None: ...
|
|
123
|
-
|
|
124
|
-
def increment_eviction(self, name: str, *, amount: int = ...) -> None: ...
|
|
125
|
-
|
|
126
|
-
def record_timing(self, name: str, duration: float) -> None: ...
|
|
127
|
-
|
|
128
|
-
def timer(self, name: str) -> TimingContext: ...
|
|
129
|
-
|
|
130
|
-
def get_metrics(self, name: str) -> CacheStatistics: ...
|
|
131
|
-
|
|
132
|
-
def iter_metrics(self) -> Iterator[tuple[str, CacheStatistics]]: ...
|
|
133
|
-
|
|
134
|
-
def aggregate_metrics(self) -> CacheStatistics: ...
|
|
135
|
-
|
|
136
|
-
def register_metrics_publisher(
|
|
137
|
-
self, publisher: Callable[[str, CacheStatistics], None]
|
|
138
|
-
) -> None: ...
|
|
139
|
-
|
|
140
|
-
def publish_metrics(
|
|
141
|
-
self,
|
|
142
|
-
*,
|
|
143
|
-
publisher: Callable[[str, CacheStatistics], None] | None = ...,
|
|
144
|
-
) -> None: ...
|
|
145
|
-
|
|
146
|
-
def log_metrics(
|
|
147
|
-
self, logger: logging.Logger, *, level: int = ...
|
|
148
|
-
) -> None: ...
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
class InstrumentedLRUCache(MutableMapping[K, V], Generic[K, V]):
|
|
152
|
-
_MISSING: ClassVar[object]
|
|
153
|
-
|
|
154
|
-
def __init__(
|
|
155
|
-
self,
|
|
156
|
-
maxsize: int,
|
|
157
|
-
*,
|
|
158
|
-
manager: CacheManager | None = ...,
|
|
159
|
-
metrics_key: str | None = ...,
|
|
160
|
-
telemetry_callbacks: Iterable[Callable[[K, V], None]]
|
|
161
|
-
| Callable[[K, V], None]
|
|
162
|
-
| None = ...,
|
|
163
|
-
eviction_callbacks: Iterable[Callable[[K, V], None]]
|
|
164
|
-
| Callable[[K, V], None]
|
|
165
|
-
| None = ...,
|
|
166
|
-
locks: MutableMapping[K, Any] | None = ...,
|
|
167
|
-
getsizeof: Callable[[V], int] | None = ...,
|
|
168
|
-
count_overwrite_hit: bool = ...,
|
|
169
|
-
) -> None: ...
|
|
170
|
-
|
|
171
|
-
@property
|
|
172
|
-
def telemetry_callbacks(self) -> tuple[Callable[[K, V], None], ...]: ...
|
|
173
|
-
|
|
174
|
-
@property
|
|
175
|
-
def eviction_callbacks(self) -> tuple[Callable[[K, V], None], ...]: ...
|
|
176
|
-
|
|
177
|
-
def set_telemetry_callbacks(
|
|
178
|
-
self,
|
|
179
|
-
callbacks: Iterable[Callable[[K, V], None]]
|
|
180
|
-
| Callable[[K, V], None]
|
|
181
|
-
| None,
|
|
182
|
-
*,
|
|
183
|
-
append: bool = ...,
|
|
184
|
-
) -> None: ...
|
|
185
|
-
|
|
186
|
-
def set_eviction_callbacks(
|
|
187
|
-
self,
|
|
188
|
-
callbacks: Iterable[Callable[[K, V], None]]
|
|
189
|
-
| Callable[[K, V], None]
|
|
190
|
-
| None,
|
|
191
|
-
*,
|
|
192
|
-
append: bool = ...,
|
|
193
|
-
) -> None: ...
|
|
194
|
-
|
|
195
|
-
def pop(self, key: K, default: Any = ...) -> V: ...
|
|
196
|
-
|
|
197
|
-
def popitem(self) -> tuple[K, V]: ...
|
|
198
|
-
|
|
199
|
-
def clear(self) -> None: ...
|
|
200
|
-
|
|
201
|
-
@property
|
|
202
|
-
def maxsize(self) -> int: ...
|
|
203
|
-
|
|
204
|
-
@property
|
|
205
|
-
def currsize(self) -> int: ...
|
|
206
|
-
|
|
207
|
-
def get(self, key: K, default: V | None = ...) -> V | None: ...
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
class ManagedLRUCache(LRUCache[K, V], Generic[K, V]):
|
|
211
|
-
def __init__(
|
|
212
|
-
self,
|
|
213
|
-
maxsize: int,
|
|
214
|
-
*,
|
|
215
|
-
manager: CacheManager | None = ...,
|
|
216
|
-
metrics_key: str | None = ...,
|
|
217
|
-
eviction_callbacks: Iterable[Callable[[K, V], None]]
|
|
218
|
-
| Callable[[K, V], None]
|
|
219
|
-
| None = ...,
|
|
220
|
-
telemetry_callbacks: Iterable[Callable[[K, V], None]]
|
|
221
|
-
| Callable[[K, V], None]
|
|
222
|
-
| None = ...,
|
|
223
|
-
locks: MutableMapping[K, Any] | None = ...,
|
|
224
|
-
) -> None: ...
|
|
225
|
-
|
|
226
|
-
def popitem(self) -> tuple[K, V]: ...
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
def prune_lock_mapping(
|
|
230
|
-
cache: Mapping[K, Any] | MutableMapping[K, Any] | None,
|
|
231
|
-
locks: MutableMapping[K, Any] | None,
|
|
232
|
-
) -> None: ...
|
tnfr/callback_utils.py
CHANGED
|
@@ -9,21 +9,20 @@ modify shared state.
|
|
|
9
9
|
|
|
10
10
|
from __future__ import annotations
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
from enum import Enum
|
|
12
|
+
import threading
|
|
13
|
+
import traceback
|
|
15
14
|
from collections import defaultdict, deque
|
|
16
|
-
from collections.abc import Callable,
|
|
15
|
+
from collections.abc import Callable, Iterable, Mapping
|
|
16
|
+
from enum import Enum
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
import networkx as nx
|
|
17
20
|
|
|
18
|
-
import traceback
|
|
19
|
-
import threading
|
|
20
|
-
from .utils import get_logger, is_non_string_sequence
|
|
21
21
|
from .constants import DEFAULTS
|
|
22
22
|
from .locking import get_lock
|
|
23
|
-
|
|
24
23
|
from .trace import CallbackSpec
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
from .utils import get_logger, is_non_string_sequence
|
|
25
|
+
from .types import CallbackError
|
|
27
26
|
|
|
28
27
|
__all__ = (
|
|
29
28
|
"CallbackEvent",
|
|
@@ -41,6 +40,7 @@ class CallbackEvent(str, Enum):
|
|
|
41
40
|
BEFORE_STEP = "before_step"
|
|
42
41
|
AFTER_STEP = "after_step"
|
|
43
42
|
ON_REMESH = "on_remesh"
|
|
43
|
+
CACHE_METRICS = "cache_metrics"
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
class CallbackManager:
|
|
@@ -130,9 +130,7 @@ class CallbackManager:
|
|
|
130
130
|
cb_name = name or getattr(func, "__name__", None)
|
|
131
131
|
spec = CallbackSpec(cb_name, func)
|
|
132
132
|
existing_map = cbs[event]
|
|
133
|
-
strict = bool(
|
|
134
|
-
G.graph.get("CALLBACKS_STRICT", DEFAULTS["CALLBACKS_STRICT"])
|
|
135
|
-
)
|
|
133
|
+
strict = bool(G.graph.get("CALLBACKS_STRICT", DEFAULTS["CALLBACKS_STRICT"]))
|
|
136
134
|
key = _reconcile_callback(event, existing_map, spec, strict)
|
|
137
135
|
|
|
138
136
|
existing_map[key] = spec
|
|
@@ -151,9 +149,7 @@ class CallbackManager:
|
|
|
151
149
|
event = _normalize_event(event)
|
|
152
150
|
with self._lock:
|
|
153
151
|
cbs = dict(self._ensure_callbacks_nolock(G).get(event, {}))
|
|
154
|
-
strict = bool(
|
|
155
|
-
G.graph.get("CALLBACKS_STRICT", DEFAULTS["CALLBACKS_STRICT"])
|
|
156
|
-
)
|
|
152
|
+
strict = bool(G.graph.get("CALLBACKS_STRICT", DEFAULTS["CALLBACKS_STRICT"]))
|
|
157
153
|
if ctx is None:
|
|
158
154
|
ctx = {}
|
|
159
155
|
for spec in cbs.values():
|
|
@@ -184,17 +180,6 @@ Callback = Callable[["nx.Graph", dict[str, Any]], None]
|
|
|
184
180
|
CallbackRegistry = dict[str, dict[str, "CallbackSpec"]]
|
|
185
181
|
|
|
186
182
|
|
|
187
|
-
class CallbackError(TypedDict):
|
|
188
|
-
"""Metadata for a failed callback invocation."""
|
|
189
|
-
|
|
190
|
-
event: str
|
|
191
|
-
step: int | None
|
|
192
|
-
error: str
|
|
193
|
-
traceback: str
|
|
194
|
-
fn: str
|
|
195
|
-
name: str | None
|
|
196
|
-
|
|
197
|
-
|
|
198
183
|
def _func_id(fn: Callable[..., Any]) -> str:
|
|
199
184
|
"""Return a deterministic identifier for ``fn``.
|
|
200
185
|
|
|
@@ -210,9 +195,7 @@ def _func_id(fn: Callable[..., Any]) -> str:
|
|
|
210
195
|
return f"{module}.{qualname}"
|
|
211
196
|
|
|
212
197
|
|
|
213
|
-
def _validate_registry(
|
|
214
|
-
G: "nx.Graph", cbs: Any, dirty: set[str]
|
|
215
|
-
) -> CallbackRegistry:
|
|
198
|
+
def _validate_registry(G: "nx.Graph", cbs: Any, dirty: set[str]) -> CallbackRegistry:
|
|
216
199
|
"""Validate and normalise the callback registry.
|
|
217
200
|
|
|
218
201
|
``cbs`` is coerced to a ``defaultdict(dict)`` and any events listed in
|
|
@@ -249,7 +232,9 @@ def _normalize_callbacks(entries: Any) -> dict[str, CallbackSpec]:
|
|
|
249
232
|
"""Return ``entries`` normalised into a callback mapping."""
|
|
250
233
|
if isinstance(entries, Mapping):
|
|
251
234
|
entries_iter = entries.values()
|
|
252
|
-
elif isinstance(entries, Iterable) and not isinstance(
|
|
235
|
+
elif isinstance(entries, Iterable) and not isinstance(
|
|
236
|
+
entries, (str, bytes, bytearray)
|
|
237
|
+
):
|
|
253
238
|
entries_iter = entries
|
|
254
239
|
else:
|
|
255
240
|
return {}
|
tnfr/callback_utils.pyi
CHANGED
|
@@ -5,13 +5,14 @@ import traceback
|
|
|
5
5
|
from collections import defaultdict, deque
|
|
6
6
|
from collections.abc import Callable, Iterable, Mapping
|
|
7
7
|
from enum import Enum
|
|
8
|
-
from typing import Any
|
|
8
|
+
from typing import Any
|
|
9
9
|
|
|
10
10
|
import networkx as nx
|
|
11
11
|
|
|
12
12
|
from .constants import DEFAULTS
|
|
13
13
|
from .locking import get_lock
|
|
14
14
|
from .trace import CallbackSpec
|
|
15
|
+
from .types import CallbackError
|
|
15
16
|
from .utils import get_logger, is_non_string_sequence
|
|
16
17
|
|
|
17
18
|
__all__ = (
|
|
@@ -23,33 +24,19 @@ __all__ = (
|
|
|
23
24
|
|
|
24
25
|
logger: Any
|
|
25
26
|
|
|
26
|
-
|
|
27
27
|
class CallbackEvent(str, Enum):
|
|
28
28
|
BEFORE_STEP = "before_step"
|
|
29
29
|
AFTER_STEP = "after_step"
|
|
30
30
|
ON_REMESH = "on_remesh"
|
|
31
|
-
|
|
31
|
+
CACHE_METRICS = "cache_metrics"
|
|
32
32
|
|
|
33
33
|
Callback = Callable[[nx.Graph, dict[str, Any]], None]
|
|
34
34
|
CallbackRegistry = dict[str, dict[str, CallbackSpec]]
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
class CallbackError(TypedDict):
|
|
38
|
-
event: str
|
|
39
|
-
step: int | None
|
|
40
|
-
error: str
|
|
41
|
-
traceback: str
|
|
42
|
-
fn: str
|
|
43
|
-
name: str | None
|
|
44
|
-
|
|
45
|
-
|
|
46
36
|
class CallbackManager:
|
|
47
37
|
def __init__(self) -> None: ...
|
|
48
|
-
|
|
49
38
|
def get_callback_error_limit(self) -> int: ...
|
|
50
|
-
|
|
51
39
|
def set_callback_error_limit(self, limit: int) -> int: ...
|
|
52
|
-
|
|
53
40
|
def register_callback(
|
|
54
41
|
self,
|
|
55
42
|
G: nx.Graph,
|
|
@@ -58,14 +45,12 @@ class CallbackManager:
|
|
|
58
45
|
*,
|
|
59
46
|
name: str | None = ...,
|
|
60
47
|
) -> Callback: ...
|
|
61
|
-
|
|
62
48
|
def invoke_callbacks(
|
|
63
49
|
self,
|
|
64
50
|
G: nx.Graph,
|
|
65
51
|
event: CallbackEvent | str,
|
|
66
52
|
ctx: dict[str, Any] | None = ...,
|
|
67
53
|
) -> None: ...
|
|
68
|
-
|
|
69
54
|
def _record_callback_error(
|
|
70
55
|
self,
|
|
71
56
|
G: nx.Graph,
|
|
@@ -74,29 +59,18 @@ class CallbackManager:
|
|
|
74
59
|
spec: CallbackSpec,
|
|
75
60
|
err: Exception,
|
|
76
61
|
) -> None: ...
|
|
77
|
-
|
|
78
62
|
def _ensure_callbacks_nolock(self, G: nx.Graph) -> CallbackRegistry: ...
|
|
79
|
-
|
|
80
63
|
def _ensure_callbacks(self, G: nx.Graph) -> CallbackRegistry: ...
|
|
81
64
|
|
|
82
|
-
|
|
83
65
|
callback_manager: CallbackManager
|
|
84
66
|
|
|
85
|
-
|
|
86
67
|
def _func_id(fn: Callable[..., Any]) -> str: ...
|
|
87
|
-
|
|
88
68
|
def _validate_registry(G: nx.Graph, cbs: Any, dirty: set[str]) -> CallbackRegistry: ...
|
|
89
|
-
|
|
90
69
|
def _normalize_callbacks(entries: Any) -> dict[str, CallbackSpec]: ...
|
|
91
|
-
|
|
92
70
|
def _normalize_event(event: CallbackEvent | str) -> str: ...
|
|
93
|
-
|
|
94
71
|
def _is_known_event(event: str) -> bool: ...
|
|
95
|
-
|
|
96
72
|
def _ensure_known_event(event: str) -> None: ...
|
|
97
|
-
|
|
98
73
|
def _normalize_callback_entry(entry: Any) -> CallbackSpec | None: ...
|
|
99
|
-
|
|
100
74
|
def _reconcile_callback(
|
|
101
75
|
event: str,
|
|
102
76
|
existing_map: dict[str, CallbackSpec],
|
tnfr/cli/__init__.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"""Command-line interface entry points for TNFR."""
|
|
2
|
+
|
|
1
3
|
from __future__ import annotations
|
|
2
4
|
|
|
3
5
|
import argparse
|
|
@@ -5,25 +7,27 @@ import logging
|
|
|
5
7
|
import sys
|
|
6
8
|
from typing import Optional
|
|
7
9
|
|
|
10
|
+
from .. import __version__
|
|
11
|
+
from ..utils import _configure_root, get_logger
|
|
8
12
|
from .arguments import (
|
|
13
|
+
_add_metrics_parser,
|
|
14
|
+
_add_profile_parser,
|
|
15
|
+
_add_profile_pipeline_parser,
|
|
16
|
+
_add_run_parser,
|
|
17
|
+
_add_sequence_parser,
|
|
18
|
+
add_canon_toggle,
|
|
9
19
|
add_common_args,
|
|
10
20
|
add_grammar_args,
|
|
11
21
|
add_grammar_selector_args,
|
|
12
22
|
add_history_export_args,
|
|
13
|
-
add_canon_toggle,
|
|
14
|
-
_add_run_parser,
|
|
15
|
-
_add_sequence_parser,
|
|
16
|
-
_add_metrics_parser,
|
|
17
23
|
)
|
|
18
24
|
from .execution import (
|
|
19
|
-
build_basic_graph,
|
|
20
25
|
apply_cli_config,
|
|
26
|
+
build_basic_graph,
|
|
21
27
|
register_callbacks_and_observer,
|
|
22
|
-
run_program,
|
|
23
28
|
resolve_program,
|
|
29
|
+
run_program,
|
|
24
30
|
)
|
|
25
|
-
from .. import __version__
|
|
26
|
-
from ..utils import _configure_root, get_logger
|
|
27
31
|
|
|
28
32
|
logger = get_logger(__name__)
|
|
29
33
|
|
|
@@ -43,6 +47,8 @@ __all__ = (
|
|
|
43
47
|
|
|
44
48
|
|
|
45
49
|
def main(argv: Optional[list[str]] = None) -> int:
|
|
50
|
+
"""Entry point for the ``tnfr`` CLI returning the exit status."""
|
|
51
|
+
|
|
46
52
|
_configure_root()
|
|
47
53
|
|
|
48
54
|
root = logging.getLogger()
|
|
@@ -69,15 +75,15 @@ def main(argv: Optional[list[str]] = None) -> int:
|
|
|
69
75
|
p.add_argument(
|
|
70
76
|
"--version",
|
|
71
77
|
action="store_true",
|
|
72
|
-
help=(
|
|
73
|
-
"show the actual version and exit (reads pyproject.toml in development)"
|
|
74
|
-
),
|
|
78
|
+
help=("show the actual version and exit (reads pyproject.toml in development)"),
|
|
75
79
|
)
|
|
76
80
|
sub = p.add_subparsers(dest="cmd")
|
|
77
81
|
|
|
78
82
|
_add_run_parser(sub)
|
|
79
83
|
_add_sequence_parser(sub)
|
|
80
84
|
_add_metrics_parser(sub)
|
|
85
|
+
_add_profile_parser(sub)
|
|
86
|
+
_add_profile_pipeline_parser(sub)
|
|
81
87
|
|
|
82
88
|
args = p.parse_args(argv)
|
|
83
89
|
if args.version:
|
tnfr/cli/__init__.pyi
CHANGED
|
@@ -7,39 +7,18 @@ from ..types import ProgramTokens, TNFRGraph
|
|
|
7
7
|
|
|
8
8
|
__all__: tuple[str, ...]
|
|
9
9
|
|
|
10
|
-
|
|
11
10
|
def main(argv: Optional[list[str]] = None) -> int: ...
|
|
12
|
-
|
|
13
|
-
|
|
14
11
|
def add_common_args(parser: argparse.ArgumentParser) -> None: ...
|
|
15
|
-
|
|
16
|
-
|
|
17
12
|
def add_grammar_args(parser: argparse.ArgumentParser) -> None: ...
|
|
18
|
-
|
|
19
|
-
|
|
20
13
|
def add_grammar_selector_args(parser: argparse.ArgumentParser) -> None: ...
|
|
21
|
-
|
|
22
|
-
|
|
23
14
|
def add_history_export_args(parser: argparse.ArgumentParser) -> None: ...
|
|
24
|
-
|
|
25
|
-
|
|
26
15
|
def add_canon_toggle(parser: argparse.ArgumentParser) -> None: ...
|
|
27
|
-
|
|
28
|
-
|
|
29
16
|
def build_basic_graph(args: argparse.Namespace) -> TNFRGraph: ...
|
|
30
|
-
|
|
31
|
-
|
|
32
17
|
def apply_cli_config(G: TNFRGraph, args: argparse.Namespace) -> None: ...
|
|
33
|
-
|
|
34
|
-
|
|
35
18
|
def register_callbacks_and_observer(G: TNFRGraph) -> None: ...
|
|
36
|
-
|
|
37
|
-
|
|
38
19
|
def resolve_program(
|
|
39
20
|
args: argparse.Namespace, default: Optional[ProgramTokens] = None
|
|
40
21
|
) -> Optional[ProgramTokens]: ...
|
|
41
|
-
|
|
42
|
-
|
|
43
22
|
def run_program(
|
|
44
23
|
G: Optional[TNFRGraph],
|
|
45
24
|
program: Optional[ProgramTokens],
|