Skip to content

Latest commit

 

History

History
91 lines (59 loc) · 1.74 KB

README.md

File metadata and controls

91 lines (59 loc) · 1.74 KB

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.