我是量子计算的新手,正在尝试编写一个 2bit Cuccaro et all adder,如下所述: https://arxiv.org/pdf/quant-ph/0410184.pdf和这里:https : //arxiv.org/ pdf/1202.6614.pdf。(我从完整用户指南中获得了链接)。
我收效甚微,希望有人能指出我错误的根本原因。我唯一真正的怀疑是,我需要添加一些隐含的空闲门,这些门在论文中没有提到。
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])