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,172 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2001-2026 JCMwave GmbH
3
+
4
+ """Subprocess execution helpers for runtime context startup probes."""
5
+
6
+ from __future__ import annotations
7
+
8
+ import asyncio
9
+ import shlex
10
+ import subprocess
11
+ import sys
12
+ from collections.abc import Callable, Mapping, Sequence
13
+ from logging import Logger
14
+ from pathlib import Path
15
+ from typing import TextIO
16
+
17
+ from ..logging import TRACE, get_logger
18
+
19
+ _logger: Logger = get_logger(__name__)
20
+
21
+
22
+ def _spawn_detached_binary(
23
+ binary_path: Path,
24
+ args: Sequence[str] | None = None,
25
+ *,
26
+ popen_factory: Callable[..., object] | None = None,
27
+ ) -> None:
28
+ """Spawn a detached child process and return immediately.
29
+
30
+ Parameters
31
+ ----------
32
+ binary_path : Path
33
+ Absolute path to the executable.
34
+ args : Sequence[str] | None, optional
35
+ Positional argument sequence passed to the executable.
36
+ popen_factory : Callable[..., object] | None, optional
37
+ Optional subprocess launcher override used by tests to intercept process
38
+ creation while preserving detached-launch semantics.
39
+
40
+ Returns
41
+ -------
42
+ None
43
+ Launches a detached child process.
44
+
45
+ Notes
46
+ -----
47
+ Internal API: this helper is an implementation detail and may change
48
+ without notice.
49
+ """
50
+
51
+ command: list[str] = [str(binary_path)]
52
+ if args is not None:
53
+ command.extend(str(entry) for entry in args)
54
+
55
+ _logger.log(TRACE, "Spawning detached command: %s", command)
56
+ launcher: Callable[..., object] = (
57
+ subprocess.Popen if popen_factory is None else popen_factory
58
+ )
59
+ _ = launcher(
60
+ command,
61
+ stdout=subprocess.DEVNULL,
62
+ stderr=subprocess.DEVNULL,
63
+ close_fds=True,
64
+ start_new_session=True,
65
+ )
66
+
67
+
68
+ async def _call_binary(
69
+ binary_path: Path,
70
+ args: list[str] | str | None = None,
71
+ cwd: Path | None = None,
72
+ stream_output: bool = False,
73
+ env: Mapping[str, str] | None = None,
74
+ ) -> tuple[str, str, int | None]:
75
+ """Call a binary command asynchronously and return decoded output.
76
+
77
+ Parameters
78
+ ----------
79
+ binary_path : Path
80
+ Absolute path to the binary executable.
81
+ args : list[str] | str | None, optional
82
+ Argument payload passed to the executable. A list is expanded into
83
+ positional arguments; a string is passed as a single argument.
84
+ cwd : Path | None, optional
85
+ Optional working directory used for process execution.
86
+ stream_output : bool, optional
87
+ If ``True``, forward subprocess stdout/stderr chunks to the current
88
+ process stdout/stderr while still capturing them for the return value.
89
+ env : Mapping[str, str] | None, optional
90
+ Optional environment mapping for the child process.
91
+
92
+ Returns
93
+ -------
94
+ tuple[str, str, int | None]
95
+ ``(stdout_text, stderr_text, return_code)``.
96
+ """
97
+
98
+ cmd_components: list[str] = [str(binary_path)]
99
+ if isinstance(args, list):
100
+ cmd_components.extend(list(args))
101
+ elif isinstance(args, str):
102
+ cmd_components.append(args)
103
+ command: str
104
+ if binary_path.suffix == ".exe":
105
+ command = subprocess.list2cmdline(cmd_components)
106
+ else:
107
+ command = " ".join(shlex.quote(component) for component in cmd_components)
108
+
109
+ _logger.log(TRACE, "Running command: %s", command)
110
+
111
+ process: asyncio.subprocess.Process = await asyncio.create_subprocess_shell(
112
+ command,
113
+ stdout=asyncio.subprocess.PIPE,
114
+ stderr=asyncio.subprocess.PIPE,
115
+ cwd=None if cwd is None else str(cwd),
116
+ close_fds=True,
117
+ env=None if env is None else dict(env),
118
+ )
119
+ if stream_output:
120
+ # Register the process waiter immediately and await it in parallel with
121
+ # stream readers. This avoids a Python 3.13 subprocess edge case where
122
+ # `await process.wait()` can stall when attached only after streams
123
+ # were fully drained.
124
+ wait_task: asyncio.Task[int] = asyncio.create_task(process.wait())
125
+ stdout_text: str
126
+ stderr_text: str
127
+ stdout_text, stderr_text = await asyncio.gather(
128
+ _read_stream(
129
+ process.stdout,
130
+ stream_to=sys.stdout,
131
+ forward_output=True,
132
+ ),
133
+ _read_stream(
134
+ process.stderr,
135
+ stream_to=sys.stderr,
136
+ forward_output=True,
137
+ ),
138
+ )
139
+ return_code_streaming: int | None = await wait_task
140
+ return stdout_text, stderr_text, return_code_streaming
141
+
142
+ stdout_data: bytes
143
+ stderr_data: bytes
144
+ return_code: int | None
145
+ stdout_data, stderr_data = await process.communicate()
146
+ return_code = process.returncode
147
+ return stdout_data.decode("utf-8"), stderr_data.decode("utf-8"), return_code
148
+
149
+
150
+ async def _read_stream(
151
+ stream: asyncio.StreamReader | None,
152
+ *,
153
+ stream_to: TextIO,
154
+ forward_output: bool,
155
+ ) -> str:
156
+ """Read one subprocess stream fully and optionally forward chunks."""
157
+
158
+ if stream is None:
159
+ return ""
160
+
161
+ chunks: list[str] = []
162
+ raw_chunk: bytes
163
+ while True:
164
+ raw_chunk = await stream.read(4096)
165
+ if raw_chunk == b"":
166
+ break
167
+ decoded_chunk: str = raw_chunk.decode("utf-8", errors="replace")
168
+ chunks.append(decoded_chunk)
169
+ if forward_output:
170
+ stream_to.write(decoded_chunk)
171
+ stream_to.flush()
172
+ return "".join(chunks)
jcmsuite/contract.py ADDED
@@ -0,0 +1,47 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2001-2026 JCMwave GmbH
3
+
4
+ """Public API export contract for `jcmsuite`.
5
+
6
+ This module separates:
7
+
8
+ 1. first-class top-level exports from ``jcmsuite.__init__``, and
9
+ 2. namespaced APIs intentionally kept off the top-level for a cleaner surface.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from typing import Final
15
+
16
+ # Keep this mapping ordered: insertion order defines the canonical first-class
17
+ # export order for ``jcmsuite.__all__``.
18
+ PUBLIC_API_MODULE_MAP: Final[dict[str, str]] = {
19
+ "info": "jcmsuite.info",
20
+ "solve": "jcmsuite.solve",
21
+ "geo": "jcmsuite.geo",
22
+ "view": "jcmsuite.view",
23
+ }
24
+
25
+ PUBLIC_API_EXPORTS: Final[tuple[str, ...]] = tuple(PUBLIC_API_MODULE_MAP)
26
+
27
+ NAMESPACED_API_MODULE_MAP: Final[dict[str, str]] = {
28
+ "context.create_context": "jcmsuite.context",
29
+ "context.get_default_context": "jcmsuite.context",
30
+ "context.set_default_context": "jcmsuite.context",
31
+ "context.reset_default_context": "jcmsuite.context",
32
+ "editing.edit": "jcmsuite.editing",
33
+ "templates.jcmt2jcm": "jcmsuite.templates",
34
+ "daemon.handler": "jcmsuite.daemon",
35
+ "results.Resultbag": "jcmsuite.results",
36
+ "results.open": "jcmsuite.results",
37
+ "results.SolveResult.load_table": "jcmsuite.results",
38
+ "results.SolveResult.load_cartesian_fields": "jcmsuite.results",
39
+ "results.Eigenvalues.to_xarray": "jcmsuite.results",
40
+ "results.ComputationalCostsHeader.to_df": "jcmsuite.results",
41
+ "results.ComputationalCostsHeader.to_xarray": "jcmsuite.results",
42
+ "results.PostprocessRecord.to_powerflux": "jcmsuite.results",
43
+ "results.PostprocessRecord.to_xarray": "jcmsuite.results",
44
+ "torch.solve": "jcmsuite.torch",
45
+ "torch.RealDerivative": "jcmsuite.torch",
46
+ "torch.ComplexDerivative": "jcmsuite.torch",
47
+ }
@@ -0,0 +1,19 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2001-2026 JCMwave GmbH
3
+
4
+ """Public daemon namespace for `jcmsuite`."""
5
+
6
+ from __future__ import annotations
7
+
8
+ from .handler import DaemonHandler, handler
9
+ from .models import Cluster, ClusterNode, Queue, SlurmNodes, Workstation
10
+
11
+ __all__: list[str] = [
12
+ "DaemonHandler",
13
+ "Cluster",
14
+ "ClusterNode",
15
+ "Queue",
16
+ "SlurmNodes",
17
+ "Workstation",
18
+ "handler",
19
+ ]