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.
Files changed (93) hide show
  1. torux/__init__.py +109 -0
  2. torux/analysis.py +2355 -0
  3. torux/answer.py +988 -0
  4. torux/api.py +281 -0
  5. torux/ask.py +760 -0
  6. torux/axis.py +315 -0
  7. torux/axis_general.py +444 -0
  8. torux/axisselect.py +250 -0
  9. torux/barrier.py +5103 -0
  10. torux/batch.py +798 -0
  11. torux/boozer.py +327 -0
  12. torux/budget.py +70 -0
  13. torux/cardtrace.py +262 -0
  14. torux/certify.py +142 -0
  15. torux/chainfind.py +246 -0
  16. torux/chains.py +203 -0
  17. torux/check.py +707 -0
  18. torux/cli.py +239 -0
  19. torux/design.py +302 -0
  20. torux/edgebound.py +2342 -0
  21. torux/envfail.py +18 -0
  22. torux/escape.py +126 -0
  23. torux/exitcurve.py +1508 -0
  24. torux/exitcurve_far.py +185 -0
  25. torux/exitcurve_nearcoil.py +234 -0
  26. torux/family.py +724 -0
  27. torux/family_general.py +475 -0
  28. torux/fast_design.py +106 -0
  29. torux/fast_family.py +133 -0
  30. torux/fast_kernels.py +715 -0
  31. torux/fast_newton.py +140 -0
  32. torux/fast_trace.py +371 -0
  33. torux/fasttrace.py +243 -0
  34. torux/field/__init__.py +1 -0
  35. torux/field/analytic.py +108 -0
  36. torux/field/cpu.py +298 -0
  37. torux/field/cuda_fil.py +384 -0
  38. torux/field/engine.py +760 -0
  39. torux/field/grid.py +131 -0
  40. torux/field/kernels.py +173 -0
  41. torux/gradients.py +385 -0
  42. torux/guard.py +89 -0
  43. torux/io/__init__.py +1 -0
  44. torux/io/_stellcommon.py +530 -0
  45. torux/io/analytic.py +215 -0
  46. torux/io/axisym.py +551 -0
  47. torux/io/focus.py +160 -0
  48. torux/io/focus_dipoles.py +200 -0
  49. torux/io/fourier_json.py +63 -0
  50. torux/io/gpec.py +59 -0
  51. torux/io/magnets.py +413 -0
  52. torux/io/makegrid.py +204 -0
  53. torux/io/simsopt_json.py +683 -0
  54. torux/io/surfaces.py +408 -0
  55. torux/io/wireframe.py +125 -0
  56. torux/islandband.py +3960 -0
  57. torux/load.py +240 -0
  58. torux/manifolds.py +178 -0
  59. torux/nearaxis.py +217 -0
  60. torux/noaxis.py +1020 -0
  61. torux/nonstell.py +2136 -0
  62. torux/nonstell_cert.py +863 -0
  63. torux/nonstell_index.py +2695 -0
  64. torux/orbits.py +326 -0
  65. torux/plot.py +784 -0
  66. torux/reference/__init__.py +59 -0
  67. torux/reference/carlson.py +274 -0
  68. torux/reference/constants.py +12 -0
  69. torux/reference/dd.py +366 -0
  70. torux/reference/fast64.py +779 -0
  71. torux/reference/geometry.py +49 -0
  72. torux/reference/precise.py +150 -0
  73. torux/reference/precise_axipoly.py +590 -0
  74. torux/reference/precise_closed.py +417 -0
  75. torux/reference/precise_curves.py +335 -0
  76. torux/reference/quadrules.py +89 -0
  77. torux/reference/trace.py +276 -0
  78. torux/seeds.py +1766 -0
  79. torux/source.py +275 -0
  80. torux/sources.py +243 -0
  81. torux/torus.py +1360 -0
  82. torux/torus_cpu.py +111 -0
  83. torux/torus_general.py +818 -0
  84. torux/trace.py +95 -0
  85. torux/verify.py +381 -0
  86. torux/verify_general.py +139 -0
  87. torux-0.1.0.dist-info/METADATA +185 -0
  88. torux-0.1.0.dist-info/RECORD +93 -0
  89. torux-0.1.0.dist-info/WHEEL +5 -0
  90. torux-0.1.0.dist-info/entry_points.txt +2 -0
  91. torux-0.1.0.dist-info/licenses/LICENSE +121 -0
  92. torux-0.1.0.dist-info/licenses/NOTICE.md +46 -0
  93. 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__"]