diff --git a/.gitignore b/.gitignore index 90354d9..2215d66 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# VSCode +.vscode/ + # HPC scripts and logs hpc/ diff --git a/Hamiltonian.jl b/Hamiltonian.jl index a206677..4e18862 100644 --- a/Hamiltonian.jl +++ b/Hamiltonian.jl @@ -68,8 +68,8 @@ end "cuTENSOR contraction and accumulation (C = A * B + C)" function contract_accumulate!(C::CuTensor, A::CuTensor, B::CuTensor)::CuTensor - CUTENSOR.contraction!(one(eltype(C)), A.data, A.inds, CUTENSOR.CUTENSOR_OP_IDENTITY, B.data, B.inds, CUTENSOR.CUTENSOR_OP_IDENTITY, - one(eltype(C)), C.data, C.inds, CUTENSOR.CUTENSOR_OP_IDENTITY, CUTENSOR.CUTENSOR_OP_IDENTITY) + cuTENSOR.contraction!(one(eltype(C)), A.data, A.inds, cuTENSOR.CUTENSOR_OP_IDENTITY, B.data, B.inds, cuTENSOR.CUTENSOR_OP_IDENTITY, + one(eltype(C)), C.data, C.inds, cuTENSOR.CUTENSOR_OP_IDENTITY, cuTENSOR.CUTENSOR_OP_IDENTITY) return C end @@ -125,6 +125,7 @@ function (H::Hamiltonian)(v) end tolerance = 1e-6 +max_iterations = 500 "Wrapper for KrylovKit.eigsolve" function eig(H::Hamiltonian{T}, levels::Int; resonances = !H.hermitian)::Tuple{Vector,Vector,KrylovKit.ConvergenceInfo} where {T<:Float} @@ -134,7 +135,7 @@ function eig(H::Hamiltonian{T}, levels::Int; resonances = !H.hermitian)::Tuple{V x₀ = CUDA.rand(Complex{T}, vectorDims(H)...) synchronize() end - evals, evecs, info = eigsolve(H, x₀, levels, resonances ? :LI : :SR; ishermitian = H.hermitian, tol = tolerance, krylovdim = levels * 8) + evals, evecs, info = eigsolve(H, x₀, levels, resonances ? :LI : :SR; ishermitian = H.hermitian, tol = tolerance, krylovdim = levels * 8, maxiter = max_iterations) info.converged < levels && throw(error("Not enough convergence")) if H.hermitian evals = real.(evals) end if H.mode == gpu_cutensor # to avoid possible GPU memory leak diff --git a/LocalPreferences.toml b/LocalPreferences.toml new file mode 100644 index 0000000..cdb275e --- /dev/null +++ b/LocalPreferences.toml @@ -0,0 +1,2 @@ +[TensorOperations] +precompile_workload = true diff --git a/Project.toml b/Project.toml new file mode 100644 index 0000000..1ef80cd --- /dev/null +++ b/Project.toml @@ -0,0 +1,7 @@ +[deps] +CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" +KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77" +NVTX = "5da4648a-3479-48b8-97b9-01cb529c0a1f" +Preferences = "21216c6a-2e73-6563-6e65-726566657250" +TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2" +cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1" diff --git a/README.md b/README.md new file mode 100644 index 0000000..57a0500 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# DVR.jl + +Solves the quantum $n$-body problem in finite volume (lattice) with periodic boundary conditions. Uses discrete variable representation (DVR) with optional support for complex scaling to study resonances. All details can be found in [H. Yu, N. Yapa, and S. König, Complex scaling in finite volume, Phys. Rev. C 109, 014316 (2024)](https://doi.org/10.1103/PhysRevC.109.014316). + +Written in Julia with optional CUDA GPU acceleration (experimental). + +## Installation + +Make sure you have Julia installed. Required packages can be installed with a single command: +```bash +julia --project=. -e 'import Pkg; Pkg.instantiate()' +``` + +## Usage + +See `calculations/3b_bound.jl` for an example on a 3-body bound state. +See `calculations/3b_res_from_paper.jl` for an example of a 3-body resonance via complex scaling. + +## Planned features + +- [ ] Spin and isospin degrees of freedom for nuclear calculations +- [ ] Multi-node HPC support +- [ ] Parity and cubic symmetries ($S_4$) + +## Acknowledgments + +The author gratefully acknowledges the guidance from Sebastian König. diff --git a/calculations/EC-R2R-S.jl b/calculations/EC-R2R-S.jl new file mode 100644 index 0000000..9e9351a --- /dev/null +++ b/calculations/EC-R2R-S.jl @@ -0,0 +1,67 @@ +using Plots, Arpack + +include("../helper.jl") +include("../Hamiltonian.jl") + +mode = cpu_tensor +T = Float32 # single-precision mode + +V_r2(c) = r2 -> c * (-5 * exp(-r2/3) + 2 * exp(-r2/10)) + +d = 3 +n = 2 +N = 48 +L = 30 +ϕ = pi/6 +n_imag = 1 +s = system{T}(d, n, N, L) + +train_cs = range(0.78, 0.45, length=5) +train_ref = reverse([0.05387926313545913-0.008900278182520881im, + 0.11254295298924327-0.020515067379548786im, + 0.16060154707503538-0.03716539208626717im, + 0.19741353362674618-0.05994519982799412im, + 0.2219100763497223-0.08959449893439568im]) + +extrapolate_cs = range(0.38, 0.22, length=5) +extrapolate_ref = reverse([0.23165109150003316-0.12052751440975719im, + 0.23190549514995962-0.1406687118589838im, + 0.22763660218046278-0.1626190970863793im, + 0.21807104244164865-0.18635600686249373im, + 0.2020979906072586-0.21180157628258728im]) + +training_E = ComplexF64[] +training_vec = Array[] +exact_E = ComplexF64[] +extrapolated_E = ComplexF64[] + +for c in train_cs + println("Training c=", c) + H = Hamiltonian{T}(s, V_r2(c), ϕ, n_imag, mode) + @time evals, evecs, info = eig(H, 20, resonances = true) + i = nearestIndex(evals, pop!(train_ref)) + push!(training_E, evals[i]) + push!(training_vec, evecs[i]) +end + +N_EC = [sum(x .* y) for (x, y) in Iterators.product(training_vec, training_vec)] + +for c in extrapolate_cs + println("Extrapolating c=", c) + H = Hamiltonian{T}(s, V_r2(c), ϕ, n_imag, mode) + @time evals, _, info = eig(H, 40, resonances = true) + nearestE = nearest(evals, pop!(extrapolate_ref)) + push!(exact_E, nearestE) + + # EC extrapolation + H_training_vec = H.(training_vec) + H_EC = [sum(x .* y) for (x, y) in Iterators.product(training_vec, H_training_vec)] + + evals = eigvals(H_EC, N_EC) + push!(extrapolated_E, nearestE) +end + +scatter(real.(training_E), imag.(training_E), label="training") +scatter!(real.(exact_E), imag.(exact_E), label="exact") +scatter!(real.(extrapolated_E), imag.(extrapolated_E), label="extrapolated") +savefig("temp/EC-R2R-S.pdf") diff --git a/helper.jl b/helper.jl new file mode 100644 index 0000000..ee9da11 --- /dev/null +++ b/helper.jl @@ -0,0 +1,5 @@ +"Index of the nearest value in a list to a given reference point" +nearestIndex(list::Array, ref) = argmin(norm.(list .- ref)) + +"Nearest value in a list to a given reference point" +nearest(list::Array, ref) = list[nearestIndex(list, ref)]