Commit 375fa7dc authored by Marco Govoni's avatar Marco Govoni
Browse files

bug fixes

parent 35baa9f2
......@@ -18,7 +18,6 @@ IFLAGS=
IO_KERNEL_OBJS = \
mpiio.o \
my_mkdir.o \
cubefile.o \
function3d.o \
pdep_io.o \
......
......@@ -99,7 +99,7 @@ MODULE function3d
IERR = kwargs%setitem("grid_function",charbase64)
IERR = kwargs%setitem("dtype","double")
!
IERR = call_py_noret(pymod, "base64_to_function3d", args, kwargs)
IERR = call_py_noret(pymod, "base64_to_function3D", args, kwargs)
!
CALL kwargs%destroy
CALL args%destroy
......@@ -162,7 +162,7 @@ MODULE function3d
IERR = args%setitem(0, TRIM(ADJUSTL(fname)) )
IERR = dict_create(kwargs)
!
IERR = call_py(return_obj,pymod, "function3d_to_base64", args, kwargs)
IERR = call_py(return_obj,pymod, "function3D_to_base64", args, kwargs)
!
IERR = cast(return_dict, return_obj)
!
......
......@@ -86,7 +86,7 @@ MODULE westin
CHARACTER(LEN=512) :: qe_prefix
CHARACTER(LEN=512) :: savedir ! outdir/west_prefix.code.save
CHARACTER(LEN=512) :: main_input_file ! input file
CHARACTER(LEN=:), ALLOCATABLE :: logfile ! savedir/logfile.xml
CHARACTER(LEN=512) :: logfile ! savedir/logfile.json
!
END MODULE
!
......@@ -148,8 +148,8 @@ MODULE wfreq_center
INTEGER :: n_secant_maxiter
REAL(DP) :: trev_secant
LOGICAL :: l_enable_lanczos
CHARACTER(LEN=1) :: macropol_calculation
LOGICAL :: l_enable_gwetot
CHARACTER(LEN=1) :: macropol_calculation
REAL(DP) :: exx_etot
REAL(DP) :: o_restart_time
REAL(DP) :: ecut_spectralf(2)
......
......@@ -67,6 +67,7 @@ class QboxServer(ClientServer) :
#
client_image = self.client_lockfile.split(".")[1]
self.server_inputfile = f"qb.{client_image}.in" # we assume that server_number = client_image
print(self.server_inputfile)
#
# List of perturbation files
#
......@@ -102,7 +103,7 @@ class QboxServer(ClientServer) :
# INTERFACE #
#############
def sleep_and_wait_for_lock_to_be_removed(*args, **kwargs):
def sleep_and_wait(*args, **kwargs):
#
client_lockfile = args[0] # name of client lockfile
maxsec = 12 * 60 * 60 # 12 hours, Max sleep time (in s)
......@@ -127,7 +128,7 @@ def sleep_and_wait_for_lock_to_be_removed(*args, **kwargs):
def test() :
with open("I.1.lock","w") as f :
f.write(" ")
sleep_and_wait_for_lock_to_be_removed("I.1.lock",maxsec=60,sleepsec=2)
sleep_and_wait("I.1.lock",maxsec=60,sleepsec=2)
if __name__ == "__main__":
# execute only if run as a script
......
......@@ -37,28 +37,29 @@ default["wstat_control"]["qlist"] = [ 1 ] # dynamically set to the actual number
default["wfreq_control"] = {}
default["wfreq_control"]["wfreq_calculation"] = "XWGQ"
default["wfreq_control"]["n_pdep_eigen_to_use"] = 1 # dynamically set to the number of electrons
default["wfreq_control"]["qp_bandrange"] = [1,2]
default["wfreq_control"]["qp_bandrange"] = [1, 2]
default["wfreq_control"]["macropol_calculation"] = 'N'
default["wfreq_control"]["n_lanczos"] = 30
default["wfreq_control"]["n_imfreq"] = 128
default["wfreq_control"]["n_refreq"] = 272 # dynamically set so that ecut_refreq / n_refreq = 0.1 eV
default["wfreq_control"]["n_refreq"] = 272
default["wfreq_control"]["ecut_imfreq"] = 25. # dynamically set to ecutrho
default["wfreq_control"]["ecut_refreq"] = 2. # dynamically set to contain eks + 0.5 Ry padding
default["wfreq_control"]["ecut_refreq"] = 2.
default["wfreq_control"]["wfreq_eta"] = 0.05 / rytoev
default["wfreq_control"]["n_secant_maxiter"] = 21
default["wfreq_control"]["trev_secant"] = 0.05 / rytoev
default["wfreq_control"]["l_enable_lanczos"] = True
default["wfreq_control"]["l_enable_gwetot"] = False
default["wfreq_control"]["o_restart_time"] = 0.
default["wfreq_control"]["ecut_spectralf"] = [-2.,1.]
default["wfreq_control"]["ecut_spectralf"] = [-2., 1.]
default["wfreq_control"]["n_spectralf"] = 204
# westpp_control
default["westpp_control"] = {}
default["westpp_control"]["westpp_calculation"] = "r"
default["westpp_control"]["westpp_range"] = [1,2]
default["westpp_control"]["westpp_range"] = [1, 2]
default["westpp_control"]["westpp_format"] = "C"
default["westpp_control"]["westpp_sign"] = False
default["westpp_control"]["westpp_n_pdep_eigen_to_use"] = 1
default["westpp_control"]["westpp_r0"] = [0.,0.,0.]
default["westpp_control"]["westpp_r0"] = [0., 0., 0.]
default["westpp_control"]["westpp_nr"] = 100
default["westpp_control"]["westpp_rmax"] = 1.
default["westpp_control"]["westpp_epsinfty"] = 1.
......@@ -78,22 +79,17 @@ def update_default_values(key,kwargs) :
#
assert("nelec") in kwargs.keys()
nelec = kwargs["nelec"]
default[key]["n_pdep_eigen"] = nelec
default[key]["n_pdep_eigen"] = int(nelec)
#
if key == "wfreq_control" :
#
assert("nelec") in kwargs.keys()
nelec = kwargs["nelec"]
default[key]["n_pdep_eigen_to_use"] = nelec
default[key]["n_pdep_eigen_to_use"] = int(nelec)
#
assert("ecutrho") in kwargs.keys()
ecutrho = kwargs["ecutrho"]
default[key]["ecut_imfreq"] = ecutrho
#
assert("eksmax") in kwargs.keys()
eksmax = kwargs["eksmax"]
default[key]["ecut_refreq"] = eksmax + 0.5
default[key]["n_refreq"] = int( default[key]["ecut_refreq"] * rytoev / 0.1 )
################
# OPEN & PARSE #
......@@ -206,6 +202,7 @@ def read_keyword_from_file(*args, **kwargs):
#
fileName = args[0]
keyword = args[1]
verbose = args[2]
#
# Assign static & dynamical defaults
#
......@@ -226,7 +223,8 @@ def read_keyword_from_file(*args, **kwargs):
#
# Print
#
print_dict(keyword, data)
if (verbose) :
print_dict(keyword, data)
#
return data
......@@ -249,10 +247,10 @@ wstat_control :
unknown_key : value # this line will be read but not passed
""")
#
read_keyword_from_file(fileName,"input_west")
read_keyword_from_file(fileName,"wstat_control",nq=20,nelec=10)
read_keyword_from_file(fileName,"wfreq_control",nelec=10,ecutrho=30.,eksmax=2.)
read_keyword_from_file(fileName,"westpp_control")
read_keyword_from_file(fileName,"input_west",True)
read_keyword_from_file(fileName,"wstat_control",True,nq=20,nelec=10)
read_keyword_from_file(fileName,"wfreq_control",True,nelec=10,ecutrho=30.)
read_keyword_from_file(fileName,"westpp_control",True)
#
remove(fileName)
......
#!/usr/bin/python3
from __future__ import print_function
from os import mkdir
import sys
#############
# INTERFACE #
#############
def my_mkdir(*args, **kwargs):
#
path = args[0]
#
try:
mkdir(path)
except OSError:
#print (f"Creation of the directory {path} failed")
pass
else:
#print (f"Successfully created the directory {path} ")
pass
sys.stdout.flush()
########
# TEST #
########
def test() :
#
dirname = "./wstat.save"
#
my_mkdir(dirname)
if __name__ == "__main__":
# execute only if run as a script
test()
......@@ -16,9 +16,9 @@ IFLAGS=
TOOLS_OBJS = \
conversions.o \
io_push.o \
logfile.o \
fetch_input.o \
my_mkdir.o \
set_dirs.o \
fetch_input.o \
west_print_clocks.o \
exx_go.o \
exx_ungo.o \
......
This diff is collapsed.
#!/usr/bin/python3
# File: fetch_input.py
# Test: python3 fetch_input.py
from __future__ import print_function
import sys
import os
import yaml
import json
#########################
# STATIC DEFAULT VALUES #
#########################
default = {}
# input_west
default["input_west"] = {}
default["input_west"]["qe_prefix"] = "pwscf"
default["input_west"]["west_prefix"] = "west"
default["input_west"]["outdir"] = "./"
# wstat_control
default["wstat_control"] = {}
default["wstat_control"]["wstat_calculation"] = "S"
default["wstat_control"]["n_pdep_eigen"] = 1
default["wstat_control"]["n_pdep_times"] = 4
default["wstat_control"]["n_pdep_maxiter"] = 100
default["wstat_control"]["n_dfpt_maxiter"] = 250
default["wstat_control"]["n_pdep_read_from_file"] = 0
default["wstat_control"]["trev_pdep"] = 1.e-3
default["wstat_control"]["trev_pdep_rel"] = 1.e-1
default["wstat_control"]["tr2_dfpt"] = 1.e-12
default["wstat_control"]["l_kinetic_only"] = False
default["wstat_control"]["l_minimize_exx_if_active"] = False
default["wstat_control"]["l_use_ecutrho"] = False
default["wstat_control"]["qlist"] = [ 1 ]
############################
# DYNAMICAL DEFAULT VALUES #
############################
def update_default_values(key,kwargs) :
assert key in default.keys()
#
if key == "wstat_control" :
assert("nq") in kwargs.keys()
nq = kwargs["nq"]
default[key]["qlist"] = [ i+1 for i in range(nq) ]
def open_and_parse_file(fileName="west.in") :
"""Opens a file and parses it using the YAML sintax
:param fileName: name of the file
:type fileName: ``string``
:return: parsed data
:rtype: ``dict``
"""
data = {}
try :
with open(fileName, 'r') as stream:
try:
data = yaml.load(stream,Loader=yaml.SafeLoader)
except:
print("Cannot parse file")
except :
print("Cannot open file : ",fileName)
#
return data
def print_bar(prefix="",nmarks=92) :
"""Prints bar.
:param prefix: prefix
:type prefix: ``string``
:param nmarks: number of marks
:type nmarks: ``int``
"""
#
s = prefix
for i in range(nmarks) :
s+="-"
print(s)
def check_dict(parsed_data={}, default_data={}) :
"""Check data: returns a dictionary with the same keys of default_data. If keys are matching, values of default_data are replaced with those of parsed_data.
:param parsed_data: parsed data
:type parsed_data: ``dict``
:param default_data: default data
:type default_data: ``dict``
:return: checked data
:rtype: ``dict``
"""
#
data = {}
#
for key in default_data.keys() :
if key in parsed_data.keys() :
data[key] = parsed_data[key]
else :
data[key] = default_data[key]
#
return data
def print_dict(title="input_west", data={}) :
"""Prints data.
:param title: title
:type title: ``string``
:param data: data to print
:type default_data: ``dict``
"""
#
nmarks = 92
nspaces = 5
s = ""
for i in range(nspaces) :
s+=" "
#
print_bar(s,nmarks)
print(s+"I/O Summary : "+str(title))
print_bar(s,nmarks)
for key in data.keys() :
print(s+key,"=",data[key])
print_bar(s,nmarks)
sys.stdout.flush()
def read_keyword_from_file(*args, **kwargs):
"""Read keyword from file
:return: read data
:rtype: ``dict``
"""
#
fileName = args[0]
keyword = args[1]
#
parsed_data = open_and_parse_file(fileName)[keyword]
default_data = default[keyword]
#
update_default_values(keyword,kwargs)
#
data = check_dict( parsed_data, default_data )
#
print_dict(keyword, data)
#
return data
def test() :
#
fileName = "west.in"
#
with open(fileName, "w") as file :
file.write("""
input_west :
qe_prefix : molecule
west_prefix : molecule
outdir : "./"
wstat_control :
wstat_calculation : R
""")
#
read_keyword_from_file(fileName,"input_west")
read_keyword_from_file(fileName,"wstat_control",nq=20)
#
os.remove(fileName)
if __name__ == "__main__":
# execute only if run as a script
test()
......@@ -14,10 +14,16 @@
SUBROUTINE my_mkdir( dirname )
!------------------------------------------------------------------------
!
USE wrappers, ONLY : f_mkdir_safe
! USE wrappers, ONLY : f_mkdir_safe
USE mp, ONLY : mp_barrier,mp_bcast
USE mp_world, ONLY : mpime, root, world_comm
USE io_files, ONLY : check_writable
! USE io_files, ONLY : check_writable
USE forpy_mod, ONLY: call_py, call_py_noret, import_py, module_py
USE forpy_mod, ONLY: tuple, tuple_create
USE forpy_mod, ONLY: dict, dict_create
USE forpy_mod, ONLY: list, list_create
USE forpy_mod, ONLY: object, cast
USE forpy_mod, ONLY: exception_matches, KeyError, err_clear, err_print
!
! I/O
!
......@@ -27,24 +33,43 @@ SUBROUTINE my_mkdir( dirname )
!
INTEGER :: ierr
CHARACTER(LEN=6), EXTERNAL :: int_to_char
TYPE(tuple) :: args
TYPE(dict) :: kwargs
TYPE(module_py) :: pymod
!
! BARRIER
!
!
IF ( mpime == root ) ierr = f_mkdir_safe( TRIM( dirname ) )
CALL mp_bcast ( ierr, root, world_comm )
!
CALL errore( 'create_directory', &
'unable to create directory ' // TRIM( dirname ), ierr )
!
! ... check whether the scratch directory is writable
!
IF ( mpime == root ) ierr = check_writable ( dirname, mpime )
CALL mp_bcast( ierr, root, world_comm )
!
CALL errore( 'create_directory:', &
TRIM( dirname ) // ' non existent or non writable', ierr )
CALL mp_barrier( world_comm )
IF ( mpime == root ) THEN
!
IERR = import_py(pymod, "utils")
!
IERR = tuple_create(args, 1)
IERR = args%setitem(0, TRIM(ADJUSTL(dirname)) )
IERR = dict_create(kwargs)
IERR = call_py_noret(pymod, "my_mkdir", args, kwargs)
!
CALL kwargs%destroy
CALL args%destroy
CALL pymod%destroy
ENDIF
CALL mp_barrier(world_comm)
! IF ( mpime == root ) ierr = f_mkdir_safe( TRIM( dirname ) )
! CALL mp_bcast ( ierr, root, world_comm )
! !
! CALL errore( 'create_directory', &
! 'unable to create directory ' // TRIM( dirname ), ierr )
! !
! ! ... check whether the scratch directory is writable
! !
! IF ( mpime == root ) ierr = check_writable ( dirname, mpime )
! CALL mp_bcast( ierr, root, world_comm )
! !
! CALL errore( 'create_directory:', &
! TRIM( dirname ) // ' non existent or non writable', ierr )
! CALL mp_barrier( world_comm )
!
RETURN
!
......
......@@ -38,7 +38,7 @@ CONTAINS
USE base64_module, ONLY : base64_init
USE json_string_utilities, ONLY : lowercase_string
USE west_version, ONLY : start_forpy
USE logfile_mod, ONLY : clear_log
!USE logfile_mod, ONLY : clear_log
!
CHARACTER(LEN=*), INTENT(IN) :: code
!
......@@ -54,15 +54,16 @@ CONTAINS
#if defined(__INTEL_COMPILER)
CALL remove_stack_limit ( )
#endif
CALL start_forpy()
!
! Input from (-i), output from (-o)
!
CALL parse_command_arguments()
CALL fetch_input(1,(/1/),.FALSE.)
CALL fetch_input_yml(1,(/1/),.FALSE.,.FALSE.)
!
savedir = TRIM(outdir) // trim(west_prefix) // "." // TRIM(lowercase_string(code)) // ".save/"
CALL my_mkdir( savedir )
logfile = TRIM(savedir) // TRIM(lowercase_string(code))//".log.xml"
savedir = TRIM(ADJUSTL(outdir)) // TRIM(ADJUSTL(west_prefix)) // "." // TRIM(lowercase_string(code)) // ".save/"
logfile = TRIM(ADJUSTL(savedir)) // TRIM(lowercase_string(code))//".json"
CALL my_mkdir( TRIM(ADJUSTL(savedir)) )
!
! ... use ".FALSE." to disable all clocks except the total cpu time clock
! ... use ".TRUE." to enable clocks
......@@ -116,9 +117,8 @@ CONTAINS
!
! Initialize base64 tables
CALL base64_init()
CALL start_forpy()
!
CALL clear_log()
!CALL clear_log()
CALL west_opening_message( code )
#if defined(__MPI)
CALL report_parallel_status ( )
......@@ -196,7 +196,7 @@ CONTAINS
!
SUBROUTINE west_opening_message( code )
!
!USE json_module, ONLY : json_file
USE json_module, ONLY : json_file
USE io_global, ONLY : stdout
USE global_version, ONLY : version_number, svn_revision
USE west_version, ONLY : west_version_number, west_git_revision
......@@ -204,7 +204,7 @@ CONTAINS
USE westcom, ONLY : logfile
USE base64_module, ONLY : islittleendian
USE forpy_mod, ONLY : dict, dict_create
USE logfile_mod, ONLY : append_log, itoa, ltoa, dtoa
!USE logfile_mod, ONLY : append_log, itoa, ltoa, dtoa
!
! I/O
!
......@@ -212,8 +212,8 @@ CONTAINS
!
! Workspace
!
!TYPE(json_file) :: json
!INTEGER :: iunit
TYPE(json_file) :: json
INTEGER :: iunit
CHARACTER(LEN=9) :: cdate, ctime
!
INTEGER :: IERR
......@@ -249,50 +249,50 @@ CONTAINS
ENDIF
!
IF( mpime == root ) THEN
!
!CALL json%initialize()
!!
!CALL json%add('runjob.startdate', TRIM(cdate) )
!CALL json%add('runjob.starttime', TRIM(ctime) )
!CALL json%add('runjob.completed', .FALSE. )
!CALL json%add('software.package', "WEST" )
!CALL json%add('software.program', TRIM(code) )
!CALL json%add('software.version', TRIM(west_version_number) )
!IF( TRIM (west_git_revision) /= "unknown" ) CALL json%add('software.westgit', TRIM(west_git_revision) )
!CALL json%add('software.website',"http://www.west-code.org")
!CALL json%add('software.citation',"M. Govoni et al., J. Chem. Theory Comput. 11, 2680 (2015).")
!CALL json%add('software.qeversion', TRIM(version_number) )
!IF( TRIM (svn_revision) /= "unknown" ) CALL json%add('software.qesvn', TRIM(svn_revision) )
!CALL json%add('config.io.islittleendian', islittleendian() )
!!
!OPEN( NEWUNIT=iunit, FILE=TRIM(logfile) )
!CALL json%print_file( iunit )
!CLOSE( iunit )
!!
!CALL json%destroy()
!
CALL json%initialize()
!
s = '{ '
s = s // '"startdate" : ' //'"'//TRIM(cdate) //'" , '
s = s // '"startime" : ' //'"'//TRIM(ctime) //'" , '
s = s // '"package" : ' //'"WEST"' //' , '
s = s // '"program" : ' //'"'//TRIM(code) //'" , '
s = s // '"version" : ' //'"'//TRIM(west_version_number) //'" , '
IF( TRIM (west_git_revision) /= "unknown" ) THEN
s = s // '"git_version" : ' //'"'//TRIM(west_git_revision) //'" , '
ENDIF
s = s // '"website" : ' //'"http://www.west-code.org"' //' , '
s = s // '"citation" : ' //'"M. Govoni et al., J. Chem. Theory Comput. 11, 2680 (2015)."' //' , '
s = s // '"website" : ' //'"http://www.west-code.org"' //' , '
s = s // '"qeversion" : ' //'"'//TRIM(version_number) //'" , '
s = s // '"islittleendian" : ' //ltoa(islittleendian()) //' '
s = s // '}'
CALL json%add('runjob.startdate', TRIM(cdate) )
CALL json%add('runjob.starttime', TRIM(ctime) )
CALL json%add('runjob.completed', .FALSE. )
CALL json%add('software.package', "WEST" )
CALL json%add('software.program', TRIM(code) )
CALL json%add('software.version', TRIM(west_version_number) )
IF( TRIM (west_git_revision) /= "unknown" ) CALL json%add('software.westgit', TRIM(west_git_revision) )
CALL json%add('software.website',"http://www.west-code.org")
CALL json%add('software.citation',"M. Govoni et al., J. Chem. Theory Comput. 11, 2680 (2015).")
CALL json%add('software.qeversion', TRIM(version_number) )
IF( TRIM (svn_revision) /= "unknown" ) CALL json%add('software.qesvn', TRIM(svn_revision) )
CALL json%add('config.io.islittleendian', islittleendian() )
!
IERR = dict_create(attr)
IERR = attr%setitem("type", "intro" )
OPEN( NEWUNIT=iunit, FILE=TRIM(logfile) )
CALL json%print_file( iunit )
CLOSE( iunit )
!
CALL append_log( s, attr )
CALL json%destroy()
!
CALL attr%destroy
!s = '{ '