This module defines the Node class that is inherited by Task, Work and Flow objects.

class Dependency(node, exts=None)[source]

Bases: object

This object describes the dependencies among the nodes of a calculation.

A Dependency consists of a Node that produces a list of products (files) that are used by the other nodes (Task or Work) to start the calculation. One usually creates the object by calling work.register


# Register the SCF task in work. scf_task = work.register(scf_strategy)

# Register the NSCF calculation and its dependency on the SCF run via deps. nscf_task = work.register(nscf_strategy, deps={scf_task: “DEN”})

  • node – The task or the worfklow associated to the dependency or string with a filepath.
  • exts – Extensions of the output files that are needed for running the other tasks.

This function is called when we specify the task dependencies with the syntax:

deps={node: “@property”}

In this case the task has to the get property from node before starting the calculation.

At present, the following properties are supported:

  • @structure

Returns a dictionary with the variables that must be added to the input file in order to connect this Node to its dependencies.


Returns the paths of the output files produced by self and its extensions


The Node associated to the dependency.


List of output files produces by self.


The status of the dependency, i.e. the status of the Node.

class FileNode(filename)[source]


A Node that consists of a file. May be not yet existing

Mainly used to connect Task objects to external files produced in previous runs.


Add a node (usually Task) to the children of this FileNode.


Basename of the file.

color_rgb = array([0.4, 0.2, 1. ])

List with the children (nodes) of this FileNode.

class GarbageCollector(exts, policy)[source]

Bases: object

This object stores information on the

class GridFsFile(path, fs_id=None, mode=u’b’)[source]

Bases: monty.collections.AttrDict

Information on a file that will stored in the MongoDb gridfs collection.

class HistoryRecord(level, pathname, lineno, msg, args, exc_info, func=None)[source]

Bases: object

A HistoryRecord instance represents an entry in the NodeHistory.

HistoryRecord instances are created every time something is logged. They contain all the information pertinent to the event being logged. The main information passed in is in msg and args, which are combined using str(msg) % args to create the message field of the record. The record also includes information such as when the record was created, the source line where the logging call was made


Numeric logging level for the message (DEBUG, INFO, WARNING, ERROR, CRITICAL)


Text logging level for the message (“DEBUG”, “INFO”, “WARNING”, “ERROR”, “CRITICAL”)


Full pathname of the source file where the logging call was issued (if available)


Filename portion of pathname


Module (name portion of filename)


Source line number where the logging call was issued (if available)


Function name


Time when the HistoryRecord was created (time.time() return value)


Textual time when the HistoryRecord was created

The result of record.getMessage(), computed just as the record is emitted

Initialize a logging record with interesting information.

as_dict(*args, **kwargs)[source]
classmethod from_dict(d)[source]
get_message(metadata=False, asctime=True)[source]

Return the message after merging any user-supplied arguments with the message.

  • metadata – True if function and module name should be added.
  • asctime – True if time string should be added.
class Node[source]

Bases: object

Abstract base class defining the interface that must be implemented by the nodes of the calculation.

Nodes are hashable and can be tested for equality

ALL_STATUS = [<Status: Initialized, at 120861586064>, <Status: Locked, at 120861588512>, <Status: Ready, at 120861586424>, <Status: Submitted, at 120861587864>, <Status: Running, at 120861588440>, <Status: Done, at 120861588152>, <Status: AbiCritical, at 120861586280>, <Status: QCritical, at 120861587072>, <Status: Unconverged, at 120861586496>, <Status: Error, at 120861587720>, <Status: Completed, at 120861587936>]

alias of NodeError


alias of NodeResults

S_ABICRITICAL = <Status: AbiCritical, at 120861586280>
S_DONE = <Status: Done, at 120861588152>
S_ERROR = <Status: Error, at 120861587720>
S_INIT = <Status: Initialized, at 120861586064>
S_LOCKED = <Status: Locked, at 120861588512>
S_OK = <Status: Completed, at 120861587936>
S_QCRITICAL = <Status: QCritical, at 120861587072>
S_READY = <Status: Ready, at 120861586424>
S_RUN = <Status: Running, at 120861588440>
S_SUB = <Status: Submitted, at 120861587864>
S_UNCONVERGED = <Status: Unconverged, at 120861586496>

alias of SpectatorNodeError

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

Add a list of dependencies to the Node.

Parameters:deps – List of Dependency objects specifying the dependencies of the node. or dictionary mapping nodes to file extensions e.g. {task: “DEN”}
classmethod as_node(obj)[source]

Convert obj into a Node instance.

Returns:obj if obj is a Node instance, cast obj to FileNode instance of obj is a string. None if obj is None

Check the status of the Node.


Node color as Hex Triplet https – //

color_rgb = array([0.41176471, 0.41176471, 0.41176471])

List of dictionaries with infornation on the actions performed to solve AbiCritical Events. Each dictionary contains the AbinitEvent who triggered the correction and a human-readable message with the description of the operation performed.


True if this node depends on the other node.


List of Dependency objects defining the dependencies of this Node. Empty list if this Node does not have dependencies.


Returns a list with the status of the dependencies.


The list of handlers registered for this node. If the node is not a Flow and does not have its own list of handlers the handlers registered at the level of the flow are returned.

This trick allows one to registered different handlers at the level of the Task for testing purposes. By default, we have a common list of handlers for all the nodes in the flow. This choice facilitates the automatic installation of the handlers when we use callbacks to generate new Works and Tasks!


True if the Node has been finalized.


Garbage collector. None if garbage collection is deactivated. Use flow.set_garbage_collector to initialize the object.


Return the list of nodes in the Flow that depends on this Node


This routine assumes the entire flow has been allocated.

get_graphviz_dirtree(engine=u’automatic’, **kwargs)[source]

Generate directory graph in the DOT language. The graph show the files and directories in the node workdir.

Returns: graphviz.Digraph <>


Return the list of nodes in the Flow required by this Node


Return pandas DataFrame with the value of the variables specified in varnames. Can be used for task/works/flow. It’s recursive!

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

Install the EventHandlers for this `Node. If no argument is provided the default list of handlers is installed.

  • categories – List of categories to install e.g. base + can_change_physics
  • handlers – explicit list of EventHandler instances. This is the most flexible way to install handlers.


categories and handlers are mutually exclusive.


True if this node is a file


True if this node is a Flow


True if this node is a Task


True if this node is a Work


Check whether the node is a instance of class_or_string. Unlinke the standard isinstance builtin, the method accepts either a class or a string. In the later case, the string is compared with self.__class__.__name__ (case insensitive).

log_correction(event, action)[source]

This method should be called once we have fixed the problem associated to this event. It adds a new entry in the correction history of the node.

  • eventAbinitEvent that triggered the correction.
  • action (str) – Human-readable string with info on the action perfomed to solve the problem.

The name of the node (only used for facilitating its identification in the user interface).


Node identifier.


Return a relative version of the workdir

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

Remove a list of dependencies from the Node.

Parameters:deps – List of Dependency objects specifying the dependencies of the node.

Send signal from this node to all connected receivers unless the node is in spectator mode.

signal – (hashable) signal value, see dispatcher connect for details

Return a list of tuple pairs [(receiver, response), … ] or None if the node is in spectator mode.

if any receiver raises an error, the error propagates back through send, terminating the dispatch loop, so it is quite possible to not have all receivers called if a raises an error.


Set the garbage collector.


Set the name of the Node.

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

Set the node identifier. Use it carefully!

show_event_handlers(stream=<open file ‘<stdout>’, mode ‘w’>, verbose=0)[source]

Print to stream the event handlers installed for this flow.


The status of the Node.


Return the string representation of the dependencies of the node.

class NodeCorrections[source]

Bases: list

Iterable storing the correctios performed by the EventHandler

exception NodeError[source]

Bases: exceptions.Exception

Base Exception raised by Node subclasses

class NodeHistory[source]

Bases: collections.deque

Logger-like object

critical(msg, *args, **kwargs)[source]

Log ‘msg % args’ with the critical severity level

info(msg, *args, **kwargs)[source]

Log ‘msg % args’ with the info severity level


Returns a string with the history. Set metadata to True to have info on function and module.

warning(msg, *args, **kwargs)[source]

Log ‘msg % args’ with the warning severity level

class NodeResults(node, **kwargs)[source]

Bases: dict, monty.json.MSONable

Dictionary used to store the most important results produced by a Node.

JSON_SCHEMA = {u’type’: u’object’, u’properties’: {u’files’: {u’required’: True, u’type’: u’object’}, u’node_status’: {u’required’: True, u’type’: u’string’}, u’node_id’: {u’required’: True, u’type’: u’integer’}, u’node_history’: {u’required’: True, u’type’: u’array’}, u’in’: {u’required’: True, u’type’: u’object’, u’description’: u’dictionary with input parameters’}, u’exceptions’: {u’required’: True, u’type’: u’array’}, u’node_finalized’: {u’required’: True, u’type’: u’boolean’}, u’node_class’: {u’required’: True, u’type’: u’string’}, u’out’: {u’required’: True, u’type’: u’object’, u’description’: u’dictionary with the output results’}, u’node_name’: {u’required’: True, u’type’: u’string’}}}
as_dict(*args, **kwargs)[source]
classmethod from_dict(d)[source]
classmethod from_node(node)[source]

Initialize an instance of NodeResults from a Node subclass.


List with the absolute paths of the files to be put in GridFs.

classmethod json_load(filename)[source]

This function registers the files that will be saved in GridFS. kwargs is a dictionary mapping the key associated to the file (usually the extension) to the absolute path. By default, files are assumed to be in binary form, for formatted files one should pass a tuple (“filepath”, “t”).


results.register_gridfs(GSR="path/to/", text_file=("/path/to/txt_file", "t"))

The GSR file is a binary file, whereas text_file is a text file.


Update a mongodb collection.

class Product(ext, path)[source]

Bases: object

A product represents an output file produced by ABINIT instance. This file is needed to start another Task or another Work.

  • ext – ABINIT file extension
  • path – (asbolute) filepath

Returns a dictionary with the ABINIT variables that must be used to make the code use this file.


Absolute path of the file.

classmethod from_file(filepath)[source]

Build a Product instance from a filepath.

exception SpectatorNodeError[source]


Exception raised by Node methods when the node is in spectator mode and we are calling a method with side effects.

class Status[source]

Bases: int

This object is an integer representing the status of the Node.

classmethod all_status_strings()[source]

List of strings with all possible values status.

classmethod as_status(obj)[source]

Convert obj into Status.


Return colorized text used to print the status if the stream supports it.

classmethod from_string(s)[source]

Return a Status instance from its string representation.


True if status is critical.

t = (11, u’Completed’, u’green’, None, None)

Decorator for Node methods. Raise SpectatorNodeError.


Returns a new node identifier used for Task, Work and Flow objects.


Save the id of the last node created.