QeCalculator

This module manages parallel calculations with QuantumESPRESSO. Both a scheduler like slurm or the python multiprocessing package can be used.

class mppi.Calculators.QeCalculator.QeCalculator(omp=1, mpi=2, mpi_run='mpirun -np', executable='pw.x', scheduler='direct', multiTask=True, skip=True, verbose=True, IO_time=5, **kwargs)[source]

Bases: mppi.Calculators.Runner.Runner

Manage (multiple) QuantumESPRESSO calculations performed in parallel. 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 (pw.x, ph.x, ..) of the QuantumESPRESSO package

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

  • multiTask (bool) – if true a single run_script is built and all the computations are performed in parallel, otherwise an independent script is built for each elements of inputs and the computations are performed sequentially

  • skip (bool) – if True evaluate if one (or many) computations can be skipped. This is done by checking if the file $name.xml is present in the prefix folder, for each name in names

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

  • IO_time (int) – time step (in second) used by the wait method to check that the job is completed

  • kwargs – other parameters that are stored in the _global_options dictionary. For instance the variable sbatch_options = [option1,option2,….] allows the user to include further options in the slurm script

Example

>>> code = calculator(omp=1,mpi=4,mpi_run='mpirun -np',skip=True,verbose=True,scheduler='direct')
>>> code.run(inputs = [...], run_dir = ...,names = [...], source_dir = ..., **kwargs)

where the arguments of the run method are:

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

  • inputs (list) – list with the instances of the PwInput class that define the input objects

  • names (list) – list with the names associated to the input files, given in the same order of the inputs list. Usually you can set the name equal to the prefix of the input object so the name of the input file and the prefix folder built by QuantumESPRESSO are equal

  • source_dir (string) – location of the scf source folder for a nscf computation. If present the class copies this folder in the run_dir with the name $prefix.save

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

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.

build_run_script(to_run)[source]

Create the run script(s) that are executed by the submit_job() method. The scripts depend on the scheduler adopted, and specific methods for direct and slurm scheduler are implemented.

Parameters

to_run (string) – list with the cardinal numbers of the runs to be performed

Returns

list with jobs to run. The type of the object in the list depends on the chosen scheduler

Return type

list

direct_scheduler(to_run)[source]

Define the list of Process (methods of multiprocessing) associated to the runs specified in the list to_run.

Parameters

to_run (string) – list with the cardinal numbers of the runs to be performed

Returns

list of the multiprocessing objects associated to the runs of the job

Return type

list

post_processing()[source]

Return a list with the names, including the path, of the data-file-schema.xml files for each element of inputs. If a file is absent the method returns None in the associated element of the list, making easy to understand if a specific computation has been correctly performed.

Returns

dictionary

{‘output’ : []}

where [] is a list with the names of the xml files (if the file exists) otherwise the associated element is set to None.

Return type

dict

pre_processing()[source]

Process local run dictionary to create the run directory and input files. If skip = False clean the run_dir. If the ‘source_dir’ key is passed to the run method copy the source folder in the run_dir with the name $prefix. This procedure is performed after the deletion run_dir/prefix.save since otherwise the copy of the source_dir is deleted.

process_run()[source]

Method associated to the running of the executable. The method prepares the jobs script(s), then submit the jobs and wait the end of the computation before passing to the post_processing() method. Computations are performed in parallel or serially accordingly to the value of the multiTask option.

run_command(index)[source]

Define the run command used to run the computation associated to the input file $names[index]. The value of the command depends on the chosen scheduler.

Parameters

index (int) – index of the computation to be performed

Returns

command that runs the computation associated to the $names[index] input file

Return type

string

select_to_run()[source]

If the skip attribute of run_options is True the method evaluates which computations can be skipped. This is done by checking if the file $prefix.xml is already present in the run_dir.

Returns

list with numbers of the computations that have to be performed, in the same order provided in the run method

Return type

list

slurm_scheduler(to_run)[source]

Create the slurm script(s) associated to the runs specified in the list to_run.

Parameters

to_run (string) – list with the cardinal numbers of the runs to be performed

Returns

list with the names of the slurm scripts associated to the computations that are not skipped

Return type

list

submit_job(jobs)[source]

Submit the job.

Parameters

jobs – The reference to the jobs to be executed. If the scheduler is direct jobs is a list with the instance of :py:class:multiprocessing. If the scheduler is slurm jobs is a list with the names of the slurm scripts

wait(jobs, to_run)[source]

Wait the end of the jobs.

Parameters
  • jobs – The reference to the jobs to be executed. If the scheduler is direct jobs is a list with the instance of :py:class:multiprocessing. If the scheduler is slurm jobs is a list with the names of the slurm scripts

  • to_run (string) – list with the cardinal numbers of the runs to be performed