0
我是新來量子計算,並試圖編寫一個2位Cuccaro和所有加法器如下所述:https://arxiv.org/pdf/quant-ph/0410184.pdf和這裏:https://arxiv.org/pdf/1202.6614.pdf。 (我從完整用戶指南中獲得了鏈接)。QisKit Cuccaro加法器的實現
我收效甚微,希望有人能指出我錯誤的根源。我唯一真正懷疑的是,我需要補充一些沒有在論文中提到的隱含空閒門。
def _maj(circuit, cin, a, b):
circuit.cx(a, b)
circuit.cx(cin, b)
circuit.ccx(cin, a, b)
#2NOT uma
def _uma2(circuit, a, b, t):
circuit.ccx(a, b, t)
circuit.cx(a, t)
circuit.cx(b, a)
def _add2bit(circuit, a, b, cin, cout):
_maj(circuit, cin, a[0], b[0])
_maj(circuit, b[0], a[1], b[1])
circuit.cx(cout, b[1])
_uma2(circuit, b[0], a[1], b[1])
_uma2(circuit, cin, a[0], b[0])
def convert_num_to_regs(circuit, n_str, regs):
for i, v in enumerate(reversed(n_str)):
v = int(v)
if v == 1:
circuit.x(regs[i])
program = QuantumProgram()
qr = program.create_quantum_register("qr", 6)
cr = program.create_classical_register("cr", 3)
qc = program.create_circuit("adder", [qr], [cr])
#inputs
a = '01'
b = '01'
a_regs = []
b_regs = []
c_in = qr[0]
z = qr[5]
for i in range(2):
a_regs.append(qr[(2*i) + 1])
b_regs.append(qr[(2*i+1) + 1])
convert_num_to_regs(qc, a, a_regs)
convert_num_to_regs(qc, b, b_regs)
_add2bit(qc, a_regs, b_regs, c_in, z)
qc.measure(b_regs[0], cr[0])
qc.measure(b_regs[1], cr[1])
qc.measure(z, cr[2])