QISKIT 错误 - numpy.ndarray 大小已更改,可能表示二进制不兼容。预期来自 C header 的 88,来自 PyObject 的 80

QISKIT error - numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

我运行这个

from qiskit import QuantumCircuit, execute, Aer
from qiskit.visualization import plot_histogram

并得到以下错误

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-07258f5373b7> in <module>
----> 1 from qiskit import QuantumCircuit, execute, Aer
      2 from qiskit.visualization import plot_histogram

~\AppData\Roaming\Python\Python37\site-packages\qiskit\__init__.py in <module>
     55 # Try to import the Aer provider if installed.
     56 try:
---> 57     from qiskit.providers.aer import Aer
     58 except ImportError:
     59     suppress_warnings = os.environ.get('QISKIT_SUPPRESS_PACKAGING_WARNINGS', '')

~\AppData\Roaming\Python\Python37\site-packages\qiskit\providers\aer\__init__.py in <module>
     62 
     63 # pylint: disable=wrong-import-position
---> 64 from .aerprovider import AerProvider
     65 from .aerjob import AerJob
     66 from .aererror import AerError

~\AppData\Roaming\Python\Python37\site-packages\qiskit\providers\aer\aerprovider.py in <module>
     21 from .backends.statevector_simulator import StatevectorSimulator
     22 from .backends.unitary_simulator import UnitarySimulator
---> 23 from .backends.pulse_simulator import PulseSimulator
     24 
     25 

~\AppData\Roaming\Python\Python37\site-packages\qiskit\providers\aer\backends\__init__.py in <module>
     18 from .statevector_simulator import StatevectorSimulator
     19 from .unitary_simulator import UnitarySimulator
---> 20 from .pulse_simulator import PulseSimulator

~\AppData\Roaming\Python\Python37\site-packages\qiskit\providers\aer\backends\pulse_simulator.py in <module>
     24 from ..version import __version__
     25 from ..aererror import AerError
---> 26 from ..pulse.controllers.pulse_controller import pulse_controller
     27 from ..pulse.system_models.pulse_system_model import PulseSystemModel
     28 from .aerbackend import AerBackend

~\AppData\Roaming\Python\Python37\site-packages\qiskit\providers\aer\pulse\__init__.py in <module>
     50 from .qutip_extra_lite.cy import pyxbuilder as pbldr
     51 
---> 52 from .system_models.duffing_model_generators import duffing_system_model
     53 from .system_models.pulse_system_model import PulseSystemModel
     54 

~\AppData\Roaming\Python\Python37\site-packages\qiskit\providers\aer\pulse\system_models\duffing_model_generators.py in <module>
     19 from collections.abc import Iterable
     20 from qiskit.providers.models.backendconfiguration import UchannelLO
---> 21 from .hamiltonian_model import HamiltonianModel
     22 from .pulse_system_model import PulseSystemModel
     23 

~\AppData\Roaming\Python\Python37\site-packages\qiskit\providers\aer\pulse\system_models\hamiltonian_model.py in <module>
     20 import numpy.linalg as la
     21 from ...aererror import AerError
---> 22 from .string_model_parser.string_model_parser import HamiltonianParser
     23 
     24 

~\AppData\Roaming\Python\Python37\site-packages\qiskit\providers\aer\pulse\system_models\string_model_parser\string_model_parser.py in <module>
     21 import numpy as np
     22 from .apply_str_func_to_qobj import apply_func
---> 23 from .qobj_from_string import gen_oper
     24 
     25 

~\AppData\Roaming\Python\Python37\site-packages\qiskit\providers\aer\pulse\system_models\string_model_parser\qobj_from_string.py in <module>
     16 """Module for creating quantum operators."""
     17 
---> 18 from ...qutip_extra_lite import qobj_generators
     19 
     20 

~\AppData\Roaming\Python\Python37\site-packages\qiskit\providers\aer\pulse\qutip_extra_lite\qobj_generators.py in <module>
     17 
     18 import numpy as np
---> 19 from . import operators as ops
     20 from . import states as st
     21 from . import tensor as ten

~\AppData\Roaming\Python\Python37\site-packages\qiskit\providers\aer\pulse\qutip_extra_lite\operators.py in <module>
     54 
     55 import numpy as np
---> 56 from .fastsparse import fast_csr_matrix, fast_identity
     57 from .qobj import Qobj
     58 

~\AppData\Roaming\Python\Python37\site-packages\qiskit\providers\aer\pulse\qutip_extra_lite\fastsparse.py in <module>
    438 # -------------------------------------
    439 # pylint: disable=no-name-in-module, wrong-import-position, import-error
--> 440 from .cy.spmath import (zcsr_transpose, zcsr_adjoint, zcsr_mult)

spmath.pyx in init qiskit.providers.aer.pulse.qutip_extra_lite.cy.spmath()

ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

有什么想法吗?

我安装了numpy 1.16/1.17和最新的,还是一样的错误。
python - 3.7.9 我 运行 ML 项目所以版本很重要

看来你的安装有问题。您是否尝试重新安装?

pip install --ignore-installed qiskit-terra qiskit-aer

这是因为最新的Qiskit Aer(0.7.4,Qiskit meta 0.23.5)是用numpy 1.20.0编译的,与旧版本的numpy不兼容。请参阅此问题:https://github.com/Qiskit/qiskit-aer/issues/1120 了解更多详情。

目前的解决方法是将您的 numpy 升级到 1.20.0。