Do `with_ancestors` and `with_descendants` work?

Hi everyone,
I am trying to use the QueryBuilder with these options, but they seem to produce nothing, even when having a very generic Node-Node path. This is my example:

q = QueryBuilder()
q.append(Group, filters={'label':'group_label', tag='g')
q.append(WorkChainNode, with_group='g', tag='wc')
q.append(Node,  with_ancestors='wc',)

No results are found. Am I interpreting it the right way? I don’t see why it produces nothing whatever is the Node chosen (even generic Node).

I think that the with_ancestors and with_descendants do not work with WorkChain nodes (at least it does not work for me). It does work with data nodes, and CalcJob nodes. I think that the explanation for why can be found here

1 Like

Thanks for pointing to this thread! It is indeed the usecase I would need.

I had the same issue recently. with_descendants does not work with WorkChain.

Indeed, the with_ancestors and with_descendants only work for the data provenance, not the logical provenance:

https://aiida.readthedocs.io/projects/aiida-core/en/stable/topics/provenance/concepts.html#data-provenance-and-logical-provenance

One critical difference between the two is that the data provenance is a directed acyclic graph (DAG). The logical provenance does allow for loops, for example the OutputInputWorkChain example from the tutorials:

This can create issues with infinite loops for with_ancestors and with_descendants if you could use these when querying the logical provenance, as is noted by Leonid (the OG Querybuilder developer, I believe) here:

1 Like

As Leonid mentioned in the issue, maybe this is something to be solved not with the Query Builder directly but with the Graph Explorer? Maybe easiest to discuss at the AiiDA meeting the details and then report them back here? I also am not 100% sure anymore (but the graph explorer is used internally e.g. for finding all nodes to delete if one deletes one node, etc., and is efficient for this type of recursive queries)