Skip to content

Commit

Permalink
Print an error if non-positive dt is detected (#192)
Browse files Browse the repository at this point in the history
Print an error if non-positive `dt` is detected when constructing an integrator. A negative timesteps can be attained with a mutable update, e.g. `dyn.Δt *= -1`.

Also deprecate `Base.copy(::Langevin)`. We might add it back depending on the resolution to #193. The story here will continue to evolve, but for now it's safe to err on the side of a thinner public API.
  • Loading branch information
kbarros authored Nov 15, 2023
1 parent 72b35a6 commit bc658c8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
19 changes: 11 additions & 8 deletions src/Integrators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ mutable struct Langevin
Δt :: Float64
λ :: Float64
kT :: Float64
end

Langevin(Δt; λ, kT) = Langevin(Δt, λ, kT)

Base.copy(dyn::Langevin) = Langevin(dyn.Δt, dyn.λ, dyn.kT)
function Langevin(Δt; λ, kT)
Δt <= 0 && error("Select positive Δt")
return new(Δt, λ, kT)
end
end

"""
ImplicitMidpoint(Δt::Float64; atol=1e-12) where N
Expand All @@ -39,10 +40,12 @@ periods of simulation time.
mutable struct ImplicitMidpoint
Δt :: Float64
atol :: Float64
end

ImplicitMidpoint(Δt; atol=1e-12) = ImplicitMidpoint(Δt, atol)

function ImplicitMidpoint(Δt; atol=1e-12)
Δt <= 0 && error("Select positive Δt")
return new(Δt, atol)
end
end


################################################################################
Expand Down Expand Up @@ -210,4 +213,4 @@ function rhs_ll!(ΔZ, HZ, integrator, sys)
for site in eachsite(sys)
ΔZ[site] = - Δt*im*HZ[site]
end
end
end
5 changes: 5 additions & 0 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ end

Base.@deprecate suggest_magnetic_supercell(qs, latsize) suggest_magnetic_supercell(qs)
Base.@deprecate offline_viewers() ()

function Base.copy(dyn::Langevin)
@warn "Base.copy(dyn::Langevin) will soon be removed! Use `Langevin(dyn.Δt; dyn.λ, dyn.kT)` instead."
Langevin(dyn.Δt; dyn.λ, dyn.kT)
end
4 changes: 2 additions & 2 deletions test/test_jet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
sampler = LocalSampler(kT=0.2; propose)
@test_opt step!(sys, sampler)

langevin = Langevin(0.01, kT=0.2, λ=0.1)
langevin = Langevin(0.01; kT=0.2, λ=0.1)
@test_opt step!(sys, langevin)

integrator = ImplicitMidpoint(0.01)
Expand Down Expand Up @@ -48,7 +48,7 @@ end
step!(sys, sampler)
@test 0 == @allocated step!(sys, sampler)

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

Expand Down
4 changes: 2 additions & 2 deletions test/test_samplers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
collect_dur = 100.0

sys = su3_anisotropy_model(; D, L, seed=0)
langevin = Langevin(Δt; kT=0.0, λ)
langevin = Langevin(Δt; kT=0, λ)

for kT in kTs
langevin.kT = kT
Expand All @@ -96,7 +96,7 @@
collect_dur = 200.0

sys = su5_anisotropy_model(; D, L, seed=0)
langevin = Langevin(Δt; kT=0.0, λ)
langevin = Langevin(Δt; kT=0, λ)

for kT kTs
langevin.kT = kT
Expand Down

0 comments on commit bc658c8

Please sign in to comment.