QuantumLaboratory 1.0.1
A Python library for quantum tests.
Requires Python: >=3.6

```markdown
# 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

```python
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

```python
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

```python
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!
```