torchspin 0.6.2__tar.gz → 0.6.4__tar.gz

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 (128) hide show
  1. {torchspin-0.6.2 → torchspin-0.6.4}/CHANGELOG.md +38 -0
  2. {torchspin-0.6.2 → torchspin-0.6.4}/CITATION.cff +1 -1
  3. {torchspin-0.6.2 → torchspin-0.6.4}/PKG-INFO +1 -1
  4. {torchspin-0.6.2 → torchspin-0.6.4}/pyproject.toml +1 -1
  5. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/__init__.py +7 -1
  6. torchspin-0.6.4/torchspin/_omp.py +54 -0
  7. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/esfit.py +3 -1
  8. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/ml.py +4 -1
  9. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin.egg-info/PKG-INFO +1 -1
  10. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin.egg-info/SOURCES.txt +1 -0
  11. {torchspin-0.6.2 → torchspin-0.6.4}/LICENSE.md +0 -0
  12. {torchspin-0.6.2 → torchspin-0.6.4}/MANIFEST.in +0 -0
  13. {torchspin-0.6.2 → torchspin-0.6.4}/README.md +0 -0
  14. {torchspin-0.6.2 → torchspin-0.6.4}/setup.cfg +0 -0
  15. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/_cardamom_istos.py +0 -0
  16. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/_cardamom_propagatedm.py +0 -0
  17. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/_cardamom_utils.py +0 -0
  18. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/_compile.py +0 -0
  19. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/_linalg.py +0 -0
  20. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/_rng.py +0 -0
  21. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/angmom.py +0 -0
  22. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/autograd.py +0 -0
  23. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/autoguess.py +0 -0
  24. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/batch.py +0 -0
  25. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/blochsteady.py +0 -0
  26. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/cardamom.py +0 -0
  27. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/chili.py +0 -0
  28. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/chili_sle.py +0 -0
  29. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/constants.py +0 -0
  30. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/convspec.py +0 -0
  31. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/ctafft.py +0 -0
  32. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/curry.py +0 -0
  33. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/data/FourierSeriesCoefficients.txt +0 -0
  34. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/data/GaussianCascadeCoefficients.txt +0 -0
  35. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/data/isotopedata.txt +0 -0
  36. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/data/spacegroups.txt +0 -0
  37. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/dataproc.py +0 -0
  38. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/dipbackground.py +0 -0
  39. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/dipkernel.py +0 -0
  40. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/diptensor.py +0 -0
  41. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/endorfrq.py +0 -0
  42. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/endorfrq_perturb.py +0 -0
  43. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/eprload.py +0 -0
  44. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/eprsave.py +0 -0
  45. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/evolve.py +0 -0
  46. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/ewrls.py +0 -0
  47. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/excitation.py +0 -0
  48. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/exciteprofile.py +0 -0
  49. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/experiment.py +0 -0
  50. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/exponfit.py +0 -0
  51. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/fastmotion.py +0 -0
  52. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/fdaxis.py +0 -0
  53. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/fitgui.py +0 -0
  54. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/garlic.py +0 -0
  55. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/gridcheck.py +0 -0
  56. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/ham.py +0 -0
  57. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/ham_cf.py +0 -0
  58. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/ham_ee.py +0 -0
  59. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/ham_ez.py +0 -0
  60. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/ham_ezho.py +0 -0
  61. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/ham_hf.py +0 -0
  62. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/ham_nn.py +0 -0
  63. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/ham_nq.py +0 -0
  64. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/ham_nz.py +0 -0
  65. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/ham_oz.py +0 -0
  66. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/ham_so.py +0 -0
  67. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/ham_zf.py +0 -0
  68. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/hamsymm.py +0 -0
  69. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/initstate.py +0 -0
  70. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/isotopologues.py +0 -0
  71. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/levels.py +0 -0
  72. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/levelsplot.py +0 -0
  73. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/lineshape.py +0 -0
  74. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/lpsvd.py +0 -0
  75. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/makespec.py +0 -0
  76. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/mdhmm.py +0 -0
  77. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/mdload.py +0 -0
  78. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/mdtraj2oripot.py +0 -0
  79. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/mlpsvd.py +0 -0
  80. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/nucdata.py +0 -0
  81. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/nucfrq2d.py +0 -0
  82. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/orca2torchspin.py +0 -0
  83. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/ordering.py +0 -0
  84. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/oripotentialplot.py +0 -0
  85. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/orisel.py +0 -0
  86. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/pepper.py +0 -0
  87. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/pepper_autograd.py +0 -0
  88. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/photoselect.py +0 -0
  89. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/plegendre.py +0 -0
  90. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/propint.py +0 -0
  91. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/pulse.py +0 -0
  92. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/py.typed +0 -0
  93. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/rapidscan2spc.py +0 -0
  94. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/resfields.py +0 -0
  95. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/resfields_batch.py +0 -0
  96. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/resfields_eig.py +0 -0
  97. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/resfields_hybrid.py +0 -0
  98. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/resfields_perturb.py +0 -0
  99. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/resfreqs_matrix.py +0 -0
  100. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/resfreqs_perturb.py +0 -0
  101. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/resonator.py +0 -0
  102. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/resonatorprofile.py +0 -0
  103. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/rfmixer.py +0 -0
  104. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/rotations.py +0 -0
  105. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/rotutils.py +0 -0
  106. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/saffron.py +0 -0
  107. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/saffron_pathways.py +0 -0
  108. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/saffron_peaks.py +0 -0
  109. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/saffron_thyme.py +0 -0
  110. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/salt.py +0 -0
  111. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/sigeq.py +0 -0
  112. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/signalprocessing.py +0 -0
  113. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/sitetransforms.py +0 -0
  114. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/sphgrid.py +0 -0
  115. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/spidyan.py +0 -0
  116. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/spinladder.py +0 -0
  117. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/spinops.py +0 -0
  118. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/spinsystem.py +0 -0
  119. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/stackplot.py +0 -0
  120. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/stev.py +0 -0
  121. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/stochtraj_diffusion.py +0 -0
  122. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/stochtraj_jump.py +0 -0
  123. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/strainwidth.py +0 -0
  124. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/transmitter.py +0 -0
  125. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin/utils.py +0 -0
  126. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin.egg-info/dependency_links.txt +0 -0
  127. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin.egg-info/requires.txt +0 -0
  128. {torchspin-0.6.2 → torchspin-0.6.4}/torchspin.egg-info/top_level.txt +0 -0
@@ -6,6 +6,44 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.6.4] — 2026-11-09
10
+
11
+ ### Fixed
12
+
13
+ - **The 0.6.3 thread fix did not apply when torch was imported before
14
+ torchspin**, the usual order in scripts (`import torch` first). The OpenMP
15
+ runtime had already read `OMP_WAIT_POLICY`, so fits stayed slow with more
16
+ threads. Now:
17
+ - esfit's process workers and `torchspin.ml.simulate_batch` workers always
18
+ start with `OMP_WAIT_POLICY=PASSIVE` (unless the user set a value), since
19
+ each worker loads its own runtime;
20
+ - when it is too late for the current process (torch loaded first, variable
21
+ unset, Linux, more than one torch thread), `import torchspin` warns once
22
+ with the fix: import torchspin first, or `export OMP_WAIT_POLICY=PASSIVE`.
23
+ See `docs/pitfalls.md`, "Threads and performance".
24
+
25
+ ## [0.6.3] — 2026-11-08
26
+
27
+ ### Fixed
28
+
29
+ - **Fits got slower when threads were added on many-core Linux machines.**
30
+ After each parallel region torch's OpenMP threads spin-wait, and a fit runs
31
+ many small spectra, so the Python thread and torchspin's worker threads
32
+ competed with spinning threads for the cores. On a 224-core Linux node one
33
+ fit-model call (nitroxide, GridSize 31×4) took 84 ms on 1 thread and 554 ms
34
+ on 8; the 4-parameter levmar fit benchmark took 3.6 s on 1 thread and 11.0 s
35
+ on 8. `import torchspin` now sets `OMP_WAIT_POLICY=PASSIVE` (idle threads
36
+ sleep), which brings the 8-thread call to 93 ms. The OpenMP runtime reads the
37
+ variable once, when torch loads, so this takes effect only when torchspin is
38
+ imported before torch; an explicit user setting is never changed. See
39
+ `docs/pitfalls.md`, "Threads and performance".
40
+
41
+ Measured with paired A/B runs (default vs PASSIVE, interleaved, pinned) on
42
+ all 13 benchmark workloads at 1–64 threads, on a 224-core cluster node and
43
+ a 64-core workstation. At 8 threads the 20-call fit loop went from 9.5 to
44
+ 2.4 s and from 3.3 to 2.2 s, and the levmar fit from 13.2 to 4.1 s and from
45
+ 5.8 to 3.4 s. No workload became measurably slower at any thread count.
46
+
9
47
  ## [0.6.2] — 2026-11-08
10
48
 
11
49
  Bug fixes found while running the GPU tests on a CUDA host.
@@ -2,7 +2,7 @@ cff-version: 1.2.0
2
2
  message: "If you use torchspin in your research, please cite both torchspin and the upstream EasySpin paper."
3
3
  title: "torchspin: Differentiable PyTorch port of EasySpin for EPR spectroscopy"
4
4
  type: software
5
- version: "0.6.2"
5
+ version: "0.6.4"
6
6
  date-released: "2026-11-08"
7
7
  license: MIT
8
8
  authors:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: torchspin
3
- Version: 0.6.2
3
+ Version: 0.6.4
4
4
  Summary: Differentiable PyTorch port of EasySpin - EPR/ESR spin Hamiltonian and spectrum simulation
5
5
  Author-email: Alec Follmer <ahfollmer@ucdavis.edu>
6
6
  Maintainer-email: Alec Follmer <ahfollmer@ucdavis.edu>
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "torchspin"
7
- version = "0.6.2"
7
+ version = "0.6.4"
8
8
  description = "Differentiable PyTorch port of EasySpin - EPR/ESR spin Hamiltonian and spectrum simulation"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -25,7 +25,13 @@ try:
25
25
  __version__ = _pkg_version("torchspin")
26
26
  except _PkgNotFound:
27
27
  # Editable install during development, or version metadata unavailable.
28
- __version__ = "0.6.2+dev"
28
+ __version__ = "0.6.4+dev"
29
+
30
+ # Idle OpenMP threads must sleep, not spin-wait (see torchspin/_omp.py and
31
+ # docs/pitfalls.md, "Threads and performance"). This has to run before anything
32
+ # imports torch; if torch is already loaded it can only warn.
33
+ from torchspin import _omp
34
+ _omp.configure_at_import()
29
35
 
30
36
  from torchspin._compile import maybe_compile, set_compile_enabled, is_compile_available
31
37
  from torchspin.autograd import differentiable_spectrum
@@ -0,0 +1,54 @@
1
+ """OpenMP wait policy: idle torch threads should sleep, not spin.
2
+
3
+ torch's OpenMP threads spin-wait after every parallel region by default. A fit
4
+ evaluates many small spectra, so the Python thread and torchspin's own worker
5
+ threads end up competing with spinning threads for the cores, and on many-core
6
+ Linux machines a fit ran several times slower with 8 threads than with 1.
7
+ ``OMP_WAIT_POLICY=PASSIVE`` makes idle threads sleep. The OpenMP runtime reads it
8
+ once, when torch loads it, so it must be in the environment before torch is
9
+ imported. This module must not import torch at load time.
10
+ """
11
+ from __future__ import annotations
12
+
13
+ import contextlib
14
+ import os
15
+ import sys
16
+ import warnings
17
+
18
+ VAR = 'OMP_WAIT_POLICY'
19
+
20
+ _HINT = ("torch was imported before torchspin, so torchspin could not set {var}=PASSIVE; "
21
+ "idle OpenMP threads will spin-wait, which can make fits several times slower "
22
+ "with more than one thread. Import torchspin first, or set the variable before "
23
+ "Python starts: export {var}=PASSIVE (any explicit value silences this warning).")
24
+
25
+
26
+ def configure_at_import() -> None:
27
+ """Called by ``torchspin/__init__`` before anything imports torch."""
28
+ if 'torch' not in sys.modules:
29
+ os.environ.setdefault(VAR, 'PASSIVE')
30
+ return
31
+ import torch
32
+ if should_warn(True, os.environ.get(VAR), sys.platform, torch.get_num_threads()):
33
+ warnings.warn(_HINT.format(var=VAR), RuntimeWarning, stacklevel=3)
34
+
35
+
36
+ def should_warn(torch_loaded: bool, value, platform: str, n_threads: int) -> bool:
37
+ """Warn only where it matters: torch already loaded, nothing set, Linux, threads > 1."""
38
+ return bool(torch_loaded and value is None and platform.startswith('linux') and n_threads > 1)
39
+
40
+
41
+ @contextlib.contextmanager
42
+ def passive_for_children():
43
+ """Make processes spawned inside this block start with ``OMP_WAIT_POLICY=PASSIVE``.
44
+
45
+ A spawned worker loads its own OpenMP runtime, so it gets the policy even when
46
+ the parent imported torch too early. An explicit user value is passed on unchanged.
47
+ """
48
+ had = VAR in os.environ
49
+ os.environ.setdefault(VAR, 'PASSIVE')
50
+ try:
51
+ yield
52
+ finally:
53
+ if not had:
54
+ os.environ.pop(VAR, None)
@@ -1542,7 +1542,9 @@ def _get_pool(n_proc: int, per: int):
1542
1542
  for k in saved:
1543
1543
  os.environ[k] = str(per)
1544
1544
  try:
1545
- pool = mp.get_context('spawn').Pool(n_proc, initializer=_pool_init, initargs=(per,))
1545
+ from torchspin._omp import passive_for_children
1546
+ with passive_for_children():
1547
+ pool = mp.get_context('spawn').Pool(n_proc, initializer=_pool_init, initargs=(per,))
1546
1548
  finally:
1547
1549
  for k, v in saved.items():
1548
1550
  if v is None:
@@ -254,7 +254,10 @@ def simulate_batch(simulator, template: SpinSystem, exp, opt, spec: ParamSpec, p
254
254
  ctx = mp.get_context('spawn')
255
255
  tk = _template_kwargs(template)
256
256
  jobs = [(simulator, tk, spec, exp, opt, params[i].detach().numpy(), sim_kwargs) for i in range(n)]
257
- with ctx.Pool(workers) as pool:
257
+ from torchspin._omp import passive_for_children
258
+ with passive_for_children():
259
+ pool = ctx.Pool(workers)
260
+ with pool:
258
261
  res = pool.map(_worker, jobs)
259
262
  x = torch.as_tensor(res[0][0])
260
263
  return x, torch.stack([torch.as_tensor(r[1]) for r in res])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: torchspin
3
- Version: 0.6.2
3
+ Version: 0.6.4
4
4
  Summary: Differentiable PyTorch port of EasySpin - EPR/ESR spin Hamiltonian and spectrum simulation
5
5
  Author-email: Alec Follmer <ahfollmer@ucdavis.edu>
6
6
  Maintainer-email: Alec Follmer <ahfollmer@ucdavis.edu>
@@ -10,6 +10,7 @@ torchspin/_cardamom_propagatedm.py
10
10
  torchspin/_cardamom_utils.py
11
11
  torchspin/_compile.py
12
12
  torchspin/_linalg.py
13
+ torchspin/_omp.py
13
14
  torchspin/_rng.py
14
15
  torchspin/angmom.py
15
16
  torchspin/autograd.py
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes