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,325 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2001-2026 JCMwave GmbH
3
+
4
+ """Pandas export helpers for typed solve results."""
5
+
6
+ from __future__ import annotations
7
+
8
+ import warnings
9
+ from collections.abc import Sequence
10
+ from typing import TYPE_CHECKING, Protocol, cast
11
+
12
+ from ..exceptions import InvalidConfigurationError
13
+ from .artifacts import Eigenvalues, PostprocessCollection
14
+ from .internal.export.pandas.common import dataframe_rows as _dataframe_rows
15
+ from .internal.export.pandas.common import expanded_keys as _expanded_keys
16
+ from .internal.export.pandas.common import (
17
+ is_field_postprocess_record as _is_field_postprocess_record,
18
+ )
19
+ from .internal.export.pandas.common import (
20
+ normalize_optional_index_columns as _normalize_optional_index_columns,
21
+ )
22
+ from .internal.export.pandas.common import (
23
+ postprocess_value_mapping as _postprocess_value_mapping,
24
+ )
25
+ from .internal.export.pandas.payload import (
26
+ payload_to_tabular_rows as _payload_to_tabular_rows,
27
+ )
28
+ from .internal.export.pandas.payload import (
29
+ postprocess_payload_to_long_rows as _postprocess_payload_to_long_rows,
30
+ )
31
+ from .internal.export.pandas.payload import value_mapping as _value_mapping
32
+ from .payloads import TablePayload
33
+
34
+ if TYPE_CHECKING:
35
+ import pandas as pd
36
+
37
+ from .artifacts import PostprocessRecord
38
+ from .internal.models.batch import BatchExportRecord
39
+
40
+
41
+ class _PandasModule(Protocol):
42
+ """Runtime protocol for the subset of pandas used by exports."""
43
+
44
+ DataFrame: type["pd.DataFrame"]
45
+
46
+
47
+ def _load_pandas_module() -> _PandasModule:
48
+ """Load pandas module.
49
+
50
+ Parameters
51
+ ----------
52
+ None
53
+ This helper uses internal state only.
54
+
55
+ Returns
56
+ -------
57
+ _PandasModule
58
+ Computed ``_PandasModule`` value.
59
+
60
+ Notes
61
+ -----
62
+ Internal API: this helper is an implementation detail and may change
63
+ without notice.
64
+ """
65
+
66
+ try:
67
+ import pandas as pandas_module
68
+ except ModuleNotFoundError as exc:
69
+ raise InvalidConfigurationError(
70
+ "pandas integration requires `pandas` to be installed."
71
+ ) from exc
72
+ return cast(_PandasModule, pandas_module)
73
+
74
+
75
+ def payload_to_tabular_rows(payload: object) -> list[dict[str, object]] | None:
76
+ """Convert payload into tabular row dictionaries when feasible.
77
+
78
+ Parameters
79
+ ----------
80
+ payload : object
81
+ Arbitrary payload object that may contain mapping/list/ndarray data.
82
+
83
+ Returns
84
+ -------
85
+ list[dict[str, object]] | None
86
+ Tabular row dictionaries, or `None` when no robust tabular
87
+ representation can be inferred.
88
+ """
89
+
90
+ return _payload_to_tabular_rows(payload)
91
+
92
+
93
+ def batch_costs_to_df(entries: Sequence["BatchExportRecord"]) -> "pd.DataFrame":
94
+ """Export batch computational-cost payloads as a DataFrame."""
95
+
96
+ pandas_module: _PandasModule = _load_pandas_module()
97
+ rows: list[dict[str, object]] = []
98
+ entry: "BatchExportRecord"
99
+ for entry in entries:
100
+ if entry.payload is None:
101
+ continue
102
+ payload_object: object = entry.payload
103
+ if not isinstance(payload_object, TablePayload):
104
+ continue
105
+ payload: TablePayload = payload_object
106
+ tabular_rows: list[dict[str, object]] | None = _payload_to_tabular_rows(
107
+ _value_mapping(payload.to_dict())
108
+ )
109
+ if tabular_rows is None:
110
+ raise InvalidConfigurationError(
111
+ "Batch costs payload is not tabular and cannot be exported via to_df()."
112
+ )
113
+ key_columns: dict[str, object] = _expanded_keys(entry.keys)
114
+ row_index: int
115
+ row_data: dict[str, object]
116
+ for row_index, row_data in enumerate(tabular_rows):
117
+ merged_row: dict[str, object] = {
118
+ "batch_index": entry.index,
119
+ "row_index": row_index,
120
+ }
121
+ merged_row.update(key_columns)
122
+ merged_row.update(row_data)
123
+ rows.append(merged_row)
124
+ dataframe = pandas_module.DataFrame(rows)
125
+ return cast("pd.DataFrame", _normalize_optional_index_columns(dataframe))
126
+
127
+
128
+ def batch_keys_to_df_long(
129
+ entries: Sequence["BatchExportRecord"],
130
+ ) -> "pd.DataFrame":
131
+ """Export batch key metadata in long form with batch identity."""
132
+
133
+ pandas_module: _PandasModule = _load_pandas_module()
134
+ rows: list[dict[str, object]] = []
135
+ entry: "BatchExportRecord"
136
+ for entry in entries:
137
+ for key_name, key_value in sorted(entry.keys.items()):
138
+ rows.append(
139
+ {
140
+ "batch_index": entry.index,
141
+ "name": key_name,
142
+ "value": key_value,
143
+ }
144
+ )
145
+ dataframe = pandas_module.DataFrame(rows)
146
+ return cast("pd.DataFrame", dataframe)
147
+
148
+
149
+ def batch_eigenvalues_to_df(
150
+ entries: Sequence["BatchExportRecord"],
151
+ ) -> "pd.DataFrame":
152
+ """Export batch eigenvalue payloads as a DataFrame."""
153
+
154
+ pandas_module: _PandasModule = _load_pandas_module()
155
+ rows: list[dict[str, object]] = []
156
+ expected_columns: tuple[str, ...] | None = None
157
+ entry: "BatchExportRecord"
158
+ for entry in entries:
159
+ if entry.payload is None:
160
+ continue
161
+ payload_object = entry.payload
162
+ if not isinstance(payload_object, Eigenvalues):
163
+ continue
164
+ payload = payload_object
165
+ tabular_rows: list[dict[str, object]] | None = _payload_to_tabular_rows(
166
+ _value_mapping(payload.to_dict())
167
+ )
168
+ if tabular_rows is None:
169
+ raise InvalidConfigurationError(
170
+ "Batch eigenvalue payload is not tabular and cannot be exported via to_df()."
171
+ )
172
+ columns: tuple[str, ...] = (
173
+ tuple(str(column_name) for column_name in tabular_rows[0])
174
+ if tabular_rows
175
+ else ()
176
+ )
177
+ if expected_columns is None:
178
+ expected_columns = columns
179
+ elif columns != expected_columns:
180
+ raise InvalidConfigurationError(
181
+ "Batch eigenvalue payloads have incompatible table schemas."
182
+ )
183
+ key_columns: dict[str, object] = _expanded_keys(entry.keys)
184
+ row_index: int
185
+ row_data: dict[str, object]
186
+ for row_index, row_data in enumerate(tabular_rows):
187
+ merged_row: dict[str, object] = {
188
+ "batch_index": entry.index,
189
+ "row_index": row_index,
190
+ }
191
+ merged_row.update(key_columns)
192
+ merged_row.update(row_data)
193
+ rows.append(merged_row)
194
+ dataframe = pandas_module.DataFrame(rows)
195
+ return cast("pd.DataFrame", _normalize_optional_index_columns(dataframe))
196
+
197
+
198
+ def batch_postprocesses_to_dfs(
199
+ entries: Sequence["BatchExportRecord"],
200
+ *,
201
+ warn_skipped: bool = True,
202
+ expand_rows: bool = False,
203
+ ) -> dict[str, "pd.DataFrame"]:
204
+ """Export batch postprocess payloads as per-title DataFrames.
205
+
206
+ Notes
207
+ -----
208
+ Field-export payloads are skipped in ``to_dfs()`` outputs.
209
+ """
210
+
211
+ pandas_module: _PandasModule = _load_pandas_module()
212
+ grouped_rows: dict[str, list[dict[str, object]]] = {}
213
+ entry: "BatchExportRecord"
214
+ for entry in entries:
215
+ if not isinstance(entry.payload, PostprocessCollection):
216
+ continue
217
+
218
+ postprocess_index: int
219
+ postprocess_record: "PostprocessRecord"
220
+ for postprocess_index, postprocess_record in enumerate(entry.payload):
221
+ if _is_field_postprocess_record(postprocess_record):
222
+ if warn_skipped:
223
+ warnings.warn(
224
+ f"Skipping field-export postprocess {postprocess_record.title!r} in to_dfs().",
225
+ stacklevel=2,
226
+ )
227
+ continue
228
+
229
+ payload_mapping = _postprocess_value_mapping(postprocess_record)
230
+ payload_object: object = (
231
+ payload_mapping
232
+ if payload_mapping is not None
233
+ else postprocess_record._raw
234
+ )
235
+ tabular_rows: list[dict[str, object]] | None = (
236
+ _postprocess_payload_to_long_rows(payload_object)
237
+ )
238
+ if tabular_rows is None:
239
+ if warn_skipped:
240
+ warnings.warn(
241
+ f"Skipping non-tabular postprocess {postprocess_record.title!r} in to_dfs().",
242
+ stacklevel=2,
243
+ )
244
+ continue
245
+
246
+ title_key: str = (
247
+ postprocess_record.title
248
+ if postprocess_record.title is not None
249
+ else f"postprocess_{postprocess_index}"
250
+ )
251
+ bucket: list[dict[str, object]] = grouped_rows.setdefault(title_key, [])
252
+ key_columns: dict[str, object] = _expanded_keys(entry.keys)
253
+ row_data: dict[str, object]
254
+ for row_data in tabular_rows:
255
+ merged_row: dict[str, object] = {
256
+ "index": entry.index,
257
+ "postprocess_index": postprocess_index,
258
+ "postprocess_title": postprocess_record.title,
259
+ "source_file": str(postprocess_record.source_file),
260
+ }
261
+ merged_row.update(key_columns)
262
+ merged_row.update(row_data)
263
+ bucket.append(merged_row)
264
+
265
+ return {
266
+ title: cast(
267
+ "pd.DataFrame",
268
+ _normalize_optional_index_columns(pandas_module.DataFrame(rows)),
269
+ )
270
+ for title, rows in grouped_rows.items()
271
+ }
272
+
273
+
274
+ def batch_postprocesses_to_df(
275
+ entries: Sequence["BatchExportRecord"],
276
+ *,
277
+ index: int,
278
+ warn_skipped: bool = True,
279
+ expand_rows: bool = False,
280
+ ) -> "pd.DataFrame":
281
+ """Export batch postprocess payloads as a DataFrame.
282
+
283
+ Notes
284
+ -----
285
+ Field-export payloads are skipped by default and only fail when explicitly
286
+ selected by ``index``.
287
+ """
288
+
289
+ pandas_module: _PandasModule = _load_pandas_module()
290
+
291
+ rows: list[dict[str, object]] = []
292
+ matching_index_seen: bool = False
293
+ entry: "BatchExportRecord"
294
+ for entry in entries:
295
+ if not isinstance(entry.payload, PostprocessCollection):
296
+ continue
297
+
298
+ postprocess_index: int
299
+ postprocess_record: "PostprocessRecord"
300
+ for postprocess_index, postprocess_record in enumerate(entry.payload):
301
+ if postprocess_index != index:
302
+ continue
303
+ matching_index_seen = True
304
+
305
+ tabular_rows = _dataframe_rows(postprocess_record.to_df(orient="long"))
306
+
307
+ key_columns = _expanded_keys(entry.keys)
308
+ row_data: dict[str, object]
309
+ for row_data in tabular_rows:
310
+ merged_row: dict[str, object] = {
311
+ "index": entry.index,
312
+ "postprocess_index": postprocess_index,
313
+ "postprocess_title": postprocess_record.title,
314
+ "source_file": str(postprocess_record.source_file),
315
+ }
316
+ merged_row.update(key_columns)
317
+ merged_row.update(row_data)
318
+ rows.append(merged_row)
319
+
320
+ if not matching_index_seen:
321
+ raise InvalidConfigurationError(
322
+ f"No postprocess records found for index {index!r}."
323
+ )
324
+ dataframe = pandas_module.DataFrame(rows)
325
+ return cast("pd.DataFrame", _normalize_optional_index_columns(dataframe))