QeCalculator

This module manages calculations performed with QuantumESPRESSO. The run of the computation is performed by the python subprocess package (direct scheduler) or by the slurm scheduler.

class mppi.Calculators.QeCalculator.QeCalculator(runRules, executable='pw.x', skip=True, clean_restart=True, dry_run=False, wait_end_run=True, activate_BeeOND=False, verbose=True, **kwargs)[source]

Bases: Runner

Perform a QuantumESPRESSO calculation. The parameters used to define the parellelization strategy are provided in the runRules object.

Parameters:
  • runRulues (RunRules) – instance of the RunRules class

  • executable (string) – set the executable (pw.x, ph.x, ..) of the QuantumESPRESSO package

  • skip (bool) – if True evaluate if the computation can be skipped. This is done by checking if the log file of the run contains the string job_done, defined as a data member of this class

  • clean_restart (bool) – if True delete the folder $prefix.save before running the computation

  • dry_run (bool) – with this option enabled the calculator setup the calculations and write the script for submitting the job, but the computations are not run

  • wait_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 scheduler

  • activate_BeeOND (bool) – if True set I/O of the run in the BeeOND_dir created by the slurm scheduler. With this options enabled the out_dir of the run is set in the BeenOND_dir folder and the input wavefunction of the source folder (if needed) are copied in the BeeOND_dir. At the end of the run the out_dir is moved in its original path. The value of the BeeOND_dir is written as a data member of the class and can be modified if needed

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

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

Computations are performed in the folder specified by the run_dir parameter. The input and the log files are written in the run_dir. Instead, the $prefix.xml file and the $prefix.save folders are written in the out_dir path. The values of the prefix and out_dir variables are read from the input file. If the out_dir path is a relative path its root is located in the run_dir folder.

Example

>>> rr = RunRules(scheduler='slurm',ntasks_per_node=4,memory='124GB')
>>> code = calculator(rr,skip=True,clean_restart=True,verbose=True)
>>> code.run(input = ..., run_dir = ...,name = ..., source_dir = ..., **kwargs)
When the run method is called the class runs the command:

cd run_dir ; mpirun command executable_name -inp name.in > name.log

where the arguments of the run method are:

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

  • input (string) – instance of the PwInput class that define the input object

  • name (string) – string with the name associated to the input file. Usually it is convenient to 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 the same

  • source_dir (string) – useful for the nscf computations. The source folder contains the wave-functions created by a scf calculation. If present the class copies this folder in the out_dir with the name $prefix.save

  • kwargs – 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 $name.log and the job_$name.out file, located in the run_dir, and the $prefix.xml file and the $prefix.save folder located in the out_dir. Finally, if the out_dir is empty it is deleted.

clean_slurm_out()[source]

Delete the job_$name.out file.

copy_source_dir()[source]

Copy the source_dir (if provided) in the out_dir and atttibute to the copied folder the name $prefix.save. The operation is performed only if a folder with the target name of the source_dir is not found in the out_dir

Parameters:
  • source_dir – the name of the source_dir (tipically it is the .save folder

  • state). (of the scf calculation that contains the wave-functions of the ground) –

is_to_run()[source]

The method evaluates if the computation has to be performed. If skip is False the run is always performed, instead if skip is True the method checks if the log file exsists and contains the string job_done defined as a member of the class. The method adds the key is_to_run to the run_options of the class.

job_done = 'JOB DONE.'
post_processing()[source]

Return the name, including the path, of the data-file-schema.xml file. If the file is absent the method displays a warning.

Returns:

name, including the path, of the xml data-file-schema file

Return type:

string

pre_processing()[source]

Process local run dictionary to create the run directory and input file. If clean_restart is True the clean_run method is called before the run. Call the copy_source_dir() that manages the source folder, if provided.

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.

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