Problems with Implementation of Draper Adder

n_bits = 3

dev = qml.device('default.qubit', wires = n_bits*2, shots = 10)
def main():
  #qml.QFT(wires = range(n_bits,n_bits*2))
  for i in range(n_bits,n_bits*2):
  for i in reversed(range(1,n_bits+1)):
    k = 1
    for j in reversed(range(1,i+1)):
      qml.ControlledPhaseShift(np.pi*2/(2**(k)), [n_bits-j,n_bits*2-i])
  qml.adjoint(qml.QFT)(wires = range(n_bits,n_bits*2))
  return qml.sample(wires=range(n_bits,n_bits*2))

res= main(3,2)
draw = qml.draw(main)(2,3)

I am working on implementing a Draper Adder in Pennylane and I am having issues. The circuit I have created seems identical to the one in the paper, but I am not getting the correct output. I believe I should get qml.sample to return |010> every time, but I am getting very mixed values. If either register was not classically representing the values, I would understand the problem but I’m not sure what is going on here. Anything would help!

My qml.about():
Name: PennyLane
Version: 0.35.1
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: GitHub - PennyLaneAI/pennylane: PennyLane is a cross-platform Python library for differentiable programming of quantum computers. Train a quantum computer the same way as a neural network.
License: Apache License 2.0
Location: /usr/local/lib/python3.10/dist-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane_Lightning

Platform info: Linux-6.1.58±x86_64-with-glibc2.35
Python version: 3.10.12
Numpy version: 1.25.2
Scipy version: 1.11.4
Installed devices:

  • default.clifford (PennyLane-0.35.1)
  • default.gaussian (PennyLane-0.35.1)
  • default.mixed (PennyLane-0.35.1)
  • default.qubit (PennyLane-0.35.1)
  • default.qubit.autograd (PennyLane-0.35.1)
  • default.qubit.jax (PennyLane-0.35.1)
  • default.qubit.legacy (PennyLane-0.35.1)
  • (PennyLane-0.35.1)
  • default.qubit.torch (PennyLane-0.35.1)
  • default.qutrit (PennyLane-0.35.1)
  • null.qubit (PennyLane-0.35.1)
  • lightning.qubit (PennyLane_Lightning-0.35.1)

Thank you!

Hi @dexfuse, welcome to the forum! Thank you for your question. We’re taking a look and will get back to you soon with an answer.