How to do provenance with items in an aiida.orm.nodes.data.list.List

48 views
Skip to first unread message

Johannes Wasmer

unread,
Feb 26, 2021, 1:42:05 PM2/26/21
to aiidausers
Hi there,

in the following, I use these conventions.
Uppercase type = aiida Data type (e.g. List = aiida.orm.nodes.data.list.List)
Lowercase type = python/numpy type ('simple type', e.g. float, numpy.float)
'--->' provenance path maintained
'-x->' provenance path broken

In general terms,
I have a Collection of items. I want to apply them *individually* to a set of Nodes 'X'.
I want to maintain the provenance
Collection --> Nodes
However, aiida Collection Types (say, List) only store simple types.
Collection -x-> (for each) item -x-> Item ---> 'X' changed with Item
My solution to this problem is to define a CalcFunction itemize(Collection)->dict_of_items, which turns the Collection of items into a collection of Items. Then I use a Group to manage both and retrieve the latter.
Collection of items ---> itemize ---> (for each) Item ---> 'X' changed with Item

Is there are a simpler way to achieve this? I feel this approach is wrong since my scheme has data redundancy to maintain provenance. But I feel the motivation is valid.

In specific terms,
I have a List of floats. I want to apply them *individually* to a set of StructureData to rescale their lattice constants, for data augmentation.
However, aiida List Type only stores simple types.
List -x-> (for each) float -x-> Float ---> StructureData rescaled with Float
My solution to this problem is to define a CalcFunction itemize(List)->dict_of_items, which turns the List of floats into a list of Floats. Then I use a Group to manage both and retrieve the latter.
List of floats ---> itemize ---> (for each) Float ---> StructureData rescaled with Float

Thanks!

Jonathan Chico

unread,
Mar 30, 2021, 3:16:16 AM3/30/21
to aiidausers
Hi!

I use a similar technique when doing structural manipulations. I guess the issue is that the specific issue in your case is that you want to know which float was used in which StructureData to ensure full provenance tracking right?

The only other solution that I can think of, is to use a couple of calcfunctions insider a workfunction to do this, you could have the workfunction have as an input the List, then have a loop inside that that calls a calcfunction that takes the float in that list and casts it as a Float in the input and then returns the desired structure. The issue I see there is that you as far as I know you can only return one single node from a workfunction or calcfunction, which could be an issue depending on what you are trying to do.

If you have found out another way of doing this I would be very happy of hearing this!

Cheers

Sebastiaan Huber

unread,
Mar 30, 2021, 3:23:01 AM3/30/21
to aiida...@googlegroups.com
Hi Jonathan,

Just to comment on the following point:


The only other solution that I can think of, is to use a couple of calcfunctions insider a workfunction to do this, you could have the workfunction have as an input the List, then have a loop inside that that calls a calcfunction that takes the float in that list and casts it as a Float in the input and then returns the desired structure. The issue I see there is that you as far as I know you can only return one single node from a workfunction or calcfunction, which could be an issue depending on what you are trying to do.

You can actually return an arbitrary amount of output nodes from a process function (collective term for workfunctions and calcfunctions).
All you have to do is return a dictionary like so:

@calcfunction
def test():
    return {'a': Int(1), 'b': Int(2)}

This calcfunction will have two output `Int` nodes with the link labels `a` and `b`.
See the documentation [1] for more details.


Regards,

Sebastiaan



[1] https://aiida-core.readthedocs.io/en/latest/topics/processes/functions.html#return-values

--
AiiDA is supported by the NCCR MARVEL (http://nccr-marvel.ch/), funded by the Swiss National Science Foundation, and by the European H2020 MaX Centre of Excellence (http://www.max-centre.eu/).
 
Before posting your first question, please see the posting guidelines at http://www.aiida.net/?page_id=356 .
---
You received this message because you are subscribed to the Google Groups "aiidausers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aiidausers+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aiidausers/f929ab6c-0c5a-4e35-af75-022e3c0e2f0en%40googlegroups.com.

Jonathan Chico

unread,
Mar 30, 2021, 3:26:37 AM3/30/21
to aiida...@googlegroups.com
Thanks Sebastiaan!

I had not read that so carefully, this is really good to know!

Cheers



--
Jonathan Chico

Johannes Wasmer

unread,
Mar 30, 2021, 3:33:00 AM3/30/21
to aiidausers
Hi Jonathan, Sebastiaan, thanks for your replies.
Yeah that's also how I do it (i.e., return a dict).
Reply all
Reply to author
Forward
0 new messages