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

bug fixes

parent 35baa9f2
...@@ -18,7 +18,6 @@ IFLAGS= ...@@ -18,7 +18,6 @@ IFLAGS=
IO_KERNEL_OBJS = \ IO_KERNEL_OBJS = \
mpiio.o \ mpiio.o \
my_mkdir.o \
cubefile.o \ cubefile.o \
function3d.o \ function3d.o \
pdep_io.o \ pdep_io.o \
......
...@@ -99,7 +99,7 @@ MODULE function3d ...@@ -99,7 +99,7 @@ MODULE function3d
IERR = kwargs%setitem("grid_function",charbase64) IERR = kwargs%setitem("grid_function",charbase64)
IERR = kwargs%setitem("dtype","double") 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 kwargs%destroy
CALL args%destroy CALL args%destroy
...@@ -162,7 +162,7 @@ MODULE function3d ...@@ -162,7 +162,7 @@ MODULE function3d
IERR = args%setitem(0, TRIM(ADJUSTL(fname)) ) IERR = args%setitem(0, TRIM(ADJUSTL(fname)) )
IERR = dict_create(kwargs) 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) IERR = cast(return_dict, return_obj)
! !
......
...@@ -86,7 +86,7 @@ MODULE westin ...@@ -86,7 +86,7 @@ MODULE westin
CHARACTER(LEN=512) :: qe_prefix CHARACTER(LEN=512) :: qe_prefix
CHARACTER(LEN=512) :: savedir ! outdir/west_prefix.code.save CHARACTER(LEN=512) :: savedir ! outdir/west_prefix.code.save
CHARACTER(LEN=512) :: main_input_file ! input file CHARACTER(LEN=512) :: main_input_file ! input file
CHARACTER(LEN=:), ALLOCATABLE :: logfile ! savedir/logfile.xml CHARACTER(LEN=512) :: logfile ! savedir/logfile.json
! !
END MODULE END MODULE
! !
...@@ -148,8 +148,8 @@ MODULE wfreq_center ...@@ -148,8 +148,8 @@ MODULE wfreq_center
INTEGER :: n_secant_maxiter INTEGER :: n_secant_maxiter
REAL(DP) :: trev_secant REAL(DP) :: trev_secant
LOGICAL :: l_enable_lanczos LOGICAL :: l_enable_lanczos
CHARACTER(LEN=1) :: macropol_calculation
LOGICAL :: l_enable_gwetot LOGICAL :: l_enable_gwetot
CHARACTER(LEN=1) :: macropol_calculation
REAL(DP) :: exx_etot REAL(DP) :: exx_etot
REAL(DP) :: o_restart_time REAL(DP) :: o_restart_time
REAL(DP) :: ecut_spectralf(2) REAL(DP) :: ecut_spectralf(2)
......
...@@ -67,6 +67,7 @@ class QboxServer(ClientServer) : ...@@ -67,6 +67,7 @@ class QboxServer(ClientServer) :
# #
client_image = self.client_lockfile.split(".")[1] client_image = self.client_lockfile.split(".")[1]
self.server_inputfile = f"qb.{client_image}.in" # we assume that server_number = client_image self.server_inputfile = f"qb.{client_image}.in" # we assume that server_number = client_image
print(self.server_inputfile)
# #
# List of perturbation files # List of perturbation files
# #
...@@ -102,7 +103,7 @@ class QboxServer(ClientServer) : ...@@ -102,7 +103,7 @@ class QboxServer(ClientServer) :
# INTERFACE # # 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 client_lockfile = args[0] # name of client lockfile
maxsec = 12 * 60 * 60 # 12 hours, Max sleep time (in s) 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): ...@@ -127,7 +128,7 @@ def sleep_and_wait_for_lock_to_be_removed(*args, **kwargs):
def test() : def test() :
with open("I.1.lock","w") as f : with open("I.1.lock","w") as f :
f.write(" ") 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__": if __name__ == "__main__":
# execute only if run as a script # execute only if run as a script
......
...@@ -37,28 +37,29 @@ default["wstat_control"]["qlist"] = [ 1 ] # dynamically set to the actual number ...@@ -37,28 +37,29 @@ default["wstat_control"]["qlist"] = [ 1 ] # dynamically set to the actual number
default["wfreq_control"] = {} default["wfreq_control"] = {}
default["wfreq_control"]["wfreq_calculation"] = "XWGQ" 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"]["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"]["macropol_calculation"] = 'N'
default["wfreq_control"]["n_lanczos"] = 30 default["wfreq_control"]["n_lanczos"] = 30
default["wfreq_control"]["n_imfreq"] = 128 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_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"]["wfreq_eta"] = 0.05 / rytoev
default["wfreq_control"]["n_secant_maxiter"] = 21 default["wfreq_control"]["n_secant_maxiter"] = 21
default["wfreq_control"]["trev_secant"] = 0.05 / rytoev default["wfreq_control"]["trev_secant"] = 0.05 / rytoev
default["wfreq_control"]["l_enable_lanczos"] = True default["wfreq_control"]["l_enable_lanczos"] = True
default["wfreq_control"]["l_enable_gwetot"] = False
default["wfreq_control"]["o_restart_time"] = 0. 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 default["wfreq_control"]["n_spectralf"] = 204
# westpp_control # westpp_control
default["westpp_control"] = {} default["westpp_control"] = {}
default["westpp_control"]["westpp_calculation"] = "r" 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_format"] = "C"
default["westpp_control"]["westpp_sign"] = False default["westpp_control"]["westpp_sign"] = False
default["westpp_control"]["westpp_n_pdep_eigen_to_use"] = 1 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_nr"] = 100
default["westpp_control"]["westpp_rmax"] = 1. default["westpp_control"]["westpp_rmax"] = 1.
default["westpp_control"]["westpp_epsinfty"] = 1. default["westpp_control"]["westpp_epsinfty"] = 1.
...@@ -78,22 +79,17 @@ def update_default_values(key,kwargs) : ...@@ -78,22 +79,17 @@ def update_default_values(key,kwargs) :
# #
assert("nelec") in kwargs.keys() assert("nelec") in kwargs.keys()
nelec = kwargs["nelec"] nelec = kwargs["nelec"]
default[key]["n_pdep_eigen"] = nelec default[key]["n_pdep_eigen"] = int(nelec)
# #
if key == "wfreq_control" : if key == "wfreq_control" :
# #
assert("nelec") in kwargs.keys() assert("nelec") in kwargs.keys()
nelec = kwargs["nelec"] 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() assert("ecutrho") in kwargs.keys()
ecutrho = kwargs["ecutrho"] ecutrho = kwargs["ecutrho"]
default[key]["ecut_imfreq"] = 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 # # OPEN & PARSE #
...@@ -206,6 +202,7 @@ def read_keyword_from_file(*args, **kwargs): ...@@ -206,6 +202,7 @@ def read_keyword_from_file(*args, **kwargs):
# #
fileName = args[0] fileName = args[0]
keyword = args[1] keyword = args[1]
verbose = args[2]
# #
# Assign static & dynamical defaults # Assign static & dynamical defaults
# #
...@@ -226,7 +223,8 @@ def read_keyword_from_file(*args, **kwargs): ...@@ -226,7 +223,8 @@ def read_keyword_from_file(*args, **kwargs):
# #
# Print # Print
# #
print_dict(keyword, data) if (verbose) :
print_dict(keyword, data)
# #
return data return data
...@@ -249,10 +247,10 @@ wstat_control : ...@@ -249,10 +247,10 @@ wstat_control :
unknown_key : value # this line will be read but not passed unknown_key : value # this line will be read but not passed
""") """)
# #
read_keyword_from_file(fileName,"input_west") read_keyword_from_file(fileName,"input_west",True)
read_keyword_from_file(fileName,"wstat_control",nq=20,nelec=10) read_keyword_from_file(fileName,"wstat_control",True,nq=20,nelec=10)
read_keyword_from_file(fileName,"wfreq_control",nelec=10,ecutrho=30.,eksmax=2.) read_keyword_from_file(fileName,"wfreq_control",True,nelec=10,ecutrho=30.)
read_keyword_from_file(fileName,"westpp_control") read_keyword_from_file(fileName,"westpp_control",True)
# #
remove(fileName) 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= ...@@ -16,9 +16,9 @@ IFLAGS=
TOOLS_OBJS = \ TOOLS_OBJS = \
conversions.o \ conversions.o \
io_push.o \ io_push.o \
logfile.o \ my_mkdir.o \
fetch_input.o \
set_dirs.o \ set_dirs.o \
fetch_input.o \
west_print_clocks.o \ west_print_clocks.o \
exx_go.o \ exx_go.o \
exx_ungo.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 @@ ...@@ -14,10 +14,16 @@
SUBROUTINE my_mkdir( dirname ) 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, ONLY : mp_barrier,mp_bcast
USE mp_world, ONLY : mpime, root, world_comm 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 ! I/O
! !
...@@ -27,24 +33,43 @@ SUBROUTINE my_mkdir( dirname ) ...@@ -27,24 +33,43 @@ SUBROUTINE my_mkdir( dirname )
! !
INTEGER :: ierr INTEGER :: ierr
CHARACTER(LEN=6), EXTERNAL :: int_to_char CHARACTER(LEN=6), EXTERNAL :: int_to_char
TYPE(tuple) :: args
TYPE(dict) :: kwargs
TYPE(module_py) :: pymod
! !
! BARRIER ! BARRIER
! !
! IF ( mpime == root ) THEN
IF ( mpime == root ) ierr = f_mkdir_safe( TRIM( dirname ) ) !
CALL mp_bcast ( ierr, root, world_comm ) IERR = import_py(pymod, "utils")
! !
CALL errore( 'create_directory', & IERR = tuple_create(args, 1)
'unable to create directory ' // TRIM( dirname ), ierr ) IERR = args%setitem(0, TRIM(ADJUSTL(dirname)) )
! IERR = dict_create(kwargs)
! ... check whether the scratch directory is writable
! IERR = call_py_noret(pymod, "my_mkdir", args, kwargs)
IF ( mpime == root ) ierr = check_writable ( dirname, mpime ) !
CALL mp_bcast( ierr, root, world_comm ) CALL kwargs%destroy
! CALL args%destroy
CALL errore( 'create_directory:', & CALL pymod%destroy
TRIM( dirname ) // ' non existent or non writable', ierr )
CALL mp_barrier( world_comm ) 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 RETURN
! !
......
...@@ -38,7 +38,7 @@ CONTAINS ...@@ -38,7 +38,7 @@ CONTAINS
USE base64_module, ONLY : base64_init USE base64_module, ONLY : base64_init
USE json_string_utilities, ONLY : lowercase_string USE json_string_utilities, ONLY : lowercase_string
USE west_version, ONLY : start_forpy USE west_version, ONLY : start_forpy
USE logfile_mod, ONLY : clear_log !USE logfile_mod, ONLY : clear_log
! !
CHARACTER(LEN=*), INTENT(IN) :: code CHARACTER(LEN=*), INTENT(IN) :: code
! !
...@@ -54,15 +54,16 @@ CONTAINS ...@@ -54,15 +54,16 @@ CONTAINS
#if defined(__INTEL_COMPILER) #if defined(__INTEL_COMPILER)
CALL remove_stack_limit ( ) CALL remove_stack_limit ( )
#endif #endif
CALL start_forpy()
! !
! Input from (-i), output from (-o) ! Input from (-i), output from (-o)
! !
CALL parse_command_arguments() 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/" savedir = TRIM(ADJUSTL(outdir)) // TRIM(ADJUSTL(west_prefix)) // "." // TRIM(lowercase_string(code)) // ".save/"
CALL my_mkdir( savedir ) logfile = TRIM(ADJUSTL(savedir)) // TRIM(lowercase_string(code))//".json"
logfile = TRIM(savedir) // TRIM(lowercase_string(code))//".log.xml" CALL my_mkdir( TRIM(ADJUSTL(savedir)) )
! !
! ... use ".FALSE." to disable all clocks except the total cpu time clock ! ... use ".FALSE." to disable all clocks except the total cpu time clock
! ... use ".TRUE." to enab