0

I'm new to quantum computing and am trying to codify a 2bit Cuccaro et all adder as described here: https://arxiv.org/pdf/quant-ph/0410184.pdf and here: https://arxiv.org/pdf/1202.6614.pdf. (I got the links from the Full Users Guide).

I am having little success and was hoping someone could point me to the root cause of my error. My only real suspicion is that there are implicit idle gates that I need to add that were not mentioned in the papers.

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])
kenorb
  • 155,785
  • 88
  • 678
  • 743
kaoao
  • 11
  • 4

1 Answers1

0

Figured it out! My syntax for CNOT's was inverted. Needed to open an example in Composer and see the QASM statements

kaoao
  • 11
  • 4