我正在使用 IBM Q experience 的 jupyter notebook 在 Qiskit 上运行以下代码,代码如下:
%matplotlib inline
# Importing standard Qiskit libraries and configuring account
from qiskit import QuantumCircuit, execute, Aer, IBMQ,QuantumRegister,ClassicalRegister
from qiskit.compiler import transpile, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import *
# Loading your IBM Q account(s)
provider = IBMQ.load_account()
simulator=Aer.get_backend('qasm_simulator')
qi=QuantumRegister(6)
qx=QuantumRegister(6)
qb=QuantumRegister(3)
qo=QuantumRegister(5)
qe=QuantumRegister(5)
v=QuantumRegister(1)
qd=QuantumRegister(3)
c=ClassicalRegister(9)
circuit=QuantumCircuit(qi,qx,qb,qe,qd,qo,v,c)
def fun_or(qc,q0,q1,q2):
qc.x(q0)
qc.x(q1)
qc.ccx(q0,q1,q2)
qc.x(q2)
qc.x(q1)
qc.x(q0)
def fun_and (qc,q0, q1, q2):
qc.ccx( q0, q1, q2)
def fun_nand (qc,q0, q1, q2):
fun_and(qc,q0,q1,q2)
qc.x(q2)
def or3 (qc,q0, q1, q2, b, q3):
fun_or(qc,q0, q1, b)
fun_or(qc,b,q2,q3)
qc.reset(b)
def or4 (qc,q0, q1, q2,q3, b1,b2,q4):
or3(qc,q0, q1, q2,b1,b2)
fun_or(qc,b2,q3,q4)
qc.reset(b1)
qc.reset(b2)
def or5 (qc,q0, q1, q2,q3,q4 ,b1,b2,b3,q5):
or4(qc,q0, q1, q2,q3,b1,b2,b3)
fun_or(qc,b3,q4,q5)
qc.reset(b1)
qc.reset(b2)
qc.reset(b3)
def and3 (qc,q0, q1, q2, b, q3):
fun_and(qc,q0,q1,b)
fun_and(qc,b, q2, q3)
qc.reset(b)
def and4 (qc,q0, q1, q2,q3, b1,b2, q4):
and3(qc,q0,q1,q2,b1,b2)
fun_and(qc,b2, q3, q4)
qc.reset(b1)
qc.reset(b2)
def and5 (qc,q0, q1, q2,q3,q4, b1,b2,b3, q5):
and4(qc,q0,q1,q2,q3,b1,b2,b3)
fun_and(qc,b3, q4, q5)
qc.reset(b1)
qc.reset(b2)
qc.reset(b3)
#give inputs below
#give inputs above
for i in range (0,6):
circuit.cx(qi[i],qx[i])
circuit.x(qx[i])
# Bit one of digit
and3(circuit,qx[0],qx[1],qx[2],qb[0],qe[0])
and4(circuit,qx[0],qx[1],qx[3],qx[4],qb[0],qb[1],qe[1])
and4(circuit,qx[0],qx[2],qx[3],qi[5],qb[0],qb[1],qe[2])
and4(circuit,qx[2],qx[1],qx[3],qi[5],qb[0],qb[1],qe[3])
and4(circuit,qx[1],qx[2],qi[5],qx[4],qb[0],qb[1],qe[4])
and4(circuit,qx[0],qx[2],qi[5],qx[3],qb[0],qb[1],qo[0])
and4(circuit,qx[2],qx[1],qx[3],qi[4],qb[0],qb[1],qo[1])
and5(circuit,qx[1],qx[2],qx[5],qx[4],qi[3],qb[0],qb[1],qb[2],qo[2])
and5(circuit,qx[0],qi[2],qi[5],qi[4],qi[3],qb[0],qb[1],qb[2],qo[3])
and5(circuit,qx[0],qi[2],qx[5],qi[4],qx[3],qb[0],qb[1],qb[2],v[0])
fun_and(circuit,v[0],qi[1],qo[4])
circuit.reset(v)
or5(circuit,qe[0],qe[1],qe[2],qe[3],qe[4],qb[0],qb[1],qb[2],v[0])
circuit.reset(qe)
or5(circuit,qo[0],qo[1],qo[2],qo[3],qo[4],qb[0],qb[1],qb[2],qe[0])
circuit.reset(qo)
fun_or(circuit,qe[0],v[0],qd[2])
circuit.measure(qd[2],c[2])
##############
#Second bit
and4(circuit,qx[0],qi[1],qx[2],qx[5],qb[0],qb[1],qe[0])
and4(circuit,qx[0],qi[1],qx[4],qx[5],qb[0],qb[1],qe[1])
and5(circuit,qx[0],qx[1],qi[2],qi[5],qx[4],qb[0],qb[1],qb[2],qe[2])
and4(circuit,qx[0],qi[1],qi[3],qx[5],qb[0],qb[1],qe[3])
and5(circuit,qx[0],qi[1],qx[2],qi[3],qi[4],qb[0],qb[1],qb[2],qe[4])
and5(circuit,qx[0],qx[1],qi[2],qx[5],qi[4],qb[0],qb[1],qb[2],qo[0])
fun_and(circuit,qo[0],qx[3],qo[1])
and5(circuit,qx[0],qi[1],qi[2],qi[5],qi[4],qb[0],qb[1],qb[2],qo[2])
fun_and(circuit,qo[2],qx[3],qd[1])
circuit.measure(qd[1],c[1])
circuit.reset(qe)
circuit.reset(qo)
#########
#Third Bit
and3(circuit,qx[0],qx[1],qx[2],qb[0],qe[0])
and3(circuit,qx[0],qx[1],qx[4],qb[0],qe[1])
and3(circuit,qx[0],qx[4],qx[5],qb[0],qe[2])
and4(circuit,qx[1],qx[2],qx[4],qx[5],qb[0],qb[1],qe[3])
and4(circuit,qx[0],qi[2],qi[3],qx[4],qb[0],qb[1],qe[4])
and5(circuit,qx[0],qi[2],qi[3],qi[4],qi[5],qb[0],qb[1],qb[2],qo[0])
or5(circuit,qe[0],qe[1],qe[2],qe[3],qe[4],qb[0],qb[1],qb[2],qo[1])
fun_or(circuit,qo[1],qo[0],qd[0])
circuit.measure(qd[0],c[0])
#####################################
#circuit.measure(qi[0],c[0])
#circuit.measure(qi[1],c[1])
#circuit.measure(qi[2],c[2])
######################################
job = execute(circuit, simulator, shots=100)
print('#')
print(job.result())
result=job.result()
print('##')
counts = result.get_counts(circuit)
print('###')
circuit.draw()
print('111!!')
print("\nTotal count ",counts)
我正在使用 IBM 的 Quantum Experience 的 Jupyter 笔记本。每当我点击运行时,程序都会运行几分钟,然后出现一个对话框,说内核死了。我不知道是什么原因造成的,也许代码对于 qiskit 来说太多了?请帮忙!