First time here? Check out the FAQ!
1

Unexpected auto-completer behavior when working with aiida

Hi,

I use wing to test the aiida-core package with the code given here: https://aiida-tutorials.readthedocs.i.... The code snippets are the following:

from aiida import load_profile
load_profile()

from aiida.orm import Code, Computer, Data, Node, Float, Str
from aiida.plugins import CalculationFactory, DataFactory
from aiida.engine import calcfunction

In the above code, the calcfunction only exists in aiida.engine, so it should be imported like this:

from aiida.engine import calcfunction

But when I type the following:

from aiida.orm import c<tab>

then the auto-completer of wing will still suggest the name of calcfunction as one of the candidates, which if I selected and input there, the code will be error and finally fail to run.

Any hints for this problem?

Regards

hongyi-zhao's avatar
547
hongyi-zhao
asked 2020-04-15 03:50:37 -0600
Wingware Support's avatar
4.2k
Wingware Support
updated 2020-07-16 10:17:54 -0600
edit flag offensive 0 remove flag close merge delete

Comments

What happens if you complete the completion and do goto-definition on calcfunction on the 'from aiida.orm import' line? This might be a result of orm importing calcfunction internally in some way, or the symbol being listed in a *.pyi file if there are any, but then having other import behavior at runtime. Looking at where Wing ends up after goto-definition is the first step to figuring this out.

Wingware Support's avatar Wingware Support (2020-04-15 10:10:50 -0600) edit

Both of the two imports will skip to the same location here: https://github.com/aiidateam/aiida-co...

Another differences I noted that is when importing by 'from aiida.orm import' the result of the completion will becomes 'calcfunction(function)', while the completion result for the 'from aiida.engine import' line is 'calcfunction'.

Still cannot figure out the reason.

Regards

hongyi-zhao's avatar hongyi-zhao (2020-04-15 10:31:30 -0600) edit

What is the code error when you try to run it? I'm guessing maybe a circular import problem.

Wingware Support's avatar Wingware Support (2020-04-15 10:35:19 -0600) edit

See the following:

  File "/home/werner/create_rescale.py", line 18, in <module>
    from aiida.orm import Code, Computer, Data, Node, Float, Str, load_node, calcfunction

builtins.ImportError: cannot import name 'calcfunction'
hongyi-zhao's avatar hongyi-zhao (2020-04-15 10:38:31 -0600) edit
add a comment see more comments

2 Answers

0

See here for the further analysis on this problem. I excerpted them from there for your info:

Dear Hongyi,

Let me add the reason why 'calcfunction' is not imported in the way described in the linked post:

In the import

orm/nodes/process/__init__.py has from .calculation import *

the calcfunction module is imported into orm/nodes/process/calculation/__init__.py, but that file also defines an attribute

__all__ = ('CalculationNode', 'CalcFunctionNode', 'CalcJobNode')

Because a wildcard (from something import *) import will import only the names defined in __all__, the "calcfunction" module is not exposed at the level of orm/nodes/process/__init__.py.

Maybe this explanation will help in figuring out what goes wrong with the autocompletion.

Best regards,

Dominik

hongyi-zhao's avatar
547
hongyi-zhao
answered 2020-04-16 04:11:22 -0600
edit flag offensive 0 remove flag delete link

Comments

Thanks. I suspect that the issue is that Wing is not understanding the __all__ in orm/nodes/process/__init__.py which reads: __all__ = (calculation.__all__ + process.__all__ + workflow.__all__)

Wingware Support's avatar Wingware Support (2020-04-16 08:14:24 -0600) edit

If that is the normal way understood by python, Wing should try to understand it. Anyway, I stay tuned from your news on the fix for this problem.

Regards

hongyi-zhao's avatar hongyi-zhao (2020-04-16 08:23:00 -0600) edit

Yup, that's it. Sorry I missed this in my earlier analysis!

Wingware Support's avatar Wingware Support (2020-04-16 08:25:50 -0600) edit
add a comment see more comments
0

I've removed my earlier incorrect answer and have tagged this a bug report. It's due to Wing not understanding the __all__ in orm/nodes/process/__init__.py which reads: __all__ = (calculation.__all__ + process.__all__ + workflow.__all__)

We'll try to fix this soon. Thanks for reporting this and noticing that our earlier analysis was incorrect!

Wingware Support's avatar
4.2k
Wingware Support
answered 2020-04-16 08:27:54 -0600
edit flag offensive 0 remove flag delete link

Comments

I tried the latest 7.2.2.4, it still has this problem.

Regards

hongyi-zhao's avatar hongyi-zhao (2020-04-21 20:31:08 -0600) edit

It's not fixed in 7.2.2.4. Will be fixed in 7.2.3+ (but also not 7.2.2.5 or other 7.2.2.* updates)

Wingware Support's avatar Wingware Support (2020-04-24 15:43:46 -0600) edit

Very glad to know this good news, when will 7.2.3+ be released?

hongyi-zhao's avatar hongyi-zhao (2020-04-24 18:35:36 -0600) edit

Not certain yet but likely in the next week or two.

Wingware Support's avatar Wingware Support (2020-04-27 07:55:46 -0600) edit

This ended up being a huge can of worms and the fix is instead pushed into Wing 8 because we felt these changes needed to go through a longer testing process. The first alpha of that should be out later today. Sorry for the long delays on this; more complex than we thought.

Wingware Support's avatar Wingware Support (2020-07-15 07:54:48 -0600) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer