From 541b954f38b6947a7446b97d01d4fe96b15bc393 Mon Sep 17 00:00:00 2001 From: singularitti Date: Sat, 14 Oct 2023 22:54:43 -0400 Subject: [PATCH 1/6] Rewrite `isconvergent` with `threshold` --- src/ConvergenceTestWorkflow/actions.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ConvergenceTestWorkflow/actions.jl b/src/ConvergenceTestWorkflow/actions.jl index b9dd83ff..8f56b570 100644 --- a/src/ConvergenceTestWorkflow/actions.jl +++ b/src/ConvergenceTestWorkflow/actions.jl @@ -30,8 +30,9 @@ struct TestConvergence{T} <: Action{T} end (::TestConvergence)(data) = isconvergent(data) -function isconvergent(a) - terms = abs.(diff(collect(a))) - x, y, z = last(terms, 3) - return all(0 <= r < 1 for r in (y / x, z / y)) +function isconvergent(iter, threshold) + last3 = last(sort(iter; by=first), 3) # Sort a `Set` of `Pair`s by the keys, i.e., increasing cutoff energies + min, max = extrema(last3) + range = abs(max - min) + return zero(range) <= range <= threshold end From b8b54b87d428206e82a89f248214e146bc71692f Mon Sep 17 00:00:00 2001 From: singularitti Date: Sat, 14 Oct 2023 22:56:33 -0400 Subject: [PATCH 2/6] Rename field `criteria` to `threshold` in `StaticConfig` --- src/ConvergenceTestWorkflow/Config.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ConvergenceTestWorkflow/Config.jl b/src/ConvergenceTestWorkflow/Config.jl index f30557d7..e9869c0e 100644 --- a/src/ConvergenceTestWorkflow/Config.jl +++ b/src/ConvergenceTestWorkflow/Config.jl @@ -38,16 +38,16 @@ end recipe::String template::String with::Union{CutoffEnergies,MonkhorstPackGrids} - criteria::Quantity + threshold::Quantity io::IO = IO() data::Data = Data() cli::SoftwareConfig - function StaticConfig(recipe, template, with, criteria, io, data, cli) + function StaticConfig(recipe, template, with, threshold, io, data, cli) @assert recipe in ("ecut", "kmesh") if !isfile(template) @warn "I cannot find template file `$template`!" end - return new(recipe, template, with, criteria, io, data, cli) + return new(recipe, template, with, threshold, io, data, cli) end end From 391a5ed5f1449492cf4c1f3b51180081ac3ff1a5 Mon Sep 17 00:00:00 2001 From: singularitti Date: Sat, 14 Oct 2023 22:56:46 -0400 Subject: [PATCH 3/6] Add `_update!` for `threshold` --- src/ConvergenceTestWorkflow/Config.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ConvergenceTestWorkflow/Config.jl b/src/ConvergenceTestWorkflow/Config.jl index e9869c0e..a9cd6a4b 100644 --- a/src/ConvergenceTestWorkflow/Config.jl +++ b/src/ConvergenceTestWorkflow/Config.jl @@ -80,6 +80,10 @@ function _update!(conf::Conf, data::Data) conf.data.raw = abspath(expanduser(data.raw)) return conf end +function _update!(conf::Conf, threshold::Quantity) + conf.threshold = threshold + return conf +end function expand(config::StaticConfig, calculation::Calculation) conf = Conf() @@ -89,6 +93,7 @@ function expand(config::StaticConfig, calculation::Calculation) _update!(conf, config.with) _update!(conf, config.io, config.with) _update!(conf, config.data) + _update!(conf, config.threshold) return conf end From d3828cb9fa44e45f13eedf13ff9670f89358b48d Mon Sep 17 00:00:00 2001 From: singularitti Date: Sat, 14 Oct 2023 22:57:31 -0400 Subject: [PATCH 4/6] Fix functor `TestConvergence` --- src/ConvergenceTestWorkflow/actions.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ConvergenceTestWorkflow/actions.jl b/src/ConvergenceTestWorkflow/actions.jl index 8f56b570..ea43b007 100644 --- a/src/ConvergenceTestWorkflow/actions.jl +++ b/src/ConvergenceTestWorkflow/actions.jl @@ -28,7 +28,7 @@ end struct TestConvergence{T} <: Action{T} calculation::T end -(::TestConvergence)(data) = isconvergent(data) +(::TestConvergence)(threshold) = Base.Fix2(isconvergent, threshold) function isconvergent(iter, threshold) last3 = last(sort(iter; by=first), 3) # Sort a `Set` of `Pair`s by the keys, i.e., increasing cutoff energies From 468da1a9808e210b53315e70c6d0b4c6bc7a719c Mon Sep 17 00:00:00 2001 From: singularitti Date: Sat, 14 Oct 2023 22:57:39 -0400 Subject: [PATCH 5/6] Fix `think` for `TestConvergence` --- src/ConvergenceTestWorkflow/think.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ConvergenceTestWorkflow/think.jl b/src/ConvergenceTestWorkflow/think.jl index 0fb88d46..e449afe0 100644 --- a/src/ConvergenceTestWorkflow/think.jl +++ b/src/ConvergenceTestWorkflow/think.jl @@ -10,7 +10,7 @@ think(action::CreateInput, conf::Conf) = think(action::ExtractData, conf::Conf) = collect(Thunk(action, file) for file in last.(conf.io)) think(action::SaveData, conf::Conf) = Thunk(action(conf.data.raw)) -think(action::TestConvergence, ::Conf) = Thunk(action) +think(action::TestConvergence, conf::Conf) = Thunk(action, conf.threshold) function think(action::Action{T}, config::StaticConfig) where {T} config = expand(config, T()) return think(action, config::Conf) From 8fb5e56d09502bd5f8ba5b8d1b9d3f81e7157df7 Mon Sep 17 00:00:00 2001 From: singularitti Date: Sat, 14 Oct 2023 23:00:40 -0400 Subject: [PATCH 6/6] Fix `isconvergent` --- src/ConvergenceTestWorkflow/actions.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ConvergenceTestWorkflow/actions.jl b/src/ConvergenceTestWorkflow/actions.jl index ea43b007..203f4c64 100644 --- a/src/ConvergenceTestWorkflow/actions.jl +++ b/src/ConvergenceTestWorkflow/actions.jl @@ -32,7 +32,7 @@ end function isconvergent(iter, threshold) last3 = last(sort(iter; by=first), 3) # Sort a `Set` of `Pair`s by the keys, i.e., increasing cutoff energies - min, max = extrema(last3) + min, max = extrema(last.(last3)) # Get the minimum and maximum energies from the last 3 pairs range = abs(max - min) return zero(range) <= range <= threshold end