Skip to content

use backends and allocators in DMRG#467

Open
lkdvos wants to merge 3 commits into
mainfrom
reuse-buf
Open

use backends and allocators in DMRG#467
lkdvos wants to merge 3 commits into
mainfrom
reuse-buf

Conversation

@lkdvos

@lkdvos lkdvos commented Jul 20, 2026

Copy link
Copy Markdown
Member

This PR threads the backend and allocators through the DMRG implementations.
As a result, we can use a single buffer that captures all temporary intermediate tensors in the effective hamiltonian applications, which is reused across sites, hopefully alleviating quite a bit of pressure from the garbage collector.

The one thing about this that is somewhat unfortunate is that this turns the algorithms into a non-threadsafe construction, and reusing the same algorithm in a parallel parameter sweep would yield wrong results.
In principle I can try to circumvent this, but I'm wondering how much that is worth it in the end?


Side note: The goal is of course to also do this for the rest of the package, but it is slightly easier to focus on a single algorithm first.

@lkdvos
lkdvos marked this pull request as draft July 20, 2026 19:09
@lkdvos
lkdvos requested review from borisdevos and leburgel July 20, 2026 19:09
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.64706% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../algorithms/derivatives/hamiltonian_derivatives.jl 90.90% 5 Missing ⚠️
Files with missing lines Coverage Δ
src/algorithms/derivatives/mpo_derivatives.jl 72.53% <100.00%> (ø)
...c/algorithms/derivatives/projection_derivatives.jl 100.00% <100.00%> (ø)
src/algorithms/groundstate/dmrg.jl 95.23% <100.00%> (ø)
.../algorithms/derivatives/hamiltonian_derivatives.jl 93.36% <90.90%> (+0.06%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lkdvos
lkdvos marked this pull request as ready for review July 20, 2026 22:42
@lkdvos

lkdvos commented Jul 21, 2026

Copy link
Copy Markdown
Member Author

Benchmark: DefaultAllocator vs BufferAllocator

End-to-end DMRG2 ground-state run measuring the effect of reusing a BufferAllocator across the sweep, driven by benchmark/allocator_gc.sbatch / benchmark/allocator_gc_run.jl.

Setup: spin-1 Heisenberg chain (Trivial), L=100, χ=128, 5 fixed sweeps, krylovdim=20, non-adaptive eigensolver (identical work for both allocators). Single Julia thread (so GC is single-threaded and its wall time is a clean number), MKL with 16 threads. julia 1.12.6.

metric (steady-state) DefaultAllocator BufferAllocator change
wall time 65.5 s 50.4 s −23%
GC time 24.2 s (37%) 10.3 s (20.5%) −57%
allocated 110.85 GiB 39.85 GiB −64% (−71 GiB)
GC pauses ~311 ~137 −56%
full collections 22 9 −59%
ground-state energy −138.940086126678 −138.940086126678 Δ = 0

Of the ~111 GiB a sweep churns through, ~71 GiB is recyclable effective-operator contraction scratch — with BufferAllocator it now comes from the reused buffer instead of the GC heap. The residual ~40 GiB (Krylov basis vectors, the gauge-step SVD, environment updates, result tensors) is not managed by the operator allocator and is therefore identical for both — that's the floor.

Raw output
model=Heisenberg S=1  L=100  χ=128  sweeps=5  krylovdim=20  reps=3
julia=1.12.6  julia_threads=1  gc_threads=1  BLAS_threads=16
DefaultAllocator | rep 1/3 |    66.79 s | GC   25.48 s ( 38.1%) |   110.85 GiB |    320 pauses |  23 full
DefaultAllocator | rep 2/3 |    65.62 s | GC   24.24 s ( 36.9%) |   110.85 GiB |    310 pauses |  22 full
DefaultAllocator | rep 3/3 |    65.41 s | GC   24.14 s ( 36.9%) |   110.85 GiB |    313 pauses |  22 full
BufferAllocator  | rep 1/3 |    50.91 s | GC   10.34 s ( 20.3%) |    39.85 GiB |    135 pauses |   9 full
BufferAllocator  | rep 2/3 |    50.37 s | GC   10.33 s ( 20.5%) |    39.85 GiB |    137 pauses |   9 full
BufferAllocator  | rep 3/3 |    50.38 s | GC   10.32 s ( 20.5%) |    39.85 GiB |    137 pauses |   9 full
energy check: |Δ| = 0.00e+00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant