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/io.py
CHANGED
|
@@ -1,311 +1,12 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Legacy JSON utilities module.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
``cached_import.cache_clear()`` and :func:`tnfr.utils.prune_failed_imports`
|
|
7
|
-
when needed.
|
|
3
|
+
The backwards-compatible re-export was removed; use :mod:`tnfr.utils.io`
|
|
4
|
+
directly. Importing :mod:`tnfr.io` now raises an :class:`ImportError` with a
|
|
5
|
+
clear migration hint.
|
|
8
6
|
"""
|
|
9
7
|
|
|
10
8
|
from __future__ import annotations
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import tempfile
|
|
15
|
-
from pathlib import Path
|
|
16
|
-
from typing import Any, Callable
|
|
17
|
-
from functools import partial
|
|
18
|
-
|
|
19
|
-
from .utils import LazyImportProxy, cached_import, get_logger
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def _raise_import_error(name: str, *_: Any, **__: Any) -> Any:
|
|
23
|
-
raise ImportError(f"{name} is not installed")
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
_MISSING_TOML_ERROR = type(
|
|
27
|
-
"MissingTOMLDependencyError",
|
|
28
|
-
(Exception,),
|
|
29
|
-
{"__doc__": "Fallback error used when tomllib/tomli is missing."},
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
_MISSING_YAML_ERROR = type(
|
|
33
|
-
"MissingPyYAMLDependencyError",
|
|
34
|
-
(Exception,),
|
|
35
|
-
{"__doc__": "Fallback error used when pyyaml is missing."},
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def _resolve_lazy(value: Any) -> Any:
|
|
40
|
-
if isinstance(value, LazyImportProxy):
|
|
41
|
-
return value.resolve()
|
|
42
|
-
return value
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
class _LazyBool:
|
|
46
|
-
__slots__ = ("_value",)
|
|
47
|
-
|
|
48
|
-
def __init__(self, value: Any) -> None:
|
|
49
|
-
self._value = value
|
|
50
|
-
|
|
51
|
-
def __bool__(self) -> bool:
|
|
52
|
-
return _resolve_lazy(self._value) is not None
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
_TOMLI_MODULE = cached_import("tomli", emit="log", lazy=True)
|
|
56
|
-
tomllib = cached_import(
|
|
57
|
-
"tomllib",
|
|
58
|
-
emit="log",
|
|
59
|
-
lazy=True,
|
|
60
|
-
fallback=_TOMLI_MODULE,
|
|
61
|
-
)
|
|
62
|
-
has_toml = _LazyBool(tomllib)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
_TOMLI_TOML_ERROR = cached_import(
|
|
66
|
-
"tomli",
|
|
67
|
-
"TOMLDecodeError",
|
|
68
|
-
emit="log",
|
|
69
|
-
lazy=True,
|
|
70
|
-
fallback=_MISSING_TOML_ERROR,
|
|
71
|
-
)
|
|
72
|
-
TOMLDecodeError = cached_import(
|
|
73
|
-
"tomllib",
|
|
74
|
-
"TOMLDecodeError",
|
|
75
|
-
emit="log",
|
|
76
|
-
lazy=True,
|
|
77
|
-
fallback=_TOMLI_TOML_ERROR,
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
_TOMLI_LOADS = cached_import(
|
|
82
|
-
"tomli",
|
|
83
|
-
"loads",
|
|
84
|
-
emit="log",
|
|
85
|
-
lazy=True,
|
|
86
|
-
fallback=partial(_raise_import_error, "tomllib/tomli"),
|
|
87
|
-
)
|
|
88
|
-
_TOML_LOADS: Callable[[str], Any] = cached_import(
|
|
89
|
-
"tomllib",
|
|
90
|
-
"loads",
|
|
91
|
-
emit="log",
|
|
92
|
-
lazy=True,
|
|
93
|
-
fallback=_TOMLI_LOADS,
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
yaml = cached_import("yaml", emit="log", lazy=True)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
YAMLError = cached_import(
|
|
101
|
-
"yaml",
|
|
102
|
-
"YAMLError",
|
|
103
|
-
emit="log",
|
|
104
|
-
lazy=True,
|
|
105
|
-
fallback=_MISSING_YAML_ERROR,
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
_YAML_SAFE_LOAD: Callable[[str], Any] = cached_import(
|
|
110
|
-
"yaml",
|
|
111
|
-
"safe_load",
|
|
112
|
-
emit="log",
|
|
113
|
-
lazy=True,
|
|
114
|
-
fallback=partial(_raise_import_error, "pyyaml"),
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
def _parse_yaml(text: str) -> Any:
|
|
119
|
-
"""Parse YAML ``text`` using ``safe_load`` if available."""
|
|
120
|
-
return _YAML_SAFE_LOAD(text)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
def _parse_toml(text: str) -> Any:
|
|
124
|
-
"""Parse TOML ``text`` using ``tomllib`` or ``tomli``."""
|
|
125
|
-
return _TOML_LOADS(text)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
PARSERS = {
|
|
129
|
-
".json": json.loads,
|
|
130
|
-
".yaml": _parse_yaml,
|
|
131
|
-
".yml": _parse_yaml,
|
|
132
|
-
".toml": _parse_toml,
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
def _get_parser(suffix: str) -> Callable[[str], Any]:
|
|
137
|
-
try:
|
|
138
|
-
return PARSERS[suffix]
|
|
139
|
-
except KeyError as exc:
|
|
140
|
-
raise ValueError(f"Unsupported suffix: {suffix}") from exc
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
_BASE_ERROR_MESSAGES: dict[type[BaseException], str] = {
|
|
144
|
-
OSError: "Could not read {path}: {e}",
|
|
145
|
-
UnicodeDecodeError: "Encoding error while reading {path}: {e}",
|
|
146
|
-
json.JSONDecodeError: "Error parsing JSON file at {path}: {e}",
|
|
147
|
-
ImportError: "Missing dependency parsing {path}: {e}",
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
def _resolve_exception_type(candidate: Any) -> type[BaseException] | None:
|
|
152
|
-
resolved = _resolve_lazy(candidate)
|
|
153
|
-
if isinstance(resolved, type) and issubclass(resolved, BaseException):
|
|
154
|
-
return resolved
|
|
155
|
-
return None
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
_OPTIONAL_ERROR_MESSAGE_FACTORIES: tuple[
|
|
159
|
-
tuple[Callable[[], type[BaseException] | None], str],
|
|
160
|
-
...,
|
|
161
|
-
] = (
|
|
162
|
-
(lambda: _resolve_exception_type(YAMLError), "Error parsing YAML file at {path}: {e}"),
|
|
163
|
-
(lambda: _resolve_exception_type(TOMLDecodeError), "Error parsing TOML file at {path}: {e}"),
|
|
164
|
-
)
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
_BASE_STRUCTURED_EXCEPTIONS = (
|
|
168
|
-
OSError,
|
|
169
|
-
UnicodeDecodeError,
|
|
170
|
-
json.JSONDecodeError,
|
|
171
|
-
ImportError,
|
|
172
|
-
)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
def _iter_optional_exceptions() -> list[type[BaseException]]:
|
|
176
|
-
errors: list[type[BaseException]] = []
|
|
177
|
-
for resolver, _ in _OPTIONAL_ERROR_MESSAGE_FACTORIES:
|
|
178
|
-
exc_type = resolver()
|
|
179
|
-
if exc_type is not None:
|
|
180
|
-
errors.append(exc_type)
|
|
181
|
-
return errors
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
def _is_structured_error(exc: Exception) -> bool:
|
|
185
|
-
if isinstance(exc, _BASE_STRUCTURED_EXCEPTIONS):
|
|
186
|
-
return True
|
|
187
|
-
for optional_exc in _iter_optional_exceptions():
|
|
188
|
-
if isinstance(exc, optional_exc):
|
|
189
|
-
return True
|
|
190
|
-
return False
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
def _format_structured_file_error(path: Path, e: Exception) -> str:
|
|
194
|
-
for exc, msg in _BASE_ERROR_MESSAGES.items():
|
|
195
|
-
if isinstance(e, exc):
|
|
196
|
-
return msg.format(path=path, e=e)
|
|
197
|
-
|
|
198
|
-
for resolver, msg in _OPTIONAL_ERROR_MESSAGE_FACTORIES:
|
|
199
|
-
exc_type = resolver()
|
|
200
|
-
if exc_type is not None and isinstance(e, exc_type):
|
|
201
|
-
return msg.format(path=path, e=e)
|
|
202
|
-
|
|
203
|
-
return f"Error parsing {path}: {e}"
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
class StructuredFileError(Exception):
|
|
207
|
-
"""Error while reading or parsing a structured file."""
|
|
208
|
-
|
|
209
|
-
def __init__(self, path: Path, original: Exception) -> None:
|
|
210
|
-
super().__init__(_format_structured_file_error(path, original))
|
|
211
|
-
self.path = path
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
def read_structured_file(path: Path) -> Any:
|
|
215
|
-
"""Read a JSON, YAML or TOML file and return parsed data."""
|
|
216
|
-
suffix = path.suffix.lower()
|
|
217
|
-
try:
|
|
218
|
-
parser = _get_parser(suffix)
|
|
219
|
-
except ValueError as e:
|
|
220
|
-
raise StructuredFileError(path, e) from e
|
|
221
|
-
try:
|
|
222
|
-
text = path.read_text(encoding="utf-8")
|
|
223
|
-
return parser(text)
|
|
224
|
-
except Exception as e:
|
|
225
|
-
if _is_structured_error(e):
|
|
226
|
-
raise StructuredFileError(path, e) from e
|
|
227
|
-
raise
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
logger = get_logger(__name__)
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
def safe_write(
|
|
234
|
-
path: str | Path,
|
|
235
|
-
write: Callable[[Any], Any],
|
|
236
|
-
*,
|
|
237
|
-
mode: str = "w",
|
|
238
|
-
encoding: str | None = "utf-8",
|
|
239
|
-
atomic: bool = True,
|
|
240
|
-
sync: bool | None = None,
|
|
241
|
-
**open_kwargs: Any,
|
|
242
|
-
) -> None:
|
|
243
|
-
"""Write to ``path`` ensuring parent directory exists and handle errors.
|
|
244
|
-
|
|
245
|
-
Parameters
|
|
246
|
-
----------
|
|
247
|
-
path:
|
|
248
|
-
Destination file path.
|
|
249
|
-
write:
|
|
250
|
-
Callback receiving the opened file object and performing the actual
|
|
251
|
-
write.
|
|
252
|
-
mode:
|
|
253
|
-
File mode passed to :func:`open`. Text modes (default) use UTF-8
|
|
254
|
-
encoding unless ``encoding`` is ``None``. When a binary mode is used
|
|
255
|
-
(``'b'`` in ``mode``) no encoding parameter is supplied so
|
|
256
|
-
``write`` may write bytes.
|
|
257
|
-
encoding:
|
|
258
|
-
Encoding for text modes. Ignored for binary modes.
|
|
259
|
-
atomic:
|
|
260
|
-
When ``True`` (default) writes to a temporary file and atomically
|
|
261
|
-
replaces the destination after flushing to disk. When ``False``
|
|
262
|
-
writes directly to ``path`` without any atomicity guarantee.
|
|
263
|
-
sync:
|
|
264
|
-
When ``True`` flushes and fsyncs the file descriptor after writing.
|
|
265
|
-
``None`` uses ``atomic`` to determine syncing behaviour.
|
|
266
|
-
"""
|
|
267
|
-
path = Path(path)
|
|
268
|
-
path.parent.mkdir(parents=True, exist_ok=True)
|
|
269
|
-
open_params = dict(mode=mode, **open_kwargs)
|
|
270
|
-
if "b" not in mode and encoding is not None:
|
|
271
|
-
open_params["encoding"] = encoding
|
|
272
|
-
if sync is None:
|
|
273
|
-
sync = atomic
|
|
274
|
-
tmp_path: Path | None = None
|
|
275
|
-
try:
|
|
276
|
-
if atomic:
|
|
277
|
-
tmp_fd = tempfile.NamedTemporaryFile(dir=path.parent, delete=False)
|
|
278
|
-
tmp_path = Path(tmp_fd.name)
|
|
279
|
-
tmp_fd.close()
|
|
280
|
-
with open(tmp_path, **open_params) as fd:
|
|
281
|
-
write(fd)
|
|
282
|
-
if sync:
|
|
283
|
-
fd.flush()
|
|
284
|
-
os.fsync(fd.fileno())
|
|
285
|
-
try:
|
|
286
|
-
os.replace(tmp_path, path)
|
|
287
|
-
except OSError as e:
|
|
288
|
-
logger.error(
|
|
289
|
-
"Atomic replace failed for %s -> %s: %s", tmp_path, path, e
|
|
290
|
-
)
|
|
291
|
-
raise
|
|
292
|
-
else:
|
|
293
|
-
with open(path, **open_params) as fd:
|
|
294
|
-
write(fd)
|
|
295
|
-
if sync:
|
|
296
|
-
fd.flush()
|
|
297
|
-
os.fsync(fd.fileno())
|
|
298
|
-
except (OSError, ValueError, TypeError) as e:
|
|
299
|
-
raise type(e)(f"Failed to write file {path}: {e}") from e
|
|
300
|
-
finally:
|
|
301
|
-
if tmp_path is not None:
|
|
302
|
-
tmp_path.unlink(missing_ok=True)
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
__all__ = (
|
|
306
|
-
"read_structured_file",
|
|
307
|
-
"safe_write",
|
|
308
|
-
"StructuredFileError",
|
|
309
|
-
"TOMLDecodeError",
|
|
310
|
-
"YAMLError",
|
|
10
|
+
raise ImportError(
|
|
11
|
+
"`tnfr.io` was removed. Import helpers from `tnfr.utils.io` instead."
|
|
311
12
|
)
|
tnfr/io.pyi
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
"""Compatibility stub removed; import from :mod:`tnfr.utils.io` instead."""
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
from typing import NoReturn
|
|
6
|
+
|
|
7
|
+
__all__ = ()
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def __getattr__(name: str) -> NoReturn:
|
|
11
|
+
"""Indicate that :mod:`tnfr.io` no longer exports IO helpers."""
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def __dir__() -> tuple[str, ...]:
|
|
15
|
+
"""Return an empty set of exports to mirror the removed shim."""
|
|
6
16
|
|
|
7
|
-
StructuredFileError: Any
|
|
8
|
-
TOMLDecodeError: Any
|
|
9
|
-
YAMLError: Any
|
|
10
|
-
read_structured_file: Any
|
|
11
|
-
safe_write: Any
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Mathematics primitives aligned with TNFR coherence modeling.
|
|
2
|
+
|
|
3
|
+
Backend selection
|
|
4
|
+
-----------------
|
|
5
|
+
Use :func:`get_backend` to retrieve a numerical backend compatible with TNFR's
|
|
6
|
+
structural operators. The selection order is ``name`` → ``TNFR_MATH_BACKEND``
|
|
7
|
+
→ :func:`tnfr.config.get_flags`. NumPy remains the canonical default so
|
|
8
|
+
existing code continues to operate even when optional dependencies are absent.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from .backend import (
|
|
12
|
+
MathematicsBackend,
|
|
13
|
+
available_backends,
|
|
14
|
+
ensure_array,
|
|
15
|
+
ensure_numpy,
|
|
16
|
+
get_backend,
|
|
17
|
+
register_backend,
|
|
18
|
+
)
|
|
19
|
+
from .dynamics import ContractiveDynamicsEngine, MathematicalDynamicsEngine
|
|
20
|
+
from .epi import BEPIElement, CoherenceEvaluation, evaluate_coherence_transform
|
|
21
|
+
from .generators import build_delta_nfr, build_lindblad_delta_nfr
|
|
22
|
+
from .metrics import dcoh
|
|
23
|
+
from .operators import CoherenceOperator, FrequencyOperator
|
|
24
|
+
from .operators_factory import make_coherence_operator, make_frequency_operator
|
|
25
|
+
from .projection import BasicStateProjector, StateProjector
|
|
26
|
+
from .runtime import (
|
|
27
|
+
coherence,
|
|
28
|
+
coherence_expectation,
|
|
29
|
+
frequency_expectation,
|
|
30
|
+
frequency_positive,
|
|
31
|
+
normalized,
|
|
32
|
+
stable_unitary,
|
|
33
|
+
)
|
|
34
|
+
from .spaces import BanachSpaceEPI, HilbertSpace
|
|
35
|
+
from .transforms import (
|
|
36
|
+
CoherenceMonotonicityReport,
|
|
37
|
+
CoherenceViolation,
|
|
38
|
+
IsometryFactory,
|
|
39
|
+
build_isometry_factory,
|
|
40
|
+
ensure_coherence_monotonicity,
|
|
41
|
+
validate_norm_preservation,
|
|
42
|
+
)
|
|
43
|
+
from ..validation import NFRValidator
|
|
44
|
+
|
|
45
|
+
__all__ = [
|
|
46
|
+
"MathematicsBackend",
|
|
47
|
+
"ensure_array",
|
|
48
|
+
"ensure_numpy",
|
|
49
|
+
"HilbertSpace",
|
|
50
|
+
"BanachSpaceEPI",
|
|
51
|
+
"BEPIElement",
|
|
52
|
+
"CoherenceEvaluation",
|
|
53
|
+
"CoherenceOperator",
|
|
54
|
+
"ContractiveDynamicsEngine",
|
|
55
|
+
"CoherenceMonotonicityReport",
|
|
56
|
+
"CoherenceViolation",
|
|
57
|
+
"FrequencyOperator",
|
|
58
|
+
"MathematicalDynamicsEngine",
|
|
59
|
+
"build_delta_nfr",
|
|
60
|
+
"build_lindblad_delta_nfr",
|
|
61
|
+
"make_coherence_operator",
|
|
62
|
+
"make_frequency_operator",
|
|
63
|
+
"NFRValidator",
|
|
64
|
+
"IsometryFactory",
|
|
65
|
+
"build_isometry_factory",
|
|
66
|
+
"validate_norm_preservation",
|
|
67
|
+
"ensure_coherence_monotonicity",
|
|
68
|
+
"evaluate_coherence_transform",
|
|
69
|
+
"StateProjector",
|
|
70
|
+
"BasicStateProjector",
|
|
71
|
+
"normalized",
|
|
72
|
+
"coherence",
|
|
73
|
+
"frequency_positive",
|
|
74
|
+
"stable_unitary",
|
|
75
|
+
"dcoh",
|
|
76
|
+
"coherence_expectation",
|
|
77
|
+
"frequency_expectation",
|
|
78
|
+
"available_backends",
|
|
79
|
+
"get_backend",
|
|
80
|
+
"register_backend",
|
|
81
|
+
]
|