Skip to content

Commit

Permalink
make tests pass and everything work
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Mar 14, 2018
1 parent 264ccac commit 5c1a770
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 68 deletions.
4 changes: 4 additions & 0 deletions src/DFControl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ module DFControl
export add_calculation!
export get_run_command
export change_run_command!
export set_runflags!
export get_runflags
export set_execflags!
export get_execflags
export get_inputs
export get_input
export change_filename!
Expand Down
51 changes: 19 additions & 32 deletions src/fileio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ function writetojob(f, job, input::QEInput)
return 1
end

#TODO: no exec runcommand flag support, is it necessary?
function writetojob(f, job, input::WannierInput)
run_command = input.run_command
filename = input.filename
Expand Down Expand Up @@ -219,37 +218,25 @@ function read_job_line(line)
return run_command, exec, input, output, run
end
# TODO: make this work again
# function read_job_filenames(job_file::String)
# input_files = String[]
# output_files = String[]
# open(job_file, "r") do f
# readline(f)
# while !eof(f)
# line = readline(f)
# if isempty(line)
# continue
# end
# if contains(line, ".x")
# spl = split(line)
# i = find(x -> contains(x, ".x"), spl)[1] + 1
# in_out = strip_split(prod(filter(x -> !contains(x, "-pp"), spl[i:end])), ">")
# if length(in_out) == 2
# push!(input_files, strip(in_out[1], '<'))
# push!(output_files, in_out[2])
# else
# input_file = strip(in_out[1], '<')
# if contains(line, "wannier90.x") && !contains(line, "pw2wannier90")
# input = splitext(input_file)[1] * ".win"
# output =splitext(input_file)[1] * ".wout"
# !in(output, output_files) && push!(output_files, output)
# !in(input, input_files) && push!(input_files, input)
# end
# end
# end
# end
# end
# return input_files, output_files
# end
function read_job_filenames(job_file::String)
input_files = String[]
output_files = String[]
open(job_file, "r") do f
readline(f)
while !eof(f)
line = readline(f)
if isempty(line)
continue
end
if contains(line, ".x")
run_command, exec, input, output, run = read_job_line(line)
!in(input, input_files) && push!(input_files, input)
!in(output, output_files) && push!(output_files, output)
end
end
end
return input_files, output_files
end

"""
read_job_file(job_file::String)
Expand Down
61 changes: 49 additions & 12 deletions src/job.jl
Original file line number Diff line number Diff line change
Expand Up @@ -571,32 +571,70 @@ function change_flow!(job::DFJob, should_runs::Union{Dict{String,Bool}, Vector{T
end

"""
change_run_command!(job::DFJob, filenames, run_command)
change_run_command!(job::DFJob, inputnames, run_command)
Goes through the calculation filenames and sets the run command of the calculation.
Goes through the job calculations and if it contains one of the inputnames it sets the run command of the calculation.
Since the `run_command` field has both the command and the flags, this function only changes the command.
To change the run_command's flags use the function `set_runflags`.
"""
function change_run_command!(job::DFJob, filenames, run_command)
function change_run_command!(job::DFJob, inputnames, run_command::String)
UNDO_JOBS[job.id] = deepcopy(job)

for calc in get_inputs(job, filenames)
calc.run_command = run_command
dfprintln("Run command of file '$(calc.filename)' is now: '$(calc.run_command)'")
for calc in get_inputs(job, inputnames)
calc.run_command = run_command => calc.run_command[2]
dfprintln("Run command of file '$(calc.filename)' is now: '$(calc.run_command[1])'")
end

return job
end

"""
get_run_command(job::DFJob, filename)
get_run_command(job::DFJob, inputname)
Returns the `run_command` string.
"""
function get_run_command(job::DFJob, inputname)
for calc in get_inputs(job, inputname)
return calc.run_command[1]
end
end

"""
set_runflags!(job::DFJob, inputnames, flags...)
Goes through the calculations of the job and if the name contains any of the `inputnames` it sets the run_command flags to the specified ones.
"""
function set_runflags!(job::DFJob, inputnames, flags...)
calcs = get_inputs(job, inputnames)
for calc in calcs
for (f,v) in flags
calc.run_command[2][f] = v
end
dfprintln("run flags of calculation $(calc.filename) are now $(calc.run_command[2]).")
end
end

"Returns the run_command flags."
get_runflags(job::DFJob, inputname) = get_input(job, inputname).run_command[2]

"""
set_execflags!(job::DFJob, inputnames, flags...)
Returns the run command for the specified calculation.
Goes through the calculations of the job and if the name contains any of the `inputnames` it sets the exec flags to the specified ones.
"""
function get_run_command(job::DFJob, filename)
for calc in get_inputs(job, filename)
return calc.run_command
function set_execflags!(job::DFJob, inputnames, flags...)
calcs = get_inputs(job, inputnames)
for calc in calcs
for (f,v) in flags
calc.exec[2][f] = v
end
dfprintln("run flags of calculation $(calc.filename) are now $(calc.exec[2]).")
end
end

"Returns the run_command flags."
get_execflags(job::DFJob, inputname) = get_input(job, inputname).exec[2]

"""
add_block!(job::DFJob, filenames, block::Block)
Expand All @@ -611,7 +649,6 @@ function add_block!(job::DFJob, filenames, block::Block)
return job
end


"""
add_data!(job::DFJob, filenames, block_symbol, data, option=:none)
Expand Down
45 changes: 26 additions & 19 deletions src/server_comm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,50 +58,57 @@ function pull_file(filepath::String, local_dir::String; server=get_default_serve
end
end


#TODO: doesn't work for abinit
"""
pull_outputs(df_job::DFJob, server="", server_dir="", local_dir=""; job_fuzzy="*job*", extras=String[])
pull_outputs(job::DFJob, server="", server_dir="", local_dir=""; job_fuzzy="*job*", extras=String[])
First pulls the job file (specified by job_fuzzy), reads the possible output files and tries to pull them.
Extra files to pull can be specified by the `extras` keyword, works with fuzzy filenames.
"""
function pull_outputs(df_job::DFJob, server="", server_dir="", local_dir=""; job_fuzzy="*job*", extras=String[])
if df_job.server == "" && server == ""
function pull_outputs(job::DFJob, server="", server_dir="", local_dir=""; job_fuzzy="*job*", extras=String[])
if job.server == "" && server == ""
error("Error: No job server specified. Please specify it first.")
elseif server != ""
df_job.server = server
job.server = server
end
if df_job.server_dir == "" && server_dir == ""
if job.server_dir == "" && server_dir == ""
error("Error: No job server_dir specified. Please specify it first.")
elseif server_dir != ""
df_job.server_dir = server_dir
job.server_dir = server_dir
end
if df_job.local_dir == "" && local_dir == ""
if job.local_dir == "" && local_dir == ""
error("Error: No job local/home directory specified. Please specify it first.")
elseif server != ""
df_job.local_dir = local_dir
job.local_dir = local_dir
end
if !ispath(df_job.local_dir)
mkpath(df_job.local_dir)
if !ispath(job.local_dir)
mkpath(job.local_dir)
end
pull_server_file(filename) = pull_file(df_job.server, df_job.server_dir, df_job.local_dir, filename)
pull_server_file(filename) = pull_file(job.server, job.server_dir, job.local_dir, filename)

pull_server_file(job_fuzzy)
# pull_server_file(job_fuzzy)

job_file = search_dir(df_job.local_dir, strip(job_fuzzy, '*'))[1]
inputs, outputs= read_job_filenames(df_job.local_dir * job_file)
# job_file = search_dir(job.local_dir, strip(job_fuzzy, '*'))[1]
# inputs, outputs= read_job_filenames(job.local_dir * job_file)
pulled_outputs = String[]
for output in outputs
for calc in job.calculations
if typeof(calc) == QEInput
ofile = splitext(calc.filename)[1] * ".out"
elseif typeof(calc) == WannierInput
ofile = splitext(calc.filename)[1] * ".wout"
end
try
pull_server_file(output)
push!(pulled_outputs, output)
pull_server_file(ofile)
push!(pulled_outputs, ofile)
end
end

for fuzzy in extras
pull_server_file(fuzzy)
push!(pulled_outputs, search_dir(df_job.local_dir, strip(fuzzy,'*'))...)
push!(pulled_outputs, search_dir(job.local_dir, strip(fuzzy,'*'))...)
end
return df_job.local_dir .* pulled_outputs
return job.local_dir .* pulled_outputs
end

"""
Expand Down
2 changes: 1 addition & 1 deletion test/file_processing_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using DFControl, Base.Test
scf_input, qestructure = read_qe_input(joinpath(@__DIR__,"../assets/inputs/qe/scf.in"));

bands_input = read_qe_input(joinpath(@__DIR__,"../assets/inputs/qe/bands.in"))[1];
projwfc_input = read_qe_input(joinpath(@__DIR__,"../assets/inputs/qe/projwfc.in"), exec="projwfc.x")[1];
projwfc_input = read_qe_input(joinpath(@__DIR__,"../assets/inputs/qe/projwfc.in"), exec="projwfc.x"=>Dict{Symbol, Any}())[1];
display(projwfc_input);
@test get_flag(scf_input, :calculation) == "'scf'";
@test get_block(scf_input,:k_points).option == :automatic;
Expand Down
2 changes: 1 addition & 1 deletion test/job_control_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ df_job = load_job(test_job_path);
df_job2 = load_job(joinpath(@__DIR__, test_job_path), new_local_dir="blabla");
@test df_job2.local_dir == "blabla/"
@test length(df_job.calculations) == 7
@test get_input(df_job, "nscf").run_command == get_run_command(df_job, "nscf")
@test get_input(df_job, "nscf").run_command[1] == get_run_command(df_job, "nscf")
@test df_job.local_dir == test_job_path*"/"

try mkdir(joinpath(test_job_path,"test_dir/")) end
Expand Down
6 changes: 3 additions & 3 deletions test/test_job/job.tt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ mpirun -np 24 ~/bin/pw.x <scf.in> scf.out
mpirun -np 24 ~/bin/pw.x <bands.in> bands.out
mpirun -np 24 ~/bin/projwfc.x <projwfc.in> projwfc.out
mpirun -np 24 ~/bin/pw.x <nscf.in> nscf.out
~/bin/wannier90.x -pp wan
mpirun -np 24 ~/bin/pw2wannier90.x <pw2wan.in> pw2wan.out
~/bin/wannier90.x wan
~/bin/wannier90.x -pp wan.win > wan.wout
mpirun -np 24 ~/bin/pw2wannier90.x <pw2wan.in> pw2wan.out
~/bin/wannier90.x wan.win > wan.wout

0 comments on commit 5c1a770

Please sign in to comment.