YamboCalculator¶
This module manages calculations performed with Yambo. The run of the computation is performed by the python subprocess package (direct scheduler) or by the slurm scheduler.
- class mppi.Calculators.YamboCalculator.YamboCalculator(runRules, executable='yambo', skip=True, clean_restart=True, dry_run=False, wait_end_run=True, activate_BeeOND=False, verbose=True, fatlog=False, **kwargs)[source]¶
Bases:
RunnerPerform a Yambo calculation. The parameters used to define the parellelization strategy are provided in the runRules object.
- Parameters:
runRulues (
RunRules) – instance of theRunRulesclassexecutable (
string) – set the executable (yambo, ypp, yambo_rt, …) of the Yambo packageskip (
bool) – if True evaluate if the computation can be skipped. This is done by checking that the report file built by yambo exists and contains the string game_over, defined as a data member of this classclean_restart (
bool) – if True delete the folder with the output files and the database before running the computationdry_run (
bool) – with this option enabled the calculator setup the calculations and write the script for submitting the job, but the computations are not runwait_end_run (
bool) – with this option disabled the run method does not wait the end of the run. This option may be useful for interacting with the code in particular in _asincronous_ computation managed by the slurm scheduleractivate_BeeOND (
bool) – if True set I/O of the run in the BeeOND_dir created by the slurm scheduler. The value of theBeeOND_diris written as a data member of the class and can be modified if neededverbose (
bool) – set the amount of information provided on terminalfatlog (
bool) – if True set the -fatlog key to provide more information in the report filekwargs –
other parameters that are stored in the _global_options dictionary
Computations are performed in the folder specified by the
run_dirparameter. Thenameparameter is used as name of the yambo input and as the name of the folder where yambo writes the o- output files. Thejobnameparameter is the name of the folder where yambo writes the .ndb databases. If this parameter is not provided in the run method the assumption jobname=name is made by the calculator.- Example:
>>> rr = RunRules(scheduler='slurm',ntasks_per_node=4,memory='124GB') >>> code = YamboCalculator(rr,executable='yambo',skip=True,verbose=True) >>> code.run(input = ..., run_dir = ...,name = ...,jobname = ..., **kwargs)
- When the run method is called the class runs the command:
cd run_dir ; mpirun command executable_name -F name.in -J jobname -C name - O out_dir
where the arguments of the run method are:
run_dir (
string) – the folder in which the simulation is performedinput (
string) – instance of theYamboInputclass that define the input objectsname (
string) – string with the names associated to the input file (without extension). This string is used also as the name of the folder in which results are written (argument of the -C option of yambo) as well as a part of the name of the output filesjobname (
listorstring) – string (or list of strings) with the value(s) of the jobname folders (argument of the -J option of yambo). The first element is the folder name, where yambo writes the database. The other values (if provided) are the folders where yambo seeks for pre existing databases. All the elements of the list are assumed to be located in therun_dirof the calculator. If this variable is not specified the value of name is attributed to jobnameout_dir (
string) – position of the folder in which the $jobname folder is located. This parameter is automatically set by the calculator the value ofBeeOND_dirif the option activate_BeeOND is enabled. Otherwise all the folders are written in therun_dirkwargs – other parameters that are stored in the run_options dictionary
- BeeOND_dir = '/mnt/${SLURM_JOB_USER}-jobid_${SLURM_JOB_ID}'¶
- build_slurm_script()[source]¶
Create the slurm script associated to the run.
- Returns:
string with the name of the slurm script
- Return type:
string
- clean_run()[source]¶
Delete existing results before performing the computation. Delete the out_dir folder and the folder with the databases. If several folders are provided in the jobname field, only the first one is deleted, since the others are assumed to contain databases obtained from other computations.
- game_over = 'Game Over & Game summary'¶
- is_to_run()[source]¶
The method evaluates if the computation has to be performed. If
skipis False the run is always performed, instead ifskipis True the method checks if the report file exists and contains the string game_over defined as a member of the class. The method adds the key is_to_run tothe run_optionsof the class.Note that the first element of the report list is used, so caution is needed if there is more than one report file in the report key of the results dictionary.
- post_processing()[source]¶
Return a dictionary with the names of the o- file(s), the report ‘r-’ file, the ns.db1 in the SAVE folder and the names of the ndb databases written by yambo in the jobname folder. The method performs a sanity check of the computation by checking that the game_over string is found in the report and shows the time needed to perform the simulation (if the time_profile string is found in the report).
- Returns:
- the dictionary
{‘output’ : [o-1,o-2,…],’report’:…,’dft’:…,’dipoles’:…, ….}
- Return type:
dict
- pre_processing()[source]¶
Process local run dictionary. Check that the run_dir exists and that it contains the SAVE folder. If clean_restart = True the results associated to previous computations are deleted before the run. The slurm out script is always deleted before the run, otherwise the calculator can erroneously assume that the run is completed.
Note
If the run_dir and/or the SAVE folder do not exist an alert is written but the execution of the run method proceedes.
- process_run()[source]¶
Method associated to the running of the executable. The method runs the computation and wait the end of the computation before passing to the
post_processing()method.
- run_command()[source]¶
Define the run command used to run the computation.
- Returns:
command that runs the computation
- Return type:
string
- run_ended(job)[source]¶
Check the status of the running job.
- Parameters:
job – reference to the actual job. job is an istance of Popen for direct scheduler or a string for slurm scheduler
- Returns:
return True if the computation is ended and False if it is running
- Return type:
bool
- run_job()[source]¶
Run the computation. The operations performed depend on the scheduler adopted. If the dry_run option is enabled the run is not performed but the slurm script is written on disk.
- Returns:
The type of the object depends on the chosen scheduler. For scheduler direct job is an instance of Popen, while for slurm scheduler job is the name of the slurm script.
- time_profile = 'Time-Profile'¶
- wait(job)[source]¶
Wait the end of the job. If the dry_run option is enabled or wait_end_run is False the check is not performed.
- Parameters:
jobs – The reference to the job to be executed. If the scheduler is direct jobs is an instance of Popen of the :py:class:subprocess package. If the scheduler is slurm jobs is a string with the name of the slurm script
- mppi.Calculators.YamboCalculator.build_results_dict(run_dir, outputPath, dbsPath, verbose=True)[source]¶
Return a dictionary with the names of the o- file(s), the report ‘r-’ file, the ns.db1 in the SAVE folder and the names of the ndb database written by yambo in the jobname folder. Databases are sought in the dbsPath.
- Parameters:
run_dir (
string) – run_dir folder of the calculationoutputPath (
string) – folder with the ‘o-’ filesdbsPath (
list) – list of folders with the ndb databasesverbose (
bool) – set the amount of information provided on terminal
- Returns:
- the dictionary
{‘output’ : [o-1,o-2,…],’dft’:…,’dipoles’:…, ….}
- Return type:
dict
- mppi.Calculators.YamboCalculator.get_db_files(dbsPath)[source]¶
Look for the files of tht type ndb.* in the dbsPath. Note that the first element of dbsPath is the folder where Yambo writes the ndb database. If a ndb is found in this folder its (eventual) replica in the other folders of dbsPath are not considered (this behavior protects under erroneuos identification of the correct databas that can happen, for instance, if a ndb given as input is not compliant with the actual computation so that Yambo has to compute it).
- Parameters:
dbstPath (
list) – list of folders in which the ndb databases created by Yambo are sought- Returns:
- A dictionary in which the keys are the extension of the
databases found and the values are their names, including the path
- Return type:
dict
- mppi.Calculators.YamboCalculator.get_output_files(path)[source]¶
Scan the path with the output files and build a dictionary in which the keys are type of output (hf,qp,carriers,…) and the values are the names of the file for each type. If the path contains several replica of the output files (due to the fact the Yambo has been exectuted many times without cleaning the output folder) the function identifies the files associated to the last run.
- Parameters:
path (
string) – folder where the o-* files are stored- Returns:
- Dictionary with the types (keys) and names values,
including the path, of the files o-* produced by the run
- Return type:
dict
- mppi.Calculators.YamboCalculator.get_report(path)[source]¶
Look for the name of the r-* file(s) produced by the execution of the code. If multiple istances of the report are found, the function selects the one assciated to the last computation.
- Parameters:
path (
string) – folder with the r-* and the o-* files- Returns:
String with the name, including the path, of the file r-* produced by the run. If no report files is found an empty string is provided as output
- Return type:
string
- mppi.Calculators.YamboCalculator.type_identifier(file)[source]¶
Found the type of the o-file according to its name. Different extension like ‘hf’ or ‘hf_01’ are recognized with the same type, that is ‘hf’ in this example.
- Parameters:
file (
string) – file name- Returns:
string with the type of the file
- Return type:
string