Skip to content

Commit 59e82e3

Browse files
authored
Merge branch 'master' into inexact_krylov
2 parents 0aa5cb3 + 47a7361 commit 59e82e3

File tree

7 files changed

+94
-8
lines changed

7 files changed

+94
-8
lines changed

benchmark/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
AtomsIO = "1692102d-eeb4-4df9-807b-c9517f998d44"
33
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
44
DFTK = "acf6eb54-70d9-11e9-0013-234b7a5f5337"
5+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
56
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
7+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
68
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
79
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
810
PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d"

benchmark/benchmarks.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ const SUITE = BenchmarkGroup()
1313
@include_case SUITE "silicon"
1414
@include_case SUITE "aluminium_rattled"
1515
@include_case SUITE "SrVO3"
16+
@include_case SUITE "aluminium12"

benchmark/cases/Al12.extxyz

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
12
2+
pbc=[T, T, T] Lattice="12.15000000 0.00000000 0.00000000 0.00000000 4.05000000 0.00000000 0.00000000 0.00000000 4.05000000" Properties=species:S:1:pos:R:3:velocities:R:3:Z:I:1
3+
Al 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 13
4+
Al 0.00000000 2.02500000 2.02500000 0.00000000 0.00000000 0.00000000 13
5+
Al 2.02500000 0.00000000 2.02500000 0.00000000 0.00000000 0.00000000 13
6+
Al 2.02500000 2.02500000 0.00000000 0.00000000 0.00000000 0.00000000 13
7+
Al 4.05000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 13
8+
Al 4.05000000 2.02500000 2.02500000 0.00000000 0.00000000 0.00000000 13
9+
Al 6.07500000 0.00000000 2.02500000 0.00000000 0.00000000 0.00000000 13
10+
Al 6.07500000 2.02500000 0.00000000 0.00000000 0.00000000 0.00000000 13
11+
Al 8.10000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 13
12+
Al 8.10000000 2.02500000 2.02500000 0.00000000 0.00000000 0.00000000 13
13+
Al 10.12500000 0.00000000 2.02500000 0.00000000 0.00000000 0.00000000 13
14+
Al 10.12500000 2.02500000 0.00000000 0.00000000 0.00000000 0.00000000 13

benchmark/cases/aluminium12.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This is a 12-atom Al supercell without any rattling.
2+
3+
module aluminium12
4+
include("common.jl")
5+
6+
const SUITE = BenchmarkGroup(["metal", "PBE", "fast"])
7+
function setup_basis(; symmetries=true, kgrid=(3, 7, 7))
8+
system = load_system(joinpath(@__DIR__, "Al12.extxyz"))
9+
pseudopotentials = PseudoFamily("dojo.nc.sr.pbe.v0_4_1.stringent.upf")
10+
model = model_DFT(system; pseudopotentials, functionals=PBE(), symmetries,
11+
temperature=1e-3, smearing=Smearing.Gaussian())
12+
PlaneWaveBasis(model; Ecut=30, kgrid)
13+
end
14+
15+
#=
16+
basis = setup_basis()
17+
scfres = setup_dummy_scfres(basis)
18+
=#
19+
20+
# Response benchmark
21+
scfres_nosym = setup_dummy_scfres(setup_basis(; symmetries=false, kgrid=(1, 2, 2));
22+
mixing=KerkerMixing())
23+
perturb = setup_atomic_perturbation(scfres_nosym)
24+
SUITE["response"] = @benchmarkable bm_response($scfres_nosym, $perturb) evals=1 samples=1
25+
26+
end

benchmark/cases/aluminium_rattled.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ function setup_basis()
1414
PlaneWaveBasis(model; Ecut=64, kgrid=(1, 1, 1))
1515
end
1616

17-
basis = setup_basis()
18-
scfres = setup_dummy_scfres(basis)
17+
basis = setup_basis()
18+
scfres = setup_dummy_scfres(basis)
1919

2020
# Assemble benchmarks
2121
SUITE["setup"] = @benchmarkable setup_basis() evals=1 samples=3

benchmark/cases/common.jl

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,46 @@
11
using AtomsIO
22
using BenchmarkTools
33
using DFTK
4+
using ForwardDiff
5+
using LinearAlgebra
46
using PseudoPotentialData
57
using Random
68

7-
function setup_dummy_scfres(basis)
9+
function setup_dummy_scfres(basis; kwargs...)
810
Random.seed!(42)
9-
self_consistent_field(basis; maxiter=1, callback=identity)
11+
self_consistent_field(basis; maxiter=1, callback=identity, kwargs...)
1012
end
1113

14+
function setup_atomic_perturbation(scfres; n_displaced=4)
15+
# Displace up to n_displaced atoms into a random direction.
16+
#
17+
basis = scfres.basis
18+
model = scfres.basis.model
19+
@assert length(model.symmetries) == 1 # Symmetries disabled in model
20+
21+
Random.seed!(1234)
22+
n_displaced = min(n_displaced, length(model.positions))
23+
displaced_atoms = shuffle(1:length(model.positions))[1:n_displaced]
24+
R = map(1:length(model.positions)) do i
25+
if i in displaced_atoms
26+
normalize!(-ones(3) + 2 * rand(3))
27+
else
28+
zeros(3)
29+
end
30+
end
31+
32+
function displacement::T) where {T}
33+
newpositions = basis.model.positions + ε * R
34+
modelV = Model(Matrix{T}(model.lattice), model.atoms, newpositions;
35+
terms=[DFTK.AtomicLocal(), DFTK.AtomicNonlocal()], symmetries=false)
36+
basisV = PlaneWaveBasis(modelV; basis.Ecut, basis.kgrid)
37+
DFTK.total_local_potential(Hamiltonian(basisV))
38+
end
39+
δV = ForwardDiff.derivative(displacement, 0.0)
40+
δHψ = -DFTK.multiply_ψ_by_blochwave(scfres.basis, scfres.ψ, δV, zeros(3))
41+
end
42+
43+
1244
#
1345
# Benchmarks
1446
#
@@ -21,10 +53,15 @@ end
2153

2254
bm_compute_forces(scfres) = compute_forces_cart(scfres)
2355

56+
function bm_response(scfres, δHψ; tol=1e-6, kwargs...)
57+
Random.seed!(101)
58+
DFTK.solve_ΩplusK_split(scfres, δHψ; tol, callback=identity, kwargs...)
59+
end
60+
2461
# TODO other benchmarks to include:
2562
# - Hamiltonian application
2663
# - Diagonalisation
27-
# - Response
64+
# - Elastic constant computation
2865

2966
#
3067
# Benchmark collections

benchmark/cases/silicon.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module silicon
44
include("common.jl")
55

66
const SUITE = BenchmarkGroup(["insulator", "LDA", "fast"])
7-
function setup_basis()
7+
function setup_basis(; symmetries=true, kgrid=(8, 8, 8))
88
a = 10.26 # Silicon lattice constant in Bohr
99
lattice = a / 2 * [[0 1 1.];
1010
[1 0 1.];
@@ -13,8 +13,8 @@ function setup_basis()
1313
atoms = [Si, Si]
1414
positions = [ones(3)/8, -ones(3)/8]
1515

16-
model = model_DFT(lattice, atoms, positions; functionals=LDA())
17-
PlaneWaveBasis(model; Ecut=35, kgrid=(8, 8, 8))
16+
model = model_DFT(lattice, atoms, positions; functionals=LDA(), symmetries)
17+
PlaneWaveBasis(model; Ecut=35, kgrid)
1818
end
1919

2020
basis = setup_basis()
@@ -23,4 +23,10 @@ scfres = setup_dummy_scfres(basis)
2323
# Assemble benchmarks
2424
SUITE["setup"] = @benchmarkable setup_basis() evals=1 samples=3
2525
add_default_benchmarks!(SUITE, basis, scfres)
26+
27+
# Response benchmark
28+
scfres_nosym = setup_dummy_scfres(setup_basis(; symmetries=false, kgrid=(4, 4, 4)))
29+
perturb = setup_atomic_perturbation(scfres_nosym)
30+
SUITE["response"] = @benchmarkable bm_response($scfres_nosym, $perturb; tol=1e-8) evals=1 samples=1
31+
2632
end

0 commit comments

Comments
 (0)