Qubit Simulator is a simple and lightweight library that provides a quantum simulator for simulating qubits and quantum gates. It supports basic quantum operations and gates such as Hadamard, π/8, Controlled-Not, and generic unitary transformations.
Install Qubit Simulator via pip:
pip install qubit-simulator
Create a simulator with a specified number of qubits:
from qubit_simulator import QubitSimulator
simulator = QubitSimulator(3)
Apply various quantum gates to the qubits:
simulator.h(0) # Hadamard gate
simulator.t(1) # π/8 gate
simulator.cx(0, 2) # Controlled-Not gate
Define and apply custom gates using angles:
simulator.u(2, 0.3, 0.4, 0.5) # Generic gate
Measure the state of the qubits:
print(simulator.run(shots=100))
{'000': 46, '001': 4, '100': 4, '101': 46}
Get a string representation of the circuit:
print(simulator)
-----------------------------------
| H | | @ | |
| | T | | |
| | | X | U(0.30, 0.40, 0.50) |
-----------------------------------
Show the amplitude and phase of all quantum states:
simulator.plot_wavefunction()
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.