I am attempting to implement the adder found in this paper.

fourier adder circuit

Here is the code:

#build the phi adder circuit
#controlled phase gates are .cp() def phi_add(num_bits):
    qc = QuantumCircuit(2*num_bits,num_bits)
    #initialize a register
    #initialize b register
    #append Fourier transform to second register
    #append phase addition gates
    for k in range(num_bits):
        for j in range(num_bits-k):
    #append inverse Fourier transform to second register
    qc.measure(range(num_bits,2*num_bits), range(num_bits))
    return qc

Resulting in this diagram:

Fourier adder circuit diagram

Which yields results that don't look very good:

Aer simulation results

EDIT: I found qiskit.circuit.library.DraperQFTAdder, which implements it but I still can't see where I went wrong.


3 Answers 3


The main issue is how you are using QFT. do_swaps should be false. And sice its default value is true, you will need to pass it explicitly:

QFT(num_qubits=4, do_swaps=False)


QFT(num_qubits=4, do_swaps=False, inverse=True)

Note also that, since the two registers have same size and the second register contains all 1s, the output will always be the value in the first register minus one.

  • $\begingroup$ Thank you, I was aware of the option but didn't understand why it'd need to be off. Works perfectly now. $\endgroup$ Commented Oct 5, 2023 at 19:33

You can take a look at how to create an adder whether it is a QFT or a ripple-carry, using the answer here

You also need a compiler that interprets the order of the qubits correctly; you can see how it is done here (you have to enforce the classiq compiler to use QFT as other implementations might be more efficient)

If it is important to you to have the qiskit implementation of the adder, you can use this command to get the QASM:


And then convert to an object according to this answer


Based on a bit of code experimentation, the order in which you target qubits depending on k is wrong: if you target the lines in the circuit from top to bottom as k increases, you'll get the circuit as it is presented in the paper, and the answer on the basis states will be a basis state as well. (You can do that by changing your code to use target_qubit=num_bits+k.)

  • $\begingroup$ I think this is notational. For me, πœ™3β†”π‘ž7 ... πœ™0β†”π‘ž4 and π‘Ž0β†”π‘ž0 ... π‘Ž3β†”π‘ž3. $\endgroup$ Commented Oct 5, 2023 at 19:59

Your Answer

By clicking β€œPost Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.