AttributeError: 'QuantumCircuit' object has no attribute 'config'
AttributeError: 'QuantumCircuit' object has no attribute 'config'
我正在为 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'
有谁知道导致此错误的原因吗?
谢谢!
我相信你需要在 运行 之前 assemble qobj 中的转译电路 :
from qiskit.compiler import assemble
my_qobj = assemble(c)
result = simulator.run(my_qobj).result()
顺便说一下,如果没有任何措施,plot_histogram(result.get_counts())
也会return 出错。
还有一个特殊的平台 Quantum Computing,https://quantumcomputing.stackexchange.com,如有任何关于 QC&co 的其他问题,请随时post :)
我正在为 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'
有谁知道导致此错误的原因吗?
谢谢!
我相信你需要在 运行 之前 assemble qobj 中的转译电路 :
from qiskit.compiler import assemble
my_qobj = assemble(c)
result = simulator.run(my_qobj).result()
顺便说一下,如果没有任何措施,plot_histogram(result.get_counts())
也会return 出错。
还有一个特殊的平台 Quantum Computing,https://quantumcomputing.stackexchange.com,如有任何关于 QC&co 的其他问题,请随时post :)