Use calcfunction for getitem in For loop workgraph#283
Use calcfunction for getitem in For loop workgraph#283agoscinski wants to merge 7 commits intomainfrom
For loop workgraph#283Conversation
|
Hi @agoscinski , thanks for the work. There is a function It's also would be good if the user can supply a list of AiiDA data as the input for [structure0, structure1, ...]Because AiiDA does not support a list of AiiDA data as input, internally, we can change it to a dict with keys, the keys keep the order information. {"sequence_0": structure0, ...}and then, in the WorkGraph engine, if the sequence is a dict, we get the AiiDA data directly without serialization. |
|
Thanks @superstar54 applied your suggestion. The test pass, but it does not test the other use cases you mentioned. I tried to implement a dictionary, but it is a bit opaque to me how to change the iterator to be compatible with dictionaries that use hashable keys. It seems the iterator is hard coded to only work for collections that can be accessed by incremental increasing numbers like lists. Maybe we should generalize this for arbitrary generators. Not sure if this PR is the right place. |
becb66a to
a4d8ab5
Compare
superstar54
left a comment
There was a problem hiding this comment.
Hi @agoscinski , thanks for the work!
Please test for the changes.
As mentioned in my previous comment, if you use a list of orm.data as the sequence, it will raise an error, because we need to change the list to a dict.
Therefore, you need also modify the aiida_workgraph.workgraph.WorkGraph to convert it into a dict. Then inside the engine, the sequence is a dict.
| @calcfunction | ||
| def __getitem__(sequence, count): | ||
| value = sequence[count.value] | ||
| # only convert value f not already orm type because sequence |
There was a problem hiding this comment.
| # only convert value f not already orm type because sequence | |
| # only convert value if not already orm type because sequence |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #283 +/- ##
==========================================
+ Coverage 75.75% 80.70% +4.95%
==========================================
Files 70 66 -4
Lines 4615 5157 +542
==========================================
+ Hits 3496 4162 +666
+ Misses 1119 995 -124
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
The |


To track the provenance in the for loop we now use a calcfunction to track provenance for the
Forloop workgraph. I would like to allow more types than integers for the sequence, but I am not sure how to generically test for types that are supported by aiida core. Some orm types have a_typeclass attribute, but not all of them.TODO: