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

📋 List to keep track of counter-intuitive API behaviour #5979

Open
mbercx opened this issue Apr 23, 2023 · 0 comments
Open

📋 List to keep track of counter-intuitive API behaviour #5979

mbercx opened this issue Apr 23, 2023 · 0 comments

Comments

@mbercx
Copy link
Member

mbercx commented Apr 23, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant