python - 属性错误 : 'QuantumCircuit' object has no attribute 'config'

标签 python qiskit

我正在为 Qiskit 开发一个程序,但是当我尝试模拟电路时出现了一个奇怪的错误(我过去没有遇到过)。这是产生错误的最小示例:

from qiskit.circuit import QuantumCircuit
from qiskit import Aer,transpile

c = QuantumCircuit(2)
simulator = Aer.get_backend('qasm_simulator')
c = transpile(c, simulator)
result = simulator.run(c).result()
plot_histogram(counts, title='Counts')

我得到的错误是:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-89904ecd5f8e> in <module>()
      5 simulator = Aer.get_backend('qasm_simulator')
      6 c = transpile(c, simulator)
----> 7 result = simulator.run(c).result()
      8 plot_histogram(counts, title='Counts')

/Users/d/anaconda3/envs/qiskit/lib/python3.7/site-packages/qiskit/providers/aer/backends/aerbackend.py in run(self, qobj, backend_options, validate, **run_options)
    146         # Add backend options to the Job qobj
    147         qobj = self._format_qobj(
--> 148             qobj, backend_options=backend_options, **run_options)
    149 
    150         # Optional validation

/Users/d/anaconda3/envs/qiskit/lib/python3.7/site-packages/qiskit/providers/aer/backends/aerbackend.py in _format_qobj(self, qobj, backend_options, **run_options)
    353         """Return execution sim config dict from backend options."""
    354         # Add options to qobj config overriding any existing fields
--> 355         config = qobj.config
    356 
    357         # Add options

AttributeError: 'QuantumCircuit' object has no attribute 'config'

有谁知道是什么导致了这个错误?

谢谢!

最佳答案

我相信您需要在运行之前在 qobj 中组装转译电路:

from qiskit.compiler import assemble
my_qobj = assemble(c)
result = simulator.run(my_qobj).result()

顺便说一下,如果没有任何度量,plot_histogram(result.get_counts()) 也会返回错误。

还有一个特殊的平台,量子计算,https://quantumcomputing.stackexchange.com , 请随时在此处发布有关 QC&co 的任何其他问题:)

关于python - 属性错误 : 'QuantumCircuit' object has no attribute 'config' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67362847/

相关文章:

python - 如何在 Python 中为图形使用多种背景颜色?

python - 如何根据条件合并两个数据集

python - Python中的通配符匹配

python - 资源警告 : unclosed file <_io. BufferedReader 名称=4>

python - 在 MacOS HighSierra 上安装 qiskit 错误 : No such file or directory: 'qiskit.egg-info'

qiskit - 如何更改 backend.run() 命令?

Python - 将内置函数与创建的函数联系起来

python - 如何在 Qiskit 中对量子位观察进行建模

quantum-computing - 如何制作一个根据参数生成 |0> 或 |1> 的门?