I have written a simple projectq code with 8qbits in order to perform full addition but it gets stuck somewhere between without generating any error message. It worked fine for 4 qbits.
def full_adder(eng,x,y,length,s,cin,cout):
aux = eng.allocate_qureg(4)
print("Going into loop to perform operations \n")
for i in range(length):
Toffoli | (x[i], y[i], aux[1])
CNOT | (x[i], s[i])
CNOT | (y[i], s[i])
Toffoli | (cin, s[i], aux[0])
CNOT | (cin, s[i])
CNOT | (aux[0], aux[2])
CNOT | (aux[1], aux[2])
Toffoli | (aux[0], aux[1], aux[3])
CNOT | (aux[2], cout)
CNOT | (aux[3], cout)
print("Addition completed going out of the loop \n")
def main(eng):
x = eng.allocate_qureg(8) # first
y = eng.allocate_qureg(8) # second
s = eng.allocate_qureg(8) # sum
cout = eng.allocate_qureg(1) # carry out
cin = eng.allocate_qureg(1) # carry in
length=8
input1=0xab
input2=0x12
Round_constant_XOR(eng,x,input1,length)
Round_constant_XOR(eng,y,input2,length)
print("About to start Addition \n")
full_adder(eng,x,y,length,s,cin,cout)
print("Addition Completed, printing results \n")
print_state(eng,s,length)
Simulate = MainEngine()
main(Simulate)
Simulate.flush()
Below is the output
(Note: This is the (slow) Python simulator.)
About to start Addition
Going into loop to perform operations
Addition completed going out of the loop
Once it gets out of the full_adder function, it gets stuck, and nothing happens after this.