A quantum circuit simulator with an interactive graphical user interface built using Python and Tkinter. This simulator allows you to design, simulate, and visualize quantum circuits with multiple qubits and various quantum gates.
Note: This project is intended for demonstration purposes and does not include advanced features like noise modeling or optimizations.
demo_qsim.mp4
- Interactive Circuit Design: Visual circuit builder with drag-and-drop gate placement
- Multiple Quantum Gates: Support for single-qubit, two-qubit, and three-qubit gates
- Custom Initial States: Set arbitrary initial quantum states for qubits
- State Visualization: Real-time visualization of quantum state vectors and probabilities
- Bloch Sphere Representation: Visualize single-qubit states on the Bloch sphere
- Step-by-Step Simulation: Execute circuits step-by-step to observe state evolution
- Measurement Operations: Perform quantum measurements with state collapse
- Circuit Import/Export: Save and load circuits in JSON, SVG, and PNG formats
git clone https://github.com/GentleClash/basic_quantum_circuit_simulator_gui.git
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
cd basic_quantum_circuit_simulator_gui
pip install -r requirements.txt
python basic_quantum_sim.pyThe identity gate leaves the qubit unchanged.
Matrix representation: $$ \begin{pmatrix} 1 & 0 \ 0 & 1 \end{pmatrix} $$
The Pauli-X gate is the quantum equivalent of the classical NOT gate. It flips the state of a qubit.
Matrix representation: $$ \begin{pmatrix} 0 & 1 \ 1 & 0 \end{pmatrix} $$
Action: $$ X|0\rangle = |1\rangle, \quad X|1\rangle = |0\rangle $$
Why: Fundamental for bit-flip operations in quantum algorithms.
The Pauli-Y gate performs a rotation around the Y-axis of the Bloch sphere.
Matrix representation: $$ \begin{pmatrix} 0 & -i \ i & 0 \end{pmatrix} $$
Action: $$ Y|0\rangle = i|1\rangle, \quad Y|1\rangle = -i|0\rangle $$
Why: Combines bit-flip and phase-flip operations, useful for creating specific superpositions with complex amplitudes.
The Pauli-Z gate is a phase-flip gate that leaves
Matrix representation: $$ \begin{pmatrix} 1 & 0 \ 0 & -1 \end{pmatrix} $$
Action: $$ Z|0\rangle = |0\rangle, \quad Z|1\rangle = -|1\rangle $$
Why: Essential for phase operations and quantum error correction.
The Hadamard gate creates an equal superposition from basis states.
Matrix representation: $$ \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \ 1 & -1 \end{pmatrix} $$
Action: $$ H|0\rangle = \frac{|0\rangle + |1\rangle}{\sqrt{2}} = |+\rangle $$ $$ H|1\rangle = \frac{|0\rangle - |1\rangle}{\sqrt{2}} = |-\rangle $$
Why: Fundamental for creating superpositions; us in almost every quantum algorithm including quantum Fourier transform and Grover's algorithm.
The S gate applies a 90° phase rotation.
Matrix representation: $$ \begin{pmatrix} 1 & 0 \ 0 & i \end{pmatrix} $$
Action: $$ S|0\rangle = |0\rangle, \quad S|1\rangle = i|1\rangle $$
Relation to Z gate: $$ S^2 = Z $$
Why: Used for precise phase control in quantum algorithms. The phase shift of
The T gate applies a 45° phase rotation.
Matrix representation: $$ \begin{pmatrix} 1 & 0 \ 0 & e^{i\pi/4} \end{pmatrix} = \begin{pmatrix} 1 & 0 \ 0 & \frac{1+i}{\sqrt{2}} \end{pmatrix} $$
Action: $$ T|0\rangle = |0\rangle, \quad T|1\rangle = e^{i\pi/4}|1\rangle $$
Relation to S gate: $$ T^2 = S, \quad T^4 = Z $$
Why: Provides finer phase control than the S gate. Part of the universal gate set {H, T, CNOT} for quantum computation. The phase shift of
The CNOT gate flips the target qubit if and only if the control qubit is
Matrix representation: $$ \begin{pmatrix} 1 & 0 & 0 & 0 \ 0 & 1 & 0 & 0 \ 0 & 0 & 0 & 1 \ 0 & 0 & 1 & 0 \end{pmatrix} $$
Action on basis states: $$ \text{CNOT}|00\rangle = |00\rangle, \quad \text{CNOT}|01\rangle = |01\rangle $$ $$ \text{CNOT}|10\rangle = |11\rangle, \quad \text{CNOT}|11\rangle = |10\rangle $$
Why: Creates entanglement between qubits. Used to generate Bell states and is essential for quantum error correction and quantum teleportation.
The CZ gate applies a Z gate to the target qubit if the control qubit is
Matrix representation: $$ \begin{pmatrix} 1 & 0 & 0 & 0 \ 0 & 1 & 0 & 0 \ 0 & 0 & 1 & 0 \ 0 & 0 & 0 & -1 \end{pmatrix} $$
Action: $$ \text{CZ}|11\rangle = -|11\rangle $$
Why: Symmetrical controlled operation useful for phase kickback and certain quantum algorithms. Equivalent to applying Hadamard before and after a CNOT.
The SWAP gate exchanges the states of two qubits.
Matrix representation: $$ \begin{pmatrix} 1 & 0 & 0 & 0 \ 0 & 0 & 1 & 0 \ 0 & 1 & 0 & 0 \ 0 & 0 & 0 & 1 \end{pmatrix} $$
Action: $$ \text{SWAP}|01\rangle = |10\rangle, \quad \text{SWAP}|10\rangle = |01\rangle $$
Why: Necessary for moving quantum information between non-adjacent qubits in architectures with limited connectivity.
The Toffoli gate is a controlled-controlled-NOT gate. It flips the target qubit only if both control qubits are
Matrix representation: $$ \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \end{pmatrix} $$
Action: $$ \text{CCNOT}|11x\rangle = |11\bar{x}\rangle $$
where
Why: Reversible classical computation. Can implement any classical boolean function. Used in quantum arithmetic and Grover's algorithm.
A quantum system with
where
The simulator implements custom complex number arithmetic:
Addition: $$ (a + bi) + (c + di) = (a + c) + (b + d)i $$
Multiplication: $$ (a + bi) \cdot (c + di) = (ac - bd) + (ad + bc)i $$
Magnitude: $$ |a + bi| = \sqrt{a^2 + b^2} $$
For a gate
where
The implementation computes matrix elements as:
where
Why: This approach avoids explicitly computing tensor products, which would be memory-intensive for large qubit systems.
Measurement of qubit
Probability of measuring |0⟩: $$ P(0) = \sum_{i: \text{bit } q \text{ of } i = 0} |\alpha_i|^2 $$
State collapse:
After measuring outcome
The normalization factor
- Select Number of Qubits: Use the dropdown at the top
- Add Gates: Click on gate buttons and then click on the circuit grid
- Set Initial State (optional): Use "Set Initial State" button
- Simulate: Click "Simulate Circuit"
To create the Bell state
- Set 2 qubits
- Apply Hadamard (H) gate to qubit 0
- Apply CNOT gate with control=0, target=1
- Simulate
The mathematical evolution: $$ |00\rangle \xrightarrow{H \otimes I} \frac{|00\rangle + |10\rangle}{\sqrt{2}} \xrightarrow{\text{CNOT}} \frac{|00\rangle + |11\rangle}{\sqrt{2}} $$
- Save: File → Save Circuit
- Load: File → Load Circuit
-
State vector size:
$O(2^n)$ for$n$ qubits -
Gate application:
$O(4^n)$ for applying a gate to the full state vector -
Memory usage:
$O(2^n)$ complex numbers
Limitation: This simulator is practical for up to 8 qubits on typical hardware due to exponential scaling.
- Complex class: Custom complex number implementation
- QuantumGates class: Static gate definitions
- QuantumCircuit class: Circuit simulation engine
- QuantumSimulatorGUI class: Tkinter-based user interface
- Export/Import module: Functions for saving/loading circuits and exporting images
- Limited to 8 qubits due to memory constraints
- No noise modeling (ideal quantum computer simulation)
- No visualization
- No optimization for sparse circuits
- Add more quantum gates (Fredkin, custom rotations)
- Implement quantum algorithms (Grover, Shor, QFT)
- Add noise models for realistic simulation
- Improve performance with sparse matrix representations
GNU General Public License v3.0 - See LICENSE file for details
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.