Name | discopy JSON |
Version |
1.1.7
JSON |
| download |
home_page | None |
Summary | The Python toolkit for computing with string diagrams. |
upload_time | 2024-03-20 09:19:51 |
maintainer | None |
docs_url | None |
author | DisCoPy |
requires_python | >=3.9 |
license | BSD 3-Clause License Copyright (c) 2019-2022, DisCoPy All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
keywords |
category theory
string diagrams
natural language processing
quantum computing
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/discopy/discopy/raw/main/docs/_static/snake-equation-dark.svg">
<img alt="Snake equation" width="60%" src="https://github.com/discopy/discopy/raw/main/docs/_static/snake-equation.svg">
</picture>
# DisCoPy
[![build](https://github.com/discopy/discopy/actions/workflows/build.yml/badge.svg)](https://github.com/discopy/discopy/actions/workflows/build.yml)
[![readthedocs](https://readthedocs.org/projects/discopy/badge/?version=main)](https://docs.discopy.org/)
[![PyPI version](https://badge.fury.io/py/discopy.svg)](https://badge.fury.io/py/discopy)
[![DOI: 10.4204/EPTCS.333.13](http://img.shields.io/badge/DOI-10.4204/EPTCS.333.13-brightgreen.svg)](https://doi.org/10.4204/EPTCS.333.13)
DisCoPy is a Python toolkit for computing with [string diagrams](https://en.wikipedia.org/wiki/String_diagram).
* **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](https://en.wikipedia.org/wiki/DisCoCat) and [QNLP](https://en.wikipedia.org/wiki/Quantum_natural_language_processing). This has now become its own library: [lambeq](https://cqcl.github.io/lambeq).
## Features
* an `Arrow` data structure for free [dagger categories](https://en.wikipedia.org/wiki/Dagger_category) with formal sums, unary operators and symbolic variables from [SymPy](https://www.sympy.org/en/index.html)
* a `Diagram` data structure for planar string diagrams in any ([pre](https://ncatlab.org/nlab/show/premonoidal+category))[monoidal category](https://en.wikipedia.org/wiki/Monoidal_category) in the [hierarchy of graphical languages](https://en.wikipedia.org/wiki/String_diagram#Hierarchy_of_graphical_languages) (with braids, twists, spiders, etc.)
* a `Hypergraph` data structure for string diagrams in hypergraph categories and its restrictions to symmetric, traced, compact and Markov categories
* methods for diagram composition, drawing, rewriting and `Functor` evaluation into:
- Python code, i.e. wires as types and boxes as functions
- [tensor networks](https://en.wikipedia.org/wiki/Tensor_network), i.e. wires as dimensions and boxes as arrays from [NumPy](https://numpy.org), [PyTorch](https://pytorch.org/), [TensorFlow](https://www.tensorflow.org/), [TensorNetwork](https://github.com/google/TensorNetwork) and [JAX](https://github.com/google/jax)
* an implementation of [categorical quantum mechanics](https://en.wikipedia.org/wiki/Categorical_quantum_mechanics) interfacing with:
- [tket](https://github.com/CQCL/tket) for circuit compilation
- [PyZX](https://github.com/Quantomatic/pyzx) for optimisation with the [ZX calculus](https://zxcalculus.com/)
- [PennyLane](https://pennylane.ai/) for automatic differentiation
* an implementation of formal grammars ([context-free](https://en.wikipedia.org/wiki/Context-free_grammar), [categorial](https://en.wikipedia.org/wiki/Categorial_grammar), [pregroup](https://en.wikipedia.org/wiki/Pregroup_grammar) or [dependency](https://en.wikipedia.org/wiki/Dependency_grammar)) with interfaces to [lambeq](https://cqcl.github.io/lambeq), [spaCy](https://spacy.io/) and [NLTK](https://www.nltk.org/)
## Example: Cooking
This example is inspired from Pawel Sobocinski's blog post [Crema di Mascarpone and Diagrammatic Reasoning](https://graphicallinearalgebra.net/2015/05/06/crema-di-mascarpone-rules-of-the-game-part-2-and-diagrammatic-reasoning/).
```python
from discopy.symmetric import Ty as Ingredient, Box as Step, Diagram as Recipe
egg, white, yolk = Ingredient("egg"), Ingredient("white"), Ingredient("yolk")
crack = Step("crack", egg, white @ yolk)
merge = lambda x: Step("merge", x @ x, x)
# DisCoPy allows string diagrams to be defined as Python functions
@Recipe.from_callable(egg @ egg, white @ yolk)
def crack_two_eggs(left_egg, right_egg):
left_white, left_yolk = crack(left_egg)
right_white, right_yolk = crack(right_egg)
return (merge(white)(left_white, right_white),
merge(yolk)(left_yolk, right_yolk))
# ... or in point-free style using parallel (@) and sequential (>>) composition
assert crack_two_eggs == crack @ crack\
>> white @ Recipe.swap(yolk, white) @ yolk\
>> merge(white) @ merge(yolk)
crack_two_eggs.draw()
```
![crack_two_eggs.draw()](https://github.com/discopy/discopy/raw/main/test/src/imgs/crack-eggs.png)
## Quickstart
```shell
pip install discopy
```
If you want to see DisCoPy in action, check out the [QNLP tutorial](https://docs.discopy.org/en/main/notebooks/qnlp.html)!
## Contribute
We're keen to welcome new contributors!
First, read the [contributing guidelines](https://github.com/discopy/discopy/blob/main/CONTRIBUTING.md).
Then get in touch on [Discord](https://discopy.org/discord)
or [open an issue](https://github.com/discopy/discopy/issues/new).
## How to cite
If you used DisCoPy in the context of 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](https://doi.org/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](https://arxiv.org/abs/2205.05190)
If you use any of the recent features (e.g. `Hypergraph`) you should also mention:
* A. Toumi, R. Yeung, B. Poór & G. de Felice, _DisCoPy: the Hierarchy of Graphical Languages in Python_ [arXiv:2311.10608](https://arxiv.org/abs/2311.10608)
Raw data
{
"_id": null,
"home_page": null,
"name": "discopy",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "category theory, string diagrams, natural language processing, quantum computing",
"author": "DisCoPy",
"author_email": "contact@discopy.org",
"download_url": "https://files.pythonhosted.org/packages/63/2a/2f1ac02e8d389ffebbcf83b757084d39c866434b56190b51e337e633ffb3/discopy-1.1.7.tar.gz",
"platform": null,
"description": "<picture>\n <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://github.com/discopy/discopy/raw/main/docs/_static/snake-equation-dark.svg\">\n <img alt=\"Snake equation\" width=\"60%\" src=\"https://github.com/discopy/discopy/raw/main/docs/_static/snake-equation.svg\">\n</picture>\n\n# DisCoPy\n\n[![build](https://github.com/discopy/discopy/actions/workflows/build.yml/badge.svg)](https://github.com/discopy/discopy/actions/workflows/build.yml)\n[![readthedocs](https://readthedocs.org/projects/discopy/badge/?version=main)](https://docs.discopy.org/)\n[![PyPI version](https://badge.fury.io/py/discopy.svg)](https://badge.fury.io/py/discopy)\n[![DOI: 10.4204/EPTCS.333.13](http://img.shields.io/badge/DOI-10.4204/EPTCS.333.13-brightgreen.svg)](https://doi.org/10.4204/EPTCS.333.13)\n\nDisCoPy is a Python toolkit for computing with [string diagrams](https://en.wikipedia.org/wiki/String_diagram).\n\n* **Organisation:** <https://discopy.org>\n* **Documentation:** <https://docs.discopy.org>\n* **Source code:** <https://github.com/discopy/discopy>\n* **Paper (for applied category theorists):** <https://doi.org/10.4204/EPTCS.333.13>\n* **Paper (for quantum computer scientists):** <https://arxiv.org/abs/2205.05190>\n\nDisCoPy began as an implementation of [DisCoCat](https://en.wikipedia.org/wiki/DisCoCat) and [QNLP](https://en.wikipedia.org/wiki/Quantum_natural_language_processing). This has now become its own library: [lambeq](https://cqcl.github.io/lambeq).\n\n## Features\n\n* an `Arrow` data structure for free [dagger categories](https://en.wikipedia.org/wiki/Dagger_category) with formal sums, unary operators and symbolic variables from [SymPy](https://www.sympy.org/en/index.html)\n* a `Diagram` data structure for planar string diagrams in any ([pre](https://ncatlab.org/nlab/show/premonoidal+category))[monoidal category](https://en.wikipedia.org/wiki/Monoidal_category) in the [hierarchy of graphical languages](https://en.wikipedia.org/wiki/String_diagram#Hierarchy_of_graphical_languages) (with braids, twists, spiders, etc.)\n* a `Hypergraph` data structure for string diagrams in hypergraph categories and its restrictions to symmetric, traced, compact and Markov categories\n* methods for diagram composition, drawing, rewriting and `Functor` evaluation into:\n - Python code, i.e. wires as types and boxes as functions\n - [tensor networks](https://en.wikipedia.org/wiki/Tensor_network), i.e. wires as dimensions and boxes as arrays from [NumPy](https://numpy.org), [PyTorch](https://pytorch.org/), [TensorFlow](https://www.tensorflow.org/), [TensorNetwork](https://github.com/google/TensorNetwork) and [JAX](https://github.com/google/jax)\n* an implementation of [categorical quantum mechanics](https://en.wikipedia.org/wiki/Categorical_quantum_mechanics) interfacing with:\n - [tket](https://github.com/CQCL/tket) for circuit compilation\n - [PyZX](https://github.com/Quantomatic/pyzx) for optimisation with the [ZX calculus](https://zxcalculus.com/)\n - [PennyLane](https://pennylane.ai/) for automatic differentiation\n* an implementation of formal grammars ([context-free](https://en.wikipedia.org/wiki/Context-free_grammar), [categorial](https://en.wikipedia.org/wiki/Categorial_grammar), [pregroup](https://en.wikipedia.org/wiki/Pregroup_grammar) or [dependency](https://en.wikipedia.org/wiki/Dependency_grammar)) with interfaces to [lambeq](https://cqcl.github.io/lambeq), [spaCy](https://spacy.io/) and [NLTK](https://www.nltk.org/)\n\n## Example: Cooking\n\nThis example is inspired from Pawel Sobocinski's blog post [Crema di Mascarpone and Diagrammatic Reasoning](https://graphicallinearalgebra.net/2015/05/06/crema-di-mascarpone-rules-of-the-game-part-2-and-diagrammatic-reasoning/).\n\n```python\nfrom discopy.symmetric import Ty as Ingredient, Box as Step, Diagram as Recipe\n\negg, white, yolk = Ingredient(\"egg\"), Ingredient(\"white\"), Ingredient(\"yolk\")\ncrack = Step(\"crack\", egg, white @ yolk)\nmerge = lambda x: Step(\"merge\", x @ x, x)\n\n# DisCoPy allows string diagrams to be defined as Python functions\n\n@Recipe.from_callable(egg @ egg, white @ yolk)\ndef crack_two_eggs(left_egg, right_egg):\n left_white, left_yolk = crack(left_egg)\n right_white, right_yolk = crack(right_egg)\n return (merge(white)(left_white, right_white),\n merge(yolk)(left_yolk, right_yolk))\n\n# ... or in point-free style using parallel (@) and sequential (>>) composition\n\nassert crack_two_eggs == crack @ crack\\\n >> white @ Recipe.swap(yolk, white) @ yolk\\\n >> merge(white) @ merge(yolk)\n\ncrack_two_eggs.draw()\n```\n\n![crack_two_eggs.draw()](https://github.com/discopy/discopy/raw/main/test/src/imgs/crack-eggs.png)\n\n## Quickstart\n\n```shell\npip install discopy\n```\n\nIf you want to see DisCoPy in action, check out the [QNLP tutorial](https://docs.discopy.org/en/main/notebooks/qnlp.html)!\n\n## Contribute\n\nWe're keen to welcome new contributors!\n\nFirst, read the [contributing guidelines](https://github.com/discopy/discopy/blob/main/CONTRIBUTING.md).\nThen get in touch on [Discord](https://discopy.org/discord)\nor [open an issue](https://github.com/discopy/discopy/issues/new).\n\n## How to cite\n\nIf you used DisCoPy in the context of an academic publication, we suggest you cite:\n\n* G. de Felice, A. Toumi & B. Coecke, _DisCoPy: Monoidal Categories in Python_, EPTCS 333, 2021, pp. 183-197, [DOI: 10.4204/EPTCS.333.13](https://doi.org/10.4204/EPTCS.333.13)\n\nIf furthermore your work is related to quantum computing, you can also cite:\n\n* A. Toumi, G. de Felice & R. Yeung, _DisCoPy for the quantum computer scientist_, [arXiv:2205.05190](https://arxiv.org/abs/2205.05190)\n\nIf you use any of the recent features (e.g. `Hypergraph`) you should also mention:\n\n* A. Toumi, R. Yeung, B. Po\u00f3r & G. de Felice, _DisCoPy: the Hierarchy of Graphical Languages in Python_ [arXiv:2311.10608](https://arxiv.org/abs/2311.10608)\n",
"bugtrack_url": null,
"license": "BSD 3-Clause License Copyright (c) 2019-2022, DisCoPy All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ",
"summary": "The Python toolkit for computing with string diagrams.",
"version": "1.1.7",
"project_urls": {
"Documentation": "https://docs.discopy.org",
"Download": "https://pypi.org/project/discopy",
"Homepage": "https://discopy.org",
"Issue-Tracker": "https://github.com/discopy/discopy/issues",
"Repository": "https://github.com/discopy/discopy"
},
"split_keywords": [
"category theory",
" string diagrams",
" natural language processing",
" quantum computing"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "549801f757e159ee17d8606081ab6113f32489bdcd541892502b4d8eeb24d15d",
"md5": "564e54235677837dfe530414cedcbe88",
"sha256": "1fe0027f6d48e1894cdc2fbc4beb2e0601c136cccc8561a30561f3b2c69b58c9"
},
"downloads": -1,
"filename": "discopy-1.1.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "564e54235677837dfe530414cedcbe88",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 149009,
"upload_time": "2024-03-20T09:19:48",
"upload_time_iso_8601": "2024-03-20T09:19:48.451593Z",
"url": "https://files.pythonhosted.org/packages/54/98/01f757e159ee17d8606081ab6113f32489bdcd541892502b4d8eeb24d15d/discopy-1.1.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "632a2f1ac02e8d389ffebbcf83b757084d39c866434b56190b51e337e633ffb3",
"md5": "69ddb1472496b111d761dc434e508cf1",
"sha256": "fe85080704a06994c2c25fea8da8da237d0b966fafedf01b264a1a859cfd1bc2"
},
"downloads": -1,
"filename": "discopy-1.1.7.tar.gz",
"has_sig": false,
"md5_digest": "69ddb1472496b111d761dc434e508cf1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 3659238,
"upload_time": "2024-03-20T09:19:51",
"upload_time_iso_8601": "2024-03-20T09:19:51.669129Z",
"url": "https://files.pythonhosted.org/packages/63/2a/2f1ac02e8d389ffebbcf83b757084d39c866434b56190b51e337e633ffb3/discopy-1.1.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-20 09:19:51",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "discopy",
"github_project": "discopy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "discopy"
}