# Workflows¶

This section describes the different base workchains and utilities for workchain development.

## Utilities¶

class aiida_quantumespresso.common.workchain.utils.ErrorHandler(priority, method)

A namedtuple to define an error handler for a WorkChain.

The priority determines in which order the error handling methods are executed, with the higher priority being executed first. The method defines an unbound WorkChain method that takes an instance of a AbstractJobCalculation as its sole argument. If the condition of the error handler is met, it should return an ErrorHandlerReport.

Parameters: priority – integer denoting the error handlers priority method – the workchain class method
method

Alias for field number 1

priority

Alias for field number 0

class aiida_quantumespresso.common.workchain.utils.ErrorHandlerReport(is_handled, do_break)

A namedtuple to define an error handler report for a WorkChain.

This namedtuple should be returned by an error handling method of a workchain instance if the condition of the error handling was met by the failure mode of the calculation. If the error was appriopriately handled, the ‘is_handled’ field should be set to True, and False otherwise. If no further error handling should be performed after this method the ‘do_break’ field should be set to True

Parameters: is_handled – boolean, set to True when an error was handled do_break – boolean, set to True if no further error handling should be performed
do_break

Alias for field number 1

is_handled

Alias for field number 0

aiida_quantumespresso.common.workchain.utils.register_error_handler(cls, priority)[source]

Decorator that will turn any function in an error handler for workchain that inherits from the BaseRestartWorkChain. The function expects two arguments, a workchain class and a priortity. The decorator will add the function as a class method to the workchain class and add an ErrorHandler tuple to the BaseRestartWorkChain._error_handlers attribute of the workchain. During failed calculation handling the inspect_calculation() outline method will call the _handle_calculation_failure which will loop over all error handler in the BaseRestartWorkChain._error_handlers, sorted with respect to the priority in reverse. If the workchain class defines a BaseRestartWorkChain._verbose attribute and is set to True, a report message will be fired when the error handler is executed.

Requirements on the function signature of error handling functions. The function to which the decorator is applied needs to take two arguments:

• self: This is the instance of the workchain itself
• calculation: This is the calculation that failed and needs to be investigated

The function body should usually consist of a single conditional that checks the calculation if the error that it is designed to handle is applicable. Although not required, it is advised that the function return an ErrorHandlerReport tuple when its conditional was met. If an error was handled it should set is_handled to True. If no other error handlers should be considered set do_break to True.

Parameters: cls – the workchain class to register the error handler with priority – an integer that defines the order in which registered handlers will be called during the handling of a failed calculation. Higher priorities will be handled first