This repository contains a comprehensive, beginner-friendly Python project that simulates the time evolution of a particle in a 1D Quantum Harmonic Oscillator potential using Quantum Phase Estimation techniques, specifically Trotterized Quantum Circuit Evolution.
It compares the simulated quantum circuit evolution against the exact analytical solution to analyze the accuracy, fidelity, and resource requirements of the quantum simulation.
- Theoretical Background
- Project Structure
- Setup and Installation
- Running the Simulation
- Understanding the Output
The system consists of a particle of mass
Where
The exact wavefunctions (eigenstates) and energy levels (eigenvalues) for this system are given analytically by:
Where
Any initial state
To simulate this on a quantum computer, we must first discretize continuous space into a grid of
We use the finite difference method to approximate the kinetic energy operator
The potential energy
The full Hamiltonian is
Quantum computers operate using fundamental gates acting on qubits. Any Hermitian matrix (like our discretized
Where
The time evolution operator is
First-Order Trotter:
Second-Order Trotter: (More accurate, symmetric)
The full simulation repeats this Trotter step
Each exponential term
- Apply basis change gates to map
$X \to Z$ and$Y \to Z$ . - Use a sequence of CNOT gates to encode the parity of the qubits into a target qubit.
- Apply a single
$R_z(2\theta)$ rotation on the target qubit. - Uncompute the CNOTs and the basis change gates.
-
main.py: The central script. Configures parameters, initializes a displaced (or coherent) state, orchestrates the simulation steps, and calls plotting functions. -
physics.py: Computes the exact, analytical benchmark. Handles eigenvalues, Hermite polynomial eigenstates, and analytical time-evolution. -
trotter.py: Handles Hamiltonian discretization (kinetic + quadratic potential), Pauli decomposition, and performs fast matrix-based Trotter evolution. -
circuit.py: Translates the Trotter steps into actualQiskitQuantumCircuitobjects and counts logical gate resources (depth, CNOTs). -
analysis.py: Calculates fidelity,$L_2$ errors, and verifies physical constraints (energy and norm conservation). -
visualization.py: Contains functions for plotting static graphs and generating animated GIFs of the wavepacket evolution. -
output/: Directory where all generated plots, diagrams, and animations are saved.
-
Clone the repository:
git clone https://github.com/TSS99/QHO_Simulation_Trotterization.git cd QHO_Simulation_Trotterization -
Create a Python virtual environment (recommended):
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies: This project relies on
numpy,scipy,matplotlib, andqiskit.pip install -r requirements.txt
Simply execute the main script:
python main.pyThe script will automatically:
- Initialize a Gaussian wavepacket (often offset so it oscillates back and forth).
- Calculate the exact analytical time-evolution.
- Discretize the harmonic oscillator Hamiltonian and decompose it into Pauli strings.
- Run the Trotterized quantum simulation.
- Compute fidelities and errors.
- Generate resource metrics for varying grid sizes.
- Save plots and an animation in the
output/directory.
After running the simulation, check the output/ folder for these files:
-
initial_state.png: Compares the continuous analytical wavepacket with the discretized starting state on the grid. -
probability_snapshots.png: Side-by-side comparison of the probability density between the Exact Evolution and the Trotterized Quantum Circuit at specific intervals as the wavepacket moves. -
fidelity_vs_time.pnganderror_vs_time.png: Tracks how closely the quantum simulation matches the exact answer as time progresses. -
physics_validation.png: Verifies that the Trotter simulation preserves total probability (norm$\approx 1$ ) and energy ($\langle H \rangle \approx \text{const}$ ). -
convergence_dt.png(or vs$N$ ): Shows how scaling the grid size or Trotter steps improves the fidelity. -
resource_scaling.png: Plots the required number of CNOT blocks and circuit depth required on a real quantum computer against grid size. -
evolution_animation.gif: An animated GIF showing the wavepacket oscillation inside the parabolic potential. -
circuit_diagram.png: A snapshot of the generated Qiskit circuit for a small subset of the simulation.