Metadata-Version: 2.3
Name: quantum-emotion
Version: 1.0.1
Summary: Classical simulation of quantum circuits.
Author: Tanishka Birdavade, Hendrik Kuehne, Matthew Howarth
Author-email: Tanishka Birdavade <tanishka.birdavade.22@ucl.ac.uk>, Hendrik Kuehne <hendrik.kuehne.26@ucl.ac.uk>, Matthew Howarth <matthew.howarth.26@ucl.ac.uk>
Requires-Dist: cotengra>=0.8.3
Requires-Dist: matplotlib>=3.11.2
Requires-Dist: networkx>=3.7
Requires-Dist: numpy>=2.5.4
Requires-Dist: scipy>=1.18.1
Requires-Dist: tqdm>=4.70.1
Requires-Python: >=3.13
Project-URL: Documentation, https://qc2-python-se.github.io/quantum-emotion/
Project-URL: Repository, https://github.com/QC2-python-SE/quantum-emotion
Description-Content-Type: text/markdown

[![Tests](https://github.com/QC2-python-SE/quantum-emotion/actions/workflows/tests.yml/badge.svg)](https://github.com/QC2-python-SE/quantum-emotion/actions/workflows/tests.yml)
[![Docs](https://github.com/QC2-python-SE/quantum-emotion/actions/workflows/docs.yml/badge.svg)](https://qc2-python-se.github.io/quantum-emotion/)
[![PyPI version](https://img.shields.io/pypi/v/quantum-emotion.svg)](https://pypi.org/project/quantum-emotion/)

<img src="logo.png" alt="Logo" width="25%">

The `quantum-emotion` package provides educational tools for quantum circuit simulation. Users may:

+ assemble quantum circuits using a variety of gates, including mid-circuit measurements and classical control,
+ visualise circuits,
+ calculate the quantum states that circuits produce, or get access to probability distributions over mid-circuit measurements,
+ add their own gates.

Under the hood, a quantum circuit is represented by a tensor network. Adding an operation to the circuit corresponds to connecting another tensor to the network, and calculating quantum states means contracting the entire tensor network.

---

# Getting Started

`quantum-emotion` may be installed from PyPI:

```bash
pip install quantum-emotion
```

Or installed locally in editable mode:

```bash
git clone https://github.com/QC2-python-SE/quantum-emotion.git
cd quantum-emotion
pip install -e .
```

The package is designed to closely follow the way in which quantum states and operators behave mathematically. As a result, assembling a circuit looks just like matrix multiplication. Consider for example a circuit that produces the Bell state $(|00\rangle + |11\rangle) / \sqrt{2}$:

```python
import matplotlib.pyplot as plt
from quantum_emotion import KetState, Hadamard, CNOT

# Create the quantum state and apply the circuit
psi0 = KetState(N=2)
psi_final = CNOT(wires=(0, 1)) @ Hadamard(wires=0) @ psi0

# Calculate the output state
print(psi_final.eval())

# Plot the circuit
ax = psi_final.plot()
plt.show()
```

---

# Tutorial Curriculum

All tutorial notebooks are located in the [`notebooks/`](notebooks/) directory and grouped into **Beginner**, **Intermediate**, **Advanced**, and **Practice & Debugging** tracks:

## Beginner

| Notebook | Topic | Key Concepts |
| :--- | :--- | :--- |
| [0_getting_started.ipynb](notebooks/0_getting_started.ipynb) | Getting Started | `KetState`, `@` operator, `.eval()`, `.plot()`, `Measure` |
| [1_superposition.ipynb](notebooks/1_superposition.ipynb) | Superposition | Ground state, Hadamard gate, probabilities, reversibility |
| [2_bell_states.ipynb](notebooks/2_bell_states.ipynb) | Bell States and Entanglement | Bell pairs, circuit diagrams, `BraState` inner products, GHZ |
| [13_shots_and_sampling.ipynb](notebooks/13_shots_and_sampling.ipynb) | Measurements and Shot Noise | `Measure`, `.sample(shots=...)`, $1/\sqrt{N}$ shot noise |

## Intermediate

| Notebook | Topic | Key Concepts |
| :--- | :--- | :--- |
| [3_deutsch_algorithm.ipynb](notebooks/3_deutsch_algorithm.ipynb) | Deutsch's Algorithm | Constant vs balanced oracles, phase kickback |
| [4_bernstein_vazirani.ipynb](notebooks/4_bernstein_vazirani.ipynb) | Bernstein-Vazirani | Single-query hidden bitstring recovery, N-qubit scaling |
| [5_quantum_teleportation.ipynb](notebooks/5_quantum_teleportation.ipynb) | Quantum Teleportation | EPR pairs, mid-circuit measurement, `.c_if()` |
| [6_custom_gates_and_modules.ipynb](notebooks/6_custom_gates_and_modules.ipynb) | Custom Gates and Rotations | Subclassing `BaseGate`, continuous rotations, `.sqrt`, Toffoli |
| [8_quantum_key_distribution.ipynb](notebooks/8_quantum_key_distribution.ipynb) | Quantum Key Distribution (BB84) | Conjugate bases, key sifting, eavesdropping detection |
| [9_circuit_modules.ipynb](notebooks/9_circuit_modules.ipynb) | Modular Circuits | Subcircuits, `ModularGate`, `BellModule`, `SwapModule`, `QFTModule` |

## Advanced

| Notebook | Topic | Key Concepts |
| :--- | :--- | :--- |
| [7_grovers_search.ipynb](notebooks/7_grovers_search.ipynb) | Grover's Search | Phase inversion, diffusion operator, amplitude amplification |
| [10_superdense_coding.ipynb](notebooks/10_superdense_coding.ipynb) | Superdense Coding | Send 2 classical bits via 1 qubit using `BellModule` + noise |
| [11_quantum_phase_estimation.ipynb](notebooks/11_quantum_phase_estimation.ipynb) | Quantum Phase Estimation | Eigenphase estimation using `QFTModule` and `InverseQFTModule` |
| [12_entanglement_swapping.ipynb](notebooks/12_entanglement_swapping.ipynb) | Entanglement Swapping | Chained `BellModule` pairs and `.c_if()` corrections |
| [16_putting_it_all_together.ipynb](notebooks/16_putting_it_all_together.ipynb) | Putting It All Together | Constant-depth long-range CNOT & GHZ via dynamic circuits (Bäumer et al., *PRX Quantum* 2024) |

## Practice & Debugging

| Notebook | Topic | Key Concepts |
| :--- | :--- | :--- |
| [14_common_mistakes.ipynb](notebooks/14_common_mistakes.ipynb) | Common Mistakes and Fixes | 8 common errors with tracebacks and fixes |
| [15_fix_the_bug.ipynb](notebooks/15_fix_the_bug.ipynb) | Debugging Exercises | 5 short buggy snippets to diagnose and fix |
| [practice_exercises.ipynb](notebooks/practice_exercises.ipynb) | Practice Exercises | 5 problems covering superposition, Bell states, oracles, and rotations |
| [practice_solutions.ipynb](notebooks/practice_solutions.ipynb) | Practice Solutions | Worked solutions for the 5 exercises |

---

# Documentation

Full theoretical background, quantum mechanics foundations, and API documentation are hosted at **[https://qc2-python-se.github.io/quantum-emotion/](https://qc2-python-se.github.io/quantum-emotion/)** and also available in the `docs/` folder:

- **States and Gates**: Dirac notation, Bloch sphere geometry, and unitary operators.
- **Entanglement and Measurement**: Tensor products, Bell states, finite-shot noise, and tensor network scaling.
- **Algorithms**: Phase kickback, Grover amplification, superdense coding, QPE, and BB84 security.
- **Modular Circuits**: Hierarchical subcircuits and modular gate composition (`BellModule`, `SwapModule`, `QFTModule`, `QPEModule`, `TeleportationModule`).
- **Simulation Boundaries**: How `quantum-emotion` contracts circuits with `cotengra`, why `.eval()` caps dense vectors at $N \le 25$, and Area-Law vs Volume-Law entanglement.
- **Tutorials**: Level-grouped curriculum (`Beginner`, `Intermediate`, `Advanced`, `Practice & Debugging`).
- **Troubleshooting**: Diagnostic guide covering common API syntax errors, structural circuit pitfalls, and physics boundaries.
- **API Reference**: Comprehensive class and method signatures.

To build and view documentation locally:

```bash
uv sync --extra docs
uv run mkdocs serve
```

---

# Package Architecture

```text
src/quantum_emotion/
├── __init__.py      # Public package exports
├── core.py          # KetState, BraState, CircuitOp, BaseGate, CompositeGate, ModularGate, Measure, .c_if()
├── gates.py         # Built-in gates (PauliX/Y/Z, Hadamard, Phase/S/T, CNOT, ControlledY/Z) & modules
├── _register.py     # Tensor-network graph and cotengra contraction engine (CoreRegister)
└── tests/           # Unit tests for core, gates, modules, and sampling
```

---

# License

This project is licensed under the Apache 2.0 License. See `license.txt` for details.
