aiida.tools.visualization package#
Provides tools for visualization of the provenance graph.
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', backend: Optional[StorageBackend] = None)[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__>, 'backend': <property object>, 'graphviz': <property object>, 'nodes': <property object>, 'edges': <property object>, '_load_node': <function Graph._load_node>, '_default_link_types': <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>, '__annotations__': {}})#
- __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', backend: Optional[StorageBackend] = None)[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)
- static _convert_link_types(link_types)[source]#
convert link types, which may be strings, to a member of LinkType
- static _default_link_types(link_types)[source]#
If link_types is empty, it will return all the links_types
- Parameters
links – iterable with the link_types ()
- Returns
list of
aiida.common.links.LinkType
- _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
in_node (int or aiida.orm.nodes.node.Node) – node or node pk/uuid
out_node (int or str or aiida.orm.nodes.node.Node) – node or node pk/uuid
link_pair (None or aiida.orm.utils.links.LinkPair) – defining the relationship between the nodes
style (dict or None) – graphviz style parameters (Default value = None)
overwrite (bool) – whether to overrite existing edge (Default value = False)
- 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
- property backend: StorageBackend#
The backend used to create the graph
- property edges#
return a copy of the edges
- property graphviz#
return a copy of the graphviz.Digraph
- property nodes#
return a copy of the nodes
- recurse_ancestors(origin, depth=None, link_types=(), annotate_links=False, origin_style=mappingproxy({'color': 'red', 'penwidth': 6}), include_process_outputs=False, highlight_classes=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 (None or dict) – node style map for origin node (Default value = None)
include_process_outputs (bool) – include outgoing links for all processes (Default value = False)
highlight_classes – class label (as displayed in the graph, e.g. ‘StructureData’, ‘FolderData’, etc.) to be highlight and other nodes are decolorized (Default value = None)
- Typle highlight_classes
list or tuple of str
- recurse_descendants(origin, depth=None, link_types=(), annotate_links=False, origin_style=mappingproxy({'color': 'red', 'penwidth': 6}), include_process_inputs=False, highlight_classes=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 (None or dict) – node style map for origin node (Default value = None)
include_calculation_inputs (bool) – include incoming links for all processes (Default value = False)
highlight_classes – target class in exported graph expected to be highlight and other nodes are decolorized (Default value = None)
- Typle highlight_classes
tuple of class or class
- aiida.tools.visualization.graph._add_graphviz_edge(graph, in_node, out_node, style=None)[source]#
add graphviz edge between two nodes
- Parameters
graph – the graphviz.DiGraph to add the edge to
in_node – the head node
out_node – the tail node
style (dict or None) – the graphviz style (Default value = None)
- aiida.tools.visualization.graph._add_graphviz_node(graph, node, node_style_func, node_sublabel_func, style_override=None, include_sublabels=True, id_type='pk')[source]#
create a node in the graph
The first line of the node text is always ‘<node.name> (<node.pk>)’. Then, if
include_sublabels=True
, subsequent lines are added, which are node type dependant.- Parameters
graph – the graphviz.Digraph to add the node to
node (aiida.orm.nodes.node.Node) – the node to add
node_style_func – callable mapping a node instance to a dictionary defining the graphviz node style
node_sublabel_func – callable mapping a node instance to a sub-label for the node text
style_override (None or dict) – style dictionary, whose keys will override the final computed style
include_sublabels (bool) – whether to include the sublabels for nodes
id_type (str) – the type of identifier to use for node labels (‘pk’ or ‘uuid’)
nodes are styled based on the node type
For subclasses of Data, the
class_node_type
attribute is used for mapping to type specific stylesFor subclasses of ProcessNode, we choose styles to distinguish between types, and also color the nodes for successful/failed processes
- aiida.tools.visualization.graph._get_node_label(node, id_type='pk')[source]#
return a label text of node and the return format is ‘<NodeType> (<id>)’.
- aiida.tools.visualization.graph.default_link_styles(link_pair: aiida.orm.utils.links.LinkPair, add_label: bool, add_type: bool) dict [source]#
map link_pair to a graphviz edge style
- Parameters
link_type (aiida.orm.utils.links.LinkPair) – a LinkPair attribute
add_label (bool) – include link label
add_type (bool) – include link type
- Return type
- 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
- 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
- aiida.tools.visualization.graph.get_node_id_label(node, id_type)[source]#
return an identifier str for the node
- 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