Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.

Home Page:https://www.ibm.com/quantum/qiskit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

module 'qiskit' has no attribute '_accelerate' when running with accelerated numpy

tinaoberoi opened this issue · comments

Environment

  • Qiskit version: 1.0.1
  • Python version: 3.10
  • system: Google colab

What is happening?

I am using cupy and accelerarted numpy to improve performance of some code. When using cupy and numpy alsong with qiskit libraries the installation gives qiskit._accelerate not found error.

----------------------------------
AttributeError                            Traceback (most recent call last)
[<ipython-input-9-50bfb866a323>](https://localhost:8080/#) in <cell line: 6>()
      4 
      5 from lattice import ZigzagSquareLattice, SquareLattice
----> 6 from hamiltonian import SkyrmionHamiltonian
      7 # from ansatz import SkyrmionAnsatz

1 frames
[/content/quantum-skyrmion-simulation/./src/hamiltonian.py](https://localhost:8080/#) in <module>
      4 import subprocess
      5 from lattice import Lattice
----> 6 from qiskit.quantum_info import SparsePauliOp
      7 from qiskit_algorithms import NumPyMinimumEigensolver
      8 

[/usr/local/lib/python3.10/dist-packages/qiskit/__init__.py](https://localhost:8080/#) in <module>
     53 # We manually define them on import so people can directly import qiskit._accelerate.* submodules
     54 # and not have to rely on attribute access.  No action needed for top-level extension packages.
---> 55 sys.modules["qiskit._accelerate.nlayout"] = qiskit._accelerate.nlayout
     56 sys.modules["qiskit._accelerate.stochastic_swap"] = qiskit._accelerate.stochastic_swap
     57 sys.modules["qiskit._accelerate.sabre_swap"] = qiskit._accelerate.sabre_swap

AttributeError: partially initialized module 'qiskit' has no attribute '_accelerate' (most likely due to a circular import)

This issue fixes itself sometimes when I restart the kernel and it is fixed. I also tried to use 0.46 qiskit version but same issue. The code works fine if I dont use accelerated numpy/cupy.

How can we reproduce the issue?

Installations

sudo apt-get install numpy libopenblas-dev
pip install cupy-cuda12x
pip install qiskit==0.46.1
pip install qiskit_algorithms==0.3.0

Use qiskit imports

What should happen?

The imports should happen without error.

Any suggestions?

No response

Please can you give more detail about what precisely you've run in a clean Colab session, both to install additional packages (both pip and the system package manager) and then try to produce a minimal reproducer of a failure that doesn't involve any of the additional packages you've got?

Fwiw, if the cupy installation is changing anything about what happens when you import numpy or any of the internal objects, then it's quite likely that Qiskit simply isn't compatible with that - we use Numpy's C API, so if anything is messing with Numpy internals, we could very quickly be getting out of sync.