discopy
БесплатноБез исполняемых скриптовНе проверенDisCoPy: Python library for computing with string diagrams - monoidal
от plurigrid★ 73 звезды на GitHubОб этом скилле
DisCoPy: String Diagrams in Python
"String diagrams are the syntax, functors are the semantics."
bmorphism Contributions
"all is bidirectional" — @bmorphism, Play/Coplay gist
Active Inference Implementation: DisCoPy provides the foundation for implementing Active Inference in String Diagrams (Tull, Kleiner, Smithe). The paper's core insight — that perception and action form a bidirectional loop — maps directly to DisCoPy's composition operators:
- Sequential (
>>) → temporal flow (action → perception → action) - Parallel (
@) → concurrent sensory channels - Dagger (
[::-1]) → time reversal (perception as action's adjoint)
Categorical Cybernetics: DisCoPy's parametrised optics implement the cybernetic lens pattern from Towards Foundations of Categorical Cybernetics, enabling the Play/Coplay duality bmorphism references.
String Diagram Coloring: Gay.jl colors can be applied to DisCoPy diagrams for deterministic visualization — each wire type gets a consistent color from the splittable RNG.
Overview
DisCoPy is a Python library for computing with string diagrams - the graphical language of monoidal categories. It provides:
- Categorical Framework: Ty, Ob, Box, Arrow, Diagram, Category
- Operads: CFG as free operads, operad algebras, colored operads
- Quantum Computing: Circuits, gates, ZX-calculus, pytket/qiskit integration
- QNLP: Pregroup grammars, DisCoCat, ansätze for quantum NLP
- Tensor Networks: NumPy/JAX/PyTorch backends, tensornetwork contraction
- Visualization: Matplotlib/TikZ drawing with color customization
Core Architecture (DeepWiki 2025-12-22)
Class Hierarchy
Category
├── ob: Ob (objects/systems)
└── ar: Arrow (morphisms/processes)
Ob → Ty (monoidal: tuple of objects, tensor = concatenation)
Arrow → Diagram (monoidal: boxes + offsets, parallel composition)
└── Box (atomic operations with dom/cod)
Composition Operators
| Operator | Method | Description |
|---|---|---|
>> |
then |
Sequential: f >> g (f.cod == g.dom) |
@ |
tensor |
Parallel: f @ g (side-by-side) |
[::-1] |
dagger |
Adjoint/reverse |
from discopy.monoidal import Ty, Box, Diagram
x, y, z = Ty('x'), Ty('y'), Ty('z')
f = Box('f', x, y)
g = Box('g', y, z)
# Sequential: x → y → z
sequential = f >> g
# Parallel: x ⊗ y → y ⊗ z
parallel = f @ g
# Both: (f ⊗ id) >> (id ⊗ g)
mixed = f @ Diagram.id(y) >> Diagram.id(y) @ g
Operads (DeepWiki 2025-12-22)
DisCoPy implements operads via discopy.grammar.cfg:
Operad Structure
- Colors:
Tyobjects (types of operations) - Operations:
Treeobjects (composable rules) - Algebras:
Functorfrom free operad to target operad
from discopy.grammar.cfg import Ty, Rule, Word, Tree
# Define colors (types)
n, v, s = Ty('N'), Ty('V'), Ty('S')
vp, np = Ty('VP'), Ty('NP')
# Define operations (rules)
Caesar = Word('Caesar', n)
crossed = Word('crossed', v)
VP = Rule(n @ v, vp)
NP = Rule(Ty('D') @ n, np)
S = Rule(vp @ np, s)
# Build tree (operadic composition)
sentence = S(VP(Caesar, crossed), NP(Word('the', Ty('D')), Word('Rubicon', n)))
# Axioms of multicategories (operads) hold on the nose
Colored Operads
Types (Ty) act as colors - operations can have different input/output colors:
x, y = Ty('x'), Ty('y')
f = Rule(x @ x, x, name='f') # x ⊗ x → x
g = Rule(x @ y, x, name='g') # x ⊗ y → x
h = Rule(y @ x, x, name='h') # y ⊗ x → x
# Operadic composition
assert f(g, h) == Tree(f, *[g, h])
Color Configuration (DeepWiki 2025-12-22)
Default Color Palette
from discopy.config import COLORS
COLORS = {
"white": "#ffffff",
"red": "#e8a5a5",
"green": "#d8f8d8",
"blue": "#776ff3",
"yellow": "#f7f700",
"black": "#000000"
}
ZX-Calculus Colors
from discopy.quantum.zx import Z, X, Y
# Z spiders: GREEN
Z(1, 1, phase=0.5).color # "green"
# X spiders: RED
X(1, 1, phase=0.25).color # "red"
# Y spiders: BLUE
Y(1, 1).color # "blue"
Custom Box Colors
from discopy.monoidal import Ty, Box
x = Ty('x')
blue_box = Box('f', x, x, color="blue")
blue_box.draw()
# Spider with custom color
from discopy.frobenius import Spider
spider = Spider(2, 3, x)
spider.color = "red"
spider.draw_as_spider = True
Drawing API
diagram.draw(
figsize=(8, 6),
color="blue", # Default box color
draw_as_nodes=True, # Draw boxes as nodes
wire_labels=True, # Show type labels on wires
draw_box_labels=True, # Show box names
path="output.png", # Save to file
to_tikz=True # Output TikZ code
)
Quantum Computing (DeepWiki 2025-12-22)
Quantum Circuits
from discopy.quantu
Установить discopy в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл discopy?
DisCoPy: Python library for computing with string diagrams - monoidal
Как установить скилл discopy?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл discopy запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic