Skip to content

Quantum Superposition with Classiq

View on GitHub

Superposition is a key concept in all quantum algorithms. In this tutorial, we show how to create an equal superposition on 3 qubits, using the Hadamard transform.

from classiq import *


@qfunc
def my_hadamard_transform(reg_a: QArray[QBit]) -> None:
    apply_to_all(H, reg_a)


@qfunc
def main(register_a: Output[QArray[QBit]]) -> None:
    allocate(3, register_a)
    my_hadamard_transform(register_a)


model = create_model(main)
write_qmod(model, "equal_superposition_3_qubits")


qprog = synthesize(model)

circuit = QuantumProgram.from_qprog(qprog)

circuit.show()
Opening: https://platform.classiq.io/circuit/bdc37c77-6432-4f51-8c6c-f5a2d2263fde?version=0.41.0.dev39%2B79c8fd0855

Mathematical Background

The 2x2 Hadamard matrix \( H \) is used to transform a single qubit's state. It is defined as:

\[H = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}\]

Application to 3 Qubits: Applying the Hadamard transform \( H \) to each of three qubits initially in the state \(|000\rangle\) results in the superposition of all possible states. The combined operation for three qubits is the tensor product \(H \otimes H \otimes H\):

\[(H \otimes H \otimes H) |000\rangle = \frac{1}{\sqrt{8}} (|000\rangle + |001\rangle + |010\rangle + |011\rangle + |100\rangle + |101\rangle + |110\rangle + |111\rangle)\]

This represents an equal superposition of all eight possible states of the three qubits.