Skip to main content

A simple quantum circuit simulator.

Project description

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. For plotting, install optional matplotlib.

Installation

Install Qubit Simulator via pip:

pip install qubit-simulator[visualization]

Usage

Initializing the Simulator

Create a simulator with a specified number of qubits:

from qubit_simulator import QubitSimulator

sim = QubitSimulator(num_qubits=2)

Applying Gates

Apply various quantum gates to the qubits:

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:

sim.u(1.05, 1.57, 3.14, 1)  # Arbitrary single-qubit gate

Circuit Drawing

Get a drawing of the circuit:

sim.draw()

Circuit Drawing

Measurements

Measure the state of the qubits:

print(sim.run(shots=100))
{'000': 49, '001': 1, '100': 1, '101': 49}

Statevector Plot

Show the amplitude and phase of all quantum states:

sim.state()

Statevector Bar Chart

Testing

Tests are included in the package to verify its functionality and provide more advanced examples:

python3 -m pytest tests/

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

qubit_simulator-0.1.1.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

qubit_simulator-0.1.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file qubit_simulator-0.1.1.tar.gz.

File metadata

  • Download URL: qubit_simulator-0.1.1.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for qubit_simulator-0.1.1.tar.gz
Algorithm Hash digest
SHA256 24f5dbdb0e3f1c4e2cbf0b6ead936cb7909f372c430316d902e002eaf5dc4b9f
MD5 63ddb1339c6753131c826d461cbd449e
BLAKE2b-256 f9ba8ef5146d7f8e8c3f244ca6ed4c7393b4217a61ed567cb817f21648c47a8d

See more details on using hashes here.

File details

Details for the file qubit_simulator-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for qubit_simulator-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8f02621165ac61c65b3f5deb106eecafa0258b19f041ce97da9b59cb4850578d
MD5 17eb1e5fc4a1978aa54880dc20373e4c
BLAKE2b-256 5371070fc9ee2985e5527057c2aab08547f4ce4c3cf925c9bda78ea1b8eb13b6

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