using Catlab.WiringDiagrams using Catlab.Graphics import Catlab.Graphics: Graphviz show_diagram(d::WiringDiagram) = to_graphviz(d, orientation=LeftToRight, labels=true, label_attr=:xlabel, node_attrs=Graphviz.Attributes( :fontname => "Courier", ), edge_attrs=Graphviz.Attributes( :fontname => "Courier", ) ) using Catlab.Theories A, B, C, D = Ob(FreeBiproductCategory, :A, :B, :C, :D) f = Hom(:f, A, B) g = Hom(:g, B, C) h = Hom(:h, C, D) f f, g, h = to_wiring_diagram(f), to_wiring_diagram(g), to_wiring_diagram(h) f show_diagram(f) compose(f,g) show_diagram(compose(f,g)) otimes(f,h) show_diagram(otimes(f,h)) mcopy(codom(f),2) show_diagram(mcopy(codom(f),2)) show_diagram(compose(f, mcopy(codom(f),2))) show_diagram(compose(mcopy(dom(f),2), otimes(f,f))) f = Box(:f, [:A], [:B]) g = Box(:g, [:B], [:C]) h = Box(:h, [:C], [:D]) f d = WiringDiagram([:A], [:C]) fv = add_box!(d, f) gv = add_box!(d, g) add_wires!(d, [ (input_id(d),1) => (fv,1), (fv,1) => (gv,1), (gv,1) => (output_id(d),1), ]) nboxes(d) nwires(d) d show_diagram(d) d = WiringDiagram([:A,:C], [:B,:D]) fv = add_box!(d, f) hv = add_box!(d, h) add_wires!(d, [ (input_id(d),1) => (fv,1), (input_id(d),2) => (hv,1), (fv,1) => (output_id(d),1), (hv,1) => (output_id(d),2), ]) d show_diagram(d)