Skip to main content

A lightweight quantum qubit simulator in Python

Project description

PyQubit v0.1

PyPI version Python 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)
  • 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 QuantumRegister to manage multiple qubits.
  • Entanglement Support: Add CNOT, Toffoli, and other multi-qubit gates.
  • Quantum Circuits: Visual 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.2.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyqubit-0.2-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file pyqubit-0.2.tar.gz.

File metadata

  • Download URL: pyqubit-0.2.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for pyqubit-0.2.tar.gz
Algorithm Hash digest
SHA256 4ad39d909592faac3abd860abd5f01c0f925a385fd1b7bcac2b64c95e699bcd7
MD5 8182a0663b6db16ad3797a62ad87bb98
BLAKE2b-256 b50639acb3c7bfb9226957fd8c84f4cc826b4c2ac3a726aac05ca40caced2cb6

See more details on using hashes here.

File details

Details for the file pyqubit-0.2-py3-none-any.whl.

File metadata

  • Download URL: pyqubit-0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for pyqubit-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9674c506587557acc4f5a31d56f5f539df28ccb0c458f784a60f8d1887d215b2
MD5 858b85baa04a6a0bbf6d57070d9281dc
BLAKE2b-256 75a5cb71cef87f52a8d65216d04666c3e68458845905e32a781e8c2c58decc31

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page