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.
Files changed (106) hide show
  1. drbx/__init__.py +20 -0
  2. drbx/__main__.py +5 -0
  3. drbx/cli.py +586 -0
  4. drbx/config/__init__.py +20 -0
  5. drbx/config/boutinp.py +556 -0
  6. drbx/config/model.py +34 -0
  7. drbx/config/normalization.py +66 -0
  8. drbx/data/atomic_rates/__init__.py +1 -0
  9. drbx/data/atomic_rates/iz_AMJUEL_H.x_2.1.5.json +213 -0
  10. drbx/data/atomic_rates/iz_AMJUEL_H.x_2.3.9a.json +213 -0
  11. drbx/data/atomic_rates/rec_AMJUEL_H.x_2.1.8.json +213 -0
  12. drbx/data/atomic_rates/rec_AMJUEL_H.x_2.3.13a.json +213 -0
  13. drbx/geometry/__init__.py +207 -0
  14. drbx/geometry/embedding.py +56 -0
  15. drbx/geometry/essos_import.py +1385 -0
  16. drbx/geometry/fci_geometry.py +4622 -0
  17. drbx/geometry/fci_maps.py +85 -0
  18. drbx/geometry/island_divertor.py +291 -0
  19. drbx/geometry/metric_tensor.py +99 -0
  20. drbx/geometry/open_slab.py +150 -0
  21. drbx/geometry/rotating_ellipse.py +253 -0
  22. drbx/geometry/shifted_torus.py +225 -0
  23. drbx/geometry/stellarator.py +287 -0
  24. drbx/geometry/vmec_extender_import.py +499 -0
  25. drbx/geometry/vmec_jax_import.py +306 -0
  26. drbx/linear/__init__.py +37 -0
  27. drbx/linear/dispersion.py +138 -0
  28. drbx/linear/eigen.py +91 -0
  29. drbx/native/__init__.py +224 -0
  30. drbx/native/array_backend.py +64 -0
  31. drbx/native/deck_runner.py +779 -0
  32. drbx/native/electromagnetic.py +250 -0
  33. drbx/native/expression.py +173 -0
  34. drbx/native/fci.py +295 -0
  35. drbx/native/fci_2_field_rhs.py +182 -0
  36. drbx/native/fci_4_field_rhs.py +1267 -0
  37. drbx/native/fci_boundaries.py +2494 -0
  38. drbx/native/fci_differentiable_case.py +304 -0
  39. drbx/native/fci_drb_EB_rhs.py +1243 -0
  40. drbx/native/fci_drb_rhs.py +190 -0
  41. drbx/native/fci_halo.py +1575 -0
  42. drbx/native/fci_helpers.py +350 -0
  43. drbx/native/fci_model.py +294 -0
  44. drbx/native/fci_neutral.py +139 -0
  45. drbx/native/fci_operators.py +4081 -0
  46. drbx/native/fci_sharding.py +597 -0
  47. drbx/native/fci_sheath_recycling.py +206 -0
  48. drbx/native/fci_time_integrator.py +96 -0
  49. drbx/native/fci_vorticity.py +198 -0
  50. drbx/native/fluid_1d.py +330 -0
  51. drbx/native/hasegawa_wakatani.py +196 -0
  52. drbx/native/limiters.py +57 -0
  53. drbx/native/mesh.py +238 -0
  54. drbx/native/metrics.py +234 -0
  55. drbx/native/neutrals/__init__.py +58 -0
  56. drbx/native/neutrals/atomic_rates.py +134 -0
  57. drbx/native/neutrals/detachment_sol_model.py +221 -0
  58. drbx/native/neutrals/reactions.py +164 -0
  59. drbx/native/neutrals/recycling_sol_model.py +197 -0
  60. drbx/native/sol_flux_tube.py +133 -0
  61. drbx/native/stellarator_turbulence.py +343 -0
  62. drbx/native/transport.py +134 -0
  63. drbx/native/units.py +32 -0
  64. drbx/native/vorticity.py +252 -0
  65. drbx/runtime/__init__.py +53 -0
  66. drbx/runtime/artifacts.py +161 -0
  67. drbx/runtime/memory.py +144 -0
  68. drbx/runtime/output.py +374 -0
  69. drbx/runtime/paths.py +9 -0
  70. drbx/runtime/performance.py +161 -0
  71. drbx/runtime/run_config.py +184 -0
  72. drbx/runtime/scheduler.py +99 -0
  73. drbx/runtime/state.py +40 -0
  74. drbx/validation/__init__.py +424 -0
  75. drbx/validation/autodiff_diffusion.py +329 -0
  76. drbx/validation/autodiff_diffusion_uncertainty.py +235 -0
  77. drbx/validation/diverted_tokamak_movie.py +558 -0
  78. drbx/validation/essos_fieldline_import_campaign.py +181 -0
  79. drbx/validation/essos_imported_artifact_audit.py +535 -0
  80. drbx/validation/essos_imported_drb_movie_campaign.py +2826 -0
  81. drbx/validation/essos_imported_fci_campaign.py +5241 -0
  82. drbx/validation/essos_imported_pytree_campaign.py +406 -0
  83. drbx/validation/essos_vmec_closed_field_campaign.py +314 -0
  84. drbx/validation/essos_vmec_closed_field_transient_campaign.py +629 -0
  85. drbx/validation/essos_vmec_fieldline_surface_campaign.py +620 -0
  86. drbx/validation/fluid_1d_mms_convergence.py +250 -0
  87. drbx/validation/geometry_lineouts.py +136 -0
  88. drbx/validation/geometry_slices.py +178 -0
  89. drbx/validation/publication_plotting.py +91 -0
  90. drbx/validation/stellarator_drb_pytree_campaign.py +621 -0
  91. drbx/validation/stellarator_fci_geometry_campaign.py +200 -0
  92. drbx/validation/stellarator_fci_operator_campaign.py +304 -0
  93. drbx/validation/stellarator_fci_suite_campaign.py +264 -0
  94. drbx/validation/stellarator_metric_mms_campaign.py +289 -0
  95. drbx/validation/stellarator_neutral_physics_campaign.py +255 -0
  96. drbx/validation/stellarator_sheath_recycling_campaign.py +331 -0
  97. drbx/validation/stellarator_sol_showcase.py +628 -0
  98. drbx/validation/stellarator_vorticity_campaign.py +304 -0
  99. drbx/validation/vmec_extender_edge_field_campaign.py +260 -0
  100. drbx/validation/vmec_extender_sol_smoke_campaign.py +365 -0
  101. drbx-2.0.0.dev0.dist-info/METADATA +380 -0
  102. drbx-2.0.0.dev0.dist-info/RECORD +106 -0
  103. drbx-2.0.0.dev0.dist-info/WHEEL +5 -0
  104. drbx-2.0.0.dev0.dist-info/entry_points.txt +2 -0
  105. drbx-2.0.0.dev0.dist-info/licenses/LICENSE +21 -0
  106. drbx-2.0.0.dev0.dist-info/top_level.txt +1 -0
@@ -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))