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,1157 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2001-2026 JCMwave GmbH
3
+
4
+ """submission handle models for daemon-dispatched solves."""
5
+
6
+ from __future__ import annotations
7
+
8
+ import asyncio
9
+ from collections.abc import Callable, Coroutine, Iterator, Sequence
10
+ from dataclasses import dataclass, field
11
+ from pathlib import Path
12
+ from typing import TYPE_CHECKING, Literal, overload
13
+
14
+ from ....exceptions import (
15
+ ConfigMappingError,
16
+ InvalidConfigurationError,
17
+ SolveExecutionError,
18
+ )
19
+ from ....internal.diagnostics import trim_exception_traceback
20
+ from .batch import BatchSolveEntry, BatchSolveFailure, BatchSolveResult
21
+ from .bundle import BundledBatchSolveResult, BundledSolveResult
22
+ from .core import SolveResult
23
+
24
+ if TYPE_CHECKING:
25
+ from ....daemon.handler import DaemonHandler
26
+ from ...resultbag import Resultbag
27
+
28
+
29
+ @dataclass(slots=True, frozen=True)
30
+ class SolveSubmission:
31
+ """Represent one solve submitted to the daemon.
32
+
33
+ Parameters
34
+ ----------
35
+ job_id : int
36
+ Daemon submission identifier for this submitted solve.
37
+ result : SolveResult
38
+ Result information associated with this submission.
39
+ keys : dict[str, object] | None, optional
40
+ Submitted project keys, if available.
41
+ index : int | None, optional
42
+ Position in the batched project keys, if applicable.
43
+ """
44
+
45
+ job_id: int
46
+ result: SolveResult
47
+ keys: dict[str, object] | None = None
48
+ index: int | None = None
49
+ _waiter: DaemonHandler | None = field(
50
+ default=None,
51
+ repr=False,
52
+ compare=False,
53
+ init=False,
54
+ )
55
+ _resultbag: Resultbag | None = field(
56
+ default=None,
57
+ repr=False,
58
+ compare=False,
59
+ init=False,
60
+ )
61
+ _suffix_pattern: str | None = field(
62
+ default=None,
63
+ repr=False,
64
+ compare=False,
65
+ init=False,
66
+ )
67
+ _source_project_mappings: tuple[tuple[Path, Path], ...] = field(
68
+ default=(),
69
+ repr=False,
70
+ compare=False,
71
+ init=False,
72
+ )
73
+
74
+ def _bind_runtime(
75
+ self,
76
+ *,
77
+ waiter: DaemonHandler | None,
78
+ resultbag: Resultbag | None = None,
79
+ suffix_pattern: str | None = None,
80
+ source_project_mappings: tuple[tuple[Path, Path], ...] = (),
81
+ ) -> SolveSubmission:
82
+ """Bind internal runtime handles not exposed in the public constructor.
83
+
84
+ Notes
85
+ -----
86
+ Internal API: this helper mutates frozen runtime-only fields to keep
87
+ constructor signatures clean in user-facing docs.
88
+ """
89
+
90
+ object.__setattr__(self, "_waiter", waiter)
91
+ object.__setattr__(self, "_resultbag", resultbag)
92
+ object.__setattr__(self, "_suffix_pattern", suffix_pattern)
93
+ object.__setattr__(self, "_source_project_mappings", source_project_mappings)
94
+ return self
95
+
96
+ @overload
97
+ def wait(
98
+ self,
99
+ *,
100
+ daemon: DaemonHandler | None = None,
101
+ asynchronous: Literal[False] = False,
102
+ break_when: Literal["all", "any"] = "all",
103
+ timeout: float | None = None,
104
+ on_timeout: Literal["raise", "return"] = "raise",
105
+ on_error: Literal["raise", "collect"] = "raise",
106
+ progress: bool = False,
107
+ progress_label: str | None = None,
108
+ ) -> SolveResult: ...
109
+
110
+ @overload
111
+ def wait(
112
+ self,
113
+ *,
114
+ daemon: DaemonHandler | None = None,
115
+ asynchronous: Literal[True],
116
+ break_when: Literal["all", "any"] = "all",
117
+ timeout: float | None = None,
118
+ on_timeout: Literal["raise", "return"] = "raise",
119
+ on_error: Literal["raise", "collect"] = "raise",
120
+ progress: bool = False,
121
+ progress_label: str | None = None,
122
+ ) -> Coroutine[object, object, SolveResult]: ...
123
+
124
+ def wait(
125
+ self,
126
+ *,
127
+ daemon: DaemonHandler | None = None,
128
+ asynchronous: bool = False,
129
+ break_when: Literal["all", "any"] = "all",
130
+ timeout: float | None = None,
131
+ on_timeout: Literal["raise", "return"] = "raise",
132
+ on_error: Literal["raise", "collect"] = "raise",
133
+ progress: bool = False,
134
+ progress_label: str | None = None,
135
+ ) -> SolveResult | Coroutine[object, object, SolveResult]:
136
+ """Wait for this submission and return its result.
137
+
138
+ Parameters
139
+ ----------
140
+ daemon : DaemonHandler | None, optional
141
+ Daemon handler to use. If `daemon` is `None`, use the handler that
142
+ created the submission.
143
+ asynchronous : bool, optional
144
+ If `True`, return a coroutine. The caller must await the coroutine.
145
+ break_when : {"all", "any"}, optional
146
+ Completion condition. `"all"` waits for all submitted solves.
147
+ `"any"` returns after the first submitted solve completes.
148
+ timeout : float | None, optional
149
+ Maximum wait time in seconds. `None` sets no time limit.
150
+ on_timeout : {"raise", "return"}, optional
151
+ Action at the time limit. `"raise"` raises an exception.
152
+ `"return"` returns the results that are available.
153
+ on_error : {"raise", "collect"}, optional
154
+ Action when a solve fails. `"raise"` raises an exception.
155
+ `"collect"` stores the failure information in the result.
156
+ progress : bool, optional
157
+ If `True`, show progress while more than one solve is pending.
158
+ progress_label : str | None, optional
159
+ Text for the progress indicator. If omitted, the wait operation
160
+ uses its default label.
161
+
162
+ Returns
163
+ -------
164
+ SolveResult | Coroutine[object, object, SolveResult]
165
+ Result for the project. If `asynchronous` is `True`, returns a
166
+ coroutine that produces the result.
167
+ """
168
+
169
+ waiter: DaemonHandler | None = daemon if daemon is not None else self._waiter
170
+ if waiter is None:
171
+ raise InvalidConfigurationError(
172
+ "SolveSubmission is not bound to a daemon handler. Pass "
173
+ "`daemon=` explicitly or create the submission via "
174
+ "`jcmsuite.solve(..., dispatch='submit')`."
175
+ )
176
+ if asynchronous:
177
+ return waiter.wait(
178
+ self,
179
+ asynchronous=True,
180
+ break_when=break_when,
181
+ timeout=timeout,
182
+ on_timeout=on_timeout,
183
+ on_error=on_error,
184
+ progress=progress,
185
+ progress_label=progress_label,
186
+ )
187
+ return waiter.wait(
188
+ self,
189
+ asynchronous=False,
190
+ break_when=break_when,
191
+ timeout=timeout,
192
+ on_timeout=on_timeout,
193
+ on_error=on_error,
194
+ progress=progress,
195
+ )
196
+
197
+
198
+ @dataclass(slots=True, frozen=True)
199
+ class BundledSolveSubmission:
200
+ """Represent one ordered project bundle submitted as one daemon job.
201
+
202
+ Parameters
203
+ ----------
204
+ job_id : int | None
205
+ One daemon job identifier, or `None` for a cached bundle.
206
+ project_files : tuple[Path, ...]
207
+ Prepared project files in execution order. Cached handles retain the
208
+ supplied project input paths instead.
209
+ keys : dict[str, object] | None, optional
210
+ Project Keys for the complete bundle.
211
+
212
+ Notes
213
+ -----
214
+ On a Slurm queue, all projects execute in order within one scheduler job.
215
+ Wait for the complete bundle before selecting individual project results.
216
+ This Submission does not support indexing or slicing. A
217
+ `BundledBatchSolveSubmission` supports both operations on complete bundles.
218
+ """
219
+
220
+ #: One daemon job identifier, or ``None`` for a cached bundle.
221
+ job_id: int | None
222
+ #: Prepared project paths in execution order; supplied input paths for a cached bundle.
223
+ project_files: tuple[Path, ...] = ()
224
+ #: Project Keys for the complete bundle, or ``None`` when no Project Keys were supplied.
225
+ keys: dict[str, object] | None = None
226
+ _wait_task: asyncio.Task[BundledSolveResult] | None = field(
227
+ default=None,
228
+ repr=False,
229
+ compare=False,
230
+ init=False,
231
+ )
232
+ _failure: ConfigMappingError | SolveExecutionError | None = field(
233
+ default=None,
234
+ repr=False,
235
+ compare=False,
236
+ init=False,
237
+ )
238
+ _waiter: DaemonHandler | None = field(
239
+ default=None,
240
+ repr=False,
241
+ compare=False,
242
+ init=False,
243
+ )
244
+ _wait_callback: (
245
+ Callable[..., Coroutine[object, object, BundledSolveResult]] | None
246
+ ) = field(
247
+ default=None,
248
+ repr=False,
249
+ compare=False,
250
+ init=False,
251
+ )
252
+ _resolved_result: BundledSolveResult | None = field(
253
+ default=None,
254
+ repr=False,
255
+ compare=False,
256
+ init=False,
257
+ )
258
+
259
+ def _bind_runtime(
260
+ self,
261
+ *,
262
+ waiter: DaemonHandler | None,
263
+ wait_callback: (
264
+ Callable[..., Coroutine[object, object, BundledSolveResult]] | None
265
+ ) = None,
266
+ resolved_result: BundledSolveResult | None = None,
267
+ ) -> BundledSolveSubmission:
268
+ """Bind runtime waiter/callback state without exposing it publicly."""
269
+
270
+ object.__setattr__(self, "_waiter", waiter)
271
+ object.__setattr__(self, "_wait_callback", wait_callback)
272
+ object.__setattr__(self, "_resolved_result", resolved_result)
273
+ return self
274
+
275
+ @overload
276
+ def wait(
277
+ self,
278
+ *,
279
+ daemon: DaemonHandler | None = None,
280
+ asynchronous: Literal[False] = False,
281
+ break_when: Literal["all", "any"] = "all",
282
+ timeout: float | None = None,
283
+ on_timeout: Literal["raise", "return"] = "raise",
284
+ on_error: Literal["raise", "collect"] = "raise",
285
+ progress: bool = False,
286
+ progress_label: str | None = None,
287
+ ) -> BundledSolveResult: ...
288
+
289
+ @overload
290
+ def wait(
291
+ self,
292
+ *,
293
+ daemon: DaemonHandler | None = None,
294
+ asynchronous: Literal[True],
295
+ break_when: Literal["all", "any"] = "all",
296
+ timeout: float | None = None,
297
+ on_timeout: Literal["raise", "return"] = "raise",
298
+ on_error: Literal["raise", "collect"] = "raise",
299
+ progress: bool = False,
300
+ progress_label: str | None = None,
301
+ ) -> Coroutine[object, object, BundledSolveResult]: ...
302
+
303
+ def wait(
304
+ self,
305
+ *,
306
+ daemon: DaemonHandler | None = None,
307
+ asynchronous: bool = False,
308
+ break_when: Literal["all", "any"] = "all",
309
+ timeout: float | None = None,
310
+ on_timeout: Literal["raise", "return"] = "raise",
311
+ on_error: Literal["raise", "collect"] = "raise",
312
+ progress: bool = False,
313
+ progress_label: str | None = None,
314
+ ) -> BundledSolveResult | Coroutine[object, object, BundledSolveResult]:
315
+ """Wait for the one job that executes the complete ordered project bundle.
316
+
317
+ Parameters
318
+ ----------
319
+ daemon : DaemonHandler | None, optional
320
+ Daemon handler to use. If `daemon` is `None`, use the handler that
321
+ created the submission.
322
+ asynchronous : bool, optional
323
+ If `True`, return a coroutine. The caller must await the coroutine.
324
+ break_when : {"all", "any"}, optional
325
+ Use `"all"` to wait for the complete bundle. `"any"` is rejected
326
+ because individual projects are not independently waitable.
327
+ timeout : float | None, optional
328
+ Maximum wait time in seconds. `None` sets no time limit.
329
+ on_timeout : {"raise", "return"}, optional
330
+ Use `"raise"` to raise a timeout without closing or resubmitting the
331
+ job. `"return"` is rejected because a bundle is one solve unit.
332
+ on_error : {"raise", "collect"}, optional
333
+ Use `"raise"` for a failed bundle. `"collect"` is supported only on
334
+ a bundled-batch wait.
335
+ progress : bool, optional
336
+ If `True`, show progress while more than one solve is pending.
337
+ progress_label : str | None, optional
338
+ Text for the progress indicator. If omitted, the wait operation
339
+ uses its default label.
340
+
341
+ Returns
342
+ -------
343
+ BundledSolveResult | Coroutine[object, object, BundledSolveResult]
344
+ Results in ordered project bundle order. If `asynchronous` is
345
+ `True`, returns a coroutine that produces the results.
346
+
347
+ Raises
348
+ ------
349
+ TimeoutError
350
+ If the wait reaches its time limit before the bundle completes.
351
+ The daemon job remains submitted. Call `wait()` again to collect
352
+ the same bundle.
353
+ ConfigMappingError
354
+ If the daemon reports an input error with a source position. The
355
+ error identifies the source file. Its `SolveExecutionError` cause
356
+ contains the exit code and log, and daemon job metadata when available.
357
+ SolveExecutionError
358
+ If the daemon reports an execution failure without a source
359
+ position. The complete bundle fails, even if an earlier project
360
+ produced files.
361
+ InvalidConfigurationError
362
+ If a wait option is unsupported or the Submission is not bound to
363
+ its submitting daemon handler.
364
+ RuntimeError
365
+ If a synchronous wait is called from a running event loop.
366
+
367
+ Notes
368
+ -----
369
+ The complete bundle is already submitted. This method does not submit
370
+ further projects. After success, later waits return the completed
371
+ bundle. After a terminal daemon failure, later waits raise that failure.
372
+ """
373
+
374
+ if break_when != "all":
375
+ raise InvalidConfigurationError(
376
+ "BundledSolveSubmission.wait() only supports `break_when='all'`."
377
+ )
378
+ if on_error != "raise":
379
+ raise InvalidConfigurationError(
380
+ "BundledSolveSubmission.wait() only supports `on_error='raise'`."
381
+ )
382
+ if on_timeout != "raise":
383
+ raise InvalidConfigurationError(
384
+ "BundledSolveSubmission.wait() only supports `on_timeout='raise'`."
385
+ )
386
+ if timeout is not None and timeout < 0.0:
387
+ raise InvalidConfigurationError("timeout must be non-negative.")
388
+ if (
389
+ daemon is not None
390
+ and self._waiter is not None
391
+ and daemon is not self._waiter
392
+ ):
393
+ raise InvalidConfigurationError(
394
+ "Bundle wait must use its submitting daemon handler."
395
+ )
396
+ resolved_result: BundledSolveResult | None = self._resolved_result
397
+ if resolved_result is not None:
398
+ if asynchronous:
399
+
400
+ async def _return_resolved_result() -> BundledSolveResult:
401
+ return resolved_result
402
+
403
+ return _return_resolved_result()
404
+ return resolved_result
405
+
406
+ wait_callback = self._wait_callback
407
+ waiter: DaemonHandler | None = daemon if daemon is not None else self._waiter
408
+ if wait_callback is None or waiter is None:
409
+ raise InvalidConfigurationError(
410
+ "BundledSolveSubmission is not bound to a daemon handler. Pass "
411
+ "`daemon=` explicitly or create the submission via "
412
+ "`jcmsuite.solve(..., dispatch='submit')`."
413
+ )
414
+
415
+ async def _run_wait() -> BundledSolveResult:
416
+ try:
417
+ collected: BundledSolveResult = await wait_callback(
418
+ bundle_submission=self,
419
+ daemon=waiter,
420
+ break_when=break_when,
421
+ timeout=timeout,
422
+ on_timeout=on_timeout,
423
+ on_error=on_error,
424
+ progress=progress,
425
+ progress_label=progress_label,
426
+ )
427
+ except (ConfigMappingError, SolveExecutionError) as error:
428
+ object.__setattr__(self, "_failure", error)
429
+ raise
430
+ object.__setattr__(self, "_resolved_result", collected)
431
+ return collected
432
+
433
+ async def _collect_bundle() -> BundledSolveResult:
434
+ if self._resolved_result is not None:
435
+ return self._resolved_result
436
+ task: asyncio.Task[BundledSolveResult] | None = self._wait_task
437
+ try:
438
+ if self._failure is not None:
439
+ raise self._failure
440
+ if task is None or task.cancelled():
441
+ task = asyncio.create_task(_run_wait())
442
+ object.__setattr__(self, "_wait_task", task)
443
+ # Every batch slice references this same handle. Share collection
444
+ # even when callers start their waits concurrently.
445
+ return await asyncio.shield(task)
446
+ except (ConfigMappingError, SolveExecutionError) as error:
447
+ cause: BaseException | None = (
448
+ error.__cause__
449
+ if isinstance(error.__cause__, SolveExecutionError)
450
+ else None
451
+ )
452
+ raise trim_exception_traceback(error) from cause
453
+ finally:
454
+ if task is not None and task.done() and self._wait_task is task:
455
+ object.__setattr__(self, "_wait_task", None)
456
+
457
+ if asynchronous:
458
+ return _collect_bundle()
459
+ try:
460
+ asyncio.get_running_loop()
461
+ except RuntimeError:
462
+ try:
463
+ return asyncio.run(_collect_bundle())
464
+ except (ConfigMappingError, SolveExecutionError) as error:
465
+ cause: BaseException | None = (
466
+ error.__cause__
467
+ if isinstance(error.__cause__, SolveExecutionError)
468
+ else None
469
+ )
470
+ raise trim_exception_traceback(error) from cause
471
+ raise RuntimeError(
472
+ "BundledSolveSubmission.wait() called from a running event loop; use "
473
+ "`await submission.wait(..., asynchronous=True)`."
474
+ )
475
+
476
+
477
+ @dataclass(slots=True, frozen=True)
478
+ class BundledBatchSolveSubmissionEntry:
479
+ """Store one submitted ordered project bundle in a batch.
480
+
481
+ Parameters
482
+ ----------
483
+ index : int
484
+ Position in the original batched project keys.
485
+ keys : dict[str, object]
486
+ project keys for this batch entry.
487
+ result : BundledSolveSubmission | None
488
+ submission for an ordered project bundle, if submission succeeded.
489
+ failure : BatchSolveFailure | None
490
+ Failure information if submission did not succeed.
491
+ project_files : tuple[Path, ...], optional
492
+ project files in ordered project bundle order.
493
+ """
494
+
495
+ index: int
496
+ keys: dict[str, object]
497
+ result: BundledSolveSubmission | None
498
+ failure: BatchSolveFailure | None
499
+ project_files: tuple[Path, ...] = ()
500
+
501
+
502
+ @dataclass(slots=True, frozen=True)
503
+ class BundledBatchSolveSubmission(Sequence[BundledSolveSubmission]):
504
+ """Represent a batch of submitted ordered project bundles.
505
+
506
+ Parameters
507
+ ----------
508
+ entries : tuple[BundledBatchSolveSubmissionEntry, ...]
509
+ Ordered project bundle submissions in batched project keys order.
510
+
511
+ Notes
512
+ -----
513
+ `submission[index]` returns one successful ordered project bundle
514
+ submission. A slice returns a new `BundledBatchSolveSubmission`. Iteration
515
+ yields successful bundle submissions in batched project keys order and
516
+ raises an error if an entry contains a collected failure.
517
+ Call `submission[index].wait()` to collect one complete bundle. Call
518
+ `submission[start:stop].wait()` to collect a subset. Slices retain the
519
+ original batch indices. Results use the project-first navigation of
520
+ `BundledBatchSolveResult`.
521
+ """
522
+
523
+ entries: tuple[BundledBatchSolveSubmissionEntry, ...]
524
+ _waiter: DaemonHandler | None = field(
525
+ default=None,
526
+ repr=False,
527
+ compare=False,
528
+ init=False,
529
+ )
530
+ _wait_callback: (
531
+ Callable[..., Coroutine[object, object, BundledBatchSolveResult]] | None
532
+ ) = field(
533
+ default=None,
534
+ repr=False,
535
+ compare=False,
536
+ init=False,
537
+ )
538
+
539
+ def _bind_runtime(
540
+ self,
541
+ *,
542
+ waiter: DaemonHandler | None,
543
+ wait_callback: (
544
+ Callable[..., Coroutine[object, object, BundledBatchSolveResult]] | None
545
+ ) = None,
546
+ ) -> BundledBatchSolveSubmission:
547
+ """Bind runtime waiter/callback state without exposing it publicly."""
548
+
549
+ object.__setattr__(self, "_waiter", waiter)
550
+ object.__setattr__(self, "_wait_callback", wait_callback)
551
+ return self
552
+
553
+ def __len__(self) -> int:
554
+ """Return the number of batch entries.
555
+
556
+ Returns
557
+ -------
558
+ int
559
+ Number of ordered project bundle submission entries.
560
+ """
561
+
562
+ return len(self.entries)
563
+
564
+ def __iter__(self) -> Iterator[BundledSolveSubmission]:
565
+ """Iterate over successful bundle submissions in batch order.
566
+
567
+ Returns
568
+ -------
569
+ Iterator[BundledSolveSubmission]
570
+ Iterator over successful ordered project bundle submissions.
571
+
572
+ Raises
573
+ ------
574
+ TypeError
575
+ If an entry contains a collected submission failure.
576
+ """
577
+
578
+ entry: BundledBatchSolveSubmissionEntry
579
+ for entry in self.entries:
580
+ if entry.result is None:
581
+ raise TypeError(
582
+ "BundledBatchSolveSubmission iteration requires successful "
583
+ "bundle entries only; inspect `.entries` for collected failures."
584
+ )
585
+ yield entry.result
586
+
587
+ @overload
588
+ def __getitem__(self, index: int) -> BundledSolveSubmission: ...
589
+
590
+ @overload
591
+ def __getitem__(self, index: slice) -> BundledBatchSolveSubmission: ...
592
+
593
+ def __getitem__(
594
+ self,
595
+ index: int | slice,
596
+ ) -> BundledSolveSubmission | BundledBatchSolveSubmission:
597
+ """Return one bundle submission or a sliced batch.
598
+
599
+ Parameters
600
+ ----------
601
+ index : int | slice
602
+ Batch position or standard Python slice. Negative positions count
603
+ from the end of the batch.
604
+
605
+ Returns
606
+ -------
607
+ BundledSolveSubmission | BundledBatchSolveSubmission
608
+ One successful bundle submission for an integer position, or a new
609
+ batch submission for a slice.
610
+
611
+ Raises
612
+ ------
613
+ TypeError
614
+ If the selected entry contains a collected submission failure.
615
+ IndexError
616
+ If an integer position is outside the batch.
617
+ """
618
+
619
+ if isinstance(index, slice):
620
+ return BundledBatchSolveSubmission(
621
+ entries=self.entries[index]
622
+ )._bind_runtime(
623
+ waiter=self._waiter,
624
+ wait_callback=self._wait_callback,
625
+ )
626
+ result: BundledSolveSubmission | None = self.entries[index].result
627
+ if result is None:
628
+ raise TypeError(
629
+ "Selected batch solve bundle submission does not contain a "
630
+ "result; inspect `.entries[index].failure`."
631
+ )
632
+ return result
633
+
634
+ @property
635
+ def keys(self) -> tuple[dict[str, object], ...]:
636
+ """Return the project keys in their original batch order.
637
+
638
+ Returns
639
+ -------
640
+ tuple[dict[str, object], ...]
641
+ project keys for each batch entry.
642
+ """
643
+
644
+ return tuple(entry.keys for entry in self.entries)
645
+
646
+ @property
647
+ def results(self) -> tuple[BundledSolveSubmission | None, ...]:
648
+ """Return the bundle submissions in batched project keys order.
649
+
650
+ A value is `None` if submission did not succeed for that batch entry.
651
+
652
+ Returns
653
+ -------
654
+ tuple[BundledSolveSubmission | None, ...]
655
+ Bundle submissions in batched project keys order.
656
+ """
657
+
658
+ return tuple(entry.result for entry in self.entries)
659
+
660
+ @property
661
+ def failures(self) -> tuple[BatchSolveFailure, ...]:
662
+ """Return collected failures in batched project keys order.
663
+
664
+ Returns
665
+ -------
666
+ tuple[BatchSolveFailure, ...]
667
+ Failures collected during submission.
668
+ """
669
+
670
+ return tuple(
671
+ failure
672
+ for failure in (entry.failure for entry in self.entries)
673
+ if failure is not None
674
+ )
675
+
676
+ def items(self) -> tuple[tuple[int, BundledBatchSolveSubmissionEntry], ...]:
677
+ """Return each original batch position with its submission entry.
678
+
679
+ Returns
680
+ -------
681
+ tuple[tuple[int, BundledBatchSolveSubmissionEntry], ...]
682
+ Pairs in batched project keys order.
683
+ """
684
+
685
+ return tuple((entry.index, entry) for entry in self.entries)
686
+
687
+ @overload
688
+ def wait(
689
+ self,
690
+ *,
691
+ daemon: DaemonHandler | None = None,
692
+ asynchronous: Literal[False] = False,
693
+ break_when: Literal["all", "any"] = "all",
694
+ timeout: float | None = None,
695
+ on_timeout: Literal["raise", "return"] = "raise",
696
+ on_error: Literal["raise", "collect"] = "raise",
697
+ progress: bool = False,
698
+ progress_label: str | None = None,
699
+ ) -> BundledBatchSolveResult: ...
700
+
701
+ @overload
702
+ def wait(
703
+ self,
704
+ *,
705
+ daemon: DaemonHandler | None = None,
706
+ asynchronous: Literal[True],
707
+ break_when: Literal["all", "any"] = "all",
708
+ timeout: float | None = None,
709
+ on_timeout: Literal["raise", "return"] = "raise",
710
+ on_error: Literal["raise", "collect"] = "raise",
711
+ progress: bool = False,
712
+ progress_label: str | None = None,
713
+ ) -> Coroutine[object, object, BundledBatchSolveResult]: ...
714
+
715
+ def wait(
716
+ self,
717
+ *,
718
+ daemon: DaemonHandler | None = None,
719
+ asynchronous: bool = False,
720
+ break_when: Literal["all", "any"] = "all",
721
+ timeout: float | None = None,
722
+ on_timeout: Literal["raise", "return"] = "raise",
723
+ on_error: Literal["raise", "collect"] = "raise",
724
+ progress: bool = False,
725
+ progress_label: str | None = None,
726
+ ) -> BundledBatchSolveResult | Coroutine[object, object, BundledBatchSolveResult]:
727
+ """Wait for the submitted batch of ordered project bundles.
728
+
729
+ Parameters
730
+ ----------
731
+ daemon : DaemonHandler | None, optional
732
+ Daemon handler to use. If `daemon` is `None`, use the handler that
733
+ created the submission.
734
+ asynchronous : bool, optional
735
+ If `True`, return a coroutine. The caller must await the coroutine.
736
+ break_when : {"all", "any"}, optional
737
+ Use `"all"` to wait for all selected bundles. `"any"` is rejected.
738
+ Select one bundle or a slice before waiting for a subset.
739
+ timeout : float | None, optional
740
+ Maximum wait time in seconds. `None` sets no time limit.
741
+ on_timeout : {"raise", "return"}, optional
742
+ Use `"raise"` to raise a timeout. `"return"` is rejected.
743
+ on_error : {"raise", "collect"}, optional
744
+ Action when a solve fails. `"raise"` raises an exception.
745
+ `"collect"` stores the failure information in the result.
746
+ progress : bool, optional
747
+ If `True`, show progress while more than one solve is pending.
748
+ progress_label : str | None, optional
749
+ Text for the progress indicator. If omitted, the wait operation
750
+ uses its default label.
751
+
752
+ Returns
753
+ -------
754
+ BundledBatchSolveResult | Coroutine[object, object, BundledBatchSolveResult]
755
+ Results for the batched ordered project bundles. If `asynchronous`
756
+ is `True`, returns a coroutine that produces the results.
757
+ """
758
+
759
+ wait_callback = self._wait_callback
760
+ waiter: DaemonHandler | None = daemon if daemon is not None else self._waiter
761
+ if wait_callback is None or waiter is None:
762
+ raise InvalidConfigurationError(
763
+ "BundledBatchSolveSubmission is not bound to a daemon handler. "
764
+ "Pass `daemon=` explicitly or create the submission via "
765
+ "`jcmsuite.solve(..., dispatch='submit')`."
766
+ )
767
+ wait_coro = wait_callback(
768
+ batch_submission=self,
769
+ daemon=waiter,
770
+ break_when=break_when,
771
+ timeout=timeout,
772
+ on_timeout=on_timeout,
773
+ on_error=on_error,
774
+ progress=progress,
775
+ progress_label=progress_label,
776
+ )
777
+ if asynchronous:
778
+
779
+ async def _wait_asynchronously() -> BundledBatchSolveResult:
780
+ try:
781
+ return await wait_coro
782
+ except (ConfigMappingError, SolveExecutionError) as error:
783
+ cause: BaseException | None = (
784
+ error.__cause__
785
+ if isinstance(error.__cause__, SolveExecutionError)
786
+ else None
787
+ )
788
+ raise trim_exception_traceback(error) from cause
789
+
790
+ return _wait_asynchronously()
791
+ try:
792
+ asyncio.get_running_loop()
793
+ except RuntimeError:
794
+ try:
795
+ return asyncio.run(wait_coro)
796
+ except (ConfigMappingError, SolveExecutionError) as error:
797
+ cause: BaseException | None = (
798
+ error.__cause__
799
+ if isinstance(error.__cause__, SolveExecutionError)
800
+ else None
801
+ )
802
+ raise trim_exception_traceback(error) from cause
803
+ raise RuntimeError(
804
+ "BundledBatchSolveSubmission.wait() called from a running event loop; "
805
+ "use `await submission.wait(..., asynchronous=True)`."
806
+ )
807
+
808
+
809
+ @dataclass(slots=True, frozen=True)
810
+ class BatchSolveSubmission(Sequence[SolveSubmission]):
811
+ """Represent batched project keys submitted to the daemon.
812
+
813
+ Parameters
814
+ ----------
815
+ entries : tuple[SolveSubmission, ...]
816
+ submissions in batched project keys order.
817
+
818
+ Notes
819
+ -----
820
+ You can select an entry by position or select a range with a slice. A slice
821
+ returns another `BatchSolveSubmission`.
822
+ """
823
+
824
+ entries: tuple[SolveSubmission, ...]
825
+ _resolved_result: BatchSolveResult | None = field(
826
+ default=None,
827
+ repr=False,
828
+ compare=False,
829
+ init=False,
830
+ )
831
+ _waiter: DaemonHandler | None = field(
832
+ default=None,
833
+ repr=False,
834
+ compare=False,
835
+ init=False,
836
+ )
837
+
838
+ def _bind_runtime(
839
+ self,
840
+ *,
841
+ waiter: DaemonHandler | None,
842
+ resolved_result: BatchSolveResult | None = None,
843
+ ) -> BatchSolveSubmission:
844
+ """Bind internal waiter handle without exposing constructor internals.
845
+
846
+ Notes
847
+ -----
848
+ Internal API: this helper mutates frozen runtime-only fields to keep
849
+ constructor signatures clean in user-facing docs.
850
+ """
851
+
852
+ object.__setattr__(self, "_waiter", waiter)
853
+ object.__setattr__(self, "_resolved_result", resolved_result)
854
+ return self
855
+
856
+ def __len__(self) -> int:
857
+ """Return the number of submission entries.
858
+
859
+ Returns
860
+ -------
861
+ int
862
+ Number of entries in the submitted batch.
863
+ """
864
+
865
+ return len(self.entries)
866
+
867
+ def __iter__(self) -> Iterator[SolveSubmission]:
868
+ """Iterate over submissions in batched project keys order.
869
+
870
+ Returns
871
+ -------
872
+ Iterator[SolveSubmission]
873
+ Iterator over the submission entries.
874
+ """
875
+
876
+ return iter(self.entries)
877
+
878
+ @overload
879
+ def __getitem__(self, index: int) -> SolveSubmission:
880
+ """Return single submission entry by integer index.
881
+
882
+ Parameters
883
+ ----------
884
+ index : int
885
+ Entry position.
886
+
887
+ Returns
888
+ -------
889
+ SolveSubmission
890
+ submission handle at ``index``.
891
+
892
+ Notes
893
+ -----
894
+ Internal API: overload declaration for typing and may change without
895
+ notice.
896
+ """
897
+
898
+ ...
899
+
900
+ @overload
901
+ def __getitem__(self, index: slice) -> BatchSolveSubmission:
902
+ """Return a sliced submission view.
903
+
904
+ Parameters
905
+ ----------
906
+ index : slice
907
+ Slice specification.
908
+
909
+ Returns
910
+ -------
911
+ BatchSolveSubmission
912
+ Sliced submission wrapper.
913
+
914
+ Notes
915
+ -----
916
+ Internal API: overload declaration for typing and may change without
917
+ notice.
918
+ """
919
+
920
+ ...
921
+
922
+ def __getitem__(self, index: int | slice) -> SolveSubmission | BatchSolveSubmission:
923
+ """Return one submission or a sliced batch submission.
924
+
925
+ Parameters
926
+ ----------
927
+ index : int | slice
928
+ Batch position or standard Python slice. Negative positions count
929
+ from the end of the batch.
930
+
931
+ Returns
932
+ -------
933
+ SolveSubmission | BatchSolveSubmission
934
+ One submission for an integer position, or a new batch submission
935
+ for a slice.
936
+
937
+ Raises
938
+ ------
939
+ IndexError
940
+ If an integer position is outside the batch.
941
+ """
942
+
943
+ if isinstance(index, slice):
944
+ sliced_submission: BatchSolveSubmission = BatchSolveSubmission(
945
+ entries=self.entries[index]
946
+ )
947
+ sliced_resolved_result: BatchSolveResult | None = self._resolved_result
948
+ if sliced_resolved_result is not None:
949
+ selected_indices: set[int] = {
950
+ entry.index
951
+ for entry in sliced_submission.entries
952
+ if entry.index is not None
953
+ }
954
+ sliced_resolved_result = BatchSolveResult(
955
+ entries=tuple(
956
+ entry
957
+ for entry in sliced_resolved_result.entries
958
+ if entry.index in selected_indices
959
+ )
960
+ )
961
+ return sliced_submission._bind_runtime(
962
+ waiter=self._waiter,
963
+ resolved_result=sliced_resolved_result,
964
+ )
965
+ return self.entries[index]
966
+
967
+ def job_ids(self) -> tuple[int, ...]:
968
+ """Return daemon submission identifiers in batched project keys order.
969
+
970
+ Returns
971
+ -------
972
+ tuple[int, ...]
973
+ Daemon submission identifiers for the submitted solves.
974
+ """
975
+
976
+ return tuple(entry.job_id for entry in self.entries)
977
+
978
+ @property
979
+ def successes(self) -> tuple[SolveResult, ...]:
980
+ """Return results that are already available on the submissions.
981
+
982
+ Returns
983
+ -------
984
+ tuple[SolveResult, ...]
985
+ Available result information in batched project keys order.
986
+ """
987
+
988
+ return tuple(entry.result for entry in self.entries)
989
+
990
+ @property
991
+ def failures(self) -> tuple[BatchSolveFailure, ...]:
992
+ """Return no failures before `wait(...)` creates the batch result.
993
+
994
+ Returns
995
+ -------
996
+ tuple[BatchSolveFailure, ...]
997
+ Empty tuple. Read failures from the `BatchSolveResult` returned by
998
+ `wait(...)`.
999
+ """
1000
+
1001
+ return ()
1002
+
1003
+ @overload
1004
+ def wait(
1005
+ self,
1006
+ *,
1007
+ daemon: DaemonHandler | None = None,
1008
+ asynchronous: Literal[False] = False,
1009
+ break_when: Literal["all", "any"] = "all",
1010
+ timeout: float | None = None,
1011
+ on_timeout: Literal["raise", "return"] = "raise",
1012
+ on_error: Literal["raise", "collect"] = "raise",
1013
+ progress: bool = False,
1014
+ progress_label: str | None = None,
1015
+ ) -> BatchSolveResult: ...
1016
+
1017
+ @overload
1018
+ def wait(
1019
+ self,
1020
+ *,
1021
+ daemon: DaemonHandler | None = None,
1022
+ asynchronous: Literal[True],
1023
+ break_when: Literal["all", "any"] = "all",
1024
+ timeout: float | None = None,
1025
+ on_timeout: Literal["raise", "return"] = "raise",
1026
+ on_error: Literal["raise", "collect"] = "raise",
1027
+ progress: bool = False,
1028
+ progress_label: str | None = None,
1029
+ ) -> Coroutine[object, object, BatchSolveResult]: ...
1030
+
1031
+ def wait(
1032
+ self,
1033
+ *,
1034
+ daemon: DaemonHandler | None = None,
1035
+ asynchronous: bool = False,
1036
+ break_when: Literal["all", "any"] = "all",
1037
+ timeout: float | None = None,
1038
+ on_timeout: Literal["raise", "return"] = "raise",
1039
+ on_error: Literal["raise", "collect"] = "raise",
1040
+ progress: bool = False,
1041
+ progress_label: str | None = None,
1042
+ ) -> BatchSolveResult | Coroutine[object, object, BatchSolveResult]:
1043
+ """Wait for the submitted batched project keys.
1044
+
1045
+ Parameters
1046
+ ----------
1047
+ daemon : DaemonHandler | None, optional
1048
+ Daemon handler to use. If `daemon` is `None`, use the handler that
1049
+ created the submission.
1050
+ asynchronous : bool, optional
1051
+ If `True`, return a coroutine. The caller must await the coroutine.
1052
+ break_when : {"all", "any"}, optional
1053
+ Completion condition. `"all"` waits for all submitted solves.
1054
+ `"any"` returns after the first submitted solve completes.
1055
+ timeout : float | None, optional
1056
+ Maximum wait time in seconds. `None` sets no time limit.
1057
+ on_timeout : {"raise", "return"}, optional
1058
+ Action at the time limit. `"raise"` raises an exception.
1059
+ `"return"` returns the results that are available.
1060
+ on_error : {"raise", "collect"}, optional
1061
+ Action when a solve fails. `"raise"` raises an exception.
1062
+ `"collect"` stores the failure information in the result.
1063
+ progress : bool, optional
1064
+ If `True`, show progress while more than one solve is pending.
1065
+ progress_label : str | None, optional
1066
+ Text for the progress indicator. If omitted, the wait operation
1067
+ uses its default label.
1068
+
1069
+ Returns
1070
+ -------
1071
+ BatchSolveResult | Coroutine[object, object, BatchSolveResult]
1072
+ Results in batched project keys order. If `asynchronous` is `True`,
1073
+ returns a coroutine that produces the results.
1074
+ """
1075
+
1076
+ waiter: DaemonHandler | None = daemon if daemon is not None else self._waiter
1077
+ resolved_result: BatchSolveResult | None = self._resolved_result
1078
+ if waiter is None and resolved_result is None:
1079
+ raise InvalidConfigurationError(
1080
+ "BatchSolveSubmission is not bound to a daemon handler. Pass "
1081
+ "`daemon=` explicitly or create the submission via "
1082
+ "`jcmsuite.solve(..., dispatch='submit')`."
1083
+ )
1084
+ resolved_waiter: DaemonHandler | None = waiter
1085
+ if resolved_result is not None and len(self.entries) == 0:
1086
+ if asynchronous:
1087
+
1088
+ async def _return_resolved_result() -> BatchSolveResult:
1089
+ return resolved_result
1090
+
1091
+ return _return_resolved_result()
1092
+ return resolved_result
1093
+
1094
+ async def _wait_and_merge() -> BatchSolveResult:
1095
+ if waiter is None:
1096
+ raise InvalidConfigurationError(
1097
+ "BatchSolveSubmission is not bound to a daemon handler. Pass "
1098
+ "`daemon=` explicitly or create the submission via "
1099
+ "`jcmsuite.solve(..., dispatch='submit')`."
1100
+ )
1101
+ resolved_waiter: DaemonHandler = waiter
1102
+ live_submission: BatchSolveSubmission = BatchSolveSubmission(
1103
+ entries=self.entries
1104
+ )._bind_runtime(waiter=resolved_waiter)
1105
+ waited_result: BatchSolveResult = await resolved_waiter.wait(
1106
+ live_submission,
1107
+ asynchronous=True,
1108
+ break_when=break_when,
1109
+ timeout=timeout,
1110
+ on_timeout=on_timeout,
1111
+ on_error=on_error,
1112
+ progress=progress,
1113
+ progress_label=progress_label,
1114
+ )
1115
+ if resolved_result is None:
1116
+ return waited_result
1117
+ merged_entries: list[BatchSolveEntry] = [
1118
+ *resolved_result.entries,
1119
+ *waited_result.entries,
1120
+ ]
1121
+ merged_entries.sort(key=lambda entry: entry.index)
1122
+ return BatchSolveResult(entries=tuple(merged_entries))
1123
+
1124
+ if resolved_result is not None:
1125
+ if asynchronous:
1126
+ return _wait_and_merge()
1127
+ try:
1128
+ asyncio.get_running_loop()
1129
+ except RuntimeError:
1130
+ return asyncio.run(_wait_and_merge())
1131
+ raise RuntimeError(
1132
+ "BatchSolveSubmission.wait() called from a running event loop; "
1133
+ "use `await submission.wait(..., asynchronous=True)`."
1134
+ )
1135
+ if asynchronous:
1136
+ assert resolved_waiter is not None
1137
+ return resolved_waiter.wait(
1138
+ self,
1139
+ asynchronous=True,
1140
+ break_when=break_when,
1141
+ timeout=timeout,
1142
+ on_timeout=on_timeout,
1143
+ on_error=on_error,
1144
+ progress=progress,
1145
+ progress_label=progress_label,
1146
+ )
1147
+ assert resolved_waiter is not None
1148
+ return resolved_waiter.wait(
1149
+ self,
1150
+ asynchronous=False,
1151
+ break_when=break_when,
1152
+ timeout=timeout,
1153
+ on_timeout=on_timeout,
1154
+ on_error=on_error,
1155
+ progress=progress,
1156
+ progress_label=progress_label,
1157
+ )