-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreaction-networks.tex
2600 lines (2316 loc) · 136 KB
/
reaction-networks.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% A compositional framework for reaction networks
% John Baez and Blake Pollard
% in LaTeX
% 2017/7/26 - 3rd arXiv version
\documentclass{compositionalityarticle}
\usepackage{color}
\usepackage{amsmath,amsthm}
\usepackage{amsfonts,amssymb}
\usepackage[draft]{fixme}
% internal links should be highlighted in blue
\definecolor{myurlcolor}{rgb}{0.6,0,0}
\definecolor{mycitecolor}{rgb}{0,0,0.8}
\definecolor{myrefcolor}{rgb}{0,0,0.8}
%\usepackage[pagebackref]{hyperref}
\usepackage{hyperref}
\hypersetup{colorlinks,
linkcolor=myrefcolor,
citecolor=mycitecolor,
urlcolor=myurlcolor}
\usepackage[all,2cell,cmtip]{xy}
\UseTwocells
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{backgrounds,circuits,circuits.ee.IEC,shapes,fit,matrix}
%\tikzstyle{species}=[circle, fill=none, draw=black,scale=2]
%\tikzstyle{transition}=[rectangle, fill=none, draw=black, scale=1.5]
\tikzstyle{simple}=[-,line width=2.000]
\tikzstyle{arrow}=[-,postaction={decorate},decoration={markings,mark=at position .5 with {\arrow{>}}},line width=1.100]
\pgfdeclarelayer{edgelayer}
\pgfdeclarelayer{nodelayer}
\pgfsetlayers{edgelayer,nodelayer,main}
\tikzstyle{none}=[inner sep=0pt]
% Petri nets
\definecolor{lblue}{rgb}{0,250,255}
\tikzstyle{species}=[circle,fill=yellow,draw=black,scale=1.15]
\tikzstyle{transition}=[rectangle,fill=lblue,draw=black,scale=1.15]
\tikzstyle{inarrow}=[->, >=stealth, shorten >=.03cm,line width=1.5]
\tikzstyle{empty}=[circle,fill=none, draw=none]
\tikzstyle{inputdot}=[circle,fill=purple,draw=purple, scale=.25]
\tikzstyle{inputarrow}=[->,draw=purple, shorten >=.05cm]
\tikzstyle{simple}=[-,draw=purple,line width=1.000]
% famous sets
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
% famous categories
\newcommand{\FinSet}{\mathtt{FinSet}}
\newcommand{\Set}{\mathtt{Set}}
\newcommand{\Knet}{\mathtt{Knet}}
\newcommand{\STnet}{\mathtt{STnet}}
\newcommand{\Petri}{\mathtt{Petri}}
\newcommand{\Cospan}{\mathtt{Cospan}}
\newcommand{\RNet}{\mathtt{RNet}}
\newcommand{\RxNet}{\mathtt{RxNet}}
\newcommand{\Vect}{\mathtt{Vect}}
\newcommand{\Dynam}{\mathtt{Dynam}}
\newcommand{\Mark}{\mathtt{Mark}}
\newcommand{\DetBalMark}{\mathtt{DetBalMark}}
\newcommand{\Rel}{\mathtt{Rel}}
\newcommand{\LinRel}{\mathtt{LinRel}}
\newcommand{\SemiAlgRel}{\mathtt{SemiAlgRel}}
\newcommand{\CC}{\mathtt{C}}
\newcommand{\D}{\mathtt{D}}
\newcommand{\Circ}{\mathtt{Circ}}
\newcommand{\Graph}{\mathtt{Graph}}
% operations
\newcommand*{\darkgraysquare}{\textcolor{gray}{\blacksquare}}
\newcommand*{\vdarkgraysquare}{\textcolor{darkgray}{\blacksquare}}
\newcommand*{\graysquare}{\textcolor{lightgray}{\blacksquare}}
\newcommand{\eval}{\mathrm{eval}}
\let\hom\relax% Set equal to \relax so that LaTeX thinks it's not defined
\DeclareMathOperator{\hom}{Hom}
\newcommand{\maps}{\colon}
\newcommand{\tr}{\mathrm{tr}}
\newcommand{\id}{\mathrm{id}}
\newcommand{\im}{\mathrm{im}}
\newcommand{\vect}[1]{{\R^{#1} \oplus \R^{#1}}}
% arrows
\newcommand{\relto}{\nrightarrow}
% numbered equations
\newcommand{\beq}{\begin{equation}}
\newcommand{\eeq}{\end{equation}}
% inline definitions
\newcommand{\define}[1]{{\bf{\boldmath{#1}}}}
% theorem environments
\newtheoremstyle{compositionality}
{15pt} % Margin above
{15pt} % Margin below
{\normalfont}
{1pt}
{\sffamily\fontfamily{Raleway-TLF}\bfseries}
{.}
{ }
{}
\theoremstyle{compositionality}
\newtheorem{thm}{Theorem}
\newtheorem{unthm}{Unproved ``Theorem''}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\newtheorem{cor}[thm]{Corollary}
\newtheorem{qstn}[thm]{Question}
\newtheorem*{utheorem}{Theorem}
\newtheorem*{ulem}{Lemma}
\newtheorem*{uprop}{Proposition}
\newtheorem*{ucor}{Corollary}
\newtheorem{defn}[thm]{Definition}
\newtheorem{prob}[thm]{Problem}
\newtheorem*{udefn}{defin}
\newtheorem{expl}[thm]{Example}
\newtheorem*{uexample}{Example}
\theoremstyle{remark}
\newtheorem{rem}[thm]{Remark}
\newtheorem{note}[thm]{Note}
\newtheorem*{uremark}{Remark}
\newtheorem*{unote}{Note}
%\numberwithin{equation}{section}
%%%%%%%%%%%% Enumeration via lowercase letters
\renewcommand{\labelenumi}{({\bf \alph{enumi}})}
\renewcommand{\theenumi}{({\bf \alph{enumi}})}
%%%%%%%%%%%% do not number subsections
\setcounter{secnumdepth}{1}
\title{A Compositional Framework for Reaction Networks}
\author[1,2]{John C. Baez}
\author[3]{Blake S. Pollard}
\affil[1]{Department of Mathematics University of California Riverside CA, USA 92521}
\affil[2]{Centre for Quantum Technologies National University of Singapore, Singapore 117543}
\affil[3]{Department of Physics and Astronomy University of California, Riverside CA 92521}
\begin{document}
\maketitle
\begin{abstract}
Reaction networks, or equivalently Petri nets, are a general framework for describing processes in which entities of various kinds interact and turn into other entities. In chemistry, where the reactions are assigned `rate constants', any reaction network gives rise to a nonlinear dynamical system called its `rate equation'. Here we generalize these ideas to `open' reaction networks, which allow entities to flow in and out at certain designated inputs and outputs. We treat open reaction networks as morphisms in a category. Composing two such morphisms connects the outputs of the first to the inputs of the second. We construct a functor sending any open reaction network to its corresponding `open dynamical system'. This provides a compositional framework for studying the dynamics of reaction networks. We then turn to statics: that is, steady state solutions of open dynamical systems. We construct a `black-boxing' functor that sends any open dynamical system to the relation that it imposes between input and output variables in steady states. This extends our earlier work on black-boxing for Markov processes.
\end{abstract}
%\merriweatherlight
% \begin{center}
% {\bf A Compositional Framework for Reaction Networks \\}
% \vspace{0.3cm}
% {\em John\ C.\ Baez \\}
% \vspace{0.3cm}
% {\small
% Department of Mathematics \\
% University of California \\
% Riverside CA, USA 92521 \\ and \\
% Centre for Quantum Technologies \\
% National University of Singapore \\
% Singapore 117543 \\ }
% \vspace{0.4cm}
% {\em Blake S. Pollard \\ }
% \vspace{0.3cm}
% {\small Department of Physics and Astronomy \\
% University of California \\
% Riverside CA 92521 \\ }
% \vspace{0.3cm}
% {\small email: [email protected], [email protected]\\}
% \vspace{0.3cm}
% {\small May 19, 2017}
% \vspace{0.3cm}
% \end{center}
\section{Introduction}
\label{sec:intro}
Reaction networks, first formally defined by Aris \cite{A} in 1965, are a framework
for describing processes whereby entities interact and transform into
other entities. While they first arose in chemistry, and are often called `chemical
reaction networks', their applications are widespread. For example, a basic model of infectious disease, the SIRS model, is described by this reaction network:
\[ S + I \stackrel{\iota}{\longrightarrow} 2 I \qquad
I \stackrel{\rho}{\longrightarrow} R \stackrel{\lambda}{\longrightarrow} S \]
We see here three types of entity, called `species':
\begin{itemize}
\item $S$: \define{susceptible},
\item $I$: \define{infected},
\item $R$: \define{resistant}.
\end{itemize}
We also have three `reactions':
\begin{itemize}
\item $\iota\maps S + I \to 2 I$: \define{infection}, in which a susceptible individual meets an infected one and becomes infected;
\item $\rho\maps I \to R$: \define{recovery}, in which an infected individual gains resistance to the disease;
\item $\lambda\maps R \to S$: \define{loss of resistance}, in which a resistant individual becomes susceptible.
\end{itemize}
In general, a reaction network involves a finite set of species, but reactions go between `complexes', which are finite linear combinations of these species with natural number coefficients. The reaction network is a directed graph whose vertices are certain complexes and whose edges are called `reactions'.
If we attach a positive real number called a `rate constant' to each reaction, a reaction network determines a system of differential equations saying how the concentrations of the species change over time. This system of equations is usually called
the `rate equation'. In the example above, the rate equation is
\beq
\label{SIRS_rate_equation}
\begin{array}{ccl}
\displaystyle{\frac{d S}{d t}} &=& r_\lambda R - r_\iota S I \\ \\
\displaystyle{\frac{d I}{d t}} &=& r_\iota S I - r_\rho I \\ \\
\displaystyle{\frac{d R}{d t}} &=& r_\rho I - r_\lambda R .
\end{array}
\eeq
Here $r_\iota, r_\rho$ and $r_\lambda$ are the rate constants for the three
reactions, and $S, I, R$ now stand for the concentrations of the three species, which are treated in a continuum approximation as smooth functions $S, I, R \maps \R \to [0,\infty)$. The rate equation can be derived from the `law of mass action', which says that any reaction occurs at a rate equal to its rate constant times the product of the concentrations of the species entering it as inputs.
A reaction network is more than just a stepping-stone to its rate equation. Interesting qualitative properties of the rate equation, such as existence and uniqueness of steady state solutions, can often be determined simply by examining the reaction network, independent of any particular choice of rate constants. Results in this direction began with Feinberg and Horn's seminal work in the 1960's \cite{Feinberg,FeinbergHorn}, leading to the Deficiency Zero and Deficiency One Theorems \cite{Feinberg1995a,Feinberg1995b} and more recently to a proof of the Global Attractor Conjecture \cite{Craciun}.
In this paper we present a `compositional framework' for reaction networks: that is, a way to build up a reaction network from smaller pieces, in such a way that its rate equation can be determined from those of the pieces. However, this framework requires that we view reaction networks in a somewhat different way, as `Petri nets'.
Petri nets were invented by Carl Petri in 1939, when he was just a teenager, for the purposes of chemistry \cite{PR}. Much later, they became popular in theoretical computer science \cite{JK,Peterson}, biology \cite{K,KRS,Wilkinson}, and other fields \cite{BaezBiamonte,Haas,MBCDF}. A Petri net is a bipartite directed graph; vertices of one kind represent species, while those of the other kind represent reactions. The edges into a transition specify which species are inputs to that transition, while the edges out specify its outputs. One can easily turn a reaction network into a Petri net and vice versa. For example, the reaction network above translates into this Petri net:
\[
\begin{tikzpicture}
\begin{pgfonlayer}{nodelayer}
\node [style=species] (S) at (0, -1.5) {$S$};
\node [style=species] (I) at (0, 1.5) {$I$};
\node [style=transition] (i) at (-1.5,0) {$\; \big. \iota$ \,};
\node [style=none] (ATL) at (-3, 2) {};
\node [style=none] (ATR) at (-2.4, 2) {};
\node [style=none] (ABR) at (-2.4, -2) {};
\node [style=none] (ABL) at (-3, -2) {};
\node [style=none] (BTL) at (0.7, 2) {};
\node [style=none] (BTR) at (1.3, 2) {};
\node [style=none] (BBR) at (1.3, -2) {};
\node [style=none] (BBL) at (0.7, -2) {};
\node [style=species] (S) at (0, -1.5) {$S$};
\node [style=species] (I) at (0, 1.5) {$I$};
\node [style=species] (R) at (2.5,0) {$R$};
\node [style=transition] (r) at (1.5,1.4) {$\; \big. \rho\,$};
\node [style=transition] (l) at (1.5,-1.4) {$\; \big. \lambda \,$};
\node [style=none] (A'TL) at (-1.3, 2) {};
\node [style=none] (A'TR) at (-0.7, 2) {};
\node [style=none] (A'BR) at (-0.7, -2) {};
\node [style=none] (A'BL) at (-1.3, -2) {};
\node [style=none] (B'TL) at (3.2, 2) {};
\node [style=none] (B'TR) at (3.8, 2) {};
\node [style=none] (B'BR) at (3.8, -2) {};
\node [style=none] (B'BL) at (3.2, -2) {};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
\draw [style=inarrow, bend left=40, looseness=1.00] (S) to (i);
\draw [style=inarrow, bend right=40, looseness=1.00] (I) to (i);
\draw [style=inarrow, bend right=25, looseness=1.00] (i) to (I);
\draw [style=inarrow, bend right=40, looseness=1.00] (i) to (I);
\draw [style=inarrow, bend left=40, looseness=1.00] (R) to (l);
\draw [style=inarrow, bend left=40, looseness=1.00] (r) to (R);
\draw [style=inarrow, bend left=10, looseness=1.00] (I) to (r);
\draw [style=inarrow, bend left=40, looseness=1.00] (R) to (l);
\draw [style=inarrow, bend left=10, looseness=1.00] (l) to (S);
\draw [style=inarrow, bend left=40, looseness=1.00] (r) to (R);
\draw [style=inarrow, bend left=10, looseness=1.00] (I) to (r);
\end{pgfonlayer}
\end{tikzpicture}
\]
One should beware that the terminology is diverse, since it comes from several communities. In the Petri net literature, species are called `places' and reactions are called `transitions'. Indeed, Petri nets are sometimes called `place-transition nets' or `P/T nets'. On the other hand, chemists call them `species-reaction graphs' or `SR-graphs'. When each reaction of a Petri net has a rate constant attached to it, it is often called a `stochastic Petri net'.
While some qualitative properties of a rate equation can be read off from a reaction network, others are more easily read from the corresponding Petri net. For example, properties of a Petri net can be used to determine whether its rate equation has the capacity to admit multiple steady states \cite{BanajiCraciun,CraciunFeinbergTang, FeinbergShinar}.
Petri nets are also better suited to a compositional framework. The key new concept
required is that of an `open' Petri net. Here is an example:
\[
\begin{tikzpicture}
\begin{pgfonlayer}{nodelayer}
\node [style=species] (S) at (0, -1.5) {$S$};
\node [style=species] (I) at (0, 1.5) {$I$};
\node [style=transition] (i) at (-1.5,0) {$\; \big. \iota$ \,};
\node [style=inputdot] (outI) at (1, 1.5) {};
\node [style=inputdot] (outS) at (1, -1.5) {};
\node [style=none] (ATL) at (-3, 2) {};
\node [style=none] (ATR) at (-2.4, 2) {};
\node [style=none] (ABR) at (-2.4, -2) {};
\node [style=none] (ABL) at (-3, -2) {};
\node [style=none] (BTL) at (0.7, 2) {};
\node [style=none] (BTR) at (1.4, 2) {};
\node [style=none] (BBR) at (1.4, -2) {};
\node [style=none] (BBL) at (0.7, -2) {};
\node [style=empty] at (-2.7, 2.4) {$X$};
\node [style=empty] at (1.1, 2.4) {$Y$};
\node [style=empty] at (1.2, 1.5) {$1$};
\node [style=empty] at (1.2, -1.5) {$2$};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
\draw [style=inarrow, bend left=40, looseness=1.00] (S) to (i);
\draw [style=inarrow, bend right=40, looseness=1.00] (I) to (i);
\draw [style=inarrow, bend right=25, looseness=1.00] (i) to (I);
\draw [style=inarrow, bend right=40, looseness=1.00] (i) to (I);
\draw [style=inputarrow] (outI) to (I);
\draw [style=inputarrow] (outS) to (S);
\draw [style=simple] (ATL.center) to (ATR.center);
\draw [style=simple] (ATR.center) to (ABR.center);
\draw [style=simple] (ABR.center) to (ABL.center);
\draw [style=simple] (ABL.center) to (ATL.center);
\draw [style=simple] (BTL.center) to (BTR.center);
\draw [style=simple] (BTR.center) to (BBR.center);
\draw [style=simple] (BBR.center) to (BBL.center);
\draw [style=simple] (BBL.center) to (BTL.center);
\end{pgfonlayer}
\end{tikzpicture}
\]
The box at left shows a set $X$ of `inputs' (which happens to be empty), while the box at right shows a set $Y$ of `outputs'. Both inputs and outputs are points at which entities of various species can flow in or out of the Petri net. We say the open Petri net goes from $X$ to $Y$, and we shall show how to treat it as a morphism $f \maps X \to Y$ in a category we call $\RxNet$.
Given an open Petri net with rate constants assigned to each reaction, we explain how to systematically obtain its `open rate equation', which amounts to the usual rate equation with extra terms describing inflows and outflows. The above example has this open rate equation:
\beq
\begin{array}{ccr}
\label{open_rate_equation_1}
\displaystyle{\frac{d S}{d t}} &=& - r_\iota S I - o_1 \\ \\
\displaystyle{\frac{d I}{d t}} &=& r_\iota S I - o_2 .
\end{array}
\eeq
Here $o_1, o_2 \maps \R \to \R$ are arbitrary smooth functions describing outflows as a function of time.
Given another open Petri net $g \maps Y \to Z$, for example this:
\[
\begin{tikzpicture}
\begin{pgfonlayer}{nodelayer}
\node [style=species] (S) at (0, -1.5) {$S$};
\node [style=species] (I) at (0, 1.5) {$I$};
\node [style=species] (R) at (2.5,0) {$R$};
\node [style=transition] (r) at (1.5,1.4) {$\; \big. \rho\,$};
\node [style=transition] (l) at (1.5,-1.4) {$\; \big. \lambda \,$};
\node [style=inputdot] (inI) at (-1, 1.5) {};
\node [style=inputdot] (inS) at (-1, -1.5) {};
\node [style=none] (A'TL) at (-1.4, 2) {};
\node [style=none] (A'TR) at (-0.7, 2) {};
\node [style=none] (A'BR) at (-0.7, -2) {};
\node [style=none] (A'BL) at (-1.4, -2) {};
\node [style=none] (B'TL) at (3.2, 2) {};
\node [style=none] (B'TR) at (3.8, 2) {};
\node [style=none] (B'BR) at (3.8, -2) {};
\node [style=none] (B'BL) at (3.2, -2) {};
\node [style=empty] at (-1, 2.4) {$Y$};
\node [style=empty] at (3.5, 2.4) {$Z$};
\node [style=empty] at (-1.2, 1.5) {$1$};
\node [style=empty] at (-1.2, -1.5) {$2$};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
\draw [style=inarrow, bend left=40, looseness=1.00] (R) to (l);
\draw [style=inarrow, bend left=10, looseness=1.00] (l) to (S);
\draw [style=inarrow, bend left=40, looseness=1.00] (r) to (R);
\draw [style=inarrow, bend left=10, looseness=1.00] (I) to (r);
\draw [style=inputarrow] (inI) to (I);
\draw [style=inputarrow] (inS) to (S);
\draw [style=simple] (A'TL.center) to (A'TR.center);
\draw [style=simple] (A'TR.center) to (A'BR.center);
\draw [style=simple] (A'BR.center) to (A'BL.center);
\draw [style=simple] (A'BL.center) to (A'TL.center);
\draw [style=simple] (B'TL.center) to (B'TR.center);
\draw [style=simple] (B'TR.center) to (B'BR.center);
\draw [style=simple] (B'BR.center) to (B'BL.center);
\draw [style=simple] (B'BL.center) to (B'TL.center);
\end{pgfonlayer}
\end{tikzpicture}
\]
it will have its own open rate equation, in this case
\beq
\label{open_rate_equation_2}
\begin{array}{ccc}
\displaystyle{\frac{d S}{d t}} &=& r_\lambda R + i_2 \\ \\
\displaystyle{\frac{d I}{d t}} &=& - r_\rho I + i_1 \\ \\
\displaystyle{\frac{d R}{d t}} &=& r_\rho I - r_\lambda R .
\end{array}
\eeq
Here $i_1, i_2 \maps \R \to \R$ are arbitrary smooth functions describing inflows. We can compose $f$ and $g$ by gluing the outputs of $f$ to the inputs of $g$, obtaining a new open Petri net $gf \maps X \to Z$, as follows:
\[
\begin{tikzpicture}
\begin{pgfonlayer}{nodelayer}
\node [style=species] (S) at (0, -1.5) {$S$};
\node [style=species] (I) at (0, 1.5) {$I$};
\node [style=transition] (i) at (-1.5,0) {$\; \big. \iota$ \,};
\node [style=none] (ATL) at (-3, 2) {};
\node [style=none] (ATR) at (-2.4, 2) {};
\node [style=none] (ABR) at (-2.4, -2) {};
\node [style=none] (ABL) at (-3, -2) {};
\node [style=none] (BTL) at (0.7, 2) {};
\node [style=none] (BTR) at (1.3, 2) {};
\node [style=none] (BBR) at (1.3, -2) {};
\node [style=none] (BBL) at (0.7, -2) {};
\node [style=empty] at (-2.7, 2.4) {$X$};
\node [style=species] (S) at (0, -1.5) {$S$};
\node [style=species] (I) at (0, 1.5) {$I$};
\node [style=species] (R) at (2.5,0) {$R$};
\node [style=transition] (r) at (1.5,1.4) {$\; \big. \rho\,$};
\node [style=transition] (l) at (1.5,-1.4) {$\; \big. \lambda \,$};
\node [style=none] (A'TL) at (-1.3, 2) {};
\node [style=none] (A'TR) at (-0.7, 2) {};
\node [style=none] (A'BR) at (-0.7, -2) {};
\node [style=none] (A'BL) at (-1.3, -2) {};
\node [style=none] (B'TL) at (3.2, 2) {};
\node [style=none] (B'TR) at (3.8, 2) {};
\node [style=none] (B'BR) at (3.8, -2) {};
\node [style=none] (B'BL) at (3.2, -2) {};
\node [style=empty] at (3.5, 2.4) {$Z$};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
\draw [style=inarrow, bend left=40, looseness=1.00] (S) to (i);
\draw [style=inarrow, bend right=40, looseness=1.00] (I) to (i);
\draw [style=inarrow, bend right=25, looseness=1.00] (i) to (I);
\draw [style=inarrow, bend right=40, looseness=1.00] (i) to (I);
\draw [style=simple] (ATL.center) to (ATR.center);
\draw [style=simple] (ATR.center) to (ABR.center);
\draw [style=simple] (ABR.center) to (ABL.center);
\draw [style=simple] (ABL.center) to (ATL.center);
\draw [style=simple] (B'TL.center) to (B'TR.center);
\draw [style=simple] (B'TR.center) to (B'BR.center);
\draw [style=simple] (B'BR.center) to (B'BL.center);
\draw [style=simple] (B'BL.center) to (B'TL.center);
\draw [style=inarrow, bend left=40, looseness=1.00] (R) to (l);
\draw [style=inarrow, bend left=40, looseness=1.00] (r) to (R);
\draw [style=inarrow, bend left=10, looseness=1.00] (I) to (r);
\draw [style=inarrow, bend left=40, looseness=1.00] (R) to (l);
\draw [style=inarrow, bend left=10, looseness=1.00] (l) to (S);
\draw [style=inarrow, bend left=40, looseness=1.00] (r) to (R);
\draw [style=inarrow, bend left=10, looseness=1.00] (I) to (r);
\end{pgfonlayer}
\end{tikzpicture}
\]
Since this open Petri net $gf$ has no inputs or outputs, it amounts to an ordinary Petri net, and its open rate equation is a rate equation of the usual kind. Indeed, this is the Petri net we have already seen, and its open rate equation is Equation \eqref{SIRS_rate_equation}.
There is a systematic procedure for combining the open rate equations for
two open Petri nets to obtain that of their composite. In the case at hand it amounts to identifying the outflows of $f$ with the inflows of $g$ (setting $i_1 = o_1$ and $i_2 = o_2$) and then adding the right hand sides of Equations \eqref{open_rate_equation_1} and \eqref{open_rate_equation_2}. The first goal of this paper is to precisely describe this procedure, and to prove that it defines a functor
\[ \graysquare\maps \RxNet \to \Dynam \]
from $\RxNet$ to a category $\Dynam$ where the morphisms are `open dynamical systems'. By a dynamical system, we essentially mean a vector field on $\R^n$, which can be used to define a system of first-order ordinary differential equations in $n$ variables. An example is the rate equation of a Petri net. An open dynamical system allows for the possibility of extra terms that are arbitrary functions of time, such as the inflows and outflows in an open rate equation.
In fact, we prove that $\RxNet$ and $\Dynam$ are symmetric monoidal categories and that $\graysquare$ is a symmetric monoidal functor. To do this, we use the machinery of `decorated cospans', developed by Fong \cite{Fong2015,FongThesis} and already applied to electrical circuits \cite{BaezFong} and Markov processes \cite{BaezFongPollard}. Decorated cospans provide a powerful general tool for describing open systems. A cospan in any category is a diagram of the form
\[ \xymatrix{ & S & \\ X \ar[ur]^{i} & & Y \ar[ul]_{o} } .\]
We are mostly interested in cospans in $\FinSet$, the category of finite sets and functions between these. The set $S$, the \define{apex} of the cospan, is the set of states of an open system. The sets $X$ and $Y$ are the \define{inputs} and \define{outputs} of this system. The \define{legs} of the cospan, meaning the morphisms $i \maps X \to S$ and $o \maps Y \to S$, describe how these inputs and outputs are included in the system. In our application, $S$ is the set of species of a Petri net.
For example, we may take this reaction network:
\[ A+B \stackrel{\alpha}{\longrightarrow} 2C \quad \quad C \stackrel{\beta}{\longrightarrow} D, \]
treat it as a Petri net with $S = \{A,B,C,D\}$:
\[
\begin{tikzpicture}
\begin{pgfonlayer}{nodelayer}
\node [style=transition] (-1) at (0.5, 0) {$\beta$};
\node [style=species] (-2) at (2, 0) {$D$};
\node [style=species] (0) at (-1, 0) {$C$};
\node [style=none] (1) at (-0.25, 0.75) {};
\node [style=species] (2) at (-4, -0.5) {$B$};
\node [style=none] (3) at (-4.75, 0.75) {};
\node [style=none] (4) at (-5.25, 0.75) {};
% \node [style=inputdot] (5) at (0, 0) {};
\node [style=none] (6) at (0.25, 0.75) {};
\node [style=transition] (7) at (-2.5, 0) {$\alpha$};
\node [style=none] (8) at (-5.25, -0.75) {};
% \node [style=empty] (10) at (-5.25, 1) {$X$};
\node [style=none] (11) at (-0.25, -0.75) {};
% \node [style=inputdot] (12) at (-5, -0.5) {};
% \node [style=inputdot] (13) at (-5, 0.5) {};
\node [style=none] (14) at (-4.75, -0.75) {};
\node [style=none] (15) at (0.25, -0.75) {};
% \node [style=inputdot] (16) at (-5, 0) {};
% \node [style=empty] (17) at (0.25, 1) {$Y$};
\node [style=species] (18) at (-4, 0.5) {$A$};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
\draw [style=inarrow] (-1) to (-2);
\draw [style=inarrow] (0) to (-1);
\draw [style=inarrow] (18) to (7);
\draw [style=inarrow] (2) to (7);
\draw [style=inarrow, bend right=15, looseness=1.00] (7) to (0);
\draw [style=inarrow, bend left=15, looseness=1.00] (7) to (0);
\end{pgfonlayer}
\end{tikzpicture}
\]
and then turn that into an open Petri net by choosing any finite sets $X,Y$ and
maps $i \maps X \to S$, $o \maps Y \to S$, for example as follows:
\[
\begin{tikzpicture}
\begin{pgfonlayer}{nodelayer}
\node [style=transition] (-1) at (0.5, 0) {$\beta$};
\node [style=species] (-2) at (2, 0) {$D$};
\node [style=species] (0) at (-1, 0) {$C$};
\node [style=none] (1) at (2.75, 0.75) {};
\node [style=species] (2) at (-4, -0.5) {$B$};
\node [style=none] (3) at (-4.75, 0.75) {};
\node [style=none] (4) at (-5.25, 0.75) {};
\node [style=inputdot] (5) at (3, 0) {};
\node [style=none] (6) at (3.25, 0.75) {};
\node [style=transition] (7) at (-2.5, 0) {$\alpha$};
\node [style=none] (8) at (-5.25, -0.75) {};
\node [style=empty] (10) at (-5, 1) {$X$};
\node [style=none] (11) at (2.75, -0.75) {};
\node [style=inputdot] (12) at (-5, -0.5) {};
\node [style=inputdot] (13) at (-5, 0.5) {};
\node [style=none] (14) at (-4.75, -0.75) {};
\node [style=none] (15) at (3.25, -0.75) {};
\node [style=inputdot] (16) at (-5, 0) {};
\node [style=empty] (17) at (3, 1) {$Y$};
\node [style=species] (18) at (-4, 0.5) {$A$};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
\draw [style=inarrow] (-1) to (-2);
\draw [style=inarrow] (0) to (-1);
\draw [style=inarrow] (18) to (7);
\draw [style=inarrow] (2) to (7);
\draw [style=inarrow, bend right=15, looseness=1.00] (7) to (0);
\draw [style=inarrow, bend left=15, looseness=1.00] (7) to (0);
\draw [style=inputarrow] (5) to (-2);
\draw [style=inputarrow] (13) to (18);
\draw [style=inputarrow] (16) to (2);
\draw [style=inputarrow] (12) to (2);
\draw [style=simple] (4.center) to (3.center);
\draw [style=simple] (3.center) to (14.center);
\draw [style=simple] (14.center) to (8.center);
\draw [style=simple] (8.center) to (4.center);
\draw [style=simple] (1.center) to (6.center);
\draw [style=simple] (6.center) to (15.center);
\draw [style=simple] (15.center) to (11.center);
\draw [style=simple] (11.center) to (1.center);
\end{pgfonlayer}
\end{tikzpicture}
\]
Notice that the maps including the inputs and outputs into the states of the system need not be one-to-one. This is technically useful, but it introduces some subtleties not yet explained in our discussion of the gray-boxing functor.
An open Petri net can thus be seen as a cospan of finite sets whose apex $S$ is `decorated' with some extra information, namely a Petri net with $S$ as its set of species. Fong's theory of decorated cospans lets us define a category with open Petri nets as morphisms, with composition given by gluing the outputs of one open Petri net to the inputs of the other. For details see Appendix \ref{sec:deccospan}, where we recall some results on constructing decorated cospan categories and functors between these.
We call the functor $\graysquare \maps \RxNet \to \Dynam$ `gray-boxing' because it hides some but not all the internal details of an open Petri net. We can go further and `black-box' an open dynamical system. This amounts to recording only the relation between input and output variables that must hold in steady state. We prove that black-boxing gives a functor
\[ \blacksquare \maps \Dynam \to \SemiAlgRel \]
to a category $\SemiAlgRel$ of `semi-algebraic relations' between real vector spaces, meaning relations defined by polynomials and inequalities. (This relies on the fact that our dynamical systems involve \emph{algebraic} vector fields, meaning those whose components are polynomials; more general dynamical systems would give more general relations.) We prove that like the gray-boxing functor, the black-boxing functor is symmetric monoidal.
This paper is structured as follows. In Section \ref{sec:petri} we review and compare reaction networks and Petri nets. In Section \ref{sec:RNet} we construct a category $\RNet$ where an object is a finite set and a morphism is an open reaction network (or more precisely, an isomorphism class of open reaction networks). In Section \ref{sec:RxNet} we enhance this construction to define a category $\RxNet$ where the transitions of the open reaction networks are equipped with rate constants. In Section \ref{sec:openrate} we explain the open dynamical system associated to an open reaction network, and in Section \ref{sec:opendynam} we construct a category $\Dynam$ of open dynamical systems. In Section \ref{sec:gray} we construct the gray-boxing functor $\graysquare \maps \RxNet \to \Dynam$. In Section \ref{sec:black} we construct the black-boxing functor $\blacksquare \maps \Dynam \to \SemiAlgRel$. Finally, in Section \ref{sec:conclusions} we fit our results into a larger `network of network theories'.
\subsection*{Acknowledgements}
We thank Brendan Fong for many conversations, and David Spivak for pointing out his closely related work on black-boxing open dynamical systems \cite{Spivak}. We thank Daniel Cicala for helping us understand the functor $D$ sending any finite set $S$ to the set of algebraic vector fields on $S$, as discussed in Section \ref{sec:opendynam}. We also thank the Centre for Quantum Technologies and DARPA's Complex Adaptive System Composition and Design Environment program, who helped support this research.
\section{Reaction networks versus Petri nets}
\label{sec:petri}
We begin by precisely defining reaction networks and Petri nets, so we can see that they are
two ways of presenting the same concept.
\begin{defn}
A \define{reaction network} $(S,T,s,t)$ consists of:
\begin{itemize}
\item a finite set $S$,
\item a finite set $T$,
\item functions $s,t \maps T \to \N^S$.
\end{itemize}
We call the elements of $S$ \define{species}, those of $\N^S$ \define{complexes},
and those of $T$ \define{transitions}. Any transition $\tau \in T$ has a \define{source}
$s(\tau)$ and \define{target} $t(\tau)$. If $s(\tau) = \kappa$ and $t(\tau) = \kappa'$
we write $\tau \maps \kappa \to \kappa'$.
\end{defn}
\noindent Our terminology here is a compromise: as mentioned before, in the
Petri net literature `species' are often called `places', while in the chemistry
literature `transitions' are often called `reactions'. The alphabetical proximity
of $S$ and $T$ gives our compromise a certain charm.
The set of complexes relevant to a given reaction network $(S,T,s,t)$ is
\[ K = \im(s) \cup \im(t) \subseteq \N^S. \]
The reaction network gives a graph with $K$ as its set of vertices and a directed
edge from $\kappa \in K$ to $\kappa' \in K$ for each transition $\tau \maps \kappa
\to \kappa'$. This graph may have multiple edges or self-loops. It is thus
the kind of graph sometimes called a `directed multigraph' or
`quiver'. However, a graph of this kind can only arise from a reaction network if
every vertex is the source or target of some edge.
On the other hand, we have Petri nets:
\begin{defn}
A \define{Petri net} $(S,T,m,n)$ consists of:
\begin{itemize}
\item a finite set $S$,
\item a finite set $T$,
\item functions $m,n \maps S \times T \to \N$.
\end{itemize}
We call the elements
of $S$ \define{species} and those of $T$ \define{transitions}.
We call any Petri net with $S$ as its set of species a \define{Petri net on} $S$.
Given a species $\sigma \in S$ and a transition $\tau \in T$, we say
$m(\sigma,\tau) \in \N$ is the number of times $\sigma$ appears
as an \define{input} of $\tau$, and $n(\sigma,\tau) \in \N$ is the
number of times $\sigma$ appears as the \define{output} of $\tau$.
\end{defn}
It is easy to convert a reaction network into a Petri net, or vice versa, using
the relations
\[ m(\sigma,\tau) = s(\tau)(\sigma) , \]
\[ n(\sigma,\tau) = t(\tau)(\sigma) .\]
Thus, anything we do with reaction networks we can do with Petri nets, and
vice versa. However, Petri nets are usually drawn in a different way. Given a Petri net $(S,T,m,n)$ we draw a yellow circle for each species $\sigma \in S$, an aqua square for each transition $\tau \in T$, a certain number $m(\sigma,\tau)$ of edges from each species $\sigma$ to each transition $\tau$, and a certain number $n(\sigma,\tau)$ of edges from each transition $\tau$ to each species $\sigma$. This gives a picture of a Petri net as a bipartite graph. For example, this reaction network
\[ 3A \stackrel{\tau}{\longrightarrow} B + C \]
gives a Petri net that we can draw as follows:
\[
\begin{tikzpicture}
\begin{pgfonlayer}{nodelayer}
% \node [style=transition] (-1) at (0.5, 0) {$\beta$};
% \node [style=species] (-2) at (2, 0) {$D$};
\node [style=species] (0) at (-4, 0) {$A$};
\node [style=none] (1) at (-0.25, 0.75) {};
\node [style=species] (2) at (-1, -0.5) {$C$};
\node [style=none] (3) at (-4.75, 0.75) {};
\node [style=none] (4) at (-5.25, 0.75) {};
% \node [style=inputdot] (5) at (0, 0) {};
\node [style=none] (6) at (0.25, 0.75) {};
\node [style=transition] (7) at (-2.5, 0) {$\tau$};
\node [style=none] (8) at (-5.25, -0.75) {};
% \node [style=empty] (10) at (-5.25, 1) {$X$};
\node [style=none] (11) at (-0.25, -0.75) {};
% \node [style=inputdot] (12) at (-5, -0.5) {};
% \node [style=inputdot] (13) at (-5, 0.5) {};
\node [style=none] (14) at (-4.75, -0.75) {};
\node [style=none] (15) at (0.25, -0.75) {};
% \node [style=inputdot] (16) at (-5, 0) {};
% \node [style=empty] (17) at (0.25, 1) {$Y$};
\node [style=species] (18) at (-1, 0.5) {$B$};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
\draw [style=inarrow] (7) to (18);
\draw [style=inarrow] (7) to (2);
\draw [style=inarrow, bend right=30, looseness=1.00] (0) to (7);
\draw [style=inarrow] (0) to (7);
\draw [style=inarrow, bend left=30, looseness=1.00] (0) to (7);
\end{pgfonlayer}
\end{tikzpicture}
\]
However, we must be a bit careful. A Petri net does not have a well-defined \emph{set} of edges from a species $\sigma$ to a transition $\tau$, or vice versa: there is merely a \emph{natural number} $m(\sigma,\tau)$ and a natural number $n(\sigma,\tau)$. Thus, unlike in a reaction network, the edges in a Petri net do not have `names'. For example, in the picture above, we are not allowed to distinguish between the three edges from $A$ to $\tau$: these edges are just a convenient way of indicating that $m(A,\tau) = 3$.
In what follows we work with reaction networks, since our applications are especially relevant to chemistry, but we often draw them as Petri nets.
\section{Open reaction networks}
\label{sec:RNet}
To treat a reaction network as an open system, we equip it with `inputs' and
`outputs':
\begin{defn}
\label{defn:open_reaction_network}
Given finite sets $X$ and $Y$, an \define{open reaction network from} $X$ \define{to} $Y$ is a cospan of finite sets
\[ \xymatrix{ & S & \\ X \ar[ur]^{i} & & Y \ar[ul]_{o} } \]
together with a reaction network $R$ on $S$. We often abbreviate all this data as $R \maps X \to Y$. We say $X$ is the set of \define{inputs} and $Y$ is the set of \define{outputs}. %We call $B = i(X) \cup o(Y)$ the set of \define{boundary species}, while species in $S-B$ are called \define{internal}.
\end{defn}
The first thing we want to do with open reaction networks is compose them: that is, glue them together to build larger ones. Given open reaction networks $R \maps X \to Y$ and $R' \maps Y \to Z$, we can compose them to get an open reaction network $R' R \maps X \to Z$.
The process of composition actually involves two steps. These are easy to visualize if we draw each reaction network as a Petri net as explained in Section \ref{sec:petri}, and also indicate the maps from inputs and outputs into the set of species. For example, suppose $R \maps X \to Y$ looks like this:
\[
\begin{tikzpicture}
\begin{pgfonlayer}{nodelayer}
\node [style=species] (A) at (-4, 0.5) {$A$};
\node [style=species] (B) at (-4, -0.5) {$B$};
\node [style=species] (C) at (-1, 0.5) {$C$};
\node [style=species] (D) at (-1, -0.5) {$D$};
\node [style=transition] (a) at (-2.5, 0) {$\alpha$};
\node [style=empty] (X) at (-5.1, 1) {$X$};
\node [style=none] (Xtr) at (-4.75, 0.75) {};
\node [style=none] (Xbr) at (-4.75, -0.75) {};
\node [style=none] (Xtl) at (-5.4, 0.75) {};
\node [style=none] (Xbl) at (-5.4, -0.75) {};
\node [style=inputdot] (1) at (-5, 0.5) {};
\node [style=empty] at (-5.2, 0.5) {$1$};
\node [style=inputdot] (2) at (-5, 0) {};
\node [style=empty] at (-5.2, 0) {$2$};
\node [style=inputdot] (3) at (-5, -0.5) {};
\node [style=empty] at (-5.2, -0.5) {$3$};
\node [style=empty] (Y) at (0.1, 1) {$Y$};
\node [style=none] (Ytr) at (.4, 0.75) {};
\node [style=none] (Ytl) at (-.25, 0.75) {};
\node [style=none] (Ybr) at (.4, -0.75) {};
\node [style=none] (Ybl) at (-.25, -0.75) {};
\node [style=inputdot] (4) at (0, 0.5) {};
\node [style=empty] at (0.2, 0.5) {$4$};
\node [style=inputdot] (5) at (0, -0.5) {};
\node [style=empty] at (0.2, -0.5) {$5$};
% \node [style=empty] (Z) at (3, 1) {$Z$};
% \node [style=none] (Ztr) at (3.25, 0.75) {};
% \node [style=none] (Ztl) at (2.75, 0.75) {};
% \node [style=none] (Zbl) at (2.75, -0.75) {};
% \node [style=none] (Zbr) at (3.25, -0.75) {};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
\draw [style=inarrow] (A) to (a);
\draw [style=inarrow] (B) to (a);
\draw [style=inarrow] (a) to (C);
\draw [style=inarrow] (a) to (D);
\draw [style=inputarrow] (1) to (A);
\draw [style=inputarrow] (2) to (B);
\draw [style=inputarrow] (3) to (B);
\draw [style=inputarrow] (4) to (C);
\draw [style=inputarrow] (5) to (D);
\draw [style=simple] (Xtl.center) to (Xtr.center);
\draw [style=simple] (Xtr.center) to (Xbr.center);
\draw [style=simple] (Xbr.center) to (Xbl.center);
\draw [style=simple] (Xbl.center) to (Xtl.center);
\draw [style=simple] (Ytl.center) to (Ytr.center);
\draw [style=simple] (Ytr.center) to (Ybr.center);
\draw [style=simple] (Ybr.center) to (Ybl.center);
\draw [style=simple] (Ybl.center) to (Ytl.center);
\end{pgfonlayer}
\end{tikzpicture}
\]
and $R' \maps Y \to Z$ looks like this:
\[
\begin{tikzpicture}
\begin{pgfonlayer}{nodelayer}
% \node [style=species] (A) at (-4, 0.5) {$A$};
% \node [style=species] (B) at (-4, -0.5) {$B$};
% \node [style=species] (C) at (-1, 0.5) {$C$};
% \node [style=species] (D) at (-1, -0.5) {$D$};
% \node [style=transition] (a) at (-2.5, 0) {$\alpha$};
\node [style = species] (E) at (1, 0) {$E$};
\node [style = transition] (b) at (2.5, 0) {$\beta$};
\node [style = species] (F) at (4,0) {$F$};
% \node [style=empty] (X) at (-5.1, 1) {$X$};
% \node [style=none] (Xtr) at (-4.75, 0.75) {};
% \node [style=none] (Xbr) at (-4.75, -0.75) {};
% \node [style=none] (Xtl) at (-5.4, 0.75) {};
% \node [style=none] (Xbl) at (-5.4, -0.75) {};
% \node [style=inputdot] (1) at (-5, 0.5) {};
% \node [style=empty] at (-5.2, 0.5) {$1$};
% \node [style=inputdot] (2) at (-5, 0) {};
% \node [style=empty] at (-5.2, 0) {$2$};
% \node [style=inputdot] (3) at (-5, -0.5) {};
% \node [style=empty] at (-5.2, -0.5) {$3$};
\node [style=empty] (Y) at (-0.1, 1) {$Y$};
\node [style=none] (Ytr) at (.25, 0.75) {};
\node [style=none] (Ytl) at (-.4, 0.75) {};
\node [style=none] (Ybr) at (.25, -0.75) {};
\node [style=none] (Ybl) at (-.4, -0.75) {};
\node [style=inputdot] (4) at (0, 0.5) {};
\node [style=empty] at (-0.2, 0.5) {$4$};
\node [style=inputdot] (5) at (0, -0.5) {};
\node [style=empty] at (-0.2, -0.5) {$5$};
\node [style=empty] (Z) at (5, 1) {$Z$};
\node [style=none] (Ztr) at (4.75, 0.75) {};
\node [style=none] (Ztl) at (5.4, 0.75) {};
\node [style=none] (Zbl) at (5.4, -0.75) {};
\node [style=none] (Zbr) at (4.75, -0.75) {};
\node [style=inputdot] (6) at (5, 0) {};
\node [style=empty] at (5.2, 0) {$6$};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
% \draw [style=inarrow] (A) to (a);
% \draw [style=inarrow] (B) to (a);
% \draw [style=inarrow] (a) to (C);
% \draw [style=inarrow] (a) to (D);
\draw [style=inarrow] (E) to (b);
\draw [style=inarrow] (b) to (F);
% \draw [style=inputarrow] (1) to (A);
% \draw [style=inputarrow] (2) to (B);
% \draw [style=inputarrow] (3) to (B);
% \draw [style=inputarrow] (4) to (C);
% \draw [style=inputarrow] (5) to (D);
\draw [style=inputarrow] (4) to (E);
\draw [style=inputarrow] (5) to (E);
\draw [style=inputarrow] (6) to (F);
% \draw [style=simple] (Xtl.center) to (Xtr.center);
% \draw [style=simple] (Xtr.center) to (Xbr.center);
% \draw [style=simple] (Xbr.center) to (Xbl.center);
% \draw [style=simple] (Xbl.center) to (Xtl.center);
\draw [style=simple] (Ytl.center) to (Ytr.center);
\draw [style=simple] (Ytr.center) to (Ybr.center);
\draw [style=simple] (Ybr.center) to (Ybl.center);
\draw [style=simple] (Ybl.center) to (Ytl.center);
\draw [style=simple] (Ztl.center) to (Ztr.center);
\draw [style=simple] (Ztr.center) to (Zbr.center);
\draw [style=simple] (Zbr.center) to (Zbl.center);
\draw [style=simple] (Zbl.center) to (Ztl.center);
\end{pgfonlayer}
\end{tikzpicture}
\]
To compose them, the first step is to put the pictures together:
\[
\begin{tikzpicture}
\begin{pgfonlayer}{nodelayer}
\node [style=species] (A) at (-4, 0.5) {$A$};
\node [style=species] (B) at (-4, -0.5) {$B$};
\node [style=species] (C) at (-1, 0.5) {$C$};
\node [style=species] (D) at (-1, -0.5) {$D$};
\node [style=transition] (a) at (-2.5, 0) {$\alpha$};
\node [style = species] (E) at (1, 0) {$E$};
\node [style = transition] (b) at (2.5, 0) {$\beta$};
\node [style = species] (F) at (4,0) {$F$};
\node [style=empty] (X) at (-5.1, 1) {$X$};
\node [style=none] (Xtr) at (-4.75, 0.75) {};
\node [style=none] (Xbr) at (-4.75, -0.75) {};
\node [style=none] (Xtl) at (-5.4, 0.75) {};
\node [style=none] (Xbl) at (-5.4, -0.75) {};
\node [style=inputdot] (1) at (-5, 0.5) {};
\node [style=empty] at (-5.2, 0.5) {$1$};
\node [style=inputdot] (2) at (-5, 0) {};
\node [style=empty] at (-5.2, 0) {$2$};
\node [style=inputdot] (3) at (-5, -0.5) {};
\node [style=empty] at (-5.2, -0.5) {$3$};
\node [style=empty] (Y) at (-0.1, 1) {$Y$};
\node [style=none] (Ytr) at (.25, 0.75) {};
\node [style=none] (Ytl) at (-.4, 0.75) {};
\node [style=none] (Ybr) at (.25, -0.75) {};
\node [style=none] (Ybl) at (-.4, -0.75) {};
\node [style=inputdot] (4) at (0, 0.5) {};
\node [style=empty] at (0, 0.25) {$4$};
\node [style=inputdot] (5) at (0, -0.5) {};
\node [style=empty] at (0, -0.25) {$5$};
\node [style=empty] (Z) at (5, 1) {$Z$};
\node [style=none] (Ztr) at (4.75, 0.75) {};
\node [style=none] (Ztl) at (5.4, 0.75) {};
\node [style=none] (Zbl) at (5.4, -0.75) {};
\node [style=none] (Zbr) at (4.75, -0.75) {};
\node [style=inputdot] (6) at (5, 0) {};
\node [style=empty] at (5.2, 0) {$6$};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
\draw [style=inarrow] (A) to (a);
\draw [style=inarrow] (B) to (a);
\draw [style=inarrow] (a) to (C);
\draw [style=inarrow] (a) to (D);
\draw [style=inarrow] (E) to (b);
\draw [style=inarrow] (b) to (F);
\draw [style=inputarrow] (1) to (A);
\draw [style=inputarrow] (2) to (B);
\draw [style=inputarrow] (3) to (B);
\draw [style=inputarrow] (4) to (C);
\draw [style=inputarrow] (5) to (D);
\draw [style=inputarrow] (4) to (E);
\draw [style=inputarrow] (5) to (E);
\draw [style=inputarrow] (6) to (F);
\draw [style=simple] (Xtl.center) to (Xtr.center);
\draw [style=simple] (Xtr.center) to (Xbr.center);
\draw [style=simple] (Xbr.center) to (Xbl.center);
\draw [style=simple] (Xbl.center) to (Xtl.center);
\draw [style=simple] (Ytl.center) to (Ytr.center);
\draw [style=simple] (Ytr.center) to (Ybr.center);
\draw [style=simple] (Ybr.center) to (Ybl.center);
\draw [style=simple] (Ybl.center) to (Ytl.center);
\draw [style=simple] (Ztl.center) to (Ztr.center);
\draw [style=simple] (Ztr.center) to (Zbr.center);
\draw [style=simple] (Zbr.center) to (Zbl.center);
\draw [style=simple] (Zbl.center) to (Ztl.center);
\end{pgfonlayer}
\end{tikzpicture}
\]
At this point, if we ignore the sets $X,Y,Z$, we have a new reaction network whose set of species is the disjoint union of those for $R$ and $R'$. The second step is to identify a species of $R$ with a species of $R'$ whenever both are images of the same point in $Y$. After this step we can stop drawing everything involving $Y$, and get an open reaction network from $X$ to $Z$:
\[
\begin{tikzpicture}
\begin{pgfonlayer}{nodelayer}
\node [style=species] (A) at (-4, 0.5) {$A$};
\node [style=species] (B) at (-4, -0.5) {$B$};;
\node [style=transition] (a) at (-2.5, 0) {$\alpha$};
\node [style = species] (E) at (-1, 0) {$C$};
\node [style = transition] (b) at (.5, 0) {$\beta$};
\node [style = species] (F) at (2,0) {$F$};
\node [style=empty] (X) at (-5.1, 1) {$X$};
\node [style=none] (Xtr) at (-4.75, 0.75) {};
\node [style=none] (Xbr) at (-4.75, -0.75) {};
\node [style=none] (Xtl) at (-5.4, 0.75) {};
\node [style=none] (Xbl) at (-5.4, -0.75) {};
\node [style=inputdot] (1) at (-5, 0.5) {};
\node [style=empty] at (-5.2, 0.5) {$1$};
\node [style=inputdot] (2) at (-5, 0) {};
\node [style=empty] at (-5.2, 0) {$2$};
\node [style=inputdot] (3) at (-5, -0.5) {};
\node [style=empty] at (-5.2, -0.5) {$3$};
\node [style=empty] (Z) at (3, 1) {$Z$};
\node [style=none] (Ztr) at (2.75, 0.75) {};
\node [style=none] (Ztl) at (3.4, 0.75) {};
\node [style=none] (Zbl) at (3.4, -0.75) {};
\node [style=none] (Zbr) at (2.75, -0.75) {};
\node [style=inputdot] (6) at (3, 0) {};
\node [style=empty] at (3.2, 0) {$6$};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
\draw [style=inarrow] (A) to (a);
\draw [style=inarrow] (B) to (a);
\draw [style=inarrow, bend right=15, looseness=1.00] (a) to (E);
\draw [style=inarrow, bend left =15, looseness=1.00] (a) to (E);
\draw [style=inarrow] (E) to (b);
\draw [style=inarrow] (b) to (F);
\draw [style=inputarrow] (1) to (A);
\draw [style=inputarrow] (2) to (B);
\draw [style=inputarrow] (3) to (B);
\draw [style=inputarrow] (6) to (F);
\draw [style=simple] (Xtl.center) to (Xtr.center);
\draw [style=simple] (Xtr.center) to (Xbr.center);
\draw [style=simple] (Xbr.center) to (Xbl.center);
\draw [style=simple] (Xbl.center) to (Xtl.center);
\draw [style=simple] (Ztl.center) to (Ztr.center);
\draw [style=simple] (Ztr.center) to (Zbr.center);
\draw [style=simple] (Zbr.center) to (Zbl.center);
\draw [style=simple] (Zbl.center) to (Ztl.center);
\end{pgfonlayer}
\end{tikzpicture}
\]
This new open reaction network is the desired composite $R' R \maps X \to Z$. Note that we have identified the species $C,D$ and $E$ and arbitrarily named the resulting species $C$.
Formalizing all this, and proving that we get a category whose morphisms are open
reaction networks, is precisely what Fong's theory of decorated cospans \cite{Fong2015,FongThesis} is designed to accomplish. A bit of notation is useful: given a finite set $S$, let $F(S)$ be the set of all reaction networks on $S$. Thus, an open reaction network with rates is a cospan of finite sets with apex $S$ together with an element $R \in F(S)$. We say that the cospan is \define{decorated} by
$R$.
Now, suppose we have open reaction networks $R \maps X \to Y$ and $R' \maps Y \to Z$ and we wish to define their composite $R' R \maps X \to Z$. Thus, we have cospans of finite sets
\[ \xymatrix { & S & & S' & \\ X \ar[ur]^{i} & & Y \ar[ul]_o \ar[ur]^{i'} & & Z \ar[ul]_{o'} } \]
decorated by elements $R \in F(S)$ and $R' \in F(S')$. To define their composite, first we
compose the cospans, and then we compose the decorations.
To compose the cospans, first we write them as part of a single diagram:
\[ \xymatrix{ & S & & S' & \\
X \ar[ur]^{i} & & Y \ar[ul]_{o} \ar[ur]^{i'} & & Z \ar[ul]_{o'} \\ } \]
Then we form the pushout of $S$ and $S'$ over $Y$. This is denoted $S +_Y S'$, and is
formed by first taking the disjoint union of $S$ and $S'$ and then taking the quotient of this by the finest equivalence relation such that $n \sim n'$ if $o(y) = n$ and $i'(y) = n'$ for some $y \in Y$. This identifies a species of $R$ with one of $R'$ whenever both are images of the same point in $Y$. The pushout comes with canonical maps $j\maps S \to S+_{Y}S'$ and $j'\maps S' \to S+_{Y}S'$, so we get a diagram
\[
\xymatrix{
&& S +_Y S' \\
& S \ar[ur]^{j} && S' \ar[ul]_{j'} \\
\quad X\quad \ar[ur]^{i} && Y \ar[ul]_{o} \ar[ur]^{i'} &&\quad Z \quad \ar[ul]_{o'}
}
\]
and we define the composite cospan to be
\[ \xymatrix{ & S +_Y S' & \\ \; X \; \ar[ur]^{j i} & & \; \ar[ul]_{j' o'} \; Z. } \]
Next we need to decorate this composite cospan with an element of $F(S +_Y S')$.
To get this element we start with what we have, namely $R \in F(S)$ and $R' \in F(S')$, and apply two maps. First, we apply the obvious map
\[ \varphi_{S,S'} \maps F(S) \times F(S') \to F(S + S') \]
that sends a pair of reaction networks, one on $S$ and one on $S'$, to one
on the disjoint union $S + S'$ of these two sets. Then, we apply a map
\[F([j,j']) \maps F(S+S') \to F(S+_Y S')\]
that glues together the two pieces of this reaction network to get one on
$S +_Y S'$. We explain these maps in turn.
First, the `obvious' map $\varphi_{S,S'}$ is defined by
\beq
\label{eq:Phi}
\varphi_{S,S'} ((S,T,s,t), (S',T',s',t')) = (S + S', T + T', s+s', t+t').
\eeq
In more detail, for the reaction network on the right hand side:
\begin{itemize}
\item The set of species is the disjoint union $S + S'$.
\item The set of transitions is the disjoint union $T + T'$.
\item The source map $s + s' \maps T + T' \to S + S'$ sends any transition $\tau \in T$
to $s(\tau) \in S$ and any transition $\tau' \in T'$ to $s'(\tau') \in S'$.
\item The target map $t + t' \maps T + T' \to S + S'$ sends any transition $\tau \in T$
to $t(\tau) \in S$ and any transition $\tau' \in T'$ to $t'(\tau') \in S'$.
%\item The rate constant for any transition $\tau \in T$ is $r(\tau)$, while the rateconstant for any transition $\tau' \in T'$ is $r'(\tau')$. We denote the resulting map from transitions to rate constants as $[r,r'] \maps T + T' \to [0,\infty)$.
\end{itemize}
Second, to define the map $F([j,j'])$, we take the canonical map
\[ [j,j'] \maps S+S' \to S+_Y S' \]
from the disjoint union $S+S'$ onto the pushout, and use the fact that the
$F$ is actually a functor, so it is defined not only on finite sets but also on functions
betwen these:
\begin{lem}
\label{lemma:RFunctor}
There is a functor $F \maps \FinSet \to \Set$ such that:
\begin{itemize}