aiida-core icon indicating copy to clipboard operation
aiida-core copied to clipboard

📋 List to keep track of counter-intuitive API behaviour

Open mbercx opened this issue 1 year ago • 0 comments

Often I'm exploring a class or some methods I'm not super familiar with, and encounter some counter-intuitive (at least to my intuition 🙃) behaviour. Typically I would just say: "huh", and move on, but in the interest of discussing improving the API I wanted to report these moments of confusion. I could make a separate issue for each, but I figured it was more organised to keep track of them in one issue.

Note: I'm not necessarily arguing that the API should be changed in each case. I'm purposely not going to investigate each occurrence in too much detail to avoid the barrier to reporting them becoming so big it just doesn't happen. Even if we decide not to change the behaviour, it might be good to document somewhere why not.


Group.collection.get

I was using the Group.collection.get_or_create() method in one of my scripts, but in the end found it's silent behaviour of creating non-existent groups too dangerous in the context. So I decided to switch to using get instead, but apparently the API doesn't work that way:

wc_group = orm.Group.collection.get('existing-group-label')

Results in a TypeError:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
 in 
     18 # wc_group = orm.Group.collection.get(f'workchains[/kconv/](https://vscode-remote+ssh-002dremote-002baiida-002dmarvel.vscode-resource.vscode-cdn.net/kconv/){magnetism[0]}')
     19 # wc_group, _ = orm.load_group()
---> 20 wc_group = orm.Group.collection.get('existing-group-label')

TypeError: get() takes 1 positional argument but 2 were given

Apparently you have to pass filters as keyword arguments instead, e.g. label:

orm.Group.collection.get(label='existing-group-label')

Set automatically stored as list

In [1]: n = Int(2)

In [2]: n.base.extras.set('set', set([1, 2, 3]))

In [3]: n.extras['set']
Out[3]: {1, 2, 3}

In [4]: n.store()
Out[4]: <Int: uuid: a8cd9881-bda4-4fe8-a175-76cf21a26145 (pk: 532115) value: 2>

In [5]: n.extras['set']
Out[5]: [1, 2, 3]

In [6]: type(n.extras['set'])
Out[6]: list

node.extras silently immutable

Continuing from above

In [8]: n.extras['set'].append(4)

In [9]: n.extras['set']
Out[9]: [1, 2, 3]

verdi code setup accepts non-existing plugins

While setting up the code for aiida-phonopy, there was a typo in the instructions:

(qe) marnikbercx@Marniks-MacBook-Pro aiida-phonopy % verdi code create core.code.installed -n --computer localhost --label phonopy --default-calc-job-plugin phoonpy.phonopy --filepath-executable $(which
 phonopy)
Success: Created InstalledCode<1>

However, the installation passed without complaint:

(qe) marnikbercx@Marniks-MacBook-Pro aiida-phonopy % verdi code show phonopy
-----------------------  ----------------------------------------------
PK                       1
UUID                     e39a0d22-34f8-4347-959c-d1b70ad93c15
Type                     core.code.installed
Computer                 localhost (localhost), pk: 4
Filepath executable      /Users/marnikbercx/.virtualenvs/qe/bin/phonopy
Label                    phonopy
Description
Default calc job plugin  phoonpy.phonopy
Use double quotes        False
With mpi
Prepend text
Append text
-----------------------  ----------------------------------------------

Not sure if this is desired behaviour.

Edge projections always come after regular ones

TODO - just so I don't forget to describe this.

mbercx avatar Apr 23 '23 15:04 mbercx