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

Posted

技术标签:

【中文标题】QISKIT 错误 - numpy.ndarray 大小已更改,可能表示二进制不兼容。预期来自 C 标头的 88,从 PyObject 获得 80【英文标题】:QISKIT error - numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject 【发布时间】:2021-05-17 11:17:28 【问题描述】:

我跑了这个

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 和最新的,还是一样的错误。 蟒蛇 - 3.7.9 我运行 ML 项目,所以版本至关重要

【问题讨论】:

您的 Qiskit 版本是多少?你可以从这里得到它们from qiskit import __qiskit_version__ @luciano 运行 import qiskit 版本时出现与上述相同的错误 【参考方案1】:

这是因为最新的 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。

【讨论】:

【参考方案2】:

您的安装似乎以某种方式损坏。您是否尝试重新安装?

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

【讨论】:

我得到了这个'错误:[pip 的依赖解析器当前没有考虑所有已安装的包。此行为是以下依赖冲突的根源。 tensorflow 2.4.1 需要 numpy~=1.19.2,但是你有 numpy 1.20.1 这是不兼容的。'] 但是运行 import qiskit 仍然给我上面的错误 好吧..你有。 qiskit 和 tensorflow 有冲突的依赖关系。您应该将它们安装在不同的 venvs 中。 我将 numpy 从 1.18 升级到 1.19.2 仍然是同样的错误。 ValueError: numpy.ndarray 大小已更改,可能表示二进制不兼容。预期来自 C 标头的 88,从 PyObject 获得 80 >>> import tensorflow as tf, numpy as np 2021-02-15 09:12:01.127018: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] 无法加载动态库“cudart64_110.dll”; dlerror: cudart64_110.dll not found 2021-02-15 09:12:01.127716: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] 如果您的机器上没有设置 GPU,请忽略上面的 cudart dlerror。 >>> print(tf.__version__, np.__version__) 2.4.1 1.19.2

以上是关于QISKIT 错误 - numpy.ndarray 大小已更改,可能表示二进制不兼容。预期来自 C 标头的 88,从 PyObject 获得 80的主要内容,如果未能解决你的问题,请参考以下文章

Numpy.ndarray 对象不可调用错误原因

属性错误:“numpy.ndarray”对象没有属性“value_counts”

错误:“numpy.ndarray”对象没有属性“iloc”

PyTorch - 获取 'TypeError: pic 应该是 PIL Image 或 ndarray。得到 <class 'numpy.ndarray'>' 错误

看到一条错误消息:“numpy.ndarray”对象没有属性“map”

Tensorflow DNNclassifier:错误训练(numpy.ndarray 没有属性索引)