https://github.com/splch/qubit-simulator
A statevector simulator for performing qubit operations and executing circuits.
https://github.com/splch/qubit-simulator
framework python quantum quantum-computing quantum-information quantum-programming-language
Last synced: 4 months ago
JSON representation
A statevector simulator for performing qubit operations and executing circuits.
- Host: GitHub
- URL: https://github.com/splch/qubit-simulator
- Owner: splch
- License: mit
- Created: 2023-08-10T09:22:59.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-17T06:12:46.000Z (5 months ago)
- Last Synced: 2025-03-06T07:50:45.442Z (4 months ago)
- Topics: framework, python, quantum, quantum-computing, quantum-information, quantum-programming-language
- Language: Python
- Homepage: https://pypi.org/project/qubit-simulator/
- Size: 64.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Qubit Simulator
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.
## Features
- **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](https://numpy.org). For plotting, install optional [matplotlib](https://matplotlib.org).## Installation
Install Qubit Simulator via pip:
```bash
pip install qubit-simulator[visualization]
```## Usage
### Initializing the Simulator
Create a simulator with a specified number of qubits:
```python
from qubit_simulator import QubitSimulatorsim = QubitSimulator(num_qubits=2)
```### Applying Gates
Apply various quantum gates to the qubits:
```python
sim.h(0) # Hadamard gate
sim.t(0) # π/8 gate
sim.cx(0, 1) # Controlled-Not gate
```### Custom Gates
Define and apply custom gates using angles:
```python
sim.u(1.2, 3.4, 5.6, 1) # Arbitrary single-qubit gate
```### Circuit Drawing
Get a drawing of the circuit:
```python
sim.draw()
```
### Measurements
Measure the state of the qubits:
```python
print(sim.run(shots=100))
``````plaintext
{'000': 49, '001': 1, '100': 1, '101': 49}
```### Statevector Plot
Show the amplitude and phase of all quantum states:
```python
sim.state()
```
## Testing
Tests are included in the package to verify its functionality and provide more advanced examples:
```shell
python3 -m pytest tests/
```## License
This project is licensed under the MIT License.