Skip to content

Commit

Permalink
added Job registry and selection
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Jun 7, 2021
1 parent ad1782a commit d27739f
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 17 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Media = "e89f7d12-3494-54d1-8411-f7d8b9ae1f27"
NearestNeighbors = "b8a86587-4115-5ab1-83bc-aa920d37bbce"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Expand Down
4 changes: 4 additions & 0 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ if !ispath(abspath(first(DEPOT_PATH), "config","DFControl", "user_defaults.jl"))
end
end

if !ispath(abspath(first(DEPOT_PATH), "config","DFControl", "job_registry.txt"))
touch(abspath(first(DEPOT_PATH), "config","DFControl", "job_registry.txt"))
end

relpath = x -> joinpath(@__DIR__, x)

pythonpath = relpath("python2")
Expand Down
24 changes: 15 additions & 9 deletions src/DFControl.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
module DFControl
const CONFIG_DIR = occursin("cache", first(Base.DEPOT_PATH)) ?
abspath(Base.DEPOT_PATH[2], "config","DFControl") :
abspath(Base.DEPOT_PATH[1], "config","DFControl")

config_path(path...) = joinpath(CONFIG_DIR, path...)

using LinearAlgebra
using Statistics
using Media
Expand All @@ -22,8 +28,9 @@ module DFControl

using NearestNeighbors
using Crayons


import REPL
using REPL.TerminalMenus

abstract type Package end
struct Wannier90 <: Package end
struct QE <: Package end
Expand Down Expand Up @@ -71,20 +78,19 @@ module DFControl
const dfprint = print
include("display/overloads.jl")
using Requires


const JOB_REGISTRY = String[]

function __init__()
@require Juno = "e5e0dc1b-0480-54bc-9374-aad01c23163d" include("display/printing_juno.jl")
@require Glimpse = "f6e19d58-12a4-5927-8606-ac30a9ce9b69" include("display/glimpse.jl")
merge!(Unitful.basefactors, localunits)
Unitful.register(@__MODULE__)
global JOB_REGISTRY = readlines(config_path("job_registry.txt"))
end

const pythonpath = Sys.iswindows() ? joinpath(depsdir, "python2", "python") : joinpath(dirname(@__DIR__), "deps", "python2", "bin", "python")
const cif2cellpath = Sys.iswindows() ? joinpath(depsdir, "python2", "Scripts", "cif2cell") : joinpath(dirname(@__DIR__), "deps", "python2", "bin", "cif2cell")
# if isfile(joinpath(dirname(@__FILE__),"..","deps","deps.jl"))
# include(joinpath(dirname(@__FILE__),"..","deps","deps.jl"))
# else
# error("DFControl not properly installed. Please run Pkg.build(\"DFControl\")")
# end
# include("precompile.jl")
# _precompile_()

end
4 changes: 2 additions & 2 deletions src/defaults.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"File with all the user defaults inside it"
# const default_file = abspath(homedir(),".julia","config","DFControl", "user_defaults.jl")
const default_file = occursin("cache", first(Base.DEPOT_PATH)) ? abspath(Base.DEPOT_PATH[2], "config","DFControl", "user_defaults.jl") : abspath(Base.DEPOT_PATH[1], "config","DFControl", "user_defaults.jl")
const default_file = config_path("user_defaults.jl")

const default_pseudodirs = Dict{Symbol, String}()
const default_pseudos = Dict{Symbol, Dict{Symbol, Vector{Pseudo}}}()
const default_jobheader = [""]
Expand Down Expand Up @@ -41,7 +42,6 @@ function removedefault_pseudodir(pseudo_symbol::Symbol)
if haskey(default_pseudodirs, pseudo_symbol)
delete!(default_pseudodirs, pseudo_symbol)
rm_expr_lhs(default_file, :(default_pseudodirs[$(QuoteNode(pseudo_symbol))]))
# removedefault_pseudos(pseudo_symbol)
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/fileio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ function read_job_inputs(job_file::String)
error("Something went wrong and no valid structures could be read from input files.")
end
outstruct = mergestructures(structures)
return (name=name, header=header, inputs=inputs, structure=outstruct, server_dir=serverdir)
return (name=name, inputs=inputs, structure=outstruct, header=header, server_dir=serverdir)
end

#---------------------------END GENERAL SECTION-------------------#
Expand Down
64 changes: 59 additions & 5 deletions src/job.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
#here all the different input structures for the different calculations go
function write_job_registry()
open(config_path("job_registry.txt"), "w") do f
for j in JOB_REGISTRY
write(f, "$j\n")
end
end
end

function cleanup_job_registry()
stale_ids = findall(!ispath, JOB_REGISTRY)
if stale_ids !== nothing
jobs_to_remove = JOB_REGISTRY[stale_ids]
message = "Removing $(length(jobs_to_remove)) stale jobs (job folder removed) from the registry:\n"
for j in jobs_to_remove
message *= "\t$j\n"
end
@warn message
deleteat!(JOB_REGISTRY, stale_ids)
end
write_job_registry()
end

function maybe_register_job(abspath::String)
if !ispath(abspath)
push!(JOB_REGISTRY, abspath)
else
jid = findfirst(isequal(abspath), JOB_REGISTRY)
if jid === nothing
push!(JOB_REGISTRY, abspath)
end
end
write_job_registry()
end

#TODO should we also create a config file for each job with stuff like server etc? and other config things,
# which if not supplied could contain the default stuff?
"""
Expand All @@ -13,13 +46,15 @@ Represents a full DFT job with multiple input files and calculations.
server_dir ::String = ""
header ::Vector{String} = getdefault_jobheader()
metadata ::Dict = Dict()
# version ::Int = 1
function DFJob(name, structure, calculations, local_dir, server, server_dir, header, metadata)
if !isabspath(local_dir)
local_dir = abspath(local_dir)
end
if isempty(structure.name)
structure.name = split(name, "_")[1]
end
maybe_register_job(local_dir)
return new(name, structure, calculations, local_dir, server, server_dir, header, metadata)
end
end
Expand Down Expand Up @@ -66,12 +101,31 @@ function DFJob(job::DFJob, flagstoset...; cell_=copy(cell(job)), atoms_=copy(ato
end

"""
DFJob(job_dir::String, job_fuzzy = "job"; kwargs...)
DFJob(job_dir::String; job_fuzzy = "job", kwargs...)
Loads and returns a local DFJob. kwargs will be passed to the constructor.
Loads and returns a local DFJob.
If `job_dir` is not a valid path the JOB_REGISTRY will be scanned for a job with matching directory.
The kwargs will be passed to the `DFJob` constructor.
"""
DFJob(job_dir::String, job_fuzzy="job"; kwargs...) =
DFJob(;merge(merge((local_dir=job_dir,), read_job_inputs(joinpath(job_dir, searchdir(job_dir, job_fuzzy)[1]))), kwargs)...)
function DFJob(job_dir::String; job_fuzzy="job", kwargs...)
if ispath(job_dir)
real_path = job_dir
else
matching_jobs = filter(x -> occursin(job_dir, x), JOB_REGISTRY)
if length(matching_jobs) == 1
real_path = matching_jobs[1]
else
menu = RadioMenu(matching_jobs)
choice = request("Multiple matching jobs were found, choose one:", menu)
if choice != -1
real_path = matching_jobs[choice]
else
return
end
end
end
return DFJob(;merge(merge((local_dir=real_path,), read_job_inputs(joinpath(real_path, searchdir(real_path, job_fuzzy)[1]))), kwargs)...)
end

name(job) = job.name
#-------------------BEGINNING GENERAL SECTION-------------#
Expand Down
4 changes: 4 additions & 0 deletions src/qe/fileio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,10 @@ function qe_read_input(filename; execs=[Exec("pw.x")], run=true, structure_name=
ids = parse.(Int, _s[2:end])
typ = flagtype(QE, exec, sym)
v = replace(v, "d" => "e")
if typ === Nothing
@warn "Flag $f in file $filename not found in allowed flags for $(exec.exec)"
continue
end
parsedval = parse.((eltype(typ),), split(v))
if !haskey(parsed_flags, sym)
if typ <: AbstractMatrix
Expand Down

0 comments on commit d27739f

Please sign in to comment.