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

Get to zero allocations in sampling and dynamics #81

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Changes from all commits
Commits
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
40 changes: 33 additions & 7 deletions test/test_jet.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testitem "JET stability" begin
@testitem "Type stability" begin
using JET

function test(mode)
Expand All @@ -22,12 +22,38 @@
langevin = Langevin(0.01, kT=0.2, λ=0.1)
@test_opt step!(sys, langevin)

# Test type stability of ImplicitMidpoint. For some reason, isapprox()
# on lists of SVectors is only type stable for Julia >= v1.9.
if VERSION >= v"1.9-beta"
integrator = ImplicitMidpoint(0.01)
@test_opt step!(sys, integrator)
end
# Test type stability of ImplicitMidpoint
integrator = ImplicitMidpoint(0.01)
@test_opt step!(sys, integrator)
end

test(:dipole)
test(:SUN)
end

# In the future this should be a static analysis, but for now we can explicitly
# run the functions. See https://github.com/aviatesk/JET.jl/issues/286
@testitem "Memory allocations" begin
function test(mode)
latvecs = lattice_vectors(1,1,2,90,90,90)
crystal = Crystal(latvecs, [[0,0,0]])
L = 2
sys = System(crystal, (L,L,1), [SpinInfo(1, S=1)], mode)
set_exchange!(sys, -1.0, Bond(1,1,(1,0,0)))
polarize_spins!(sys, (0,0,1))

propose = @mix_proposals 0.5 propose_flip 0.5 propose_delta(0.2)
sampler = LocalSampler(kT=0.2; propose)
step!(sys, sampler)
@test 0 == @allocated step!(sys, sampler)

langevin = Langevin(0.01, kT=0.2, λ=0.1)
step!(sys, langevin)
@test 0 == @allocated step!(sys, langevin)

integrator = ImplicitMidpoint(0.01)
step!(sys, integrator)
@test 0 == @allocated step!(sys, integrator)
end

test(:dipole)
Expand Down