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

ImportWarning when grabbing a FakeBackend #8853

Closed
nonhermitian opened this issue Oct 8, 2022 · 7 comments · Fixed by #9078
Closed

ImportWarning when grabbing a FakeBackend #8853

nonhermitian opened this issue Oct 8, 2022 · 7 comments · Fixed by #9078
Assignees
Labels
bug Something isn't working

Comments

@nonhermitian
Copy link
Contributor

nonhermitian commented Oct 8, 2022

Environment

  • Qiskit Terra version: 0.22rc1
  • Python version:
  • Operating system: Ubuntu 22.04

What is happening?

from qiskit.providers.fake_provider import FakeMumbai
import mthree

backend = FakeMumbai()

gives

<frozen importlib._bootstrap>:671: ImportWarning: QiskitLoader.exec_module() not found; falling back to load_module()

How can we reproduce the issue?

Run the above

What should happen?

no warnings

Any suggestions?

No response

@nonhermitian nonhermitian added the bug Something isn't working label Oct 8, 2022
@jakelishman
Copy link
Member

What version of Python?

@mtreinish
Copy link
Member

It's interesting because that code hasn't changed since 0.21.x, and I've never seen the warning. But reading the python docs on Loader the load_module() method I used to implement the import redirect for aer has been deprecated since 3.4 and exec_module() is the recommended path forward: https://docs.python.org/3/library/importlib.html#importlib.abc.Loader

I'll take a look into this and see if I can adapt how we're using load_module() to the newer interface.

@mtreinish mtreinish self-assigned this Oct 8, 2022
@nonhermitian
Copy link
Contributor Author

3.10.5

@nonhermitian
Copy link
Contributor Author

nonhermitian commented Oct 8, 2022

Oddly enough it only happens if I first import mthree before grabbing the backend. I updated the issue.

@nonhermitian
Copy link
Contributor Author

But if I explicitly import AerSimulator before calling mthree there is no error again:

from qiskit_aer import AerSimulator

import mthree

fixes it

@nonhermitian
Copy link
Contributor Author

So it looks like it boils down to grabbing Cython extensions and then the FakeBackend. Ie this causes it:

from qiskit.providers.fake_provider import FakeHanoi
from mthree.matrix import _reduced_cal_matrix
backend = FakeHanoi()

@jakelishman
Copy link
Member

jakelishman commented Oct 9, 2022

We do some trickery in Terra to make qiskit.providers.aer import paths work now that Aer doesn't inject itself into the namespace. If the first time a given module is seen is with the qiskit.providers.aer name it will trigger an import warning due to the deprecated code Matthew's accidentally used, as shown above. If the first time we see it is as qiskit_aer, then we we do see a qiskit.providers.aer name, the loader short-circuit returns the imported module without triggering the deprecated code.

The solution is what Matthew had above - we should be using exec_module rather than load_module, and it's fixable within Terra.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants