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.
- jcmsuite/__init__.py +22 -0
- jcmsuite/_build_info.py +4 -0
- jcmsuite/context/__init__.py +44 -0
- jcmsuite/context/interface_metadata.py +158 -0
- jcmsuite/context/models.py +213 -0
- jcmsuite/context/scope.py +210 -0
- jcmsuite/context/solver_context.py +569 -0
- jcmsuite/context/subprocess_tools.py +172 -0
- jcmsuite/contract.py +47 -0
- jcmsuite/daemon/__init__.py +19 -0
- jcmsuite/daemon/handler.py +925 -0
- jcmsuite/daemon/internal/__init__.py +4 -0
- jcmsuite/daemon/internal/bundle_protocol.py +64 -0
- jcmsuite/daemon/internal/handler_helpers.py +368 -0
- jcmsuite/daemon/internal/handler_resource_jobs.py +227 -0
- jcmsuite/daemon/internal/handler_wait.py +564 -0
- jcmsuite/daemon/models.py +349 -0
- jcmsuite/daemon/namespaces.py +250 -0
- jcmsuite/daemon/protocol.py +801 -0
- jcmsuite/daemon/resources.py +407 -0
- jcmsuite/daemon/scope.py +53 -0
- jcmsuite/daemon/transport.py +223 -0
- jcmsuite/editing/__init__.py +10 -0
- jcmsuite/editing/editor.py +274 -0
- jcmsuite/exceptions/__init__.py +32 -0
- jcmsuite/exceptions/errors.py +173 -0
- jcmsuite/geo/__init__.py +10 -0
- jcmsuite/geo/mesh.py +302 -0
- jcmsuite/info/__init__.py +10 -0
- jcmsuite/info/runtime_info.py +45 -0
- jcmsuite/internal/__init__.py +2 -0
- jcmsuite/internal/diagnostics.py +74 -0
- jcmsuite/internal/progress.py +80 -0
- jcmsuite/loaders/__init__.py +18 -0
- jcmsuite/loaders/blob_header.py +315 -0
- jcmsuite/loaders/cartesian_field_reader.py +249 -0
- jcmsuite/loaders/cartesian_fields.py +324 -0
- jcmsuite/loaders/nested_mapping.py +69 -0
- jcmsuite/loaders/powerflux.py +136 -0
- jcmsuite/loaders/table.py +637 -0
- jcmsuite/logging/__init__.py +22 -0
- jcmsuite/logging/runtime.py +210 -0
- jcmsuite/results/__init__.py +126 -0
- jcmsuite/results/artifacts.py +806 -0
- jcmsuite/results/discovery.py +82 -0
- jcmsuite/results/field_exports.py +1062 -0
- jcmsuite/results/field_payloads.py +453 -0
- jcmsuite/results/internal/__init__.py +4 -0
- jcmsuite/results/internal/export/__init__.py +4 -0
- jcmsuite/results/internal/export/common.py +56 -0
- jcmsuite/results/internal/export/pandas/__init__.py +4 -0
- jcmsuite/results/internal/export/pandas/common.py +165 -0
- jcmsuite/results/internal/export/pandas/payload.py +480 -0
- jcmsuite/results/internal/export/pandas/rows.py +484 -0
- jcmsuite/results/internal/export/preview.py +178 -0
- jcmsuite/results/internal/export/xarray/__init__.py +4 -0
- jcmsuite/results/internal/export/xarray/export.py +688 -0
- jcmsuite/results/internal/export/xarray/grouped.py +608 -0
- jcmsuite/results/internal/export/xarray/headers.py +290 -0
- jcmsuite/results/internal/export/xarray/runtime.py +99 -0
- jcmsuite/results/internal/export/xarray/shared.py +246 -0
- jcmsuite/results/internal/export/xarray/tabular.py +304 -0
- jcmsuite/results/internal/export/xarray/types.py +28 -0
- jcmsuite/results/internal/models/__init__.py +4 -0
- jcmsuite/results/internal/models/batch.py +1081 -0
- jcmsuite/results/internal/models/batch_postprocess.py +1728 -0
- jcmsuite/results/internal/models/bundle.py +343 -0
- jcmsuite/results/internal/models/core.py +556 -0
- jcmsuite/results/internal/models/submission.py +1157 -0
- jcmsuite/results/internal/resultbag/__init__.py +4 -0
- jcmsuite/results/internal/resultbag/access.py +489 -0
- jcmsuite/results/internal/resultbag/iteration.py +199 -0
- jcmsuite/results/internal/resultbag/query.py +226 -0
- jcmsuite/results/internal/resultbag/raw.py +407 -0
- jcmsuite/results/internal/resultbag/source_files.py +142 -0
- jcmsuite/results/internal/resultbag/store.py +881 -0
- jcmsuite/results/internal/resultbag/utils.py +258 -0
- jcmsuite/results/models.py +76 -0
- jcmsuite/results/opening.py +55 -0
- jcmsuite/results/pandas_export.py +325 -0
- jcmsuite/results/payloads.py +478 -0
- jcmsuite/results/postprocess.py +97 -0
- jcmsuite/results/postprocess_payloads.py +757 -0
- jcmsuite/results/postprocess_record.py +418 -0
- jcmsuite/results/resultbag.py +279 -0
- jcmsuite/results/resultbag_management.py +433 -0
- jcmsuite/results/structured_derivatives.py +387 -0
- jcmsuite/solve/__init__.py +10 -0
- jcmsuite/solve/daemon_bundle_staging.py +100 -0
- jcmsuite/solve/daemon_bundle_wait.py +89 -0
- jcmsuite/solve/orchestration.py +1576 -0
- jcmsuite/solve/orchestration_execution.py +180 -0
- jcmsuite/solve/orchestration_routing.py +128 -0
- jcmsuite/solve/orchestration_support.py +323 -0
- jcmsuite/solve/path_resolution.py +98 -0
- jcmsuite/solve/progress.py +20 -0
- jcmsuite/solve/solver.py +709 -0
- jcmsuite/solve/staging.py +264 -0
- jcmsuite/solve/types.py +25 -0
- jcmsuite/solve/working_dirs.py +227 -0
- jcmsuite/templates/__init__.py +11 -0
- jcmsuite/templates/converter.py +71 -0
- jcmsuite/templates/formatting.py +335 -0
- jcmsuite/templates/formatting_cli.py +47 -0
- jcmsuite/templates/rendering.py +666 -0
- jcmsuite/torch/__init__.py +25 -0
- jcmsuite/torch/autograd.py +488 -0
- jcmsuite/torch/coordinate_policy.py +82 -0
- jcmsuite/torch/core.py +312 -0
- jcmsuite/torch/results/__init__.py +51 -0
- jcmsuite/torch/types.py +84 -0
- jcmsuite/torch/validation.py +208 -0
- jcmsuite/torch/wrappers.py +4332 -0
- jcmsuite/view/__init__.py +10 -0
- jcmsuite/view/viewer.py +122 -0
- jcmsuite-7.4.2.dist-info/METADATA +180 -0
- jcmsuite-7.4.2.dist-info/RECORD +119 -0
- jcmsuite-7.4.2.dist-info/WHEEL +4 -0
- jcmsuite-7.4.2.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
|
2
|
+
# Copyright (c) 2001-2026 JCMwave GmbH
|
|
3
|
+
|
|
4
|
+
"""Parameter derivative views for structured numeric postprocess mappings."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections.abc import Mapping
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from typing import TYPE_CHECKING, Literal
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
from ..exceptions import InvalidConfigurationError
|
|
15
|
+
from .payloads import Source
|
|
16
|
+
from .postprocess_payloads import _StructuredRecordPayload
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
import pandas as pd
|
|
20
|
+
|
|
21
|
+
from .internal.export.xarray.types import XarrayDataTree
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
_STRUCTURED_ROOT_METADATA_KEYS: frozenset[str] = frozenset(
|
|
25
|
+
{"coordinates", "header", "metadata", "title"}
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _is_metadata_key(key: object, *, root: bool) -> bool:
|
|
30
|
+
"""Return whether a structured mapping key names schema/coordinate metadata."""
|
|
31
|
+
return (
|
|
32
|
+
root and isinstance(key, str) and key.lower() in _STRUCTURED_ROOT_METADATA_KEYS
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _parameter_branches(
|
|
37
|
+
values: Mapping[object, object],
|
|
38
|
+
) -> dict[str, Mapping[object, object]]:
|
|
39
|
+
"""Return immediate ``d_<parameter>`` mapping branches in source order."""
|
|
40
|
+
|
|
41
|
+
branches: dict[str, Mapping[object, object]] = {}
|
|
42
|
+
key: object
|
|
43
|
+
value: object
|
|
44
|
+
for key, value in values.items():
|
|
45
|
+
if not isinstance(key, str) or not key.startswith("d_"):
|
|
46
|
+
continue
|
|
47
|
+
parameter: str = key[2:]
|
|
48
|
+
if not parameter:
|
|
49
|
+
raise InvalidConfigurationError(
|
|
50
|
+
"Structured derivative branch has an empty parameter name."
|
|
51
|
+
)
|
|
52
|
+
if not isinstance(value, Mapping) or not _contains_numeric(value):
|
|
53
|
+
continue
|
|
54
|
+
branches[parameter] = value
|
|
55
|
+
return branches
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _contains_numeric(value: object) -> bool:
|
|
59
|
+
"""Return whether a nested branch contains a numerical value."""
|
|
60
|
+
|
|
61
|
+
if isinstance(value, Mapping):
|
|
62
|
+
return any(_contains_numeric(child) for child in value.values())
|
|
63
|
+
return bool(np.issubdtype(np.asarray(value).dtype, np.number))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _base_values(values: Mapping[object, object]) -> dict[object, object]:
|
|
67
|
+
"""Remove derivative namespaces to obtain the ordinary structured payload."""
|
|
68
|
+
|
|
69
|
+
base: dict[object, object] = {}
|
|
70
|
+
key: object
|
|
71
|
+
value: object
|
|
72
|
+
for key, value in values.items():
|
|
73
|
+
if isinstance(key, str) and key.startswith("d_"):
|
|
74
|
+
continue
|
|
75
|
+
base[key] = _base_values(value) if isinstance(value, Mapping) else value
|
|
76
|
+
return base
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _same_metadata(left: object, right: object) -> bool:
|
|
80
|
+
"""Compare non-numeric coordinate or schema values safely."""
|
|
81
|
+
|
|
82
|
+
try:
|
|
83
|
+
return bool(np.array_equal(np.asarray(left), np.asarray(right)))
|
|
84
|
+
except (TypeError, ValueError):
|
|
85
|
+
return False
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _selected_values(
|
|
89
|
+
branch: Mapping[object, object],
|
|
90
|
+
base: Mapping[object, object],
|
|
91
|
+
*,
|
|
92
|
+
root: bool = True,
|
|
93
|
+
) -> dict[object, object]:
|
|
94
|
+
"""Select numeric derivative leaves and unchanged metadata in the base schema."""
|
|
95
|
+
|
|
96
|
+
selected: dict[object, object] = {}
|
|
97
|
+
key: object
|
|
98
|
+
value: object
|
|
99
|
+
for key, value in branch.items():
|
|
100
|
+
if isinstance(key, str) and key.startswith("d_"):
|
|
101
|
+
continue
|
|
102
|
+
if key not in base:
|
|
103
|
+
continue
|
|
104
|
+
base_value: object = base[key]
|
|
105
|
+
if _is_metadata_key(key, root=root):
|
|
106
|
+
selected[key] = base_value
|
|
107
|
+
continue
|
|
108
|
+
if isinstance(value, Mapping) and isinstance(base_value, Mapping):
|
|
109
|
+
selected[key] = _selected_values(value, base_value, root=False)
|
|
110
|
+
elif _contains_numeric(value) and _contains_numeric(base_value):
|
|
111
|
+
selected[key] = value
|
|
112
|
+
elif not _contains_numeric(value) and _same_metadata(value, base_value):
|
|
113
|
+
selected[key] = value
|
|
114
|
+
return selected
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _has_selected_numeric(
|
|
118
|
+
branch: Mapping[object, object], base: Mapping[object, object]
|
|
119
|
+
) -> bool:
|
|
120
|
+
"""Return whether a branch selects at least one numeric base-schema leaf."""
|
|
121
|
+
|
|
122
|
+
return _contains_numeric_payload(_selected_values(branch, base))
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _contains_numeric_payload(value: object, *, root: bool = True) -> bool:
|
|
126
|
+
"""Return whether a structured selection contains a numeric value leaf."""
|
|
127
|
+
if isinstance(value, Mapping):
|
|
128
|
+
return any(
|
|
129
|
+
not _is_metadata_key(key, root=root)
|
|
130
|
+
and _contains_numeric_payload(child, root=False)
|
|
131
|
+
for key, child in value.items()
|
|
132
|
+
)
|
|
133
|
+
return bool(np.issubdtype(np.asarray(value).dtype, np.number))
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _same_values(left: object, right: object, *, path: str) -> bool:
|
|
137
|
+
"""Compare duplicate symmetric payloads and reject incompatible shapes."""
|
|
138
|
+
|
|
139
|
+
if isinstance(left, Mapping) and isinstance(right, Mapping):
|
|
140
|
+
if left.keys() != right.keys():
|
|
141
|
+
raise InvalidConfigurationError(
|
|
142
|
+
f"Structured second-derivative payloads have incompatible keys at {path!r}."
|
|
143
|
+
)
|
|
144
|
+
return all(
|
|
145
|
+
_same_values(left[key], right[key], path=f"{path}.{key}") for key in left
|
|
146
|
+
)
|
|
147
|
+
left_array: np.ndarray = np.asarray(left)
|
|
148
|
+
right_array: np.ndarray = np.asarray(right)
|
|
149
|
+
if left_array.shape != right_array.shape:
|
|
150
|
+
raise InvalidConfigurationError(
|
|
151
|
+
f"Structured second-derivative payloads have incompatible shapes at {path!r}: "
|
|
152
|
+
f"{left_array.shape} and {right_array.shape}."
|
|
153
|
+
)
|
|
154
|
+
try:
|
|
155
|
+
return bool(np.array_equal(left_array, right_array, equal_nan=True))
|
|
156
|
+
except TypeError:
|
|
157
|
+
return bool(np.array_equal(left_array, right_array))
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _validate_output_shapes(
|
|
161
|
+
derivative: object, base: object, *, path: str = "payload"
|
|
162
|
+
) -> None:
|
|
163
|
+
"""Ensure derivative leaves retain the corresponding base-value shape."""
|
|
164
|
+
|
|
165
|
+
if isinstance(derivative, Mapping) and isinstance(base, Mapping):
|
|
166
|
+
key: object
|
|
167
|
+
for key, value in derivative.items():
|
|
168
|
+
if key in base:
|
|
169
|
+
_validate_output_shapes(value, base[key], path=f"{path}.{key}")
|
|
170
|
+
return
|
|
171
|
+
derivative_shape: tuple[int, ...] = np.asarray(derivative).shape
|
|
172
|
+
base_shape: tuple[int, ...] = np.asarray(base).shape
|
|
173
|
+
if derivative_shape != base_shape:
|
|
174
|
+
raise InvalidConfigurationError(
|
|
175
|
+
f"Structured derivative has incompatible shape at {path!r}: "
|
|
176
|
+
f"{derivative_shape} does not match base shape {base_shape}."
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
@dataclass(frozen=True, slots=True)
|
|
181
|
+
class StructuredDerivativeCollection:
|
|
182
|
+
"""Discover and select structured derivative views by solver parameter.
|
|
183
|
+
|
|
184
|
+
Use a postprocess record's ``derivatives`` property to obtain this collection.
|
|
185
|
+
Call ``keys()`` to discover parameter names, then select a name with brackets.
|
|
186
|
+
Do not construct this collection directly.
|
|
187
|
+
"""
|
|
188
|
+
|
|
189
|
+
_branches: Mapping[str, Mapping[object, object]]
|
|
190
|
+
_source: Source
|
|
191
|
+
_title: str | None
|
|
192
|
+
_root: Mapping[object, object]
|
|
193
|
+
_pair_context: str | None = None
|
|
194
|
+
|
|
195
|
+
@property
|
|
196
|
+
def _derivative_order(self) -> Literal[0, 1]:
|
|
197
|
+
"""Return semantic derivative order without changing constructor shape."""
|
|
198
|
+
return 1 if self._pair_context is not None else 0
|
|
199
|
+
|
|
200
|
+
def keys(self) -> tuple[str, ...]:
|
|
201
|
+
"""Return the available immediate parameter names in source order.
|
|
202
|
+
|
|
203
|
+
Returns
|
|
204
|
+
-------
|
|
205
|
+
tuple[str, ...]
|
|
206
|
+
Exact solver parameter names available at this selection level.
|
|
207
|
+
"""
|
|
208
|
+
|
|
209
|
+
if self._pair_context is None:
|
|
210
|
+
return tuple(self._branches)
|
|
211
|
+
prior: str = self._pair_context
|
|
212
|
+
available: list[str] = []
|
|
213
|
+
base: Mapping[object, object] = _base_values(self._root)
|
|
214
|
+
for name, branch in _parameter_branches(self._root).items():
|
|
215
|
+
nested_branch: Mapping[object, object] | None = _parameter_branches(
|
|
216
|
+
branch
|
|
217
|
+
).get(prior)
|
|
218
|
+
if (
|
|
219
|
+
nested_branch is not None
|
|
220
|
+
and _has_selected_numeric(nested_branch, base)
|
|
221
|
+
and name not in available
|
|
222
|
+
):
|
|
223
|
+
available.append(name)
|
|
224
|
+
prior_branch: Mapping[object, object] | None = _parameter_branches(
|
|
225
|
+
self._root
|
|
226
|
+
).get(prior)
|
|
227
|
+
if prior_branch is not None:
|
|
228
|
+
for name in _parameter_branches(prior_branch):
|
|
229
|
+
nested_branch = _parameter_branches(prior_branch)[name]
|
|
230
|
+
if _has_selected_numeric(nested_branch, base) and name not in available:
|
|
231
|
+
available.append(name)
|
|
232
|
+
return tuple(available)
|
|
233
|
+
|
|
234
|
+
def __getitem__(self, parameter: str) -> StructuredDerivativeView:
|
|
235
|
+
"""Select the derivative for one exact parameter name.
|
|
236
|
+
|
|
237
|
+
Parameters
|
|
238
|
+
----------
|
|
239
|
+
parameter : str
|
|
240
|
+
Exact solver parameter name to select.
|
|
241
|
+
|
|
242
|
+
Returns
|
|
243
|
+
-------
|
|
244
|
+
StructuredDerivativeView
|
|
245
|
+
Selected structured derivative payload.
|
|
246
|
+
|
|
247
|
+
Raises
|
|
248
|
+
------
|
|
249
|
+
KeyError
|
|
250
|
+
If the named derivative branch is not available.
|
|
251
|
+
InvalidConfigurationError
|
|
252
|
+
If symmetric mixed-pair payloads conflict.
|
|
253
|
+
"""
|
|
254
|
+
|
|
255
|
+
if parameter not in self.keys():
|
|
256
|
+
context: str = (
|
|
257
|
+
"" if self._pair_context is None else f" after {self._pair_context}"
|
|
258
|
+
)
|
|
259
|
+
raise KeyError(
|
|
260
|
+
f"Derivative path {context} -> {parameter!r} is unavailable."
|
|
261
|
+
)
|
|
262
|
+
branch: Mapping[object, object]
|
|
263
|
+
if self._pair_context is None:
|
|
264
|
+
branch = self._branches[parameter]
|
|
265
|
+
_validate_output_shapes(branch, self._root)
|
|
266
|
+
else:
|
|
267
|
+
branch = self._root
|
|
268
|
+
base: Mapping[object, object] = _base_values(self._root)
|
|
269
|
+
selected: dict[object, object] = _selected_values(branch, base)
|
|
270
|
+
nested: dict[str, Mapping[object, object]] = _parameter_branches(branch)
|
|
271
|
+
if self._pair_context is not None:
|
|
272
|
+
prior_name: str = self._pair_context
|
|
273
|
+
# Table parsing represents d(d(Q)_p)_q as d_q -> d_p -> Q.
|
|
274
|
+
# Also accept the reverse nested representation when present.
|
|
275
|
+
candidates: list[Mapping[object, object]] = []
|
|
276
|
+
outer: Mapping[str, Mapping[object, object]] = _parameter_branches(
|
|
277
|
+
self._root
|
|
278
|
+
)
|
|
279
|
+
if parameter in outer and prior_name in _parameter_branches(
|
|
280
|
+
outer[parameter]
|
|
281
|
+
):
|
|
282
|
+
candidates.append(_parameter_branches(outer[parameter])[prior_name])
|
|
283
|
+
if prior_name in outer and parameter in _parameter_branches(
|
|
284
|
+
outer[prior_name]
|
|
285
|
+
):
|
|
286
|
+
candidates.append(_parameter_branches(outer[prior_name])[parameter])
|
|
287
|
+
if candidates:
|
|
288
|
+
canonical: Mapping[object, object] = candidates[0]
|
|
289
|
+
for duplicate in candidates[1:]:
|
|
290
|
+
if not _same_values(
|
|
291
|
+
canonical, duplicate, path=f"{prior_name},{parameter}"
|
|
292
|
+
):
|
|
293
|
+
raise InvalidConfigurationError(
|
|
294
|
+
f"Conflicting duplicate structured derivative pair "
|
|
295
|
+
f"{prior_name!r}, {parameter!r}."
|
|
296
|
+
)
|
|
297
|
+
_validate_output_shapes(canonical, self._root)
|
|
298
|
+
selected = _selected_values(canonical, base)
|
|
299
|
+
if not _contains_numeric_payload(selected):
|
|
300
|
+
raise KeyError(
|
|
301
|
+
f"Derivative path {prior_name!r} -> {parameter!r} "
|
|
302
|
+
"has no numeric values matching the base payload."
|
|
303
|
+
)
|
|
304
|
+
nested = _parameter_branches(canonical)
|
|
305
|
+
else:
|
|
306
|
+
raise KeyError(
|
|
307
|
+
f"Derivative path {prior_name!r} -> {parameter!r} is unavailable."
|
|
308
|
+
)
|
|
309
|
+
derivatives: StructuredDerivativeCollection = StructuredDerivativeCollection(
|
|
310
|
+
_branches={} if self._pair_context is not None else nested,
|
|
311
|
+
_source=self._source,
|
|
312
|
+
_title=self._title,
|
|
313
|
+
_root=self._root,
|
|
314
|
+
_pair_context=parameter if self._pair_context is None else None,
|
|
315
|
+
)
|
|
316
|
+
return StructuredDerivativeView(
|
|
317
|
+
_values=selected,
|
|
318
|
+
source=self._source,
|
|
319
|
+
title=self._title,
|
|
320
|
+
derivatives=derivatives,
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
@dataclass(frozen=True, slots=True)
|
|
325
|
+
class StructuredDerivativeView:
|
|
326
|
+
"""Selected numeric derivative data with structured export operations.
|
|
327
|
+
|
|
328
|
+
Attributes
|
|
329
|
+
----------
|
|
330
|
+
source : Source
|
|
331
|
+
Source path or provenance of the originating postprocess.
|
|
332
|
+
title : str | None
|
|
333
|
+
Postprocess title, when available.
|
|
334
|
+
derivatives : StructuredDerivativeCollection
|
|
335
|
+
Derivative directions available from this selected payload.
|
|
336
|
+
"""
|
|
337
|
+
|
|
338
|
+
_values: Mapping[object, object]
|
|
339
|
+
source: Source
|
|
340
|
+
title: str | None
|
|
341
|
+
derivatives: StructuredDerivativeCollection
|
|
342
|
+
|
|
343
|
+
def to_dict(self) -> Mapping[object, object]:
|
|
344
|
+
"""Return only the selected derivative values.
|
|
345
|
+
|
|
346
|
+
Returns
|
|
347
|
+
-------
|
|
348
|
+
Mapping[object, object]
|
|
349
|
+
Selected derivative values and matching structured metadata.
|
|
350
|
+
"""
|
|
351
|
+
|
|
352
|
+
return dict(self._values)
|
|
353
|
+
|
|
354
|
+
def _payload(self) -> _StructuredRecordPayload:
|
|
355
|
+
"""Build the structured export adapter with the view's provenance."""
|
|
356
|
+
|
|
357
|
+
mapping: dict[object, object] = dict(self._values)
|
|
358
|
+
if self.title is not None:
|
|
359
|
+
mapping["title"] = self.title
|
|
360
|
+
return _StructuredRecordPayload(mapping=mapping, source=self.source)
|
|
361
|
+
|
|
362
|
+
def to_df(self, orient: str | None = None) -> "pd.DataFrame":
|
|
363
|
+
"""Export the selected values using the structured long layout.
|
|
364
|
+
|
|
365
|
+
Parameters
|
|
366
|
+
----------
|
|
367
|
+
orient : str | None, optional
|
|
368
|
+
Use `None` or ``"long"``. Structured wide export is unsupported.
|
|
369
|
+
|
|
370
|
+
Returns
|
|
371
|
+
-------
|
|
372
|
+
pandas.DataFrame
|
|
373
|
+
Long-form path/value rows for the selected derivative.
|
|
374
|
+
"""
|
|
375
|
+
|
|
376
|
+
return self._payload().to_df(orient=orient)
|
|
377
|
+
|
|
378
|
+
def to_xarray(self) -> "XarrayDataTree":
|
|
379
|
+
"""Export the selected values using the structured xarray layout.
|
|
380
|
+
|
|
381
|
+
Returns
|
|
382
|
+
-------
|
|
383
|
+
xarray.DataTree
|
|
384
|
+
Tree containing the selected derivative values.
|
|
385
|
+
"""
|
|
386
|
+
|
|
387
|
+
return self._payload().to_xarray()
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
|
2
|
+
# Copyright (c) 2001-2026 JCMwave GmbH
|
|
3
|
+
|
|
4
|
+
"""Isolate staged daemon bundle entries without copying their previous results."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections.abc import Sequence
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from ..exceptions import InvalidConfigurationError
|
|
12
|
+
from .staging import stage_bundle_runtime_inputs
|
|
13
|
+
from .types import WorkingDirInput
|
|
14
|
+
from .working_dirs import (
|
|
15
|
+
create_temporary_working_dir,
|
|
16
|
+
resolve_batch_working_dirs,
|
|
17
|
+
resolve_bundle_common_base,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def resolve_daemon_bundle_batch_dirs(
|
|
22
|
+
*,
|
|
23
|
+
working_dir: WorkingDirInput,
|
|
24
|
+
batch_size: int,
|
|
25
|
+
temp_dir_root: Path | None,
|
|
26
|
+
cached_indices: set[int],
|
|
27
|
+
project_files: Sequence[Path],
|
|
28
|
+
) -> list[Path | None]:
|
|
29
|
+
"""Resolve distinct live entry roots and reject overlapping explicit roots."""
|
|
30
|
+
|
|
31
|
+
roots: list[Path | None] = resolve_batch_working_dirs(
|
|
32
|
+
working_dir=working_dir,
|
|
33
|
+
batch_size=batch_size,
|
|
34
|
+
temporary=False,
|
|
35
|
+
temp_dir_root=temp_dir_root,
|
|
36
|
+
)
|
|
37
|
+
if working_dir is None:
|
|
38
|
+
roots = [
|
|
39
|
+
(
|
|
40
|
+
None
|
|
41
|
+
if index in cached_indices
|
|
42
|
+
else create_temporary_working_dir(
|
|
43
|
+
index=index, temp_dir_root=temp_dir_root
|
|
44
|
+
)
|
|
45
|
+
)
|
|
46
|
+
for index in range(batch_size)
|
|
47
|
+
]
|
|
48
|
+
live_roots: list[Path] = [
|
|
49
|
+
root
|
|
50
|
+
for index, root in enumerate(roots)
|
|
51
|
+
if index not in cached_indices and root is not None
|
|
52
|
+
]
|
|
53
|
+
for index, root in enumerate(live_roots):
|
|
54
|
+
if len(live_roots) > 1 and any(
|
|
55
|
+
project.is_relative_to(root) for project in project_files
|
|
56
|
+
):
|
|
57
|
+
raise InvalidConfigurationError(
|
|
58
|
+
"Live daemon bundle batch roots must not contain source projects."
|
|
59
|
+
)
|
|
60
|
+
if any(
|
|
61
|
+
root.is_relative_to(other) or other.is_relative_to(root)
|
|
62
|
+
for other in live_roots[:index]
|
|
63
|
+
):
|
|
64
|
+
raise InvalidConfigurationError(
|
|
65
|
+
"Daemon bundle batch working directories must not overlap."
|
|
66
|
+
)
|
|
67
|
+
return roots
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def stage_daemon_bundles(
|
|
71
|
+
*,
|
|
72
|
+
project_files: Sequence[Path],
|
|
73
|
+
bundle_roots: Sequence[Path | None],
|
|
74
|
+
excluded_roots: Sequence[Path | None] = (),
|
|
75
|
+
) -> None:
|
|
76
|
+
"""Stage all live roots before submission, excluding outputs and sibling roots."""
|
|
77
|
+
|
|
78
|
+
live_roots: tuple[Path, ...] = tuple(
|
|
79
|
+
root for root in bundle_roots if root is not None
|
|
80
|
+
)
|
|
81
|
+
if not live_roots:
|
|
82
|
+
return
|
|
83
|
+
common_base: Path = resolve_bundle_common_base(project_files=project_files)
|
|
84
|
+
excluded_dirs: tuple[Path, ...] = (
|
|
85
|
+
*live_roots,
|
|
86
|
+
*(
|
|
87
|
+
root
|
|
88
|
+
for root in excluded_roots
|
|
89
|
+
if root is not None
|
|
90
|
+
and not any(project.is_relative_to(root) for project in project_files)
|
|
91
|
+
),
|
|
92
|
+
*(project.parent / f"{project.stem}_results" for project in project_files),
|
|
93
|
+
)
|
|
94
|
+
for root in live_roots:
|
|
95
|
+
stage_bundle_runtime_inputs(
|
|
96
|
+
source_root=common_base,
|
|
97
|
+
target_root=root,
|
|
98
|
+
skip_files=set(),
|
|
99
|
+
skip_directories=excluded_dirs,
|
|
100
|
+
)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
|
2
|
+
# Copyright (c) 2001-2026 JCMwave GmbH
|
|
3
|
+
|
|
4
|
+
"""Collect one bundle batch entry with whole-bundle retry and failure semantics."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections.abc import Callable, Coroutine
|
|
9
|
+
from typing import TYPE_CHECKING
|
|
10
|
+
|
|
11
|
+
from ..exceptions import InvalidConfigurationError, SolveExecutionError
|
|
12
|
+
from ..results import (
|
|
13
|
+
BatchSolveFailure,
|
|
14
|
+
BundledBatchSolveEntry,
|
|
15
|
+
BundledBatchSolveSubmissionEntry,
|
|
16
|
+
BundledSolveResult,
|
|
17
|
+
)
|
|
18
|
+
from .types import BatchOnError
|
|
19
|
+
|
|
20
|
+
if TYPE_CHECKING:
|
|
21
|
+
from ..daemon.handler import DaemonHandler
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
async def wait_bundle_batch_entry(
|
|
25
|
+
*,
|
|
26
|
+
entry: BundledBatchSolveSubmissionEntry,
|
|
27
|
+
daemon: DaemonHandler,
|
|
28
|
+
timeout: float | None,
|
|
29
|
+
on_error: BatchOnError,
|
|
30
|
+
progress: bool,
|
|
31
|
+
progress_label: str | None,
|
|
32
|
+
max_retries: int,
|
|
33
|
+
resubmit: Callable[
|
|
34
|
+
[BundledBatchSolveSubmissionEntry],
|
|
35
|
+
Coroutine[object, object, BundledBatchSolveSubmissionEntry],
|
|
36
|
+
],
|
|
37
|
+
) -> BundledBatchSolveEntry:
|
|
38
|
+
"""Retain the original entry index and retry only closed execution failures."""
|
|
39
|
+
|
|
40
|
+
active: BundledBatchSolveSubmissionEntry = entry
|
|
41
|
+
for attempt in range(max_retries + 1):
|
|
42
|
+
if active.result is None:
|
|
43
|
+
if active.failure is None:
|
|
44
|
+
raise InvalidConfigurationError(
|
|
45
|
+
"Batch bundle submission entry has neither result nor failure."
|
|
46
|
+
)
|
|
47
|
+
if on_error == "raise":
|
|
48
|
+
raise InvalidConfigurationError(active.failure.message)
|
|
49
|
+
return BundledBatchSolveEntry(
|
|
50
|
+
index=entry.index,
|
|
51
|
+
keys=entry.keys,
|
|
52
|
+
result=None,
|
|
53
|
+
failure=active.failure,
|
|
54
|
+
project_files=entry.project_files,
|
|
55
|
+
)
|
|
56
|
+
try:
|
|
57
|
+
result: BundledSolveResult = await active.result.wait(
|
|
58
|
+
daemon=daemon,
|
|
59
|
+
asynchronous=True,
|
|
60
|
+
timeout=timeout,
|
|
61
|
+
progress=progress,
|
|
62
|
+
progress_label=progress_label,
|
|
63
|
+
)
|
|
64
|
+
except Exception as error:
|
|
65
|
+
if isinstance(error, SolveExecutionError) and attempt < max_retries:
|
|
66
|
+
active = await resubmit(entry)
|
|
67
|
+
continue
|
|
68
|
+
if on_error == "raise":
|
|
69
|
+
raise
|
|
70
|
+
return BundledBatchSolveEntry(
|
|
71
|
+
index=entry.index,
|
|
72
|
+
keys=entry.keys,
|
|
73
|
+
result=None,
|
|
74
|
+
failure=BatchSolveFailure(
|
|
75
|
+
index=entry.index,
|
|
76
|
+
keys=entry.keys,
|
|
77
|
+
exception_type=type(error),
|
|
78
|
+
message=str(error),
|
|
79
|
+
),
|
|
80
|
+
project_files=entry.project_files,
|
|
81
|
+
)
|
|
82
|
+
return BundledBatchSolveEntry(
|
|
83
|
+
index=entry.index,
|
|
84
|
+
keys=entry.keys,
|
|
85
|
+
result=result,
|
|
86
|
+
failure=None,
|
|
87
|
+
project_files=entry.project_files,
|
|
88
|
+
)
|
|
89
|
+
raise RuntimeError("Bundle batch retry loop terminated unexpectedly.")
|