YamboCalculator

This module manages calculations performed with Yambo. Actually the run of the computation can be managed by the python subprocess package (direct scheduler) or by the slurm scheduler.

class mppi.Calculators.YamboCalculator.YamboCalculator(omp=1, mpi=2, mpi_run='mpirun -np', executable='yambo', scheduler='direct', skip=True, clean_restart=True, verbose=True, **kwargs)[source]

Bases: mppi.Calculators.Runner.Runner

Perform a Yambo calculation. Computations are managed by a scheduler that, in the actual implementation of the class, can be direct or slurm.

Parameters
  • omp (int) – value of the OMP_NUM_THREADS variable

  • mpi (int) – number of mpi processes

  • mpi_run (string) – command for the execution of mpirun, e.g. ‘mpirun -np’ or ‘mpiexec -np’

  • executable (string) – set the executable (yambo, ypp, yambo_rt, …) of the Yambo package

  • scheduler (string) – choose the scheduler used to submit the job, actually the choices implemented are ‘direct’ that runs the computation using the python subprocess package and ‘slurm’ that creates a slurm script

  • skip (bool) – if True evaluate if the computation can be skipped. This is done by checking that the folder where yambo write the results contains at least one file ‘o-*

  • clean_restart (bool) – if True delete the folder with the output files and the database before running the computation

  • verbose (bool) – set the amount of information provided on terminal

  • kwargs

    other parameters that are stored in the _global_options dictionary

    Example: >>> code = YamboCalculator(omp=1,mpi=4,mpi_run=’mpirun -np’,executable=’yambo’,skip=True,verbose=True,scheduler=’direct’) >>> code.run(input = …, run_dir = …,name = …,jobname = …, **kwargs)

    where the arguments of the run method are:

  • run_dir (string) – the folder in which the simulation is performed

  • input (string) – instance of the YamboInput class that define the input objects

  • name (string) – string with the names associated to the input file (without extension). This string is used also as the radical of the folders in which results are written as well as a part of the name of the output files.

  • jobname (string) – string with the values of the jobname. If this variable is not specified the value of name is attributed to jobname by process_run.

  • kwargs – other parameters that are stored in the run_options dictionary

When the run method is called the class runs the command:

executable_name -F name.in -J jobname -C name

The calculator looks for the following variables in the run_options dictionary. These options may be useful for _asincronous_ computation managed the slurm scheduler.

dry_run=True with this option the calculator setup the calculations and write the scrpt for submitting the jobs, but the computations are not run.

wait_end_run=False with this option the wait of the end of the run is suppressed.

sbatch_options = [option1,option2,….] allows the user to include further options in the slurm script

build_slurm_script()[source]

Create the slurm script associated to the run.

Returns

string with the name of the slurm script

Return type

string

is_to_run()[source]

The method evaluates if the computation can be skipped. This is done by checking if the folder where yambo write the results contains at least one file ‘o-*’.

Returns

the boolean is True if the computation needs to be run

Return type

bool

post_processing()[source]

Return a dictionary with the names of the o- file(s) and the names of the ndb databases written by yambo in the jobname folder .

Returns

the dictionary

{‘output’ : [o-1,o-2,…],’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 run_dir is cleaned before the run.

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. The value of the command depends on the chosen scheduler.

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.

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