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,304 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2001-2026 JCMwave GmbH
3
+
4
+ """Tabular payload helpers for internal `xarray` exports."""
5
+
6
+ from __future__ import annotations
7
+
8
+ import logging
9
+ from collections.abc import Mapping, Sequence
10
+ from dataclasses import dataclass
11
+ from typing import Protocol
12
+
13
+ import numpy as np
14
+
15
+ from .....exceptions import InvalidConfigurationError
16
+ from ..pandas.payload import payload_to_tabular_rows
17
+ from .runtime import _XarrayModule
18
+ from .shared import (
19
+ _ensure_generated_value_dim_coords,
20
+ _normalize_scalar_coord_value,
21
+ _ordered_union,
22
+ _tabular_column_dtype_for_padding,
23
+ )
24
+ from .types import XarrayDataset
25
+
26
+
27
+ class _BatchIndexedKeys(Protocol):
28
+ """Structural batch metadata required by tabular stacking."""
29
+
30
+ @property
31
+ def index(self) -> int: ...
32
+
33
+ @property
34
+ def keys(self) -> Mapping[str, object]: ...
35
+
36
+
37
+ logger = logging.getLogger(f"{__package__}.export")
38
+
39
+
40
+ @dataclass(slots=True, frozen=True)
41
+ class _TabularXarrayTable:
42
+ """Normalized tabular payload ready for xarray export."""
43
+
44
+ row_count: int
45
+ column_names: tuple[str, ...]
46
+ column_arrays: dict[str, np.ndarray]
47
+ column_dims: dict[str, tuple[str, ...]]
48
+ attrs: dict[str, object]
49
+
50
+
51
+ def tabular_payload_to_xarray_table(
52
+ payload: object,
53
+ *,
54
+ payload_name: str,
55
+ ) -> _TabularXarrayTable:
56
+ """Normalize one tabular payload into stacked column arrays."""
57
+
58
+ rows: list[dict[str, object]] | None = payload_to_tabular_rows(payload)
59
+ if rows is None:
60
+ raise InvalidConfigurationError(
61
+ f"{payload_name} is not tabular and cannot be exported via to_xarray()."
62
+ )
63
+
64
+ row_count: int = len(rows)
65
+ ordered_column_names: tuple[object, ...] = _ordered_union(
66
+ [tuple(row.keys()) for row in rows]
67
+ )
68
+ column_names: tuple[str, ...] = tuple(
69
+ str(column_name) for column_name in ordered_column_names
70
+ )
71
+ column_arrays: dict[str, np.ndarray] = {}
72
+ column_dims: dict[str, tuple[str, ...]] = {}
73
+ column_name: str
74
+ for column_name in column_names:
75
+ values: list[object] = [row[column_name] for row in rows]
76
+ column_array: np.ndarray
77
+ column_dims_tuple: tuple[str, ...]
78
+ column_array, column_dims_tuple = _stack_tabular_column_values(
79
+ column_name,
80
+ values,
81
+ )
82
+ column_arrays[column_name] = column_array
83
+ column_dims[column_name] = column_dims_tuple
84
+
85
+ attrs: dict[str, object] = {}
86
+ if isinstance(payload, Mapping):
87
+ title_value: object | None = payload.get("title")
88
+ header_value: object | None = payload.get("header")
89
+ if title_value is not None:
90
+ attrs["title"] = title_value
91
+ if header_value is not None:
92
+ attrs["header"] = header_value
93
+
94
+ return _TabularXarrayTable(
95
+ row_count=row_count,
96
+ column_names=column_names,
97
+ column_arrays=column_arrays,
98
+ column_dims=column_dims,
99
+ attrs=attrs,
100
+ )
101
+
102
+
103
+ def tabular_table_to_xarray_dataset(
104
+ table: _TabularXarrayTable,
105
+ *,
106
+ xarray_module: _XarrayModule,
107
+ ) -> XarrayDataset:
108
+ """Convert one normalized tabular payload into an `xarray.Dataset`."""
109
+
110
+ data_vars: dict[str, object] = {}
111
+ column_name: str
112
+ for column_name in table.column_names:
113
+ data_vars[column_name] = (
114
+ table.column_dims[column_name],
115
+ table.column_arrays[column_name],
116
+ )
117
+
118
+ is_valid: np.ndarray = np.ones((table.row_count,), dtype=bool)
119
+ is_padded: np.ndarray = np.zeros((table.row_count,), dtype=bool)
120
+ data_vars["is_valid"] = (("row_index",), is_valid)
121
+ data_vars["is_padded"] = (("row_index",), is_padded)
122
+
123
+ coords: dict[str, object] = {"row_index": list(range(table.row_count))}
124
+ return xarray_module.Dataset(
125
+ data_vars=data_vars,
126
+ coords=coords,
127
+ attrs=dict(table.attrs),
128
+ )
129
+
130
+
131
+ def _stack_batch_tabular_tables(
132
+ entries: Sequence[_BatchIndexedKeys],
133
+ tables: Sequence[_TabularXarrayTable | None],
134
+ *,
135
+ xarray_module: _XarrayModule,
136
+ batch_axis_name: str = "index",
137
+ valid_entries: Sequence[bool] | None = None,
138
+ ) -> XarrayDataset:
139
+ """Stack normalized tabular payloads onto a leading batch axis."""
140
+
141
+ available_tables: list[_TabularXarrayTable] = [
142
+ table for table in tables if table is not None
143
+ ]
144
+ if not available_tables:
145
+ raise InvalidConfigurationError(
146
+ "No batch tabular payloads are available for to_xarray()."
147
+ )
148
+ first_table: _TabularXarrayTable = available_tables[0]
149
+ max_rows: int = max(table.row_count for table in available_tables)
150
+ requires_padding: bool = len(available_tables) != len(entries) or any(
151
+ table.row_count != max_rows for table in available_tables
152
+ )
153
+ if requires_padding:
154
+ logger.debug(
155
+ "Padding batch eigenvalues to row count %d from row counts %s.",
156
+ max_rows,
157
+ [None if table is None else table.row_count for table in tables],
158
+ )
159
+
160
+ for table in available_tables[1:]:
161
+ if table.column_names != first_table.column_names:
162
+ raise InvalidConfigurationError(
163
+ "Selected batch eigenvalue stream mixes different tabular columns and cannot be stacked via to_xarray()."
164
+ )
165
+ column_name: str
166
+ for column_name in first_table.column_names:
167
+ if table.column_dims[column_name] != first_table.column_dims[column_name]:
168
+ raise InvalidConfigurationError(
169
+ "Selected batch eigenvalue stream mixes incompatible column shapes and cannot be stacked via to_xarray()."
170
+ )
171
+
172
+ coords: dict[str, object] = {
173
+ batch_axis_name: [entry.index for entry in entries],
174
+ "row_index": list(range(max_rows)),
175
+ }
176
+ common_key_names: set[str] = set(entries[0].keys)
177
+ entry: _BatchIndexedKeys
178
+ for entry in entries[1:]:
179
+ common_key_names &= set(entry.keys)
180
+ key_name: str
181
+ for key_name in sorted(common_key_names):
182
+ normalized_values: list[object] = []
183
+ supported: bool = True
184
+ entry_value: object
185
+ for entry in entries:
186
+ entry_value = entry.keys[key_name]
187
+ normalized_value: object | None = _normalize_scalar_coord_value(entry_value)
188
+ if normalized_value is None:
189
+ supported = False
190
+ break
191
+ normalized_values.append(normalized_value)
192
+ if supported:
193
+ coords[key_name] = (batch_axis_name, np.asarray(normalized_values))
194
+
195
+ data_vars: dict[str, object] = {}
196
+ column_name = ""
197
+ for column_name in first_table.column_names:
198
+ first_array: np.ndarray = first_table.column_arrays[column_name]
199
+ arrays: list[np.ndarray] = [
200
+ (
201
+ np.empty(
202
+ (0,) + first_array.shape[1:],
203
+ dtype=first_array.dtype,
204
+ )
205
+ if table is None
206
+ else table.column_arrays[column_name]
207
+ )
208
+ for table in tables
209
+ ]
210
+ stacked_array: np.ndarray = _stack_batch_tabular_column(
211
+ arrays,
212
+ target_rows=max_rows,
213
+ )
214
+ base_dims: tuple[str, ...] = first_table.column_dims[column_name]
215
+ _ensure_generated_value_dim_coords(
216
+ coords,
217
+ value_dims=(batch_axis_name,) + base_dims,
218
+ value_array=stacked_array,
219
+ )
220
+ data_vars[column_name] = ((batch_axis_name,) + base_dims, stacked_array)
221
+
222
+ is_valid: np.ndarray = np.zeros((len(entries), max_rows), dtype=bool)
223
+ is_padded: np.ndarray = np.ones((len(entries), max_rows), dtype=bool)
224
+ entry_position: int
225
+ batch_table: _TabularXarrayTable | None
226
+ for entry_position, batch_table in enumerate(tables):
227
+ if batch_table is not None and (
228
+ valid_entries is None or valid_entries[entry_position]
229
+ ):
230
+ is_valid[entry_position, : batch_table.row_count] = True
231
+ is_padded[entry_position, : batch_table.row_count] = False
232
+ data_vars["is_valid"] = ((batch_axis_name, "row_index"), is_valid)
233
+ data_vars["is_padded"] = ((batch_axis_name, "row_index"), is_padded)
234
+
235
+ attrs: dict[str, object] = {}
236
+ if "title" in first_table.attrs:
237
+ attrs["title"] = first_table.attrs["title"]
238
+ if "header" in first_table.attrs:
239
+ attrs["header"] = first_table.attrs["header"]
240
+
241
+ return xarray_module.Dataset(
242
+ data_vars=data_vars,
243
+ coords=coords,
244
+ attrs=attrs,
245
+ )
246
+
247
+
248
+ def _stack_tabular_column_values(
249
+ column_name: str,
250
+ values: Sequence[object],
251
+ ) -> tuple[np.ndarray, tuple[str, ...]]:
252
+ """Stack one tabular column into a dense array plus dimension labels."""
253
+
254
+ value_arrays: list[np.ndarray] = [np.asarray(value) for value in values]
255
+ first_shape: tuple[int, ...] = value_arrays[0].shape if value_arrays else ()
256
+ value_array: np.ndarray
257
+ for value_array in value_arrays[1:]:
258
+ if value_array.shape != first_shape:
259
+ raise InvalidConfigurationError(
260
+ f"Tabular column {column_name!r} has inconsistent row value shapes and cannot be exported via to_xarray()."
261
+ )
262
+
263
+ if not value_arrays:
264
+ return np.asarray([], dtype=float), ("row_index",)
265
+
266
+ if first_shape == ():
267
+ return np.asarray(values), ("row_index",)
268
+
269
+ stacked: np.ndarray = np.stack(value_arrays, axis=0)
270
+ trailing_dims: tuple[str, ...] = tuple(
271
+ f"{column_name}_dim_{dimension_index}"
272
+ for dimension_index in range(len(first_shape))
273
+ )
274
+ return stacked, ("row_index",) + trailing_dims
275
+
276
+
277
+ def _stack_batch_tabular_column(
278
+ arrays: Sequence[np.ndarray],
279
+ *,
280
+ target_rows: int,
281
+ ) -> np.ndarray:
282
+ """Stack one tabular column across batch entries with row padding."""
283
+
284
+ requires_padding: bool = any(int(array.shape[0]) != target_rows for array in arrays)
285
+ dtype: np.dtype[np.generic] = _tabular_column_dtype_for_padding(
286
+ arrays,
287
+ requires_padding=requires_padding,
288
+ )
289
+ first_array: np.ndarray = arrays[0]
290
+ trailing_shape: tuple[int, ...] = tuple(int(axis) for axis in first_array.shape[1:])
291
+ fill_value: object = np.nan if dtype != np.dtype(object) else None
292
+ output_shape: tuple[int, ...] = (len(arrays), target_rows) + trailing_shape
293
+ stacked: np.ndarray = np.full(output_shape, fill_value, dtype=dtype)
294
+
295
+ array_position: int
296
+ array_value: np.ndarray
297
+ for array_position, array_value in enumerate(arrays):
298
+ row_count: int = int(array_value.shape[0])
299
+ cast_array: np.ndarray = array_value.astype(dtype, copy=False)
300
+ if trailing_shape:
301
+ stacked[array_position, :row_count, ...] = cast_array
302
+ else:
303
+ stacked[array_position, :row_count] = cast_array
304
+ return stacked
@@ -0,0 +1,28 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2001-2026 JCMwave GmbH
3
+
4
+ """Typing helpers for `xarray` integration."""
5
+
6
+ from __future__ import annotations
7
+
8
+ from typing import TYPE_CHECKING, Protocol, TypeAlias
9
+
10
+ __all__ = ["XarrayDataTree", "XarrayDataset"]
11
+
12
+ if TYPE_CHECKING:
13
+ from xarray import (
14
+ Dataset as _XarrayDataset, # pyright: ignore[reportMissingImports]
15
+ )
16
+ from xarray import (
17
+ DataTree as _XarrayDataTree, # pyright: ignore[reportAttributeAccessIssue]
18
+ )
19
+
20
+ XarrayDataTree: TypeAlias = _XarrayDataTree
21
+ XarrayDataset: TypeAlias = _XarrayDataset
22
+ else:
23
+
24
+ class XarrayDataset(Protocol):
25
+ """Fallback protocol for internal `xarray.Dataset` construction."""
26
+
27
+ class XarrayDataTree(Protocol):
28
+ """Runtime placeholder for public `xarray.DataTree` exports."""
@@ -0,0 +1,4 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2001-2026 JCMwave GmbH
3
+
4
+ """Internal result model implementations grouped by solve shape."""