drbx 2.0.0.dev0__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.
- drbx/__init__.py +20 -0
- drbx/__main__.py +5 -0
- drbx/cli.py +586 -0
- drbx/config/__init__.py +20 -0
- drbx/config/boutinp.py +556 -0
- drbx/config/model.py +34 -0
- drbx/config/normalization.py +66 -0
- drbx/data/atomic_rates/__init__.py +1 -0
- drbx/data/atomic_rates/iz_AMJUEL_H.x_2.1.5.json +213 -0
- drbx/data/atomic_rates/iz_AMJUEL_H.x_2.3.9a.json +213 -0
- drbx/data/atomic_rates/rec_AMJUEL_H.x_2.1.8.json +213 -0
- drbx/data/atomic_rates/rec_AMJUEL_H.x_2.3.13a.json +213 -0
- drbx/geometry/__init__.py +207 -0
- drbx/geometry/embedding.py +56 -0
- drbx/geometry/essos_import.py +1385 -0
- drbx/geometry/fci_geometry.py +4622 -0
- drbx/geometry/fci_maps.py +85 -0
- drbx/geometry/island_divertor.py +291 -0
- drbx/geometry/metric_tensor.py +99 -0
- drbx/geometry/open_slab.py +150 -0
- drbx/geometry/rotating_ellipse.py +253 -0
- drbx/geometry/shifted_torus.py +225 -0
- drbx/geometry/stellarator.py +287 -0
- drbx/geometry/vmec_extender_import.py +499 -0
- drbx/geometry/vmec_jax_import.py +306 -0
- drbx/linear/__init__.py +37 -0
- drbx/linear/dispersion.py +138 -0
- drbx/linear/eigen.py +91 -0
- drbx/native/__init__.py +224 -0
- drbx/native/array_backend.py +64 -0
- drbx/native/deck_runner.py +779 -0
- drbx/native/electromagnetic.py +250 -0
- drbx/native/expression.py +173 -0
- drbx/native/fci.py +295 -0
- drbx/native/fci_2_field_rhs.py +182 -0
- drbx/native/fci_4_field_rhs.py +1267 -0
- drbx/native/fci_boundaries.py +2494 -0
- drbx/native/fci_differentiable_case.py +304 -0
- drbx/native/fci_drb_EB_rhs.py +1243 -0
- drbx/native/fci_drb_rhs.py +190 -0
- drbx/native/fci_halo.py +1575 -0
- drbx/native/fci_helpers.py +350 -0
- drbx/native/fci_model.py +294 -0
- drbx/native/fci_neutral.py +139 -0
- drbx/native/fci_operators.py +4081 -0
- drbx/native/fci_sharding.py +597 -0
- drbx/native/fci_sheath_recycling.py +206 -0
- drbx/native/fci_time_integrator.py +96 -0
- drbx/native/fci_vorticity.py +198 -0
- drbx/native/fluid_1d.py +330 -0
- drbx/native/hasegawa_wakatani.py +196 -0
- drbx/native/limiters.py +57 -0
- drbx/native/mesh.py +238 -0
- drbx/native/metrics.py +234 -0
- drbx/native/neutrals/__init__.py +58 -0
- drbx/native/neutrals/atomic_rates.py +134 -0
- drbx/native/neutrals/detachment_sol_model.py +221 -0
- drbx/native/neutrals/reactions.py +164 -0
- drbx/native/neutrals/recycling_sol_model.py +197 -0
- drbx/native/sol_flux_tube.py +133 -0
- drbx/native/stellarator_turbulence.py +343 -0
- drbx/native/transport.py +134 -0
- drbx/native/units.py +32 -0
- drbx/native/vorticity.py +252 -0
- drbx/runtime/__init__.py +53 -0
- drbx/runtime/artifacts.py +161 -0
- drbx/runtime/memory.py +144 -0
- drbx/runtime/output.py +374 -0
- drbx/runtime/paths.py +9 -0
- drbx/runtime/performance.py +161 -0
- drbx/runtime/run_config.py +184 -0
- drbx/runtime/scheduler.py +99 -0
- drbx/runtime/state.py +40 -0
- drbx/validation/__init__.py +424 -0
- drbx/validation/autodiff_diffusion.py +329 -0
- drbx/validation/autodiff_diffusion_uncertainty.py +235 -0
- drbx/validation/diverted_tokamak_movie.py +558 -0
- drbx/validation/essos_fieldline_import_campaign.py +181 -0
- drbx/validation/essos_imported_artifact_audit.py +535 -0
- drbx/validation/essos_imported_drb_movie_campaign.py +2826 -0
- drbx/validation/essos_imported_fci_campaign.py +5241 -0
- drbx/validation/essos_imported_pytree_campaign.py +406 -0
- drbx/validation/essos_vmec_closed_field_campaign.py +314 -0
- drbx/validation/essos_vmec_closed_field_transient_campaign.py +629 -0
- drbx/validation/essos_vmec_fieldline_surface_campaign.py +620 -0
- drbx/validation/fluid_1d_mms_convergence.py +250 -0
- drbx/validation/geometry_lineouts.py +136 -0
- drbx/validation/geometry_slices.py +178 -0
- drbx/validation/publication_plotting.py +91 -0
- drbx/validation/stellarator_drb_pytree_campaign.py +621 -0
- drbx/validation/stellarator_fci_geometry_campaign.py +200 -0
- drbx/validation/stellarator_fci_operator_campaign.py +304 -0
- drbx/validation/stellarator_fci_suite_campaign.py +264 -0
- drbx/validation/stellarator_metric_mms_campaign.py +289 -0
- drbx/validation/stellarator_neutral_physics_campaign.py +255 -0
- drbx/validation/stellarator_sheath_recycling_campaign.py +331 -0
- drbx/validation/stellarator_sol_showcase.py +628 -0
- drbx/validation/stellarator_vorticity_campaign.py +304 -0
- drbx/validation/vmec_extender_edge_field_campaign.py +260 -0
- drbx/validation/vmec_extender_sol_smoke_campaign.py +365 -0
- drbx-2.0.0.dev0.dist-info/METADATA +380 -0
- drbx-2.0.0.dev0.dist-info/RECORD +106 -0
- drbx-2.0.0.dev0.dist-info/WHEEL +5 -0
- drbx-2.0.0.dev0.dist-info/entry_points.txt +2 -0
- drbx-2.0.0.dev0.dist-info/licenses/LICENSE +21 -0
- drbx-2.0.0.dev0.dist-info/top_level.txt +1 -0
drbx/native/__init__.py
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
from ..runtime import configure_jax_runtime
|
|
2
|
+
|
|
3
|
+
configure_jax_runtime()
|
|
4
|
+
|
|
5
|
+
from .deck_runner import (
|
|
6
|
+
NativeRestartState,
|
|
7
|
+
NativeRunResult,
|
|
8
|
+
build_restart_state,
|
|
9
|
+
run_config_case,
|
|
10
|
+
run_input_case,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"NativeRestartState",
|
|
15
|
+
"NativeRunResult",
|
|
16
|
+
"build_restart_state",
|
|
17
|
+
"run_config_case",
|
|
18
|
+
"run_input_case",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
# --- FCI stack incorporated from PR #3 (Aiken Xie, branch 3D_fci) ---
|
|
22
|
+
from .fci_halo import (
|
|
23
|
+
FciCutWallValueEvaluator,
|
|
24
|
+
GhostFillWeights1D,
|
|
25
|
+
HaloExchange3D,
|
|
26
|
+
LocalFciCutWallValueEvaluator,
|
|
27
|
+
LocalPeriodicTopologyRule3D,
|
|
28
|
+
LocalStateAndBoundaryPreparer3D,
|
|
29
|
+
PhysicalGhostCellFiller3D,
|
|
30
|
+
PolarAxisRegularScalarRule3D,
|
|
31
|
+
PolarAxisRegularVectorRule3D,
|
|
32
|
+
PreparedLocalState3D,
|
|
33
|
+
RemoteFciDependencyExchange,
|
|
34
|
+
TopologyHaloFiller3D,
|
|
35
|
+
make_default_topology_halo_filler_3d,
|
|
36
|
+
)
|
|
37
|
+
from .fci_boundaries import (
|
|
38
|
+
ConservativeStencil3D,
|
|
39
|
+
FaceGradientStencil3D,
|
|
40
|
+
FourFieldBoundaryConditions,
|
|
41
|
+
LocalBoundaryConditionBuilder,
|
|
42
|
+
LocalBoundaryData3D,
|
|
43
|
+
LocalCoordinateNormalDerivativeConstructor3D,
|
|
44
|
+
LocalCoordinateSideValues1D,
|
|
45
|
+
LocalCoordinateSideValues3D,
|
|
46
|
+
LocalBoundaryFaceBC3D,
|
|
47
|
+
LocalCutWallBC3D,
|
|
48
|
+
LocalCutWallGeometry3D,
|
|
49
|
+
LocalCutWallNormalDerivativeConstructor3D,
|
|
50
|
+
LocalCutWallValueReconstructor3D,
|
|
51
|
+
LocalStencil1D,
|
|
52
|
+
LocalStencil3D,
|
|
53
|
+
)
|
|
54
|
+
from .fci_model import (
|
|
55
|
+
FciFieldBundle,
|
|
56
|
+
FciModelState,
|
|
57
|
+
assert_matching_field_names,
|
|
58
|
+
extract_owned_field_from_halo,
|
|
59
|
+
extract_owned_state_from_halo,
|
|
60
|
+
inject_owned_field_to_halo,
|
|
61
|
+
inject_owned_vector_field_to_halo,
|
|
62
|
+
inject_owned_state_to_halo,
|
|
63
|
+
update_halo_owned_slice,
|
|
64
|
+
update_state_halo_owned_slices,
|
|
65
|
+
)
|
|
66
|
+
from .fci_time_integrator import Rk4StepResult, rk4_step, sum_stage_outputs
|
|
67
|
+
from .fci_sharding import (
|
|
68
|
+
Sharded2FieldStepInfo,
|
|
69
|
+
ShardedFciGeometry3D,
|
|
70
|
+
assemble_local_fci_geometry,
|
|
71
|
+
build_local_fci_geometries,
|
|
72
|
+
make_shard_mesh,
|
|
73
|
+
make_sharded_2field_step,
|
|
74
|
+
)
|
|
75
|
+
from .fci_operators import (
|
|
76
|
+
PerpLaplacianMgHierarchy,
|
|
77
|
+
PerpLaplacianMgLevel,
|
|
78
|
+
build_perp_laplacian_mg_hierarchy,
|
|
79
|
+
build_conservative_stencil_from_field,
|
|
80
|
+
build_local_conservative_stencil_from_field,
|
|
81
|
+
build_local_perp_laplacian_stencil,
|
|
82
|
+
build_local_projected_laplacian_flux_stencil,
|
|
83
|
+
build_perp_laplacian_stencil,
|
|
84
|
+
build_perp_laplacian_face_projectors,
|
|
85
|
+
build_local_perp_laplacian_face_projectors,
|
|
86
|
+
divergence_conservative_op,
|
|
87
|
+
local_divergence_conservative_op,
|
|
88
|
+
curvature_op,
|
|
89
|
+
local_grad_parallel_op_direct,
|
|
90
|
+
local_grad_parallel_op_fci,
|
|
91
|
+
local_grad_perp_op_direct,
|
|
92
|
+
local_parallel_laplacian_direct_op,
|
|
93
|
+
local_perp_laplacian_local_op,
|
|
94
|
+
local_perp_laplacian_conservative_op,
|
|
95
|
+
grad_parallel_op_fci,
|
|
96
|
+
grad_perp_op,
|
|
97
|
+
mg_apply_preconditioner,
|
|
98
|
+
perp_laplacian_local_op,
|
|
99
|
+
perp_laplacian_conservative_op,
|
|
100
|
+
parallel_laplacian_direct_op,
|
|
101
|
+
parallel_laplacian_conservative_op,
|
|
102
|
+
local_poisson_bracket_op,
|
|
103
|
+
local_curvature_op,
|
|
104
|
+
poisson_bracket_op,
|
|
105
|
+
)
|
|
106
|
+
from .fci_2_field_rhs import Fci2FieldRhsParameters, Fci2FieldRhsResult, Fci2FieldState, compute_2field_rhs
|
|
107
|
+
from .fci_drb_EB_rhs import (
|
|
108
|
+
FciDrbEBBoundaryConditions,
|
|
109
|
+
FciDrbEBRhsParameters,
|
|
110
|
+
FciDrbEBRhsResult,
|
|
111
|
+
FciDrbEBState,
|
|
112
|
+
compute_fci_drb_eb_rhs,
|
|
113
|
+
)
|
|
114
|
+
from .fci_4_field_rhs import (
|
|
115
|
+
Fci4FieldBlobParameters,
|
|
116
|
+
Fci4FieldFreeDecayParameters,
|
|
117
|
+
Fci4FieldRhsParameters,
|
|
118
|
+
Fci4FieldRhsResult,
|
|
119
|
+
Fci4FieldState,
|
|
120
|
+
compute_4field_blob_rhs,
|
|
121
|
+
compute_4field_curvature,
|
|
122
|
+
compute_4field_diffusion,
|
|
123
|
+
compute_4field_free_decay_rhs,
|
|
124
|
+
compute_4field_rhs,
|
|
125
|
+
compute_4field_poisson_diffusion,
|
|
126
|
+
)
|
|
127
|
+
__all__ += [
|
|
128
|
+
"ConservativeStencil3D",
|
|
129
|
+
"FaceGradientStencil3D",
|
|
130
|
+
"Fci2FieldRhsParameters",
|
|
131
|
+
"Fci2FieldRhsResult",
|
|
132
|
+
"Fci2FieldState",
|
|
133
|
+
"Fci4FieldBlobParameters",
|
|
134
|
+
"Fci4FieldFreeDecayParameters",
|
|
135
|
+
"Fci4FieldRhsParameters",
|
|
136
|
+
"Fci4FieldRhsResult",
|
|
137
|
+
"Fci4FieldState",
|
|
138
|
+
"FciCutWallValueEvaluator",
|
|
139
|
+
"FciDrbEBBoundaryConditions",
|
|
140
|
+
"FciDrbEBRhsParameters",
|
|
141
|
+
"FciDrbEBRhsResult",
|
|
142
|
+
"FciDrbEBState",
|
|
143
|
+
"FciFieldBundle",
|
|
144
|
+
"FciModelState",
|
|
145
|
+
"FourFieldBoundaryConditions",
|
|
146
|
+
"GhostFillWeights1D",
|
|
147
|
+
"HaloExchange3D",
|
|
148
|
+
"LocalBoundaryConditionBuilder",
|
|
149
|
+
"LocalBoundaryData3D",
|
|
150
|
+
"LocalBoundaryFaceBC3D",
|
|
151
|
+
"LocalCoordinateNormalDerivativeConstructor3D",
|
|
152
|
+
"LocalCoordinateSideValues1D",
|
|
153
|
+
"LocalCoordinateSideValues3D",
|
|
154
|
+
"LocalCutWallBC3D",
|
|
155
|
+
"LocalCutWallGeometry3D",
|
|
156
|
+
"LocalCutWallNormalDerivativeConstructor3D",
|
|
157
|
+
"LocalCutWallValueReconstructor3D",
|
|
158
|
+
"LocalFciCutWallValueEvaluator",
|
|
159
|
+
"LocalPeriodicTopologyRule3D",
|
|
160
|
+
"LocalStateAndBoundaryPreparer3D",
|
|
161
|
+
"LocalStencil1D",
|
|
162
|
+
"LocalStencil3D",
|
|
163
|
+
"PerpLaplacianMgHierarchy",
|
|
164
|
+
"PerpLaplacianMgLevel",
|
|
165
|
+
"PhysicalGhostCellFiller3D",
|
|
166
|
+
"PolarAxisRegularScalarRule3D",
|
|
167
|
+
"PolarAxisRegularVectorRule3D",
|
|
168
|
+
"PreparedLocalState3D",
|
|
169
|
+
"RemoteFciDependencyExchange",
|
|
170
|
+
"Rk4StepResult",
|
|
171
|
+
"TopologyHaloFiller3D",
|
|
172
|
+
"assert_matching_field_names",
|
|
173
|
+
"build_conservative_stencil_from_field",
|
|
174
|
+
"build_local_conservative_stencil_from_field",
|
|
175
|
+
"build_local_perp_laplacian_face_projectors",
|
|
176
|
+
"build_local_perp_laplacian_stencil",
|
|
177
|
+
"build_local_projected_laplacian_flux_stencil",
|
|
178
|
+
"build_perp_laplacian_face_projectors",
|
|
179
|
+
"build_perp_laplacian_mg_hierarchy",
|
|
180
|
+
"build_perp_laplacian_stencil",
|
|
181
|
+
"compute_2field_rhs",
|
|
182
|
+
"compute_4field_blob_rhs",
|
|
183
|
+
"compute_4field_curvature",
|
|
184
|
+
"compute_4field_diffusion",
|
|
185
|
+
"compute_4field_free_decay_rhs",
|
|
186
|
+
"compute_4field_poisson_diffusion",
|
|
187
|
+
"compute_4field_rhs",
|
|
188
|
+
"compute_fci_drb_eb_rhs",
|
|
189
|
+
"curvature_op",
|
|
190
|
+
"divergence_conservative_op",
|
|
191
|
+
"extract_owned_field_from_halo",
|
|
192
|
+
"extract_owned_state_from_halo",
|
|
193
|
+
"grad_parallel_op_fci",
|
|
194
|
+
"grad_perp_op",
|
|
195
|
+
"inject_owned_field_to_halo",
|
|
196
|
+
"inject_owned_state_to_halo",
|
|
197
|
+
"inject_owned_vector_field_to_halo",
|
|
198
|
+
"local_curvature_op",
|
|
199
|
+
"local_divergence_conservative_op",
|
|
200
|
+
"local_grad_parallel_op_direct",
|
|
201
|
+
"local_grad_parallel_op_fci",
|
|
202
|
+
"local_grad_perp_op_direct",
|
|
203
|
+
"local_parallel_laplacian_direct_op",
|
|
204
|
+
"local_perp_laplacian_conservative_op",
|
|
205
|
+
"local_perp_laplacian_local_op",
|
|
206
|
+
"local_poisson_bracket_op",
|
|
207
|
+
"make_default_topology_halo_filler_3d",
|
|
208
|
+
"mg_apply_preconditioner",
|
|
209
|
+
"parallel_laplacian_conservative_op",
|
|
210
|
+
"parallel_laplacian_direct_op",
|
|
211
|
+
"perp_laplacian_conservative_op",
|
|
212
|
+
"perp_laplacian_local_op",
|
|
213
|
+
"poisson_bracket_op",
|
|
214
|
+
"rk4_step",
|
|
215
|
+
"Sharded2FieldStepInfo",
|
|
216
|
+
"ShardedFciGeometry3D",
|
|
217
|
+
"assemble_local_fci_geometry",
|
|
218
|
+
"build_local_fci_geometries",
|
|
219
|
+
"make_shard_mesh",
|
|
220
|
+
"make_sharded_2field_step",
|
|
221
|
+
"sum_stage_outputs",
|
|
222
|
+
"update_halo_owned_slice",
|
|
223
|
+
"update_state_halo_owned_slices",
|
|
224
|
+
]
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from numbers import Number
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import jax.numpy as jnp
|
|
7
|
+
import numpy as np
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def is_jax_array(value: Any) -> bool:
|
|
11
|
+
"""Return whether ``value`` is a JAX array or tracer.
|
|
12
|
+
|
|
13
|
+
Several hot-path kernels mix static NumPy metric arrays with dynamic JAX
|
|
14
|
+
state arrays during ``jax.jvp`` or ``jax.linearize``. Backend selection must
|
|
15
|
+
prefer JAX whenever any dynamic argument is a JAX value; otherwise a single
|
|
16
|
+
NumPy metric would force ``np.asarray`` on a tracer.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
if value is None:
|
|
20
|
+
return False
|
|
21
|
+
if isinstance(value, (np.ndarray, np.generic, Number, bool)):
|
|
22
|
+
return False
|
|
23
|
+
module = type(value).__module__
|
|
24
|
+
if module == "numpy" or module.startswith("numpy."):
|
|
25
|
+
return False
|
|
26
|
+
return hasattr(value, "aval") or module.startswith("jax") or module.startswith("jaxlib")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def use_jax_backend(*values: Any) -> bool:
|
|
30
|
+
"""Select JAX when any argument is a JAX array/tracer."""
|
|
31
|
+
|
|
32
|
+
for value in values:
|
|
33
|
+
if value is not None and is_jax_array(value):
|
|
34
|
+
return True
|
|
35
|
+
return False
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def asarray(value: Any, *, use_jax: bool):
|
|
39
|
+
"""Cast to the selected floating array backend."""
|
|
40
|
+
|
|
41
|
+
if use_jax:
|
|
42
|
+
return jnp.asarray(value, dtype=jnp.float64)
|
|
43
|
+
return np.asarray(value, dtype=np.float64)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def zeros_like(value: Any, *, use_jax: bool):
|
|
47
|
+
"""Create a float64 zeros array on the selected backend."""
|
|
48
|
+
|
|
49
|
+
if use_jax:
|
|
50
|
+
return jnp.zeros_like(jnp.asarray(value, dtype=jnp.float64), dtype=jnp.float64)
|
|
51
|
+
return np.zeros_like(np.asarray(value, dtype=np.float64), dtype=np.float64)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def maximum_reduce(values: tuple[Any, ...], *, use_jax: bool):
|
|
55
|
+
"""Backend-preserving equivalent of ``np.maximum.reduce``."""
|
|
56
|
+
|
|
57
|
+
if not values:
|
|
58
|
+
raise ValueError("maximum_reduce requires at least one value.")
|
|
59
|
+
if use_jax:
|
|
60
|
+
result = jnp.asarray(values[0], dtype=jnp.float64)
|
|
61
|
+
for value in values[1:]:
|
|
62
|
+
result = jnp.maximum(result, jnp.asarray(value, dtype=jnp.float64))
|
|
63
|
+
return result
|
|
64
|
+
return np.maximum.reduce(tuple(np.asarray(value, dtype=np.float64) for value in values))
|