How to Implement a 13-bit Full Adder Quantum Circuit on Dynex

Dynex [DNX]
4 min readAug 13, 2024

This guide explains how to implement a 13-bit full adder using a quantum circuit. A full adder is a fundamental component in digital circuits used to perform binary addition. In a quantum computing context, a full adder can add binary numbers using qubits and quantum gates, leveraging the principles of superposition and entanglement for parallel computation.

Full source code

1. Introduction to the Quantum Full Adder

A full adder quantum circuit adds three binary digits (two input bits and a carry-in bit) and produces a sum bit and a carry-out bit. When extended to multiple bits, this allows for the addition of larger binary numbers. Implementing this on a quantum computer takes advantage of quantum parallelism, which could lead to more efficient addition operations compared to classical methods, especially as the number of bits increases.

Why Quantum Adders Matter: Quantum adders are crucial for quantum arithmetic operations, which are foundational to more complex quantum algorithms, such as Shor’s algorithm for integer factorization. Implementing adders efficiently in quantum circuits can significantly enhance the performance of quantum computers in solving problems that involve large numbers or require extensive arithmetic calculations.

2. Setting Up the Quantum Circuit

The first step involves determining the number of qubits needed. For a 13-bit full adder, the number of qubits required is based on the number of bits in the two input numbers.

  • Determine the Number of Qubits: The number of qubits is calculated based on the bit-length of the sum of the two input numbers.
  • Initialize Qubits: The qubits are initialized in the |0⟩ or |1⟩ states corresponding to the binary representation of the input numbers.
import pennylane as qml
from pennylane import numpy as np

params = [1024, 5429] # Example numbers to add
def Nqubits(a, b):
mxVal = a + b
return mxVal.bit_length()
wires = Nqubits(*params)

3. Implementing the Quantum Fourier Transform (QFT)

The Quantum Fourier Transform (QFT) is used to efficiently perform the addition. The QFT transforms the quantum state into the frequency domain, where the addition operation is easier to implement.

def Kfourier(k, wires):
for j in range(len(wires)):
qml.RZ(k * np.pi / (2**j), wires=wires[j])

4. Constructing the Full Adder Circuit

The full adder circuit is constructed using the QFT and controlled quantum gates. The input states are first embedded using BasisEmbedding, then the QFT is applied. The addition is performed by applying phase shifts proportional to the second number. Finally, the inverse QFT is applied to bring the state back to the computational basis.

@qml.qnode(dev)
def FullAdder(params, state=True):
a, b = params
wires = Nqubits(a, b)
qml.BasisEmbedding(a, wires=range(wires))
qml.QFT(wires=range(wires))
Kfourier(b, range(wires))
qml.adjoint(qml.QFT)(wires=range(wires))
if state:
return qml.state()
else:
return qml.sample()
Example circuit: 13 qubit adder

5. Running the Quantum Full Adder

To run the quantum full adder, simply provide the two numbers to be added as input. The circuit will output the quantum state representing the sum of the two numbers.

result = FullAdder(params)
print("Quantum Full Adder Result:", result)

Conclusion

This 13-bit full adder quantum circuit leverages the principles of quantum computing to perform binary addition more efficiently. Quantum adders are fundamental to quantum arithmetic operations, which are critical for executing complex algorithms on quantum computers. By implementing a full adder on the Dynex neuromorphic quantum computing cloud, you can explore the potential benefits of quantum computing for arithmetic operations and gain insights into how quantum circuits can enhance classical computational tasks.

Why Quantum Adders on Dynex Matter: Executing quantum adders on the Dynex neuromorphic quantum computing cloud, with its support for quantum circuits, provides a platform for scalable quantum arithmetic. This not only improves the performance of quantum algorithms but also serves as a building block for future quantum applications, particularly in fields requiring large-scale arithmetic computations.

About Dynex

Dynex is the world’s only accessible neuromorphic quantum computing cloud for solving real-world problems, at scale. The company began as an informal project in September 2020 in collaboration amongst a community of extraordinary minds and quickly evolved into a technological leader ready to scale into global markets. The Dynex n.quantum computing cloud performs quantum computing based algorithms without limitation, executing calculations with unparalleled speed and efficiency, surpassing usual quantum computing constraints. Dynex is dedicated to pushing the boundaries of technology to create sustainable, secure, and innovative solutions that address complex challenges and drive progress. For more information, visit dynex.co.

--

--

Dynex [DNX]

Dynex is a next-generation platform for neuromorphic computing based on a groundbreaking flexible blockchain protocol.