A representation of the “internal wiring” of string diagrams. Bipartite multigraphs have edge labels corresponding to the “ports” of operations, and node labels either generating objects or generating operations of a signature Σ.

As with other classes, these graphs are implemented with an abstract base class AbstractBipartiteMultigraph, whose concrete instantiations choose a backend. For example, BipartiteMultigraph are backed by numpy arrays.

class yarrow.bipartite_multigraph.AbstractBipartiteMultigraph(wi, wo, xi, xo, wn, pi, po, xn)

The type of bipartite multigraphs, parametrised by cls._Fun, the underlying representation of finite functions

__init__(wi, wo, xi, xo, wn, pi, po, xn)

Create a BipartiteMultigraph from its component finite functions. For more details see [WZ23], Section 3.2.

property W




property Ei



The number of input edges in the graph

property Eo

Returns: The number of output edges in the graph

property X

Returns: int: Corresponds to G(X), the number of generating operations in the diagram

classmethod empty(wn, xn)
  • wn – Finite function typed 0 → Σ₀

  • xn – Finite function typed 0 → Σ₁


The empty bipartite multigraph with no edges and no nodes.

Return type:


classmethod discrete(wn: AbstractFiniteFunction, xn: AbstractFiniteFunction)

Create the discrete graph of n wires for a given monoidal signature Σ whose maps are all initial except for wn.

  • wn – An array of wire labels as a finite function typed n → Σ₀

  • xn – The type of operations as an empty finite function typed 0 → Σ₁


Compute the coproduct of bipartite multigraphs


g – an arbitrary AbstractBipartiteMultigraph over the same signature


The coproduct self + g.

classmethod coproduct_list(Gs: List[AbstractBipartiteMultigraph], wn=None, xn=None)

Compute the coproduct of a list of bipartite multigraphs. O(n) in the size of the result.


Does not speed up to O(log n) in the parallel case.

coequalize_wires(q: AbstractFiniteFunction)

Apply a morphism α of bipartite multigraphs whose only non-identity component α_W = q for some coequalizer q.


q – An AbstractFiniteFunction which is a coequalizer.


The bipartite multigraph equal to the target of α.

Return type:


yarrow.bipartite_multigraph.universal(q: AbstractFiniteFunction, f: AbstractFiniteFunction)

Given a coequalizer q : B → Q of morphisms a, b : A → B and some f : B → B’ such that f(a) = f(b), Compute the universal map u : Q → B’ such that q ; u = f.