Metadata-Version: 2.3
Name: quantum-emotion
Version: 1.0.0
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-Dist: mkdocs>=1.6.1 ; extra == 'docs'
Requires-Dist: mkdocs-material>=9.7.7 ; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=1.0.8 ; extra == 'docs'
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
Provides-Extra: docs
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:

| Notebook | Topic | Key Concepts | Level |
| :--- | :--- | :--- | :--- |
| [0_ground_zero_quickstart.ipynb](notebooks/0_ground_zero_quickstart.ipynb) | Ground Zero Quickstart | Register initialization, gate application (`@`), `.eval()`, circuit plotting | Beginner |
| [1_superposition.ipynb](notebooks/1_superposition.ipynb) | Single Qubit Superposition | Ground state, Hadamard gate, Born rule, state plotting | Beginner |
| [2_bell_states.ipynb](notebooks/2_bell_states.ipynb) | Bell States and Entanglement | Bell pairs, circuit diagrams, BraState inner products | Beginner |
| [3_deutsch_algorithm.ipynb](notebooks/3_deutsch_algorithm.ipynb) | Deutsch Algorithm | Constant vs balanced oracles, phase kickback | Intermediate |
| [4_bernstein_vazirani.ipynb](notebooks/4_bernstein_vazirani.ipynb) | Bernstein-Vazirani | Single-query hidden bitstring recovery, N-qubit scaling | Intermediate |
| [5_quantum_teleportation.ipynb](notebooks/5_quantum_teleportation.ipynb) | Quantum Teleportation | EPR pairs, mid-circuit measurement, classical feedforward `.c_if()` | Intermediate |
| [6_custom_gates_and_modules.ipynb](notebooks/6_custom_gates_and_modules.ipynb) | Custom Gates and Tools | Subclassing `BaseGate`, continuous rotations, `.sqrt`, expectation values | Advanced |
| [7_grovers_search.ipynb](notebooks/7_grovers_search.ipynb) | Grover's Search Algorithm | Phase inversion, diffusion operator, amplitude amplification | Advanced |
| [8_quantum_key_distribution.ipynb](notebooks/8_quantum_key_distribution.ipynb) | Quantum Key Distribution (BB84) | Conjugate bases, key sifting, eavesdropping detection (QBER) | Advanced |
| [9_circuit_modules.ipynb](notebooks/9_circuit_modules.ipynb) | Modular Circuits | Hierarchical subcircuits, `ModularGate`, `BellModule`, `QFTModule`, decomposed plotting | Advanced |
| [10_superdense_coding.ipynb](notebooks/10_superdense_coding.ipynb) | Superdense Coding | Transmit 2 classical bits via 1 qubit using `BellModule` in satellite communication | Advanced |
| [11_quantum_phase_estimation.ipynb](notebooks/11_quantum_phase_estimation.ipynb) | Quantum Phase Estimation | Eigenphase estimation for molecular spectroscopy using `QFTModule` and `InverseQFTModule` | Advanced |
| [12_entanglement_swapping.ipynb](notebooks/12_entanglement_swapping.ipynb) | Entanglement Swapping | Quantum repeater networks with chained `BellModule` pairs and feedforward corrections | Advanced |
| [13_laboratory_measurement_and_shots.ipynb](notebooks/13_laboratory_measurement_and_shots.ipynb) | Laboratory Measurement and Finite-Shot Noise | `Measure`, Born rule sampling (`.sample(shots=...)`), Poisson error scaling $1/\sqrt{N}$, expectation value reconstruction | Advanced |
| [14_multiqubit_scaling_tensor_networks.ipynb](notebooks/14_multiqubit_scaling_tensor_networks.ipynb) | Multi-Qubit Scaling and Tensor Networks | 100-qubit GHZ entanglement chain, tensor network contraction (`cotengra`), local observables, avoiding the exponential memory wall | Advanced |
| [15_single_qubit_and_bloch_sphere.ipynb](notebooks/15_single_qubit_and_bloch_sphere.ipynb) | Single-Qubit Geometry and the Bloch Sphere | Bloch vector coordinates from Pauli expectation values, 3D visualization, state tomography, pure vs mixed states | Intermediate |
| [16_simulation_boundaries_and_complexity.ipynb](notebooks/16_simulation_boundaries_and_complexity.ipynb) | Simulation Boundaries and Complexity | Memory wall scaling, Area-Law vs Volume-Law entanglement, safe evaluation guards, quantum advantage limits | Advanced |
| [17_debugging_and_common_pitfalls.ipynb](notebooks/17_debugging_and_common_pitfalls.ipynb) | Interactive Debugging and Pitfalls | 8 live error tracebacks and verified fixes across syntax, circuit architecture, and physics rules | Intermediate |
| [18_debugging_challenges.ipynb](notebooks/18_debugging_challenges.ipynb) | Circuit Debugging Challenges | 5 hands-on code diagnostic challenges: fixing probabilities, sampling, unitarity, branches, and cloning | All Levels |
| [19_capstone_quantum_emotion_model.ipynb](notebooks/19_capstone_quantum_emotion_model.ipynb) | Capstone Model: Affective Dynamics | Full-stack live demo: Valence on Bloch sphere, `BellModule` empathy, feedforward regulation, and 100-agent crowd scaling | All Levels |
| [practice_exercises.ipynb](notebooks/practice_exercises.ipynb) | Student Practice Workbook | 5 challenge problems covering superposition, oracles, and search | All Levels |
| [practice_solutions.ipynb](notebooks/practice_solutions.ipynb) | Practice Solutions | Complete reference solutions and output verifications | All Levels |

---

# 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.
- **Simulation Boundaries**: Mathematical limits of classical simulation, Area-Law vs Volume-Law entanglement, and quantum advantage.
- **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
pip install "mkdocs-material>=9.0" "mkdocstrings[python]>=0.20"
mkdocs serve
```

---

# Package Architecture

```
src/quantum_emotion/
├── core/
│   ├── state.py         # KetState and BraState register abstractions
│   ├── gates.py         # CircuitOp, BaseGate, CompositeGate
│   └── measurement.py   # Measure, ClassicallyControlledGate, .c_if()
├── gates/
│   ├── single_qubit.py  # PauliX, PauliY, PauliZ, Hadamard, PhaseGate, SGate, TGate
│   └── multi_qubit.py   # CNOT, ControlledY, ControlledZ
└── _register/
    └── core_register.py # Tensor network contraction engine via cotengra
```

---

# License

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