Skip to main content

A simple qubit simulator

Project description

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:

pip install qubit-simulator

Usage

Initializing the Simulator

Create a simulator with a specified number of qubits:

from qubit_simulator import QubitSimulator

simulator = QubitSimulator(3)

Applying Gates

Apply various quantum gates to the qubits:

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:

simulator.u(2, 0.3, 0.4, 0.5)  # Generic gate

Measurements

Measure the state of the qubits:

print(simulator.run(shots=100))
{'000': 46, '001': 4, '100': 4, '101': 46}

Circuit Representation

Get a string representation of the circuit:

print(simulator)
-----------------------------------
| H |   | @ |                     |
|   | T |   |                     |
|   |   | X | U(0.30, 0.40, 0.50) |
-----------------------------------

Wavefunction Plot

Show the amplitude and phase of all quantum states:

simulator.plot_wavefunction()

Wavefunction Scatter Plot

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.0.8.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

qubit_simulator-0.0.8-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file qubit-simulator-0.0.8.tar.gz.

File metadata

  • Download URL: qubit-simulator-0.0.8.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for qubit-simulator-0.0.8.tar.gz
Algorithm Hash digest
SHA256 2b66274bd61c54aef79c4d1617bc268e04d7bfde96d8ed3041b1c6bbf1d36816
MD5 acd3eb4784ebeadfe8a1fac72ab74c84
BLAKE2b-256 95f7d5d889624c3b80af82c839ca13c5529b2b179239952c150814ac6804b77c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for qubit_simulator-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 492cebb26ca23495d937d58e034f0977d98c04d51c927a2f4e956cd1448716ab
MD5 260b3edd5f7f3d07df4abbd6a0f19844
BLAKE2b-256 09553a459d1397d1a8943e0d8a0f2f0fd0ec582039618ef20432a63409ac755a

See more details on using hashes here.

Supported by

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