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,433 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2001-2026 JCMwave GmbH
3
+
4
+ """Semi-public advanced operations exposed through ``Resultbag.management``."""
5
+
6
+ from __future__ import annotations
7
+
8
+ from collections.abc import Callable, Mapping, Sequence
9
+ from pathlib import Path
10
+ from typing import TYPE_CHECKING
11
+
12
+ if TYPE_CHECKING:
13
+ from .internal.resultbag.store import _ResultbagStore
14
+
15
+
16
+ class ResultbagManagement:
17
+ """Provide advanced Resultbag maintenance and solve operations."""
18
+
19
+ def __init__(self, store: _ResultbagStore) -> None:
20
+ self._store: _ResultbagStore = store
21
+
22
+ def add(
23
+ self,
24
+ *,
25
+ keys: Mapping[str, object],
26
+ result: object,
27
+ log: object | None = None,
28
+ suffix_pattern: str | None = None,
29
+ ) -> None:
30
+ """Add or replace one Resultbag entry.
31
+
32
+ Parameters
33
+ ----------
34
+ keys : Mapping[str, object]
35
+ project keys that identify the Resultbag entry.
36
+ result : object
37
+ Versioned raw result dictionary to store. Other pickleable values
38
+ remain available through this low-level management surface. Older
39
+ result objects are converted before persistence.
40
+ log : object | None, optional
41
+ Log to store with the result.
42
+ suffix_pattern : str | None, optional
43
+ Suffix pattern that identifies the result. `None` identifies the
44
+ unsuffixed result.
45
+
46
+ Returns
47
+ -------
48
+ None
49
+ This method has no return value. The method adds or replaces the
50
+ Resultbag entry.
51
+ """
52
+
53
+ self._store.add(
54
+ keys=keys,
55
+ result=result,
56
+ log=log,
57
+ suffix_pattern=suffix_pattern,
58
+ )
59
+
60
+ def add_attempt_log(
61
+ self,
62
+ *,
63
+ keys: Mapping[str, object],
64
+ attempt_index: int,
65
+ payload: object,
66
+ suffix_pattern: str | None = None,
67
+ ) -> None:
68
+ """Store the log from one solve attempt.
69
+
70
+ Parameters
71
+ ----------
72
+ keys : Mapping[str, object]
73
+ project keys that identify the Resultbag entry.
74
+ attempt_index : int
75
+ Zero-based attempt index.
76
+ payload : object
77
+ Attempt log to store.
78
+ suffix_pattern : str | None, optional
79
+ Suffix pattern that identifies the result. `None` identifies the
80
+ unsuffixed result.
81
+
82
+ Returns
83
+ -------
84
+ None
85
+ This method has no return value. The method stores the attempt log.
86
+
87
+ Raises
88
+ ------
89
+ InvalidConfigurationError
90
+ If `attempt_index` is negative.
91
+ """
92
+
93
+ self._store.add_attempt_log(
94
+ keys=keys,
95
+ attempt_index=attempt_index,
96
+ payload=payload,
97
+ suffix_pattern=suffix_pattern,
98
+ )
99
+
100
+ def check_result(
101
+ self,
102
+ keys: Mapping[str, object],
103
+ *,
104
+ suffix_pattern: str | None = None,
105
+ ) -> bool:
106
+ """Check whether one Resultbag entry exists.
107
+
108
+ Parameters
109
+ ----------
110
+ keys : Mapping[str, object]
111
+ project keys that identify the Resultbag entry.
112
+ suffix_pattern : str | None, optional
113
+ Suffix pattern that identifies the result. `None` identifies the
114
+ unsuffixed result.
115
+
116
+ Returns
117
+ -------
118
+ bool
119
+ `True` if the exact Resultbag entry exists. Otherwise, `False`.
120
+ """
121
+
122
+ return self._store._check_result(keys, suffix_pattern=suffix_pattern)
123
+
124
+ def check_source_files(self, files: Sequence[str | Path]) -> bool:
125
+ """Check whether source files are unchanged.
126
+
127
+ Parameters
128
+ ----------
129
+ files : Sequence[str | Path]
130
+ Source files to compare with the stored file information.
131
+
132
+ Returns
133
+ -------
134
+ bool
135
+ `True` if the files match or source-file checks are ignored.
136
+ Otherwise, `False`.
137
+ """
138
+
139
+ return self._store.check_source_files(files)
140
+
141
+ def clear_attempt_logs(
142
+ self,
143
+ keys: Mapping[str, object],
144
+ *,
145
+ suffix_pattern: str | None = None,
146
+ ) -> None:
147
+ """Remove the solve-attempt logs for one Resultbag entry.
148
+
149
+ Parameters
150
+ ----------
151
+ keys : Mapping[str, object]
152
+ project keys that identify the Resultbag entry.
153
+ suffix_pattern : str | None, optional
154
+ Suffix pattern that identifies the result. `None` identifies the
155
+ unsuffixed result.
156
+
157
+ Returns
158
+ -------
159
+ None
160
+ This method has no return value. The method removes all matching
161
+ attempt logs.
162
+ """
163
+
164
+ self._store.clear_attempt_logs(keys, suffix_pattern=suffix_pattern)
165
+
166
+ def get_attempt_logs(
167
+ self,
168
+ keys: Mapping[str, object],
169
+ *,
170
+ suffix_pattern: str | None = None,
171
+ ) -> tuple[object, ...]:
172
+ """Return the stored solve-attempt logs for one Resultbag entry.
173
+
174
+ Parameters
175
+ ----------
176
+ keys : Mapping[str, object]
177
+ project keys that identify the Resultbag entry.
178
+ suffix_pattern : str | None, optional
179
+ Suffix pattern that identifies the result. `None` identifies the
180
+ unsuffixed result.
181
+
182
+ Returns
183
+ -------
184
+ tuple[object, ...]
185
+ Attempt logs in order of their `attempt_index` values.
186
+
187
+ Notes
188
+ -----
189
+ Only load attempt logs from a Resultbag file that you trust. This
190
+ method uses Python pickle to load stored objects.
191
+ """
192
+
193
+ return self._store.get_attempt_logs(keys, suffix_pattern=suffix_pattern)
194
+
195
+ def get_result(
196
+ self,
197
+ keys: Mapping[str, object],
198
+ *,
199
+ suffix_pattern: str | None = None,
200
+ ) -> object:
201
+ """Return the stored result for one set of project keys.
202
+
203
+ Parameters
204
+ ----------
205
+ keys : Mapping[str, object]
206
+ project keys that identify the Resultbag entry.
207
+ suffix_pattern : str | None, optional
208
+ Suffix pattern that identifies the result. `None` identifies the
209
+ unsuffixed result.
210
+
211
+ Returns
212
+ -------
213
+ object
214
+ Stored raw result dictionary or other management data.
215
+
216
+ Raises
217
+ ------
218
+ InvalidConfigurationError
219
+ If the entry does not exist.
220
+
221
+ Notes
222
+ -----
223
+ Only load results from a Resultbag file that you trust. This method
224
+ uses serialized storage data to load the raw result data.
225
+ """
226
+
227
+ return self._store._get_result(keys, suffix_pattern=suffix_pattern)
228
+
229
+ def get_log(
230
+ self,
231
+ keys: Mapping[str, object],
232
+ *,
233
+ suffix_pattern: str | None = None,
234
+ ) -> object:
235
+ """Return the stored log for one set of project keys.
236
+
237
+ Parameters
238
+ ----------
239
+ keys : Mapping[str, object]
240
+ project keys that identify the Resultbag entry.
241
+ suffix_pattern : str | None, optional
242
+ Suffix pattern that identifies the result. `None` identifies the
243
+ unsuffixed result.
244
+
245
+ Returns
246
+ -------
247
+ object
248
+ Stored log.
249
+
250
+ Raises
251
+ ------
252
+ InvalidConfigurationError
253
+ If the entry does not exist.
254
+
255
+ Notes
256
+ -----
257
+ Only load logs from a Resultbag file that you trust. This method uses
258
+ Python pickle to load the stored object.
259
+ """
260
+
261
+ return self._store.get_log(keys, suffix_pattern=suffix_pattern)
262
+
263
+ def remove(self, filter_function: Callable[[dict[str, object]], bool]) -> None:
264
+ """Remove entries selected by a filter function.
265
+
266
+ Parameters
267
+ ----------
268
+ filter_function : Callable[[dict[str, object]], bool]
269
+ Filter function that receives project keys. The function returns
270
+ `True` for each Resultbag entry to remove.
271
+
272
+ Examples
273
+ --------
274
+ Remove entries whose `material` project key is `"Si"`:
275
+
276
+ >>> resultbag.management.remove(
277
+ ... filter_function=lambda project_keys: project_keys.get("material") == "Si"
278
+ ... )
279
+
280
+ Returns
281
+ -------
282
+ None
283
+ This method has no return value. The method removes matching
284
+ entries, suffix variants, and attempt logs.
285
+ """
286
+
287
+ self._store.remove(filter_function)
288
+
289
+ def remove_result(
290
+ self,
291
+ keys: Mapping[str, object],
292
+ *,
293
+ suffix_pattern: str | None = None,
294
+ ) -> None:
295
+ """Remove one Resultbag entry.
296
+
297
+ Parameters
298
+ ----------
299
+ keys : Mapping[str, object]
300
+ project keys that identify the Resultbag entry.
301
+ suffix_pattern : str | None, optional
302
+ Suffix pattern that identifies the result. `None` identifies the
303
+ unsuffixed result.
304
+
305
+ Returns
306
+ -------
307
+ None
308
+ This method has no return value. The method removes the matching
309
+ Resultbag entry and its attempt logs.
310
+ """
311
+
312
+ self._store.remove_result(keys, suffix_pattern=suffix_pattern)
313
+
314
+ def reset(self) -> None:
315
+ """Remove all stored entries and attempt logs.
316
+
317
+ Returns
318
+ -------
319
+ None
320
+ This method has no return value. Resultbag settings remain stored.
321
+ """
322
+
323
+ self._store.reset()
324
+
325
+ def set_source_files(self, files: Sequence[str | Path]) -> None:
326
+ """Store information about the Resultbag source files.
327
+
328
+ Parameters
329
+ ----------
330
+ files : Sequence[str | Path]
331
+ Source files that determine whether stored results can be reused.
332
+
333
+ Returns
334
+ -------
335
+ None
336
+ This method has no return value. The method stores each file path
337
+ and a value that detects file changes.
338
+
339
+ Raises
340
+ ------
341
+ InvalidConfigurationError
342
+ If a path is missing or is not a regular file.
343
+ """
344
+
345
+ self._store.set_source_files(files)
346
+
347
+ def ignore_source_files(self, ignore: bool = True) -> None:
348
+ """Enable or disable source-file consistency checks.
349
+
350
+ Parameters
351
+ ----------
352
+ ignore : bool, optional
353
+ If `True`, do not check source files. If `False`, check the source
354
+ files before reusing results.
355
+
356
+ Returns
357
+ -------
358
+ None
359
+ This method has no return value. The method stores the setting.
360
+ """
361
+
362
+ self._store.ignore_source_files(ignore)
363
+
364
+ def bind_job(
365
+ self,
366
+ *,
367
+ keys: Mapping[str, object],
368
+ job_id: int,
369
+ suffix_pattern: str | None,
370
+ ) -> None:
371
+ """Associate a daemon submission with project keys.
372
+
373
+ Parameters
374
+ ----------
375
+ keys : Mapping[str, object]
376
+ project keys for the daemon submission.
377
+ job_id : int
378
+ Daemon submission identifier.
379
+ suffix_pattern : str | None
380
+ Suffix pattern for the result. `None` identifies the unsuffixed
381
+ result.
382
+
383
+ Returns
384
+ -------
385
+ None
386
+ This method has no return value. The Resultbag stores the
387
+ association until the daemon result is available.
388
+ """
389
+
390
+ self._store._set_job_id(keys, job_id, suffix_pattern=suffix_pattern)
391
+
392
+ def store_job_result(self, *, job_id: int, result: object, log: object) -> None:
393
+ """Store the result for an associated daemon submission.
394
+
395
+ Parameters
396
+ ----------
397
+ job_id : int
398
+ Daemon submission identifier previously passed to `bind_job(...)`.
399
+ result : object
400
+ Result to store.
401
+ log : object
402
+ Log to store with the result.
403
+
404
+ Returns
405
+ -------
406
+ None
407
+ This method has no return value. The method stores the result and
408
+ removes the daemon submission association.
409
+ """
410
+
411
+ self._store._add_for_job(
412
+ id=job_id,
413
+ result=result,
414
+ log=log,
415
+ )
416
+ self.release_job(job_id)
417
+
418
+ def release_job(self, job_id: int) -> None:
419
+ """Release a daemon submission association.
420
+
421
+ Parameters
422
+ ----------
423
+ job_id : int
424
+ Daemon submission identifier to release.
425
+
426
+ Returns
427
+ -------
428
+ None
429
+ This method has no return value. If the association exists, the
430
+ method removes it.
431
+ """
432
+
433
+ self._store._release(job_id)