From 7cc20a9c27b7d3b198c732a2d5532116ce8b64ea Mon Sep 17 00:00:00 2001 From: ysyapa Date: Sun, 27 Aug 2023 23:02:51 -0400 Subject: [PATCH 1/8] Fixed GPU related bug --- Hamiltonian.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Hamiltonian.jl b/Hamiltonian.jl index a206677..e09cafa 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 From 45b43728fbe10f554675b1e8f799cefa67c3c118 Mon Sep 17 00:00:00 2001 From: Nuwan Yapa Date: Fri, 12 Jul 2024 18:09:36 -0400 Subject: [PATCH 2/8] R2R EC implemented --- calculations/EC-R2R-S.jl | 67 ++++++++++++++++++++++++++++++++++++++++ helper.jl | 5 +++ 2 files changed, 72 insertions(+) create mode 100644 calculations/EC-R2R-S.jl create mode 100644 helper.jl 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)] From 37acda8fac12cf2b28c7f62489bf117b42adb8e2 Mon Sep 17 00:00:00 2001 From: Nuwan Yapa Date: Fri, 13 Feb 2026 15:32:27 -0500 Subject: [PATCH 3/8] Ignore VS Code configuration files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) 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/ From cf9de201a9dfcdbe5de59040b6d0da71dad3d671 Mon Sep 17 00:00:00 2001 From: Nuwan Yapa Date: Fri, 13 Feb 2026 23:53:42 +0000 Subject: [PATCH 4/8] Julia package dependencies --- LocalPreferences.toml | 2 ++ Project.toml | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 LocalPreferences.toml create mode 100644 Project.toml 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" From 840efad148fcd6d272ce62059510337fc7a9b5c0 Mon Sep 17 00:00:00 2001 From: Nuwan Yapa Date: Sat, 14 Feb 2026 01:02:21 +0000 Subject: [PATCH 5/8] First version of README.md --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..a92faf7 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# 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). + +## Installation + +Make sure you have Julia installed. To install the required packages, follow these steps: + +1. Open a terminal in the project root directory. +2. Start Julia with the project environment activated: + ```bash + julia --project=. + ``` +3. Enter the package manager mode by pressing `]`. +4. Run the `instantiate` command: + ```julia + (DVR-jl) pkg> instantiate + ``` + +Alternatively, you can run this single command from your terminal: +```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. From 7545ebf5b5323189353b7a56f577feef4bc0c368 Mon Sep 17 00:00:00 2001 From: Nuwan Yapa Date: Wed, 18 Feb 2026 01:09:14 +0000 Subject: [PATCH 6/8] Update README.md --- README.md | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a92faf7..9eb4955 100644 --- a/README.md +++ b/README.md @@ -2,22 +2,11 @@ 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. To install the required packages, follow these steps: - -1. Open a terminal in the project root directory. -2. Start Julia with the project environment activated: - ```bash - julia --project=. - ``` -3. Enter the package manager mode by pressing `]`. -4. Run the `instantiate` command: - ```julia - (DVR-jl) pkg> instantiate - ``` - -Alternatively, you can run this single command from your terminal: +Make sure you have Julia installed. Required packages can be installed with a single command: ```bash julia --project=. -e 'import Pkg; Pkg.instantiate()' ``` From 7029fdaf56b97b9d3eaf5cff727110dedfcd862d Mon Sep 17 00:00:00 2001 From: Nuwan Yapa Date: Thu, 30 Apr 2026 17:34:19 -0400 Subject: [PATCH 7/8] Name fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9eb4955..57a0500 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# DVR-jl +# 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). From e3545e4fbe2d5d240c2da3a6b215c9d7c25c19cd Mon Sep 17 00:00:00 2001 From: Nuwan Yapa Date: Thu, 7 May 2026 12:43:44 -0400 Subject: [PATCH 8/8] Increase maximum iterations --- Hamiltonian.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Hamiltonian.jl b/Hamiltonian.jl index e09cafa..4e18862 100644 --- a/Hamiltonian.jl +++ b/Hamiltonian.jl @@ -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