-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from ACEsuit/test_noparallel
3D BackFlowLux
- Loading branch information
Showing
40 changed files
with
2,780 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,8 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
version: | ||
- '1.0' | ||
- '1.8' | ||
- '1.9' | ||
- 'nightly' | ||
os: | ||
- ubuntu-latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using ACEpsi, Polynomials4ML, StaticArrays, Test | ||
using Polynomials4ML: natural_indices, degree, SparseProduct | ||
using ACEpsi.AtomicOrbitals: Nuc, make_nlms_spec, evaluate | ||
using ACEpsi: BackflowPooling, BFwf_lux, setupBFState, Jastrow | ||
using ACEpsi.vmc: gradient, laplacian, grad_params | ||
using ACEbase.Testing: print_tf, fdtest | ||
using LuxCore | ||
using Lux | ||
using Zygote | ||
using Optimisers # mainly for the destrcuture(ps) function | ||
using Random | ||
using Printf | ||
using LinearAlgebra | ||
using BenchmarkTools | ||
using HyperDualNumbers: Hyper | ||
|
||
Rnldegree = n1 = 2 | ||
Ylmdegree = 3 | ||
totdegree = 3 | ||
Nel = 2 | ||
X = randn(SVector{3, Float64}, Nel) | ||
Σ = rand(spins(), Nel) | ||
nuclei = [ Nuc(3 * rand(SVector{3, Float64}), 1.0) for _=1:3 ] | ||
|
||
# wrap it as HyperDualNumbers | ||
x2dualwrtj(x, j) = SVector{3}([Hyper(x[i], i == j, i == j, 0) for i = 1:3]) | ||
hX = [x2dualwrtj(x, 0) for x in X] | ||
hX[1] = x2dualwrtj(X[1], 1) # test eval for grad wrt x coord of first elec | ||
|
||
## | ||
|
||
# Defining AtomicOrbitalsBasis | ||
n2 = 2 | ||
Pn = Polynomials4ML.legendre_basis(n1+1) | ||
spec = [(n1 = n1, n2 = n2, l = l) for n1 = 1:n1 for n2 = 1:n2 for l = 0:n1-1] | ||
ζ = rand(length(spec)) | ||
Dn = GaussianBasis(ζ) | ||
bRnl = AtomicOrbitalsRadials(Pn, Dn, spec) | ||
bYlm = RYlmBasis(Ylmdegree) | ||
|
||
# setup state | ||
BFwf_chain, spec, spec1p = BFwf_lux(Nel, bRnl, bYlm, nuclei; totdeg = totdegree, ν = 2) | ||
ps, st = setupBFState(MersenneTwister(1234), BFwf_chain, Σ) | ||
|
||
## | ||
|
||
@info("Test evaluate") | ||
|
||
@btime BFwf_chain($X, $ps, $st) | ||
@btime gradient($BFwf_chain, $X, $ps, $st) | ||
@btime laplacian($BFwf_chain, $X, $ps, $st) | ||
|
||
|
||
@profview let BFwf_chain = BFwf_chain, X = X, ps = ps, st = st | ||
for i = 1:10_000 | ||
BFwf_chain(X, ps, st) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using ACEpsi, Polynomials4ML, StaticArrays, Test | ||
using Polynomials4ML: natural_indices, degree, SparseProduct | ||
using ACEpsi.AtomicOrbitals: Nuc, make_nlms_spec, evaluate | ||
using ACEpsi: BackflowPooling, BFwf_lux, setupBFState, Jastrow | ||
using ACEpsi.vmc: gradient, laplacian, grad_params, SumH, MHSampler, VMC, gd_GradientByVMC | ||
using ACEbase.Testing: print_tf, fdtest | ||
using LuxCore | ||
using Lux | ||
using Zygote | ||
using Optimisers # mainly for the destrcuture(ps) function | ||
using Random | ||
using Printf | ||
using LinearAlgebra | ||
using BenchmarkTools | ||
using HyperDualNumbers: Hyper | ||
|
||
n1 = Rnldegree = 5 | ||
Ylmdegree = 2 | ||
totdegree = 5 | ||
Nel = 4 | ||
X = randn(SVector{3, Float64}, Nel) | ||
Σ = [↑,↑,↓,↓] | ||
nuclei = [ Nuc(zeros(SVector{3, Float64}), Nel * 1.0)] | ||
## | ||
|
||
# Defining AtomicOrbitalsBasis | ||
n2 = 1 | ||
Pn = Polynomials4ML.legendre_basis(n1+1) | ||
spec = [(n1 = n1, n2 = n2, l = l) for n1 = 1:n1 for n2 = 1:n2 for l = 0:n1-1] | ||
ζ = 10 * rand(length(spec)) | ||
Dn = SlaterBasis(ζ) | ||
bRnl = AtomicOrbitalsRadials(Pn, Dn, spec) | ||
bYlm = RYlmBasis(Ylmdegree) | ||
|
||
# setup state | ||
wf, spec, spec1p = BFwf_chain, spec, spec1p = BFwf_lux(Nel, bRnl, bYlm, nuclei; totdeg = totdegree, ν = 2) | ||
displayspec(spec, spec1p) | ||
|
||
ps, st = setupBFState(MersenneTwister(1234), BFwf_chain, Σ) | ||
p, = destructure(ps) | ||
length(p) | ||
|
||
K(wf, X::AbstractVector, ps, st) = -0.5 * laplacian(wf, X, ps, st) | ||
Vext(wf, X::AbstractVector, ps, st) = -sum(nuclei[i].charge/norm(nuclei[i].rr - X[j]) for i = 1:length(nuclei) for j in 1:length(X)) | ||
Vee(wf, X::AbstractVector, ps, st) = sum(1/norm(X[i]-X[j]) for i = 1:length(X)-1 for j = i+1:length(X)) | ||
|
||
ham = SumH(nuclei) | ||
sam = MHSampler(wf, Nel, nuclei, Δt = 0.5, burnin = 1000, nchains = 2000) | ||
|
||
opt_vmc = VMC(3000, 0.1, ACEpsi.vmc.adamW(), lr_dc = 100) | ||
wf, err_opt, ps = gd_GradientByVMC(opt_vmc, sam, ham, wf, ps, st) | ||
|
||
err = err_opt | ||
per = 0.2 | ||
err1 = zero(err) | ||
for i = 1:length(err) | ||
err1[i] = mean(err[Int(ceil(i-per * i)):i]) | ||
end | ||
err1 | ||
|
||
Eref = -14.667 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using ACEpsi, Polynomials4ML, StaticArrays, Test | ||
using Polynomials4ML: natural_indices, degree, SparseProduct | ||
using ACEpsi.AtomicOrbitals: Nuc, make_nlms_spec, evaluate | ||
using ACEpsi.vmc: gradient, laplacian, grad_params, EmbeddingW!, _invmap, VMC_multilevel, wf_multilevel, VMC, gd_GradientByVMC, gd_GradientByVMC_multilevel, AdamW, SR, SumH, MHSampler | ||
using ACEbase.Testing: print_tf, fdtest | ||
using LuxCore | ||
using Lux | ||
using Zygote | ||
using Optimisers # mainly for the destrcuture(ps) function | ||
using Random | ||
using Printf | ||
using LinearAlgebra | ||
using BenchmarkTools | ||
using HyperDualNumbers: Hyper | ||
|
||
|
||
# Define He model | ||
Nel = 2 | ||
X = randn(SVector{3, Float64}, Nel) | ||
Σ = [↑,↓] | ||
nuclei = [ Nuc(zeros(SVector{3, Float64}), 2.0)] | ||
|
||
K(wf, X::AbstractVector, ps, st) = -0.5 * laplacian(wf, X, ps, st) | ||
Vext(wf, X::AbstractVector, ps, st) = -sum(nuclei[i].charge/norm(nuclei[i].rr - X[j]) for i = 1:length(nuclei) for j in 1:length(X)) | ||
Vee(wf, X::AbstractVector, ps, st) = sum(1/norm(X[i]-X[j]) for i = 1:length(X)-1 for j = i+1:length(X)) | ||
|
||
ham = SumH(nuclei) | ||
|
||
# Defining Multilevel | ||
Rnldegree = [4, 6, 6, 7] | ||
Ylmdegree = [2, 2, 3, 4] | ||
totdegree = [2, 3, 3, 4] | ||
n2 = [1, 1, 2, 2] | ||
ν = [1, 1, 2, 2] | ||
MaxIters = [3, 3, 3, 3] | ||
## | ||
|
||
# | ||
wf_list, spec_list, spec1p_list, specAO_list, ps_list, st_list = wf_multilevel(Nel, Σ, nuclei, Rnldegree, Ylmdegree, totdegree, n2, ν) | ||
|
||
sam = MHSampler(wf_list[1], Nel, nuclei, Δt = 0.5, burnin = 1, nchains = 20) | ||
opt_vmc = VMC_multilevel(MaxIters, 0.0015, SR(1e-4, 0.015), lr_dc = 50.0) | ||
|
||
wf, err_opt, ps = gd_GradientByVMC_multilevel(opt_vmc, sam, ham, wf_list, ps_list, st_list, spec_list, spec1p_list, specAO_list) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using ACEpsi, Polynomials4ML, StaticArrays, Test | ||
using Polynomials4ML: natural_indices, degree, SparseProduct | ||
using ACEpsi.AtomicOrbitals: Nuc, make_nlms_spec, evaluate | ||
using ACEpsi: BackflowPooling, BFwf_lux, setupBFState, Jastrow, displayspec | ||
using ACEpsi.vmc: gradient, laplacian, grad_params, SumH, MHSampler, VMC, gd_GradientByVMC | ||
using ACEbase.Testing: print_tf, fdtest | ||
using LuxCore | ||
using Lux | ||
using Zygote | ||
using Optimisers | ||
using Random | ||
using Printf | ||
using LinearAlgebra | ||
using BenchmarkTools | ||
using HyperDualNumbers: Hyper | ||
|
||
n1 = Rnldegree = 2 | ||
Ylmdegree = 1 | ||
totdegree = 30 | ||
Nel = 10 | ||
X = randn(SVector{3, Float64}, Nel) | ||
Σ = [↑,↑,↑,↑,↑,↓,↓,↓,↓,↓] | ||
spacing = 1.0 | ||
nuclei = [Nuc(SVector(0.0,0.0,(i-1/2-Nel/2) * spacing), 1.0) for i = 1:Nel] | ||
Pn = Polynomials4ML.legendre_basis(n1) | ||
spec = [(n1 = 1, n2 = 1, l = 0), (n1 = 1, n2 = 2, l = 0), (n1 = 2, n2 = 1, l = 1)] | ||
|
||
# Ref: http://www.grant-hill.group.shef.ac.uk/ccrepo/hydrogen/hbasis.php | ||
# (4s,1p) -> [2s,1p] | ||
# H S | ||
# 1.301000E+01 1.968500E-02 0.000000E+00 | ||
# 1.962000E+00 1.379770E-01 0.000000E+00 | ||
# 4.446000E-01 4.781480E-01 0.000000E+00 | ||
# 1.220000E-01 5.012400E-01 1.000000E+00 | ||
# H P | ||
# 7.270000E-01 1.0000000 | ||
|
||
ζ = [[1.301000E+01, 1.962000E+00, 4.446000E-01, 1.220000E-01], [1.220000E-01], [7.270000E-01]] | ||
D = [[1.968500E-02, 1.379770E-01, 4.781480E-01, 5.012400E-01], [1.0000000], [1.0000000]] | ||
D[1] = [(2 * ζ[1][i]/pi)^(3/4) * D[1][i] for i = 1:length(ζ[1])] * sqrt(2) * 2 * sqrt(pi) | ||
D[2] = [(2 * ζ[2][i]/pi)^(3/4) * D[2][i] for i = 1:length(ζ[2])] * sqrt(2) * 2 * sqrt(pi) | ||
|
||
Dn = STO_NG((ζ, D)) | ||
bRnl = AtomicOrbitalsRadials(Pn, Dn, spec) | ||
bYlm = RYlmBasis(Ylmdegree) | ||
|
||
ord = 1 | ||
wf, spec, spec1p = BFwf_chain, spec, spec1p = BFwf_lux(Nel, bRnl, bYlm, nuclei; totdeg = totdegree, ν = ord) | ||
|
||
ps, st = setupBFState(MersenneTwister(1234), BFwf_chain, Σ) | ||
p, = destructure(ps) | ||
length(p) | ||
wf(X, ps, st) | ||
@profview begin for i = 1:100000 wf(X, ps, st) end end | ||
|
||
ham = SumH(nuclei) | ||
sam = MHSampler(wf, Nel, nuclei, Δt = 0.5, burnin = 1000, nchains = 2000) | ||
|
||
#using BenchmarkTools # N = 10, nuc = 10 # 50, 6325, 408425 | ||
#@btime $wf($X, $ps, $st) # ord = 1: 22.764 μs (17 allocations: 19.67 KiB) | ||
# ord = 2: 119.143 μs (17 allocations: 19.67 KiB) | ||
# ord = 3: 9.800 ms (17 allocations: 19.67 KiB) | ||
|
||
#@btime $gradient($wf, $X, $ps, $st) # ord = 1: 81.785 μs (165 allocations: 153.27 KiB) | ||
# ord = 2: 742.233 μs (167 allocations: 1.11 MiB) | ||
# ord = 3: 60.314 ms (167 allocations: 62.47 MiB) | ||
|
||
#@btime $grad_params($wf, $X, $ps, $st) # ord = 1: 74.807 μs (142 allocations: 94.42 KiB) | ||
# ord = 2: 732.846 μs (144 allocations: 1.05 MiB) | ||
# ord = 3: 59.758 ms (144 allocations: 62.41 MiB) | ||
|
||
#@btime $laplacian($wf, $X, $ps, $st) # ord = 1: 1.215 ms (611 allocations: 2.20 MiB) | ||
# ord = 2: 25.875 ms (611 allocations: 2.20 MiB) | ||
# ord = 3: 2.648 s (611 allocations: 2.20 MiB) | ||
|
||
opt_vmc = VMC(5000, 0.015, ACEpsi.vmc.adamW(); lr_dc = 300.0) | ||
#wf, err_opt, ps = gd_GradientByVMC(opt_vmc, sam, ham, wf, ps, st) | ||
|
||
## MRCI+Q: -23.5092 | ||
## UHF: -23.2997 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using ACEpsi, Polynomials4ML, StaticArrays, Test | ||
using Polynomials4ML: natural_indices, degree, SparseProduct | ||
using ACEpsi.AtomicOrbitals: Nuc, make_nlms_spec, evaluate | ||
using ACEpsi: BackflowPooling, BFwf_lux, setupBFState, Jastrow, displayspec | ||
using ACEpsi.vmc: gradient, laplacian, grad_params, SumH, MHSampler, VMC, gd_GradientByVMC | ||
using ACEbase.Testing: print_tf, fdtest | ||
using LuxCore | ||
using Lux | ||
using Zygote | ||
using Optimisers | ||
using Random | ||
using Printf | ||
using LinearAlgebra | ||
using BenchmarkTools | ||
using HyperDualNumbers: Hyper | ||
|
||
n1 = Rnldegree = 1 | ||
Ylmdegree = 0 | ||
totdegree = 20 | ||
Nel = 10 | ||
X = randn(SVector{3, Float64}, Nel) | ||
Σ = [↑,↑,↑,↑,↑,↓,↓,↓,↓,↓] | ||
spacing = 1.0 | ||
nuclei = [Nuc(SVector(0.0,0.0,(i-1/2-Nel/2) * spacing), 1.0) for i = 1:Nel] | ||
Pn = Polynomials4ML.legendre_basis(n1+1) | ||
spec = [(n1 = 1, n2 = 1, l = 0)] | ||
|
||
# Ref: https://link.springer.com/book/10.1007/978-90-481-3862-3: P235 | ||
# STO: 0.7790 * e^(-1.24 * r) | ||
# ϕ_1s(1, r) = \sum_(k = 1)^K d_1s,k g_1s(α_1k, r) | ||
# g_1s(α, r) = (2α/π)^(3/4) * exp(-αr^2): α ∼ ζ, g ∼ D | ||
# sto-3g: Ref: https://www.basissetexchange.org/ | ||
# BASIS SET: (3s) -> [1s] | ||
# H S | ||
# 0.3425250914E+01 0.1543289673E+00 | ||
# 0.6239137298E+00 0.5353281423E+00 | ||
# 0.1688554040E+00 0.4446345422E+00 | ||
|
||
# ζ = [[0.3425250914E+01, 0.6239137298E+00, 0.1688554040E+00]] | ||
# D = [[0.1543289673E+00, 0.5353281423E+00, 0.4446345422E+00]] | ||
# D[1] = [(2 * ζ[1][i]/pi)^(3/4) * D[1][i] for i = 1:length(ζ[1])] | ||
# P_0(x) = 1/sqrt(2) | ||
# Y_0(x) = 1/(2*sqrt(pi)) | ||
|
||
# sto-6g: Ref: https://www.basissetexchange.org/ | ||
# BASIS SET: (6s) -> [1s] | ||
# H S | ||
# 0.3552322122E+02 0.9163596281E-02 | ||
# 0.6513143725E+01 0.4936149294E-01 | ||
# 0.1822142904E+01 0.1685383049E+00 | ||
# 0.6259552659E+00 0.3705627997E+00 | ||
# 0.2430767471E+00 0.4164915298E+00 | ||
# 0.1001124280E+00 0.1303340841E+00 | ||
|
||
ζ = [[0.3552322122E+02, 0.6513143725E+01, 0.1822142904E+01,0.6259552659E+00, 0.2430767471E+00, 0.1001124280E+00]] | ||
D = [[0.9163596281E-02, 0.4936149294E-01,0.1685383049E+00,0.3705627997E+00, 0.4164915298E+00, 0.1303340841E+00]] | ||
D[1] = [(2 * ζ[1][i]/pi)^(3/4) * D[1][i] for i = 1:length(ζ[1])] * sqrt(2) * 2 * sqrt(pi) | ||
|
||
Dn = STO_NG((ζ, D)) | ||
bRnl = AtomicOrbitalsRadials(Pn, Dn, spec) | ||
bYlm = RYlmBasis(Ylmdegree) | ||
|
||
ord = 3 | ||
wf, spec, spec1p = BFwf_chain, spec, spec1p = BFwf_lux(Nel, bRnl, bYlm, nuclei; totdeg = totdegree, ν = ord) | ||
|
||
ps, st = setupBFState(MersenneTwister(1234), BFwf_chain, Σ) # ps.hidden1.W: Nels * basis | ||
p, = destructure(ps) | ||
length(p) | ||
|
||
ham = SumH(nuclei) | ||
sam = MHSampler(wf, Nel, nuclei, Δt = 0.5, burnin = 1000, nchains = 2000) | ||
|
||
#using BenchmarkTools # N = 10, nuc = 10 # 10, 265, 3685 | ||
#@btime $wf($X, $ps, $st) # ord = 1: 17.197 μs (17 allocations: 6.86 KiB) | ||
# ord = 2: 23.086 μs (17 allocations: 6.86 KiB) | ||
# ord = 3: 78.264 μs (17 allocations: 6.86 KiB) | ||
|
||
#@btime $gradient($wf, $X, $ps, $st) # ord = 1: 56.969 μs (165 allocations: 100.73 KiB) | ||
# ord = 2: 75.596 μs (167 allocations: 143.98 KiB) | ||
# ord = 3: 889.464 μs (167 allocations: 681.77 KiB) | ||
|
||
#@btime $grad_params($wf, $X, $ps, $st) # ord = 1: 48.483 μs (142 allocations: 41.89 KiB) | ||
# ord = 2: 67.085 μs (144 allocations: 81.73 KiB) | ||
# ord = 3: 887.024 μs (144 allocations: 616.11 KiB) | ||
|
||
#@btime $laplacian($wf, $X, $ps, $st) # ord = 1: 738.616 μs (581 allocations: 720.28 KiB) | ||
# ord = 2: 1.747 ms (581 allocations: 720.28 KiB) | ||
# ord = 3: 20.752 ms (581 allocations: 720.28 KiB) | ||
|
||
opt_vmc = VMC(5000, 0.015, ACEpsi.vmc.adamW(); lr_dc = 100.0) | ||
wf, err_opt, ps = gd_GradientByVMC(opt_vmc, sam, ham, wf, ps, st) | ||
|
||
## FCI: -23.1140: ord = 2: -23.3829 | ||
## UHF: -23.0414: ord = 1: -23.0432 |
Oops, something went wrong.