torux 0.1.0__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.
- torux/__init__.py +109 -0
- torux/analysis.py +2355 -0
- torux/answer.py +988 -0
- torux/api.py +281 -0
- torux/ask.py +760 -0
- torux/axis.py +315 -0
- torux/axis_general.py +444 -0
- torux/axisselect.py +250 -0
- torux/barrier.py +5103 -0
- torux/batch.py +798 -0
- torux/boozer.py +327 -0
- torux/budget.py +70 -0
- torux/cardtrace.py +262 -0
- torux/certify.py +142 -0
- torux/chainfind.py +246 -0
- torux/chains.py +203 -0
- torux/check.py +707 -0
- torux/cli.py +239 -0
- torux/design.py +302 -0
- torux/edgebound.py +2342 -0
- torux/envfail.py +18 -0
- torux/escape.py +126 -0
- torux/exitcurve.py +1508 -0
- torux/exitcurve_far.py +185 -0
- torux/exitcurve_nearcoil.py +234 -0
- torux/family.py +724 -0
- torux/family_general.py +475 -0
- torux/fast_design.py +106 -0
- torux/fast_family.py +133 -0
- torux/fast_kernels.py +715 -0
- torux/fast_newton.py +140 -0
- torux/fast_trace.py +371 -0
- torux/fasttrace.py +243 -0
- torux/field/__init__.py +1 -0
- torux/field/analytic.py +108 -0
- torux/field/cpu.py +298 -0
- torux/field/cuda_fil.py +384 -0
- torux/field/engine.py +760 -0
- torux/field/grid.py +131 -0
- torux/field/kernels.py +173 -0
- torux/gradients.py +385 -0
- torux/guard.py +89 -0
- torux/io/__init__.py +1 -0
- torux/io/_stellcommon.py +530 -0
- torux/io/analytic.py +215 -0
- torux/io/axisym.py +551 -0
- torux/io/focus.py +160 -0
- torux/io/focus_dipoles.py +200 -0
- torux/io/fourier_json.py +63 -0
- torux/io/gpec.py +59 -0
- torux/io/magnets.py +413 -0
- torux/io/makegrid.py +204 -0
- torux/io/simsopt_json.py +683 -0
- torux/io/surfaces.py +408 -0
- torux/io/wireframe.py +125 -0
- torux/islandband.py +3960 -0
- torux/load.py +240 -0
- torux/manifolds.py +178 -0
- torux/nearaxis.py +217 -0
- torux/noaxis.py +1020 -0
- torux/nonstell.py +2136 -0
- torux/nonstell_cert.py +863 -0
- torux/nonstell_index.py +2695 -0
- torux/orbits.py +326 -0
- torux/plot.py +784 -0
- torux/reference/__init__.py +59 -0
- torux/reference/carlson.py +274 -0
- torux/reference/constants.py +12 -0
- torux/reference/dd.py +366 -0
- torux/reference/fast64.py +779 -0
- torux/reference/geometry.py +49 -0
- torux/reference/precise.py +150 -0
- torux/reference/precise_axipoly.py +590 -0
- torux/reference/precise_closed.py +417 -0
- torux/reference/precise_curves.py +335 -0
- torux/reference/quadrules.py +89 -0
- torux/reference/trace.py +276 -0
- torux/seeds.py +1766 -0
- torux/source.py +275 -0
- torux/sources.py +243 -0
- torux/torus.py +1360 -0
- torux/torus_cpu.py +111 -0
- torux/torus_general.py +818 -0
- torux/trace.py +95 -0
- torux/verify.py +381 -0
- torux/verify_general.py +139 -0
- torux-0.1.0.dist-info/METADATA +185 -0
- torux-0.1.0.dist-info/RECORD +93 -0
- torux-0.1.0.dist-info/WHEEL +5 -0
- torux-0.1.0.dist-info/entry_points.txt +2 -0
- torux-0.1.0.dist-info/licenses/LICENSE +121 -0
- torux-0.1.0.dist-info/licenses/NOTICE.md +46 -0
- torux-0.1.0.dist-info/top_level.txt +1 -0
torux/__init__.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""torux: the vacuum magnetic field and flux surfaces of any external source for toroidal confinement.
|
|
2
|
+
|
|
3
|
+
import torux
|
|
4
|
+
|
|
5
|
+
s = torux.solve("quasr:954") # a QUASR design: its own request
|
|
6
|
+
s = torux.solve("coils.json", flux=0.0691) # the surface enclosing this full toroidal flux, Wb
|
|
7
|
+
s = torux.solve("coils.json", minor_radius=0.12) # or of this minor radius, m, or volume=, m^3
|
|
8
|
+
s = torux.solve("coils.json", largest=True) # or the largest torux can verify
|
|
9
|
+
print(s) # what it found, how it was checked, or why there is none
|
|
10
|
+
s.iota, s.volume, s.minor_radius, s.profile, s.section(phi)
|
|
11
|
+
s.save("input.mine") # VMEC input. Also *.json, *.vtk
|
|
12
|
+
s.plot("surface.png"), s.boozer()
|
|
13
|
+
torux.check("coils.json", "wout_mine.nc") # how close another code's surface is to a flux surface
|
|
14
|
+
torux.many(files, table="answers.csv") # many designs at once, each in its own process
|
|
15
|
+
|
|
16
|
+
s.status 'surface' | 'no_surface' | 'range' | 'undetermined' | 'no_axis' | 'timeout' | 'error', or
|
|
17
|
+
'surface_unverified' / 'range_unverified'
|
|
18
|
+
|
|
19
|
+
A request is answered 'surface' only when the solver's acceptance and an independent evaluator that shares no
|
|
20
|
+
code with it both agree, and 'no_surface' only with a certificate or a proof. Everything else is 'undetermined':
|
|
21
|
+
never a guess.
|
|
22
|
+
|
|
23
|
+
Environment:
|
|
24
|
+
TORUX_THREADS threads of every pool, BLAS included even when numpy or scipy was imported first (default:
|
|
25
|
+
four, or the cores available if fewer)
|
|
26
|
+
TORUX_CACHE_DIR where JAX's compiled programs are kept between processes (default ~/.cache/torux).
|
|
27
|
+
TORUX_JAX_CACHE=0 turns that cache off. QUASR downloads are kept there too. numba keeps
|
|
28
|
+
its own cache beside the package.
|
|
29
|
+
"""
|
|
30
|
+
import os as _os
|
|
31
|
+
|
|
32
|
+
__version__ = "0.1.0"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _threads():
|
|
36
|
+
try:
|
|
37
|
+
n = int(_os.environ.get("TORUX_THREADS") or 0)
|
|
38
|
+
except ValueError:
|
|
39
|
+
n = 0
|
|
40
|
+
if n <= 0:
|
|
41
|
+
try:
|
|
42
|
+
avail = len(_os.sched_getaffinity(0))
|
|
43
|
+
except AttributeError:
|
|
44
|
+
avail = _os.cpu_count() or 1
|
|
45
|
+
n = max(1, min(4, avail))
|
|
46
|
+
return n
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# One number for every pool, set before numpy loads its BLAS: an uncapped BLAS on a large or shared machine makes
|
|
50
|
+
# the dense solves many times slower.
|
|
51
|
+
_os.environ["TORUX_THREADS"] = str(_threads())
|
|
52
|
+
for _v in ("OPENBLAS_NUM_THREADS", "OMP_NUM_THREADS", "MKL_NUM_THREADS", "VECLIB_MAXIMUM_THREADS",
|
|
53
|
+
"NUMBA_NUM_THREADS"):
|
|
54
|
+
_os.environ.setdefault(_v, _os.environ["TORUX_THREADS"])
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _cap_loaded_blas():
|
|
58
|
+
"""A BLAS loaded before torux (numpy or scipy imported first) started with as many threads as the machine has,
|
|
59
|
+
and the last bits of a solve depend on that count: each such pool is capped to TORUX_THREADS."""
|
|
60
|
+
import sys
|
|
61
|
+
if not any(m in sys.modules for m in ("numpy", "scipy")):
|
|
62
|
+
return # nothing loaded yet: the variables above hold every pool
|
|
63
|
+
from threadpoolctl import ThreadpoolController
|
|
64
|
+
n = int(_os.environ["TORUX_THREADS"])
|
|
65
|
+
for lib in ThreadpoolController().lib_controllers:
|
|
66
|
+
if lib.user_api == "blas" and (lib.num_threads or 0) > n:
|
|
67
|
+
lib.set_num_threads(n)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
_cap_loaded_blas()
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _cache_dir():
|
|
74
|
+
d = _os.environ.get("TORUX_CACHE_DIR")
|
|
75
|
+
if not d:
|
|
76
|
+
base = _os.environ.get("XDG_CACHE_HOME") or _os.path.join(_os.path.expanduser("~"), ".cache")
|
|
77
|
+
d = _os.path.join(base, "torux")
|
|
78
|
+
return d
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
try:
|
|
82
|
+
import jax as _jax
|
|
83
|
+
_jax.config.update("jax_enable_x64", True)
|
|
84
|
+
if _os.environ.get("TORUX_JAX_CACHE", "1") != "0":
|
|
85
|
+
_d = _os.environ.get("TORUX_JAX_CACHE_DIR") or _os.environ.get("JAX_COMPILATION_CACHE_DIR") \
|
|
86
|
+
or _os.path.join(_cache_dir(), "jax")
|
|
87
|
+
try:
|
|
88
|
+
_os.makedirs(_d, exist_ok=True)
|
|
89
|
+
except OSError:
|
|
90
|
+
_d = None # no writable cache directory: compile without the persistent cache
|
|
91
|
+
if _d:
|
|
92
|
+
_jax.config.update("jax_compilation_cache_dir", _d)
|
|
93
|
+
try:
|
|
94
|
+
_jax.config.update("jax_persistent_cache_min_compile_time_secs", 0.0)
|
|
95
|
+
except Exception: # noqa: BLE001
|
|
96
|
+
pass
|
|
97
|
+
except Exception: # noqa: BLE001
|
|
98
|
+
pass
|
|
99
|
+
|
|
100
|
+
from .source import (AxisymPolygons, Dipoles, FourierCurves, PolylineCurves, Rings, Segments, # noqa: E402
|
|
101
|
+
Source, ToroidalField)
|
|
102
|
+
from .sources import load # noqa: E402
|
|
103
|
+
from .api import Request, Result # noqa: E402
|
|
104
|
+
from .answer import Answer, solve # noqa: E402
|
|
105
|
+
from .check import Check, check # noqa: E402
|
|
106
|
+
from .batch import many # noqa: E402
|
|
107
|
+
|
|
108
|
+
__all__ = ["solve", "load", "check", "many", "Answer", "Check", "Request", "Result", "Source", "FourierCurves",
|
|
109
|
+
"PolylineCurves", "Segments", "Dipoles", "Rings", "AxisymPolygons", "ToroidalField", "__version__"]
|