Skip to main content

A Python library for quantum tests.

Project description

# QuantumLab

**QuantumLab** is an advanced and comprehensive Python library for simulating and experimenting with quantum computing. Built using powerful libraries like NumPy and SciPy, QuantumLab enables you to work with qubits (using state vectors or density matrices), simulate multi-qubit circuits, apply standard and rotation gates, implement controlled multi-qubit operations, and model noise channels using Kraus operators. It also provides helper tools for tensor products, partial traces, and fidelity calculations between quantum states.

**Creator:** Mohammad Taha Gorji

---

## Table of Contents

- [Features](#features)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Usage Guide](#usage-guide)
  - [Qubit](#qubit)
  - [QuantumCircuit](#quantumcircuit)
  - [AdvancedQuantumCircuit](#advancedquantumcircuit)
  - [Noise Channels and Kraus Operators](#noise-channels-and-kraus-operators)
  - [Helper Functions](#helper-functions)
- [Sample Projects](#sample-projects)
  - [Project 1: Simple Quantum Algorithm](#project-1-simple-quantum-algorithm)
  - [Project 2: Simulating Noise in a Quantum Circuit](#project-2-simulating-noise-in-a-quantum-circuit)
  - [Project 3: Comparing Fidelity Between Two Quantum States](#project-3-comparing-fidelity-between-two-quantum-states)
- [Contributing](#contributing)
- [License](#license)
- [Contact](#contact)

---

## Features

- **Qubit Representation:** Supports both pure states (state vectors) and mixed states (density matrices).
- **Multi-Qubit Circuits:** Simulate quantum circuits with multiple qubits. Start with an initial state |00…0⟩ and apply gates to individual or groups of qubits.
- **Quantum Gates:** Includes standard gates such as I, X, Y, Z, H, S, T and rotation gates (Rx, Ry, Rz).
- **Controlled Operations:** Implement controlled gates (e.g., CNOT) in your quantum circuits.
- **Noise Channels:** Simulate noise effects using amplitude damping and phase damping channels through Kraus operators.
- **Helper Tools:** Provides functions for tensor products, partial trace computation, and fidelity measurement between quantum states.

---

## Installation

You can easily install QuantumLab using pip:

```bash
pip install QuantumLab

Quick Start

After installing QuantumLab, you can start building quantum circuits and simulating experiments. Here are a few quick examples to get you started:

Example 1: Using the Qubit Class

from QuantumLab import Qubit
from QuantumLab import H  # Hadamard gate

# Create a qubit in the default state |0>
q = Qubit()

# Apply the Hadamard gate to put it into a superposition
q.apply_gate(H)
print("State of qubit after applying H:", q)

# Measure the qubit (collapsing its state)
result = q.measure()
print("Measurement result:", result)

Example 2: Using the QuantumCircuit Class

from QuantumLab import QuantumCircuit, H, X

# Create a 2-qubit circuit
circuit = QuantumCircuit(num_qubits=2)

# Apply Hadamard gate on qubit 0
circuit.apply_gate(H, targets=0)

# Apply a controlled-X (CNOT) gate with qubit 0 as control and qubit 1 as target
circuit.apply_controlled_gate(X, control=0, target=1)

# Measure the circuit
outcome = circuit.measure()
print("Circuit measurement outcome:", outcome)

Example 3: Using the AdvancedQuantumCircuit and Noise Channels

from QuantumLab import AdvancedQuantumCircuit, H, amplitude_damping_channel

# Create an advanced 2-qubit circuit using density matrix simulation
adv_circuit = AdvancedQuantumCircuit(num_qubits=2, use_density=True)

# Apply Hadamard gate on qubit 0
adv_circuit.apply_gate(H, targets=0)

# Apply a controlled-X (CNOT) gate with qubit 0 as control and qubit 1 as target
adv_circuit.apply_controlled_gate(X, control=0, target=1)

# Apply amplitude damping noise channel on qubit 1 (with gamma = 0.1)
gamma = 0.1
kraus_ops = amplitude_damping_channel(gamma)
adv_circuit.apply_noise_kraus(kraus_ops, targets=1)

# Measure the advanced circuit
outcome = adv_circuit.measure()
print("Advanced circuit measurement outcome:", outcome)

Usage Guide

Qubit

  • Creation:

    • By default, a qubit is initialized in the |0⟩ state.
    • You can initialize a qubit with a custom state vector.
    • To use density matrix representation (mixed state), set use_density=True during initialization.
  • Gate Application:

    • Use the apply_gate(gate) method to apply any quantum gate (2×2 matrix).
  • Measurement:

    • The measure() method performs a projective measurement, collapsing the qubit state to either |0⟩ or |1⟩ and returning the result.

QuantumCircuit

  • Creation:

    • Initialize a circuit with a specified number of qubits. The default initial state is |00…0⟩.
  • Single-Qubit Gates:

    • Use apply_gate(gate, targets) where targets can be an integer or a list of indices.
  • Controlled Gates:

    • Use apply_controlled_gate(gate, control, target) to apply a controlled operation (e.g., CNOT).
  • Measurement:

    • The measure(targets=None) method measures the specified qubits. If no targets are specified, it measures all qubits.

AdvancedQuantumCircuit

  • Additional Features:
    • Designed to simulate circuits using density matrices for more realistic noise modeling.
    • Supports noise channels via the apply_noise_kraus(kraus_ops, targets) method.

Noise Channels and Kraus Operators

  • Noise Channels:

    • amplitude_damping_channel(gamma): Simulates amplitude damping with parameter gamma.
    • phase_damping_channel(gamma): Simulates phase damping.
  • Kraus Operators:

    • Use the helper function apply_kraus_operators(rho, kraus_ops) to apply a list of Kraus operators to a density matrix.

Helper Functions

  • Tensor Product:

    • tensor(*args) computes the tensor (Kronecker) product of multiple matrices or vectors.
  • Partial Trace:

    • partial_trace(rho, keep, dims) computes the partial trace over specified subsystems.
  • Fidelity:

    • fidelity(rho, sigma) calculates the fidelity between two density matrices.

Sample Projects

Project 1: Simple Quantum Algorithm

Objective:
Simulate a simple quantum circuit to create a Bell state using Hadamard and CNOT gates.

Steps:

  1. Create a 2-qubit circuit using QuantumCircuit.
  2. Apply the Hadamard gate on qubit 0.
  3. Apply a controlled-X (CNOT) gate with qubit 0 as control and qubit 1 as target.
  4. Measure the circuit and analyze the outcomes.

Project 2: Simulating Noise in a Quantum Circuit

Objective:
Investigate the effect of amplitude damping noise on a quantum circuit.

Steps:

  1. Create a 2-qubit circuit with AdvancedQuantumCircuit using density matrix simulation.
  2. Apply quantum gates to generate a complex quantum state.
  3. Apply an amplitude damping channel (with a chosen gamma value) to one of the qubits.
  4. Measure the circuit and compare the noisy results with the ideal (noise-free) scenario.

Project 3: Comparing Fidelity Between Two Quantum States

Objective:
Compute the fidelity between two quantum states generated by different circuits.

Steps:

  1. Create two quantum circuits using either QuantumCircuit or AdvancedQuantumCircuit.
  2. Apply different sets of gates to generate two distinct quantum states.
  3. Use the fidelity function to calculate the fidelity between the resulting density matrices.
  4. Analyze the results to determine how similar the two quantum states are.

Contributing

Contributions to QuantumLab are highly welcome! If you would like to contribute:

  • Clone the repository from GitHub.
  • Create a new branch for your feature or bugfix.
  • Submit a pull request with detailed information about your changes.
  • For any issues or feature requests, please open an issue on the GitHub repository.

License

QuantumLab is released under the MIT License. See the LICENSE file for more details.


Contact

For questions, suggestions, or further information, please feel free to contact the creator:

Mohammad Taha Gorji

You can also open an issue on the GitHub repository to discuss any matters related to QuantumLab.


With QuantumLab, you can easily simulate and experiment with quantum circuits, explore the effects of noise on quantum systems, and perform detailed analyses of quantum states. We hope that QuantumLab becomes a valuable tool for your research and projects in quantum computing!

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

QuantumLaboratory-1.0.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

QuantumLaboratory-1.0.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file QuantumLaboratory-1.0.0.tar.gz.

File metadata

  • Download URL: QuantumLaboratory-1.0.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for QuantumLaboratory-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5122dae9e95e55474f9d5c62895f351bf8e81c2a0b2e1e1a09531aedda4add2b
MD5 52ab2334ab5532cc39639e11cd4f3960
BLAKE2b-256 fdca6ac0c73c6b13f059503f78c957471103fc01233ffb7fe16fc39c582d81d0

See more details on using hashes here.

File details

Details for the file QuantumLaboratory-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for QuantumLaboratory-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cfceb6672917baea6821b14ead89b81e3e61d6857c0bbd5d0d89756d80f28db5
MD5 9c02f2d24e4ba8d11e7d79e983778906
BLAKE2b-256 b49e745abfb1fa17f4a2c6b317f5e601764173cc399a4107296ccf47b261eb51

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