This module provides functions and classes related to Task objects.

class TaskManager(**kwargs)[source]

Bases: monty.json.MSONable

A TaskManager is responsible for the generation of the job script and the submission of the task, as well as for the specification of the parameters passed to the resource manager (e.g. Slurm, PBS ...) and/or the run-time specification of the ABINIT variables governing the parallel execution. A TaskManager delegates the generation of the submission script and the submission of the task to the QueueAdapter. A TaskManager has a TaskPolicy that governs the specification of the parameters for the parallel executions. Ideally, the TaskManager should be the main entry point used by the task to deal with job submission/optimization

Parameters: policy – None qadapters – List of qadapters in YAML format db_connector – Dictionary with data used to connect to the database (optional)
ENTRIES = {'policy', 'qadapters', 'db_connector', 'batch_adapter'}
USER_CONFIG_DIR = '/Users/shyue/.abinit/abipy'
YAML_FILE = 'manager.yml'
as_dict()[source]
classmethod as_manager(obj)[source]

Convert obj into TaskManager instance. Accepts string, filepath, dictionary, TaskManager object. If obj is None, the manager is initialized from the user config file.

classmethod autodoc()[source]
cancel(job_id)[source]

Cancel the job. Returns exit status.

deepcopy()[source]

Deep copy of self.

exclude_nodes(nodes)[source]
classmethod from_dict(d)[source]

Create an instance from a dictionary.

classmethod from_file(filename)[source]

Read the configuration parameters from the Yaml file filename.

classmethod from_string(s)[source]

Create an instance from string s containing a YAML dictionary.

classmethod from_user_config()[source]

Initialize the TaskManager from the YAML file ‘manager.yaml’. Search first in the working directory and then in the abipy configuration directory.

get_collection(**kwargs)[source]

Return the MongoDB collection used to store the results.

get_njobs_in_queue(username=None)[source]

returns the number of jobs in the queue, returns None when the number of jobs cannot be determined.

Parameters: username – (str) the username of the jobs to count (default is to autodetect)
has_db

True if we are using MongoDB database

has_omp

True if we are using OpenMP parallelization.

has_queue

True if we are submitting jobs via a queue manager.

increase_mem()[source]
increase_ncpus()[source]

increase the number of cpus, first ask the current quadapter, if that one raises a QadapterIncreaseError switch to the next qadapter. If all fail raise an ManagerIncreaseError

increase_resources()[source]
increase_time()[source]
launch(task, **kwargs)[source]

Build the input files and submit the task via the Qadapter

Parameters: task – TaskObject Process object.
max_cores

Maximum number of cores that can be used. This value is mainly used in the autoparal part to get the list of possible configurations.

mem_per_proc

Memory per MPI process.

mpi_procs

Number of MPI processes.

new_with_fixed_mpi_omp(mpi_procs, omp_threads)[source]

Return a new TaskManager in which autoparal has been disabled. The jobs will be executed with mpi_procs MPI processes and omp_threads OpenMP threads. Useful for generating input files for benchmarks.

num_cores

Total number of CPUs used to run the task.

omp_threads

qadapter

The qadapter used to submit jobs.

qads

List of QueueAdapter objects sorted according to priorities (highest comes first)

select_qadapter(pconfs)[source]

Given a list of parallel configurations, pconfs, this method select an optimal configuration according to some criterion as well as the QueueAdapter to use.

Parameters: pconfs – ParalHints object with the list of parallel configurations ParallelConf object with the optimal configuration.
set_mem_per_proc(mem_mb)[source]

Set the memory (in Megabytes) per CPU.

set_mpi_procs(mpi_procs)[source]

Set the number of MPI processes to use.

set_omp_threads(omp_threads)[source]

Set the number of OpenMp threads to use.

to_shell_manager(mpi_procs=1)[source]

Returns a new TaskManager with the same parameters as self but replace the QueueAdapter with a ShellAdapter with mpi_procs so that we can submit the job without passing through the queue.

write_jobfile(task, **kwargs)[source]

Write the submission script. Return the path of the script

kwargs Meaning
exec_args List of arguments passed to task.executable. Default: no arguments.
class AbinitBuild(workdir=None, manager=None)[source]

Bases: object

This object stores information on the options used to build Abinit

info
String with build information as produced by abinit -b
version
Abinit version number e.g 8.0.1 (string)
has_netcdf
True if netcdf is enabled.
has_omp
True if OpenMP is enabled.
has_mpi
True if MPI is enabled.
has_mpiio
True if MPI-IO is supported.
class ParalHintsParser[source]

Bases: object

Error

alias of ParalHintsError

add_error(errmsg)[source]
parse(filename)[source]

Read the AutoParal section (YAML format) from filename. Assumes the file contains only one section.

class ParalHints(info, confs)[source]

Bases: collections.abc.Iterable

Iterable with the hints for the parallel execution reported by ABINIT.

Error

alias of ParalHintsError

as_dict(**kwargs)[source]
copy()[source]

Shallow copy of self.

classmethod from_dict(d)[source]
classmethod from_mpi_omp_lists(mpi_procs, omp_threads)[source]

Build a list of Parallel configurations from two lists containing the number of MPI processes and the number of OpenMP threads i.e. product(mpi_procs, omp_threads). The configuration have parallel efficiency set to 1.0 and no input variables. Mainly used for preparing benchmarks.

get_ordered_with_policy(policy, max_ncpus)[source]

Sort and return a new list of configurations ordered according to the TaskPolicy policy.

max_cores[source]

Maximum number of cores.

max_efficiency[source]

Maximum parallel efficiency.

max_mem_per_proc[source]

Maximum memory per MPI process.

max_speedup[source]

Maximum speedup.

multidimensional_optimization(priorities=('speedup', 'efficiency'))[source]
select_with_condition(condition, key=None)[source]

Remove all the configurations that do not satisfy the given condition.

Args:

condition: dict or Condition object with operators expressed with a Mongodb-like syntax key: Selects the sub-dictionary on which condition is applied, e.g. key=”vars”

if we have to filter the configurations depending on the values in vars
sort_by_efficiency(reverse=True)[source]

Sort the configurations in place. items with highest efficiency come first

sort_by_mem_per_proc(reverse=False)[source]

Sort the configurations in place. items with lowest memory per proc come first.

sort_by_speedup(reverse=True)[source]

Sort the configurations in place. items with highest speedup come first

class AbinitTask(input, workdir=None, manager=None, deps=None)[source]

Bases: pymatgen.io.abinit.tasks.Task

Base class defining an ABINIT calculation

Parameters: input – AbinitInput object. workdir – Path to the working directory. manager – TaskManager object. deps – Dictionary specifying the dependency of this node. None means that this Task has no dependency.
Results

alias of TaskResults

autoparal_run()[source]

Find an optimal set of parameters for the execution of the task This method can change the ABINIT input variables and/or the submission parameters e.g. the number of CPUs for MPI and OpenMp.

Set:
self.pconfs where pconfs is a ParalHints object with the configuration reported by autoparal and optimal is the optimal configuration selected. Returns 0 if success
executable

Path to the executable required for running the Task.

filesfile_string

String with the list of files and prefixes needed to execute ABINIT.

find_optconf(pconfs)[source]

Find the optimal Parallel configuration.

fix_abicritical()[source]

method to fix crashes/error caused by abinit

Returns: 1 if task has been fixed else 0.
fix_queue_critical()[source]

This function tries to fix critical events originating from the queue submission system.

General strategy, first try to increase resources in order to fix the problem, if this is not possible, call a task specific method to attempt to decrease the demands.

Returns: 1 if task has been fixed else 0.
classmethod from_input(input, workdir=None, manager=None)[source]

Create an instance of AbinitTask from an ABINIT input.

Parameters: ainput – AbinitInput object. workdir – Path to the working directory. manager – TaskManager object.
isnc

True if norm-conserving calculation.

ispaw

True if PAW calculation

parse_timing()[source]

Parse the timer data in the main output file of Abinit. Requires timopt /= 0 in the input file (usually timopt = -1)

Return: AbinitTimerParser instance, None if error.

pconfs

List of autoparal configurations.

pseudos

List of pseudos used in the calculation.

reset_from_scratch()[source]

Restart from scratch, this is to be used if a job is restarted with more resources after a crash

Move output files produced in workdir to _reset otherwise check_status continues to see the task as crashed even if the job did not run

restart()[source]

general restart used when scheduler problems have been taken care of

select_files(what='o')[source]

Helper function used to select the files of a task.

Parameters: what – string with the list of characters selecting the file type Possible choices: i ==> input_file, o ==> output_file, f ==> files_file, j ==> job_file, l ==> log_file, e ==> stderr_file, q ==> qout_file, all ==> all files.
set_pconfs(pconfs)[source]

Set the list of autoparal configurations.

setup()[source]

Abinit has the very bad habit of changing the file extension by appending the characters in [A,B ..., Z] to the output file, and this breaks a lot of code that relies of the use of a unique file extension. Here we fix this issue by renaming run.abo to run.abo_[number] if the output file “run.abo” already exists. A few lines of code in python, a lot of problems if you try to implement this trick in Fortran90.

classmethod temp_shell_task(inp, workdir=None, manager=None)[source]

Build a Task with a temporary workdir. The task is executed via the shell with 1 MPI proc. Mainly used for invoking Abinit to get important parameters needed to prepare the real task.

uses_paral_kgb(value=1)[source]

True if the task is a GS Task and uses paral_kgb with the given value.

class ScfTask(input, workdir=None, manager=None, deps=None)[source]

Bases: pymatgen.io.abinit.tasks.GsTask

Self-consistent ground-state calculations. Provide support for in-place restart via (WFK|DEN) files

Parameters: input – AbinitInput object. workdir – Path to the working directory. manager – TaskManager object. deps – Dictionary specifying the dependency of this node. None means that this Task has no dependency.
CRITICAL_EVENTS = [<class 'pymatgen.io.abinit.events.ScfConvergenceWarning'>]
color_rgb = array([ 1., 0., 0.])
get_results(**kwargs)[source]
inspect(**kwargs)[source]

Plot the SCF cycle results with matplotlib.

Returns
matplotlib figure, None if some error occurred.
restart()[source]

SCF calculations can be restarted if we have either the WFK file or the DEN file.

class NscfTask(input, workdir=None, manager=None, deps=None)[source]

Bases: pymatgen.io.abinit.tasks.GsTask

Non-Self-consistent GS calculation. Provide in-place restart via WFK files

Parameters: input – AbinitInput object. workdir – Path to the working directory. manager – TaskManager object. deps – Dictionary specifying the dependency of this node. None means that this Task has no dependency.
CRITICAL_EVENTS = [<class 'pymatgen.io.abinit.events.NscfConvergenceWarning'>]
color_rgb = array([ 1. , 0.47843137, 0.47843137])
get_results(**kwargs)[source]
restart()[source]

NSCF calculations can be restarted only if we have the WFK file.

class RelaxTask(input, workdir=None, manager=None, deps=None)[source]

Bases: pymatgen.io.abinit.tasks.GsTask, pymatgen.io.abinit.tasks.ProduceHist

Parameters: input – AbinitInput object. workdir – Path to the working directory. manager – TaskManager object. deps – Dictionary specifying the dependency of this node. None means that this Task has no dependency.
CRITICAL_EVENTS = [<class 'pymatgen.io.abinit.events.RelaxConvergenceWarning'>]
color_rgb = array([ 1. , 0.23921569, 1. ])
fix_ofiles()[source]

Note that ABINIT produces lots of out_TIM1_DEN files for each step. Here we list all TIM*_DEN files, we select the last one and we rename it in out_DEN

This change is needed so that we can specify dependencies with the syntax {node: “DEN”} without having to know the number of iterations needed to converge the run in node!

get_final_structure()[source]

Read the final structure from the GSR file.

get_results(**kwargs)[source]
inspect(**kwargs)[source]

Plot the evolution of the structural relaxation with matplotlib.

Parameters: what – Either “hist” or “scf”. The first option (default) extracts data from the HIST file and plot the evolution of the structural parameters, forces, pressures and energies. The second option, extracts data from the main output file and plot the evolution of the SCF cycles (etotal, residuals, etc). matplotlib figure, None if some error occurred.
reduce_dilatmx(target=1.01)[source]
restart()[source]

Restart the structural relaxation.

Structure relaxations can be restarted only if we have the WFK file or the DEN or the GSR file. from which we can read the last structure (mandatory) and the wavefunctions (not mandatory but useful). Prefer WFK over other files since we can reuse the wavefunctions.

Note

The problem in the present approach is that some parameters in the input are computed from the initial structure and may not be consistent with the modification of the structure done during the structure relaxation.

class DdkTask(input, workdir=None, manager=None, deps=None)[source]

Bases: pymatgen.io.abinit.tasks.DfptTask

Parameters: input – AbinitInput object. workdir – Path to the working directory. manager – TaskManager object. deps – Dictionary specifying the dependency of this node. None means that this Task has no dependency.
color_rgb = array([ 0.23921569, 0.61960784, 1. ])
get_results(**kwargs)[source]
class PhononTask(input, workdir=None, manager=None, deps=None)[source]

Bases: pymatgen.io.abinit.tasks.DfptTask

DFPT calculations for a single atomic perturbation. Provide support for in-place restart via (1WF|1DEN) files

Parameters: input – AbinitInput object. workdir – Path to the working directory. manager – TaskManager object. deps – Dictionary specifying the dependency of this node. None means that this Task has no dependency.
CRITICAL_EVENTS = [<class 'pymatgen.io.abinit.events.ScfConvergenceWarning'>]
color_rgb = array([ 0., 0., 1.])
get_results(**kwargs)[source]
inspect(**kwargs)[source]

Plot the Phonon SCF cycle results with matplotlib.

Returns: matplotlib figure, None if some error occurred.
restart()[source]

Phonon calculations can be restarted only if we have the 1WF file or the 1DEN file. from which we can read the first-order wavefunctions or the first order density. Prefer 1WF over 1DEN since we can reuse the wavefunctions.

class SigmaTask(input, workdir=None, manager=None, deps=None)[source]

Bases: pymatgen.io.abinit.tasks.ManyBodyTask

Tasks for SIGMA calculations. Provides support for in-place restart via QPS files

Parameters: input – AbinitInput object. workdir – Path to the working directory. manager – TaskManager object. deps – Dictionary specifying the dependency of this node. None means that this Task has no dependency.
CRITICAL_EVENTS = [<class 'pymatgen.io.abinit.events.QPSConvergenceWarning'>]
color_rgb = array([ 0., 1., 0.])
get_results(**kwargs)[source]
get_scissors_builder()[source]

Returns an instance of ScissorsBuilder from the SIGRES file.

Raise:
open_sigres()[source]

Open the SIGRES file located in the in self.outdir. Returns SigresFile object, None if file could not be found or file is not readable.

restart()[source]
sigres_path

Absolute path of the SIGRES file. Empty string if file is not present.

class OpticTask(optic_input, nscf_node, ddk_nodes, workdir=None, manager=None)[source]

Bases: pymatgen.io.abinit.tasks.Task

Task for the computation of optical spectra with optic i.e. RPA without local-field effects and velocity operator computed from DDK files.

Create an instance of OpticTask from an string containing the input.

Parameters: optic_input – string with the optic variables (filepaths will be added at run time). nscf_node – The NSCF task that will produce thw WFK file or string with the path of the WFK file. ddk_nodes – List of DdkTask nodes that will produce the DDK files or list of DDF paths. workdir – Path to the working directory. manager – TaskManager object.
autoparal_run()[source]

Find an optimal set of parameters for the execution of the Optic task This method can change the submission parameters e.g. the number of CPUs for MPI and OpenMp.

Returns 0 if success

color_rgb = array([ 1. , 0.8, 0.4])
ddk_filepaths

Returns (at runtime) the absolute path of the DDK files produced by the DDK runs.

executable

Path to the executable required for running the OpticTask.

filesfile_string

String with the list of files and prefixes needed to execute ABINIT.

fix_abicritical()[source]

Cannot fix abicritical errors for optic

fix_queue_critical()[source]

This function tries to fix critical events originating from the queue submission system.

General strategy, first try to increase resources in order to fix the problem, if this is not possible, call a task specific method to attempt to decrease the demands.

Returns: 1 if task has been fixed else 0.
get_results(**kwargs)[source]
make_input()[source]

Construct and write the input file of the calculation.

Optic allows the user to specify the paths of the input file. hence we don’t need to create symbolic links.

reset_from_scratch()[source]

restart from scratch, this is to be used if a job is restarted with more resources after a crash

set_vars(*args, **kwargs)[source]

Optic does not use get or ird variables hence we should never try to change the input when we connect this task

set_workdir(workdir, chroot=False)[source]

Set the working directory of the task.

setup()[source]

Public method called before submitting the task.

wfk_filepath

Returns (at runtime) the absolute path of the WFK file produced by the NSCF run.

class AnaddbTask(anaddb_input, ddb_node, gkk_node=None, md_node=None, ddk_node=None, workdir=None, manager=None)[source]

Bases: pymatgen.io.abinit.tasks.Task

Create an instance of AnaddbTask from a string containing the input.

Parameters: anaddb_input – string with the anaddb variables. ddb_node – The node that will produce the DDB file. Accept Task, Work or filepath. gkk_node – The node that will produce the GKK file (optional). Accept Task, Work or filepath. md_node – The node that will produce the MD file (optional). Accept Task, Work or filepath. gkk_node – The node that will produce the GKK file (optional). Accept Task, Work or filepath. workdir – Path to the working directory (optional). manager – TaskManager object (optional).
color_rgb = array([ 0.8, 0.4, 1. ])
ddb_filepath

Returns (at runtime) the absolute path of the input DDB file.

ddk_filepath

Returns (at runtime) the absolute path of the input DKK file.

executable

Path to the executable required for running the AnaddbTask.

filesfile_string

String with the list of files and prefixes needed to execute ABINIT.

get_results(**kwargs)[source]
gkk_filepath

Returns (at runtime) the absolute path of the input GKK file.

Anaddb allows the user to specify the paths of the input file. hence we don’t need to create symbolic links.

md_filepath

Returns (at runtime) the absolute path of the input MD file.

open_phbst()[source]

Open PHBST file produced by Anaddb and returns PhbstFile object.

open_phdos()[source]

Open PHDOS file produced by Anaddb and returns PhdosFile object.

setup()[source]

Public method called before submitting the task.

classmethod temp_shell_task(inp, ddb_node, gkk_node=None, md_node=None, ddk_node=None, workdir=None, manager=None)[source]

Build a AnaddbTask with a temporary workdir. The task is executed via the shell with 1 MPI proc. Mainly used for post-processing the DDB files.

Parameters: anaddb_input – string with the anaddb variables. ddb_node – The node that will produce the DDB file. Accept Task, Work or filepath.

See AnaddbInit for the meaning of the other arguments.