xiaohongshu
xiaohongshu
discopy-categorical-computing
Category theory for compositional computing with string diagrams, quantum circuits, and QNLP. Covers monoidal categories, functors, tensor evaluation, and practical applications in quantum natural language processing and diagrammatic reasoning.
Full skill instructions
Use Discopy when you need:
Sweet Spot: Research at the mathematics-computer science interface, QNLP experiments, compositional semantics modeling, and educational tools for category theory.
Not For: Production NLP systems (use spaCy/Transformers), large-scale quantum compilation (use Qiskit/Cirq), or standard ML pipelines (use PyTorch/scikit-learn).
Discopy treats computation as information flow through typed channels:
Text → Parse → Diagram → Functor → Tensor/Circuit → Evaluate → Result
Category (objects + morphisms)
↓
Monoidal (>> sequential, @ parallel)
↓
Symmetric (swap wires)
↓
Rigid (duals)
↓
Compact (cups/caps)
↓
Traced (feedback loops)
Each level adds capabilities while maintaining composition guarantees.
# Sequential composition (then)
f >> g # "f then g"
# Parallel composition (and)
f @ g # "f and g simultaneously"
# Dagger (adjoint/inverse)
f.dagger()
# Tensor product
f.tensor(g)
# Feedback
f.feedback()
# Basic installation
pip install discopy
# With quantum features
pip install discopy[quantum]
# With all backends
pip install discopy[pytorch,tensorflow,jax]
from discopy import Ty, Box
# Define types (objects)
x = Ty('X')
y = Ty('Y')
z = Ty('Z')
# Define operations (morphisms)
f = Box('f', x, y) # f: X → Y
g = Box('g', y, z) # g: Y → Z
# Sequential composition
diagram = f >> g # X → Y → Z
# Parallel composition
parallel = f @ g # X⊗Y → Y⊗Z
# Visualize
diagram.draw()
from discopy.matrix import Functor
import numpy as np
# Define semantics
F = Functor(
ob={x: 2, y: 3, z: 4}, # Dimensions
ar={
f: np.random.rand(3, 2), # Y=3, X=2
g: np.random.rand(4, 3) # Z=4, Y=3
}
)
# Evaluate
result = F(diagram)
print(result.array.shape) # (4, 2)
from discopy.quantum.circuit import Circuit, gates
# Build circuit
circuit = (
gates.H @ Circuit.id(1) # Hadamard on qubit 0
>> gates.CNOT # CNOT on qubits 0,1
>> gates.Rx(0.5) @ gates.Ry(0.3) # Rotations
)
# Visualize
circuit.draw()
# Export to other frameworks
qiskit_circuit = circuit.to_qiskit()
DisCoPy follows a 7-level progression from simple pipelines to formally verified systems.
→ EXAMPLES-L1-L2.md - Basic >> pipelines
→ EXAMPLES-L1-L2.md - Parallel @ + evaluation
→ EXAMPLES-L3-L4.md - Diagram.swap() for routing
→ EXAMPLES-L3-L4.md - Cups, caps, quantum circuits
→ EXAMPLES-L5-L7.md - .trace() for state feedback
→ EXAMPLES-L5-L7.md - GPU acceleration, custom semantics
→ EXAMPLES-L5-L7.md - Proof-carrying code
→ USE-CASES.md - Complete use cases across all levels
# 1. Build diagram (syntax)
diagram = f >> g >> h
# 2. Define functor (semantics)
functor = Functor(ob={...}, ar={...})
# 3. Evaluate
result = functor(diagram)
# 1. Parse text
from discopy.grammar.pregroup import Diagram as Grammar
sentence = parse("Alice loves Bob")
# 2. Convert to quantum
from discopy.quantum.circuit import Functor as CircuitFunctor
to_circuit = CircuitFunctor(word_circuits, grammar_ops)
circuit = to_circuit(sentence)
# 3. Execute
result = circuit.eval()
class DomainFunctor(Functor):
def __init__(self, domain_mappings):
self.mappings = domain_mappings
def __call__(self, diagram):
# Custom interpretation logic
return self.interpret(diagram)
→ REFERENCE.md - Complete API lookup
→ PATTERNS.md - Design patterns and idioms
→ TROUBLESHOOTING.md - Common issues and solutions
→ INTEGRATION.md - Using Discopy with other libraries
❌ Production NLP: Use spaCy, Transformers (Discopy is research-focused) ❌ Large Quantum Circuits: Use Qiskit, Cirq (better optimization) ❌ Standard Deep Learning: Use PyTorch, TensorFlow directly ❌ High-Performance Numerics: Use NumPy, SciPy (less overhead) ❌ Commercial Applications: Wait for hardware maturity (QNLP still experimental)
Discopy inverts traditional programming:
The categorical approach provides:
pip install discopyxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience