A lightweight quantum qubit simulator in Python
Project description
PyQubit v0.3 (first version)
A simple and intuitive Python class for single-qubit simulation.
Installation
pip install pyqubit
Quick Start
from pyqubit import Qubit
q = Qubit(1, 0)
print(q)
q.hadamard()
print(q.probabilities())
✨ Features
- Qubit State Management: Initialize a qubit in any valid superposition of the ∣0⟩ and ∣1⟩ states.
- State Normalization: Automatically ensures the qubit's state vector remains valid after every operation.
- Measurement Simulation: Collapse the qubit's state to a classical bit (0 or 1) based on its quantum probabilities.
- Standard Single-Qubit Gates:
- Pauli-X (NOT)
- Pauli-Y
- Pauli-Z
- Hadamard
- Phase (S)
- Phase (T)
- Parametrized Rotation Gates:
- Rotation around X-axis (
rX) - Rotation around Y-axis (
rY) - Rotation around Z-axis (
rZ)
- Rotation around X-axis (
- Probability Inspection: Easily retrieve the probabilities of measuring the qubit in the ∣0⟩ or ∣1⟩ state.
🧩 Installation
Currently, you can use PyQubit by including the qubit.py file directly in your project.
# (Future installation via pip)
# pip install pyqubit
🚀 Usage Guide
1. Import the Class
Save the file as qubit.py, then:
from qubit import Qubit
import numpy as np
2. Initializing a Qubit
# Create a qubit in the state |0⟩ (alpha=1, beta=0)
q = Qubit(1, 0)
print(f"Initial state: {q}")
# Output: Qubit((1+0j), (0+0j))
3. Applying Gates
Hadamard Gate – Creating Superposition
q = Qubit(1, 0) # Start in |0⟩
q.hadamard()
print(f"State after Hadamard: {q}")
probs = q.probabilities()
print(f"Probabilities: P(|0⟩)={probs[0]:.1%}, P(|1⟩)={probs[1]:.1%}")
Pauli-X (NOT) Gate
q = Qubit(1, 0)
print(f"Before Pauli-X: {q}")
q.pauliX()
print(f"After Pauli-X: {q}")
4. Performing a Measurement
q = Qubit(1, 1) # Automatically normalized to superposition
print(f"Superposition: {q}")
print("Performing 10 measurements...")
for _ in range(10):
result = q.measure()
print(f"Measured: {result}, Collapsed state: {q}")
5. Applying Rotation Gates
q = Qubit(1, 0)
# Rotate by 90° (π/2 radians) around Y-axis
q.rY(np.pi / 2)
print(f"After rY(Ï€/2): {q}")
print(f"Probabilities: {q.probabilities()}")
🔠Future Plans (v0.2+)
- Multi-Qubit Systems: Add
QuantumRegisterto manage multiple qubits. - Entanglement Support: Add CNOT, Toffoli, and other multi-qubit gates.
- Quantum Circuits: Circuit builder and execution.
- Performance Boosts: Optimized calculations for larger systems.
- Visualization: Bloch sphere and state vector plotting tools.
📄 License
This project is licensed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyqubit-0.3.1.tar.gz
(4.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyqubit-0.3.1.tar.gz.
File metadata
- Download URL: pyqubit-0.3.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca156c349324bb50119456eaa64dcdaca4a73996a3589a5b496ed9e0276b8135
|
|
| MD5 |
4868116141095e1ff4dfa29a15f673cd
|
|
| BLAKE2b-256 |
78b54947bc83fb9245aae0dce930317fab607314dc1841c0004d16718c226353
|
File details
Details for the file pyqubit-0.3.1-py3-none-any.whl.
File metadata
- Download URL: pyqubit-0.3.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
683c5098839feab20cf53048b0cced6e482b237c32ace9ff6f8d93fa94738cfc
|
|
| MD5 |
a2aaad6bce51ba016ee6b99b4a3f91ab
|
|
| BLAKE2b-256 |
2ce470c551463f869212620f4cb45586b964bfa9b9d66a97256b37370dfd689d
|