Commit 3749404c authored by Marco Govoni's avatar Marco Govoni
Browse files

Added server document

parent ca8d8988
......@@ -125,6 +125,14 @@ MODULE wstat_center
CHARACTER(LEN=512) :: wstat_restart_dir
LOGICAL :: l_is_wstat_converged
!
END MODULE
!
MODULE server_center
SAVE
!
! INPUT for server_control
!
CHARACTER(LEN=:),ALLOCATABLE :: document
END MODULE
!
!
......@@ -252,6 +260,7 @@ MODULE westcom
USE scratch_area
USE westin
USE wstat_center
USE server_center
USE wfreq_center
USE westpp_center
USE wan_center
......
......@@ -13,6 +13,7 @@
from time import sleep, perf_counter as pc
from os import path, remove
from abc import ABC, abstractmethod
import json
##############
# SUPERCLASS #
......@@ -20,11 +21,12 @@ from abc import ABC, abstractmethod
class ClientServer(ABC):
#
def __init__(self,client_lockfile,maxsec=21600,sleepsec=10):
def __init__(self,client_lockfile,maxsec=21600,sleepsec=10,document={}):
#
self.client_lockfile = client_lockfile
self.maxsec = maxsec
self.sleepsec = sleepsec
self.document = document
super().__init__()
#
@abstractmethod
......@@ -73,6 +75,21 @@ class QboxServer(ClientServer) :
#
def before_sleep(self):
#
command_suffix = ""
if "response" in self.document.keys() :
if self.document["response"] == "RPA" :
command_suffix += "-RPA "
if self.document["response"] == "IPA" :
command_suffix += "-IPA "
if "amplitude" in self.document.keys() :
command_suffix += f'-amplitude {self.document["amplitude"]} '
if "nitscf" in self.document.keys() :
command_suffix += f'{self.document["nitscf"]} '
else :
command_suffix += f'20 '
if "nite" in self.document.keys() :
command_suffix += f'{self.document["nite"]}'
#
# Determine the name of the server file
#
client_image = self.client_lockfile.split(".")[1]
......@@ -87,13 +104,12 @@ class QboxServer(ClientServer) :
#
# Create the input file for the server
#
with open(self.server_inputfile,"w") as f:
f.write("load gs.xml\n")
f.write("set xc PBE\n")
f.write("set wf_dyn PSDA\n")
f.write("set scf_tol 1.e-8\n")
with open(self.server_inputfile,"w") as f:
if "script" in self.document.keys() :
for line in self.document["script"] :
f.write(line+"\n")
for pert in perturbation_list :
f.write(f"response -vext {pert} -IPA -amplitude 0 20\n")
f.write(f"response -vext {pert} "+command_suffix+"\n")
#
# Awake server, by removing its lockfile
#
......@@ -120,6 +136,7 @@ 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)
sleepsec = 1 # 1 second, Sleep interval (in s)
document = {}
#
# change defaults
#
......@@ -127,8 +144,10 @@ def sleep_and_wait(*args, **kwargs):
maxsec = kwargs["maxsec"]
if "sleepsec" in kwargs.keys() :
sleepsec = kwargs["sleepsec"]
if "document" in kwargs.keys() :
document = json.loads(kwargs["document"])
#
server = QboxServer(client_lockfile,maxsec,sleepsec)
server = QboxServer(client_lockfile,maxsec,sleepsec,document)
return_int = server.start()
#
return return_int
......@@ -139,8 +158,8 @@ def sleep_and_wait(*args, **kwargs):
def test() :
with open("I.1.lock","w") as f :
f.write(" ")
sleep_and_wait("I.1.lock",maxsec=60,sleepsec=2)
f.write("I.1_P.1.xml")
sleep_and_wait("I.1.lock",maxsec=60,sleepsec=2,document='{"response": "IPA", "amplitude": 0, "script" : ["set xc PBE"]}')
if __name__ == "__main__":
# execute only if run as a script
......
......@@ -73,6 +73,10 @@ 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.
# server_control
default["server_control"] = {}
default["server_control"]["document"] = "{}"
############################
# DYNAMICAL DEFAULT VALUES #
......@@ -124,6 +128,11 @@ def open_and_parse_file(fileName="west.in") :
except :
print("Cannot open file : ",fileName)
#
if "server_control" in data.keys() :
if "document" in data["server_control"].keys() :
jsonText = json.dumps(data["server_control"]["document"])
data["server_control"]["document"] = jsonText
#
return data
##############
......@@ -223,10 +232,9 @@ def read_keyword_from_file(*args, **kwargs):
# Read input file
#
input_data = open_and_parse_file(fileName)
parsed_data = {}
if keyword in input_data.keys() :
parsed_data = input_data[keyword]
else :
parsed_data = {}
#
# Compare defaults and input variables
#
......@@ -256,12 +264,15 @@ input_west :
wstat_control :
wstat_calculation : R # this is a comment
unknown_key : value # this line will be read but not passed
server_control :
document : {}
""")
#
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)
read_keyword_from_file(fileName,"server_control",True)
#
remove(fileName)
......
......@@ -96,6 +96,12 @@ SUBROUTINE add_intput_parameters_to_json_file( num_drivers, driver, json )
!
ENDIF
!
IF ( ANY(driver(:)==5) ) THEN
!
CALL json%add('input.server_control.document',TRIM(document))
!
ENDIF
!
ENDIF
!
END SUBROUTINE
......@@ -146,7 +152,7 @@ SUBROUTINE fetch_input_yml( num_drivers, driver, verbose, debug )
CHARACTER(LEN=512), EXTERNAL :: trimcheck
CHARACTER(LEN=:),ALLOCATABLE :: cvalue
TYPE(json_file) :: json
INTEGER :: iunit
INTEGER :: iunit, lenc
!
CALL start_clock('fetch_input')
!
......@@ -317,8 +323,30 @@ SUBROUTINE fetch_input_yml( num_drivers, driver, verbose, debug )
!
ENDIF
!
IF ( ANY(driver(:)==5) ) THEN
!
IERR = tuple_create(args, 3)
IERR = args%setitem(0, TRIM(ADJUSTL(main_input_file)) )
IERR = args%setitem(1, "server_control" )
IERR = args%setitem(2, verbose )
IERR = dict_create(kwargs)
!
IERR = call_py(return_obj, pymod, "read_keyword_from_file", args, kwargs)
IERR = cast(return_dict, return_obj)
!
CALL args%destroy
CALL kwargs%destroy
CALL return_obj%destroy
!
IERR = return_dict%getitem(cvalue, "document"); document = TRIM(ADJUSTL(cvalue))
!
CALL return_dict%destroy
!
ENDIF
!
CALL pymod%destroy
!
!
ENDIF
!
! BCAST & CHECKS
......@@ -442,6 +470,15 @@ SUBROUTINE fetch_input_yml( num_drivers, driver, verbose, debug )
!
ENDIF
!
IF ( ANY(driver(:)==5) ) THEN
!
lenc = LEN(document)
CALL mp_bcast(lenc,root,world_comm)
IF(mpime/=root) ALLOCATE(CHARACTER(LEN=lenc) :: document)
CALL mp_bcast(document,root,world_comm)
!
ENDIF
!
CALL mp_barrier(world_comm)
!
! REPORT
......@@ -545,6 +582,19 @@ SUBROUTINE fetch_input_yml( num_drivers, driver, verbose, debug )
!
ENDIF
!
IF ( ANY(driver(:)==5) ) THEN
!
! REPORT
!
CALL io_push_title('I/O Summary : server_control')
!
numsp=40
CALL io_push_value('document',document,numsp)
!
CALL io_push_bar()
!
ENDIF
!
ENDIF
!
IF ( verbose .AND. mpime == root ) THEN
......
......@@ -95,7 +95,7 @@ SUBROUTINE calc_outsourced (m,dvg,dng,iq)
!
USE kinds, ONLY : DP
USE mp, ONLY : mp_barrier
USE westcom, ONLY : npwq,npwqx,fftdriver,igq_q
USE westcom, ONLY : npwq,npwqx,fftdriver,igq_q
USE mp_global, ONLY : intra_image_comm,inter_pool_comm,my_image_id,me_bgrp
USE fft_at_k, ONLY : single_fwfft_k,single_invfft_k
USE fft_at_gamma, ONLY : single_fwfft_gamma,single_invfft_gamma,double_fwfft_gamma,double_invfft_gamma
......@@ -210,6 +210,7 @@ END SUBROUTINE
SUBROUTINE sleep_and_wait_for_lock_to_be_removed(lockfile)
!
USE westcom, ONLY: document
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
......@@ -233,6 +234,7 @@ SUBROUTINE sleep_and_wait_for_lock_to_be_removed(lockfile)
IERR = tuple_create(args, 1)
IERR = args%setitem(0, TRIM(ADJUSTL(lockfile)) )
IERR = dict_create(kwargs)
IERR = kwargs%setitem("document",document)
!
IERR = call_py(return_obj, pymod, "sleep_and_wait", args, kwargs)
!
......
......@@ -52,7 +52,7 @@ SUBROUTINE wstat_readin()
!
! READ other sections of the input file
!
CALL fetch_input_yml(1,(/2/),.TRUE.,.FALSE.)
CALL fetch_input_yml(2,(/2,5/),.TRUE.,.FALSE.)
!
CALL stop_clock('wstat_readin')
!
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment