A simple yet flexible statevector-based quantum circuit simulator for Python. It supports common single-, two-, and three-qubit gates (including parameterized gates), measurement (shot-based sampling), state resetting, and basic circuit visualization.
- Statevector Simulation: Maintains a complex-valued statevector of size ( 2^n ).
- Common Gates: X, Y, Z, H, S, T, plus multi-qubit gates like CNOT, SWAP, Toffoli, Fredkin, etc.
- Parameterized Gates: General single-qubit rotation ( U(θ, φ, λ) ).
- Controlled Gates: Automatically construct controlled versions of single-qubit gates.
- Circuit Visualization: Generate a diagram of applied operations with
.draw()
. - Measurement: Returns shot-based measurement outcomes from the final state.
- Lightweight: Only requires NumPy. For plotting, install optional matplotlib.
Install Qubit Simulator via pip:
pip install qubit-simulator[visualization]
Create a simulator with a specified number of qubits:
from qubit_simulator import QubitSimulator
sim = QubitSimulator(num_qubits=2)
Apply various quantum gates to the qubits:
sim.h(0) # Hadamard gate
sim.t(0) # π/8 gate
sim.cx(0, 1) # Controlled-Not gate
Define and apply custom gates using angles:
sim.u(1.2, 3.4, 5.6, 1) # Arbitrary single-qubit gate
Get a drawing of the circuit:
sim.draw()
Measure the state of the qubits:
print(sim.run(shots=100))
{'000': 49, '001': 1, '100': 1, '101': 49}
Show the amplitude and phase of all quantum states:
sim.state()
Tests are included in the package to verify its functionality and provide more advanced examples:
python3 -m pytest tests/
This project is licensed under the MIT License.