Skip to content

Commit

Permalink
cleanup imgs
Browse files Browse the repository at this point in the history
  • Loading branch information
toumix committed Dec 4, 2022
1 parent 6044cc5 commit f4cbdb8
Show file tree
Hide file tree
Showing 29 changed files with 37 additions and 23 deletions.
2 changes: 1 addition & 1 deletion discopy/monoidal.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
>>> assert s0 @ s1 == s0 >> s1 == (s1 @ s0).interchange(0, 1)
>>> assert s1 @ s0 == s1 >> s0 == (s0 @ s1).interchange(0, 1)
.. image:: /imgs/EckmannHilton.gif
.. image:: /imgs/monoidal/EckmannHilton.gif
:align: center
"""

Expand Down
9 changes: 4 additions & 5 deletions discopy/quantum/optics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
Example
-------
>>> from discopy.quantum.optics import zx2path
>>> from discopy.quantum.zx import Z
>>> from discopy import drawing
>>> drawing.equation(Z(2, 1), zx2path(Z(2, 1)), symbol='->',
>>> drawing.equation(Z(2, 1), zx2path(Z(2, 1)), symbol='$\\mapsto$',
... draw_type_labels=False, figsize=(6, 4),
... path='docs/imgs/optics-fusion.png')
... path='docs/imgs/optics/fusion.png')
.. image:: /imgs/optics-fusion.png
.. image:: /imgs/optics/fusion.png
:align: center
"""

Expand Down Expand Up @@ -1040,7 +1039,7 @@ def make_spiders(cls, n_legs_in, n_legs_out, phase=0):
>>> equation(orig, decomp, symbol='->',
... path='docs/imgs/spider-decomp.png')
.. image:: /imgs/spider-decomp.png
.. image:: /imgs/optics/spider-decomp.png
:align: center
"""
Expand Down
41 changes: 28 additions & 13 deletions discopy/quantum/zx.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,34 @@
Scalar
"""

from discopy import messages, cat, rigid, frobenius, quantum
from math import pi

from discopy import messages, cat, rigid, tensor, quantum
from discopy.cat import factory
from discopy.rigid import Sum, PRO
from discopy.frobenius import Functor, Category
from discopy.quantum.circuit import Circuit, qubit
from discopy.quantum.gates import (
Bra, Ket, Rz, Rx, Ry, CX, CZ, CRz, CRx, Controlled, format_number)
from discopy.quantum.gates import Scalar as GatesScalar
from math import pi
from discopy.utils import factory_name


@factory
class Diagram(frobenius.Diagram):
class Diagram(tensor.Diagram):
""" ZX Diagram. """
ty_factory = PRO

@staticmethod
def swap(left, right):
left = left if isinstance(left, PRO) else PRO(left)
right = right if isinstance(right, PRO) else PRO(right)
return frobenius.Diagram.swap.__func__(Diagram, left, right)
return tensor.Diagram.swap.__func__(Diagram, left, right)

@staticmethod
def permutation(perm, dom=None):
dom = PRO(len(perm)) if dom is None else dom
return frobenius.Diagram.permutation.__func__(Diagram, perm, dom)
return tensor.Diagram.permutation.__func__(Diagram, perm, dom)

@staticmethod
def cup_factory(left, right):
Expand Down Expand Up @@ -222,7 +224,7 @@ def make_wires_adjacent(scan, diagram, inputs):
return diagram


class Box(frobenius.Box, Diagram):
class Box(tensor.Box, Diagram):
"""
A ZX box is a tensor box in a ZX diagram.
Expand All @@ -231,26 +233,39 @@ class Box(frobenius.Box, Diagram):
dom (rigid.PRO) : The domain of the box, i.e. its input.
cod (rigid.PRO) : The codomain of the box, i.e. its output.
"""
__ambiguous_inheritance__ = (frobenius.Box, )
__ambiguous_inheritance__ = (tensor.Box, )


class Swap(frobenius.Swap, Box):
class Sum(tensor.Sum, Box):
"""
A formal sum of ZX diagrams with the same domain and codomain.
Parameters:
terms (tuple[Diagram, ...]) : The terms of the formal sum.
dom (Dim) : The domain of the formal sum.
cod (Dim) : The codomain of the formal sum.
"""
__ambiguous_inheritance__ = (tensor.Sum, )


class Swap(tensor.Swap, Box):
""" Swap in a ZX diagram. """
def __repr__(self):
return "SWAP"

__str__ = __repr__


class Spider(frobenius.Spider, Box):
class Spider(tensor.Spider, Box):
""" Abstract spider box. """
def __init__(self, n_legs_in, n_legs_out, phase=0):
super().__init__(n_legs_in, n_legs_out, PRO(1), phase)

def __str__(self):
factory_str = type(self).__name__
phase_str = f", {self.phase}" if self.phase else ""
return f"{factory_str}({len(self.dom)}, {len(self.cod)}{phase_str})"
self.name = f"{factory_str}({n_legs_in}, {n_legs_out}{phase_str})"

def __repr__(self):
return str(self).replace(type(self).__name__, factory_name(type(self)))

def subs(self, *args):
phase = cat.rsubs(self.phase, *args)
Expand Down Expand Up @@ -365,5 +380,5 @@ def gate2zx(box):
H.color, H.shape = "yellow", "rectangle"

SWAP = Swap(PRO(1), PRO(1))
Diagram.braid_factory, Diagram.spider_factory = Swap, Spider
Diagram.braid_factory, Diagram.sum_factory = Swap, Sum
Id = Diagram.id
Binary file removed docs/imgs/alice-loves-bob.png
Binary file not shown.
Binary file removed docs/imgs/autonomisation.gif
Binary file not shown.
Binary file removed docs/imgs/bell-state.png
Binary file not shown.
Binary file removed docs/imgs/circuit-normal_form.gif
Binary file not shown.
Binary file removed docs/imgs/crack-eggs.png
Binary file not shown.
Binary file removed docs/imgs/foliate.gif
Binary file not shown.
Binary file removed docs/imgs/jane_boys.gif
Binary file not shown.
Binary file removed docs/imgs/ket-fusion.gif
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
Binary file removed docs/imgs/scalars.gif
Binary file not shown.
Binary file removed docs/imgs/sentence-as-diagram.png
Binary file not shown.
Binary file removed docs/imgs/snake-equation.png
Binary file not shown.
Binary file removed docs/imgs/spiral-normal-form.png
Binary file not shown.
Binary file removed docs/imgs/spiral.png
Binary file not shown.
Binary file removed docs/imgs/typed-snake-equation.png
Binary file not shown.
Binary file removed docs/imgs/who-ansatz.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"source": [
"from discopy import Ty, Box, Id, Diagram\n",
"\n",
"folder = lambda file: '../docs/_static/imgs/' + file\n",
"folder = lambda file: 'imgs/' + file\n",
"params = dict(\n",
" aspect='auto',\n",
" loop=True,\n",
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
4 changes: 2 additions & 2 deletions notebooks/pixels2diagram.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
" linewidth=10,\n",
" path='/Users/alexis.toumi/WORK/TEX/THESIS/img/punkt-und-linie/start.png')\n",
"\n",
"diagram.draw(**params, path='../docs/_static/imgs/test-pixels2diagram.png')\n",
"img = Image.open('../docs/_static/imgs/test-pixels2diagram.png')\n",
"diagram.draw(**params, path='imgs/test-pixels2diagram.png')\n",
"img = Image.open('imgs/test-pixels2diagram.png')\n",
"img"
]
},
Expand Down
2 changes: 1 addition & 1 deletion notebooks/snake-removal.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
"\n",
"print(\"Removing snakes from autonomisation of '{}'\".format(sentences[12]))\n",
"diagrams = list(A(parsing[sentences[12]]).normalize())\n",
"parsing[sentences[12]].to_gif(*diagrams, aspect='auto', path='../docs/imgs/unsnake-sentence.gif')"
"parsing[sentences[12]].to_gif(*diagrams, aspect='auto', path='imgs/unsnake-sentence.gif')"
]
},
{
Expand Down

0 comments on commit f4cbdb8

Please sign in to comment.