Ask Your Question
1

Unexpected auto-completer behavior when working with aiida

asked 2020-04-15 03:50:37 -0500

hongyi-zhao gravatar image

updated 2020-04-24 15:44:00 -0500

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

edit retag flag offensive 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 gravatar imageWingware Support ( 2020-04-15 10:10:50 -0500 )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 gravatar imagehongyi-zhao ( 2020-04-15 10:31:30 -0500 )edit

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

Wingware Support gravatar imageWingware Support ( 2020-04-15 10:35:19 -0500 )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 gravatar imagehongyi-zhao ( 2020-04-15 10:38:31 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-04-16 08:27:54 -0500

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!

edit flag offensive delete link more

Comments

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

Regards

hongyi-zhao gravatar imagehongyi-zhao ( 2020-04-21 20:31:08 -0500 )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 gravatar imageWingware Support ( 2020-04-24 15:43:46 -0500 )edit

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

hongyi-zhao gravatar imagehongyi-zhao ( 2020-04-24 18:35:36 -0500 )edit

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

Wingware Support gravatar imageWingware Support ( 2020-04-27 07:55:46 -0500 )edit
0

answered 2020-04-16 04:11:22 -0500

hongyi-zhao gravatar image

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

edit flag offensive delete link more

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 gravatar imageWingware Support ( 2020-04-16 08:14:24 -0500 )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 gravatar imagehongyi-zhao ( 2020-04-16 08:23:00 -0500 )edit

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

Wingware Support gravatar imageWingware Support ( 2020-04-16 08:25:50 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2020-04-15 03:50:37 -0500

Seen: 129 times

Last updated: Apr 16