Skip to content

Commit

Permalink
splitting testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
epolack committed Dec 22, 2023
1 parent 49ba939 commit a57637b
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions benchmark/regression/testcases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@ high_symmetry = let
Atom(:O, [x, y, y]u"bohr", magnetic_moment=0),
]
system = periodic_system(atoms, lattice)
merge(DFTK.parse_system(system), (; temperature=0.03, Ecut=10, kgrid=[4,4,4],
n_electrons=45))
merge(DFTK.parse_system(system), (; temperature=0.03, Ecut=20, kgrid=[4,4,4],
n_electrons=45, description="high_sym"))
end
high_kpoints = merge(magnesium, (; kgrid=[13,13,13], Ecut=10))
high_Ecut = merge(magnesium, (; kgrid=[4,4,4], Ecut=60))
high_kpoints = merge(magnesium, (; kgrid=[13,13,13], Ecut=20, description="high_kpoint"))
high_Ecut = merge(magnesium, (; kgrid=[4,4,4], Ecut=60, description="high_Ecut"))

testcases = (; high_symmetry, high_kpoints, high_Ecut)
end


@testitem "Hamiltonian application" tags=[:regression] setup=[TestCases, Regression] begin
using DFTK
using LinearAlgebra
using BenchmarkTools
using .Main: SUITE

SUITE["ham"] = BenchmarkGroup()
for testcase in Regression.testcases
model = Model(testcase.lattice, testcase.atoms, testcase.positions;
testcase.temperature, terms=[Kinetic()])
Expand All @@ -46,10 +49,10 @@ end

(; ham) = energy_hamiltonian(basis, ψ, occupation)

SUITE["ham"] = BenchmarkGroup()
SUITE["ham"] = @benchmarkable for ik = 1:length($(basis.kpoints))
$(ham.blocks)[ik]*$ψ[ik]
end
SUITE["ham"][testcase.description] =
@benchmarkable for ik = 1:length($(basis.kpoints))
$(ham.blocks)[ik]*$ψ[ik]
end
end
end

Expand All @@ -58,12 +61,13 @@ end
using BenchmarkTools
using .Main: SUITE

SUITE["scf"] = BenchmarkGroup()
for testcase in Regression.testcases
model = model_LDA(testcase.lattice, testcase.atoms, testcase.positions;
testcase.temperature)
basis = PlaneWaveBasis(model; testcase.Ecut, testcase.kgrid)
SUITE["scf"] = BenchmarkGroup()
SUITE["scf"] = @benchmarkable self_consistent_field($basis; tol=1e5)
SUITE["scf"][testcase.description] =
@benchmarkable self_consistent_field($basis; tol=1e5)
end
end

Expand All @@ -72,6 +76,7 @@ end
using BenchmarkTools
using .Main: SUITE

SUITE["density"] = BenchmarkGroup()
for testcase in Regression.testcases
model = model_LDA(testcase.lattice, testcase.atoms, testcase.positions;
testcase.temperature)
Expand All @@ -81,9 +86,10 @@ end
ψ, occupation = DFTK.select_occupied_orbitals(basis, scfres.ψ, scfres.occupation;
threshold=1e-6)

SUITE["density", "ρ", "sym"] = BenchmarkGroup()
SUITE["density", "ρ"] = @benchmarkable compute_density($basis, $ψ, $occupation)
SUITE["density", "sym"] = @benchmarkable DFTK.symmetrize_ρ($basis, $(scfres.ρ))
SUITE["density"]["ρ"][testcase.description] =
@benchmarkable compute_density($basis, $ψ, $occupation)
SUITE["density"]["sym"][testcase.description] =
@benchmarkable DFTK.symmetrize_ρ($basis, $(scfres.ρ))
end
end

Expand All @@ -92,12 +98,13 @@ end
using BenchmarkTools
using .Main: SUITE

SUITE["basis"] = BenchmarkGroup()
for testcase in Regression.testcases
model = model_LDA(testcase.lattice, testcase.atoms, testcase.positions;
testcase.temperature)
SUITE["basis"] = BenchmarkGroup()
SUITE["basis"] = @benchmarkable PlaneWaveBasis($model; Ecut=$(testcase.Ecut),
kgrid=$(testcase.kgrid))
SUITE["basis"][testcase.description] =
@benchmarkable PlaneWaveBasis($model;
Ecut=$(testcase.Ecut), kgrid=$(testcase.kgrid))
end
end

Expand All @@ -106,15 +113,16 @@ end
using BenchmarkTools
using .Main: SUITE

SUITE["response", "sternheimer"] = BenchmarkGroup()
for testcase in Regression.testcases
model = model_LDA(testcase.lattice, testcase.atoms, testcase.positions;
testcase.temperature)
basis = PlaneWaveBasis(model; testcase.Ecut, testcase.kgrid)
scfres = self_consistent_field(basis; tol=10)

rhs = DFTK.compute_projected_gradient(basis, scfres.ψ, scfres.occupation)
SUITE["sternheimer"] = BenchmarkGroup()
SUITE["sternheimer"] = @benchmarkable DFTK.solve_ΩplusK_split($scfres, $rhs)
SUITE["response", "sternheimer"][testcase.description] =
@benchmarkable DFTK.solve_ΩplusK_split($scfres, $rhs; tol=1e-2)
end
end

Expand Down Expand Up @@ -146,7 +154,7 @@ end
end

# Function to compute the dipole for a given field strength
function compute_dipole(ε; tol=1e-8, kwargs...)
function compute_dipole(ε; tol=1e-2, kwargs...)
scfres = self_consistent_field(make_basis(ε; kwargs...); tol)
dipole(scfres.basis, scfres.ρ)
end
Expand Down

0 comments on commit a57637b

Please sign in to comment.