jcmsuite 7.4.2__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 jcmsuite might be problematic. Click here for more details.

Files changed (119) hide show
  1. jcmsuite/__init__.py +22 -0
  2. jcmsuite/_build_info.py +4 -0
  3. jcmsuite/context/__init__.py +44 -0
  4. jcmsuite/context/interface_metadata.py +158 -0
  5. jcmsuite/context/models.py +213 -0
  6. jcmsuite/context/scope.py +210 -0
  7. jcmsuite/context/solver_context.py +569 -0
  8. jcmsuite/context/subprocess_tools.py +172 -0
  9. jcmsuite/contract.py +47 -0
  10. jcmsuite/daemon/__init__.py +19 -0
  11. jcmsuite/daemon/handler.py +925 -0
  12. jcmsuite/daemon/internal/__init__.py +4 -0
  13. jcmsuite/daemon/internal/bundle_protocol.py +64 -0
  14. jcmsuite/daemon/internal/handler_helpers.py +368 -0
  15. jcmsuite/daemon/internal/handler_resource_jobs.py +227 -0
  16. jcmsuite/daemon/internal/handler_wait.py +564 -0
  17. jcmsuite/daemon/models.py +349 -0
  18. jcmsuite/daemon/namespaces.py +250 -0
  19. jcmsuite/daemon/protocol.py +801 -0
  20. jcmsuite/daemon/resources.py +407 -0
  21. jcmsuite/daemon/scope.py +53 -0
  22. jcmsuite/daemon/transport.py +223 -0
  23. jcmsuite/editing/__init__.py +10 -0
  24. jcmsuite/editing/editor.py +274 -0
  25. jcmsuite/exceptions/__init__.py +32 -0
  26. jcmsuite/exceptions/errors.py +173 -0
  27. jcmsuite/geo/__init__.py +10 -0
  28. jcmsuite/geo/mesh.py +302 -0
  29. jcmsuite/info/__init__.py +10 -0
  30. jcmsuite/info/runtime_info.py +45 -0
  31. jcmsuite/internal/__init__.py +2 -0
  32. jcmsuite/internal/diagnostics.py +74 -0
  33. jcmsuite/internal/progress.py +80 -0
  34. jcmsuite/loaders/__init__.py +18 -0
  35. jcmsuite/loaders/blob_header.py +315 -0
  36. jcmsuite/loaders/cartesian_field_reader.py +249 -0
  37. jcmsuite/loaders/cartesian_fields.py +324 -0
  38. jcmsuite/loaders/nested_mapping.py +69 -0
  39. jcmsuite/loaders/powerflux.py +136 -0
  40. jcmsuite/loaders/table.py +637 -0
  41. jcmsuite/logging/__init__.py +22 -0
  42. jcmsuite/logging/runtime.py +210 -0
  43. jcmsuite/results/__init__.py +126 -0
  44. jcmsuite/results/artifacts.py +806 -0
  45. jcmsuite/results/discovery.py +82 -0
  46. jcmsuite/results/field_exports.py +1062 -0
  47. jcmsuite/results/field_payloads.py +453 -0
  48. jcmsuite/results/internal/__init__.py +4 -0
  49. jcmsuite/results/internal/export/__init__.py +4 -0
  50. jcmsuite/results/internal/export/common.py +56 -0
  51. jcmsuite/results/internal/export/pandas/__init__.py +4 -0
  52. jcmsuite/results/internal/export/pandas/common.py +165 -0
  53. jcmsuite/results/internal/export/pandas/payload.py +480 -0
  54. jcmsuite/results/internal/export/pandas/rows.py +484 -0
  55. jcmsuite/results/internal/export/preview.py +178 -0
  56. jcmsuite/results/internal/export/xarray/__init__.py +4 -0
  57. jcmsuite/results/internal/export/xarray/export.py +688 -0
  58. jcmsuite/results/internal/export/xarray/grouped.py +608 -0
  59. jcmsuite/results/internal/export/xarray/headers.py +290 -0
  60. jcmsuite/results/internal/export/xarray/runtime.py +99 -0
  61. jcmsuite/results/internal/export/xarray/shared.py +246 -0
  62. jcmsuite/results/internal/export/xarray/tabular.py +304 -0
  63. jcmsuite/results/internal/export/xarray/types.py +28 -0
  64. jcmsuite/results/internal/models/__init__.py +4 -0
  65. jcmsuite/results/internal/models/batch.py +1081 -0
  66. jcmsuite/results/internal/models/batch_postprocess.py +1728 -0
  67. jcmsuite/results/internal/models/bundle.py +343 -0
  68. jcmsuite/results/internal/models/core.py +556 -0
  69. jcmsuite/results/internal/models/submission.py +1157 -0
  70. jcmsuite/results/internal/resultbag/__init__.py +4 -0
  71. jcmsuite/results/internal/resultbag/access.py +489 -0
  72. jcmsuite/results/internal/resultbag/iteration.py +199 -0
  73. jcmsuite/results/internal/resultbag/query.py +226 -0
  74. jcmsuite/results/internal/resultbag/raw.py +407 -0
  75. jcmsuite/results/internal/resultbag/source_files.py +142 -0
  76. jcmsuite/results/internal/resultbag/store.py +881 -0
  77. jcmsuite/results/internal/resultbag/utils.py +258 -0
  78. jcmsuite/results/models.py +76 -0
  79. jcmsuite/results/opening.py +55 -0
  80. jcmsuite/results/pandas_export.py +325 -0
  81. jcmsuite/results/payloads.py +478 -0
  82. jcmsuite/results/postprocess.py +97 -0
  83. jcmsuite/results/postprocess_payloads.py +757 -0
  84. jcmsuite/results/postprocess_record.py +418 -0
  85. jcmsuite/results/resultbag.py +279 -0
  86. jcmsuite/results/resultbag_management.py +433 -0
  87. jcmsuite/results/structured_derivatives.py +387 -0
  88. jcmsuite/solve/__init__.py +10 -0
  89. jcmsuite/solve/daemon_bundle_staging.py +100 -0
  90. jcmsuite/solve/daemon_bundle_wait.py +89 -0
  91. jcmsuite/solve/orchestration.py +1576 -0
  92. jcmsuite/solve/orchestration_execution.py +180 -0
  93. jcmsuite/solve/orchestration_routing.py +128 -0
  94. jcmsuite/solve/orchestration_support.py +323 -0
  95. jcmsuite/solve/path_resolution.py +98 -0
  96. jcmsuite/solve/progress.py +20 -0
  97. jcmsuite/solve/solver.py +709 -0
  98. jcmsuite/solve/staging.py +264 -0
  99. jcmsuite/solve/types.py +25 -0
  100. jcmsuite/solve/working_dirs.py +227 -0
  101. jcmsuite/templates/__init__.py +11 -0
  102. jcmsuite/templates/converter.py +71 -0
  103. jcmsuite/templates/formatting.py +335 -0
  104. jcmsuite/templates/formatting_cli.py +47 -0
  105. jcmsuite/templates/rendering.py +666 -0
  106. jcmsuite/torch/__init__.py +25 -0
  107. jcmsuite/torch/autograd.py +488 -0
  108. jcmsuite/torch/coordinate_policy.py +82 -0
  109. jcmsuite/torch/core.py +312 -0
  110. jcmsuite/torch/results/__init__.py +51 -0
  111. jcmsuite/torch/types.py +84 -0
  112. jcmsuite/torch/validation.py +208 -0
  113. jcmsuite/torch/wrappers.py +4332 -0
  114. jcmsuite/view/__init__.py +10 -0
  115. jcmsuite/view/viewer.py +122 -0
  116. jcmsuite-7.4.2.dist-info/METADATA +180 -0
  117. jcmsuite-7.4.2.dist-info/RECORD +119 -0
  118. jcmsuite-7.4.2.dist-info/WHEEL +4 -0
  119. jcmsuite-7.4.2.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,637 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2001-2026 JCMwave GmbH
3
+
4
+ """JCM table loader."""
5
+
6
+ from __future__ import annotations
7
+
8
+ import re
9
+ from collections.abc import Mapping
10
+ from dataclasses import dataclass
11
+ from pathlib import Path
12
+ from typing import TYPE_CHECKING, BinaryIO, Literal, TypeAlias, cast
13
+
14
+ import numpy as np
15
+
16
+ from ..exceptions import InvalidConfigurationError, UnsupportedExportError
17
+ from .blob_header import BlobHeaderReader
18
+ from .nested_mapping import PathComponent, nested_get, nested_set
19
+
20
+ if TYPE_CHECKING:
21
+ import pandas as pd
22
+
23
+ from ..results.internal.export.xarray.types import XarrayDataTree
24
+ from ..results.payloads import TableCollectionPayload, TablePayload
25
+
26
+ SingleTableData: TypeAlias = dict[PathComponent, object]
27
+
28
+
29
+ @dataclass(slots=True)
30
+ class TableColumn:
31
+ """Column descriptor extracted from a table blob."""
32
+
33
+ name: str
34
+ dtype: str
35
+ data: np.ndarray
36
+
37
+
38
+ class TableCollection(list[SingleTableData]):
39
+ """List-compatible result for `.jcm` files containing multiple tables.
40
+
41
+ Parameters
42
+ ----------
43
+ tables : list[SingleTableData]
44
+ Parsed tables in file order.
45
+ source_file : Path | None, optional
46
+ Source file used for metadata in exports.
47
+ """
48
+
49
+ def __init__(
50
+ self,
51
+ tables: list[SingleTableData],
52
+ *,
53
+ source_file: Path | None = None,
54
+ ) -> None:
55
+
56
+ super().__init__(tables)
57
+ self.source_file: Path | None = source_file
58
+
59
+ def table_names(self) -> tuple[str, ...]:
60
+ """Return deterministic, title-based names for table exports."""
61
+
62
+ return _unique_table_names(self)
63
+
64
+ def to_df(self, orient: str | None = None) -> "pd.DataFrame":
65
+ """Export all named tables into one long-form pandas DataFrame."""
66
+
67
+ if orient not in (None, "long"):
68
+ if orient == "wide":
69
+ raise UnsupportedExportError(
70
+ "to_df is not supported for wide table collections."
71
+ )
72
+ raise ValueError("orient must be None, 'wide', or 'long'")
73
+
74
+ from ..results.internal.export.pandas.common import (
75
+ normalize_optional_index_columns,
76
+ )
77
+ from ..results.internal.export.pandas.payload import (
78
+ postprocess_payload_to_long_rows,
79
+ )
80
+ from ..results.pandas_export import _load_pandas_module
81
+
82
+ table_names: tuple[str, ...] = self.table_names()
83
+ rows: list[dict[str, object]] = []
84
+ table_index: int
85
+ table_payload: SingleTableData
86
+ for table_index, table_payload in enumerate(self):
87
+ title: str | None = _table_title(table_payload)
88
+ normalized_payload: dict[PathComponent, object] = dict(table_payload)
89
+ normalized_payload.pop("title", None)
90
+ normalized_payload.pop("header", None)
91
+ table_rows: list[dict[str, object]] | None = (
92
+ postprocess_payload_to_long_rows(normalized_payload)
93
+ )
94
+ if table_rows is None:
95
+ raise InvalidConfigurationError(
96
+ f"Table {table_names[table_index]!r} is not tabular and cannot be exported via to_df()."
97
+ )
98
+ table_row: dict[str, object]
99
+ for table_row in table_rows:
100
+ merged_row: dict[str, object] = {
101
+ "table": table_names[table_index],
102
+ "table_index": table_index,
103
+ "title": title,
104
+ }
105
+ merged_row.update(table_row)
106
+ rows.append(merged_row)
107
+
108
+ pandas_module = _load_pandas_module()
109
+ dataframe = pandas_module.DataFrame(rows)
110
+ return cast("pd.DataFrame", normalize_optional_index_columns(dataframe))
111
+
112
+ def to_xarray(self) -> "XarrayDataTree":
113
+ """Export all named tables into a title-keyed `DataTree`."""
114
+
115
+ from ..results.artifacts import PostprocessRecord
116
+ from ..results.internal.export.xarray.runtime import (
117
+ _create_data_tree,
118
+ _load_datatree_module,
119
+ _load_xarray_module,
120
+ )
121
+
122
+ xarray_module = _load_xarray_module()
123
+ datatree_module = _load_datatree_module()
124
+ table_names: tuple[str, ...] = self.table_names()
125
+ children: dict[str, XarrayDataTree] = {}
126
+ table_index: int
127
+ table_payload: SingleTableData
128
+ for table_index, table_payload in enumerate(self):
129
+ title: str | None = _table_title(table_payload)
130
+ child_tree: XarrayDataTree = PostprocessRecord(
131
+ source_file=Path() if self.source_file is None else self.source_file,
132
+ _raw=table_payload,
133
+ title=title,
134
+ ).to_xarray()
135
+ child_dataset = getattr(child_tree, "ds", None)
136
+ child_children: Mapping[str, XarrayDataTree] | None = cast(
137
+ "Mapping[str, XarrayDataTree] | None",
138
+ getattr(child_tree, "children", None),
139
+ )
140
+ children[table_names[table_index]] = _create_data_tree(
141
+ datatree_module=datatree_module,
142
+ dataset=child_dataset,
143
+ children=child_children,
144
+ name=table_names[table_index],
145
+ )
146
+
147
+ attrs: dict[str, object] = {
148
+ "table_count": len(self),
149
+ "tables": table_names,
150
+ }
151
+ if self.source_file is not None:
152
+ attrs["source_file"] = str(self.source_file)
153
+ root_dataset = xarray_module.Dataset(data_vars={}, attrs=attrs)
154
+ return _create_data_tree(
155
+ datatree_module=datatree_module,
156
+ dataset=root_dataset,
157
+ children=children or None,
158
+ )
159
+
160
+
161
+ def load_table(
162
+ file_name: str | Path,
163
+ *,
164
+ format: Literal["named"] = "named",
165
+ ) -> "TablePayload | TableCollectionPayload":
166
+ """Load table data from a `.jcm` file.
167
+
168
+ Parameters
169
+ ----------
170
+ file_name : str | Path
171
+ Path to the table file.
172
+ format : {"named"}, optional
173
+ Output format. The only supported value is `"named"`.
174
+
175
+ Returns
176
+ -------
177
+ TablePayload | TableCollectionPayload
178
+ One table, or an ordered collection if the file contains multiple
179
+ tables.
180
+
181
+ Raises
182
+ ------
183
+ InvalidConfigurationError
184
+ If `file_name` is not a file or `format` is not `"named"`.
185
+ """
186
+
187
+ file_path: Path = Path(file_name).expanduser().resolve()
188
+ if not file_path.is_file():
189
+ raise InvalidConfigurationError("file_name -> file path expected.")
190
+ if format != "named":
191
+ raise InvalidConfigurationError(
192
+ "Only the canonical `named` table output format is supported."
193
+ )
194
+
195
+ with open(file_path, "rb") as stream:
196
+ tables: list[SingleTableData] = []
197
+ while True:
198
+ tables.append(_load_single_table(stream))
199
+
200
+ at_end: bool = True
201
+ while True:
202
+ previous_position: int = stream.tell()
203
+ header_start: str = stream.readline().decode()
204
+ if stream.tell() == previous_position:
205
+ break
206
+ header_start = (
207
+ header_start.replace(" ", "").replace("\r\n", "").replace("\n", "")
208
+ )
209
+ if not header_start:
210
+ continue
211
+ if header_start == "/*<BLOBHead>":
212
+ at_end = False
213
+ stream.seek(previous_position)
214
+ break
215
+ if at_end:
216
+ break
217
+
218
+ if len(tables) == 1:
219
+ loaded_table: SingleTableData = tables[0]
220
+ from ..results.postprocess_payloads import _StandaloneTablePayload
221
+
222
+ return cast(
223
+ "TablePayload | TableCollectionPayload",
224
+ _StandaloneTablePayload(
225
+ cast(Mapping[object, object], loaded_table),
226
+ source=file_path,
227
+ ),
228
+ )
229
+ collection = TableCollection(tables, source_file=file_path)
230
+ from ..results.postprocess_payloads import _StandaloneTableCollectionPayload
231
+
232
+ return _StandaloneTableCollectionPayload(collection)
233
+
234
+
235
+ def _unique_table_names(tables: list[SingleTableData]) -> tuple[str, ...]:
236
+ """Return title-derived table names with deterministic duplicate suffixes."""
237
+
238
+ seen_counts: dict[str, int] = {}
239
+ names: list[str] = []
240
+ table_index: int
241
+ table_payload: SingleTableData
242
+ for table_index, table_payload in enumerate(tables):
243
+ base_name: str = _table_title(table_payload) or f"table_{table_index}"
244
+ base_name = base_name.replace("/", "_") or f"table_{table_index}"
245
+ seen_count: int = seen_counts.get(base_name, 0)
246
+ seen_counts[base_name] = seen_count + 1
247
+ if seen_count == 0:
248
+ names.append(base_name)
249
+ continue
250
+ names.append(f"{base_name}_{seen_count}")
251
+ return tuple(names)
252
+
253
+
254
+ def _table_title(table_payload: SingleTableData) -> str | None:
255
+ """Return a table title from named table payloads when available."""
256
+
257
+ if not isinstance(table_payload, dict):
258
+ return None
259
+ title_object: object | None = table_payload.get("title")
260
+ if isinstance(title_object, str):
261
+ return title_object
262
+ return None
263
+
264
+
265
+ def _load_single_table(stream: BinaryIO) -> SingleTableData:
266
+ """Load single table.
267
+
268
+ Parameters
269
+ ----------
270
+ stream : BinaryIO
271
+ Value passed via ``stream``.
272
+ Returns
273
+ -------
274
+ SingleTableData
275
+ Decoded single-table payload.
276
+
277
+ Notes
278
+ -----
279
+ Internal API: this helper is an implementation detail and may change
280
+ without notice.
281
+ """
282
+
283
+ header: dict[PathComponent, object] = BlobHeaderReader(
284
+ stream, "Table"
285
+ ).read_header()
286
+
287
+ table: dict[PathComponent, object] = {"title": header["Title"]}
288
+ if "MetaData" in header:
289
+ table["header"] = header["MetaData"]
290
+
291
+ n_columns: int = _coerce_int(header.get("NColumns"), key_name="NColumns")
292
+ n_rows: int = _coerce_int(header.get("NRows"), key_name="NRows")
293
+ columns: list[TableColumn] = _parse_column_metadata(header, n_columns, n_rows)
294
+
295
+ _read_column_payload(stream, header=header, columns=columns, n_rows=n_rows)
296
+
297
+ _populate_named_table(
298
+ table=table,
299
+ columns=columns,
300
+ n_rows=n_rows,
301
+ )
302
+ return table
303
+
304
+
305
+ def _coerce_int(value: object, *, key_name: str) -> int:
306
+ """Coerce integer to expected type.
307
+
308
+ Parameters
309
+ ----------
310
+ value : object
311
+ Input value(s) to convert into normalized representation.
312
+ key_name : str
313
+ Value passed via ``key_name``.
314
+
315
+ Returns
316
+ -------
317
+ int
318
+ Parsed numeric value.
319
+
320
+ Notes
321
+ -----
322
+ Internal API: this helper is an implementation detail and may change
323
+ without notice.
324
+ """
325
+
326
+ if isinstance(value, bool) or not isinstance(value, (int, np.integer)):
327
+ raise RuntimeError(f"File corrupted: `{key_name}` missing or invalid.")
328
+ return int(value)
329
+
330
+
331
+ def _parse_column_metadata(
332
+ header: dict[PathComponent, object],
333
+ n_columns: int,
334
+ n_rows: int,
335
+ ) -> list[TableColumn]:
336
+ """Parse column metadata.
337
+
338
+ Parameters
339
+ ----------
340
+ header : dict[PathComponent, object]
341
+ Value passed via ``header``.
342
+ n_columns : int
343
+ Value passed via ``n_columns``.
344
+ n_rows : int
345
+ Value passed via ``n_rows``.
346
+
347
+ Returns
348
+ -------
349
+ list[TableColumn]
350
+ Normalized list output.
351
+
352
+ Notes
353
+ -----
354
+ Internal API: this helper is an implementation detail and may change
355
+ without notice.
356
+ """
357
+
358
+ columns: list[TableColumn] = []
359
+ column_index: int
360
+ for column_index in range(n_columns):
361
+ column_key: str = f"Column{column_index + 1}"
362
+ column_header_object: object | None = header.get(column_key)
363
+ if not isinstance(column_header_object, dict):
364
+ raise RuntimeError("File corrupted: column metadata is missing.")
365
+ column_header: dict[PathComponent, object] = column_header_object
366
+
367
+ name_object: object | None = column_header.get("Name")
368
+ type_object: object | None = column_header.get("Type")
369
+ if not isinstance(name_object, str) or not isinstance(type_object, str):
370
+ raise RuntimeError("File corrupted: column name/type is missing.")
371
+
372
+ dtype: str
373
+ if type_object == "int":
374
+ dtype = "int32"
375
+ elif type_object == "double":
376
+ dtype = "float64"
377
+ elif type_object == "doublecomplex":
378
+ dtype = "complex128"
379
+ else:
380
+ raise RuntimeError("File corrupted: unsupported column type.")
381
+
382
+ columns.append(
383
+ TableColumn(
384
+ name=name_object,
385
+ dtype=dtype,
386
+ data=np.ndarray((n_rows,), dtype=dtype),
387
+ )
388
+ )
389
+ return columns
390
+
391
+
392
+ def _read_column_payload(
393
+ stream: BinaryIO,
394
+ *,
395
+ header: dict[PathComponent, object],
396
+ columns: list[TableColumn],
397
+ n_rows: int,
398
+ ) -> None:
399
+ """Read column payload.
400
+
401
+ Parameters
402
+ ----------
403
+ stream : BinaryIO
404
+ Value passed via ``stream``.
405
+ header : dict[PathComponent, object]
406
+ Value passed via ``header``.
407
+ columns : list[TableColumn]
408
+ Value passed via ``columns``.
409
+ n_rows : int
410
+ Value passed via ``n_rows``.
411
+
412
+ Returns
413
+ -------
414
+ None
415
+ No value is returned.
416
+
417
+ Notes
418
+ -----
419
+ Internal API: this helper is an implementation detail and may change
420
+ without notice.
421
+ """
422
+
423
+ mode_object: object | None = header.get("__MODE__")
424
+ mode: str = cast(str, mode_object)
425
+ try:
426
+ if mode == "BINARY":
427
+ column: TableColumn
428
+ for column in columns:
429
+ column.data = np.fromfile(stream, column.dtype, n_rows)
430
+ return
431
+
432
+ n_columns: int = len(columns)
433
+ n_entries: int = n_rows * n_columns
434
+ entry_index: int = 0
435
+ while entry_index < n_entries:
436
+ line: str = stream.readline().decode()
437
+ # Complex text rows may include spaces after `(` and `,`.
438
+ # We normalize both so token splitting remains stable.
439
+ line = re.sub(r"\([ ]*", "(", line)
440
+ line = re.sub(r",[ ]*", ",", line)
441
+ token_line: list[str] = line.split("#")[0].split()
442
+ token: str
443
+ for token in token_line:
444
+ current_column: TableColumn = columns[entry_index % n_columns]
445
+ row_index: int = entry_index // n_columns
446
+ if current_column.dtype == "int32":
447
+ current_column.data[row_index] = int(token)
448
+ elif current_column.dtype == "float64":
449
+ current_column.data[row_index] = float(token)
450
+ else:
451
+ tag_real, tag_imag = token.split(",")
452
+ current_column.data[row_index] = complex(
453
+ float(tag_real[1:]),
454
+ float(tag_imag[:-1]),
455
+ )
456
+ entry_index += 1
457
+ except Exception as error:
458
+ raise RuntimeError("File corrupted.") from error
459
+
460
+
461
+ def _populate_named_table(
462
+ *,
463
+ table: dict[PathComponent, object],
464
+ columns: list[TableColumn],
465
+ n_rows: int,
466
+ ) -> None:
467
+ """Populate nested named-table output from parsed column metadata.
468
+
469
+ Parameters
470
+ ----------
471
+ table : dict[PathComponent, object]
472
+ Value passed via ``table``.
473
+ columns : list[TableColumn]
474
+ Value passed via ``columns``.
475
+ n_rows : int
476
+ Value passed via ``n_rows``.
477
+ Returns
478
+ -------
479
+ None
480
+ No value is returned.
481
+
482
+ Notes
483
+ -----
484
+ Internal API: this helper is an implementation detail and may change
485
+ without notice.
486
+ """
487
+
488
+ fix_path_format: list[list[PathComponent]] = []
489
+ last_path: list[PathComponent] = []
490
+
491
+ column: TableColumn
492
+ for column in columns:
493
+ key: str = column.name
494
+
495
+ # Regex captures derivative form `d(A)_b` and rewrites it so we can split
496
+ # by a placeholder separator into deterministic nested-dict path parts.
497
+ def derivative_placeholder(match: re.Match[str]) -> str:
498
+ return f"d_{match.group(2)}<DerivativeSep>{match.group(1)}"
499
+
500
+ key = re.sub(r"d\((.*)\)_(.*)", derivative_placeholder, key)
501
+ key = re.sub(r"d\((.*)\)_(.*)", derivative_placeholder, key)
502
+
503
+ name_indices: list[int] = []
504
+ while True:
505
+ name_index: re.Match[str] | None = re.search(r"(.*)(_\d{1,})", key)
506
+ if name_index is None:
507
+ break
508
+ key = name_index.group(1)
509
+ name_indices.append(int(name_index.group(2)[1:]) - 1)
510
+ name_indices.reverse()
511
+
512
+ vector_index: int = -1
513
+ if key.endswith("X"):
514
+ vector_index = 0
515
+ key = key[:-1]
516
+ elif key.endswith("Y"):
517
+ vector_index = 1
518
+ key = key[:-1]
519
+ elif key.endswith("Z"):
520
+ vector_index = 2
521
+ key = key[:-1]
522
+
523
+ path: list[PathComponent] = cast(
524
+ list[PathComponent],
525
+ key.split("<DerivativeSep>") + name_indices,
526
+ )
527
+ if vector_index > -1:
528
+ if last_path != path:
529
+ try:
530
+ value_np: object = nested_get(table, path)
531
+ except KeyError:
532
+ value_np = np.ndarray((n_rows, 3), dtype=column.dtype)
533
+ else:
534
+ value_np = nested_get(table, path)
535
+ if not isinstance(value_np, np.ndarray):
536
+ raise RuntimeError("File corrupted: expected ndarray at vector path.")
537
+ value_np[:, vector_index] = column.data
538
+ nested_set(table, path, value_np)
539
+ elif len(name_indices) == 2:
540
+ nested_set(table, path, column.data)
541
+ fix_path_format.append(
542
+ cast(list[PathComponent], key.split("<DerivativeSep>"))
543
+ )
544
+ elif len(name_indices) > 2:
545
+ name_indices.insert(0, name_indices.pop())
546
+ path = cast(
547
+ list[PathComponent],
548
+ key.split("<DerivativeSep>") + name_indices,
549
+ )
550
+ nested_set(table, path, column.data)
551
+ fix_path_format.append(
552
+ cast(
553
+ list[PathComponent],
554
+ key.split("<DerivativeSep>") + [name_indices[0]],
555
+ )
556
+ )
557
+ else:
558
+ nested_set(table, path, column.data)
559
+
560
+ last_path = path
561
+
562
+ if fix_path_format:
563
+ _convert_to_array(table, fix_path_format)
564
+
565
+
566
+ def _convert_to_array(
567
+ table: dict[PathComponent, object],
568
+ fix_path_format: list[list[PathComponent]],
569
+ ) -> None:
570
+ """Convert to array.
571
+
572
+ Parameters
573
+ ----------
574
+ table : dict[PathComponent, object]
575
+ Value passed via ``table``.
576
+ fix_path_format : list[list[PathComponent]]
577
+ Filesystem path supplied via `fix_path_format`.
578
+
579
+ Returns
580
+ -------
581
+ None
582
+ No value is returned.
583
+
584
+ Notes
585
+ -----
586
+ Internal API: this helper is an implementation detail and may change
587
+ without notice.
588
+ """
589
+
590
+ path: list[PathComponent]
591
+ for path in fix_path_format:
592
+ value_object: object = nested_get(table, path)
593
+ if isinstance(value_object, np.ndarray):
594
+ continue
595
+ if not isinstance(value_object, dict):
596
+ raise RuntimeError(
597
+ "File corrupted: expected nested dictionary for conversion."
598
+ )
599
+ array_representation: np.ndarray = np.moveaxis(
600
+ _convert_dict_to_array(value_object),
601
+ -1,
602
+ 0,
603
+ )
604
+ nested_set(table, path, array_representation)
605
+
606
+
607
+ def _convert_dict_to_array(value_dict: dict[PathComponent, object]) -> np.ndarray:
608
+ """Convert dict to array.
609
+
610
+ Parameters
611
+ ----------
612
+ value_dict : dict[PathComponent, object]
613
+ Value passed via ``value_dict``.
614
+
615
+ Returns
616
+ -------
617
+ np.ndarray
618
+ Computed ``np.ndarray`` value.
619
+
620
+ Notes
621
+ -----
622
+ Internal API: this helper is an implementation detail and may change
623
+ without notice.
624
+ """
625
+
626
+ values: list[object] = []
627
+ value: object
628
+ for value in value_dict.values():
629
+ if isinstance(value, np.ndarray):
630
+ values.append(value)
631
+ elif isinstance(value, dict):
632
+ values.append(_convert_dict_to_array(value))
633
+ else:
634
+ raise RuntimeError(
635
+ "File corrupted: unexpected scalar while converting arrays."
636
+ )
637
+ return np.array(values)
@@ -0,0 +1,22 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2001-2026 JCMwave GmbH
3
+
4
+ """Public logging namespace for `jcmsuite`."""
5
+
6
+ from __future__ import annotations
7
+
8
+ from .runtime import (
9
+ TRACE,
10
+ TRACE_NAME,
11
+ configure_logging,
12
+ get_logger,
13
+ setup_logger,
14
+ )
15
+
16
+ __all__: list[str] = [
17
+ "TRACE",
18
+ "TRACE_NAME",
19
+ "configure_logging",
20
+ "get_logger",
21
+ "setup_logger",
22
+ ]