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,556 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
|
2
|
+
# Copyright (c) 2001-2026 JCMwave GmbH
|
|
3
|
+
|
|
4
|
+
"""Core solve result models and result-file discovery helpers."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections.abc import Mapping
|
|
9
|
+
from dataclasses import dataclass, field
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import TYPE_CHECKING, Literal, cast
|
|
12
|
+
|
|
13
|
+
from ....context.models import BackendMode
|
|
14
|
+
from ....exceptions import InvalidConfigurationError
|
|
15
|
+
from ....loaders import (
|
|
16
|
+
CartesianFieldFormat,
|
|
17
|
+
load_cartesian_fields,
|
|
18
|
+
load_table,
|
|
19
|
+
)
|
|
20
|
+
from ...artifacts import (
|
|
21
|
+
ComputationalCosts,
|
|
22
|
+
DiscoveredArtifacts,
|
|
23
|
+
Eigenvalues,
|
|
24
|
+
PostprocessCollection,
|
|
25
|
+
discover_artifacts_from_project,
|
|
26
|
+
discover_artifacts_from_result_dir,
|
|
27
|
+
)
|
|
28
|
+
from ...field_exports import FieldExportPayload
|
|
29
|
+
from ...payloads import SolveKeys, Source, TableCollectionPayload, TablePayload
|
|
30
|
+
|
|
31
|
+
if TYPE_CHECKING:
|
|
32
|
+
import pandas as pd
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(slots=True, frozen=True)
|
|
36
|
+
class SolveExecutionLog:
|
|
37
|
+
"""Store the captured log for one solve.
|
|
38
|
+
|
|
39
|
+
Parameters
|
|
40
|
+
----------
|
|
41
|
+
backend : BackendMode
|
|
42
|
+
Execution method that produced the log.
|
|
43
|
+
stdout : str
|
|
44
|
+
Messages written to stdout.
|
|
45
|
+
stderr : str
|
|
46
|
+
Error messages written to standard error.
|
|
47
|
+
return_code : int | None
|
|
48
|
+
Completion code from JCMsuite, if available. A value of `0` indicates
|
|
49
|
+
success.
|
|
50
|
+
streamed_to_console : bool
|
|
51
|
+
`True` if the messages were also shown in the terminal while the solve
|
|
52
|
+
ran.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
#: Execution method that produced the log.
|
|
56
|
+
backend: BackendMode
|
|
57
|
+
#: Messages written to stdout.
|
|
58
|
+
stdout: str
|
|
59
|
+
#: Error messages written to standard error.
|
|
60
|
+
stderr: str
|
|
61
|
+
#: Completion code from JCMsuite, if available. Zero indicates success.
|
|
62
|
+
return_code: int | None
|
|
63
|
+
#: Whether the messages were also shown in the terminal during the solve.
|
|
64
|
+
streamed_to_console: bool
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@dataclass(slots=True, frozen=True)
|
|
68
|
+
class TemplateRenderInfo:
|
|
69
|
+
"""Store information about one template that JCMsuite converted.
|
|
70
|
+
|
|
71
|
+
Parameters
|
|
72
|
+
----------
|
|
73
|
+
source_template : Path
|
|
74
|
+
Source `.jcmt` or `.jcmpt` template.
|
|
75
|
+
rendered_project : Path
|
|
76
|
+
Generated `.jcm` or `.jcmp` file used by the solver.
|
|
77
|
+
keys : dict[str, object]
|
|
78
|
+
project keys used for template rendering.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
source_template: Path
|
|
82
|
+
rendered_project: Path
|
|
83
|
+
keys: dict[str, object]
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class SolveKeysPayload(SolveKeys):
|
|
87
|
+
"""Deprecated bridge for deferred pre-foundation consumers."""
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
def _raw(self) -> Mapping[str, object]:
|
|
91
|
+
return self
|
|
92
|
+
|
|
93
|
+
def to_dict(self) -> Mapping[object, object]:
|
|
94
|
+
return cast(Mapping[object, object], dict(self))
|
|
95
|
+
|
|
96
|
+
def to_df(self, orient: str | None = None) -> "pd.DataFrame":
|
|
97
|
+
if orient not in (None, "wide"):
|
|
98
|
+
return super().to_df(orient=orient)
|
|
99
|
+
return self._to_df_wide()
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@dataclass(slots=True)
|
|
103
|
+
class SolveResult:
|
|
104
|
+
"""Provide the result for one project and one set of project keys.
|
|
105
|
+
|
|
106
|
+
Parameters
|
|
107
|
+
----------
|
|
108
|
+
project_file : Path | None, optional
|
|
109
|
+
project file used for the solve.
|
|
110
|
+
backend_used : BackendMode | None, optional
|
|
111
|
+
Execution method used for the solve.
|
|
112
|
+
template_renders : tuple[TemplateRenderInfo, ...], optional
|
|
113
|
+
Template rendering operations completed during solve preparation.
|
|
114
|
+
daemon_job_id : int | None, optional
|
|
115
|
+
Daemon submission identifier, if the solve used the daemon.
|
|
116
|
+
log : SolveExecutionLog | None, optional
|
|
117
|
+
Messages and completion code from the solve.
|
|
118
|
+
keys : Mapping[str, object] | None, optional
|
|
119
|
+
project keys used for this solve result, or `None` if no project keys
|
|
120
|
+
were supplied.
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
#: Project file used for the solve.
|
|
124
|
+
project_file: Path | None = None
|
|
125
|
+
backend_used: BackendMode | None = field(default=None, repr=False)
|
|
126
|
+
template_renders: tuple[TemplateRenderInfo, ...] = field(
|
|
127
|
+
default_factory=tuple, repr=False
|
|
128
|
+
)
|
|
129
|
+
daemon_job_id: int | None = None
|
|
130
|
+
#: Messages and completion code from :class:`~jcmsuite.results.SolveExecutionLog`.
|
|
131
|
+
log: SolveExecutionLog | None = field(default=None, repr=False)
|
|
132
|
+
#: Project keys represented by :class:`~jcmsuite.results.SolveKeys`, or ``None`` when none were supplied.
|
|
133
|
+
keys: Mapping[str, object] | SolveKeys | None = field(
|
|
134
|
+
default_factory=SolveKeys,
|
|
135
|
+
repr=False,
|
|
136
|
+
)
|
|
137
|
+
_post_process_only: bool = field(default=False, repr=False)
|
|
138
|
+
_file: Path | None = field(default=None, init=False, repr=False)
|
|
139
|
+
_costs: ComputationalCosts | None = field(default=None, init=False, repr=False)
|
|
140
|
+
_eigenvalues: Eigenvalues | None = field(default=None, init=False, repr=False)
|
|
141
|
+
_postprocesses: PostprocessCollection | None = field(
|
|
142
|
+
default=None, init=False, repr=False
|
|
143
|
+
)
|
|
144
|
+
_field_data: Mapping[object, object] | None = field(
|
|
145
|
+
default=None, init=False, repr=False
|
|
146
|
+
)
|
|
147
|
+
_field_source: Source = field(default=None, init=False, repr=False)
|
|
148
|
+
_artifact_root: Path | None = field(default=None, init=False, repr=False)
|
|
149
|
+
_artifacts_loaded: bool = field(default=False, init=False, repr=False)
|
|
150
|
+
|
|
151
|
+
def __post_init__(self) -> None:
|
|
152
|
+
"""Normalize incoming key payload to ``SolveKeys``."""
|
|
153
|
+
|
|
154
|
+
if self.keys is not None and not isinstance(self.keys, SolveKeys):
|
|
155
|
+
self.keys = SolveKeys(dict(self.keys), source=self.project_file)
|
|
156
|
+
elif (
|
|
157
|
+
type(self.keys) is SolveKeys
|
|
158
|
+
and self.keys.source is None
|
|
159
|
+
and self.project_file is not None
|
|
160
|
+
):
|
|
161
|
+
self.keys = SolveKeys(dict(self.keys), source=self.project_file)
|
|
162
|
+
|
|
163
|
+
@classmethod
|
|
164
|
+
def from_project_file(cls, project_file: str | Path) -> SolveResult:
|
|
165
|
+
"""Open an existing solve result from a project file.
|
|
166
|
+
|
|
167
|
+
Parameters
|
|
168
|
+
----------
|
|
169
|
+
project_file : str | Path
|
|
170
|
+
Path to a rendered project file (`.jcmp` or `.jcm`). The method
|
|
171
|
+
loads result data from the `*_results` directory with the same
|
|
172
|
+
file stem.
|
|
173
|
+
|
|
174
|
+
Returns
|
|
175
|
+
-------
|
|
176
|
+
SolveResult
|
|
177
|
+
Solve result with its available result data loaded.
|
|
178
|
+
|
|
179
|
+
Raises
|
|
180
|
+
------
|
|
181
|
+
InvalidConfigurationError
|
|
182
|
+
If the project file is missing or no result data is found.
|
|
183
|
+
"""
|
|
184
|
+
|
|
185
|
+
resolved_project_file: Path = Path(project_file).expanduser().resolve()
|
|
186
|
+
if not resolved_project_file.is_file():
|
|
187
|
+
raise InvalidConfigurationError(
|
|
188
|
+
f"Project file is missing or not a file: {resolved_project_file}"
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
result: SolveResult = cls(project_file=resolved_project_file)
|
|
192
|
+
result.refresh_artifacts()
|
|
193
|
+
if not _has_discovered_artifacts(
|
|
194
|
+
file=result.file,
|
|
195
|
+
costs=result.costs,
|
|
196
|
+
eigenvalues=result.eigenvalues,
|
|
197
|
+
postprocesses=result.postprocesses,
|
|
198
|
+
):
|
|
199
|
+
expected_result_dir: Path = (
|
|
200
|
+
resolved_project_file.parent / f"{resolved_project_file.stem}_results"
|
|
201
|
+
)
|
|
202
|
+
raise InvalidConfigurationError(
|
|
203
|
+
"No result artifacts found for project file "
|
|
204
|
+
f"{resolved_project_file} (expected {expected_result_dir})."
|
|
205
|
+
)
|
|
206
|
+
return result
|
|
207
|
+
|
|
208
|
+
@classmethod
|
|
209
|
+
def from_result_dir(
|
|
210
|
+
cls,
|
|
211
|
+
result_dir: str | Path,
|
|
212
|
+
*,
|
|
213
|
+
project_file: str | Path | None = None,
|
|
214
|
+
) -> SolveResult:
|
|
215
|
+
"""Open an existing solve result from a result directory.
|
|
216
|
+
|
|
217
|
+
Parameters
|
|
218
|
+
----------
|
|
219
|
+
result_dir : str | Path
|
|
220
|
+
Path to a ``*_results`` directory that contains solver results.
|
|
221
|
+
project_file : str | Path | None, optional
|
|
222
|
+
project file associated with the result directory. If omitted, the
|
|
223
|
+
method tries to find the project file next to the directory.
|
|
224
|
+
|
|
225
|
+
Returns
|
|
226
|
+
-------
|
|
227
|
+
SolveResult
|
|
228
|
+
Solve result with its available result data loaded.
|
|
229
|
+
|
|
230
|
+
Raises
|
|
231
|
+
------
|
|
232
|
+
InvalidConfigurationError
|
|
233
|
+
If the result directory is invalid or no result data is found.
|
|
234
|
+
"""
|
|
235
|
+
|
|
236
|
+
resolved_result_dir: Path = Path(result_dir).expanduser().resolve()
|
|
237
|
+
if not resolved_result_dir.is_dir():
|
|
238
|
+
raise InvalidConfigurationError(
|
|
239
|
+
f"Result directory is missing or not a directory: {resolved_result_dir}"
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
resolved_project_file: Path | None
|
|
243
|
+
if project_file is not None:
|
|
244
|
+
resolved_project_file = Path(project_file).expanduser().resolve()
|
|
245
|
+
if not resolved_project_file.is_file():
|
|
246
|
+
raise InvalidConfigurationError(
|
|
247
|
+
"Explicit `project_file` is missing or not a file: "
|
|
248
|
+
f"{resolved_project_file}"
|
|
249
|
+
)
|
|
250
|
+
else:
|
|
251
|
+
resolved_project_file = _infer_project_file_from_result_dir(
|
|
252
|
+
resolved_result_dir
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
discovered_artifacts: DiscoveredArtifacts = discover_artifacts_from_result_dir(
|
|
256
|
+
resolved_result_dir
|
|
257
|
+
)
|
|
258
|
+
if not _has_discovered_artifacts(
|
|
259
|
+
file=discovered_artifacts.file,
|
|
260
|
+
costs=discovered_artifacts.costs,
|
|
261
|
+
eigenvalues=discovered_artifacts.eigenvalues,
|
|
262
|
+
postprocesses=discovered_artifacts.postprocesses,
|
|
263
|
+
):
|
|
264
|
+
raise InvalidConfigurationError(
|
|
265
|
+
f"No recognizable result artifacts found in {resolved_result_dir}."
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
result = cls(project_file=resolved_project_file)
|
|
269
|
+
result._artifact_root = resolved_result_dir
|
|
270
|
+
result._file = discovered_artifacts.file
|
|
271
|
+
result._costs = discovered_artifacts.costs
|
|
272
|
+
result._eigenvalues = discovered_artifacts.eigenvalues
|
|
273
|
+
result._postprocesses = discovered_artifacts.postprocesses
|
|
274
|
+
result._artifacts_loaded = True
|
|
275
|
+
return result
|
|
276
|
+
|
|
277
|
+
def load_table(
|
|
278
|
+
self,
|
|
279
|
+
table_file: str | Path,
|
|
280
|
+
*,
|
|
281
|
+
format: Literal["named"] = "named",
|
|
282
|
+
) -> TablePayload | TableCollectionPayload:
|
|
283
|
+
"""Load a table file associated with this solve result.
|
|
284
|
+
|
|
285
|
+
Parameters
|
|
286
|
+
----------
|
|
287
|
+
table_file : str | Path
|
|
288
|
+
Table file path. Relative paths are resolved against
|
|
289
|
+
`project_file.parent` when available.
|
|
290
|
+
format : {"named"}, optional
|
|
291
|
+
Output format. The only supported value is `"named"`.
|
|
292
|
+
|
|
293
|
+
Returns
|
|
294
|
+
-------
|
|
295
|
+
TablePayload | TableCollectionPayload
|
|
296
|
+
One table, or an ordered collection if the file contains multiple
|
|
297
|
+
tables.
|
|
298
|
+
|
|
299
|
+
Raises
|
|
300
|
+
------
|
|
301
|
+
InvalidConfigurationError
|
|
302
|
+
If the table path is not a file or `format` is not supported.
|
|
303
|
+
"""
|
|
304
|
+
|
|
305
|
+
resolved_table_file: Path = self._resolve_artifact_path(table_file)
|
|
306
|
+
return load_table(resolved_table_file, format=format)
|
|
307
|
+
|
|
308
|
+
def load_cartesian_fields(
|
|
309
|
+
self,
|
|
310
|
+
field_file: str | Path,
|
|
311
|
+
*,
|
|
312
|
+
format: CartesianFieldFormat = "squeeze",
|
|
313
|
+
) -> FieldExportPayload:
|
|
314
|
+
"""Load a Cartesian fieldbag file associated with this solve result.
|
|
315
|
+
|
|
316
|
+
Parameters
|
|
317
|
+
----------
|
|
318
|
+
field_file : str | Path
|
|
319
|
+
Fieldbag file path. Relative paths are resolved against
|
|
320
|
+
`project_file.parent` when available.
|
|
321
|
+
format : {"squeeze", "full"}, optional
|
|
322
|
+
Shape of the returned coordinates and field values. `"squeeze"`
|
|
323
|
+
removes dimensions of length 1. `"full"` keeps all dimensions.
|
|
324
|
+
|
|
325
|
+
Returns
|
|
326
|
+
-------
|
|
327
|
+
FieldExportPayload
|
|
328
|
+
Coordinates, field values, available derivatives, and file
|
|
329
|
+
information.
|
|
330
|
+
|
|
331
|
+
Raises
|
|
332
|
+
------
|
|
333
|
+
InvalidConfigurationError
|
|
334
|
+
If the fieldbag path is not a file or `format` is not supported.
|
|
335
|
+
RuntimeError
|
|
336
|
+
If the fieldbag file is damaged or uses an unsupported storage
|
|
337
|
+
format.
|
|
338
|
+
"""
|
|
339
|
+
|
|
340
|
+
if self._field_data is not None:
|
|
341
|
+
return FieldExportPayload(
|
|
342
|
+
self._field_data,
|
|
343
|
+
source=(
|
|
344
|
+
self._field_source
|
|
345
|
+
if self._field_source is not None
|
|
346
|
+
else "resultbag"
|
|
347
|
+
),
|
|
348
|
+
)
|
|
349
|
+
resolved_field_file: Path = self._resolve_artifact_path(field_file)
|
|
350
|
+
return load_cartesian_fields(resolved_field_file, format=format)
|
|
351
|
+
|
|
352
|
+
def _resolve_artifact_path(self, artifact_file: str | Path) -> Path:
|
|
353
|
+
"""Resolve a result-file path relative to known solve/result roots.
|
|
354
|
+
|
|
355
|
+
Parameters
|
|
356
|
+
----------
|
|
357
|
+
artifact_file : str | Path
|
|
358
|
+
Result filename or path from solver payloads.
|
|
359
|
+
|
|
360
|
+
Returns
|
|
361
|
+
-------
|
|
362
|
+
pathlib.Path
|
|
363
|
+
Absolute resolved result-file path.
|
|
364
|
+
|
|
365
|
+
Notes
|
|
366
|
+
-----
|
|
367
|
+
Internal API: this helper is implementation detail and may change
|
|
368
|
+
without notice.
|
|
369
|
+
"""
|
|
370
|
+
|
|
371
|
+
artifact_path: Path = Path(artifact_file).expanduser()
|
|
372
|
+
if artifact_path.is_absolute():
|
|
373
|
+
return artifact_path.resolve()
|
|
374
|
+
if self._artifact_root is not None:
|
|
375
|
+
return (self._artifact_root / artifact_path).resolve()
|
|
376
|
+
if self.project_file is not None:
|
|
377
|
+
return (self.project_file.parent / artifact_path).resolve()
|
|
378
|
+
return artifact_path.resolve()
|
|
379
|
+
|
|
380
|
+
def refresh_artifacts(self) -> None:
|
|
381
|
+
"""Read the result files again.
|
|
382
|
+
|
|
383
|
+
Returns
|
|
384
|
+
-------
|
|
385
|
+
None
|
|
386
|
+
The fieldbag, computational-cost, eigenvalue, and postprocess data
|
|
387
|
+
reflect the current files.
|
|
388
|
+
"""
|
|
389
|
+
|
|
390
|
+
discovered_artifacts: DiscoveredArtifacts
|
|
391
|
+
if self.project_file is None:
|
|
392
|
+
if self._artifact_root is None:
|
|
393
|
+
self._file = None
|
|
394
|
+
self._costs = None
|
|
395
|
+
self._eigenvalues = None
|
|
396
|
+
self._postprocesses = PostprocessCollection(records=())
|
|
397
|
+
self._artifacts_loaded = True
|
|
398
|
+
return
|
|
399
|
+
discovered_artifacts = discover_artifacts_from_result_dir(
|
|
400
|
+
self._artifact_root
|
|
401
|
+
)
|
|
402
|
+
else:
|
|
403
|
+
discovered_artifacts = discover_artifacts_from_project(self.project_file)
|
|
404
|
+
self._file = None if self._post_process_only else discovered_artifacts.file
|
|
405
|
+
self._costs = None if self._post_process_only else discovered_artifacts.costs
|
|
406
|
+
self._eigenvalues = (
|
|
407
|
+
None if self._post_process_only else discovered_artifacts.eigenvalues
|
|
408
|
+
)
|
|
409
|
+
self._postprocesses = discovered_artifacts.postprocesses
|
|
410
|
+
self._artifacts_loaded = True
|
|
411
|
+
|
|
412
|
+
def _ensure_artifacts_loaded(self) -> None:
|
|
413
|
+
"""Populate cached result-file fields on first access.
|
|
414
|
+
|
|
415
|
+
Returns
|
|
416
|
+
-------
|
|
417
|
+
None
|
|
418
|
+
This method mutates internal caches and returns nothing.
|
|
419
|
+
|
|
420
|
+
Notes
|
|
421
|
+
-----
|
|
422
|
+
Internal API: this helper is implementation detail and may change
|
|
423
|
+
without notice.
|
|
424
|
+
"""
|
|
425
|
+
|
|
426
|
+
if self._artifacts_loaded:
|
|
427
|
+
return
|
|
428
|
+
self.refresh_artifacts()
|
|
429
|
+
|
|
430
|
+
@property
|
|
431
|
+
def file(self) -> Path | None:
|
|
432
|
+
"""Return the solution fieldbag file.
|
|
433
|
+
|
|
434
|
+
Returns
|
|
435
|
+
-------
|
|
436
|
+
Path | None
|
|
437
|
+
Solution fieldbag file, or `None` if it is unavailable.
|
|
438
|
+
"""
|
|
439
|
+
|
|
440
|
+
self._ensure_artifacts_loaded()
|
|
441
|
+
return self._file
|
|
442
|
+
|
|
443
|
+
@property
|
|
444
|
+
def costs(self) -> ComputationalCosts | None:
|
|
445
|
+
"""Return computational-cost data.
|
|
446
|
+
|
|
447
|
+
Returns
|
|
448
|
+
-------
|
|
449
|
+
ComputationalCosts | None
|
|
450
|
+
Computational-cost data, or `None` if it is unavailable.
|
|
451
|
+
"""
|
|
452
|
+
|
|
453
|
+
self._ensure_artifacts_loaded()
|
|
454
|
+
return self._costs
|
|
455
|
+
|
|
456
|
+
@property
|
|
457
|
+
def postprocesses(self) -> PostprocessCollection:
|
|
458
|
+
"""Return the postprocess results in project file order.
|
|
459
|
+
|
|
460
|
+
Returns
|
|
461
|
+
-------
|
|
462
|
+
PostprocessCollection
|
|
463
|
+
Available postprocess results. An empty collection indicates that
|
|
464
|
+
no postprocess result is available.
|
|
465
|
+
"""
|
|
466
|
+
|
|
467
|
+
self._ensure_artifacts_loaded()
|
|
468
|
+
if self._postprocesses is None:
|
|
469
|
+
return PostprocessCollection(records=())
|
|
470
|
+
return self._postprocesses
|
|
471
|
+
|
|
472
|
+
@property
|
|
473
|
+
def eigenvalues(self) -> Eigenvalues | None:
|
|
474
|
+
"""Return eigenvalue data.
|
|
475
|
+
|
|
476
|
+
Returns
|
|
477
|
+
-------
|
|
478
|
+
Eigenvalues | None
|
|
479
|
+
Eigenvalue data, or `None` if it is unavailable.
|
|
480
|
+
"""
|
|
481
|
+
|
|
482
|
+
self._ensure_artifacts_loaded()
|
|
483
|
+
return self._eigenvalues
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
def _infer_project_file_from_result_dir(result_dir: Path) -> Path | None:
|
|
487
|
+
"""Infer project file next to a ``*_results`` directory.
|
|
488
|
+
|
|
489
|
+
Parameters
|
|
490
|
+
----------
|
|
491
|
+
result_dir : pathlib.Path
|
|
492
|
+
Candidate result directory path.
|
|
493
|
+
|
|
494
|
+
Returns
|
|
495
|
+
-------
|
|
496
|
+
pathlib.Path | None
|
|
497
|
+
Resolved project file path when inferable, else ``None``.
|
|
498
|
+
|
|
499
|
+
Notes
|
|
500
|
+
-----
|
|
501
|
+
Internal API: this helper is implementation detail and may change without
|
|
502
|
+
notice.
|
|
503
|
+
"""
|
|
504
|
+
|
|
505
|
+
directory_name: str = result_dir.name
|
|
506
|
+
if not directory_name.endswith("_results"):
|
|
507
|
+
return None
|
|
508
|
+
project_stem: str = directory_name[: -len("_results")]
|
|
509
|
+
if not project_stem:
|
|
510
|
+
return None
|
|
511
|
+
|
|
512
|
+
candidate_suffix: str
|
|
513
|
+
for candidate_suffix in (".jcmp", ".jcm"):
|
|
514
|
+
candidate_path: Path = result_dir.parent / f"{project_stem}{candidate_suffix}"
|
|
515
|
+
if candidate_path.is_file():
|
|
516
|
+
return candidate_path.resolve()
|
|
517
|
+
return None
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
def _has_discovered_artifacts(
|
|
521
|
+
*,
|
|
522
|
+
file: Path | None,
|
|
523
|
+
costs: ComputationalCosts | None,
|
|
524
|
+
eigenvalues: Eigenvalues | None,
|
|
525
|
+
postprocesses: PostprocessCollection,
|
|
526
|
+
) -> bool:
|
|
527
|
+
"""Determine whether discovered result-file data is non-empty.
|
|
528
|
+
|
|
529
|
+
Parameters
|
|
530
|
+
----------
|
|
531
|
+
file : pathlib.Path | None
|
|
532
|
+
Discovered primary solution file.
|
|
533
|
+
costs : ComputationalCosts | None
|
|
534
|
+
Discovered computational-cost payload.
|
|
535
|
+
eigenvalues : Eigenvalues | None
|
|
536
|
+
Discovered eigenvalue payload.
|
|
537
|
+
postprocesses : PostprocessCollection
|
|
538
|
+
Discovered postprocess collection.
|
|
539
|
+
|
|
540
|
+
Returns
|
|
541
|
+
-------
|
|
542
|
+
bool
|
|
543
|
+
``True`` if at least one result-file category is present.
|
|
544
|
+
|
|
545
|
+
Notes
|
|
546
|
+
-----
|
|
547
|
+
Internal API: this helper is implementation detail and may change without
|
|
548
|
+
notice.
|
|
549
|
+
"""
|
|
550
|
+
|
|
551
|
+
return (
|
|
552
|
+
file is not None
|
|
553
|
+
or costs is not None
|
|
554
|
+
or eigenvalues is not None
|
|
555
|
+
or len(postprocesses) > 0
|
|
556
|
+
)
|