Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/splch/qubit-simulator
A simple 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: about 2 months ago
JSON representation
A simple 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 (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-15T07:55:45.000Z (about 1 year ago)
- Last Synced: 2024-03-15T12:25:57.668Z (10 months ago)
- Topics: framework, python, quantum, quantum-computing, quantum-information, quantum-programming-language
- Language: Python
- Homepage:
- Size: 51.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Qubit Simulator
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.
## Installation
Install Qubit Simulator via pip:
```bash
pip install qubit-simulator
```## Usage
### Initializing the Simulator
Create a simulator with a specified number of qubits:
```python
from qubit_simulator import QubitSimulatorsimulator = QubitSimulator(3)
```### Applying Gates
Apply various quantum gates to the qubits:
```python
simulator.h(0) # Hadamard gate
simulator.t(1) # π/8 gate
simulator.cx(0, 2) # Controlled-Not gate
```### Custom Gates
Define and apply custom gates using angles:
```python
simulator.u(2, 0.3, 0.4, 0.5) # Generic gate
```### Measurements
Measure the state of the qubits:
```python
print(simulator.run(shots=100))
``````plaintext
{'000': 46, '001': 4, '100': 4, '101': 46}
```### Circuit Representation
Get a string representation of the circuit:
```python
print(simulator)
``````plaintext
-----------------------------------
| H | | @ | |
| | T | | |
| | | X | U(0.30, 0.40, 0.50) |
-----------------------------------
```### Wavefunction Plot
Show the amplitude and phase of all quantum states:
```python
simulator.plot_wavefunction()
```![Wavefunction Scatter Plot](https://github.com/splch/qubit-simulator/assets/25377399/de3242ef-9c14-44be-b49b-656e9727c618)
## 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.