Skip to content

Commit

Permalink
Merge pull request #59 from MineralsCloud:args
Browse files Browse the repository at this point in the history
Remove `path` in `PwxConfig`, etc., use `pw_path`, etc.
  • Loading branch information
singularitti authored Oct 25, 2021
2 parents 2835b03 + 61e67e0 commit a6aa719
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 24 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Configurations = "5218b696-f38b-4ac9-8b61-a12ec717816d"
AbInitioSoftwareBase = "df5135bc-470e-46c6-b451-292e27ca5b84"
Comonicon = "863f3e99-da2a-4334-8734-de3dacbe5542"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand All @@ -18,6 +19,7 @@ Compat = "3.16"
Configurations = "0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.10, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16"
AbInitioSoftwareBase = "0.4, 0.5, 0.6"
Comonicon = "0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9"
Preferences = "1"

[targets]
test = ["Test"]
150 changes: 126 additions & 24 deletions src/QuantumESPRESSOCommands.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
module QuantumESPRESSOCommands

using AbInitioSoftwareBase: parentdir
using AbInitioSoftwareBase.Commands: CommandConfig, MpiexecConfig, mpiexec
using AbInitioSoftwareBase.Commands: CommandConfig, mpiexec
using Comonicon: @cast, @main
using Compat: addenv
using Configurations: from_dict, @option
@static if VERSION >= v"1.6"
using Preferences: @load_preference
end

@static if VERSION >= v"1.6"
const pw_path = @load_preference("pw.x path", "pw.x")
const ph_path = @load_preference("ph.x path", "ph.x")
const q2r_path = @load_preference("q2r.x path", "q2r.x")
const matdyn_path = @load_preference("matdyn.x path", "matdyn.x")
const dynmat_path = @load_preference("dynmat.x path", "dynmat.x")
else
const pw_path = "pw.x"
const ph_path = "ph.x"
const q2r_path = "q2r.x"
const matdyn_path = "matdyn.x"
const dynmat_path = "dynmat.x"
end

export pw, ph, q2r, matdyn, dynmat

Expand Down Expand Up @@ -35,7 +51,6 @@ Create configurations for `pw.x`.
flags of `pw.x`.
"""
@option mutable struct PwxConfig <: CommandConfig
path::String = "pw.x"
chdir::Bool = true
options::ParallelizationFlags = ParallelizationFlags()
env::Union{Dict,Vector} = Dict(ENV)
Expand All @@ -53,7 +68,6 @@ Create configurations for `ph.x`.
flags of `ph.x`.
"""
@option mutable struct PhxConfig <: CommandConfig
path::String = "ph.x"
chdir::Bool = true
options::ParallelizationFlags = ParallelizationFlags()
env::Union{Dict,Vector} = Dict(ENV)
Expand All @@ -71,7 +85,6 @@ Create configurations for `q2r.x`.
flags of `q2r.x`.
"""
@option mutable struct Q2rxConfig <: CommandConfig
path::String = "q2r.x"
chdir::Bool = true
options::ParallelizationFlags = ParallelizationFlags()
env::Union{Dict,Vector} = Dict(ENV)
Expand All @@ -89,7 +102,6 @@ Create configurations for `matdyn.x`.
flags of `matdyn.x`.
"""
@option mutable struct MatdynxConfig <: CommandConfig
path::String = "matdyn.x"
chdir::Bool = true
options::ParallelizationFlags = ParallelizationFlags()
env::Union{Dict,Vector} = Dict(ENV)
Expand All @@ -107,7 +119,6 @@ Create configurations for `dynmat.x`.
flags of `dynmat.x`.
"""
@option mutable struct DynmatxConfig <: CommandConfig
path::String = "dynmat.x"
chdir::Bool = true
options::ParallelizationFlags = ParallelizationFlags()
env::Union{Dict,Vector} = Dict(ENV)
Expand Down Expand Up @@ -145,9 +156,24 @@ Run command `pw.x`.
np = 1,
path = "pw.x",
chdir = false,
nimage = 0,
npool = 0,
ntg = 0,
nyfft = 0,
nband = 0,
ndiag = 0,
)
mpi = MpiexecConfig(; np = np)
main = PwxConfig(; path = path, chdir = chdir)
main = PwxConfig(;
path = path,
chdir = chdir,
nimage = nimage,
npool = npool,
ntg = ntg,
nyfft = nyfft,
nband = nband,
ndiag = ndiag,
)
cmd = makecmd(input, output; mpi = mpi, main = main)
return run(cmd)
end
Expand All @@ -174,9 +200,24 @@ Run command `ph.x`.
np = 1,
path = "ph.x",
chdir = true,
nimage = 0,
npool = 0,
ntg = 0,
nyfft = 0,
nband = 0,
ndiag = 0,
)
mpi = MpiexecConfig(; np = np)
main = PhxConfig(; path = path, chdir = chdir)
main = PhxConfig(;
path = path,
chdir = chdir,
nimage = nimage,
npool = npool,
ntg = ntg,
nyfft = nyfft,
nband = nband,
ndiag = ndiag,
)
cmd = makecmd(input, output; mpi = mpi, main = main)
return run(cmd)
end
Expand All @@ -203,9 +244,24 @@ Run command `q2r.x`.
np = 1,
path = "q2r.x",
chdir = true,
nimage = 0,
npool = 0,
ntg = 0,
nyfft = 0,
nband = 0,
ndiag = 0,
)
mpi = MpiexecConfig(; np = np)
main = Q2rxConfig(; path = path, chdir = chdir)
main = Q2rxConfig(;
path = path,
chdir = chdir,
nimage = nimage,
npool = npool,
ntg = ntg,
nyfft = nyfft,
nband = nband,
ndiag = ndiag,
)
cmd = makecmd(input, output; mpi = mpi, main = main)
return run(cmd)
end
Expand All @@ -232,9 +288,24 @@ Run command `matdyn.x`.
np = 1,
path = "matdyn.x",
chdir = true,
nimage = 0,
npool = 0,
ntg = 0,
nyfft = 0,
nband = 0,
ndiag = 0,
)
mpi = MpiexecConfig(; np = np)
main = MatdynxConfig(; path = path, chdir = chdir)
main = MatdynxConfig(;
path = path,
chdir = chdir,
nimage = nimage,
npool = npool,
ntg = ntg,
nyfft = nyfft,
nband = nband,
ndiag = ndiag,
)
cmd = makecmd(input, output; mpi = mpi, main = main)
return run(cmd)
end
Expand All @@ -261,9 +332,24 @@ Run command `dynmat.x`.
np = 1,
path = "dynmat.x",
chdir = true,
nimage = 0,
npool = 0,
ntg = 0,
nyfft = 0,
nband = 0,
ndiag = 0,
)
mpi = MpiexecConfig(; np = np)
main = DynmatxConfig(; path = path, chdir = chdir)
main = DynmatxConfig(;
path = path,
chdir = chdir,
nimage = nimage,
npool = npool,
ntg = ntg,
nyfft = nyfft,
nband = nband,
ndiag = ndiag,
)
cmd = makecmd(input, output; mpi = mpi, main = main)
return run(cmd)
end
Expand All @@ -279,21 +365,37 @@ Make commands for QuantumESPRESSO executables.
- `mpi=MpiexecConfig()`: MPI configurations.
- `main`: the configurations of the main executable.
"""
function makecmd(input, output = mktemp(parentdir(input))[1]; mpi = MpiexecConfig(), main)
f = mpiexec(mpi)
args = [main.path]
for name in fieldnames(ParallelizationFlags)
value = getfield(main.options, name)
function cmdtemplate(
path,
input,
output = mktemp(parentdir(input))[1];
chdir = true,
nimage = 0,
npool = 0,
ntg = 0,
nyfft = 0,
nband = 0,
ndiag = 0,
np = 1,
kwargs...,
)
if ndiag^2 > np
@error "`ndiag` square should be less than `np`!"
end
f = mpiexec(; kwargs...)
args = [path]
for (key, value) in (;
zip(
(:nimage, :npool, :ntg, :nyfft, :nband, :ndiag),
(nimage, npool, ntg, nyfft, nband, ndiag),
)...,
)
if !iszero(value)
push!(args, "-$name", string(value))
push!(args, "-$key", string(value))
end
end
dir = abspath(main.chdir ? parentdir(input) : pwd())
return pipeline(
Cmd(addenv(f(args), main.env); dir = dir);
stdin = input,
stdout = output,
)
dir = abspath(chdir ? parentdir(input) : pwd())
return pipeline(Cmd(f(args); dir = dir); stdin = input, stdout = output)
end

"""
Expand Down

0 comments on commit a6aa719

Please sign in to comment.