Skip to content

Commit

Permalink
Monoidal streams (#276)
Browse files Browse the repository at this point in the history
* Feedback categories

* add broken test

* add streams

* wip

* wip

* wip

* make pylint happy

* add example to docs

* wip

* add random walk example

* more tests

* add fibonacci example

* make pylint happy

* fix type error

* add signatures

* add copy

* add feedback and stream to dcos

* add docs

* wip

* Monoidal Streams

* rm streams

* rm test

* add axioms

* make pylint happy

* more axioms

* Implementing stuff together

* Implementing stuff together

* fix singleton

* refactor

* add unroll docs

* implement Stream.feedback

* wip

* Add then, tensor, swap and copy to `Stream`

* One must imagine pylint happy

* broken test

* nailing feedback

* feedback example

* refactor

* .later() -> .later

* wip

* Merge branch 'feedback' into streams

* merge back

* implement Diagram.head and tail

* add broken test

* wip

* add feedback example to docs

* tikz

* clean up

* add functor example

* add more tests

* better tests

* better docs

* add tests for tensor and composition

* fix Stream.then

* random walk passes

* Fix Function.call and a related test

* Fix test_Funciton

* Fix test_fixed_point

* pass walks

* dcl -> d

* use with

* Make flake8 happy

* Fix unroll of constant

* add docs

* Merge branch 'feedback' into streams

* add tests back

* missing import

* make fibonacci pass

* fix notebooks

* more docs

* better docs

* better docs

* better docs

* add fibonacci to docs

* more tests, more docs

* better docs

* more docs

* more docs

* add index

* more docs

* move interaction to semantics

* format docs

* add random walk to docs

* more docs, cleanup tests

---------

Co-authored-by: Boldi <boldar99@gmail.com>
Co-authored-by: Richie Yeung <richie.yeung1@gmail.com>
  • Loading branch information
3 people committed Apr 13, 2024
1 parent 5fe5a70 commit c6815c6
Show file tree
Hide file tree
Showing 31 changed files with 925 additions and 95 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,8 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
run: |
sphinx-build ${{ env.DOCS_DIR }} ${{ env.DOCS_DIR }}/_build/html
- name: Upload
uses: actions/upload-artifact@v4
with:
name: docs
path: ${{ env.DOCS_DIR }}/_build/html # or path/to/artifact
1 change: 1 addition & 0 deletions discopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
hypergraph,
interaction,
feedback,
stream,
python,
matrix,
tensor,
Expand Down
6 changes: 5 additions & 1 deletion discopy/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
assert_isinstance,
assert_iscomposable,
assert_isparallel,
get_origin,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -860,7 +861,10 @@ def __repr__(self):

def __call__(self, other):
if isinstance(other, Ob):
return self.ob[other]
result, origin = self.ob[other], get_origin(self.cod.ob)
if isinstance(result, origin):
return result
return (result, ) if origin == tuple else self.cod.ob(result)
if isinstance(other, Sum):
return sum(map(self, other.terms),
self.cod.ar.zero(self(other.dom), self(other.cod)))
Expand Down
10 changes: 7 additions & 3 deletions discopy/compact.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
>>> Diagram.use_hypergraph_equality = True
>>> x, y = Ty('x'), Ty('y')
* Snake equations:
Snake equations
===============
>>> snake = Equation(Id(x.l).transpose(left=True), Id(x), Id(x.r).transpose())
>>> assert snake
Expand All @@ -35,7 +36,9 @@
.. image:: /_static/compact/snake.png
:align: center
* Yanking (a.k.a. Reidemeister move 1):
Yanking
=======
a.k.a. Reidemeister move 1
>>> right_loop = x @ Cap(x, x.r) >> Swap(x, x) @ x.r >> x @ Cup(x, x.r)
>>> left_loop = Cap(x.r, x) @ x >> x.r @ Swap(x, x) >> Cup(x.r, x) @ x
Expand All @@ -55,7 +58,8 @@
.. image:: /_static/compact/yanking_cup_and_cap.png
:align: center
* Coherence:
Coherence
=========
>>> assert Diagram.caps(x @ y, y.r @ x.r)\\
... == Cap(x, x.r) @ Cap(y, y.r) >> x @ Diagram.swap(x.r, y @ y.r)
Expand Down

0 comments on commit c6815c6

Please sign in to comment.