Skip to content

Commit

Permalink
Merge pull request #143 from MineralsCloud:PhononWorkflow
Browse files Browse the repository at this point in the history
Fix `PhononWorkflow`
  • Loading branch information
singularitti authored Oct 15, 2023
2 parents 7aa6de3 + 22a7247 commit f107bf5
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 320 deletions.
130 changes: 3 additions & 127 deletions src/ConvergenceTestWorkflow/Config.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module Config

using Configurations: OptionField, @option
using Configurations: OptionField
using ExpressBase.Config: SoftwareConfig
using QuantumESPRESSO.PWscf: PWInput

using ...QuantumESPRESSOExpress: QuantumESPRESSOConfig, MpiexecConfig, PwxConfig

import Configurations: from_dict
import Express.ConvergenceTestWorkflow.Config: StaticConfig, _update!

Expand All @@ -13,132 +15,6 @@ function _update!(conf, template::AbstractString)
return conf
end

@option struct MpiexecOptions <: SoftwareConfig
path::String = "mpiexec"
f::String = ""
hosts::Vector{String} = String[]
wdir::String = ""
configfile::String = ""
env::Union{Dict,Vector} = Dict(ENV)
np::UInt = 1
end

const MpiexecConfig = MpiexecOptions

"""
ParallelizationFlags(; nimage=0, npool=0, ntg=0, nyfft=0, nband=0, ndiag=0)
Construct parallelization flags of QuantumESPRESSO commands.
"""
@option mutable struct ParallelizationFlags
nimage::UInt = 0
npool::UInt = 0
ntg::UInt = 0
nyfft::UInt = 0
nband::UInt = 0
ndiag::UInt = 0
end

"""
PwxConfig(; path, chdir, options)
Create configurations for `pw.x`.
# Arguments
- `path::String="pw.x"`: the path to the executable.
- `chdir::Bool=true`: whether to change directory to where the input file is
stored when running `pw.x`. If `false`, stay in the current directory.
- `options::ParallelizationFlags=ParallelizationFlags()`: the parallelization
flags of `pw.x`.
"""
@option mutable struct PwxConfig <: SoftwareConfig
path::String = "pw.x"
chdir::Bool = true
options::ParallelizationFlags = ParallelizationFlags()
env::Union{Dict,Vector} = Dict(ENV)
end
"""
PhxConfig(; path, chdir, options)
Create configurations for `ph.x`.
# Arguments
- `path::String="ph.x"`: the path to the executable.
- `chdir::Bool=true`: whether to change directory to where the input file is
stored when running `ph.x`. If `false`, stay in the current directory.
- `options::ParallelizationFlags=ParallelizationFlags()`: the parallelization
flags of `ph.x`.
"""
@option mutable struct PhxConfig <: SoftwareConfig
path::String = "ph.x"
chdir::Bool = true
options::ParallelizationFlags = ParallelizationFlags()
env::Union{Dict,Vector} = Dict(ENV)
end
"""
Q2rxConfig(; path, chdir, options)
Create configurations for `q2r.x`.
# Arguments
- `path::String="q2r.x"`: the path to the executable.
- `chdir::Bool=true`: whether to change directory to where the input file is
stored when running `q2r.x`. If `false`, stay in the current directory.
- `options::ParallelizationFlags=ParallelizationFlags()`: the parallelization
flags of `q2r.x`.
"""
@option mutable struct Q2rxConfig <: SoftwareConfig
path::String = "q2r.x"
chdir::Bool = true
options::ParallelizationFlags = ParallelizationFlags()
env::Union{Dict,Vector} = Dict(ENV)
end
"""
MatdynxConfig(; path, chdir, options)
Create configurations for `matdyn.x`.
# Arguments
- `path::String="matdyn.x"`: the path to the executable.
- `chdir::Bool=true`: whether to change directory to where the input file is
stored when running `matdyn.x`. If `false`, stay in the current directory.
- `options::ParallelizationFlags=ParallelizationFlags()`: the parallelization
flags of `matdyn.x`.
"""
@option mutable struct MatdynxConfig <: SoftwareConfig
path::String = "matdyn.x"
chdir::Bool = true
options::ParallelizationFlags = ParallelizationFlags()
env::Union{Dict,Vector} = Dict(ENV)
end
"""
DynmatxConfig(; path, chdir, options)
Create configurations for `dynmat.x`.
# Arguments
- `path::String="dynmat.x"`: the path to the executable.
- `chdir::Bool=true`: whether to change directory to where the input file is
stored when running `dynmat.x`. If `false`, stay in the current directory.
- `options::ParallelizationFlags=ParallelizationFlags()`: the parallelization
flags of `dynmat.x`.
"""
@option mutable struct DynmatxConfig <: SoftwareConfig
path::String = "dynmat.x"
chdir::Bool = true
options::ParallelizationFlags = ParallelizationFlags()
env::Union{Dict,Vector} = Dict(ENV)
end

@option mutable struct QuantumESPRESSOConfig <: SoftwareConfig
mpi::MpiexecConfig = MpiexecConfig()
pw::PwxConfig = PwxConfig()
ph::PhxConfig = PhxConfig()
q2r::Q2rxConfig = Q2rxConfig()
matdyn::MatdynxConfig = MatdynxConfig()
dynmat::DynmatxConfig = DynmatxConfig()
end

function from_dict(
::Type{<:StaticConfig}, ::OptionField{:cli}, ::Type{SoftwareConfig}, dict
)
Expand Down
130 changes: 3 additions & 127 deletions src/EquationOfStateWorkflow/Config.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module Config

using Configurations: OptionField, @option
using Configurations: OptionField
using ExpressBase.Config: SoftwareConfig
using QuantumESPRESSO.PWscf: PWInput

using ...QuantumESPRESSOExpress: QuantumESPRESSOConfig, MpiexecConfig, PwxConfig

import Configurations: from_dict
import Express.EquationOfStateWorkflow.Config: StaticConfig, _update!

Expand All @@ -13,132 +15,6 @@ function _update!(conf, template::AbstractString)
return conf
end

@option struct MpiexecOptions <: SoftwareConfig
path::String = "mpiexec"
f::String = ""
hosts::Vector{String} = String[]
wdir::String = ""
configfile::String = ""
env::Union{Dict,Vector} = Dict(ENV)
np::UInt = 1
end

const MpiexecConfig = MpiexecOptions

"""
ParallelizationFlags(; nimage=0, npool=0, ntg=0, nyfft=0, nband=0, ndiag=0)
Construct parallelization flags of QuantumESPRESSO commands.
"""
@option mutable struct ParallelizationFlags
nimage::UInt = 0
npool::UInt = 0
ntg::UInt = 0
nyfft::UInt = 0
nband::UInt = 0
ndiag::UInt = 0
end

"""
PwxConfig(; path, chdir, options)
Create configurations for `pw.x`.
# Arguments
- `path::String="pw.x"`: the path to the executable.
- `chdir::Bool=true`: whether to change directory to where the input file is
stored when running `pw.x`. If `false`, stay in the current directory.
- `options::ParallelizationFlags=ParallelizationFlags()`: the parallelization
flags of `pw.x`.
"""
@option mutable struct PwxConfig <: SoftwareConfig
path::String = "pw.x"
chdir::Bool = true
options::ParallelizationFlags = ParallelizationFlags()
env::Union{Dict,Vector} = Dict(ENV)
end
"""
PhxConfig(; path, chdir, options)
Create configurations for `ph.x`.
# Arguments
- `path::String="ph.x"`: the path to the executable.
- `chdir::Bool=true`: whether to change directory to where the input file is
stored when running `ph.x`. If `false`, stay in the current directory.
- `options::ParallelizationFlags=ParallelizationFlags()`: the parallelization
flags of `ph.x`.
"""
@option mutable struct PhxConfig <: SoftwareConfig
path::String = "ph.x"
chdir::Bool = true
options::ParallelizationFlags = ParallelizationFlags()
env::Union{Dict,Vector} = Dict(ENV)
end
"""
Q2rxConfig(; path, chdir, options)
Create configurations for `q2r.x`.
# Arguments
- `path::String="q2r.x"`: the path to the executable.
- `chdir::Bool=true`: whether to change directory to where the input file is
stored when running `q2r.x`. If `false`, stay in the current directory.
- `options::ParallelizationFlags=ParallelizationFlags()`: the parallelization
flags of `q2r.x`.
"""
@option mutable struct Q2rxConfig <: SoftwareConfig
path::String = "q2r.x"
chdir::Bool = true
options::ParallelizationFlags = ParallelizationFlags()
env::Union{Dict,Vector} = Dict(ENV)
end
"""
MatdynxConfig(; path, chdir, options)
Create configurations for `matdyn.x`.
# Arguments
- `path::String="matdyn.x"`: the path to the executable.
- `chdir::Bool=true`: whether to change directory to where the input file is
stored when running `matdyn.x`. If `false`, stay in the current directory.
- `options::ParallelizationFlags=ParallelizationFlags()`: the parallelization
flags of `matdyn.x`.
"""
@option mutable struct MatdynxConfig <: SoftwareConfig
path::String = "matdyn.x"
chdir::Bool = true
options::ParallelizationFlags = ParallelizationFlags()
env::Union{Dict,Vector} = Dict(ENV)
end
"""
DynmatxConfig(; path, chdir, options)
Create configurations for `dynmat.x`.
# Arguments
- `path::String="dynmat.x"`: the path to the executable.
- `chdir::Bool=true`: whether to change directory to where the input file is
stored when running `dynmat.x`. If `false`, stay in the current directory.
- `options::ParallelizationFlags=ParallelizationFlags()`: the parallelization
flags of `dynmat.x`.
"""
@option mutable struct DynmatxConfig <: SoftwareConfig
path::String = "dynmat.x"
chdir::Bool = true
options::ParallelizationFlags = ParallelizationFlags()
env::Union{Dict,Vector} = Dict(ENV)
end

@option mutable struct QuantumESPRESSOConfig <: SoftwareConfig
mpi::MpiexecConfig = MpiexecConfig()
pw::PwxConfig = PwxConfig()
ph::PhxConfig = PhxConfig()
q2r::Q2rxConfig = Q2rxConfig()
matdyn::MatdynxConfig = MatdynxConfig()
dynmat::DynmatxConfig = DynmatxConfig()
end

function from_dict(
::Type{<:StaticConfig}, ::OptionField{:cli}, ::Type{SoftwareConfig}, dict
)
Expand Down
46 changes: 28 additions & 18 deletions src/PhononWorkflow/Config.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
module Config

using AbInitioSoftwareBase.Commands: MpiexecConfig
using Configurations: OptionField
using Express.PhononWorkflow.Config: StaticConfig, Template
using Express.PhononWorkflow.Config: StaticConfig
using ExpressBase:
SelfConsistentField,
DensityFunctionalPerturbationTheory,
RealSpaceForceConstants,
PhononDispersion,
PhononDensityOfStates
using ExpressBase.Config: SoftwareConfig
using QuantumESPRESSO.Commands:
QuantumESPRESSOConfig, PwxConfig, PhxConfig, Q2rxConfig, MatdynxConfig
using QuantumESPRESSO.PWscf: PWInput
using QuantumESPRESSO.PHonon: PhInput, Q2rInput, MatdynInput

using ...QuantumESPRESSOExpress:
MpiexecConfig, QuantumESPRESSOConfig, PwxConfig, PhxConfig, Q2rxConfig, MatdynxConfig

import Configurations: from_dict
import Express.PhononWorkflow.Config: ExpandConfig
import Express.PhononWorkflow.Config: StaticConfig, _update!

function (::ExpandConfig)(template::Template)
inputs = map(
(:scf, :dfpt, :q2r, :disp), (PWInput, PhInput, Q2rInput, MatdynInput)
) do field, T
str = read(getproperty(template, field), String)
parse(T, str)
function _update!(conf, templates::Vector{String})
stage, T = if conf.calculation isa SelfConsistentField
1, PWInput
elseif conf.calculation isa DensityFunctionalPerturbationTheory
2, PhInput
elseif conf.calculation isa RealSpaceForceConstants
3, Q2rInput
elseif conf.calculation isa PhononDispersion
4, MatdynInput
elseif conf.calculation isa PhononDensityOfStates
4, MatdynInput
else
4, DynmatInput
end
return (; zip((:scf, :dfpt, :q2r, :disp), inputs)...)
str = read(templates[stage], String)
conf.template = parse(T, str)
return conf
end

function from_dict(
::Type{<:StaticConfig}, ::OptionField{:cli}, ::Type{<:SoftwareConfig}, dict
)
return from_dict(StaticConfig, OptionField{:cli}(), QuantumESPRESSOConfig, dict)
end
function from_dict(
::Type{<:StaticConfig}, ::OptionField{:cli}, ::Type{QuantumESPRESSOConfig}, dict
::Type{<:StaticConfig}, ::OptionField{:cli}, ::Type{SoftwareConfig}, dict
)
return QuantumESPRESSOConfig(;
mpi=get(dict, "mpi", MpiexecConfig()),
Expand Down
Loading

0 comments on commit f107bf5

Please sign in to comment.