Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BFwf with many grads and laps + Hyperduals #20

Closed
wants to merge 84 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
f4f5241
starting reorganisation towards 3d
Apr 20, 2023
82bc707
initial example or atomic orbitals
Apr 20, 2023
30e16c8
fix unit tests
Apr 20, 2023
a2bf38d
several steps towards 3d A basis
May 1, 2023
86cc764
lots of cleanup and drafting
May 1, 2023
7ea915f
working but untested evaluation of A
May 1, 2023
ab85417
first unit test for proto_evaluate passing
May 2, 2023
dddcb2c
test atorbbasis
DexuanZhou May 8, 2023
750a055
a small clean up for the draft for constructing A basis, depends on 0…
CheukHinHoJerry May 8, 2023
caee2be
add backflowpooing, define sensible constructor and test evaluate of …
CheukHinHoJerry May 8, 2023
efea037
small clean ups
CheukHinHoJerry May 8, 2023
541359a
add lux implementation draft
CheukHinHoJerry May 15, 2023
eb7ee05
use WrappedLayer
CheukHinHoJerry May 15, 2023
620c39a
clean up and move productbasis to P4ML
CheukHinHoJerry May 16, 2023
0323f17
minor fix
CheukHinHoJerry May 17, 2023
fdc6bda
add jastrow layer
DexuanZhou May 17, 2023
bd9474e
clean up
CheukHinHoJerry May 17, 2023
cfcab47
add test_rrule for js
DexuanZhou May 17, 2023
fdb23d5
minor fix
DexuanZhou May 17, 2023
81d1f6d
Merge branch '3d-2' into test_rrule
DexuanZhou May 18, 2023
41a2447
add backflow pooling rrule
CheukHinHoJerry May 18, 2023
84ccbc7
Merge branch 'test_rrule' of https://github.com/ACEsuit/ACEpsi.jl int…
CheukHinHoJerry May 18, 2023
9b57699
fix Zygote of jastrow
DexuanZhou May 18, 2023
ab8da0f
draft towards grad
CheukHinHoJerry May 23, 2023
0db7bea
test layers' pullback
DexuanZhou May 23, 2023
f5eae2c
add aobasis layer' pull back
DexuanZhou May 23, 2023
240f7cd
minor fix
DexuanZhou May 23, 2023
d5735db
Calling rrule correctly, fix correctness next
CheukHinHoJerry May 23, 2023
c35759f
add rrule of rnlexample
DexuanZhou May 24, 2023
e278b2b
add gradp test
CheukHinHoJerry May 27, 2023
061f2dc
draft HyperDual
CheukHinHoJerry May 30, 2023
3bbe08f
minor fix
CheukHinHoJerry May 30, 2023
dded5b1
minor change on test_bflow_lux
DexuanZhou May 31, 2023
94f6a5e
minor fix on hyper_real
DexuanZhou May 31, 2023
b96f307
minor fix
DexuanZhou May 31, 2023
fd4e9d2
pass lap test and grad test with hypderdual
CheukHinHoJerry Jun 1, 2023
ed6a971
rewrite dense layer
DexuanZhou Jun 2, 2023
f446849
add gradp_lap
DexuanZhou Jun 2, 2023
b936147
test clean ups
CheukHinHoJerry Jun 3, 2023
70d030c
minor fix
DexuanZhou Jun 5, 2023
ede054a
minor fix
DexuanZhou Jun 5, 2023
d653b37
replacing ProductBasis and aobasis with lux layer, bflow lux tests pa…
CheukHinHoJerry Jun 5, 2023
d1fd930
fix atorbbasis test
CheukHinHoJerry Jun 5, 2023
52a1201
fix type instability in bfpooling, more performance fix soon...
CheukHinHoJerry Jun 7, 2023
6171a0f
draft of vmc
DexuanZhou Jun 7, 2023
75bae97
Merge branch 'test_rrule' into vmc
DexuanZhou Jun 7, 2023
b69f3bb
add metropolis
DexuanZhou Jun 10, 2023
0eb5311
remove trans layer
DexuanZhou Jun 12, 2023
cbe3af4
Merge branch 'test_rrule' into vmc
DexuanZhou Jun 12, 2023
beaf70d
example of gaussian lux
DexuanZhou Jun 12, 2023
eb58a49
add vmc
DexuanZhou Jun 12, 2023
2b1784c
add example of He
DexuanZhou Jun 12, 2023
a42f67f
add example of harmonic_oscillator
DexuanZhou Jun 13, 2023
8d0dd49
minor fix
DexuanZhou Jun 13, 2023
5aec160
minor fix
DexuanZhou Jun 14, 2023
10c5c68
fix BFwf and performacen fix
CheukHinHoJerry Jun 15, 2023
83e65d9
fix dense layer with HyperDualsNumberExt with Octavian
CheukHinHoJerry Jun 15, 2023
fd76d44
minor fix
DexuanZhou Jun 20, 2023
6c27a5a
remove Octavian extension
CheukHinHoJerry Jun 20, 2023
007cc04
Merge branch 'vmc' of https://github.com/ACEsuit/ACEpsi.jl into vmc
CheukHinHoJerry Jun 20, 2023
afa90ab
minor change of js factor
DexuanZhou Jun 26, 2023
73a5ac5
add example of jastrow factor
DexuanZhou Jun 26, 2023
406bee8
minor fix
DexuanZhou Jun 26, 2023
eeea92e
minor fix
Jun 26, 2023
04cd372
minor fix
DexuanZhou Jun 28, 2023
00126e4
small change of spec
DexuanZhou Jun 28, 2023
6ca783b
minor fix
CheukHinHoJerry Jun 30, 2023
a71dc31
first step towards non-allocating lux interface...
CheukHinHoJerry Jun 30, 2023
1038576
add sr
DexuanZhou Jul 9, 2023
4d2b0da
minor fix
DexuanZhou Jul 10, 2023
bbfd1f7
minor change of sr
DexuanZhou Jul 28, 2023
d09e017
remove ACEcore dependency, add compat bounds of P4ML and Obejctpools
CheukHinHoJerry Aug 8, 2023
90c070a
add CI for julia 1.9
CheukHinHoJerry Aug 8, 2023
3a8186b
clean up
CheukHinHoJerry Aug 8, 2023
8428569
remove CI of J1.0, added and fixed all tests
CheukHinHoJerry Aug 8, 2023
2cde5c6
swap out dense layer by LinearLayer in P4ML
CheukHinHoJerry Aug 8, 2023
a2e16ed
add benchmark
CheukHinHoJerry Aug 8, 2023
fde91cb
remove consistency test with ACESchrodinger
CheukHinHoJerry Aug 9, 2023
d627877
quick fix on pullback performance
CheukHinHoJerry Aug 9, 2023
30a1a3d
add sto-ng example
DexuanZhou Sep 3, 2023
cf557a2
quick fix
CheukHinHoJerry Sep 5, 2023
c779077
hand written pb for aobassis and more performance fix
CheukHinHoJerry Sep 9, 2023
97f6d47
hand written pb w.r.t parameter
CheukHinHoJerry Sep 10, 2023
99f5653
add pb for gradp of sto-ng
DexuanZhou Sep 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
fail-fast: false
matrix:
version:
- '1.0'
- '1.8'
- '1.9'
- 'nightly'
os:
- ubuntu-latest
Expand Down
24 changes: 17 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,35 @@ version = "0.0.1"

[deps]
ACEbase = "14bae519-eb20-449c-a949-9c58ed33163e"
ACEcore = "44c1e890-45d1-48ea-94d6-c2ea5b573f71"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
ChainRules = "082447d4-558c-5d27-93f4-14fc19e9eca2"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
HyperDualNumbers = "50ceba7f-c3ee-5a84-a6e8-3ad40456ec97"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Lux = "b2108857-7c20-44ae-9111-449ecde12c47"
LuxCore = "bb33d45b-7691-41d6-9220-0943567d0623"
ObjectPools = "658cac36-ff0f-48ad-967c-110375d98c9d"
Octavian = "6fd5a793-0b7e-452c-907f-f8bfe9c57db4"
Optimisers = "3bd65402-5787-11e9-1adc-39752487f4e2"
Polynomials4ML = "03c4bcba-a943-47e9-bfa1-b1661fc2974f"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
StrideArrays = "d1fa6d79-ef01-42a6-86c9-f7c551f8593b"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[compat]
ACEcore = "0.0.1"
ACEbase = "0.4.2"
BenchmarkTools = "1"
ForwardDiff = "0.10"
ObjectPools = "0.0.2"
Polynomials4ML = "0.0.2"
julia = "1"
JSON = "0.21"
ACEbase = "0.2"

ObjectPools = "0.3.1"
julia = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
58 changes: 58 additions & 0 deletions benchmarks/benchmark_bflow_lux.jl
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
65 changes: 65 additions & 0 deletions examples/3D/Be.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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(K, Vext, Vee)
sam = MHSampler(wf, Nel, Δ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


# using Plots
# plot(abs.(err1 .- Eref), w = 3, yscale=:log10)
65 changes: 65 additions & 0 deletions examples/3D/He.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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, AdamW, SR
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 = 4
Ylmdegree = 2
totdegree = 4
Nel = 2
X = randn(SVector{3, Float64}, Nel)
Σ = [↑,↓]
nuclei = [ Nuc(zeros(SVector{3, Float64}), 2.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(K, Vext, Vee)
sam = MHSampler(wf, Nel, Δt = 0.5, burnin = 1000, nchains = 2000)

opt_vmc = VMC(3000, 0.0015, SR(1e-4, 0.015), lr_dc = 50)
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

Eref = -2.9037

# using Plots
# plot(abs.(err1 .- Eref), w = 3, yscale=:log10)
53 changes: 53 additions & 0 deletions examples/3D/harmonic_oscillator.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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 # mainly for the destrcuture(ps) function
using Random
using Printf
using LinearAlgebra
using BenchmarkTools
using HyperDualNumbers: Hyper



n1 = Rnldegree = 6
Ylmdegree = 1
totdegree = 10
Nel = 3
X = randn(SVector{3, Float64}, Nel)
Σ = [↑,↑,↓]
nuclei = [ Nuc(zeros(SVector{3, Float64}), 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]
ζ = rand(length(spec))
Dn = GaussianBasis(ζ)
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)
ps, st = setupBFState(MersenneTwister(1234), BFwf_chain, Σ)

wf(X, ps, st)

K(wf, X::AbstractVector, ps, st) = -0.5 * laplacian(wf, X, ps, st)

Vext(wf, X::AbstractVector, ps, st) = 1/2 * sum([X[i][j]^2 for i = 1:length(X) for j = 1:3]) #sum(1/norm(nuclei[i].rr - X[j]) for i = 1:length(nuclei) for j in 1:length(X))

Vee(wf, X::AbstractVector, ps, st) = 0 # sum(1/norm(X[i]-X[j]) for i = 1:length(X)-1 for j = i+1:length(X))

ham = SumH(K, Vext, Vee)
sam = MHSampler(wf, Nel, nuclei, Δt = 1.0, burnin = 1000, nchains = 2000)

opt_vmc = VMC(100, 0.05, ACEpsi.vmc.adamW(); lr_dc = 30.0)
wf, err_opt, ps = gd_GradientByVMC(opt_vmc, sam, ham, wf, ps, st)
63 changes: 63 additions & 0 deletions examples/3D/sto-3g_H.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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 # mainly for the destrcuture(ps) function
using Random
using Printf
using LinearAlgebra
using BenchmarkTools
using HyperDualNumbers: Hyper

n1 = Rnldegree = 1
Ylmdegree = 0
totdegree = 4
Nel = 1
X = randn(SVector{3, Float64}, Nel)
Σ = [↑]
nuclei = [Nuc(SVector(0.0,0.0,0.0), 1.0)]
##

# Defining AtomicOrbitalsBasis
n2 = 1
Pn = Polynomials4ML.legendre_basis(n1+1)
spec = [(n1 = 1, n2 = 1, l = 0) ]

ζ = [0.3425250914E+01, 0.6239137298E+00, 0.1688554040E+00]
ζ = reshape(ζ, 1, length(ζ))
D = [0.1543289673E+00, 0.5353281423E+00, 0.4446345422E+00]
D = reshape(D, 1, length(D))

Dn = STO_NG((ζ, D))
bRnl = AtomicOrbitalsRadials(Pn, Dn, spec)
bYlm = RYlmBasis(Ylmdegree)

# setup state
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)

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))
function Vee(wf, X::AbstractVector, ps, st)
nX = length(X)
if nX <=1
return 0
else
return sum(1/norm(X[i]-X[j]) for i = 1:length(X)-1 for j = i+1:length(X))
end
end

ham = SumH(K, Vext, Vee)
sam = MHSampler(wf, Nel, nuclei, Δt = 1.0, burnin = 1000, nchains = 2000)

opt_vmc = VMC(3000, 0.1, ACEpsi.vmc.adamW(); lr_dc = 100.0)
wf, err_opt, ps = gd_GradientByVMC(opt_vmc, sam, ham, wf, ps, st)
Loading