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:
pip install quantum-emotion
Or installed locally in editable mode:
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}$:
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/ directory:
| Notebook | Topic | Key Concepts | Level |
|---|---|---|---|
| 0_ground_zero_quickstart.ipynb | Ground Zero Quickstart | Register initialization, gate application (@), .eval(), circuit plotting |
Beginner |
| 1_superposition.ipynb | Single Qubit Superposition | Ground state, Hadamard gate, Born rule, state plotting | Beginner |
| 2_bell_states.ipynb | Bell States and Entanglement | Bell pairs, circuit diagrams, BraState inner products | Beginner |
| 3_deutsch_algorithm.ipynb | Deutsch Algorithm | Constant vs balanced oracles, phase kickback | Intermediate |
| 4_bernstein_vazirani.ipynb | Bernstein-Vazirani | Single-query hidden bitstring recovery, N-qubit scaling | Intermediate |
| 5_quantum_teleportation.ipynb | Quantum Teleportation | EPR pairs, mid-circuit measurement, classical feedforward .c_if() |
Intermediate |
| 6_custom_gates_and_modules.ipynb | Custom Gates and Tools | Subclassing BaseGate, continuous rotations, .sqrt, expectation values |
Advanced |
| 7_grovers_search.ipynb | Grover's Search Algorithm | Phase inversion, diffusion operator, amplitude amplification | Advanced |
| 8_quantum_key_distribution.ipynb | Quantum Key Distribution (BB84) | Conjugate bases, key sifting, eavesdropping detection (QBER) | Advanced |
| 9_circuit_modules.ipynb | Modular Circuits | Hierarchical subcircuits, ModularGate, BellModule, QFTModule, decomposed plotting |
Advanced |
| 10_superdense_coding.ipynb | Superdense Coding | Transmit 2 classical bits via 1 qubit using BellModule in satellite communication |
Advanced |
| 11_quantum_phase_estimation.ipynb | Quantum Phase Estimation | Eigenphase estimation for molecular spectroscopy using QFTModule and InverseQFTModule |
Advanced |
| 12_entanglement_swapping.ipynb | Entanglement Swapping | Quantum repeater networks with chained BellModule pairs and feedforward corrections |
Advanced |
| 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 | 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 | 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 | 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 | Interactive Debugging and Pitfalls | 8 live error tracebacks and verified fixes across syntax, circuit architecture, and physics rules | Intermediate |
| 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 | 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 | Student Practice Workbook | 5 challenge problems covering superposition, oracles, and search | All Levels |
| 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/ 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:
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.
Metadata
Release files for quantum-emotion 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| quantum_emotion-1.0.0.tar.gz | 49.1 kB | Without provenance | Details for quantum_emotion-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| quantum_emotion-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for quantum_emotion-1.0.0-py3-none-any.whl |
Total release size: 104.8 kB
Release files / quantum_emotion-1.0.0.tar.gz
| Download URL | quantum_emotion-1.0.0.tar.gz |
|---|---|
| Size | 49.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
843a19ee58c85959915fb8bfd3a134463dbee4aecc39e8a4b900a6411e7de094
|
|
BLAKE2b-256 checksum How to use checksums |
7b5ac3520d9d98f74871811e84de2357ee74eec4eab16e575b254c61d84b4aab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / quantum_emotion-1.0.0-py3-none-any.whl
| Download URL | quantum_emotion-1.0.0-py3-none-any.whl |
|---|---|
| Size | 55.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5331f50534c8e91ec842d6836e33037a420236744764c9e85dc4482d2bb4994f
|
|
BLAKE2b-256 checksum How to use checksums |
bc9efae15de5d1a97131cd40baa210772762090ab3cc458248e05254954d2221
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for quantum-emotion 1.0.0
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.