trnsolver 0.20.0__tar.gz → 0.22.0__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 (108) hide show
  1. {trnsolver-0.20.0 → trnsolver-0.22.0}/CHANGELOG.md +567 -0
  2. {trnsolver-0.20.0 → trnsolver-0.22.0}/CLAUDE.md +22 -14
  3. {trnsolver-0.20.0 → trnsolver-0.22.0}/PKG-INFO +57 -21
  4. {trnsolver-0.20.0 → trnsolver-0.22.0}/README.md +55 -19
  5. trnsolver-0.22.0/docs/api/eigen.md +122 -0
  6. {trnsolver-0.20.0 → trnsolver-0.22.0}/docs/api/factor.md +4 -2
  7. trnsolver-0.22.0/docs/api/iterative.md +119 -0
  8. trnsolver-0.22.0/docs/api/nki.md +118 -0
  9. {trnsolver-0.20.0 → trnsolver-0.22.0}/docs/architecture.md +20 -12
  10. {trnsolver-0.20.0 → trnsolver-0.22.0}/docs/benchmarks.md +31 -4
  11. trnsolver-0.22.0/docs/index.md +34 -0
  12. {trnsolver-0.20.0 → trnsolver-0.22.0}/docs/installation.md +13 -4
  13. {trnsolver-0.20.0 → trnsolver-0.22.0}/docs/quickstart.md +8 -1
  14. trnsolver-0.22.0/examples/df_store.py +397 -0
  15. trnsolver-0.22.0/examples/scf_df_mp2.py +393 -0
  16. trnsolver-0.22.0/examples/scf_df_rhf.py +1710 -0
  17. {trnsolver-0.20.0 → trnsolver-0.22.0}/pyproject.toml +4 -2
  18. trnsolver-0.22.0/scripts/bench_eager_handle.py +118 -0
  19. trnsolver-0.22.0/scripts/bench_gp_precond.py +321 -0
  20. trnsolver-0.22.0/scripts/bench_occupied_subspace.py +227 -0
  21. {trnsolver-0.20.0 → trnsolver-0.22.0}/scripts/bench_scf.py +78 -6
  22. trnsolver-0.22.0/scripts/bench_scf_ladder.py +418 -0
  23. trnsolver-0.22.0/tests/conftest.py +82 -0
  24. trnsolver-0.22.0/tests/test_bench_scf_ladder.py +98 -0
  25. trnsolver-0.22.0/tests/test_block_neuron.py +135 -0
  26. trnsolver-0.22.0/tests/test_cg_block.py +564 -0
  27. trnsolver-0.22.0/tests/test_complex_rhs.py +77 -0
  28. trnsolver-0.22.0/tests/test_conformance.py +1512 -0
  29. {trnsolver-0.20.0 → trnsolver-0.22.0}/tests/test_eigh_cutover.py +27 -0
  30. {trnsolver-0.20.0 → trnsolver-0.22.0}/tests/test_factor.py +71 -0
  31. trnsolver-0.22.0/tests/test_hermitian_batch.py +278 -0
  32. {trnsolver-0.20.0 → trnsolver-0.22.0}/tests/test_iterative.py +74 -0
  33. trnsolver-0.22.0/tests/test_iterative_autograd.py +72 -0
  34. trnsolver-0.22.0/tests/test_iterative_rhs_scale.py +53 -0
  35. {trnsolver-0.20.0 → trnsolver-0.22.0}/tests/test_jacobi.py +38 -0
  36. trnsolver-0.22.0/tests/test_jacobi_onezero_arg.py +126 -0
  37. trnsolver-0.22.0/tests/test_kernel_dtype_guard.py +1100 -0
  38. {trnsolver-0.20.0 → trnsolver-0.22.0}/tests/test_native_dispatch.py +294 -5
  39. {trnsolver-0.20.0 → trnsolver-0.22.0}/tests/test_nki_native.py +71 -0
  40. trnsolver-0.22.0/tests/test_nki_tail_audit.py +279 -0
  41. trnsolver-0.22.0/tests/test_orthogonalize.py +314 -0
  42. trnsolver-0.22.0/tests/test_scf_df_mp2.py +141 -0
  43. trnsolver-0.22.0/tests/test_scf_df_rhf.py +724 -0
  44. trnsolver-0.22.0/tests/test_subspace.py +540 -0
  45. trnsolver-0.22.0/tests/test_trace_cache_safety.py +563 -0
  46. {trnsolver-0.20.0 → trnsolver-0.22.0}/trnsolver/__init__.py +31 -1
  47. trnsolver-0.22.0/trnsolver/block.py +757 -0
  48. {trnsolver-0.20.0 → trnsolver-0.22.0}/trnsolver/eigen.py +189 -70
  49. {trnsolver-0.20.0 → trnsolver-0.22.0}/trnsolver/factor.py +91 -17
  50. {trnsolver-0.20.0 → trnsolver-0.22.0}/trnsolver/iterative.py +135 -13
  51. {trnsolver-0.20.0 → trnsolver-0.22.0}/trnsolver/nki/_native.py +62 -6
  52. {trnsolver-0.20.0 → trnsolver-0.22.0}/trnsolver/nki/dispatch.py +486 -4
  53. {trnsolver-0.20.0 → trnsolver-0.22.0}/trnsolver/nki/jacobi.py +52 -20
  54. trnsolver-0.22.0/trnsolver/nki/subspace.py +462 -0
  55. trnsolver-0.22.0/trnsolver/orthogonalize.py +223 -0
  56. trnsolver-0.22.0/trnsolver/subspace.py +638 -0
  57. {trnsolver-0.20.0 → trnsolver-0.22.0}/trnsolver.egg-info/PKG-INFO +57 -21
  58. {trnsolver-0.20.0 → trnsolver-0.22.0}/trnsolver.egg-info/SOURCES.txt +26 -1
  59. {trnsolver-0.20.0 → trnsolver-0.22.0}/trnsolver.egg-info/requires.txt +1 -1
  60. trnsolver-0.20.0/docs/api/eigen.md +0 -36
  61. trnsolver-0.20.0/docs/api/iterative.md +0 -37
  62. trnsolver-0.20.0/docs/api/nki.md +0 -61
  63. trnsolver-0.20.0/docs/index.md +0 -33
  64. trnsolver-0.20.0/examples/scf_df_rhf.py +0 -987
  65. trnsolver-0.20.0/tests/conftest.py +0 -51
  66. trnsolver-0.20.0/tests/test_scf_df_rhf.py +0 -207
  67. {trnsolver-0.20.0 → trnsolver-0.22.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  68. {trnsolver-0.20.0 → trnsolver-0.22.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  69. {trnsolver-0.20.0 → trnsolver-0.22.0}/.github/pull_request_template.md +0 -0
  70. {trnsolver-0.20.0 → trnsolver-0.22.0}/.github/workflows/ci.yml +0 -0
  71. {trnsolver-0.20.0 → trnsolver-0.22.0}/.github/workflows/neuron.yml +0 -0
  72. {trnsolver-0.20.0 → trnsolver-0.22.0}/.github/workflows/notify-umbrella.yml +0 -0
  73. {trnsolver-0.20.0 → trnsolver-0.22.0}/.github/workflows/publish.yml +0 -0
  74. {trnsolver-0.20.0 → trnsolver-0.22.0}/.gitignore +0 -0
  75. {trnsolver-0.20.0 → trnsolver-0.22.0}/.pre-commit-config.yaml +0 -0
  76. {trnsolver-0.20.0 → trnsolver-0.22.0}/CODE_OF_CONDUCT.md +0 -0
  77. {trnsolver-0.20.0 → trnsolver-0.22.0}/CONTRIBUTING.md +0 -0
  78. {trnsolver-0.20.0 → trnsolver-0.22.0}/LICENSE +0 -0
  79. {trnsolver-0.20.0 → trnsolver-0.22.0}/benchmarks/bench_cuda.py +0 -0
  80. {trnsolver-0.20.0 → trnsolver-0.22.0}/benchmarks/bench_solver.py +0 -0
  81. {trnsolver-0.20.0 → trnsolver-0.22.0}/benchmarks/conftest.py +0 -0
  82. {trnsolver-0.20.0 → trnsolver-0.22.0}/docs/aws_setup.md +0 -0
  83. {trnsolver-0.20.0 → trnsolver-0.22.0}/docs/developing_kernels.md +0 -0
  84. {trnsolver-0.20.0 → trnsolver-0.22.0}/examples/scf_eigen.py +0 -0
  85. {trnsolver-0.20.0 → trnsolver-0.22.0}/infra/terraform/README.md +0 -0
  86. {trnsolver-0.20.0 → trnsolver-0.22.0}/infra/terraform/gpu.tf +0 -0
  87. {trnsolver-0.20.0 → trnsolver-0.22.0}/infra/terraform/main.tf +0 -0
  88. {trnsolver-0.20.0 → trnsolver-0.22.0}/mkdocs.yml +0 -0
  89. {trnsolver-0.20.0 → trnsolver-0.22.0}/scripts/bench_jacobi.py +0 -0
  90. {trnsolver-0.20.0 → trnsolver-0.22.0}/scripts/bench_jacobi_multicore.py +0 -0
  91. {trnsolver-0.20.0 → trnsolver-0.22.0}/scripts/probe_large_n_split.py +0 -0
  92. {trnsolver-0.20.0 → trnsolver-0.22.0}/scripts/run_cuda_tests.sh +0 -0
  93. {trnsolver-0.20.0 → trnsolver-0.22.0}/scripts/run_neuron_tests.sh +0 -0
  94. {trnsolver-0.20.0 → trnsolver-0.22.0}/scripts/run_simulator_tests.sh +0 -0
  95. {trnsolver-0.20.0 → trnsolver-0.22.0}/scripts/stop_neuron_ci.sh +0 -0
  96. {trnsolver-0.20.0 → trnsolver-0.22.0}/setup.cfg +0 -0
  97. {trnsolver-0.20.0 → trnsolver-0.22.0}/tests/test_compile.py +0 -0
  98. {trnsolver-0.20.0 → trnsolver-0.22.0}/tests/test_dtype.py +0 -0
  99. {trnsolver-0.20.0 → trnsolver-0.22.0}/tests/test_eigen.py +0 -0
  100. {trnsolver-0.20.0 → trnsolver-0.22.0}/tests/test_eigh_neuron.py +0 -0
  101. {trnsolver-0.20.0 → trnsolver-0.22.0}/tests/test_nki_compile.py +0 -0
  102. {trnsolver-0.20.0 → trnsolver-0.22.0}/tests/test_nki_sim.py +0 -0
  103. {trnsolver-0.20.0 → trnsolver-0.22.0}/trnsolver/_jacobi.py +0 -0
  104. {trnsolver-0.20.0 → trnsolver-0.22.0}/trnsolver/nki/__init__.py +0 -0
  105. {trnsolver-0.20.0 → trnsolver-0.22.0}/trnsolver/nki/eigh_pool.py +0 -0
  106. {trnsolver-0.20.0 → trnsolver-0.22.0}/trnsolver.egg-info/dependency_links.txt +0 -0
  107. {trnsolver-0.20.0 → trnsolver-0.22.0}/trnsolver.egg-info/top_level.txt +0 -0
  108. {trnsolver-0.20.0 → trnsolver-0.22.0}/uv.lock +0 -0
@@ -7,6 +7,573 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.22.0] — 2026-11-04
11
+
12
+ Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron) — see trnsci/trnsci#35.
13
+
14
+ Headline: `cg_block` / `cg_block_ir` block CG and pivoted-Cholesky low-rank preconditioners for matrix-free operators (#97, #114); out-of-core and streamed DF-RHF + DF-MP2 at large basis on Trn2 (#15, trnsci/trnsci#115); cached eager NKI handles; and the trnsci float64 policy with a dtype guard at the kernel boundary. The `[dev]` extra now requires trntensor>=0.24 (`AuxStream`, trntensor#102).
15
+
16
+ ### Performance
17
+
18
+ - **Eager NKI kernel calls skip the per-call handle rebuild and the custom-op
19
+ layer (same fix as trnblas#92).** On the native path a `trnsolver::`
20
+ custom-op call cost about 0.1 ms of host time before the kernel was queued,
21
+ against 0.016 ms for aten. Most of it went to nki's `Kernel.__call__`,
22
+ which rebuilds the torch handle on every call, plus the `torch.library`
23
+ layer. `dispatch._launch` now calls a `torch_neuronx.wrap_nki` handle built
24
+ once per kernel; `static=` arguments (the Jacobi `onezero`) get the op
25
+ body's `int()`. On trn2 (LNC=2), a `matvec` launch drops from 0.121 to
26
+ 0.032 ms of issue time (e2e 0.203 to 0.130 ms) and a 128x128x32 `matmul`
27
+ from 0.123 to 0.032 ms (e2e 0.196 to 0.117 ms). `eigh` itself is host-bound
28
+ and gains less: n=32 on the Householder kernels 86.7 to 76.1 ms, a 4x32x32
29
+ Jacobi batch 6.10 to 5.95 ms. Results are bit-identical. `torch.compile`,
30
+ requires-grad, int64 and tensor-subclass inputs keep the custom op, as
31
+ does the folded `occupied_subspace` pass (`subspace_step`) for now.
32
+ `TRNSOLVER_NKI_EAGER_HANDLE=0` turns this off;
33
+ `scripts/bench_eager_handle.py` measures it.
34
+
35
+ ### Added
36
+
37
+ - **`run_scf(guess=...)`: a minao initial guess, or given occupied orbitals (trnsci/trnsci#115).**
38
+ - `"core"` is the default and keeps the old behaviour.
39
+ - `"minao"` takes PySCF's superposed atomic densities (`minao_density`) as natural orbitals in the kept orthonormal basis (`guess_orbitals`).
40
+ - An `(n, nocc)` tensor is S-orthonormalised and used directly, for example to restart.
41
+ - Why: from the core guess, fp32 DIIS did not converge for alkane69 / cc-pVDZ (n_ao 1666) in 40 iterations, on either `subspace` or `orth`, with the energy wandering between -1900 and +9500 Eh. J and K matched the CPU to 5e-6 relative. From minao it converged in 6 iterations.
42
+ - `bench_scf_ladder.py` now defaults to `--guess minao`. `scf_df_rhf.py` and `scf_df_mp2.py` take `--guess`.
43
+ - **`pivoted_cholesky(..., block=, sub_fn=, relax=)`: block row requests
44
+ for the pivoted-Cholesky build (#114).**
45
+ - A round takes the `block` largest remaining diagonals as candidates and
46
+ picks pivots greedily from their exact c × c Schur complement. It
47
+ accepts a candidate while its diagonal is at least `relax` times the
48
+ largest one outside the round. With `relax=1` that is the one-row
49
+ algorithm's pivot sequence (up to ties).
50
+ - The accepted pivots' rows come from one `rows_fn` call, so a device
51
+ kernel evaluation (`trnsparse.kernel_matmul(X, X[idx], I)`) makes one
52
+ launch per round. One GEMM gives the Schur rows and one triangular
53
+ solve the new columns, in float64 on the host, independent of the
54
+ device's reduction order.
55
+ - `sub_fn(idx)` gives `K[idx][:, idx]`, so only accepted rows are
56
+ requested. Without it, every candidate row is.
57
+ - GP kernel (RBF, ℓ = 0.15, d = 3, rank 1024, CPU), with
58
+ `block=512, relax=0.5`:
59
+ - n = 10⁵: 26 calls instead of 1024, 0.85 s against 4.1 s;
60
+ - n = 10⁶: 61 calls, 11.3 s against 34.6 s, with fp32 kernel rows. Two
61
+ host threads; the factor adds 4.5 s (`"host64"`) or 5.2 s
62
+ (`"projected"`).
63
+ - CG iteration counts are unchanged at n = 2×10⁴, 5×10⁴ and 10⁵.
64
+ - The default `block=1` keeps one row per step. The factor is now
65
+ stored row-major internally, so appending a column is stride-1.
66
+ - **`PivotedLowRankPreconditioner(..., apply="projected")`: an fp32
67
+ on-device apply that does not cancel (#114).**
68
+ - Q is an orthonormal basis of L's range, from the Gram matrix LᵀL in
69
+ float64 on the host (one n × k × k GEMM; no n × k QR).
70
+ - The apply is `Q (Σ² + sI)⁻¹ QᵀV + (I − QQᵀ)V/s`, with the projection
71
+ applied twice: four (n × k) GEMMs on the device, no host round trip.
72
+ - The single-pass Woodbury form (`"native"`) leaves an error of about
73
+ u·√k·‖V‖ along the captured subspace, which the 1/s weight amplifies.
74
+ The second pass removes it. What remains is orthogonal to Q and
75
+ perturbs the preconditioner only to second order.
76
+ - CPU, fp32 operator, R = 33, rank 1024, tol 1e-6, `"host64"` against
77
+ `"projected"`:
78
+ - n = 2×10⁴, noise 1e-2: 10 and 10 iterations. Posterior mean against
79
+ scipy `cho_solve`: 6.0e-5 and 6.1e-5.
80
+ - n = 2×10⁴, noise 1e-3: 30 and 30.
81
+ - n = 5×10⁴: 20 and 20.
82
+ - n = 10⁵: 20 and 20 (column maximum 15 and 15). The posterior means
83
+ differ by 6.4e-5.
84
+ - `"native"` does not converge in 150–200 iterations on the same cases.
85
+ - Opt-in. `apply="auto"` is unchanged: `"host64"` for a non-float64 L.
86
+ - `tests/test_block_neuron.py` holds the device gates: apply accuracy on
87
+ the device, CG iterations against `"host64"`, and a build from device
88
+ rows.
89
+ - **`cg_block`: block CG for many right-hand sides on matrix-free operators (#97).**
90
+ - R independent preconditioned CG recurrences, one per column of an (n, R)
91
+ B, driven by ONE operator call A(P) on the whole block per iteration.
92
+ The GP exemplar (trnsci/trnsci#109) gets the posterior-mean solve and
93
+ every log-det probe solve from the same applications.
94
+ - Converged columns freeze through `torch.where` masks (α = β = 0) and the
95
+ block keeps its shape. Zero columns return zero, converged at
96
+ iteration 0.
97
+ - The host reads the convergence state only every `check_every`
98
+ iterations. That changes when the loop stops, never the solution.
99
+ - `info` has per-column iterations, the converged and breakdown masks,
100
+ the recurrence residual, and a true residual ‖B − A X‖ / ‖B‖ from one
101
+ extra call at the end. Report both: on an RBF kernel + 1e-4 I
102
+ (n = 2000), fp32 recurrence residuals of 1e-4 had true residuals of
103
+ 0.05–0.5.
104
+ - `return_coeffs=True` adds per-column α, β histories and r₀ᵀ M r₀.
105
+ - **`PivotedLowRankPreconditioner(..., apply="auto")` applies in float64 on
106
+ the host for a non-float64 L.** The Woodbury form V − W (Wᵀ V) cancels
107
+ (W Wᵀ is within s/λ of the identity on the captured subspace), so in fp32
108
+ the applied operator is wrong by up to u·√k·λ/s there. On a GP with
109
+ noise 1e-3 (n = 2×10⁴, rank 1024) fp32 preconditioned CG did not
110
+ converge in 150 iterations; with the host-float64 apply it converges in
111
+ 30, against 20 in full float64. `apply="native"` keeps the old
112
+ on-device path.
113
+ - **`cg_block_ir`:** fp32 inner `cg_block` inside a float64 host refinement
114
+ loop, the same shape as `gmres_ir`. Returns a float64 host X and
115
+ per-outer-step true residuals. With the pivoted preconditioner it reaches
116
+ 1e-10 relative residual on that matrix where fp32 alone stalls.
117
+ - **`pivoted_cholesky(diag_fn, rows_fn, rank)` and
118
+ `pivoted_lowrank_preconditioner(diag_fn, rows_fn, rank, shift)`:** rank-k
119
+ greedy pivoted Cholesky from the diagonal plus one row of K per step. The
120
+ preconditioner applies (L Lᵀ + shift I)⁻¹ as two (n × k) GEMMs, through
121
+ the low-rank-plus-diagonal inverse identity (k × k factor built once, in
122
+ float64 on the host). It also has `logdet()` (matrix determinant lemma)
123
+ and `sample()` (probes from N(0, L Lᵀ + shift I)). On the RBF matrices
124
+ above, rank 100 cuts CG iterations by about 10×.
125
+ - **`lanczos_tridiag_from_cg` and `slq_logdet`:** Lanczos tridiagonals from
126
+ CG coefficients, and stochastic Lanczos quadrature for log det(A) over one
127
+ `cg_block` of probes. Probes are Rademacher, or N(0, P) when preconditioned
128
+ (log det P is then exact and only the remainder is estimated). Within 4
129
+ standard errors of `torch.linalg.slogdet` at n = 1024 with 64 probes.
130
+
131
+ - **`scripts/bench_scf_ladder.py`: a DF-RHF + DF-MP2 size ladder (#15).**
132
+ - **Systems.** Linear alkanes C_k H_{2k+2} and k-water clusters, both
133
+ synthetic geometries, in cc-pVDZ, aug-cc-pVDZ and cc-pVTZ with
134
+ -jkfit. k is picked for each basis to land nearest 500, 1000, 1658
135
+ (C40H82 / aug-cc-pVDZ), 2500 and 3500 AOs, which gives 30 systems.
136
+ - **`--dry-run`** computes no integrals. Per system it gives:
137
+ - sizes, the fp32 B, PySCF's in-core build memory and B_ia;
138
+ - logical cores and chips needed to hold B resident (20 GB per 24 GiB
139
+ core);
140
+ - the window plan: trn2.3xlarge resident, trn2.3xlarge streaming from
141
+ host RAM or NVMe, or trn2.48xlarge resident on N chips;
142
+ - rough per-iteration and MP2 times, scaled from the window-3
143
+ measurements.
144
+ - **Otherwise** each system up to `--max-nao` runs end to end:
145
+ - the out-of-core build (time, peak RSS);
146
+ - the fp32 SCF (noise-aware convergence; `--solver auto` picks
147
+ `subspace` with `refresh=None` above 1200 AOs, as window 3 found);
148
+ - the float64 E_HF at the SCF orbitals and DF-MP2;
149
+ - PySCF DF-RHF + DF-MP2 on the same jkfit basis, with a matched
150
+ linear-dependency threshold, up to `--ref-max-nao`.
151
+ - Output is a `RESULT` JSON line per system and a markdown table.
152
+ `--out` saves the rows.
153
+
154
+ - **`examples/scf_df_mp2.py`: DF-MP2 on top of the converged DF-RHF (#15).**
155
+ - `canonical_orbitals` builds one Fock matrix at the SCF's occupied orbitals
156
+ (streamed J/K, float64 on the host by default) and diagonalises it in the
157
+ orthogonalizer's basis.
158
+ - `df_mp2` forms `B_ia^P` aux chunk by aux chunk with
159
+ `trntensor.AuxStream.ao_to_mo`, into host memory or a `.npy` memmap
160
+ (`bia_path`). The energy comes from `trntensor.mp2_energy` when `B_ia`
161
+ fits one device, else from `trntensor.mp2_energy_blocked` over occupied
162
+ blocks, with pairs dealt over `devices`.
163
+ - `run_mp2` chains them and returns E_HF (float64 at the SCF orbitals),
164
+ E_corr, E_total and stage times. `frozen` freezes the lowest occupied
165
+ orbitals.
166
+ - It uses the SCF's jkfit basis, the same one PySCF's `mp.dfmp2.DFMP2`
167
+ uses on a density-fitted mean field.
168
+ - Against PySCF: water/cc-pVDZ fp64 is within 1.1e-9 Eh of E_MP2. A fp32
169
+ SCF with a fp32 transform and energy is within 2.7e-7 Eh at C4H10
170
+ (`tests/test_scf_df_mp2.py`).
171
+ - A fp32 canonical Fock costs 4e-6 Eh there, which is why the float64
172
+ host Fock is the default (`--fock-on-device` to override).
173
+
174
+ - **`examples/scf_df_rhf.py`: J/K streamed over aux chunks (#15).**
175
+ `DFJK(stream=True)` (and `run_scf(jk_stream=..., jk_resident_gb=...,
176
+ jk_prefetch=...)`) hands B to `trntensor.AuxStream` (trntensor#102).
177
+ - Aux chunks are under 2 GiB, below the 4 GiB transposed-LHS limit of
178
+ aws-neuron-sdk#1457, and dealt round-robin over `jk_devices`
179
+ (`neuron:0..3`).
180
+ - Chunks are kept resident up to `DEVICE_RESIDENT_GB` = 20 GB per
181
+ NeuronCore (one LNC=2 core has 24 GiB) and uploaded every iteration
182
+ otherwise. A loader thread works one chunk ahead per device, so the
183
+ upload overlaps the kernels on the previous chunk.
184
+ - J and K come from one pass: `df_coulomb` + `df_exchange` per chunk, with
185
+ each streamed chunk uploaded once.
186
+ - The default streams an out-of-core `DFStore` B from its memory-mapped
187
+ chunk files when trntensor has `AuxStream`. In-memory B keeps the
188
+ resident blocks as before.
189
+ - The float64 re-evaluation `energy_at_orbitals` streams too, so it no
190
+ longer needs a float64 copy of B.
191
+ - `info["stream"]` records the chunk count, width, resident count and the
192
+ bytes streamed / wait / load time per iteration.
193
+ - Flags: `--jk-stream`, `--resident-gb` and `--jk-devices` on the example;
194
+ `--jk-stream`, `--resident-gb` and `--prefetch` on `bench_scf.py`.
195
+ - J/K are identical to the block path on one and three devices,
196
+ all-streamed or all-resident, with or without host pack (CPU tests).
197
+ The tests skip without `AuxStream`.
198
+
199
+ - **`examples/df_store.py`: out-of-core DF integrals (#15).** At n_ao 1658
200
+ PySCF's in-core build held two float64 copies of B (133 GB, over the 124 GB
201
+ host), and window 3 had to go through a 67 GB HDF5 file and a separate fp32
202
+ conversion.
203
+ - `build_pyscf_store` computes `B = (mn|P) L^{-T}` a block of AO shell rows
204
+ at a time (PySCF `int3c2e`, `aosym="s2ij"`, then a triangular solve with
205
+ the metric's Cholesky factor, or PySCF's eigen fallback) and writes each
206
+ block's packed rows straight into the chunk files. Peak host memory is
207
+ one row block (1 GiB by default) plus the metric. It is the same tensor as
208
+ `df.incore.cholesky_eri` (CPU test, 1e-12).
209
+ - The store is a directory: `meta.json`, `system.pt` (H, S, nocc, e_nuc,
210
+ reference) and one C-contiguous `(npair, nq)` `.npy` file per aux chunk.
211
+ The chunks are 128-multiples under 2 GiB, below the 4 GiB
212
+ transposed-LHS limit (aws-neuron-sdk#1457). Each is one sequential read,
213
+ and memory-mapped without a copy.
214
+ - `DFStore` serves `B.shape`, `B.dtype` and `B[:, q0:q1]`, so `DFJK`
215
+ takes it as is, plus per-chunk loaders for streaming. fp32 by default:
216
+ 33.4 GB at n_ao 1658.
217
+ - The synthetic H2-lattice integrals are generated in pair-row blocks too
218
+ (`h2_lattice(n, store=...)`).
219
+ - **`make_system` goes out of core by default above `OUTCORE_GB` = 16 GB of
220
+ estimated build memory** (`outcore=True|False|None`). Stores go under
221
+ `store_dir` (default `$TRNSCI_DF_DIR` or `~/.cache/trnsci/df`), and a
222
+ finished store is reused without recomputing anything. With an
223
+ out-of-core build the PySCF reference energy is off unless asked for, and
224
+ uses PySCF's own DF build. `--outcore`, `--store-dir` and `--store-dtype`
225
+ on the example; `--outcore` and `--store-dir` on `bench_scf.py`.
226
+ - **`pyscf:water<k>`**: a synthetic cluster of k water molecules on a 3.1 Å
227
+ cubic lattice with seeded orientations. `pyscf_mol` / `pyscf_sizes` give
228
+ the molecule and its basis sizes without computing integrals.
229
+
230
+ ### Changed
231
+
232
+ - **`bench_scf_ladder.py --dry-run` uses the window-4 Trn2 measurements (trnsci/trnsci#115).**
233
+ - The build is scaled by npair · naux² (the triangular solve), from 1215 s on 2 pinned host threads at n_ao 1658. Before, it was npair · naux from the Mac's 12 threads, about 10× low on the box.
234
+ - A streamed layout keeps the per-core budget less three chunks of headroom resident, about 60 GB per chip, not 80. That matches #109's `default_resident_bytes`.
235
+ - DF-MP2 is costed at the measured 5.8e13 multiply-adds/s per chip.
236
+ - At water61 / aug-cc-pVDZ the planner now gives 54 GB/it streamed (measured 49.7 under the earlier two-chunk rule), 4.9 s/it (measured ≈ 6), MP2 71 s (measured 69) and a 6290 s build (10051 s measured, sharing the CPUs).
237
+
238
+ - **float64 policy for the NKI kernels (#89, trnsci/trnsci#35; the same rule
239
+ across the trnsci suite).** Every trnsolver kernel computes in FP32, and
240
+ Trainium computes float64 at FP32 precision on device. Where an FP32
241
+ input would run the kernels (`eigh` on the Householder path,
242
+ `eigh_generalized` through it, `eigh_randomized`, `eigh(method="jacobi")`,
243
+ the auto Jacobi region, `occupied_subspace`):
244
+ - **backend `auto`: float64 under `auto` now computes in torch at float64
245
+ accuracy (previously cast to fp32 on the NKI path).** `eigh` and
246
+ `eigh_generalized` take `torch.linalg.eigh`, the Jacobi entries the torch
247
+ Jacobi, the auto Jacobi region the default aten dispatch,
248
+ `occupied_subspace` its torch filter, `eigh_randomized` `torch.matmul`.
249
+ Affected: `eigh` / `eigh_generalized` float64 on the Householder path ran
250
+ the FP32 kernels in 0.21.0 (#84; before that, 0.4.0 through 0.20.0, it
251
+ gave garbage); this lands in 0.22.0.
252
+ - **backend `nki`: float64 runs the FP32 kernels and returns float64, with
253
+ one `UserWarning` per op** (the first call of each op) saying that
254
+ precision is reduced to fp32. This now also applies to the Jacobi
255
+ kernels and `occupied_subspace` (through 0.21.0 they took torch for
256
+ float64) and to `eigh_randomized` (a compile error on Trn2 through
257
+ 0.21.0).
258
+ - **`TRNSOLVER_REQUIRE_NKI=1`: float64 raises `NotImplementedError` on every
259
+ kernel path**, under either backend, as trnblas does (trnblas#69). This
260
+ takes precedence over the `nki` cast. **Callers of
261
+ `eigh(method="jacobi")`, the auto Jacobi region and `occupied_subspace`
262
+ with float64 input under `TRNSOLVER_REQUIRE_NKI=1` now get
263
+ `NotImplementedError`** where through 0.21.0 they got a float64 torch
264
+ result; `eigh` / `eigh_generalized` float64 under it raise where 0.21.0
265
+ ran the FP32 kernels.
266
+ - **Result dtype:** always what the pytorch backend returns for the same
267
+ inputs, for float32, float64, bfloat16, float16 and mixed-dtype operands
268
+ (e.g. `eigh_generalized` with a float64 B), including after the FP32
269
+ kernels.
270
+ - **float64 on the `neuron` device is computed on the host under `auto`.**
271
+ Device aten computes float64 at fp32 precision (measured on Trn2), so
272
+ "torch at float64 accuracy" did not hold for device-resident input.
273
+ Every public op now copies a float64 / complex128 operand on the
274
+ `neuron` device to the host, computes there and returns the result on
275
+ the original device in float64 / complex128, with one `UserWarning` per
276
+ op ("float64 on the neuron device is computed on the host for float64
277
+ accuracy (device arithmetic is fp32); pass float32 to stay on device").
278
+ **`TRNSOLVER_FP64_ON_DEVICE=1` keeps device aten (fp32 precision)** for
279
+ callers who prefer speed. Host-resident float64 and backends `nki` /
280
+ `pytorch` are unchanged. **Under `TRNSOLVER_REQUIRE_NKI=1` a float64 /
281
+ complex128 operand on the `neuron` device now raises
282
+ `NotImplementedError` at every public op** (backends `auto` and `nki`,
283
+ no host copy, ahead of `TRNSOLVER_FP64_ON_DEVICE=1`). Before, the routes
284
+ with no kernel (`solve_spd`, `inv_spd`, `pinv`, `cg`, `gmres`, ...) ran
285
+ device aten at fp32 precision with no error. One decorator
286
+ (`nki.dispatch._fp64_host_guard`) holds the rule; the preconditioner
287
+ constructors (`jacobi_` / `block_jacobi_` / `ssor_preconditioner`), which
288
+ return closures, use `_fp64_host_preconditioner`: the closure computes on
289
+ the host and returns `z` on `r`'s device. The block CG routes (#97)
290
+ follow the same rule: `cg_block` is guarded; `pivoted_cholesky` builds
291
+ in float64 on the host for every input (#117, one row or batched with
292
+ `rows_fn` / `sub_fn`), so a device-resident float64 diagonal needs no
293
+ extra host route and L returns to its device; and
294
+ `PivotedLowRankPreconditioner`'s `apply="auto"` and `apply="projected"`
295
+ (#117, an on-device apply) pick `"host64"` for a float64 L on the device
296
+ (one `UserWarning`). `cg_block_ir` already refines in float64 on the host.
297
+ The library has no complex kernels; complex input keeps its aten / torch
298
+ routes (#65). Paths where an FP32 input would not run a kernel either (the
299
+ aten cutover, the XLA lineage for Jacobi) are unchanged.
300
+
301
+ - **`examples/scf_df_rhf.py`: a noise-aware convergence test for fp32
302
+ (#15).** `run_scf(conv="auto"|"energy"|"density")`; `"auto"` keeps the
303
+ energy test in float64 and uses `"density"` otherwise.
304
+ - `"density"` stops when the commutator rms(FPS − SPF) < `d_tol` and the
305
+ density change rms(P_k − P_{k−1}) < `p_tol` (fp32 defaults 1e-5 and
306
+ 1e-5). The energy only has to be inside its own rounding noise:
307
+ |dE| < max(`e_tol`, `e_noise_mult` · σ_E), with σ_E = ε · ½ Σ|P||H + F|
308
+ computed on the device each iteration, in the same single host copy.
309
+ - Why: at |E| = 1562 Eh one fp32 ulp is 1.9e-4 Eh, and the energy sum
310
+ rounds above that, so a fixed energy delta (the old relative 2e-7 test)
311
+ sat at its noise floor at n_ao 1658.
312
+ - On the CPU it converges as fast as or faster than the energy test, with
313
+ the float64 energy at the fp32 orbitals within 1.4e-8 Eh of the fp64
314
+ run (h2-lattice:16/32, benzene/cc-pVDZ). With ±3e-5 Eh of injected
315
+ energy jitter the energy test never stops and the density test does
316
+ (test).
317
+ - Both norms are taken in the orthonormal basis of the kept subspace,
318
+ `Xᵀ(FPS − SPF)X` and `XᵀS dP S X`. In the AO basis, with functions dropped
319
+ by the orthogonalizer, the commutator keeps a floor along the dropped
320
+ directions: 4.7e-7 at a converged float64 C12H26 / aug-cc-pVDZ
321
+ (canonical 1e-6), which never passed the float64 1e-7 test and ran to
322
+ `max_iter`. In fp32, X's 1/sqrt(s_min) amplified the AO dP noise to
323
+ 4e-5. Now that system converges in 33 iterations in float64.
324
+ - The commutator threshold is noise-aware too:
325
+ max(`d_tol`, `d_noise_mult` · σ_d) with σ_d = ε max|F| max|X|. The fp32
326
+ floor there is 1.3e-4 against σ_d = 1.2e-4, and the float64 energy at
327
+ those orbitals is 4e-5 Eh above fp64. That is the fp32 conditioning
328
+ limit window 3 met at n_ao 1658.
329
+ - `info["history"]` holds per-iteration `dE`, `err_rms` and `dp_rms`;
330
+ `info["e_noise"]` the last σ_E. `--conv` on the example and
331
+ `bench_scf.py`.
332
+
333
+ - **`examples/scf_df_rhf.py`: `DFJK` packs P and unpacks J on the host above
334
+ 1e6 pairs (#87).** At n_ao = 1658 (npair 1.4e6) the two device gathers in
335
+ `DFJK.j` (`index_select` with npair and n² indices) compiled for over
336
+ 40 min each, so window 3 patched them out in the driver. Now
337
+ `DFJK(host_pack=None)` (and `run_scf(jk_host_pack=...)`,
338
+ `bench_scf.py --host-pack auto|on|off`) does that by default off the CPU
339
+ when npair > `HOST_PACK_NPAIR` = 1e6: an 11 MB copy each way per iteration
340
+ at that size. The J values are bit-identical to the device-gather path
341
+ (CPU test).
342
+
343
+ ### Fixed
344
+
345
+ - **`run_scf` releases its device integrals before it returns (trnsci/trnsci#115).**
346
+ The DFJK's resident chunks (or blocks) were left for the garbage collector.
347
+ A second `run_scf` on the same system, such as the ladder's `--warmup-iters` run
348
+ followed by the timed run, then uploaded a second copy of B while the first was
349
+ still held. At alkane43 / cc-pVTZ over 4 cores (19.2 GB per core), the second
350
+ upload failed with NRT_RESOURCE. The new `DFJK.close()` is called at the end of
351
+ `run_scf` and after the canonical Fock build in `scf_df_mp2.py`.
352
+ - **DIIS history padded to a multiple of 16384 elements (trnsci/trnsci#115).** On Trn2 the
353
+ `(space, n²) @ (n²,)` GEMV for the DIIS row did not finish compiling in 21 min at n = 1640
354
+ (water40 / aug-cc-pVDZ; walrus `remat_optimization`). Two exclusive slots and two
355
+ single-core runs timed out inside it. Padded with zeros to 2,703,360 elements, it
356
+ compiles in 40 s. Dot products and the extrapolated Fock are unchanged.
357
+ - **`df_mp2` on a NeuronCore takes the blocked energy unless trntensor's row kernel fits (trnsci/trnsci#115).**
358
+ Before, a B_ia under 20 GB always went to `trntensor.mp2_energy`. When the row kernel
359
+ doesn't fit SBUF, that call runs aten einsums summed into an fp32 scalar. At C40H82 /
360
+ aug-cc-pVDZ on one core it took 222 s, against 184 s for `mp2_energy_blocked`,
361
+ and landed 3.8e-6 Eh off it. At alkane43 / cc-pVTZ it took 531 s against 258 s, 5.2e-6 Eh
362
+ off. The blocked route sums per-pair partials in float64.
363
+ - **Streamed J/K: the default resident budget leaves room for chunks in flight (trnsci/trnsci#115).**
364
+ If some chunks stream, the default per-device resident budget is now
365
+ `DEVICE_RESIDENT_GB` minus (prefetch + 2) chunks: the uploads in flight plus one
366
+ chunk of `df_exchange` working memory. Before, it was the full 20 GB, and a 24 GiB
367
+ Trn2 core ran out of memory (NRT_RESOURCE) in the second SCF iteration in two cases:
368
+ C40H82 / aug-cc-pVDZ on one core at 20 GB resident (16 GB ran), and
369
+ alkane69 / cc-pVDZ (nocc 277) at 15.7 GB (13 GB converged in 6 iterations).
370
+ Fully resident layouts (B fits the budget) are unchanged.
371
+ - **`df_store` row blocks no longer overflow on int32 `ao_loc` (trnsci/trnsci#115).**
372
+ PySCF's `ao_loc` is int32, so the block-size test `3 · rows · naux · 8` wrapped
373
+ past 2³¹ once one shell pushed a block from under `block_bytes` to over 2 GiB.
374
+ That happens at cc-pVTZ, n_ao ≈ 2500. The test then passed when it should have
375
+ stopped. At alkane43 / cc-pVTZ (n_ao 2522) the largest row block came out at 13.0 GB
376
+ of float64 int3c2e, about 39 GB with its solve copies, against the 1 GiB budget,
377
+ and the box build was among the processes OOM-killed. With Python ints the sizes give 495 blocks of
378
+ ≤ 0.61 GB (previously 344).
379
+ - **Host float64 J/K over an fp32 store no longer raises at n_ao ≳ 2050 (trnsci/trnsci#115).**
380
+ The canonical Fock in `scf_df_mp2.py` streams the fp32 store in float64 on the host.
381
+ The store's 128-column chunks double to more than 2 GiB there, so `DFJK` re-split B
382
+ under the device's 2 GiB bound. At n_ao 2522 not even 128 float64 columns fit, and
383
+ `aux_chunk_width` raised. On the host the store's own chunks are now used as they
384
+ are, since that bound applies only to the device matmul.
385
+ - **float64, integer and bool operands reached the FP32 NKI kernels (#83,
386
+ trnsci/trnsci#35).** One dtype table (`KERNEL_DTYPES` in
387
+ `trnsolver/nki/dispatch.py`) now lists what each kernel takes, and
388
+ `_launch` (native and XLA) and the new `_simulate` (simulator) raise
389
+ `TypeError` for anything else, so no kernel is reached with another dtype.
390
+ The wrappers route first with one guard (`_kernel_dtype` /
391
+ `_kernel_operands`), which applies the float64 policy above. Integer and
392
+ bool input takes torch (which raises, as the pytorch backend does), or
393
+ raises `NotImplementedError` under `TRNSOLVER_REQUIRE_NKI=1`. float16 and
394
+ bfloat16 are cast to FP32 (lossless) and restored. Affected: every release
395
+ with the kernels.
396
+
397
+ - **`cg` dropped the imaginary part of complex input (#100).** Its inner
398
+ products were `float(u.dot(v))`: unconjugated, and cast to real, so a
399
+ complex Hermitian positive definite system iterated on the wrong
400
+ quantities and returned a wrong `x` (or ran to `maxiter`) with only a
401
+ UserWarning. A complex `A` with a real `b` also lost `A`'s imaginary
402
+ part. `cg` now uses conjugated inner products `r^H z`, `p^H A p`
403
+ (accumulated in complex128 / float64) and promotes a real `b` to complex
404
+ for a complex `A`. Real input is unchanged. Affected: every release
405
+ through 0.21.0.
406
+ - **`eigh(method="jacobi")` raised on complex and 0×0 input; `solve_spd`
407
+ raised on a batch of vector right-hand sides (#79).** Jacobi is real-only:
408
+ complex Hermitian input (`NotImplementedError: "ge_cpu"`) now takes the
409
+ default `eigh` path, as `torch.linalg.eigh` does. An n = 0 input (any
410
+ batch) returns empty `w`, `V` instead of failing to reshape. `solve_spd`
411
+ now reads B (*, n) with `B.shape == A.shape[:-1]` as a batch of vectors,
412
+ following `torch.linalg.solve`, where it raised before. The one shape that
413
+ already worked, last batch dim of A equal to n, keeps its old (*, n, k)
414
+ reading. Affected: `eigh(method="jacobi")` 0.17.0 through 0.21.0;
415
+ `solve_spd` every release through 0.21.0.
416
+ - **`cg` gave a wrong gradient with respect to `A`; `schur` detached
417
+ silently; `gmres` backward raised (#76).** `cg` read its step sizes as
418
+ Python floats, so autograd differentiated a fixed polynomial in `A`
419
+ (relative error 0.55 at n = 5, 7.2 at n = 20). `cg` and `gmres` with a
420
+ tensor `A` now differentiate implicitly: backward solves the adjoint
421
+ system `A^H λ = ∂x` with the same solver, giving `∂b = λ` and
422
+ `∂A = -λ x^H` (one extra solve per backward; double backward works).
423
+ `gmres` with a callable `A` raises `RuntimeError` when `b` or `x0`
424
+ requires grad. `schur` now raises `RuntimeError` when `A` requires grad
425
+ in grad mode, instead of returning `Q` and `T` that contributed zero
426
+ gradient. Affected: every release through 0.21.0.
427
+
428
+ ## [0.21.0] — 2026-11-02
429
+
430
+ Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron) — see trnsci/trnsci#35.
431
+
432
+ Headline: **correctness fixes — upgrade recommended.** Complex Hermitian and batched inputs used `.T` instead of `.mH` in `cholesky(upper)`, `solve_spd`, `inv_spd`, `inv_sqrt_spd`, `eigh_generalized`, `pinv` and `ssor` on every backend (#64); a real A with a complex B dropped its imaginary part (#66); `cg`/`gmres` returned `x0` for a zero or tiny b (#68); fp64 Householder `eigh` was wrong on device (#83); device matmuls now resolve lazy conjugates (aws-neuron-sdk#1455). New: `orthogonalizer` for near-singular overlaps (#72) and `occupied_subspace`, a Chebyshev-filtered subspace eigensolver for SCF (#78, #91).
433
+
434
+ ### Fixed
435
+
436
+ - **`eigh` on the NKI Householder path: float64 input gave garbage, and n = 1
437
+ returned `(1, 1)` eigenvalues** (silent, #83). The path runs under
438
+ `TRNSOLVER_REQUIRE_NKI=1` or on a non-native NKI device. float64 matrices
439
+ reached the fp32 kernels as is. On Trn2, n = 2 came back float32 with
440
+ rel err ~1e17 and n = 12 raised a dtype mismatch. They now run in fp32 and
441
+ return float64. n = 1 returned `(1, 1)` eigenvalues (0.4.0 through 0.20.0)
442
+ and now returns `(1,)`. `eigh_generalized` inherited both. Found by the
443
+ round-3 device harness on Trn2 (trnsci/trnsci#35).
444
+ - **Complex Hermitian and batched input gave wrong results with no error (#64).**
445
+ `cholesky(upper=True)`, `solve_spd` (including `iterative_refinement=True`),
446
+ `inv_spd`, `inv_sqrt_spd`, `eigh_generalized`, `eigh_randomized`, `pinv`
447
+ and `ssor_preconditioner` now follow the conjugate transpose and per-matrix
448
+ semantics of `torch.linalg`. Before, they used `.T`, which drops the
449
+ conjugation and reverses batch dims; a batch of size n kept its shape.
450
+ Relative error was 0.3–0.5 for complex input, and 0.4–2.5 or non-finite
451
+ for a batch of size n. `pinv` used the first matrix's singular values as
452
+ the cutoff for the whole batch and raised on empty input. Real (n, n)
453
+ results are unchanged. Affected: every release through 0.20.0 (`pinv`
454
+ since 0.5.0, `ssor_preconditioner` since 0.8.0). Complex input to
455
+ `eigh_randomized` (eigenvalue error 1.35) now also stays off the real NKI
456
+ matmul kernel.
457
+ `eigh` sends complex and batched input (as from `eigh_generalized`) to
458
+ aten instead of the real single-matrix NKI Householder path, which raised
459
+ for them under `TRNSOLVER_REQUIRE_NKI=1` on a Neuron host.
460
+ Every conjugate transpose that reaches a matmul or triangular solve, or is
461
+ returned (`cholesky(upper=True)`), is materialized with `resolve_conj()`:
462
+ on a Neuron device matmul ignores the lazy conj bit of a `.mH` view
463
+ (aws-neuron/aws-neuron-sdk#1455), so `A.mH @ B` computed `A.mT @ B`.
464
+ - **`cg`/`gmres` returned `x0` (or zeros) with residual 0.0 for a zero or
465
+ small-scale right-hand side (#68).** `b = 0` with an `x0` returned `x0`
466
+ in place of the solution 0. Any `‖b‖ < 1e-15` returned without
467
+ iterating, and `cg` stopped a small-scale problem before its first step
468
+ (`|pAp| < 1e-30`). Now only `b == 0` short-circuits (to zeros), and `cg`
469
+ stops on exact breakdown. `jacobi_preconditioner` scaled the columns of
470
+ a block `r` of shape (n, k); it now scales rows. Affected: every
471
+ release through 0.20.0 (`jacobi_preconditioner` since 0.2.0).
472
+ - **`lu` documented the wrong permutation convention (#71).** The docstring,
473
+ API docs, quickstart and README said `P @ A = L @ U`; `lu` returns
474
+ `A = P @ L @ U` (the `torch.linalg.lu` convention), which differs whenever
475
+ the pivot permutation is not its own inverse. The docs now match; the
476
+ returned values are unchanged. Affected docs: every release through 0.20.0.
477
+ - **A real matrix with a complex right-hand side dropped the imaginary part
478
+ (#66).** `solve`, `solve_spd` and `eigh_generalized` cast B to A's dtype,
479
+ so a complex B lost its imaginary part with only a UserWarning, and the
480
+ result was real. A real A is now promoted to complex when B is complex.
481
+ Real B is unchanged. Affected: 0.7.0–0.20.0. `eigh_generalized(A, None,
482
+ X=X)` (new on main, #72) likewise promotes a real A for a complex X.
483
+
484
+
485
+ - **`TRNSOLVER_JACOBI_ONEZERO` is a kernel argument ([aws-neuron/aws-neuron-sdk#1454](https://github.com/aws-neuron/aws-neuron-sdk/issues/1454)).**
486
+ `jacobi_sweeps_kernel` and `jacobi_block_kernel` read the `_ONEZERO`
487
+ module global from their body, which the persistent NKI trace cache does
488
+ not key on, so a process could run a trace made under the other setting.
489
+ The flag is now their `onezero` argument (a static `int` on the
490
+ `trnsolver::jacobi_sweeps` / `jacobi_block` ops; `dispatch._launch` takes
491
+ `static=`). Both settings compute the same result; only the Tensor
492
+ Engine pass count differs.
493
+
494
+ ### Added
495
+
496
+ - **`occupied_subspace(F, k, guess=state)`: lowest-k eigensolver for SCF
497
+ (#77).** Warm-started Chebyshev-filtered subspace iteration. Per pass,
498
+ one NKI launch (`trnsolver/nki/subspace.py`) keeps F resident in SBUF,
499
+ runs the degree-8 filter as Tensor Engine GEMMs, forms the correction
500
+ E = Y - X X^T Y and the six Gram blocks of span[X, E]; the 2kb x 2kb
501
+ Rayleigh-Ritz runs in float64 on the host. FP32 DF-RHF on the host
502
+ reference filter converges in the same iterations as with a full `eigh`
503
+ (water 10 / 10, benzene 11 / 10, H2 lattice 9 / 10, C10H22 16 / 16).
504
+ `examples/scf_df_rhf.py --solver subspace`, `bench_scf.py --solver
505
+ subspace`, `scripts/bench_occupied_subspace.py`. Simulator and MLIR
506
+ verified (lnc = 1, 2). On Trn2 the `-m neuron` tests pass at LNC = 1
507
+ and 2, with the trace cache on and off. Per call (2 passes) it takes
508
+ 13 / 16 / 44 ms at n = 250 / 490 / 970, against 3.8 / 12.6 / 68 ms for
509
+ aten `eigh`. The host Rayleigh-Ritz dominates at n = 970. In DF-RHF it
510
+ did not beat the full `eigh` in time to convergence at any measured
511
+ size (docs/api/eigen.md).
512
+ - **`occupied_subspace`: a cheaper host Rayleigh-Ritz, the block update
513
+ folded into the next launch, and adaptive passes instead of `refresh`
514
+ (#85, #86).**
515
+ - The Rayleigh-Ritz keeps only the lowest kb pairs. A well-conditioned
516
+ Gram takes one Cholesky and one `eigh`: at n = 970 that is 14 ms per
517
+ pass, against 16 ms.
518
+ - Each launch after a call's first applies the previous update
519
+ X = [X, E] Q on chip (`subspace_step_kernel`). Q arrives in the same
520
+ copy as the filter scalars. `TRNSOLVER_SUBSPACE_FOLD=0` turns this
521
+ off.
522
+ - New defaults: `passes=6`, `rtol=0.05` (stop once the residual has
523
+ dropped 20x), `tol="auto"` (30 ulp: return a converged block
524
+ unchanged, so an FP32 energy test can see two equal energies) and
525
+ `refresh=None`.
526
+ - Per call (2 passes) on Trn2: 5.6 / 9.3 / 34 ms at n = 250 / 490 /
527
+ 970, against 7.8 / 12 / 40 ms before.
528
+ - FP32 DF-RHF on Trn2 takes 11 / 14 / 15 / 18 iterations at n_ao =
529
+ 114 / 250 / 490 / 970, against 11 / 14 / 16 / 17 with a full `eigh`.
530
+ That is 1.10x faster at 490, 3% slower at 970 and 15-21% slower at
531
+ 250 and below.
532
+ - **`orthogonalizer(S, method, lindep)` and `eigh_generalized(F, S, X=X)`:
533
+ a tolerance for near-singular overlaps (#72, for #15).** `"symmetric"`
534
+ (Loewdin S^-1/2, the default), `"canonical"` (keeps the eigenvalues of S
535
+ above `lindep` x max, n x m X) and `"cholesky"` (pivoted Cholesky, no
536
+ eigensolve, O(n m^2)). It returns `X` with X^H S X = I on the kept
537
+ subspace and the kept `rank`. It is built once, in float64 on the host,
538
+ for real or complex Hermitian S, batched, and differentiable.
539
+ `eigh_generalized(F, S, X=X)` then needs only two GEMMs, an m x m `eigh`
540
+ and a back-transform, in F's dtype and on F's device, and no Cholesky of
541
+ S. `examples/scf_df_rhf.py` uses them (`--orth`, `--lindep`, and
542
+ `pyscf:<name>@<basis>` systems for diffuse bases). The default results
543
+ are unchanged: every current test system is far from the 1e-7 threshold,
544
+ so `symmetric` is still S^-1/2, and its energies match the previous
545
+ release to all printed digits (fp64 and fp32, h2-lattice, water, benzene,
546
+ C10H22). With a diffuse basis, dropping the dependencies is what lets an
547
+ FP32 SCF converge. benzene/aug-cc-pVTZ (n = 414): with three functions
548
+ dropped, it converges in 23 iterations, and the float64 energy at its
549
+ orbitals is 4.7e-6 Eh from PySCF. Plain S^-1/2, the Cholesky of S, or
550
+ `cholesky` at 1e-7 do not converge in 80 iterations.
551
+ C20H42/aug-cc-pVDZ (n = 838, two functions dropped) converges in FP32
552
+ either way. In float64, dropping the two functions raises the energy by
553
+ 2.8e-5 Eh: lower `lindep` when that matters more than FP32 conditioning.
554
+ - **Guard against the NKI trace-cache closure bug ([aws-neuron/aws-neuron-sdk#1454](https://github.com/aws-neuron/aws-neuron-sdk/issues/1454),
555
+ trnsci/trnsci#35).** `tests/test_trace_cache_safety.py` (CPU) finds every
556
+ `@nki.jit` kernel and fails if its body, or a helper it calls, reads a
557
+ closure variable or a module global that is not a constant expression
558
+ (reviewed exceptions are allow-listed with a reason), and checks each
559
+ kernel's `__closure__` at runtime against a stub `nki`.
560
+ - Tests: `conftest.py` no longer turns the NKI trace cache off. Neuron tests
561
+ run with it on, as under `import torch_neuronx`, with a fresh
562
+ `NKI_TRACE_CACHE_URL` directory per session (no stale editable-install
563
+ traces). `NKI_ENABLE_TRACE_CACHE=0` still turns it off.
564
+ - README: known platform issue note for #1454.
565
+ - **DF-RHF example: J and K from trntensor's fused packed-integral kernels
566
+ (trntensor#60).** `DFJK(fused=None)` (and `run_scf(jk_fused=...)`,
567
+ `bench_scf.py --jk-k auto|fused|unpack`) builds K with
568
+ `trntensor.df_exchange` and J with `trntensor.df_coulomb` on a `neuron`
569
+ device when trntensor provides them. The packed integrals stay in one
570
+ block per device and are never unpacked. Trn2, LNC=2, one logical core,
571
+ time to convergence against the unpack + einsum + syrk path: C10H22
572
+ 352 -> 229 ms, C20H42 756 -> 587 ms, C40H82 9.68 -> 4.71 s (J/K stage
573
+ 365 -> 163 ms per iteration). At LNC=1, C40H82 runs in 7.7 s fused; the
574
+ unpack path no longer fits there (12 GB per physical core). Older
575
+ trntensor keeps the unpack path.
576
+
10
577
  ## [0.20.0] — 2026-10-31
11
578
 
12
579
  Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron) — see trnsci/trnsci#35.
@@ -21,7 +21,9 @@ trnsolver/
21
21
  │ ├── __init__.py # Re-exports all solver operations
22
22
  │ ├── eigen.py # eigh, eigh_generalized (Jacobi + torch fallback)
23
23
  │ ├── factor.py # cholesky, lu, qr, solve, solve_spd, inv_sqrt_spd
24
+ │ ├── orthogonalize.py # orthogonalizer(S): symmetric / canonical / pivoted Cholesky
24
25
  │ ├── iterative.py # cg, gmres
26
+ │ ├── block.py # cg_block(_ir), pivoted low-rank preconditioner, SLQ
25
27
  │ └── nki/
26
28
  │ ├── __init__.py
27
29
  │ ├── dispatch.py # NKI kernels, launch helper, dispatch-path selection
@@ -45,6 +47,7 @@ trnsolver/
45
47
  |----------|------|---------------|
46
48
  | Overlap Cholesky | S = L L^T | `cholesky(S)` |
47
49
  | Reduce to standard | A' = L^{-1} F L^{-T} | `eigh_generalized(F, S)` |
50
+ | ...near-singular S | X = orthogonalizer(S).X once, A' = X^T F X | `eigh_generalized(F, S, X=X)` |
48
51
  | Eigensolve | A' V = V Λ | `eigh(A')` (Jacobi on NKI) |
49
52
  | Back-transform | C = L^{-T} V | `trsm` (in trnblas) |
50
53
  | Density | P = C_occ @ C_occ^T | `syrk` (in trnblas) |
@@ -52,21 +55,27 @@ trnsolver/
52
55
 
53
56
  ## NKI Jacobi Strategy
54
57
 
55
- The Jacobi eigensolver maps to Trainium hardware:
58
+ The batched one-sided (Hestenes) Jacobi kernels in `trnsolver/nki/jacobi.py`
59
+ map to Trainium hardware:
56
60
 
57
- - **Each Givens rotation** is a 2-row/col update — rank-2 matmul on Tensor Engine
58
- - **Off-diagonal max finding** maps to Vector Engine reduction
59
- - **Sweep convergence check** is a scalar reduction on Scalar Engine
60
- - **Eigenvector accumulation** V' = V @ G is a batched column update
61
+ - **Parallel order:** each step rotates n/2 disjoint column pairs, so a batch
62
+ advances in lockstep; up to 128 tiles of 128 / n matrices stay in SBUF
63
+ for a whole sweep (one launch per sweep)
64
+ - **Tensor Engine:** the step's partner permutation (exact matmul); for
65
+ 33 <= n <= 128 also the Gram matrix and block-pair rotations
66
+ - **Vector Engine:** the rotations (block kernel: 16 x 16 pair Gram blocks)
67
+ - **Convergence check** after the expected sweep count, at most 15 sweeps
61
68
 
62
- The Jacobi method is preferred over Householder tridiagonalization on
63
- Trainium because each rotation is a fixed-size operation that maps cleanly
64
- to the 128×128 tile, vs Householder which requires growing reflector chains.
69
+ Jacobi is preferred over Householder tridiagonalization on Trainium because
70
+ Householder is n - 2 dependent BLAS-2 steps that leave the Tensor Engine
71
+ idle; batched on device it still lost to CPU LAPACK (#48).
65
72
 
66
73
  ## Known Gaps & Design Notes
67
74
 
68
- - **NKI Jacobi kernel is a stub.** Falls back to torch.linalg.eigh until
69
- validated on hardware. The rotation kernel scaffold is in nki/dispatch.py.
75
+ - **NKI Jacobi kernels are batched and n <= 128.** `trnsolver/nki/jacobi.py`
76
+ (scalar n <= 32, block 33 <= n <= 128), validated on Trn2. Householder-QR
77
+ `eigh` is single-tile (n <= 128); the default aten cutover (n < 512) and
78
+ the > 128 fallback send single matrices to `torch.linalg.eigh`.
70
79
 
71
80
  - **Jacobi is O(n³) per sweep with O(n) sweeps** — cubic overall but with
72
81
  a large constant. For n > ~500, Householder + QR iteration would be faster.
@@ -77,9 +86,8 @@ to the 128×128 tile, vs Householder which requires growing reflector chains.
77
86
  benefit from NKI Level 1/2 kernels in trnblas, but the iteration logic
78
87
  stays on the host.
79
88
 
80
- - **inv_sqrt_spd uses eigendecomposition**, not the Newton-Schulz iteration.
81
- Newton-Schulz (X_{k+1} = 0.5 X_k (3I - A X_k²)) is all GEMMs and would
82
- map better to trnblas, but needs good initial scaling.
89
+ - **inv_sqrt_spd uses eigendecomposition.** The all-GEMM Newton-Schulz
90
+ variant is `inv_sqrt_spd_ns` (GEMMs via `trnblas.gemm` when installed).
83
91
 
84
92
  ## Dependencies
85
93
 
@@ -101,7 +109,7 @@ Sibling repos in the trn-* suite:
101
109
  - `trnfft` — FFT + complex ops (https://github.com/trnsci/trnfft)
102
110
  - `trnblas` — BLAS operations (https://github.com/trnsci/trnblas)
103
111
  - `trnsolver` — Linear solvers, eigendecomposition (this repo)
104
- - `trnrand` — Random number generation (planned)
112
+ - `trnrand` — Random number generation
105
113
 
106
114
  All repos: Python/NKI, Apache 2.0.
107
115