Commit 960de52
Integrate PR #31: preconditioner framework, warm-starts, kernel sparse blocks
Integrates the capabilities from #31
on top of the recent gp_data/gp_prior/gp_kv refactor, omitting the changes
that conflicted with the new structure or removed safety/diagnostics.
gp_lin_alg.py
- New sparse preconditioner framework: ILU, IC(0), block Jacobi, additive
Schwarz, AMG; alias resolution via `resolve_gp2scale_linalg_mode` and
`normalize_sparse_preconditioner_type`; dispatcher
`calculate_sparse_preconditioner(KV, args) -> (factor, operator)`.
- Block conjugate gradient (`_block_conjugate_gradient`) with multi-column
x0 normalization (`_normalize_rhs`, `_normalize_initial_guess`,
`_column_initial_guess`) so warm-starts survive an append.
- maxiter support in MINRES/CG (`sparse_minres_maxiter`, `sparse_cg_maxiter`,
`sparse_krylov_maxiter`).
- GPU detection: `_torch_gpu_device` (CUDA + MPS + device index),
`_cupy_gpu_available`, `_imate_gpu_enabled`; `get_gpu_engine` now actually
verifies a usable GPU before returning torch/cupy.
- CPU fallback with UserWarning in every GPU branch that previously set
`res = None`; cupy added to `calculate_logdet`, `calculate_inv`, `solve`,
`matmul`, `matmul3`.
- `args=args` propagation through `update_Chol_factor`,
`cholesky_update_rank_n`, `update_logdet`, `calculate_inv_from_chol`,
`update_inv`, `cholesky_update_rank_1_torch`.
- Preserves NonPositiveDefiniteError and its diagnostics; preserves user
dtype on GPU paths (rejected float32 downcasts); keeps `.tocsc()` in
`calculate_sparse_solve`; preserves docstrings.
gp_kv.py (training-path preconditioner cache + warm-start plumbing)
- Mode aliases `sparseCGpre_<type>` / `sparseMINRESpre_<type>` resolved at
__init__; resolved args written back to data.args.
- Preconditioner cache (factor/operator/signature/shape/reuse counter) used
by solve(), set_KV (force-refresh), update_KV (reuse-with-interval), and
compute_new_*. Refresh interval default 1 = always rebuild (no change to
prior behavior). Invalidated on shape or `sparse_preconditioner_*` arg
change. Cached factor/operator dropped from pickle state.
- compute_new_KVinvY / compute_new_KVlogdet_KVinvY gain optional x0 for
warm-start; replaces inline `sparse.linalg.spilu` with the unified
preconditioner framework.
gp_marginal_likelihood.py
- `_warm_start_KVinvY` cache; `_iterative_initial_guess` returns a usable
x0 (last training iteration's solution, fallback to committed kv.KVinvY)
when `args["sparse_krylov_warm_start"]=True`. Default off.
kernels.py
- Support-aware sparse Wendland blocks for gp2Scale:
`wendland_anisotropic_gp2Scale_cpu_sparse` and its GPU counterpart,
output-sensitive cKDTree neighbor search in whitened coordinates.
- Multi-backend GPU Wendland with torch/cupy/CPU fallback.
- Preserved existing docstrings and `polynomial_kernel` (collaborator's
version returned `p` instead of the kernel value).
gp.py / fvgp.py
- Docstrings updated: `linalg_mode` documents the new `_<type>` aliases,
`args` section split into themed groups with the new
`sparse_preconditioner_*`, `sparse_krylov_*`, `sparse_*_maxiter`,
`GPU_device`, `GPU_device_index` keys.
pyproject.toml
- `pyamg` added to tests extras so CI exercises the AMG preconditioner.
CLAUDE.md
- New 'Iterative-solver acceleration' section documenting the cache,
preconditioner choices, warm-start, and the default-off semantics;
`GPkv` and `GPMarginalLikelihood` rows updated.
Tests
- All linalg modes (canonical + every `_<type>` alias for the two
preconditioned solvers) exercised end-to-end in `test_linalg_modes`.
- Per-preconditioner correctness via CG convergence
(`test_calculate_sparse_preconditioner_{ilu,ic0,block_jacobi,
additive_schwarz,amg}`).
- Block CG, multi-column x0, maxiter, legacy tolerance keys, GPU engine
detection, CPU fallbacks for both linalg and kernel paths.
- New training-path tests: preconditioner cache reuse counter and refresh
interval, signature invalidation, set_KV force-refresh, warm-start
on/off, build-failure fallback, end-to-end agreement of cached +
warm-started compute_new_KVlogdet against the cold-start baseline.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 7682a99 commit 960de52
9 files changed
Lines changed: 2107 additions & 173 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
95 | 104 | | |
96 | 105 | | |
97 | 106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
184 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
185 | 190 | | |
186 | 191 | | |
187 | 192 | | |
| |||
207 | 212 | | |
208 | 213 | | |
209 | 214 | | |
| 215 | + | |
| 216 | + | |
210 | 217 | | |
211 | 218 | | |
212 | 219 | | |
213 | 220 | | |
214 | | - | |
215 | | - | |
216 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
217 | 261 | | |
218 | 262 | | |
219 | 263 | | |
220 | 264 | | |
221 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
222 | 271 | | |
223 | 272 | | |
224 | 273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
184 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
185 | 190 | | |
186 | 191 | | |
187 | 192 | | |
| |||
207 | 212 | | |
208 | 213 | | |
209 | 214 | | |
| 215 | + | |
| 216 | + | |
210 | 217 | | |
211 | 218 | | |
212 | 219 | | |
213 | 220 | | |
214 | | - | |
215 | | - | |
216 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
217 | 261 | | |
218 | 262 | | |
219 | 263 | | |
220 | 264 | | |
221 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
222 | 271 | | |
223 | 272 | | |
224 | 273 | | |
| |||
0 commit comments