A Python library for quantum tests.
Project description
# 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=Trueduring initialization.
-
Gate Application:
- Use the
apply_gate(gate)method to apply any quantum gate (2×2 matrix).
- Use the
-
Measurement:
- The
measure()method performs a projective measurement, collapsing the qubit state to either |0⟩ or |1⟩ and returning the result.
- The
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)wheretargetscan be an integer or a list of indices.
- Use
-
Controlled Gates:
- Use
apply_controlled_gate(gate, control, target)to apply a controlled operation (e.g., CNOT).
- Use
-
Measurement:
- The
measure(targets=None)method measures the specified qubits. If no targets are specified, it measures all qubits.
- The
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 parametergamma.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.
- Use the helper function
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:
- Create a 2-qubit circuit using
QuantumCircuit. - Apply the Hadamard gate on qubit 0.
- Apply a controlled-X (CNOT) gate with qubit 0 as control and qubit 1 as target.
- 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:
- Create a 2-qubit circuit with
AdvancedQuantumCircuitusing density matrix simulation. - Apply quantum gates to generate a complex quantum state.
- Apply an amplitude damping channel (with a chosen gamma value) to one of the qubits.
- 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:
- Create two quantum circuits using either
QuantumCircuitorAdvancedQuantumCircuit. - Apply different sets of gates to generate two distinct quantum states.
- Use the
fidelityfunction to calculate the fidelity between the resulting density matrices. - 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!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file QuantumLaboratory-1.0.1.tar.gz.
File metadata
- Download URL: QuantumLaboratory-1.0.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d8d378eb6a6a86546b50f380efc9f0b55d509b94bf70d5897bc21e10c730013
|
|
| MD5 |
8c9a884e15e49fe73afb75553f532831
|
|
| BLAKE2b-256 |
00b706447724f455adb916a08e4ad3777de399b23ab883ba50c7c7d221445daa
|
File details
Details for the file QuantumLaboratory-1.0.1-py3-none-any.whl.
File metadata
- Download URL: QuantumLaboratory-1.0.1-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06b190a4db9077f491ac43b072cd7864fc7d0f2411af9ee984f36b367912d791
|
|
| MD5 |
fe8e9a730f653c92b93bd10ae40d464c
|
|
| BLAKE2b-256 |
bd5c61b843c7dca24fd9214abbdb04f109aed26c4cb8a12d94ea10f795aff7d0
|