以下代码引发错误。基于我在qiskit github上阅读的一些问题,似乎它与运行配置和编译配置有关,但是我找不到其他信息可以帮助我解决此问题。
from qiskit import QuantumCircuit, IBMQ, execute
from qiskit import BasicAer as Aer
from qiskit.providers.aer import noise
ckt = QuantumCircuit(2, 2)
ckt.h(0)
ckt.cx(0, 1)
ckt.measure(0, 0)
ckt.measure(1, 1)
qsim = Aer.get_backend("qasm_simulator")
IBMQ.load_account()
provider = IBMQ.get_provider(hub="ibm-q")
qc = provider.get_backend("ibmqx2")
props = qc.properties()
coupling_map = qc.configuration().coupling_map
noise_model = noise.device.basic_device_noise_model(props)
job = execute(
ckt,
qsim,
noise_model=noise_model,
coupling_map=coupling_map,
basis_gates=noise_model.basis_gates
)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-2f987d65d1f7> in <module>
25 noise_model=noise_model,
26 coupling_map=coupling_map,
---> 27 basis_gates=noise_model.basis_gates
28 )
~/.venvs/qk/lib/python3.7/site-packages/qiskit/execute.py in execute(experiments, backend, basis_gates, coupling_map, backend_properties, initial_layout, seed_transpiler, optimization_level, pass_manager, qobj_id, qobj_header, shots, memory, max_credits, seed_simulator, default_qubit_los, default_meas_los, schedule_los, meas_level, meas_return, memory_slots, memory_slot_size, rep_time, parameter_binds, **run_config)
220
221 # executing the circuits on the backend and returning the job
--> 222 return backend.run(qobj, **run_config)
TypeError: run() got an unexpected keyword argument 'noise_model'
答案 0 :(得分:0)
由于您正在使用BasicAer来检索模拟器后端,因此出现错误。我认为这不适用于BasicAer提供程序。您应该使用Aer提供程序。
from qiskit import Aer
qsim = Aer.get_backend('qasm_simulator')
如果仅从
更改导入语句from qiskit import BasicAer as Aer
到
from qiskit import Aer
然后您的代码应该可以使用