Skip to main content
# QuantumLaboratory

**QuantumLaboratory** is an advanced and comprehensive Python library for simulating and experimenting with quantum computing. Built using powerful libraries like NumPy and SciPy, QuantumLaboratory 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 QuantumLaboratory using pip:

```bash
pip install QuantumLaboratory

Quick Start

After installing QuantumLaboratory, 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 QuantumLaboratory import Qubit
from QuantumLaboratory 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 QuantumLaboratory 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 QuantumLaboratory import AdvancedQuantumCircuit, H, amplitude_damping_channel, X

# 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 QuantumLaboratory 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

QuantumLaboratory 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 QuantumLaboratory.


With QuantumLaboratory, 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 QuantumLaboratory becomes a valuable tool for your research and projects in quantum computing!

Metadata

Release files for QuantumLaboratory 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for QuantumLaboratory 1.0.1
File Size Uploaded Provenance
QuantumLaboratory-1.0.1.tar.gz 6.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for QuantumLaboratory 1.0.1
File Interpreter ABI Platform
QuantumLaboratory-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.2 kB

Release files / QuantumLaboratory-1.0.1.tar.gz

Download URL QuantumLaboratory-1.0.1.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3d8d378eb6a6a86546b50f380efc9f0b55d509b94bf70d5897bc21e10c730013
BLAKE2b-256 checksum
How to use checksums
00b706447724f455adb916a08e4ad3777de399b23ab883ba50c7c7d221445daa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.1

Release files / QuantumLaboratory-1.0.1-py3-none-any.whl

Download URL QuantumLaboratory-1.0.1-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06b190a4db9077f491ac43b072cd7864fc7d0f2411af9ee984f36b367912d791
BLAKE2b-256 checksum
How to use checksums
bd5c61b843c7dca24fd9214abbdb04f109aed26c4cb8a12d94ea10f795aff7d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.1

Security for QuantumLaboratory 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page