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 812b783
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions benchmark/regression/testcases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ 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
Expand All @@ -46,10 +48,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 @@ -62,8 +64,8 @@ end
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 @@ -81,9 +83,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 @@ -95,9 +98,9 @@ end
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 @@ -113,8 +116,8 @@ end
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,11 +149,10 @@ 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

SUITE["response", "ad"] = BenchmarkGroup()
SUITE["response", "ad"] = @benchmarkable ForwardDiff.derivative($compute_dipole, 0.0)
SUITE["response"]["ad"] = @benchmarkable ForwardDiff.derivative($compute_dipole, 0.0)
end

0 comments on commit 812b783

Please sign in to comment.