discopy/discopy
The Python toolkit for computing with string diagrams.
What it solves
DisCoPy provides a way to compute with string diagrams, which are graphical representations of morphisms in monoidal categories. It allows users to model complex systems—such as natural language grammars, quantum circuits, and recipe steps—as diagrams that can be composed, rewritten, and evaluated into concrete mathematical objects like tensors or functions.
How it works
The toolkit implements a hierarchy of category theory concepts (Category, MonoidalCategory, etc.) using Python. It uses a Diagram data structure composed of layers of boxes and wires. These diagrams can be transformed via Functors, which map the abstract diagrams to concrete implementations. For example, a tensor-valued functor can evaluate a diagram as a tensor network using libraries like PyTorch, NumPy, or JAX.
Who it’s for
It is designed for researchers and practitioners in applied category theory, quantum computer science, and computational linguistics (specifically those working with compositional distributional models like DisCoCat).
Highlights
- Multi-backend Tensor Support: Evaluates diagrams into tensor networks using NumPy, PyTorch, TensorFlow, JAX, and others.
- C-Grammar Integration: Implements context-free, categorial, pregroup, and dependency grammars with interfaces to spaCy and NLTK.
- Quantum Computing Tools: Interfaces with tket for circuit compilation and PyZX for ZX-calculus optimization.
- Diverse Data Structures: Supports lambda terms (
Term), combinatorial maps (CMap), and hypergraphs for different categorical structures.
Related
- Project
- Project
- Project
- Project
- Project