Use this file to discover all available pages before exploring further.
View on GitHub
Open this notebook in GitHub to run it yourself
In this tutorial, we implement 1D and 2D quantum walk.Quantum walks are quantum-mechanical extensions of classical random walks and play a central role in the design of quantum algorithms. In particular, quantum walks are known to provide polynomial, and in some cases exponential, speedups over classical methods for tasks such as search problems and the acceleration of Markov-chain–based procedures.There are two main types of quantum walks: discrete-time quantum walks and continuous-time quantum walks. In the discrete-time model, the time evolution is defined by a unitary operator U=S(C⊗I), where C is a coin operator and S is a shift operator. In the continuous-time model, the adjacency matrix A or the Laplacian L of the graph is used as the Hamiltonian, and the state evolves according to the unitary operator e−iHt.Unlike classical random walks, quantum walks exhibit dramatically different behavior due to interference and unitarity.For instance, the probability distribution does not take a Gaussian form; instead, it spreads ballistically, leading to an O(t) dispersion rather than the classical O(t).These properties form the foundation for the speedups observed in quantum-walk–based algorithms.Quantum walks have a wide range of applications, including search algorithms, Hamiltonian simulation, quantum Markov chains, and quantum machine learning. In particular, Szegedy’s quantum walk provides a general framework for quantizing classical Markov chains into unitary operators, enabling powerful algorithmic constructions across diverse domains.
In a one-dimensional discrete-time quantum walk, the position space is the integer lattice Z, and the coin space is a two-dimensional Hilbert space.The state is written as∣ψt⟩=x=0∑N−1l=0∑1αx,l∣x⟩⊗∣l⟩.Using a coin operator C and a shift operator S, one step of the time evolution is defined byU=S(C⊗I).A typical example of a coin is the Hadamard coin:C=H=21(111−1).The shift operator moves the walker left or right depending on the coin state:S∣x⟩∣0⟩=∣x−1⟩∣0⟩,S∣x⟩∣1⟩=∣x+1⟩∣1⟩.As a result, the quantum walk spreads ballistically due to interference, producing a probability distribution very different from the Gaussian diffusion of classical random walks.
import matplotlib.pyplot as pltimport numpy as npfrom classiq import *
# n is number of qubitsn = 6# number of grids of 1 dimentional latticecircle_size = 2**nNUM_SAMPLES = 1000
In a discrete-time quantum walk on a two-dimensional lattice, the position space is Z2, and a four-dimensional coin space is used to represent movement directions.The state is written as∣ψt⟩=x=0∑N−1y=0∑N−1l=0∑3αt(x,y,l)∣x,y⟩⊗∣l⟩.The coin operator C is a 4×4 unitary matrix. A commonly used example is the Grover coin:C=G4=21−11111−11111−11111−1.The shift operator S moves the walker according to the coin state:S∣x,y⟩∣0⟩S∣x,y⟩∣1⟩S∣x,y⟩∣2⟩S∣x,y⟩∣3⟩=∣x+1,y⟩∣0⟩,=∣x−1,y⟩∣1⟩,=∣x,y+1⟩∣2⟩,=∣x,y−1⟩∣3⟩.The time evolution is given, as in the 1D case, byU=S(C⊗I).Two-dimensional quantum walks exhibit richer interference patterns, and it is known that strong localization can occur, particularly when using the Grover coin.
Quantum program link: https://platform.classiq.io/circuit/36pbYSrYqQHQjfPUsLSauntyXAq
from collections import defaultdictimport matplotlib.pyplot as pltimport numpy as npwith ExecutionSession(qprog_2d) as es: result = es.sample({"t": 20})quantum_probs = { (s.state["x"], s.state["y"]): s.shots / result.num_shots for s in result.parsed_counts}"""Data Vizualization"""L = 1 << nZ = np.zeros((L, L), dtype=float)for (x, y), p in quantum_probs.items(): if 0 <= x < L and 0 <= y < L: Z[y, x] = pfig, ax = plt.subplots(figsize=(7, 6))im = ax.imshow( Z, origin="lower", extent=[-0.5, L - 0.5, -0.5, L - 0.5], aspect="equal", interpolation="nearest", vmin=0.0, vmax=Z.max() if Z.max() > 0 else 1.0,)cbar = plt.colorbar(im, ax=ax)cbar.set_label("probability", fontsize=12)ax.set_xlim(-0.5, L - 0.5)ax.set_ylim(-0.5, L - 0.5)ax.set_xlabel("x")ax.set_ylabel("y")ax.set_title("Probability heatmap P(x, y)")plt.tight_layout()plt.show()