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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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