1

下面给出的是我在 jupyter notebook 上运行的代码,我为此项目在 IBM 上创建了帐户。请帮忙 !

import qiskit as q
import numpy as np
import matplotlib
%matplotlib inline

circuit = q.QuantumCircuit(2 , 2) # 2 qubit and 2 classical bits 
#currently: (0,0)
circuit.x(0)
#now : (1,0)
circuit.cx(0 , 1)  #cnot gate , controlled NOT gate , it flips 2nd bit if 1 quibit is 1
# now : (1 , 1)
circuit.measure([0,1],[0,1])  # map quibit to bits
circuit.draw(output="mpl")  # ascii of circuit

from qiskit import IBMQ
IBMQ.save_account('MY_TOKEN_NUMBER',overwrite=True)  #save your creds
IBMQ.load_account()
#got this as output to prev line of code :
# <AccountProvider for IBMQ(hub='ibm-q', group='open', project='main')>

provider = IBMQ.get_provider(q.providers.baseprovider)
4

1 回答 1

2

提供者从load_account()调用中返回,然后用于选择后端。通过将字符串传递给方法来选择后端provider.get_backend()。因此,我相信您需要的代码是:

provider = IBMQ.load_account()
backend = provider.get_backend('ibmq_qasm_simulator')

我建议您查看自述文件以获取有关如何加载帐户的更多信息。

此外,当您保存了您的帐户详细信息后,无需继续重新保存它们,您只需调用IBMQ.load_account().

于 2019-12-01T10:35:22.250 回答