DisCoPy is a Python toolkit for computing with string diagrams.
- Organisation: https://discopy.org
- Documentation: https://docs.discopy.org
- Source code: https://github.com/discopy/discopy
- Paper (for applied category theorists): https://doi.org/10.4204/EPTCS.333.13
- Paper (for quantum computer scientists): https://arxiv.org/abs/2205.05190
DisCoPy began as an implementation of DisCoCat and QNLP. This has now become its own library: lambeq.
- a data structure for arrows in free dagger categories with formal sums, unary operators and symbolic variables from SymPy
- data structures for string diagrams in any (pre)monoidal category in the hierarchy of graphical languages (braids, twists, spiders, etc.)
- methods for diagram composition, drawing, rewriting and evaluation as:
- Python code, i.e. wires as types and boxes as functions
- tensor networks, i.e. wires as dimensions and boxes as arrays from NumPy, PyTorch, TensorFlow, TensorNetwork and JAX
- an implementation of categorical quantum mechanics interfacing with:
- tket for circuit compilation
- PyZX for optimisation with the ZX calculus
- PennyLane for automatic differentiation
- an implementation of formal grammars (context-free, categorial, pregroup or dependency) with interfaces to lambeq, spaCy and NLTK
Software dependencies between modules go top-to-bottom, left-to-right and forgetful functors between categories go the other way.
pip install discopy
If you want the bleeding edge, you can install DisCoPy locally:
git clone https://github.com/discopy/discopy.git
cd discopy
pip install .
You should check you haven't broken anything by running the test suite:
pip install ".[test]" .
coverage run -m pytest --doctest-modules --pycodestyle
coverage report -m discopy/*.py discopy/*/*.py
The documentation is built using sphinx. You can build it locally with:
pip install ".[docs]" .
sphinx-build docs docs/_build/html
Contributions are welcome, please get in touch or open an issue.
If you wish to cite DisCoPy in an academic publication, we suggest you cite:
- G. de Felice, A. Toumi & B. Coecke, DisCoPy: Monoidal Categories in Python, EPTCS 333, 2021, pp. 183-197, DOI: 10.4204/EPTCS.333.13
If furthermore your work is related to quantum computing, you can also cite:
- A. Toumi, G. de Felice & R. Yeung, DisCoPy for the quantum computer scientist, arXiv:2205.05190