Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: add the "How to explore the provenance graph" section #4491

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Oct 20, 2020

Fixes #4464

This section adds completely new documentation on the graph exploring
methods get_incoming and get_outgoing that were not yet documented.
It also documents the creator, caller and creator properties that
also weren't documented yet.

The working_with_aiida/resultmanager.rst is removed and its content,
that documents the inputs and outputs properties of process nodes as
well as the res property of the CalcJobNode class, is added to the
new section in heavily rewritten form.

@sphuber sphuber requested a review from giovannipizzi October 20, 2020 14:56
Incoming and outgoing links
===========================

The provenance graph in AiiDA is a :ref:`directed acyclic graph <topics:provenance:concepts>`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The provenance graph in AiiDA is a :ref:`directed acyclic graph <topics:provenance:concepts>`.
The provenance graph in AiiDA is a :ref:`directed graph <topics:provenance:concepts>`.


The provenance graph in AiiDA is a :ref:`directed acyclic graph <topics:provenance:concepts>`.
The vertices of the graph are the *nodes* and the edges that connect them are called *links*.
Since the graph is directed, any node can have *incoming* and *outgoing* links that connects it to neighboring nodes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Since the graph is directed, any node can have *incoming* and *outgoing* links that connects it to neighboring nodes.
Since the graph is directed, any node can have *incoming* and *outgoing* links that connect it to neighboring nodes.

Since the graph is directed, any node can have *incoming* and *outgoing* links that connects it to neighboring nodes.

To discover the neighbors of a given node, you can use the methods :meth:`~aiida.orm.nodes.node.Node.get_incoming` and :meth:`~aiida.orm.nodes.node.Node.get_outgoing`.
They have the exact same interface but will return the neighbors from which the links are incoming, or to which the links are pointing, respectively.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
They have the exact same interface but will return the neighbors from which the links are incoming, or to which the links are pointing, respectively.
They have the exact same interface but will return the neighbors connected to the current node with link coming into it, or with links going out of it, respectively.

I feel this is a bit more clear (I hope)

The :meth:`~aiida.orm.nodes.node.Node.get_incoming` and :meth:`~aiida.orm.nodes.node.Node.get_outgoing` methods accept various arguments that allow one to filter what neighboring nodes should be matched:

* ``node_class``: accepts a subclass of :class:`~aiida.orm.nodes.node.Node`, only neighboring nodes with a class that matches this will be returned
* ``link_type``: accepts a vale of :class:`~aiida.common.links.LinkType`, only neighboring nodes that are linked with this link type will be returned
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* ``link_type``: accepts a vale of :class:`~aiida.common.links.LinkType`, only neighboring nodes that are linked with this link type will be returned
* ``link_type``: accepts a value of :class:`~aiida.common.links.LinkType`, only neighboring nodes that are linked with this link type will be returned


* ``node_class``: accepts a subclass of :class:`~aiida.orm.nodes.node.Node`, only neighboring nodes with a class that matches this will be returned
* ``link_type``: accepts a vale of :class:`~aiida.common.links.LinkType`, only neighboring nodes that are linked with this link type will be returned
* ``link_label_filter``: accepts a string regex (with optional wildcards), only neighboring nodes that are linked with a link label that matches the regex will be returned
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* ``link_label_filter``: accepts a string regex (with optional wildcards), only neighboring nodes that are linked with a link label that matches the regex will be returned
* ``link_label_filter``: accepts a string expression (with optional wildcards using the syntax of SQL `LIKE` patterns, see below), only neighboring nodes that are linked with a link label that matches the regex will be returned

I think regex means a specific thing - we shouldn't say that these are regexes.
These are called patterns e.g. in the postgres docs

outputs = process_node.outputs

These properties do not return the actual inputs and outputs directly, but instead return an instance of :class:`~aiida.orm.utils.managers.NodeLinksManager`
The reason is because through the manager, the inputs or outputs are accessible through their link label and it is tab-completed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The reason is because through the manager, the inputs or outputs are accessible through their link label and it is tab-completed.
The reason is because through the manager, the inputs or outputs are accessible through their link label (that, for inputs and outputs of processes, is unique) and can be tab-completed.

.. note::

The ``inputs`` and ``outputs`` properties are only defined for :class:`~aiida.orm.nodes.process.process.ProcessNode`'s.
This means that you cannot *chain* these calls, because an input or output of a process node is guaranteed to be a :class:`~aiida.orm.nodes.data.Data` node, which does not have inputs or outputs.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put this comment below, after explaining creator, to say that inputs+creator allows to go up in the provenance graph as much as you want, chaining them. Instead, going down, you cannot for the reason you mention

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where exactly you intend this to be placed. It is true that chaining creator and inputs alternatively works, but that is just one example and not every node has a creator. Instead, I kept this as is and added another note after the explanation of creator that gives the example you propose.

* :meth:`~aiida.orm.nodes.process.process.ProcessNode.called`: defined for :class:`~aiida.orm.nodes.process.process.ProcessNode`'s and returns the list of process nodes called by this node.
If this process node did not call any other processes, this property returns an empty list.
* :meth:`~aiida.orm.nodes.process.process.ProcessNode.caller`: defined for :class:`~aiida.orm.nodes.process.process.ProcessNode`'s and returns the process node that called this node.
If this ndoe was not called by a process, this property returns ``None``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If this ndoe was not called by a process, this property returns ``None``.
If this node was not called by a process, this property returns ``None``.


Similar to the ``inputs`` and ``outputs`` properties of process nodes, there are some more properties that make exploring the provenance graph easier:

* :meth:`~aiida.orm.nodes.process.process.ProcessNode.called`: defined for :class:`~aiida.orm.nodes.process.process.ProcessNode`'s and returns the list of process nodes called by this node.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not relevant for this PR, but I realise now that we could have defined this only for WorkflowNodes, actually, since the list will always be empty for CalculationNodes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, and I think the ProcessNode should also have a inputs and outputs implementation. Now I cannot reference it

node.res.some_key

In an interactive shell, the available keys are also tab-completed.
If you type ``node.res.`` followed by the tab key twice, a list of the available keys is printed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add that, if the default output node link label is output_parameters, then node.res.some_key is equivalent to node.outputs.output_parameters.dict.some_key and stress that we are looking at the keys of a different node (this, together with the fact that verdi node outputcat/outputls act on a different node, does not seem to be super intuitive at first for new users, in my experience)

This section adds completely new documentation on the graph exploring
methods `get_incoming` and `get_outgoing` that were not yet documented.
It also documents the `creator`, `caller` and `creator` properties that
also weren't documented yet.

The `working_with_aiida/resultmanager.rst` is removed and its content,
that documents the `inputs` and `outputs` properties of process nodes as
well as the `res` property of the `CalcJobNode` class, is added to the
new section in heavily rewritten form.
@sphuber sphuber force-pushed the fix/4464/docs-exploring-provenance-graph branch from 3633cbf to 808b262 Compare October 21, 2020 13:39
@sphuber sphuber requested a review from giovannipizzi October 21, 2020 13:39
@sphuber
Copy link
Contributor Author

sphuber commented Oct 21, 2020

@giovannipizzi addressed all your comments

Copy link
Member

@giovannipizzi giovannipizzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@giovannipizzi giovannipizzi merged commit 3070610 into aiidateam:develop Oct 21, 2020
@giovannipizzi giovannipizzi deleted the fix/4464/docs-exploring-provenance-graph branch October 21, 2020 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docs: How to explore the provenance graph
2 participants