jcmsuite-data-tree 1.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.
- jcmsuite_data_tree/__init__.py +91 -0
- jcmsuite_data_tree/_build_info.py +4 -0
- jcmsuite_data_tree/compat_runtime/__init__.py +10 -0
- jcmsuite_data_tree/compat_runtime/tree_writer.py +53 -0
- jcmsuite_data_tree/data_branch.py +366 -0
- jcmsuite_data_tree/data_primitives.py +1060 -0
- jcmsuite_data_tree/data_tree_exceptions.py +196 -0
- jcmsuite_data_tree/decorators.py +40 -0
- jcmsuite_data_tree/facade.py +91 -0
- jcmsuite_data_tree/parser.py +1045 -0
- jcmsuite_data_tree/py.typed +0 -0
- jcmsuite_data_tree/schema_primitives.py +989 -0
- jcmsuite_data_tree/schema_tree.py +369 -0
- jcmsuite_data_tree/system.py +102 -0
- jcmsuite_data_tree/toolbox.py +322 -0
- jcmsuite_data_tree-1.0.0.dist-info/METADATA +61 -0
- jcmsuite_data_tree-1.0.0.dist-info/RECORD +18 -0
- jcmsuite_data_tree-1.0.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
|
2
|
+
# Copyright (c) 2001-2026 JCMwave GmbH
|
|
3
|
+
|
|
4
|
+
"""Toolbox primitives shared by the data-tree modules."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections.abc import Iterator
|
|
9
|
+
from typing import Literal, TypeVar, overload
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class NiL(str):
|
|
13
|
+
"""Sentinel string used to propagate non-values in expression trees."""
|
|
14
|
+
|
|
15
|
+
real: float = float("nan")
|
|
16
|
+
imag: float = float("nan")
|
|
17
|
+
|
|
18
|
+
def __add__(self, other: object) -> NiL:
|
|
19
|
+
"""Return `self` when used in addition expressions."""
|
|
20
|
+
|
|
21
|
+
return self
|
|
22
|
+
|
|
23
|
+
def __radd__(self, other: object) -> NiL:
|
|
24
|
+
"""Return `self` for reflected addition."""
|
|
25
|
+
|
|
26
|
+
return self
|
|
27
|
+
|
|
28
|
+
def __iadd__(self, other: object) -> NiL:
|
|
29
|
+
"""Return `self` for in-place addition."""
|
|
30
|
+
|
|
31
|
+
return self
|
|
32
|
+
|
|
33
|
+
def __sub__(self, other: object) -> NiL:
|
|
34
|
+
"""Return `self` when used in subtraction expressions."""
|
|
35
|
+
|
|
36
|
+
return self
|
|
37
|
+
|
|
38
|
+
def __rsub__(self, other: object) -> NiL:
|
|
39
|
+
"""Return `self` for reflected subtraction."""
|
|
40
|
+
|
|
41
|
+
return self
|
|
42
|
+
|
|
43
|
+
def __isub__(self, other: object) -> NiL:
|
|
44
|
+
"""Return `self` for in-place subtraction."""
|
|
45
|
+
|
|
46
|
+
return self
|
|
47
|
+
|
|
48
|
+
def __mul__(self, other: object) -> NiL:
|
|
49
|
+
"""Return `self` when used in multiplication expressions."""
|
|
50
|
+
|
|
51
|
+
return self
|
|
52
|
+
|
|
53
|
+
def __rmul__(self, other: object) -> NiL:
|
|
54
|
+
"""Return `self` for reflected multiplication."""
|
|
55
|
+
|
|
56
|
+
return self
|
|
57
|
+
|
|
58
|
+
def __imul__(self, other: object) -> NiL:
|
|
59
|
+
"""Return `self` for in-place multiplication."""
|
|
60
|
+
|
|
61
|
+
return self
|
|
62
|
+
|
|
63
|
+
# Python 3 equivalent of legacy __div__/__rdiv__/__idiv__ hooks.
|
|
64
|
+
def __truediv__(self, other: object) -> NiL:
|
|
65
|
+
"""Return `self` when used in division expressions."""
|
|
66
|
+
|
|
67
|
+
return self
|
|
68
|
+
|
|
69
|
+
def __rtruediv__(self, other: object) -> NiL:
|
|
70
|
+
"""Return `self` for reflected division."""
|
|
71
|
+
|
|
72
|
+
return self
|
|
73
|
+
|
|
74
|
+
def __itruediv__(self, other: object) -> NiL:
|
|
75
|
+
"""Return `self` for in-place division."""
|
|
76
|
+
|
|
77
|
+
return self
|
|
78
|
+
|
|
79
|
+
def __getitem__(self, key: object) -> NiL:
|
|
80
|
+
"""Return `self` for any item lookup."""
|
|
81
|
+
|
|
82
|
+
return self
|
|
83
|
+
|
|
84
|
+
def __setitem__(self, key: object, value: object) -> None:
|
|
85
|
+
"""Ignore item assignments on `NiL` values."""
|
|
86
|
+
|
|
87
|
+
return None
|
|
88
|
+
|
|
89
|
+
def __len__(self) -> int:
|
|
90
|
+
"""Reject length queries for `NiL` values."""
|
|
91
|
+
# The legacy implementation returned NaN here; that is invalid for
|
|
92
|
+
# Python's __len__ contract, so raising TypeError is the closest
|
|
93
|
+
# semantics-preserving behavior for "length not meaningful".
|
|
94
|
+
|
|
95
|
+
raise TypeError("Unable to determine length of NiL-type.")
|
|
96
|
+
|
|
97
|
+
def __eq__(self, other: object) -> bool:
|
|
98
|
+
"""Reject equality comparisons against `NiL`."""
|
|
99
|
+
|
|
100
|
+
raise ValueError("Unable to compare to NiL-type.")
|
|
101
|
+
|
|
102
|
+
def __ne__(self, other: object) -> bool:
|
|
103
|
+
"""Reject inequality comparisons against `NiL`."""
|
|
104
|
+
|
|
105
|
+
raise ValueError("Unable to compare to NiL-type.")
|
|
106
|
+
|
|
107
|
+
def __gt__(self, other: object) -> bool:
|
|
108
|
+
"""Reject greater-than comparisons against `NiL`."""
|
|
109
|
+
|
|
110
|
+
raise ValueError("Unable to compare to NiL-type.")
|
|
111
|
+
|
|
112
|
+
def __ge__(self, other: object) -> bool:
|
|
113
|
+
"""Reject greater-or-equal comparisons against `NiL`."""
|
|
114
|
+
|
|
115
|
+
raise ValueError("Unable to compare to NiL-type.")
|
|
116
|
+
|
|
117
|
+
def __lt__(self, other: object) -> bool:
|
|
118
|
+
"""Reject less-than comparisons against `NiL`."""
|
|
119
|
+
|
|
120
|
+
raise ValueError("Unable to compare to NiL-type.")
|
|
121
|
+
|
|
122
|
+
def __le__(self, other: object) -> bool:
|
|
123
|
+
"""Reject less-or-equal comparisons against `NiL`."""
|
|
124
|
+
|
|
125
|
+
raise ValueError("Unable to compare to NiL-type.")
|
|
126
|
+
|
|
127
|
+
def __str__(self) -> str:
|
|
128
|
+
"""Return the underlying string representation."""
|
|
129
|
+
|
|
130
|
+
return super().__str__()
|
|
131
|
+
|
|
132
|
+
def __repr__(self) -> str:
|
|
133
|
+
"""Return the underlying string representation."""
|
|
134
|
+
|
|
135
|
+
return super().__str__()
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
TNumber = TypeVar("TNumber", int, float, complex)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def get_derived_nil(obj: object) -> NiL:
|
|
142
|
+
"""Return a `NiL` subtype that also inherits from `type(obj)`.
|
|
143
|
+
|
|
144
|
+
Built-in numeric and collection types cannot share their instance layout
|
|
145
|
+
with a `str` subclass. In that case, return the base sentinel instead.
|
|
146
|
+
"""
|
|
147
|
+
|
|
148
|
+
try:
|
|
149
|
+
|
|
150
|
+
class DerivedNiL(NiL, type(obj)): # type: ignore[misc]
|
|
151
|
+
pass
|
|
152
|
+
|
|
153
|
+
return DerivedNiL()
|
|
154
|
+
except TypeError:
|
|
155
|
+
return NiL()
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def is_nil(obj: object) -> bool:
|
|
159
|
+
"""Return whether `obj` is a `NiL` instance."""
|
|
160
|
+
|
|
161
|
+
return isinstance(obj, NiL)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
@overload
|
|
165
|
+
def typename(obj: int, do_return_type: Literal[False] = False) -> str: ...
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
@overload
|
|
169
|
+
def typename(obj: int, do_return_type: Literal[True]) -> tuple[str, type[int]]: ...
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
@overload
|
|
173
|
+
def typename(obj: float, do_return_type: Literal[False] = False) -> str: ...
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
@overload
|
|
177
|
+
def typename(obj: float, do_return_type: Literal[True]) -> tuple[str, type[float]]: ...
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
@overload
|
|
181
|
+
def typename(obj: complex, do_return_type: Literal[False] = False) -> str: ...
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
@overload
|
|
185
|
+
def typename(
|
|
186
|
+
obj: complex, do_return_type: Literal[True]
|
|
187
|
+
) -> tuple[str, type[complex]]: ...
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def typename(
|
|
191
|
+
obj: int | float | complex, do_return_type: bool = False
|
|
192
|
+
) -> str | tuple[str, type[int] | type[float] | type[complex]]:
|
|
193
|
+
"""Return the scalar type name and optionally the Python type."""
|
|
194
|
+
|
|
195
|
+
if isinstance(obj, int):
|
|
196
|
+
return ("int", int) if do_return_type else "int"
|
|
197
|
+
if isinstance(obj, float):
|
|
198
|
+
return ("float", float) if do_return_type else "float"
|
|
199
|
+
return ("complex", complex) if do_return_type else "complex"
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
class AsciiVector:
|
|
203
|
+
"""Legacy ASCII vector helper used for path-like token storage."""
|
|
204
|
+
|
|
205
|
+
def __init__(self, delimiter: str = ":") -> None:
|
|
206
|
+
"""Initialize an empty vector with the given delimiter."""
|
|
207
|
+
|
|
208
|
+
self._delimiter: str = delimiter
|
|
209
|
+
self._data: list[str] = []
|
|
210
|
+
|
|
211
|
+
def Copy(self) -> AsciiVector:
|
|
212
|
+
"""Return a copy of the vector."""
|
|
213
|
+
copy_value: AsciiVector = AsciiVector(self.GetDelimiter())
|
|
214
|
+
copy_value.Clear()
|
|
215
|
+
copy_value.Append(self)
|
|
216
|
+
return copy_value
|
|
217
|
+
|
|
218
|
+
def GetDelimiter(self) -> str:
|
|
219
|
+
"""Return the delimiter used for export."""
|
|
220
|
+
return self._delimiter
|
|
221
|
+
|
|
222
|
+
def PushBack(self, next_item: str) -> None:
|
|
223
|
+
"""Append one element to the vector."""
|
|
224
|
+
self._data.append(next_item)
|
|
225
|
+
|
|
226
|
+
def PopBack(self) -> str:
|
|
227
|
+
"""Remove and return the last element."""
|
|
228
|
+
return self._data.pop()
|
|
229
|
+
|
|
230
|
+
def Append(self, other_ascii_vector: AsciiVector) -> None:
|
|
231
|
+
"""Append all elements from another ASCII vector."""
|
|
232
|
+
if not isinstance(other_ascii_vector, AsciiVector):
|
|
233
|
+
raise TypeError('Append only accepts objects of type "AsciiVector".')
|
|
234
|
+
self._data.extend(other_ascii_vector)
|
|
235
|
+
|
|
236
|
+
def Clear(self) -> None:
|
|
237
|
+
"""Remove all stored elements."""
|
|
238
|
+
self._data = []
|
|
239
|
+
|
|
240
|
+
def Size(self) -> int:
|
|
241
|
+
"""Return the number of stored elements."""
|
|
242
|
+
return len(self)
|
|
243
|
+
|
|
244
|
+
def At(self, index: int) -> str:
|
|
245
|
+
"""Return the element at `index`."""
|
|
246
|
+
return self._data[index]
|
|
247
|
+
|
|
248
|
+
def Import(self, ascii_path: str, delimiters: set[str] | None = None) -> None:
|
|
249
|
+
"""Populate the vector by splitting an ASCII path string."""
|
|
250
|
+
delimiters_set: set[str] = (
|
|
251
|
+
set(delimiters) if delimiters is not None else {self._delimiter}
|
|
252
|
+
)
|
|
253
|
+
buffer: str = ""
|
|
254
|
+
self._data = []
|
|
255
|
+
for character in ascii_path:
|
|
256
|
+
if character not in delimiters_set:
|
|
257
|
+
buffer += character
|
|
258
|
+
else:
|
|
259
|
+
self._data.append(buffer)
|
|
260
|
+
buffer = ""
|
|
261
|
+
if len(buffer) > 0:
|
|
262
|
+
self._data.append(buffer)
|
|
263
|
+
|
|
264
|
+
def Export(self) -> str:
|
|
265
|
+
"""Return the vector joined with its delimiter."""
|
|
266
|
+
return self._delimiter.join(self._data)
|
|
267
|
+
|
|
268
|
+
def ExportParent(self) -> str:
|
|
269
|
+
"""Return all but the last component joined with the delimiter."""
|
|
270
|
+
return self._delimiter.join(self._data[:-1])
|
|
271
|
+
|
|
272
|
+
def __eq__(self, other: object) -> bool:
|
|
273
|
+
"""Return whether two ASCII vectors contain the same elements."""
|
|
274
|
+
|
|
275
|
+
if not isinstance(other, AsciiVector):
|
|
276
|
+
raise TypeError("Can only compare to AsciiVector type.")
|
|
277
|
+
if len(self) != len(other):
|
|
278
|
+
return False
|
|
279
|
+
for index in range(len(self)):
|
|
280
|
+
if self.At(index) != other.At(index):
|
|
281
|
+
return False
|
|
282
|
+
return True
|
|
283
|
+
|
|
284
|
+
def __ne__(self, other: object) -> bool:
|
|
285
|
+
"""Return whether two ASCII vectors differ."""
|
|
286
|
+
|
|
287
|
+
return not self.__eq__(other)
|
|
288
|
+
|
|
289
|
+
def __len__(self) -> int:
|
|
290
|
+
"""Return the number of stored elements."""
|
|
291
|
+
|
|
292
|
+
return len(self._data)
|
|
293
|
+
|
|
294
|
+
def __getitem__(self, index: int) -> str:
|
|
295
|
+
"""Return the element at `index`."""
|
|
296
|
+
|
|
297
|
+
return self._data[index]
|
|
298
|
+
|
|
299
|
+
def __iter__(self) -> Iterator[str]:
|
|
300
|
+
"""Iterate over stored elements."""
|
|
301
|
+
|
|
302
|
+
return iter(self._data)
|
|
303
|
+
|
|
304
|
+
def __str__(self) -> str:
|
|
305
|
+
"""Return the exported ASCII representation."""
|
|
306
|
+
|
|
307
|
+
return self.Export()
|
|
308
|
+
|
|
309
|
+
def __repr__(self) -> str:
|
|
310
|
+
"""Return the exported ASCII representation."""
|
|
311
|
+
|
|
312
|
+
return self.Export()
|
|
313
|
+
|
|
314
|
+
def __hash__(self) -> int:
|
|
315
|
+
"""Return a hash of the exported representation."""
|
|
316
|
+
|
|
317
|
+
return hash(self.Export())
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
# Legacy-compatible names used by original modules.
|
|
321
|
+
getDerivedNiL = get_derived_nil
|
|
322
|
+
isNiL = is_nil
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: jcmsuite-data-tree
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Compatibility and facade data-tree package for JCMsuite tooling.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Author: Matthias Plock
|
|
7
|
+
Author-email: matthias.plock@jcmwave.com
|
|
8
|
+
Requires-Python: >=3.13
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
13
|
+
Project-URL: Documentation, https://docs.jcmwave.com/JCMsuite/html/
|
|
14
|
+
Project-URL: Homepage, https://www.jcmwave.com
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# jcmsuite-data-tree
|
|
18
|
+
|
|
19
|
+
Standalone data-tree and serialization helpers for JCMsuite tooling.
|
|
20
|
+
|
|
21
|
+
Use this package to work directly with tree structures, schemas, and serialized
|
|
22
|
+
data. It is a low-level support library, not the JCMsuite solver interface, and
|
|
23
|
+
it does not provide xarray DataTree result exports.
|
|
24
|
+
|
|
25
|
+
## What It Provides
|
|
26
|
+
|
|
27
|
+
- `TreeDir` and `TreePrimitive` data-tree building blocks,
|
|
28
|
+
- facade helpers such as `create_tree_dir(...)` and `serialize_tree_dir(...)`,
|
|
29
|
+
- compatibility helpers used by tooling and protocol layers.
|
|
30
|
+
|
|
31
|
+
Python imports use `jcmsuite_data_tree`, for example:
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from jcmsuite_data_tree import TreeDir, create_tree_dir, serialize_tree_dir
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
Requires Python 3.13 or later. The standalone tree helpers do not require a
|
|
40
|
+
JCMsuite solver installation.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
python -m pip install jcmsuite-data-tree
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Relationship To `jcmsuite`
|
|
47
|
+
|
|
48
|
+
Use this package when you need the low-level data-tree model or serialization
|
|
49
|
+
helpers directly. For solver, daemon, and result workflows, install the main
|
|
50
|
+
`jcmsuite` package instead.
|
|
51
|
+
|
|
52
|
+
## Documentation and Support
|
|
53
|
+
|
|
54
|
+
See the [JCMsuite documentation](https://docs.jcmwave.com/JCMsuite/html/) for the
|
|
55
|
+
JCMsuite manuals and tutorials. For product and support information, visit
|
|
56
|
+
[JCMwave](https://www.jcmwave.com).
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
This Python package is licensed under the MIT License.
|
|
61
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
jcmsuite_data_tree/__init__.py,sha256=Go3FAJnbwxGIEKygviDCL-4C9wQNT_jwnZ6CGRIrZCQ,2112
|
|
2
|
+
jcmsuite_data_tree/_build_info.py,sha256=n1fwNB4DyNaGjHGgG9n_QQ7pPUY8s1cMcJco1UFWH_I,180
|
|
3
|
+
jcmsuite_data_tree/compat_runtime/__init__.py,sha256=CpIlX4x-KL10A2-MEcxPsKDrrRs5mqr6Q0ruKK7BygI,228
|
|
4
|
+
jcmsuite_data_tree/compat_runtime/tree_writer.py,sha256=aSZPVsrczpJ38PuWQIq2CCKFxVkBrq7xTcRwla9zu4c,1745
|
|
5
|
+
jcmsuite_data_tree/data_branch.py,sha256=I7PbYBMAJug-RfQjX5Oxq3RzJHm4H44w7twmtvrka54,12919
|
|
6
|
+
jcmsuite_data_tree/data_primitives.py,sha256=aE2RNXgQTgm6-0RzlUwgJp2-W_hTCDnO3m70q1Kb5HQ,35915
|
|
7
|
+
jcmsuite_data_tree/data_tree_exceptions.py,sha256=20N4kvXMnYNZME7iPsn_xhvjALn_u_pVRCKQwOI0mI8,6585
|
|
8
|
+
jcmsuite_data_tree/decorators.py,sha256=ggSVyFUw3Iasiyg9tngjzsjVAd9z_GJP6RReGfhTNbY,939
|
|
9
|
+
jcmsuite_data_tree/facade.py,sha256=LsqilpTaTC0fmVaN6A2U8x-T9MZ_3KplSmOzfzO_wlg,2111
|
|
10
|
+
jcmsuite_data_tree/parser.py,sha256=mcdKEpOZ_ehhsHY-RciIujR1Hr8sNsyaiieG9hpKRtk,41326
|
|
11
|
+
jcmsuite_data_tree/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
+
jcmsuite_data_tree/schema_primitives.py,sha256=eUgWNjl_iLUjj_YNa4NhIeQ-Ay3MGzFpNB1nLYUjkIU,33680
|
|
13
|
+
jcmsuite_data_tree/schema_tree.py,sha256=63Pnzidhn1sojVdGU1a4TuWtAFelpQQ1mF5O4O2EXJ0,13568
|
|
14
|
+
jcmsuite_data_tree/system.py,sha256=8AnbSiHxZu3qben6c-NAz7jOO-i3cc32Zah7kLuNtS4,3239
|
|
15
|
+
jcmsuite_data_tree/toolbox.py,sha256=Mt6ro6UqqpfTo_bmgA6ANFx-EQENJ1q_eRma6g6BjX8,9322
|
|
16
|
+
jcmsuite_data_tree-1.0.0.dist-info/METADATA,sha256=CLq9Fk4jt-GquCShTHU086v6awoTnk2slHfE325txHE,1951
|
|
17
|
+
jcmsuite_data_tree-1.0.0.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
|
|
18
|
+
jcmsuite_data_tree-1.0.0.dist-info/RECORD,,
|