Skip to main content

Tests Docs PyPI version

Logo

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 and grouped into Beginner, Intermediate, Advanced, and Practice & Debugging tracks:

Beginner

Notebook Topic Key Concepts
0_getting_started.ipynb Getting Started KetState, @ operator, .eval(), .plot(), Measure
1_superposition.ipynb Superposition Ground state, Hadamard gate, probabilities, reversibility
2_bell_states.ipynb Bell States and Entanglement Bell pairs, circuit diagrams, BraState inner products, GHZ
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 Deutsch's Algorithm Constant vs balanced oracles, phase kickback
4_bernstein_vazirani.ipynb Bernstein-Vazirani Single-query hidden bitstring recovery, N-qubit scaling
5_quantum_teleportation.ipynb Quantum Teleportation EPR pairs, mid-circuit measurement, .c_if()
6_custom_gates_and_modules.ipynb Custom Gates and Rotations Subclassing BaseGate, continuous rotations, .sqrt, Toffoli
8_quantum_key_distribution.ipynb Quantum Key Distribution (BB84) Conjugate bases, key sifting, eavesdropping detection
9_circuit_modules.ipynb Modular Circuits Subcircuits, ModularGate, BellModule, SwapModule, QFTModule

Advanced

Notebook Topic Key Concepts
7_grovers_search.ipynb Grover's Search Phase inversion, diffusion operator, amplitude amplification
10_superdense_coding.ipynb Superdense Coding Send 2 classical bits via 1 qubit using BellModule + noise
11_quantum_phase_estimation.ipynb Quantum Phase Estimation Eigenphase estimation using QFTModule and InverseQFTModule
12_entanglement_swapping.ipynb Entanglement Swapping Chained BellModule pairs and .c_if() corrections
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 Common Mistakes and Fixes 8 common errors with tracebacks and fixes
15_fix_the_bug.ipynb Debugging Exercises 5 short buggy snippets to diagnose and fix
practice_exercises.ipynb Practice Exercises 5 problems covering superposition, Bell states, oracles, and rotations
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/ 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:

uv sync --extra docs
uv run mkdocs serve

Package Architecture

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.

Metadata

Release files for quantum-emotion 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quantum-emotion 1.0.1
File Size Uploaded Provenance Actions
quantum_emotion-1.0.1.tar.gz 49.1 kB Without provenance Details for quantum_emotion-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for quantum-emotion 1.0.1
File Interpreter ABI Platform Actions
quantum_emotion-1.0.1-py3-none-any.whl Python 3 none any Details for quantum_emotion-1.0.1-py3-none-any.whl

Total release size: 104.8 kB

Release files / quantum_emotion-1.0.1.tar.gz

Download URL quantum_emotion-1.0.1.tar.gz
Size 49.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5ca39c4abb1701b662bfe69b4e655aff10c7245ef8333db7beaa383809250e2a
BLAKE2b-256 checksum
How to use checksums
cda4cc776ab352356a7dcf17c3e74ba326ad8266e94c5d1708235b7139f23a1b
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.1-py3-none-any.whl

Download URL quantum_emotion-1.0.1-py3-none-any.whl
Size 55.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5ad5c2fd7ff6d783c3c6c36ce9b2295b8e00665f46bdf0f0f9fb998580e7ab9
BLAKE2b-256 checksum
How to use checksums
fda8bb20a7aa09e84cf371876341f3e451882eb2da7427d26ea173ecb59232d5
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.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page