aiida.tools.visualization package

Provides tools for visualization of the provenance graph.

class aiida.tools.visualization.Graph(engine=None, graph_attr=None, global_node_style=None, global_edge_style=None, include_sublabels=True, link_style_fn=None, node_style_fn=None, node_sublabel_fn=None, node_id_type='pk')[source]

Bases: object

a class to create graphviz graphs of the AiiDA node provenance

__dict__ = mappingproxy({'__module__': 'aiida.tools.visualization.graph', '__doc__': 'a class to create graphviz graphs of the AiiDA node provenance', '__init__': <function Graph.__init__>, 'graphviz': <property object>, 'nodes': <property object>, 'edges': <property object>, '_load_node': <staticmethod object>, 'add_node': <function Graph.add_node>, 'add_edge': <function Graph.add_edge>, '_convert_link_types': <staticmethod object>, 'add_incoming': <function Graph.add_incoming>, 'add_outgoing': <function Graph.add_outgoing>, 'recurse_descendants': <function Graph.recurse_descendants>, 'recurse_ancestors': <function Graph.recurse_ancestors>, 'add_origin_to_targets': <function Graph.add_origin_to_targets>, 'add_origins_to_targets': <function Graph.add_origins_to_targets>, '__dict__': <attribute '__dict__' of 'Graph' objects>, '__weakref__': <attribute '__weakref__' of 'Graph' objects>})
__init__(engine=None, graph_attr=None, global_node_style=None, global_edge_style=None, include_sublabels=True, link_style_fn=None, node_style_fn=None, node_sublabel_fn=None, node_id_type='pk')[source]

a class to create graphviz graphs of the AiiDA node provenance

Nodes and edges, are cached, so that they are only created once

Parameters:
  • engine (str or None) – the graphviz engine, e.g. dot, circo (Default value = None)
  • graph_attr (dict or None) – attributes for the graphviz graph (Default value = None)
  • global_node_style (dict or None) – styles which will be added to all nodes. Note this will override any builtin attributes (Default value = None)
  • global_edge_style (dict or None) – styles which will be added to all edges. Note this will override any builtin attributes (Default value = None)
  • include_sublabels (bool) – if True, the note text will include node dependant sub-labels (Default value = True)
  • link_style_fn – callable mapping LinkType to graphviz style dict; link_style_fn(link_type) -> dict (Default value = None)
  • node_sublabel_fn – callable mapping nodes to a graphviz style dict; node_sublabel_fn(node) -> dict (Default value = None)
  • node_sublabel_fn – callable mapping data node to a sublabel (e.g. specifying some attribute values) node_sublabel_fn(node) -> str (Default value = None)
  • node_id_type (str) – the type of identifier to within the node text (‘pk’, ‘uuid’ or ‘label’)
__module__ = 'aiida.tools.visualization.graph'
__weakref__

list of weak references to the object (if defined)

convert link types, which may be strings, to a member of LinkType

static _load_node(node)[source]

load a node (if not already loaded)

Parameters:node (int or str or aiida.orm.nodes.node.Node) – node or node pk/uuid
Returns:aiida.orm.nodes.node.Node
add_edge(in_node, out_node, link_pair=None, style=None, overwrite=False)[source]

add single node to the graph

Parameters:
add_incoming(node, link_types=(), annotate_links=None, return_pks=True)[source]

add nodes and edges for incoming links to a node

Parameters:
  • node (aiida.orm.nodes.node.Node or int) – node or node pk/uuid
  • link_types (str or tuple[str] or aiida.common.links.LinkType or tuple[aiida.common.links.LinkType]) – filter by link types (Default value = ())
  • annotate_links (bool or str) – label edges with the link ‘label’, ‘type’ or ‘both’ (Default value = None)
  • return_pks (bool) – whether to return a list of nodes, or list of node pks (Default value = True)
Returns:

list of nodes or node pks

add_node(node, style_override=None, overwrite=False)[source]

add single node to the graph

Parameters:
  • node (int or str or aiida.orm.nodes.node.Node) – node or node pk/uuid
  • style_override (dict or None) – graphviz style parameters that will override default values
  • overwrite (bool) – whether to overrite an existing node (Default value = False)
add_origin_to_targets(origin, target_cls, target_filters=None, include_target_inputs=False, include_target_outputs=False, origin_style=(), annotate_links=False)[source]

Add nodes and edges from an origin node to all nodes of a target node class.

Parameters:
  • origin (aiida.orm.nodes.node.Node or int) – node or node pk/uuid
  • target_cls – target node class
  • target_filters (dict or None) – (Default value = None)
  • include_target_inputs (bool) – (Default value = False)
  • include_target_outputs (bool) – (Default value = False)
  • origin_style (dict or tuple) – node style map for origin node (Default value = ())
  • annotate_links (bool) – label edges with the link ‘label’, ‘type’ or ‘both’ (Default value = False)
add_origins_to_targets(origin_cls, target_cls, origin_filters=None, target_filters=None, include_target_inputs=False, include_target_outputs=False, origin_style=(), annotate_links=False)[source]

Add nodes and edges from all nodes of an origin class to all node of a target node class.

Parameters:
  • origin_cls – origin node class
  • target_cls – target node class
  • origin_filters (dict or None) – (Default value = None)
  • target_filters (dict or None) – (Default value = None)
  • include_target_inputs (bool) – (Default value = False)
  • include_target_outputs (bool) – (Default value = False)
  • origin_style (dict or tuple) – node style map for origin node (Default value = ())
  • annotate_links (bool) – label edges with the link ‘label’, ‘type’ or ‘both’ (Default value = False)
add_outgoing(node, link_types=(), annotate_links=None, return_pks=True)[source]

add nodes and edges for outgoing links to a node

Parameters:
  • node (aiida.orm.nodes.node.Node or int) – node or node pk
  • link_types (str or tuple[str] or aiida.common.links.LinkType or tuple[aiida.common.links.LinkType]) – filter by link types (Default value = ())
  • annotate_links (bool or str) – label edges with the link ‘label’, ‘type’ or ‘both’ (Default value = None)
  • return_pks (bool) – whether to return a list of nodes, or list of node pks (Default value = True)
Returns:

list of nodes or node pks

edges

return a copy of the edges

graphviz

return a copy of the graphviz.Digraph

nodes

return a copy of the nodes

recurse_ancestors(origin, depth=None, link_types=(), annotate_links=False, origin_style=(), include_process_outputs=False, print_func=None)[source]

add nodes and edges from an origin recursively, following incoming links

Parameters:
  • origin (aiida.orm.nodes.node.Node or int) – node or node pk/uuid
  • depth (None or int) – if not None, stop after travelling a certain depth into the graph (Default value = None)
  • link_types (tuple or str) – filter by subset of link types (Default value = ())
  • annotate_links (bool) – label edges with the link ‘label’, ‘type’ or ‘both’ (Default value = False)
  • origin_style (dict or tuple) – node style map for origin node (Default value = ())
  • include_process_outputs (bool) – include outgoing links for all processes (Default value = False)
  • print_func – a function to stream information to, i.e. print_func(str)
recurse_descendants(origin, depth=None, link_types=(), annotate_links=False, origin_style=(), include_process_inputs=False, print_func=None)[source]

add nodes and edges from an origin recursively, following outgoing links

Parameters:
  • origin (aiida.orm.nodes.node.Node or int) – node or node pk/uuid
  • depth (None or int) – if not None, stop after travelling a certain depth into the graph (Default value = None)
  • link_types (tuple or str) – filter by subset of link types (Default value = ())
  • annotate_links (bool or str) – label edges with the link ‘label’, ‘type’ or ‘both’ (Default value = False)
  • origin_style (dict or tuple) – node style map for origin node (Default value = ())
  • include_calculation_inputs (bool) – include incoming links for all processes (Default value = False)
  • print_func – a function to stream information to, i.e. print_func(str)

map link_pair to a graphviz edge style

Parameters:
Return type:

dict

aiida.tools.visualization.default_node_styles(node)[source]

map a node to a graphviz node style

Parameters:node (aiida.orm.nodes.node.Node) – the node to map
Return type:dict
aiida.tools.visualization.pstate_node_styles(node)[source]

map a process node to a graphviz node style

Parameters:node (aiida.orm.nodes.node.Node) – the node to map
Return type:dict
aiida.tools.visualization.default_node_sublabels(node)[source]

function mapping nodes to a sublabel (e.g. specifying some attribute values)

Parameters:node (aiida.orm.nodes.node.Node) – the node to map
Return type:str

Submodules

provides functionality to create graphs of the AiiDa data providence, via graphviz.

class aiida.tools.visualization.graph.Graph(engine=None, graph_attr=None, global_node_style=None, global_edge_style=None, include_sublabels=True, link_style_fn=None, node_style_fn=None, node_sublabel_fn=None, node_id_type='pk')[source]

Bases: object

a class to create graphviz graphs of the AiiDA node provenance

__dict__ = mappingproxy({'__module__': 'aiida.tools.visualization.graph', '__doc__': 'a class to create graphviz graphs of the AiiDA node provenance', '__init__': <function Graph.__init__>, 'graphviz': <property object>, 'nodes': <property object>, 'edges': <property object>, '_load_node': <staticmethod object>, 'add_node': <function Graph.add_node>, 'add_edge': <function Graph.add_edge>, '_convert_link_types': <staticmethod object>, 'add_incoming': <function Graph.add_incoming>, 'add_outgoing': <function Graph.add_outgoing>, 'recurse_descendants': <function Graph.recurse_descendants>, 'recurse_ancestors': <function Graph.recurse_ancestors>, 'add_origin_to_targets': <function Graph.add_origin_to_targets>, 'add_origins_to_targets': <function Graph.add_origins_to_targets>, '__dict__': <attribute '__dict__' of 'Graph' objects>, '__weakref__': <attribute '__weakref__' of 'Graph' objects>})
__init__(engine=None, graph_attr=None, global_node_style=None, global_edge_style=None, include_sublabels=True, link_style_fn=None, node_style_fn=None, node_sublabel_fn=None, node_id_type='pk')[source]

a class to create graphviz graphs of the AiiDA node provenance

Nodes and edges, are cached, so that they are only created once

Parameters:
  • engine (str or None) – the graphviz engine, e.g. dot, circo (Default value = None)
  • graph_attr (dict or None) – attributes for the graphviz graph (Default value = None)
  • global_node_style (dict or None) – styles which will be added to all nodes. Note this will override any builtin attributes (Default value = None)
  • global_edge_style (dict or None) – styles which will be added to all edges. Note this will override any builtin attributes (Default value = None)
  • include_sublabels (bool) – if True, the note text will include node dependant sub-labels (Default value = True)
  • link_style_fn – callable mapping LinkType to graphviz style dict; link_style_fn(link_type) -> dict (Default value = None)
  • node_sublabel_fn – callable mapping nodes to a graphviz style dict; node_sublabel_fn(node) -> dict (Default value = None)
  • node_sublabel_fn – callable mapping data node to a sublabel (e.g. specifying some attribute values) node_sublabel_fn(node) -> str (Default value = None)
  • node_id_type (str) – the type of identifier to within the node text (‘pk’, ‘uuid’ or ‘label’)
__module__ = 'aiida.tools.visualization.graph'
__weakref__

list of weak references to the object (if defined)

convert link types, which may be strings, to a member of LinkType

static _load_node(node)[source]

load a node (if not already loaded)

Parameters:node (int or str or aiida.orm.nodes.node.Node) – node or node pk/uuid
Returns:aiida.orm.nodes.node.Node
add_edge(in_node, out_node, link_pair=None, style=None, overwrite=False)[source]

add single node to the graph

Parameters:
add_incoming(node, link_types=(), annotate_links=None, return_pks=True)[source]

add nodes and edges for incoming links to a node

Parameters:
  • node (aiida.orm.nodes.node.Node or int) – node or node pk/uuid
  • link_types (str or tuple[str] or aiida.common.links.LinkType or tuple[aiida.common.links.LinkType]) – filter by link types (Default value = ())
  • annotate_links (bool or str) – label edges with the link ‘label’, ‘type’ or ‘both’ (Default value = None)
  • return_pks (bool) – whether to return a list of nodes, or list of node pks (Default value = True)
Returns:

list of nodes or node pks

add_node(node, style_override=None, overwrite=False)[source]

add single node to the graph

Parameters:
  • node (int or str or aiida.orm.nodes.node.Node) – node or node pk/uuid
  • style_override (dict or None) – graphviz style parameters that will override default values
  • overwrite (bool) – whether to overrite an existing node (Default value = False)
add_origin_to_targets(origin, target_cls, target_filters=None, include_target_inputs=False, include_target_outputs=False, origin_style=(), annotate_links=False)[source]

Add nodes and edges from an origin node to all nodes of a target node class.

Parameters:
  • origin (aiida.orm.nodes.node.Node or int) – node or node pk/uuid
  • target_cls – target node class
  • target_filters (dict or None) – (Default value = None)
  • include_target_inputs (bool) – (Default value = False)
  • include_target_outputs (bool) – (Default value = False)
  • origin_style (dict or tuple) – node style map for origin node (Default value = ())
  • annotate_links (bool) – label edges with the link ‘label’, ‘type’ or ‘both’ (Default value = False)
add_origins_to_targets(origin_cls, target_cls, origin_filters=None, target_filters=None, include_target_inputs=False, include_target_outputs=False, origin_style=(), annotate_links=False)[source]

Add nodes and edges from all nodes of an origin class to all node of a target node class.

Parameters:
  • origin_cls – origin node class
  • target_cls – target node class
  • origin_filters (dict or None) – (Default value = None)
  • target_filters (dict or None) – (Default value = None)
  • include_target_inputs (bool) – (Default value = False)
  • include_target_outputs (bool) – (Default value = False)
  • origin_style (dict or tuple) – node style map for origin node (Default value = ())
  • annotate_links (bool) – label edges with the link ‘label’, ‘type’ or ‘both’ (Default value = False)
add_outgoing(node, link_types=(), annotate_links=None, return_pks=True)[source]

add nodes and edges for outgoing links to a node

Parameters:
  • node (aiida.orm.nodes.node.Node or int) – node or node pk
  • link_types (str or tuple[str] or aiida.common.links.LinkType or tuple[aiida.common.links.LinkType]) – filter by link types (Default value = ())
  • annotate_links (bool or str) – label edges with the link ‘label’, ‘type’ or ‘both’ (Default value = None)
  • return_pks (bool) – whether to return a list of nodes, or list of node pks (Default value = True)
Returns:

list of nodes or node pks

edges

return a copy of the edges

graphviz

return a copy of the graphviz.Digraph

nodes

return a copy of the nodes

recurse_ancestors(origin, depth=None, link_types=(), annotate_links=False, origin_style=(), include_process_outputs=False, print_func=None)[source]

add nodes and edges from an origin recursively, following incoming links

Parameters:
  • origin (aiida.orm.nodes.node.Node or int) – node or node pk/uuid
  • depth (None or int) – if not None, stop after travelling a certain depth into the graph (Default value = None)
  • link_types (tuple or str) – filter by subset of link types (Default value = ())
  • annotate_links (bool) – label edges with the link ‘label’, ‘type’ or ‘both’ (Default value = False)
  • origin_style (dict or tuple) – node style map for origin node (Default value = ())
  • include_process_outputs (bool) – include outgoing links for all processes (Default value = False)
  • print_func – a function to stream information to, i.e. print_func(str)
recurse_descendants(origin, depth=None, link_types=(), annotate_links=False, origin_style=(), include_process_inputs=False, print_func=None)[source]

add nodes and edges from an origin recursively, following outgoing links

Parameters:
  • origin (aiida.orm.nodes.node.Node or int) – node or node pk/uuid
  • depth (None or int) – if not None, stop after travelling a certain depth into the graph (Default value = None)
  • link_types (tuple or str) – filter by subset of link types (Default value = ())
  • annotate_links (bool or str) – label edges with the link ‘label’, ‘type’ or ‘both’ (Default value = False)
  • origin_style (dict or tuple) – node style map for origin node (Default value = ())
  • include_calculation_inputs (bool) – include incoming links for all processes (Default value = False)
  • print_func – a function to stream information to, i.e. print_func(str)

map link_pair to a graphviz edge style

Parameters:
Return type:

dict

aiida.tools.visualization.graph.default_node_styles(node)[source]

map a node to a graphviz node style

Parameters:node (aiida.orm.nodes.node.Node) – the node to map
Return type:dict
aiida.tools.visualization.graph.pstate_node_styles(node)[source]

map a process node to a graphviz node style

Parameters:node (aiida.orm.nodes.node.Node) – the node to map
Return type:dict
aiida.tools.visualization.graph.default_node_sublabels(node)[source]

function mapping nodes to a sublabel (e.g. specifying some attribute values)

Parameters:node (aiida.orm.nodes.node.Node) – the node to map
Return type:str