Optimization decomposition methods are a fundamental tool to develop distributed solution algorithms for large scale optimization problems arising in fields such as machine learning, optimal control, and operations research. In this paper, we present an algebraic framework for hierarchically composing optimization problems defined on hypergraphs and automatically generating distributed solution algorithms that respect the given hierarchical structure.
The central abstractions of our framework are operads, operad algebras, and algebra morphisms, which formalize notions of syntax, semantics, and structure preserving semantic transformations respectively. These abstractions allow us to formally relate composite optimization problems to the distributed algorithms that solve them. Specifically, we show that certain classes of optimization problems form operad algebras, and a collection of first-order solution methods, namely gradient descent, Uzawa's algorithm  (also called gradient ascent-descent), and their subgradient variants, yield algebra morphisms from these problem algebras to algebras of dynamical systems. Primal and dual decomposition methods are then recovered by applying these morphisms to certain classes of composite problems.

Using this framework, we also derive a novel sufficient condition for when a problem defined by compositional data is solvable by a decomposition method. We show that the minimum cost network flow problem satisfies this condition, thereby allowing us to automatically derive a hierarchical dual decomposition algorithm for finding minimum cost flows on composite flow networks. We implement our operads, algebras, and algebra morphisms in a Julia package called AlgebraicOptimization.jl and use our implementation to empirically demonstrate that hierarchical dual decomposition outperforms standard dual decomposition on classes of flow networks with hierarchical structure.

Optimization decomposition methods are a fundamental tool to develop distributed solution algorithms for large scale optimization problems arising in fields such as machine learning, optimal control, and operations research.

In this paper, we present an algebraic framework for composing optimization problems defined on graphs and hypergraphs and automatically generating solution algorithms which both unifies and generalizes several fundamental first-order techniques, namely gradient descent, Uzawa's algorithm  (also called gradient ascent-descent), certain primal and dual decomposition methods, and subgradient variants of each. Our results on gradient descent apply to convex problems and non-convex problems, and results on other algorithms apply to convex, concave, and saddle problems.

The central abstractions of this framework are undirected wiring diagrams (UWDs), which are a special type of hypergraph, UWD-algebras, which give compositional semantics to UWDs, and algebra morphisms, which are structure preserving maps between UWD-algebras.

These structures allow us to formally relate compositional optimization problems to the decomposition algorithms that solve them. This provides a mechanized approach to constructing distributed optimization algorithms from hierarchical specifications of the optimization problem.

The formulation of this framework allows us to derive a novel sufficient condition for when a problem is solvable via a decomposition method: namely, when there exists an algebra morphism from a UWD-algebra of problem data to one of the optimization problem algebras described above. The structure of UWD-algebras provides a distributed solution algorithm. We use minimum cost network flow problems on graphs to demonstrate this approach in a software implementation.

We emphasize that this framework allows the exploitation of a wide variety of composition structures in a hierarchical fashion. We discuss our prototype implementation of this framework in the Julia programming language and show how exploiting higher level compositional structure can result in faster solution times than conventional distributed or centralized solution algorithms.

§ INTRODUCTION

[inline]FOCM SUBMISSION TODOS by Priority

* (DONE for now) Address co-author feedback.

* (DONE) Add references throughout text to appendix at key points.

* Clean up all citations (add journal references etc.)

* Write a compelling cover letter.

* Proof read entire document from head to toe.

Decomposition methods such as primal and dual decomposition are fundamental tools to develop distributed solution algorithms for large scale optimization problems arising in machine learning [1, 2], optimal control [3, 4], and operations research [5, 6]. These methods generally work by splitting a large problem into several several simpler subproblems and repeatedly solving these to arive at a solution to the original problem. As such, decomposition methods are most naturally applicable to problems which themselves are composites of subproblems, for some appropriate notion of composition. We say that such problems have compositional structure. Often, compositional structure at the problem level is left implicit, and expertise is required to determine whether a decomposition method can be applied. Additionally, it can be non-trivial to transform a given problem into an equivalent one which can be decomposed.

On the other hand, when compositional problem structure is made explicit, decomposition methods can often be applied more directly. Common examples of problems with explicit compositional structure are those defined on graphs and hypergraphs, where nodes represent subproblems and (hyper)edges represent coupling between subproblems. The benefit of making compositional structure explicit is that by fixing the types of problems that can inhabit nodes and the types of coupling allowed between subproblems, one can derive a decomposition method which solves problems defined over arbitrary graphs or hypergraphs [7, 8, 9]. In this sense, problems over graphs and hypergraphs can be viewed as standard forms for problems to which decomposition is applicable. However, it can still be challenging to translate a given problem or the data defining a problem instance into such a standard form.

We are thus motivated to develop a general framework for decomposition methods that both explicitly represents compositional structure and offers a principled way to transform problem data into such explicit structures. This paper presents a foundational step towards achieving this goal by introducing a novel algebraic/structural perspective on first-order optimization decomposition methods.

The central abstractions of this framework revolve around undirected wiring diagrams (UWDs) which are a special class of hypergraphs with a distinguished boundary node. Undirected wiring diagrams form a syntactic structure called an operad which allows the hierarchical construction of UWDs by recursive substitution [10]. Algebras on the operad of undirected wiring diagrams, or UWD-algebras for short, provide formal semantic interpretations to UWDs that respect their hierarchical structure. Intuitively, a UWD-algebra specifies how to build interconnected systems where the pattern of interconnection can be represented by a UWD. Consequently, UWD-algebras have been used to define network-style composition operations for an array of combinatorial objects such as labelled graphs [11], electrical circuits [12], and Petri networks [13], as well as quantitative objects such as linear and convex relations [14, 15], Markov processes [16], and dynamical systems [17]. UWD-algebras also provide a natural abstraction for modeling optimization problems defined on hypergraphs, which is the approach we take in this paper.

UWD-algebra morphisms then provide structure preserving transformations between different semantic interpretations of UWDs. Using this machinery, the central idea of our framework can be summarized as follows. If a first-order optimization algorithm defines an algebra morphism from a UWD-algebra of optimization problems to a UWD-algebra of dynamical systems, that algorithm decomposes problems defined on arbitrary UWDs. Furthermore, applying such a morphism to a problem generates a dynamical system to solve the problem in a distributed fashion using message passing semantics.

Turning to specific examples of this general pattern, we first define a UWD-algebra of once-differentiable (denoted $C^1$), unconstrained minimization problems called $\Opt$ and show that gradient descent is an algebra morphism from $\Opt$ to the UWD-algebra $\Dynam_D$ of discrete dynamical systems, namely it is the morphsim

\begin{equation}
\gd^\gamma\maps \Opt\to \Dynam_D,
\end{equation}

where $\gamma>0$ is a fixed step size.

A. An example undirected wiring diagram (UWD), which is a special type of hypergraph. Each box has a finite set of connection points which we call ports. We refer to the small circles as junctions and the edges connecting ports to junctions as wires.
Importantly, every UWD has a boundary, visualized by the large outer box. We refer to ports on inner boxes and outer boxes as inner ports and outer ports, respectively. B. The UWD in (A) interpreted as a composite optimization problem. Subproblems inhabit boxes and their optimization variables inhabit wires. Subproblems connected by the same junction share the variables on wires incident to that junction. C. The UWD in (A) interpreted as a composite dynamical system. Subsystems inhabit boxes and their state variables inhabit wires with junctions indicating which state variables are shared. The change in a shared state variable is computed by summing changes from contributing subsystems (encoded by the matrix $K^T$). Gradient descent gives a structure-preserving map from the objective function semantics to the dynamical systems semantics.

With the gradient descent morphism, we then show that distributed message-passing versions of gradient descent and primal decomposition can be recovered by applying $\gd^\gamma$ to different types of composite problems. Naturality of $\gd^\gamma$ implies that the decomposed solution algorithm for solving a composite problem is equivalent to solving the entire composite problem directly with gradient descent. Moreover, the fact that the gradient algebra morphism preserves the hypergraph structure implies that problems defined on arbitrary UWDs can be decomposed. This is illustrated in Figure <ref>. Informally, we can summarize these results by saying that the following diagram commutes for any choice of subproblems and composition pattern:

\[\begin{tikzcd}
{\text{Subproblems}} && {\text{Problem}} \\
\\
{\text{Subsystems}} && {\text{System}}
\arrow["{\text{compose}}", from=1-1, to=1-3]
\arrow["{\text{compose}}"', from=3-1, to=3-3]
\arrow["{\text{gradient descent}}"{description}, from=1-1, to=3-1]
\arrow["{\text{gradient descent}}"{description}, from=1-3, to=3-3]
\end{tikzcd}\]

Another drawback of traditional decomposition methods defined on graphs and hypergraphs which our framework addresses is that the resulting decompositions are flat, i.e., there is a single master problem coordinating all the subproblems. However, many practical problems exhibit hierarchical compositional structure, in which subproblems can themselves be master problems for a collection of lower level subproblems [18][19] [20]. Exploiting hierarchical structure when available can often lead to even faster solution times. Thus, a further benefit of our framework is the ability to capture and exploit such hierarchical structure. Specifically, stating our results in terms of operad algebras makes it clear that we can compose optimization problems hierarchically by recursive substitution of UWDs and that gradient descent must respect this hierarchical composition.

So far we have only spoken of gradient descent applied to non-convex differentiable minimization problems.

In addition, this paper presents a family of closely related results for different types of problems including unconstrained and equality constrained convex programs, and various first-order solution methods such as Uzawa's algorithm [21]

(also called gradient ascent-descent) and a primal-dual subgradient method [22]. Specifically, we show that each of these types of problems defines a UWD-algebra and each solution method provides an algebra morphism to dynamical systems. The full hierarchy of results presented in this paper is summarized in Figure <ref>. These extended results allow us to apply the same reasoning as above to derive message-passing versions of Uzawa's algorithm and dual decomposition within the same general framework.

This novel perspective on decomposition algorithms allows us to derive a new sufficient condition for when a problem is decomposable: namely, if there exists an algebra morphism from a UWD-algebra of data on which the problem is defined to one of our algebras of optimization problems which translates the problem data into an optimization problem.

We refer to this as the compositional data condition.
Satisfying the compositional data condition is also a constructive proof in that composing a problem translation morphism with the appropriate (sub)gradient morphism yields a distributed solution algorithm. This condition thus gives a principled way to convert problem data into explicit compositional problem structure which can be exploited via decomposition. To demonstrate the use of this sufficient condition, we show that the minimum cost network flow (MCNF) problem defines an algebra morphism from a UWD-algebra of flow networks to the UWD-algebra of unconstrained concave optimization problems, which when composed with the gradient ascent morphsim recovers a generalization of the standard dual decomposition algorithm for solving MCNF.

\[\begin{tikzcd}
& \Opt &&& \Conc \\
& \DiffSaddle &&& \Saddle && {\NDD_D} \\
\DiffConv && \DiffConc & {\Dynam_D} & \Conv
\arrow[hook, from=2-2, to=1-2]
\arrow[hook, from=3-1, to=2-2]
\arrow[hook, from=3-3, to=2-2]
\arrow["{\text{gd}}", curve={height=30pt}, from=3-1, to=3-4]
\arrow["{\text{ga}}"', from=3-3, to=3-4]
\arrow["{\text{ga-d}}", curve={height=-6pt}, from=2-2, to=3-4]
\arrow["{\text{gd}}", curve={height=-12pt}, from=1-2, to=3-4]
\arrow["{\text{sga}}", from=1-5, to=2-7]
\arrow["{\text{sga-d}}"', from=2-5, to=2-7]
\arrow["{\text{sgd}}"', from=3-5, to=2-7]
\arrow[hook, from=1-5, to=2-5]
\arrow[hook, from=3-5, to=2-5]
\end{tikzcd}\]

\[\begin{tikzcd}
\DiffConv &&& {\Dynam_D} \\
& \DiffSaddle \\
\Conv && \DiffConc & {\NDD_D} \\
& \Saddle \\
&& \Conc
\arrow[hook, from=1-1, to=2-2]
\arrow[hook, from=3-3, to=2-2]
\arrow[hook, from=5-3, to=4-2]
\arrow[hook, from=3-1, to=4-2]
\arrow[hook, from=1-1, to=3-1]
\arrow[hook, from=2-2, to=4-2]
\arrow[hook, from=3-3, to=5-3]
\arrow["{\text{sga-d}}"', from=4-2, to=3-4]
\arrow["{\text{ga-d}}"', from=2-2, to=1-4]
\arrow[from=1-4, to=3-4]
\end{tikzcd}\]

\[\begin{tikzcd}
& \Opt \\
\DiffConv &&& {\Dynam_D} \\
& \DiffSaddle \\
\Conv && \DiffConc & {\NDD_D} \\
& \Saddle \\
&& \Conc
\arrow[hook, from=2-1, to=3-2]
\arrow[hook, from=4-3, to=3-2]
\arrow[hook, from=6-3, to=5-2]
\arrow[hook, from=4-1, to=5-2]
\arrow[hook, from=2-1, to=4-1]
\arrow[hook, from=3-2, to=5-2]
\arrow[hook, from=4-3, to=6-3]
\arrow["{\text{pd-subg}}"'{pos=0.7}, from=5-2, to=4-4]
\arrow["{\text{ga-d}}"', from=3-2, to=2-4]
\arrow[from=2-4, to=4-4]
\arrow[hook, from=3-2, to=1-2]
\arrow["{\gd}", from=1-2, to=2-4]
\end{tikzcd}\]

\[\begin{tikzcd}
{} &&& {} \\
& \Opt \\
\DiffConv && {} & {\Dynam_D} \\
& \DiffSaddle \\
\Conv && \DiffConc & {\NDD_D} \\
& \Saddle \\
&& \Conc
\arrow[hook, from=3-1, to=4-2]
\arrow[hook, from=5-3, to=4-2]
\arrow[hook, from=7-3, to=6-2]
\arrow[hook, from=5-1, to=6-2]
\arrow[hook, from=3-1, to=5-1]
\arrow[hook, from=4-2, to=6-2]
\arrow[hook, from=5-3, to=7-3]
\arrow["\pdsubg"'{pos=0.7}, from=6-2, to=5-4]
\arrow["\gad"'{pos=0.7}, from=4-2, to=3-4]
\arrow[hook, from=3-4, to=5-4]
\arrow[hook, from=4-2, to=2-2]
\arrow["\gd"{pos=0.7}, curve={height=-12pt}, from=2-2, to=3-4]
\arrow[dashed, no head, from=3-1, to=1-1]
\arrow[dashed, no head, from=1-1, to=2-2]
\arrow[dashed, no head, from=2-2, to=3-3]
\arrow[dashed, no head, from=5-3, to=3-3]
\arrow[dashed, no head, from=2-2, to=1-4]
\arrow[dashed, no head, from=1-4, to=3-4]
\end{tikzcd}\]

The full hierarchy of results presented in this paper. Nodes represent the various UWD-algebras developed including those for composing saddle problems, convex problems, concave problems, all with and without differentiability assumptions, as well as composing deterministic and non-deterministic dynamical systems. Hooked arrows indicate that there is an inclusion of one algebra into another. Non-hooked arrows are the algebra morphisms including gradient descent ($\gd$), gradient ascent-descent ($\gad$) and the primal-dual subgradient method ($\pdsubg$). Composing the inclusions with the gradient algebra morphisms yields (sub)gradient descent for convex problems and (super)gradient ascent for concave problems.

In summary, our contributions are as follows.

* We construct a family of UWD-algebras for hierarchically composing different types of problems including non-convex $C^1$ problems as well as unconstrained and equality constrained convex programs.

* We prove that gradient descent and Uzawa's algorithm are algebra morphisms from their respective problem algebras to the algebra of dynamical systems. We further prove that subgradient variants of these algorithms also provide algebra morphisms into a novel UWD-algebra of non-deterministic dynamical systems.

* Based on these results, we provide a novel sufficient condition for when problems are decomposable in terms of algebra morphisms from data algebras into problem algebras.

* As a demonstration of this sufficient condition, we construct a UWD-algebra of flow networks and prove that the translation of a flow network into its associated minimum cost network flow optimization problem yields an algebra morphism. Composing this morphism with the gradient ascent morphism yields a hierarchical dual decomposition solution algorithm.

* We present a prototype implementation of this framework in the Julia programming language and empirically demonstrate how exploiting higher-level compositional structure can improve solution times by utilizing hierarchical decompositions of flow networks.

In this following section we use the word "extension" without saying exactly what we're extending

* We construct a UWD-algebra called $\Opt$ for hierarchically composing once differentiable optimization problems defined on hypergraphs.

* We prove that gradient descent is an algebra morphism from $\Opt$ to $\Dynam$, which provides a unified perspective on distributed gradient descent and primal decomposition algorithms.

* We develop an extension for composing saddle functions and solving them in a distributed fashion with Uzawa's algorithm, recovering dual decomposition as a special case.

* We develop an extension for solving non-differentiable problems using distributed subgradient descent. Along the way, we construct UWD-algebras for non-deterministic dynamical systems.

* We prove that minimum cost network flow defines a functor from flow networks to concave optimization problems, and composing with gradient ascent yields a generalization of a well known distributed solution method for solving this problem.

* We provide a prototype implementation of this framework and empirically demonstrate how exploiting higher-level compositional structure can improve solution times.

We hope that the presentation of this framework will benefit optimization researchers and practitioners in the following ways:

* Implementation. In the same way that disciplined convex programming [23] lowered the barrier of entry for specifying and solving convex optimization problems, our framework aims to lower the barrier of entry for composing optimization problems and automatically generating distributed solution algorithms.

* Performance. It is well known that exploiting problem structure can improve performance, and our framework can accommodate a broad array of structures to do so. For example, we demonstrate that the algorithm produced by our framework to solve minimum cost network flow for composite networks outperforms both a centralized solution method and a conventional distributed algorithm, and this performance improvement is attained by exploiting large scale compositional structure in flow networks.

* Formal Visualization. Undirected wiring diagrams provide an intuitive graphical syntax for composing problems. Further, UWD-algebras give a formal and unambiguous semantics to this graphical syntax, enabling diagrams to be compiled automatically to executable code.

* Generalization. In our framework, primal and dual decomposition are both recovered as special cases of applying the same UWD-algebra morphism. Consequently, our framework also enables the combination of primal and dual decomposition in a hierarchical fashion.
We hope that by presenting a general tool for building distributed optimization algorithms, new and unique algorithms can be discovered and implemented more easily.

* Relation to other fields. Framing our results in the language of category theory situates optimization decomposition methods in a broader mathematical landscape. For example, supervised learning [24, 25], optimal control [26], and game theory [27, 28] have all been studied using related categorical abstractions. We hope that by framing optimization decomposition methods in the same language, we can further elucidate the connections between these fields.

The rest of the paper is organized as follows. Section <ref> gives the relevant mathematical background in optimization and category theory. Specifically, Section <ref> reviews the definitions of operads, operad algebras, and operad algebra morphisms, which are the core abstractions we use to develop this framework. Section <ref> proves the fundamental result that gradient descent is an algebra morphism from the UWD-algebra of differentiable minimization problems to the UWD-algebra of dynamical systems. At this point, the core of the framework has been developed. Subsequent sections focus on extensions, generalizations, and examples.

Specifically, Section <ref> expands our framework to handle equality constrained convex programs by proving that Uzawa's algorithm yields an algebra morphism from a UWD-algebra of differentiable saddle functions to dynamical systems. Section <ref> generalizes this to primal-dual subgradient methods for handling equality constrained non-differentiable convex problems. To achieve this generalization we introduce new UWD-algebras for continuous and discrete non-deterministic dynamical systems, and prove that Euler's method is an algebra morphism in the non-deterministic setting.

Turning to applications, Section <ref> shows an example use of the compositional data condition by constructing a UWD-algebra of flow networks and proving that the minimum cost network flow problem defines an algebra morphism into the algebra of concave problems. Section <ref> presents empirical results obtained using our Julia implementation of this framework. Finally, Section <ref> offers concluding remarks and directions for future work.

§ PRELIMINARIES

This paper brings together concepts from first-order optimization and category theory. We assume knowledge of fundamental concepts of category theory, such as categories, functors, and natural transformations. Some prior exposure to symmetric monoidal categories and lax monoidal functors is also helpful. For convenience, we have compiled a list of important categorical definitions in Appendix <ref>. For a more complete explanation of basic category theory, a number of excellent introductory texts are available [29, 30, 31]. For an introduction to monoidal category theory, we refer the reader to [32]. Standard references for convex analysis and optimization are [33] and [34].

§.§ Notation

* Given an $n\in\mathbb{N}$, we use $[n]$ to denote the set $\{1,\dots,n\}$.

* Given a linear map $T\maps V\to W$, we use $\mathcal{M}(T)$ to denote the matrix representation of $T$ with respect to a chosen basis.

* We use $C^1$ to denote the set of once-continuously-differentiable functions.

* We use $+$ to denote the coproduct of two objects and $\coprod$ to denote the coproduct of an arbitary collection of objects. Likewise, we use $\times$ to denote the Cartesian product of two objects and $\prod$ to denote the Cartesian product of an arbitrary collection of objects.

§.§ First-order Optimization

In this section, we recall the basics of first-order optimization such as gradient descent for solving unconstrained minimization problems and Uzawa's algorithm for solving constrained minimization problems. We also briefly cover the notions of sub- and super-gradients and how these generalize first-order methods to non-differentiable problems.

First-order optimization methods find extrema of real valued objective functions using only information about the objective's value (zeroth-order information) and the objective's first derivatives (first-order information). Recall that the gradient of a differentiable objective function $f\maps \R^n\to \R$ at a point $x\in\R^n$ defines the direction to move from $x$ which would most quickly increase the value of $f$. Thus, if our task is to minimize $f$, the most natural method is gradient descent, which iterates

\begin{equation}
x_{k+1}\coloneqq x_k - \gamma \nabla f(x_k)
\end{equation}

from a given starting value $x_0$, where $\gamma>0$ is a parameter called the step size or learning rate in the context of machine learning. We call $x$ the decision variable or optimization variable.
In general, the gradient descent optimization scheme can be thought of as a family of maps

\begin{equation}
\gd_n\maps (\R^n\to\R)\to (\R^n\to\R^n)
\end{equation}

indexed by $n\in \mathbb{N}$ which takes a differentiable objective function $f\maps \R^n\to \R$ to the smooth map $-\nabla f\maps \R^n\to\R^n$ [35]. Such a smooth map implicitly defines both a continuous and a discrete dynamical system. The continuous system is given by the system of ordinary differential equations (ODEs)

\begin{equation}
\dot{x}\coloneqq -\nabla f(x)
\end{equation}

known as gradient flow, while the discrete system can be obtained by applying Euler's method to the continuous system. Specifically, given a smooth map $d\maps \R^n\to\R^n$ defining the ODE $\dot{x}\coloneqq d(x)$, Euler's method for a given step size $\gamma>0$ gives the discrete system $x_{k+1}\coloneqq x_k+\gamma d(x_k)$. The discrete gradient descent algorithm is thus the result of applying Euler's method to gradient flow.

With a suitable choice of step size and mild assumptions on $f$, gradient descent is guaranteed to converge to a local minimum. Under stricter convexity assumptions on $f$, gradient descent can be shown to converge to a global minimum. Recall that a function $f\maps \R^n\to \R$ is convex if it satisfies Jensen's inequality, i.e.,

\begin{equation}\label{eq:jensen}
f(tx + (1-ty)) \leq tf(x) + (1-t)f(y)
\end{equation}

for all $x,y\in\R^n$ and $t\in[0,1]$. When the inequality in (<ref>) is strict, $f$ is called strictly convex.

The basic idea behind gradient descent can be extended to also solve constrained minimization problems. A generic equality-constrained minimization problem $P$ has the standard form

\begin{equation*}
P: \left\{\begin{array}{ll@{}ll}
\text{minimize} & f & (x) & \\
\text{subject to} & h & (x) = 0.
\end{array}\right.
\end{equation*}

The function $h\maps \R^n\to\R^m$ defines $m$ equality constraints. If $f$ is convex and $h(x)=Ax-b$ is affine, then $P$ is a convex optimization problem. We consider this case for the remainder of Section <ref>. A standard method for solving $P$ is via Lagrangian relaxation, which relaxes the constrained problem in $\R^n$ to an unconstrained problem in $\R^{n+m}$. Specifically, the Lagrangian of $P$ is the function

\begin{equation}
L(x,\lambda)\coloneqq f(x) + \lambda^T(Ax-b).
\end{equation}

The components of $\lambda\in\R^m$ are called the Lagrange multipliers and there is one for each constraint. The Lagrangian is a saddle function as it is convex in $x$ for any fixed $\lambda$ and concave in $\lambda$ for any fixed $x$. The key insight of Lagrange was that saddle points of $L$, i.e., points $(\hat{x}, \hat{\lambda}) \in \argmin_{x \in \mathbb{R}^n} \argmax_{\lambda \in \mathbb{R}^m} L(x, \lambda)$, correspond to constrained minima of $P$. As such, finding a saddle point of $L$ is sufficient for solving $P$ ([34], 5.4.2).

Uzawa's algorithm is a straightforward generalization of gradient descent for finding saddle points of saddle functions. Specifically, it performs gradient descent on the convex part of the saddle function and gradient ascent on the concave part. Applying this to the Lagrangian $L$ gives the algorithm

\begin{equation}
\begin{array}{ll@{}ll}
x_{k+1} & \coloneqq x_k - \gamma \nabla_x L(x_k,\lambda_k)  \\
\lambda_{k+1} & \coloneqq \lambda_k +\gamma\nabla_\lambda L(x_k,\lambda_k).
\end{array}
\end{equation}

This can again be seen as the Euler discretization applied to a continuous system, which we call saddle flow:

\begin{equation}
\begin{array}{ll@{}ll}
\dot{x} &\coloneqq -\nabla_x L(x,\lambda) \\
\dot{\lambda} & \coloneqq \nabla_\lambda L(x,\lambda).
\end{array}
\end{equation}

Under similar conditions to gradient descent, Uzawa's algorithm converges to a saddle point of $L$.

Finally, most of these ideas can be generalized to the case when $f$ and $h$ are still convex and affine, respectively, but not necessarily differentiable. For example, the absolute value function is a common objective which is convex but not differentiable at zero. Minimizing such a function is achieved through a generalization of the gradient to convex functions that need not be differentiable.

Given a convex function $f\maps\R^n\to\R$, a vector $v\in\R^n$ is called a subgradient at a point $x\in \R^n$ if for every $y\in\R^n$,

\begin{equation}
f(y) - f(x) \geq v^T(y - x).
\end{equation}

The set of all such points is called the subdifferential of $f$ at $x$.

Similarly, when $f$ is concave, a vector $w\in\R^n$ is called a supergradient at a point $x\in\R^n$ if for every $y\in\R^n$,

\begin{equation}
f(y) - f(x) \leq w^T(y-x).
\end{equation}

The set of all such points is called the superdifferential of $f$ at $x$. The superdifferentials and subdifferentials of $f$ at $x$ are both denoted $\partial f(x)$; the distinction between super and sub will be clear from context.

The subdifferential of a convex function $f$ at a point $x$ is the set of affine under-approximations of $f$ at $x$. When $f$ is differentiable at $x$, $\partial f(x)$ is the singleton set $\{\nabla f(x)\}$, implying that the subgradient is a proper generalization of the gradient for convex functions.

The subdifferential is the basis for an iterative algorithm to find minima of non-differentiable convex functions, known as subgradient descent. For a convex objective function $f\maps\R^n\to \R$, this simply iterates

\begin{equation}
x_{k+1} = x_k - \gamma \rho_k,
\end{equation}

where $\rho_k$ is any subgradient of $f$ at $x_k$[This subgradient method is not guaranteed to descend at each iteration. However, by keeping track of the best iterate found so far, this can be made into a descent method.]. The continuous-time analog of subgradient descent is subgradient differential inclusion, given by the system

\begin{equation}
\dot{x}\in -\partial f(x).
\end{equation}

It is important to note that because the subdifferential is a point-to-set mapping, these dynamical systems are non-deterministic, meaning that at a given state, they can evolve in different directions. In spite of this non-determinism, subgradient descent also converges to within an $\epsilon$-neighborhood of a minimum, where $\epsilon$ scales with step size. By using a combination of subgradients and supergradients, such methods can be extended to find extrema of non-differentiable saddle functions.

§.§ Algebras of Undirected Wiring Diagrams

An undirected wiring diagram (UWD) is a combinatorial object representing a pattern of interconnection between boxes and junctions. Specifically, a UWD consists of finite sets of boxes and junctions. Each box has a finite set of ports associated to it, and each port is wired to a junction. One of the boxes is distinguished as an outer box, and the ports on the inner boxes and outer box are referred to as inner ports and outer ports respectively. An example UWD is shown in Figure <ref>.A.

The goal of this section is to define algebras on the operad of undirected wiring diagrams and show how they can be specified by lax symmetric monoidal functors $(\FinSet,+)\to (\Set,\times)$, which we call finset algebras.

Similarly, we discuss how monoidal natural transformations between finset algebras give rise to UWD-algebra morphisms. These will be the core abstractions repeatedly utilized throughout the paper. We ground this section with the examples from [17] of continuous and discrete dynamical systems as UWD-algebras and Euler's method as an algebra morphism from continuous to discrete.

Intuitively, undirected wiring diagrams give a syntax for composition, and can be imbued with various semantics. Formally, UWDs form an operad and a specific choice of semantics is given by an operad algebra.

An symmetric coloured operad $\mathcal{O}$ consists of the following:

* A collection of objects,

* For each $n\in \mathbb{N}^+$ and collection of objects $s_1,\dots,s_n,t$ in $\mathcal{O}$, a collection of morphisms $\mathcal{O}(s_1,\dots,s_n;t)$,

* An identity morphism $\id_t\in\mathcal{O}(t;t)$ for each object $t$,

* Composition maps of the form

\begin{equation}
\mathcal{O}(s_1,\dots,s_n;t)\times \prod_{i=1}^n\mathcal{O}(r_{i,1},\dots,r_{i,m_i};s_i) \to \mathcal{O}(r_1,\dots,r_n;t),
\end{equation}

where $r_i = r_{i,1},\dots,r_{i,m_i}$.

* Permutation maps of the form

\begin{equation}
\OO(s_1,\dots,s_n;t)\to \OO(s_{\sigma(1)},\dots, s_{\sigma(n)};t)
\end{equation}

for every permutation $\sigma$ in the symmetric group $\Sigma_{[n]}$.

This data is subject to suitable identity, associativity, and symmetry laws.

Henceforth, we simply use the term operad to refer to symmetric coloured operads. A basic but essential operad is that of sets.

The operad of sets, denoted $\Sets$, has sets as objects. Given sets $X_1,\dots,X_n,Y$, the morphisms in $\Sets(X_1,\dots,X_n;Y)$ are the functions $X_1\times\dots\times X_n\to Y$. Given composable morphisms $g\maps Y_1\times\dots\times Y_n\to Z$ and $f_i\maps X_{i,1}\times\dots\times X_{i,m_i}\to Y_i$ for all $i\in [n]$, the composite is the function

\begin{equation}
(X_{1,1}\times\dots\times X_{1,m_1})\times\dots\times (X_{n,1}\times\dots \times X_{n,m_n})\xrightarrow{f_1\times\dots\times f_n} Y_1\times\dots\times Y_n\xrightarrow{g}Z.
\end{equation}

A. An example UWD with two inner boxes. B. The cospan representation of the UWD in (A). The signature of this UWD is $\{1,2\}+\{3,4\}\to \{a,b,c\}\leftarrow\{1',2'\}$.

To see how UWDs form an operad, first note that any UWD with $n$ inner boxes can be encoded by a pair of functions $P_1+\dots+P_n\xrightarrow{l} J\xleftarrow{r}P'$, where $P_i$ is the set of inner ports of box $i$, $J$ is the set of junctions, and $P'$ is the set of outer ports. The function $l$ then encodes the connection pattern of inner ports to junctions, while $r$ encodes the connection pattern of outer ports to junctions. Such a pair of morphisms with common codomain is called a cospan. Figure <ref> shows an example of the correspondance between a UWD and its cospan representation.

The operad of UWDs, denoted UWD, has finite sets as objects. Given finite sets $P_1\dots,P_n,P'$, a morphism in $\UWD(P_1,\dots,P_n;P')$ is a UWD with those ports, i.e., a choice of finite set $J$ and a cospan $P_1+\dots+P_n\xrightarrow{l} J\xleftarrow{r}P'$. Given composable UWDs

\begin{equation}
\coprod_{i\in[n]}Y_i\xrightarrow{l'} J'\xleftarrow{r'} Z,
\end{equation}

\begin{equation}
\coprod_{j\in [m_i]} X_{i,j}\xrightarrow{l_i}J_i\xleftarrow{r_i} Y_i,
\qquad i \in [n],
\end{equation}

their composite is defined by taking the following pushout:

\[\begin{tikzcd}
&&&& Z \\
\\
&& {\coprod_{i\in [n]}Y_i} && {J'} \\
\\
{\coprod_{i\in[n]}\coprod_{j\in[m_i]}X_{i,j}} && {\coprod_{i\in[n]}J_i} && {J''}
\arrow["{r'}", from=1-5, to=3-5]
\arrow["{l'}", from=3-3, to=3-5]
\arrow["{\coprod_ir_i}"', from=3-3, to=5-3]
\arrow["{\coprod_il_i}"', from=5-1, to=5-3]
\arrow["p"', from=5-3, to=5-5]
\arrow["q", from=3-5, to=5-5]
\arrow["\lrcorner"{anchor=center, pos=0.125, rotate=180}, draw=none, from=5-5, to=3-3]
\end{tikzcd}\]

The composite UWD is then given by the cospan with left leg $p\circ \coprod_il_i$ and right leg $q\circ r'$.
The identity UWD on $X$ is the identity cospan $X=X=X$.

Although composition of UWDs is somewhat complicated to define formally, it has an intuitive explanation. It takes a “target" UWD with $n$ inner boxes along with $n$ “filler" UWDs and substitutes one of the filler UWDs into each of the inner boxes of the target UWD. This operation is only defined when each filler UWD has the same number of outer ports as the number of ports on the inner box it is filling.

Having defined the operad of UWDs and the operad of sets, we can now construct UWD-algebras, which give semantic interpretations to UWDs. These are special cases of operad functors, which are the operadic analogue of functors between categories.

A UWD-algebra is an operad functor $F\maps \UWD\to \Sets$. Unpacking this definition, $F$ consists of an object map taking each finite set $P$ to a set $F(P)$ and a morphism map taking each UWD of the form $\Phi\maps P_1+\dots + P_n\to J\leftarrow P'$ to a function $F(\Phi)\maps F(P_1)\times\dots\times F(P_n)\to F(P')$. These maps must respect the following axioms:

* $F$ preserves identities, i.e., $F(\id_X)=\id_{F(X)}$ for all objects $X$.

* $F$ respects composition, i.e., the following diagram commutes for all composable UWDs:

\[\begin{tikzcd}
{\UWD(Y_1,\dots,Y_n;Z)\times\prod_{i\in[n]}\UWD(X_i;Y_i)} & {\UWD(X_1,\dots,X_n;Z)} \\
\\
{\Sets(FY_1,\dots,FY_n;FZ)\times\prod_{i\in[n]}\Sets(FX_i;FY_i)} & {\Sets(FX_1,\dots,FX_n;FZ)}
\arrow["\circ", from=1-1, to=1-2]
\arrow["\circ"', from=3-1, to=3-2]
\arrow["F"', from=1-1, to=3-1]
\arrow["F", from=1-2, to=3-2]
\end{tikzcd}\]

where $X_i\coloneqq X_{i,1},\dots,X_{i,m_i}$ and $FX_i$ denotes objectwise application of $F$ to each $X_{i,j}$. Intuitively, this diagram says that the result of substituting UWDs and then applying the algebra must be the same as applying the algebra to each component UWD and then composing those as functions.

Given a UWD $\Phi\in \UWD(P_1,\dots,P_n;P')$ and fillers $o_i\in F(P_i)$ for all $i\in[n]$, we refer to the resultant $o'\in F(P')$ obtained by $F(\Phi)(o_1,\dots,o_n)$ as an $F$-UWD.

We can think of a UWD-algebra $F$ applied to a finite set $X$ as defining the set of possible objects which can fill a box with $X$ connection points. Then, we can think of $F$ applied to a UWD $\Phi$ as a composition function which specifies how to compose objects filling each inner box of $\Phi$ into an object which fills the outer box of $\Phi$.

Given UWD-algebras $F,G\maps \UWD\to \Sets$, an algebra morphism $\alpha\maps F\Rightarrow G$ consists of, for every finite set $X$, a function $\alpha_X\maps F(X)\to G(X)$, known as the component of $\alpha$ at $X$. These components must obey the following law:
given a UWD $\Phi\maps P_1+\dots +P_n\to J\leftarrow P'$, the following naturality square must commute:

\[\begin{tikzcd}
{\prod_{i\in [n]}F(P_i)} && {\prod_{i\in[n]}G(P_i)} \\
{F(P')} && {G(P')}
\arrow["{F(\Phi)}"', from=1-1, to=2-1]
\arrow["{G(\Phi)}", from=1-3, to=2-3]
\arrow["{\prod_i\alpha_{P_i}}", from=1-1, to=1-3]
\arrow["{\alpha_{P'}}"', from=2-1, to=2-3]
\end{tikzcd}\]

Intuitively, naturality of $\alpha$ just says that composing objects with $F$ then transforming the composite to an object of $G$ is the same as transforming each component object and composing with $G$.

There is an important connection between the operadic definitions presented above and (i) symmetric monoidal categories (SMCs),
(ii) lax symmetric monoidal functors, and (iii) monoidal natural transformations (consult Appendix <ref> for these definitions). Specifically, every SMC $(\CC,\otimes)$ has an underlying operad $\OO(\CC)$ with objects the same as those of $\CC$ and whose morphisms $\OO(\CC)(s_1,\dots,s_n;t)$ are the morphisms $s_1\otimes\dots\otimes s_n\to t$ in $\CC$. For example, $\Sets$ is the operad underlying the SMC $(\Set,\times)$. Similarly, $\UWD$ is the operad underlying the SMC $(\Cospan,+)$ of cospans between finite sets, where composition is given by pushout and the monoidal product is given by disjoint union. Furthermore, every lax symmetric monoidal functor $(F,\varphi)\maps (\CC,\otimes)\to (\DD,\boxtimes)$ gives rise to an operad functor $\OO(F)\maps \OO(\CC)\to\OO(\DD)$ which acts on objects the same as $F$ and on morphisms $f\maps X_1\otimes\dots\otimes X_n\to Y$ is defined as

\begin{equation}
\OO(F)(f)\coloneqq F(X_1)\boxtimes\dots\boxtimes F(X_n)\xrightarrow{\varphi_{X_1,\dots,X_n}}F(X_1\otimes\dots\otimes X_n)\xrightarrow{F(f)}F(Y).
\end{equation}

Thus, we can specify UWD-algebras by specifying lax symmetric monoidal functors $(\Cospan,+)\to (\Set,\times)$, also known as cospan algebras [36]. Finally, the components of monoidal natural transformations $\alpha\maps F\Rightarrow G$ between cospan algebras will also be natural as components of a UWD-algebra morphism $\alpha \maps \OO(F)\Rightarrow \OO(G)$ [37]. Because of this tight connection, we will typically use the concepts of SMCs, lax symmetric monoidal functors, and monoidal natural transformations interchangably with their operadic counterparts moving forward.

Throughout this paper, we utilize a particularly well behaved class of cospan algebras, namely those generated by lax symmetric monoidal functors from $(\FinSet,+)\to (\Set,\times)$, which we call finset algebras. The following simple, but fundamental, example illustrates the use of finset algebras to define linear maps which merge or copy components of their inputs.

[Pushforwards and Pullbacks]

A visualization of the relationship between a function $\phi\maps[2]+[3]\to [4]$, the action of the pushforward $\phi_*$ on an input pair $(x,y)$, and the action of the pullback $\phi^*$ on an input $z$. The pushforward sums components of $(x,y)$ according to $\phi$ while the pullback duplicates components of $z$ according to $\phi$.

Given a finite set $N$, the set of functions $\{N\to\R\}=\R^N$ is a vector space, which is called the free vector space generated by $N$. If we let $n\coloneqq |N|$ be the cardinality of $N$, then choosing an ordering $N\xrightarrow{\cong}[n]$ on $N$ induces an isomorphism of vector spaces $\R^N\cong \R^n$.
We can thus think of the free vector space $\R^N$ as standard $n$-dimensional Euclidean space, but where each basis vector is labelled by an element of $N$. This free vector space construction will be essential for creating UWD-algebras whose semantics are given by functions defined on $\R^n$ such as objective functions and dynamical systems. First, we consider two ways of constructing linear maps between free vector spaces that give rise to finset algebras.

Given a function $\phi\maps N\to M$ between finite sets, the pushforward along $\phi$ is the linear map $\phi_*\maps\R^N\to\R^M$ defined by

\begin{equation}
\phi_*(x)_j \coloneqq \sum_{i\in \phi^{-1}(j)} x_i
\end{equation}

for all $x\in\R^N$ and $j\in M$. This lets us define the strong[A strong symmetric monoidal functor is one whose comparison maps are all isomorphisms (see Definition <ref>).] finset algebra $(-)_*\maps (\FinSet,+)\to (\Set,\times)$, which takes finite sets to their free vector spaces and functions between finite sets to their pushforwards. The product comparison is given by the isomorphisms $\varphi_{N,M}\maps \R^N\times\R^M\cong \R^{N+M}$, while the unit comparison $\varphi_0\maps 1\to \R^\emptyset$ is unique because $\R^\emptyset$ contains only the zero vector.

Given a function $\phi\maps X+Y\to Z$, we can apply this finset algebra to produce a linear map which takes a pair of vectors $x\in\R^X$ and $y\in\R^Y$ as input, applies the product comparison isomorphism to concatenate $x$ and $y$ into a single vector, then applies the pushforward $\phi_*$ to the resultant vector.

A dual operation to the pushforward along $\phi$ is the pullback along $\phi$, which is the linear map $\phi^*\maps \R^M\to \R^N$ defined by

\begin{equation}
\phi^*(y)_i\coloneqq y_{\phi(i)}
\end{equation}

for all $y\in\R^M$ and $i\in N$. It is straightforward to show that the pullback along $\phi$ is dual as a linear map to the pushforward along $\phi$. The pullback operation defines a contravariant finset algebra $(-)^*\maps (\FinSet^{op},+)\to (\Set,\times)$
taking finite sets to their free vector spaces and functions to their pullbacks. The product comparisons and unit comparison are the same as those of $(-)_*$, but in the opposite direction. This algebra takes a function $\phi\maps X+Y\to Z$ and a vector $z\in \R^Z$ and produces a pair of vectors in $\R^X\times\R^Y$ by copying components of $z$ into the respective components of the results dictated by $\phi$. This is illustrated in Figure <ref>.

Intuitively, the action of a finset algebra on a morphism $\phi\maps X_1+\dots + X_n\to Y$ specifies how to compose an $n$-tuple of objects defined on $X_1,\dots,X_n$ into a single object defined on $Y$. Such an action is sufficient to specify a UWD-algebra, as described in the following lemma.

Given a lax symmetric monoidal functor $(F,\varphi)\maps (\FinSet,+)\to(\Set,\times)$, there is a lax symmetric monoidal functor $(F\textnormal{Csp},\varphi')\maps (\Cospan,+)\to(\Set,\times)$ defined by the following maps:

* On objects, $F\textnormal{Csp}$ takes a finite set $X$ to the set of triples of the form $(S\in\FinSet, o\in F(S), m\maps X\to S)$.

* Given a cospan $\Phi\coloneqq (X\xrightarrow{l}J\xleftarrow{r} Y)$, the function $F\textnormal{Csp}(\Phi)\maps F\textnormal{Csp}(X)\to F\textnormal{Csp}(Y)$ is defined by

\begin{equation}
(S,o,m)\mapsto (S+_X J, F(p_S)(o), p_J\circ r),
\end{equation}

where $S+_X J, p_S$, and $p_J$ are defined by the pushout:

\[\begin{tikzcd}
& X && Y \\
S && J \\
& {S+_XJ}
\arrow["m", from=1-2, to=2-1]
\arrow["l"', from=1-2, to=2-3]
\arrow["r", from=1-4, to=2-3]
\arrow["{p_S}"', from=2-1, to=3-2]
\arrow["{p_J}", from=2-3, to=3-2]
\arrow["\lrcorner"{anchor=center, pos=0.125, rotate=135}, draw=none, from=3-2, to=1-2]
\end{tikzcd}\]

* Given objects $N,M\in\FinSet$, the product comparison

\begin{equation}
\varphi'_{N,M}\maps F\textnormal{Csp}(N)\times F\textnormal{Csp}(M)\to F\textnormal{Csp}(N+M)
\end{equation}

is given by

\begin{equation}
\varphi'_{N,M}((S_1,o_1,m_1),(S_2,o_2,m_2))\coloneqq (S_1+S_2, \varphi_{S_1,S_2}(o_1,o_2),m_1+m_2),
\end{equation}

where $\varphi_{S_1,S_2}$ is the product comparison of $F$.

* The unit comparison $\varphi'_0\maps \1\to F\textnormal{Csp}(\emptyset)$ picks the triple $(\emptyset,\varphi_0,\emptyset\xrightarrow{!}\emptyset)$,
where $\varphi_0$ is the unit comparison of $F$.

This is an application of the equivalence between hypergraph categories and cospan algebras proven in [36] to the hypergraph category of $F$-decorated cospans introduced in [38]. This is also straightforward to prove directly.

We can develop intuition for this lemma by again thinking in terms of UWDs. The set of triples $(S, o, m\maps X\to S)$ obtained by applying $F\textnormal{Csp}$ to $X$ corresponds to the set of fillers for a UWD box with $X$ ports. However, the object filling a box is allowed to have a domain $S$ other than $X$, and $m\maps X\to S$ determines the relationship between the ports of the box and the domain of the filling object. Then, treating the cospan $\Phi\coloneqq X\xrightarrow{l}J\xleftarrow{r} Y$ as a UWD, the map $l\maps X\to J$ specifies the gluing of inner ports to junctions. By taking the pushout of $m$ and $l$, the map $p_S\maps S\to S+_XJ$ specifies how to glue together the domains of the objects filling each box: if two ports are mapped to the same junction by $l$, then their image under $m$ will be mapped to the same element of $S+_XJ$ by $p_S$.

With this perspective, the fundamental operation is applying $F$ to the function $p_S$, which should specify how to glue together parts of an object with domain $S$ to produce an object with domain $S+_XJ$ according to $p_S$. The rest of the operations are essentially book-keeping operations to produce a valid UWD with this new object as its filler.

Consider a UWD-algebra $F\mathrm{Csp}$ generated by a finset algebra $F$ by applying Lemma <ref>. If we restrict our attention to UWDs of the form $\Phi\coloneqq (X\xrightarrow{\phi}J\cong Y)$, so that every junction maps to a unique outer port, and only consider algebra objects $F\mathrm{Csp}(X)$ of the form $(S, o\in F(S), X\xrightarrow{\cong}S)$, we get a subalgebra that corresponds directly to the finset algebra $F$. Specifically, the pushout needed to define the function $F\mathrm{Csp}(\Phi)\maps F\mathrm{Csp}(X)\to F\mathrm{Csp}(Y)$ is

\[\begin{tikzcd}
& X && Y \\
S && J \\
& J
\arrow["\phi", from=1-2, to=2-3]
\arrow["\cong"', from=1-4, to=2-3]
\arrow["{\cong}"', from=1-2, to=2-1]
\arrow["\phi"', from=2-1, to=3-2]
\arrow["{\cong}", from=2-3, to=3-2]
\arrow["\lrcorner"{anchor=center, pos=0.125, rotate=135}, draw=none, from=3-2, to=1-2]
\end{tikzcd}\]

and the result of $F\mathrm{Csp}(\Phi)(S,o,X\xrightarrow{\cong}S)$ is $(J, F(\phi)(o), Y\xrightarrow{\cong}J)$.

Therefore, in this restricted case that the set of outer ports is isomorphic to the set of junctions and each UWD filler has a domain which is isomorphic to the set of ports on the box it is filling, we obtain the resulting composite object by simply applying our finset algebra $F$ to the function $\phi$ which maps inner ports to junctions.

We will make use of this simplification in some of our examples, but we emphasize that all this machinery still works for general UWDs and algebra objects.

In a similar vein, we can use monoidal natural transformations between finset algebras to define monoidal natural transformations between cospan algebras.

Suppose we are given two lax symmetric monoidal functors $F,G\maps(\FinSet,+)\to(\Set,\times)$ and a monoidal natural transformation $\alpha\maps F\Rightarrow G$. Let $F\textnormal{Csp}$ and $G\textnormal{Csp}$ be the cospan algebras which result from applying Lemma <ref> to $F$ and $G$. Then there is a monoidal natural transformation $\alpha'\maps F\textnormal{Csp}\Rightarrow G\textnormal{Csp}$ with components $\alpha'_N\maps F\textnormal{Csp}(N)\to G\textnormal{Csp}(N)$ defined by

\begin{equation}
(S,v\in F(S), m\maps N\to S)\mapsto (S,\alpha_S(v),m).
\end{equation}

This is an application of the equivalence between cospan algebra morphisms and hypergraph functors proven in [36] applied to the hypergraph functor induced by applying Theorem 2.8 in [38] to $\alpha$.

In summary, we can build a UWD-algebra from a finset algebra $F$ by applying Lemma <ref> to produce a cospan algebra $F\mathrm{Csp}$ and then taking its underlying operad functor $\OO(F\mathrm{Csp})$. Similarly, given finset algebras $F$ and $G$ and a monoidal natural transformation $\alpha\maps F\Rightarrow G$, we can produce a UWD-algebra morphism by applying Lemma <ref> to obtain a monoidal natural transformation $\alpha'\maps F\mathrm{Csp}\Rightarrow G\mathrm{Csp}$. The components of $\alpha'$ then also define the algebra morphism $\alpha'\maps\OO(F\mathrm{Csp})\Rightarrow \OO(G\mathrm{Csp})$.

All the UWD-algebras we define in this paper will be generated by a finset algebra in the way described above. Similarly, all algebra morphisms we define will come from monoidal natural transformations between finset algebras. Consequently, for the remainder of this paper, we elide the difference between finset algebras and their associated UWD-algebras. Specifically, whenever we define a finset algebra $F$, uses of $F$ beyond the definition implicitly refer to $\OO(F\textnormal{Csp})$.

[Building Linear Maps with UWDs]

A. An example of the collect algebra acting on a UWD $\Phi$ with two inner boxes. The resulting linear map $\Phi_*$ takes a pair of vectors in $\R^2\times \R^2$ as input and produces a vector in $\R^3$ by summing the components of the inputs which share the same junction in $\Phi$. Arrows are added to emphasize that the flow of information is directed from the inner boxes to the boundary box. B. An example of the distribute algebra acting on $\Phi$. The resulting linear map $\Phi^*$ takes a vector in $\R^3$ and produces a pair of vectors in $\R^2\times \R^2$ by copying components of the input which share the same junction in $\Phi$. Arrows are added to emphasize that the flow of information is directed from the boundary box to the inner boxes. The matrix representations are with respect to the standard bases.
Note that these examples satisfy the simplifying assumptions of Remark <ref>.

We can apply Lemma <ref> to the pushforward and pullback algebras defined in Example <ref> to lift them to UWD-algebras. This lets us use the graphical syntax of UWDs to specify linear maps.

We call the UWD-algebra obtained by applying Lemma <ref> to the pushforward algebra the collect algebra because it takes vectors for each inner box of a UWD and collects them into a vector for the outer box. Likewise, we call the UWD-algebra obtained by applying Lemma <ref> to the pullback algebra the distribute algebra because it takes a vector for the outer box and distributes it to produce vectors for each inner box. Both these operations are shown in Figure <ref>.

Simple though they are, these algebras will be indispensable to defining the subsequent algebras of optimization problems and dynamical systems.

[Composing Dynamical Systems]
There is a finset algebra $\Dynam\maps (\FinSet,+)\to (\Set,\times)$ given by the following maps:

* On objects, $\Dynam$ takes a finite set $N$ to the set of smooth maps $\{\upsilon\maps \R^N\to \R^N\}$.

* Given a morphism $\phi\maps N\to M$ in $\FinSet$, $\Dynam(\phi)\maps \Dynam(N)\to\Dynam(M)$ is defined by the function $\upsilon\mapsto \phi_*\circ \upsilon \circ\phi^*$.

* Given finite sets $N$ and $M$, the product comparison $\varphi_{N,M}\maps \Dynam(N)\times\Dynam(M)\to\Dynam(N+M)$ is given by the function

\begin{equation}
(\upsilon,\rho)\mapsto \iota_{N*}\circ\upsilon \circ\iota_N^* + \iota_{M*}\circ\rho\circ\iota_M^*,
\end{equation}

where $\iota_N\maps N\to N+M$ and $\iota_M\maps M\to N+M$ are the natural inclusions.

* The unit comparison $\varphi_0\maps \1\to\Dynam(\emptyset)$ is uniquely determined because the set of maps $\{\R^0\to \R^0\}$ is a singleton.

This example is the content of Lemmas 15 and 16 in [13].

We can now apply Lemma <ref> to obtain a UWD-algebra for composing dynamical systems.

A filler for a box in a $\Dynam$-UWD with $X$ ports is a triple $(S, \upsilon\maps \R^S\to\R^S, m\maps X\to S)$. We refer to such an object as an open dynamical system, because it designates only a subset of the system's state variables as being open to sharing with other systems. This is determined by the map $m\maps X\to S$. The connection pattern of ports to junctions in a UWD then specifies which open state variables of one system are shared with which open state variables of other systems. The overall intuitive picture of composite systems obtained by $\Dynam$ is that the change in a shared state variable is the sum of changes from contributing subsystems, where a UWD indicates which state variables are shared.

Now, we explicitly unpack the definition of composition given by the $\Dynam$ UWD-algebra. First, given a UWD $\Phi\maps X_1+\dots + X_n\xrightarrow{l} J \xleftarrow{r} Y$ and component open dynamical systems, $(S_i, \upsilon_i\maps \R^{S_i}\to\R^{S_i}, m_i\maps X_i\to S_i)$ for all $i\in [n]$, the product comparison is applied to the component systems to produce a single system which can be thought of as the disjoint union of the input systems. Explicitly, this is the open system $(S\coloneqq S_1+\dots+S_n, \upsilon\maps \R^S\to \R^S, m\coloneqq m_1 + \dots + m_n)$, where the dynamics $\upsilon$ are given by

\begin{equation}\label{eq:lax-d}
\sum_{i=1}^n \iota_{S_i *}\circ\upsilon_i\circ\iota_{S_i}^*.
\end{equation}

Here, the $\iota_{S_i}$'s are the natural inclusions of $S_i$ into $S$, so (<ref>) can be thought of as simply “stacking" the dynamics of $\upsilon_1$ through $\upsilon_n$, with no interactions occurring between subsystems. Then, to complete the composition, let $X\coloneqq X_1+\dots+X_n$ and form the following pushout.

\[\begin{tikzcd}
& X && Y \\
S && J \\
& {S+_XJ}
\arrow["m", from=1-2, to=2-1]
\arrow["l"', from=1-2, to=2-3]
\arrow["r", from=1-4, to=2-3]
\arrow["{p_S}"', from=2-1, to=3-2]
\arrow["{p_J}", from=2-3, to=3-2]
\arrow["\lrcorner"{anchor=center, pos=0.125, rotate=135}, draw=none, from=3-2, to=1-2]
\end{tikzcd}\]

The composite open dynamical system is then

\begin{equation}
(S+_X J, p_{S*}\circ\upsilon \circ p_S^*, p_J\circ r).
\end{equation}

The dynamics of this composite system uses the distribute algebra to distribute the current state vector to the subsystems and the collect algebra to collect the results of each subsystem applied to its part of the state vector. Crucially, components of the state vector which inhabit shared junctions of $\Phi$ are copied to the subsystems incident to those junctions by the distribute algebra, and the results from each incident subsystem are summed by the collect algebra to obtain a state update for the junction.

At this point, we introduce some notation to make it easier to write down composite systems. Given a collection of $m$ systems $\{\upsilon_j\maps\R^{N_j}\to\R^{N_j}\mid j\in[m]\}$, we denote the action of $\Dynam$'s product comparison $\varphi_{N_1,\dots,N_m}(\upsilon_1,\dots,\upsilon_m)$ as

\begin{equation}
\begin{bmatrix}
\upsilon_1 \\
\vdots \\
\upsilon_m
\end{bmatrix}.
\end{equation}

We use this notation to emphasize that the system obtained by applying the product comparison just “stacks up" the individual input dynamical systems.

We can slightly modify $\Dynam$ to produce a UWD-algebra for composing discrete dynamical systems, as in Proposition 3.1 of [17]. There is a finset algebra $\Dynam_D\maps(\FinSet,+)\to(\Set,\times)$ given by the following maps:

* On objects, $\Dynam_D$ takes a finite set $N$ to the set of discrete dynamical systems $\{\upsilon \maps \R^N\to\R^N\}$.

* Given a morphism $\phi\maps N\to M$ in $\FinSet$, $\Dynam_D(\phi)\maps\Dynam_D(N)\to\Dynam_D(M)$ is defined by the function $v\mapsto \id_{\R^M} + \phi_*\circ (v - \id_{\R^N})\circ \phi^*$, where the $\id$'s are in $\Vect$.

* The comparison maps are the same as $\Dynam$.

Proposition 3.3 of [17] shows that Euler's method for a given stepsize $\gamma>0$ defines the components of an algebra morphism from continuous to discrete systems. Specifically, there is a monoidal natural transformation $\Euler^\gamma\maps \Dynam\Rightarrow\Dynam_D$ with components

\begin{equation}
\Euler^\gamma_N\maps\Dynam(N)\to\Dynam_D(N),\;
\upsilon\mapsto \id_{\R^N} + \gamma\upsilon.
\end{equation}

Systems inhabiting $\Dynam$-UWDs have a natural message passing semantics. Specifically, at each time point, the “distribute” step is given by applying the distribute algebra to the current state vector to project the relevant components to their associated subsystems. The parallel computation step is given by applying each of the subsystem dynamics, and the “collect” step is given by applying the collect algebra to the results. These steps will enable our formalization of decomposition methods in the subsequent sections.

§ GRADIENT DESCENT IS AN ALGEBRA MORPHISM

This section develops the fundamental result of the paper: that gradient descent is an algebra morphism from a UWD-algebra of unconstrained, differentiable minimization problems to the UWD-algebra of discrete dynamical systems (Example <ref>).

§.§ Composing Optimization Problems

To show that gradient descent is an algebra morphism, we must first specify our UWD-algebra of optimization problems. In this algebra, subproblems will compose by summing their objective functions subject to the pattern of decision variable sharing dictated by a UWD.

There is a finset algebra $(\Opt,\varphi)\maps (\FinSet,+)\to (\Set,\times)$ defined as follows.

* On objects, $\Opt$ takes a finite set $N$ to the set of functions $\{f\maps\R^N\to \R \mid f\in C^1\}$.

* On morphisms, $\Opt$ takes a function $\phi\maps N\to M$ to the function $\Opt(\phi)\maps \Opt(N)\to\Opt(M)$ defined by

\begin{equation}
\Opt(\phi)\maps f\mapsto f\circ\phi^*.
\end{equation}

* Given objects $N,M\in\FinSet$, the product comparison $\varphi_{N,M}\maps \Opt(N)\times \Opt(M)\to \Opt(N+M)$ is given by pointwise addition in $\R$, i.e.,

\begin{equation}
\varphi_{N,M}(f,g)(z)\coloneqq f(\iota_N^*(z)) + g(\iota_M^*(z))
\end{equation}

for all $z\in \R^{N+M}$. Here, $\iota_N\maps N\to N+M$ and $\iota_M\maps M\to N+M$ are the inclusions of $N$ and $M$ into their disjoint union.

* The unit comparison $\varphi_0\maps \1\to \Opt(\emptyset)$ picks out the zero function $0 \mapsto 0$.

We construct the covariant functor $\Opt$ as the composite

\[
\Opt \coloneqq \FinSet\xrightarrow{(-)^*}\Vect^\text{op}\xrightarrow{O}\Set
\]

of two contravariant functors, where $(-)^*$ is the distribute algebra from Example <ref>.
The contravariant functor $O$ takes a vector space $V$ to the set of $C^1$ functions $V\to \R$. Similarly to $(-)^*$, the functor $O$ acts on linear maps $T\maps V\to W$ by precomposition: $O(T)(f) \coloneqq f\circ T$. This is plainly functorial, and thus $\Opt \coloneqq O \circ (-)^*$ is functorial. It is also clear that precomposition of a $C^1$ function with a linear map is again $C^1$.

We now need to verify that the product comparison is natural, i.e., that the following diagram commutes:

\[\begin{tikzcd}
{\Opt(X)\times\Opt(Y)} &&& {\Opt(N)\times\Opt(M)} \\
\\
{\Opt(X+Y)} &&& {\Opt(N+M)}
\arrow["{\Opt(\phi)\times\Opt(\psi)}", from=1-1, to=1-4]
\arrow["{\varphi_{X,Y}}"', from=1-1, to=3-1]
\arrow["{\varphi_{N,M}}", from=1-4, to=3-4]
\arrow["{\Opt(\phi+\psi)}"', from=3-1, to=3-4]
\end{tikzcd}\]

for all finite sets $X,Y,N,M$ and functions $\phi\maps X\to N$ and $\psi\maps Y\to M$. To do so, let $(f,g)\in\Opt(X)\times\Opt(Y)$. Following the top path yields the function $h_1\coloneqq f\circ\phi^*\circ \iota_N^* + g\circ\psi^*\circ\iota_M^*$ while following the bottom path yields the function $h_2\coloneqq (f\circ\iota_X^* + g\circ\iota_Y^*)\circ (\phi+\psi)^*$. To show that these are equivalent, first note that since $(-)^*$ is a strong monoidal functor, the map $(\phi+\psi)^*$ is isomorphic to the map $\phi^*\oplus\psi^*$. Similarly, since $(-)^*$ takes coproducts in $\FinSet$ to products in $\Vect$, we know that $\iota_X^*\maps \R^{X+Y}\to \R^X$ is equivalent to the projection $\pi_{\R^X}\maps\R^X\oplus\R^Y\to\R^X$, and similarly for all the above $\iota^*$'s. Thus we can rewrite $h_1$ as $f\circ\phi^*\circ \pi_{\R^N} + g\circ\psi^*\circ\pi_{\R^M}$ and $h_2$ as $(f\circ \pi_{\R^X} + g\circ \pi_{\R^Y})\circ (\phi^*\oplus \psi^*)$.

Finally, noting that the following pair of diagrams commutes

\begin{equation}\label{eq:oplus_comm}\begin{tikzcd}
{\R^N\oplus\R^M} && {\R^X\oplus \R^Y} && {\R^N\oplus\R^M} && {\R^X\oplus\R^Y} \\
{\R^N} && {\R^X} && {\R^M} && {\R^Y}
\arrow["{\phi^*\oplus \psi^*}", from=1-1, to=1-3]
\arrow["{\pi_{\R^X}}", from=1-3, to=2-3]
\arrow["{\pi_{\R^N}}"', from=1-1, to=2-1]
\arrow["{\phi^*}"', from=2-1, to=2-3]
\arrow["{\phi^*\oplus\psi^*}", from=1-5, to=1-7]
\arrow["{\psi^*}"', from=2-5, to=2-7]
\arrow["{\pi_{\R^M}}"', from=1-5, to=2-5]
\arrow["{\pi_{\R^Y}}", from=1-7, to=2-7]
\end{tikzcd}\end{equation}

shows that $h_1$ is equivalent to $h_2$.

The associativity and symmetry of the product comparison follow from the associativity and symmetry of pointwise addition of functions, while the unitality follows from the unitality of the zero function with respect to pointwise addition.

Recall the UWD in Figure <ref>.A, which we call $\Phi$. Note that the junctions of $\Phi$ are in one-to-one correspondence with outer ports, so we will use the simplification of Remark <ref>. Applying $\Opt$ to this UWD gives a function $\Opt(\Phi)\maps \Opt([2])\times \Opt([3])\times\Opt([3])\to\Opt([5])$ specifying how to compose three subproblem objectives of appropriate dimensions to yield a composite objective on $\R^5$.

Given $C^1$ subproblems $f\maps \R^2\to \R,g\maps \R^3\to\R$, and $h\maps \R^3\to \R$, the result $\Opt(\Phi)(f,g,h)$ is the composite problem

\begin{equation}\label{eq:simple_ex}
\textnormal{minimize } f(w,x) + g(u,w,y) + h(u,w,z),
\end{equation}

corresponding to the $\Opt$-UWD in Figure <ref>.B. To see why, first note that the distribute algebra copies components of the decision variable to their respective subproblems dictated by the mapping of inner ports to junctions. Then, the product comparison of $\Opt$ simply sums the results of applying each objective to the components of the decision variable they received.

§.§ Solving Composite Problems with Gradient Descent

We can now prove that gradient descent defines an algebra morphism from $\Opt$ to $\Dynam_D$. Our approach is to first show that gradient flow gives a morphism to continuous systems and then recover gradient descent as a corollary by composing with the Euler's method algebra morphism.

Recalling the symmetric monoidal functor $\Dynam$ from Example <ref>, there is a monoidal natural transformation $\flow\maps \Opt\Rightarrow \Dynam$ with components

\begin{equation*}
\flow_N\maps \Opt(N)\to \Dynam(N)
\end{equation*}

defined by

\begin{equation}
\flow_N(f)\coloneqq x\mapsto -\nabla f(x).
\end{equation}

We first need to verify naturality. For this, we need to ensure that

\[\begin{tikzcd}
{\Opt(N)} && {\Opt(M)} \\
\\
{\Dynam(N)} && {\Dynam(M)}
\arrow["{\Opt(\phi)}", from=1-1, to=1-3]
\arrow["{\flow_N}"', from=1-1, to=3-1]
\arrow["{\flow_M}", from=1-3, to=3-3]
\arrow["{\Dynam(\phi)}"', from=3-1, to=3-3]
\end{tikzcd}\]

commutes for any choice of $N,M\in \FinSet$ and $\phi\maps N\to M$. Fix any optimization problem $f\in \Opt(N)$. The top path of the naturality square yields the vector field

\begin{equation}\label{eq:top_path}
(y \in \R^M) \mapsto -\nabla (f(\phi^*(y))) = -\nabla(f(Ky)),
\end{equation}

where we use $K$ to denote the matrix representation of $\phi^*$ with respect to the standard basis. Then, by applying the chain rule, we have that (<ref>) is equal to

\begin{equation}
y\mapsto -K^T\nabla f(Ky).
\end{equation}

Likewise, following the bottom path yields

\begin{equation}\label{eq:botpath}
y\mapsto \phi_*(-\nabla f(\phi^*(y))) = -\phi_*(\nabla f(\phi^*(y))).
\end{equation}

Noting that the pushforward is dual to the pullback shows that (<ref>) is equivalent to (<ref>), as desired.

To verify that the natural transformation is monoidal, we need to show that the diagrams

\[\begin{tikzcd}
{\Opt(N)\times\Opt(M)} &&& {\Dynam(N)\times\Dynam(M)} \\
\\
{\Opt(N+M)} &&& {\Dynam(N+M)}
\arrow["{\flow_N\times \flow_M}", from=1-1, to=1-4]
\arrow["{\flow_{N+M}}"', from=3-1, to=3-4]
\arrow["{\varphi^{\Opt}_{N,M}}"', from=1-1, to=3-1]
\arrow["{\varphi^{\Dynam}_{N,M}}", from=1-4, to=3-4]
\end{tikzcd}\]

\[\begin{tikzcd}
\1 && {\text{Opt}(\emptyset)} \\
&& {\text{Dynam}(\emptyset)}
\arrow["{\varphi_0^\Opt}", from=1-1, to=1-3]
\arrow["{\varphi_0^\Dynam}"', from=1-1, to=2-3]
\arrow["{\flow(\emptyset)}", from=1-3, to=2-3]
\end{tikzcd}\]

commute for all $N,M\in\FinSet$. The unit comparison diagram commutes trivially (noting that the constant zero function $\R^0\to \R$ is the same as the unique vector field $\R^0\to\R^0$). For the product comparison diagram, let $f\in \Opt(N)$ and $g\in \Opt(M)$ be optimization problems. Following the top path yields the vector field

\begin{equation}
z\mapsto \iota_{N*}(-\nabla f(\iota_N^*(z))) + \iota_{M*}(-\nabla g(\iota_M^*(z))),
\end{equation}

while following the bottom path yields

\begin{equation}
z\mapsto -\nabla(f(\iota_N^*(z))) -\nabla(g(\iota_M^*(z))).
\end{equation}

These vector fields are seen to be equivalent by the same reasoning used to verify naturality.

Given a positive real number $\gamma$, there is a monoidal natural transformation $\gd^\gamma\maps \Opt\Rightarrow \Dynam_D$ with components $\gd^\gamma_N\maps \Opt(N)\to\Dynam_D(N)$ given by the function

\begin{equation}
f\mapsto \id_{\R^N} - \gamma\nabla f.
\end{equation}

The claimed monoidal transformation is the composite of monoidal transformations

\[
\Opt \xRightarrow{\flow} \Dynam \xRightarrow{\Euler^\gamma} \Dynam_D,
\]

where the Euler transformation was described at the end of Section <ref>.

In words, the transformation $\gd^\gamma$ takes a differentiable minimization problem to the dynamical system which implements gradient descent on it. Naturality of gradient descent means that composing the gradient descent dynamical systems of subproblems is equivalent to composing subproblems and then taking the gradient descent dynamical system of the composite problem. This equivalence is what enables composite problems to be solved using the distributed message passing semantics of composite dynamical systems, illustrated by the following example.

[Distributed Gradient Descent]
Recall Problem (<ref>):

\begin{equation*}
\textnormal{minimize } f(w,x) + g(u,w,y) + h(u,w,z).
\end{equation*}

Here, we assume that $f\maps\R^2\to\R, g\maps\R^3\to\R$, and $h\maps\R^3\to\R$ are all $C^1$ functions. We showed in Example <ref> that this problem is the composite produced by filling the UWD $\Phi$ in Figure <ref>.A with the component functions $f,g,$ and $h$. This composite has the form

\begin{equation}
P(u,w,x,y,z) \coloneqq \boldsymbol{1}^T\begin{bmatrix}
f(w,x) \\ g(u,w,y) \\ h(u,w,z)
\end{bmatrix}.
\end{equation}

In other words, the composite problem takes an input vector, distributes it to the subproblems, and sums the results. If we apply $\gd^\gamma$ to the composite problem $P$ and let $s\coloneqq (u,w,x,y,z)^T$, we get the discrete system

\begin{equation}\label{eq:comp_system}
s_{k+1} = s_k -\gamma\nabla P(s_k),
\end{equation}

for a chosen step-size $\gamma>0$.
This is a centralized gradient descent algorithm for minimizing $P$. However, by Theorem <ref> and the fact that $P$ is decomposed by the UWD $\Phi$, we know that this system is equivalent to applying $\gd^\gamma$ to each individual subproblem and composing these discrete dynamical systems according to $\Phi$, i.e.,

\begin{equation}\label{eq:dynam_d_comp}
\Dynam_D(\Phi)\Bigl((\id_{\R^2}-\gamma\nabla f), (\id_{\R^3}-\gamma\nabla g), (\id_{\R^3}-\gamma\nabla h)\Bigr).
\end{equation}

Simplifying (<ref>) results in the equivalent dynamical system

\begin{equation}\label{eq:distributed-system}
s_{k+1} = s_k-\gamma K^T\begin{bmatrix}
\nabla f \\ \nabla g \\ \nabla h
\end{bmatrix}Ks,
\end{equation}

where $K$ is the pullback of the function mapping inner ports to junctions of $\Phi$.

Note that naturality of $\gd^\gamma$ says that (<ref>) and (<ref>) are extensionally equal, meaning they produce the same output given the same input. This also implies that the trajectories of these systems from a given initial condition will be the same. However, these systems have very different computational properties.
Specifically, unlike the system in (<ref>), the system in (<ref>) can be run using the distributed message passing semantics discussed in Remark <ref>. Explicitly, the system (<ref>) yields Algorithm <ref>, which is a simple distributed gradient method for minimizing (<ref>).
Comment/*  */

Message Passing Gradient Descent
An initial state vector $s_0\in\R^5$.
$s\gets s_0$
a stopping criterion is not reached
$t \gets K*s$ *[r]Duplicate shared states
$t_1,t_2,t_3\gets \pi_1(t),\pi_2(t),\pi_3(t)$ *[r]Project subvectors to subsystems
$t_1, t_2, t_3\gets \nabla f(t_1),\nabla g(t_2),\nabla h(t_3)$ *[r]This can be done in parallel
$t\gets \texttt{concatenate}(t_1,t_2, t_3)$
$\Delta s\gets \gamma*K^T*t$ *[r]Sum changes in shared states
$s\gets s - \Delta s$ *[r]Update state

The process described in Example <ref> of taking a UWD and component subproblems and generating a distributed solution algorithm for solving them can be automated by the meta-algorithm shown in Algorithm <ref>.

Minimization Algorithm Generator
A UWD $\Phi$ with $n$ inner boxes
Open $C^1$ objectives $f_1,\dots,f_n$ to fill each inner box of $\Phi$.
A positive real step-size $\gamma$.
A message passing dynamical system for minimizing $\Opt(\Phi)(f_1,\dots,f_n)$.

$i\gets1$ $n$
$v_i\gets \gd^\gamma(f_i)$

[Recovering Primal Decomposition]

The $\Opt$-UWD setting up primal decomposition of Problem (<ref>).

Example <ref> shows that applying the natural transformation $\gd^\gamma\maps \Opt\Rightarrow\Dynam$ gives a simple distributed gradient method that decomposes $C^1$ problems defined on arbitrary UWDs.
However, this simple distributed gradient method still requires synchronization after each gradient step.

Supposing that $f,g,$ and $h$ are $C^1$, strictly convex functions, an alternative distributed solution method for (<ref>) can be obtained by applying primal decomposition. At each iteration, primal decomposition fixes the values of shared variables to decouple the problem, finds minimizers of the subproblems in parallel, and uses these minimizers to compute gradient updates for the shared variables. We can implement primal decomposition in this framework by applying the same gradient descent natural transformation to a slightly modified UWD and component problems that fill it. Specifically, we apply gradient flow to the $\Opt$-UWD shown in Figure <ref>.

Because $f,g,$ and $h$ are strictly convex, their infima are attained at unique points for any values of $w$ and $u$. Thus, the gradient of $\inf_x f(w,x)$ can be computed as $\nabla_w f(w,x^*)$ where $x^*=\argmin_x f(w,x)$. A similar computation produces gradients of the other subproblems with respect to $w$ and $u$. Applying $\gd^\gamma$ to each subproblem and composing these systems results in the composite system

\begin{equation}
\begin{bmatrix}u_{k+1}\\w_{k+1}\end{bmatrix}=\begin{bmatrix}
\end{bmatrix}-\gamma Q^T\begin{bmatrix}
\nabla f(w_k,x^*) \\ \nabla g(u_k,w_k,y^*) \\ \nabla h(u_k,w_k,z^*)
\end{bmatrix},
\end{equation}

where $x^*=\argmin_x f(w_k,x), y^*=\argmin_y g(u_k,w_k,y), z^*=\argmin_z h(u_k,w_k,z)$, and $Q^T$ is the matrix obtained by applying the collect algebra to the UWD in Figure <ref>. This system yields Algorithm <ref>.

Comment/*  */

Message Passing Primal Decomposition
An initial state vector $s_0\in\R^2$.
$s\gets s_0$
a stopping criterion is not reached
$t \gets Q*s$ *[r]Duplicate shared states
$t_1,t_2,t_3\gets \pi_1(t),\pi_2(t),\pi_3(t)$ *[r]Project subvectors to subsystems
Compute the following argmins in parallel using an appropriate algorithm
$x^*\gets \argmin_x f(t_1,x)$
$y^*\gets \argmin_y g(t_2,y)$
$z^*\gets \argmin_z h(t_3,z)$
$t_1, t_2, t_3\gets \nabla f(t_1,x^*),\nabla g(t_2,y^*),\nabla h(t_3,z^*)$ *[r]This can be done in parallel
$t\gets \texttt{concatenate}(t_1,t_2, t_3)$
$\Delta s\gets \gamma*Q^T*t$ *[r]Sum changes in shared states
$s\gets s - \Delta s$ *[r]Update state

This is primal decomposition applied to Problem (<ref>). Naturality of gradient flow automatically proves that running this algorithm will produce the same result as running the equivalent synchronous dynamical system obtained by applying $\gd^\gamma$ to the original composite problem. Note that although Algorithm <ref> and Algorithm <ref> are different, they both the result from applying meta-Algorithm <ref> to different UWDs and component objectives.

§.§ The Compositional Data Condition

Often, an instance of a specific optimization problem is determined by some data. Examples include how a neural network architecture is incorporated into a machine learning objective or how a specific graph defines a network flow objective. In general, we can view such encodings of problem data into objective functions as families of functions $p_N\maps D(N)\to \Opt(t(N))$ indexed by finite sets $N$. We think of $D(N)$ as the set of all possible problem data defined on $N$ (e.g., the set of graphs with vertex set $N$, the set of neural networks with $|N|$ weights, etc.). The function $t$ is then a transformation of $N$ into a set of decision variables for a corresponding objective. Sometimes, the problem data itself can be composed. For example, graphs can be glued together along their vertices, and neural networks can share weights across different components (weight tying).  We refer to data of these kinds as compositional data. Our compositional data condition essentially says that if the compositional structure of a problem's data is compatible with the compositional structure of objectives in $\Opt$, then the problem can be solved via a decomposition method. Formally, this is stated as follows.

Let $t\maps (\FinSet,+)\to (\FinSet,+)$ and $D\maps (\FinSet,+)\to (\Set,\times)$ be  lax symmetric monoidal functors. Given a family of functions $p_N\maps D(N)\to \Opt(t(N))$ for $N\in \FinSet$, we say that $p$ satisfies the compositional data condition if the maps $p_N$ form the components of a monoidal natural transformation $p\maps D\Rightarrow \Opt\circ t$.

The compositional data condition is a sufficient condition for when a problem defined by compositional data is decomposable. Specifically, when the condition is satisfied, we obtain a monoidal natural transformation from an algebra $D$ of data to the algebra of dynamical systems by post-composition, i.e.,

\[D\xRightarrow{p} \Opt\circ t\xRightarrow{\gd^\gamma * t} \Dynam_D \circ t.\]

This provides a transformation from problem data into systems for minimizing the objectives defined by this data. The benefit of this framing is that the systems produced by this composite will respect any hierarchical decomposition of the input data encodable as an undirected wiring diagram. As an example, we will see how the minimum cost network flow problem satisfies the compositional data condition in Section <ref>.

§ UZAWA'S ALGORITHM IS AN ALGEBRA MORPHISM

So far, we have shown that gradient descent is natural with respect to composition for unconstrained minimization problems. To extend this framework to equality constrained problems, we show that Uzawa's algorithm [21] is natural for equality constrained minimization problems. This result will also allow us to extend the compositional data condition to a broader class of problems. Doing so first requires a notion of composition for constrained problems. Recall that Uzawa's algorithm uses saddle functions as representations of constrained problems. Therefore, we specify how to compose constrained problems by specifying how to compose their corresponding saddle functions.

§.§ Composing Saddle Problems

Saddle functions should compose like unconstrained objective functions do under $\Opt$, namely by summing objectives subject to a pattern of variable sharing dictated by a UWD. The crucial difference with saddle problems is that we need to guarantee that the composite of saddle problems is again a saddle problem. One way to achieve this is to enforce that the pattern of variable sharing must respect the saddle properties of the subproblems being composed. Specifically, we only want to allow saddle problems to share a given variable if they are either both convex in that variable or both concave in it.

If one is convex in that variable and the other is concave, then they should not be allowed to share that variable.

Therefore, we need a way to track whether a given saddle function depends in a convex or concave way upon each of its inputs. For this, we make use of a categorical construction known as the slice category, which can be thought of as imposing a “type system" on a category.

Given a category $\CC$ and an object $c\in\CC$, the slice category $\CC/c$ is defined as follows.

* The objects of $\CC/c$ are morphisms $f\maps x\to c$ in $\CC$ with codomain $c$.

* A morphism from $f\maps x\to c$ to $g\maps y\to c$ in $\CC/c$ is a morphism $h\maps x\to y$ in $\CC$ such that the triangle

\[\begin{tikzcd}
x && y \\
& c
\arrow["f"', from=1-1, to=2-2]
\arrow["g", from=1-3, to=2-2]
\arrow["h", from=1-1, to=1-3]
\end{tikzcd}\]

commutes, i.e., $f=g\circ h$.

A slice category $\CC/c$ has an associated forgetful functor $U\maps \CC/c\to\CC$ defined by taking objects $x\xrightarrow{f}c$ in $\CC/c$ to their domains $x\in\CC$, and by taking commuting triangles to the morphisms which made them commute.

The distinction between convex and concave is binary,
so the slice category we use to encode the distinction is $\FinSet/[2]$. We can think of this category as essentially the same as $\FinSet$, but with each element of a set being “labelled" with either a 1 or a 2, representing convex-labelled and concave-labelled components respectively. We note that linear functions are both convex and concave and in principle they
can be labeled with either. However, in the engineering literature, one conventionally regards a linear function as convex
when it is being minimized and concave when it is being maximized, and we adopt this convention here as well.

To produce an algebra of saddle functions, we will require that an objective function defined on such a labelled set be convex in the convex-labelled components and concave in the concave-labelled components.

The morphisms in $\FinSet/[2]$ can then be thought of as label-preserving functions, i.e., functions which map convex-labelled elements of their domain set to convex-labelled elements of their codomain set and likewise for concave-labelled elements. Note that colimits in a slice category are constructed as colimits in the original category ([30], Proposition 3.3.8). In particular, the coproduct of two objects $N\xrightarrow{\tau} [2]$ and $M\xrightarrow{\sigma} [2]$ in $\FinSet/[2]$ is the coproduct $N+M$ in $\FinSet$ labelled by the copairing $[\tau,\sigma]$. Therefore, $(\FinSet/[2],+,\emptyset\xrightarrow{!}[2])$ inherits a co-Cartesian monoidal structure from that of $(\FinSet, +, \emptyset)$.

Given an object $\tau\maps N\to [2]$ in $\FinSet/[2]$, the sets $N_1\coloneqq \tau^{-1}(1)$ and $N_2\coloneqq \tau^{-1}(2)$ form a partition of $N$.

We also have two unique injections $N_1\xhookrightarrow{\textnormal{cnvx}} N$ defined by $(\tau\circ \textnormal{cnvx})(n_1) = 1$ for all $n_1\in N_1$ and $N_2\xhookrightarrow{\textnormal{cncv}} N$ defined by $(\tau\circ \textnormal{cncv})(n_2) = 2$ for all $n_2\in N_2$. In other words, `cnvx' picks out the convex-labelled components of $N$ and `cncv' picks out the concave-labelled components.

Furthermore, utilizing the functor $(-)_*$ to generate $\R^{N_1}$ and $\R^{N_2}$ and taking the pushforward of `cnvx' and `cncv', we define the isomorphism $u\maps \R^{N_1}\oplus\R^{N_2}\cong \R^N$ as the unique arrow in the following coproduct diagram:

\[\begin{tikzcd}
& {\R^N} \\
\\
{\R^{N_1}} & {\R^{N_1}\oplus\R^{N_2}} & {\R^{N_2}}
\arrow["u"', dashed, hook, two heads, from=3-2, to=1-2]
\arrow["{\iota_{\R^{N_1}}}"', from=3-1, to=3-2]
\arrow["{\iota_{\R^{N_2}}}", from=3-3, to=3-2]
\arrow["{\textnormal{cnvx}_*}", from=3-1, to=1-2]
\arrow["{\textnormal{cncv}_*}"', from=3-3, to=1-2]
\end{tikzcd}\]

This isomorphism simply takes a pair $(x,y)\in\R^{N_1}\oplus\R^{N_2}$ and arranges them into a single vector $z\in\R^N$ whose ordering of convex and concave components is given by $\tau$.

There is a finset algebra $\Saddle\maps (\FinSet/[2],+)\to(\Set,\times)$ defined as follows.

* Given an object $\tau\maps N\to [2]$ in $\FinSet/[2]$, let $N_1,N_2$ and $u\maps \R^{N_1}\oplus\R^{N_2}\cong \R^N$ be defined as in Remark <ref>. Then $\Saddle$ takes $\tau$ to the set

\begin{multline}
\Big\{f\maps \R^N\to \R \mid f(u(\cdot,y)) \text{ is convex for any fixed } y\in\R^{N_2}\text{ } \textnormal{ and } \\ f(u(x,\cdot)) \text{ is concave for any fixed } x\in \R^{N_1}\Big\}.
\end{multline}

* On morphisms, $\Saddle$ takes a commuting triangle

\[\begin{tikzcd}[ampersand replacement=\&]
N \&\& M \\
\& {[2]}
\arrow["\phi", from=1-1, to=1-3]
\arrow[""{name=0, anchor=center, inner sep=0}, "{\tau_1}"', from=1-1, to=2-2]
\arrow[""{name=1, anchor=center, inner sep=0}, "{\tau_2}", from=1-3, to=2-2]
%\arrow[shift left=2, shorten <=13pt, shorten >=13pt, Rightarrow, no head, from=0, to=1]
\end{tikzcd}\]

to the function $\Saddle(\tau_1)\to\Saddle(\tau_2)$ defined by precomposition: $f\mapsto f\circ \phi^*$.

* Given objects $\tau_1\maps N\to [2]$ and $\tau_2\maps M\to [2]$ in $\FinSet/[2]$, the product comparison $\varphi_{\tau_1,\tau_2}\maps\Saddle(\tau_1)\times\Saddle(\tau_2)\to\Saddle(\tau_1+\tau_2)$ is defined by

\begin{equation}
\varphi_{\tau_1,\tau_2}(f,g)(z)\coloneqq f(\iota_N^*(z)) + g(\iota_M^*(z)),
\end{equation}

for all $z\in \R^{N+M}$.

* The unit comparison $\varphi_0\maps \1\to \Saddle(\emptyset\xrightarrow{!}[2])$ is given by the constant 0 function.

First, we must prove that given a saddle function $f\in\Saddle(N\xrightarrow{\tau} [2])$ and a map $\phi\maps (N\xrightarrow{\tau}[2])\to (M\xrightarrow{\sigma}[2])$, the composition $f\circ\phi^*$ is again a saddle function whose convex and concave components respect $\sigma$. The precomposition of a saddle function with a linear map is again a saddle function ([39], 2.1) so $f\circ \phi^*$ is a saddle function because $f$ is a saddle function and $\phi^*$ is linear.
Furthermore, since $\phi$ makes the diagram

\[\begin{tikzcd}[ampersand replacement=\&]
N \&\& M \\
\& {[2]}
\arrow["\phi", from=1-1, to=1-3]
\arrow[""{name=0, anchor=center, inner sep=0}, "{\tau}"', from=1-1, to=2-2]
\arrow[""{name=1, anchor=center, inner sep=0}, "{\sigma}", from=1-3, to=2-2]
%\arrow[shift left=2, shorten <=13pt, shorten >=13pt, Rightarrow, no head, from=0, to=1]
\end{tikzcd}\]

commute, $\phi^*$ must map convex labelled components of $x\in\R^M$ to convex labelled componenets in $\R^N$ and likewise for concave labelled components. Thus $f\circ \phi^*$ has convex and concave components that respect $\sigma$. With this verified, the proof of functoriality of $\Saddle$ is the same as the proof of functoriality of $\Opt$ because $\Saddle(\phi) = \Opt(\phi)$.

Similarly, because the comparison maps of $\Saddle$ act the same as those of $\Opt$, the proofs of the necessary unitality, symmetry, and associativity diagrams carry over. We then just need to verify that the results of applying the comparison maps are again saddle functions with the correct labelling of convex and concave components. For the unit comparison, the constant 0 function is affine and thus trivially a saddle function. Furthermore, it has no arguments and thus no labelling to respect.

For the product comparison, consider arbitrary objects $N\xrightarrow{\tau_1} [2], M\xrightarrow{\tau_2} [2]$ in $\FinSet/[2]$ and arbitrary saddle functions $f\in\Saddle(\tau_1)$ and $g\in \Saddle(\tau_2)$. Let $N_1, N_2, M_1, M_2, u_N\maps \R^{N_1}\oplus \R^{N_2}\cong \R^N$, and $u_M\maps\R^{M_1}\oplus\R^{M_2}\cong\R^M$ be defined as in Remark <ref>. Then we know that

\begin{equation}
f(u_N(\cdot, y)) + g(u_M(\cdot, z))
\end{equation}

is convex for all $(y,z)\in\R^{N_2}\oplus \R^{M_2}$ because the sum of convex functions is convex. Likewise, we have that

\begin{equation}
f(u_N(x,\cdot)) + g(u_M(w,\cdot))
\end{equation}

is concave for all $(x,w)\in \R^{N_1}\oplus \R^{M_1}$ because the sum of concave functions is concave. This establishes the desired saddle property for the result of applying the product comparison maps.

[Lagrangians and Augmented Lagrangians]
The $\Saddle$ cospan algebra now allows us to give a compositional perspective on Lagrangians and augmented Lagrangians.
[inline]Just show this in a figure.

§.§ Additional Classes of Optimization Problems

The functor $\Opt$ gives a way to compose unconstrained $C^1$ non-convex minimization problems while $\Saddle$ gives a way to compose saddle problems which are not necessarily differentiable. By adding additional restrictions on the sets of functions in the image of these functors or restricting their domains, we can easily produce new functors for composing other types of problems. In this paper specifically, we will make use of the following restrictions:

* $\DiffSaddle$ restricts functions in the image of $\Saddle$ to be continuously differentiable, i.e.,
\[\DiffSaddle(N)\coloneqq \{L\in\Saddle(N)\mid L\in C^1\}.\]

* We get a subcategory of $\FinSet/[2]$ isomorphic to $\FinSet$ by only looking at objects of the form $\tau\maps N\to [2]$ for which $\tau(n)=1$ for all $n\in N$. Restricting $\Saddle$ to this subcategory gives us a finset algebra $\Conv\maps\FinSet\to\Set$ defining composition of convex optimization problems. Similarly, restricting $\Saddle$ to the subcategory for which $\tau(n)=2$ for all $n\in N$ gives us a finset algebra $\Conc\maps\FinSet\to\Set$ defining composition of concave optimization problems.

* Finally, we can perform the same restrictions as above to $\DiffSaddle$ to yield finset algebras

\[\DiffConv\maps \FinSet\to\Set \text{ and } \DiffConc\maps\FinSet\to\Set\]
for composing continuously differentiable convex and concave problems, respectively.

Figure <ref> in the Introduction shows a graphical view of the relationship between these various restrictions.

§.§ Solving Composite Saddle Problems with Uzawa's Algorithm

We can now show that Uzawa's algorithm, i.e., gradient descent on convex components and gradient ascent on concave components, respects the compositional structure of saddle problems. This will allow us to derive distributed versions of both Uzawa's algorithm
and dual decomposition.

Let $U\maps \FinSet/[2]\to\FinSet$ be the forgetful functor from the slice category. Then there is a monoidal natural transformation $\flow\maps\DiffSaddle\Rightarrow\Dynam\circ U$ with components

\begin{equation}
\flow_{N\xrightarrow{\tau}[2]}\maps \DiffSaddle(\tau)\to \Dynam(N)
\end{equation}

defined component-wise by

\begin{equation}
\flow_\tau(f)(x)_i\coloneqq \begin{cases}
-\nabla f(x)_i & \tau(i) = 1 \\
\nabla f(x)_i & \tau(i) = 2
\end{cases}
\end{equation}

for all $x\in\R^N$ and $i\in N$.

To verify naturality, we need to show that the diagram

\begin{equation}\label{eq:comm_tri}\begin{tikzcd}
{\DiffSaddle(\tau)} && {\DiffSaddle(\sigma)} \\
{\Dynam(N)} && {\Dynam(M)}
\arrow["{\DiffSaddle(\phi)}", from=1-1, to=1-3]
\arrow["{\Dynam(\phi)}"', from=2-1, to=2-3]
\arrow["{\flow_\tau}"', from=1-1, to=2-1]
\arrow["{\flow_\sigma}", from=1-3, to=2-3]
\end{tikzcd}\end{equation}

commutes for all $N\xrightarrow{\tau}[2]$, $M\xrightarrow{\sigma}[2]$, and commuting triangles

\[\begin{tikzcd}[ampersand replacement=\&]
N \&\& {M.} \\
\& {[2]}
\arrow["\phi", from=1-1, to=1-3]
\arrow[""{name=0, anchor=center, inner sep=0}, "{\tau}"', from=1-1, to=2-2]
\arrow[""{name=1, anchor=center, inner sep=0}, "{\sigma}", from=1-3, to=2-2]
%\arrow[shift left=2, shorten <=13pt, shorten >=13pt, Rightarrow, no head, from=0, to=1]
\end{tikzcd}\]

Conceptually, this proof will be similar to the proof of naturality in Theorem <ref>, with the crucial difference being that we also need to verify that $\Dynam(\phi)\circ\flow_\tau$ performs gradient descent on the same components as $\flow_\sigma\circ\DiffSaddle(\phi)$ and likewise for gradient ascent.

To begin, let $f\in\DiffSaddle(\tau)$ be arbitrary. Following the bottom path yields the following dynamical system defined component-wise:

\begin{equation}\label{eq:saddle_top}
\Dynam(\phi)(\flow_\tau(f))(y)_j = \sum_{i\in\phi^{-1}(j)}\begin{cases}
-[\nabla f(\phi^*(y))]_i & \tau(i)=1 \\
[\nabla f(\phi^*(y))]_i & \tau(i)=2,
\end{cases}
\end{equation}

for all $y\in\R^M$ and $j\in M$. The summation in (<ref>) comes from the component-wise definition of the pushforward. Likewise, following the bottom path yields the system

\begin{equation}\label{eq:saddle_bot}
\flow_\sigma(f\circ\phi^*)(y)_j = \begin{cases}
-\nabla[f(\phi^*(y))]_j & \sigma(j) = 1 \\
\nabla[f(\phi^*(y))]_j & \sigma(j) =2,
\end{cases}
\end{equation}

for all $y\in\R^M$ and $j\in M$. By applying the chain rule and noting that the pushforward is dual to the pullback (same reasoning as in Theorem <ref>, we have that (<ref>) equals

\begin{equation}
\sum_{i\in\phi^{-1}(j)}\begin{cases}
-[\nabla f(\phi^*(y))]_i & \sigma(\phi(i))=1 \\
[\nabla f(\phi^*(y))]_i & \sigma(\phi(i))=2.
\end{cases}
\end{equation}

Crucially, because (<ref>) is a commuting triangle, we have that $\tau(i) = \sigma(\phi(i))$ for all $i\in N$. This shows that (<ref>) equals (<ref>) as desired.

To prove that $\flow$ is monoidal, it again suffices to combine the above reasoning with that of Theorem <ref>.

Gradient ascent-descent gives a monoidal natural transformation $\gad^\gamma\maps \DiffSaddle\Rightarrow \Dynam_D\circ U$ with components

\begin{equation}
\gad^\gamma_{N\xrightarrow{\tau}[2]}\maps \DiffSaddle(\tau)\to\Dynam_D(N)
\end{equation}

defined by

\begin{equation}
\gad^\gamma_\tau(f)(x)_i\coloneqq \begin{cases}
x_i-\gamma\nabla f(x)_i & \tau(i) = 1 \\
x_i+\gamma\nabla f(x)_i & \tau(i) = 2
\end{cases}
\end{equation}

for all $x\in\R^N$ and $i\in N$.

This follows by composing $\flow\maps \DiffSaddle\Rightarrow\Dynam\circ U$ with $\Euler^\gamma$.

Unpacking the definition of this natural transformation, it is simply implementing gradient descent on the convex components of the objective and gradient ascent on the concave components. With this proven, we can extend the compositional data condition to the case when the objectives defined by data are in $\DiffSaddle$, i.e., when $D, p,$ and $t$ are chosen such that

\[D\xRightarrow{p}\DiffSaddle\circ t\xRightarrow{\gad^\gamma * t}\Dynam_D\circ U \circ t\]

is a monoidal natural transformation.

[Distributed Uzawa's Algorithm and Dual Decomposition]
Similar to how applying $\gd^\gamma$ to $\Opt$-UWDs gave us distributed gradient and primal decomposition algorithms in Examples <ref> and <ref> respectively, we can apply $\gad^\gamma$ to $\DiffSaddle$-UWDs to obtain distributed primal-dual and dual decomposition algorithms.

A. A $\DiffSaddle$-UWD encoding the structure of a separable sum of objective functions subject to a complicating equality constraint. B. A $\DiffSaddle$-UWD setting up dual decomposition of the problem encoded in (A). Since these are $\DiffSaddle$-UWDs, we denote the convex-labelled variables with black junctions and the concave labelled variables with white junctions.

A common scenario, which will be revisited in our network flow example in Section <ref>,
is having a separable sum of objective functions subject to some complicating equality constraint. Following the discussion in Section 2.2 of [1], a general example is the problem

\begin{equation}\label{eq:cons-prob}
\begin{array}{ll@{}ll}
\textnormal{minimize } & \sum_{i=1}^N f_i(x_i) \\
\textnormal{subject to } & Ax=b,
\end{array}
\end{equation}

where the decision variable $x\in\R^n$ is partitioned into subvectors $x = [x_1,\dots,x_N]^T$ where $x_i\in\R^{n_i}$ and $\sum_i n_i=n$. Here, $A\in \R^{m\times n}, b\in\R^m$, and we assume that all the $f_i\maps\R^{n_i}\to \R$ are strictly convex. We can then partition $A$ conformably to match the partition of $x$ by using $A=[A_1,\dots,A_N]$ such that

\begin{equation}
Ax = \sum_{i=1}^N A_ix_i,
\end{equation}

where $A_i\in\R^{m\times n_i}$.
With this partitioning, the Lagrangian is also separable in $x$ and can be written as

\begin{equation}
L(x,\lambda) = \sum_{i=1}^N \Bigl(f_i(x_i) + \lambda^TA_ix_i\Bigr) - \lambda^Tb.
\end{equation}

The separable structure of $L$ can then be encoded as the $\DiffSaddle$-UWD in Figure <ref>.A. Now, applying $\gad^\gamma$ to this UWD yields a distributed primal-dual solution algorithm which requires synchronization after each gradient step. Specifically, at every iteration, the gradient with respect to $\lambda$ and the $x_i$'s are computed locally for each box. These local gradients are then collected and summed along junctions to produce a gradient update for the total system.

Like Example <ref> which modified a distributed gradient descent UWD to a primal decomposition UWD, we can perform a similar modification to convert our distributed primal-dual UWD to a dual decomposition UWD. For this, we take the dual function

\begin{equation}
q(\lambda)\coloneqq \inf_x L(x,\lambda) = \sum_{i=1}^N\Bigl(\inf_{x_i}f_i(x_i) + \lambda^TA_ix_i\Bigr) - \lambda^Tb,
\end{equation}

which is again separable in $x$. The dual function can then be encoded as the $\DiffSaddle$-UWD shown in Figure <ref>.B. Applying $\gad^\gamma$ to this UWD yields the standard dual decomposition algorithm for solving (<ref>).

§ SUBGRADIENT DESCENT AS A FUNCTOR

We now have algebra morphisms which provide distributed solution algorithms to compositions of unconstrained and equality constrained differentiable problems. The goal of this section is to extend these results to their non-differentiable counterparts, a key aspect
of which is the generalization from gradients to subgradients.
To incorporate subgradient methods into our framework, we need to show that they also provide an algebra morphism from a UWD-algebra of optimization problems to a UWD-algebra of dynamical systems. We can use the $\Conv$ UWD-algebra of convex non-differentiable problems as the domain of this algebra morphism. However, because the subgradient is a point-to-set mapping, $\Dynam$ will not suffice as the codomain. Thus, we first generalize $\Dynam$ and $\Dynam_D$ to algebras of non-deterministic continuous and discrete dynamical systems, which we call $\NDD$ and $\NDD_D$ respectively. We then show that Euler's method is still natural in this non-deterministic setting. Finally, this result allows us to prove that the subgradient method gives an algebra morphism from $\Conv$ to $\NDD_D$.

§.§ Non-deterministic Dynamical Systems

In general, a non-deterministic continuous dynamical system is given by a map $\upsilon\maps \R^N\to P\R^N$, where $P\R^N$ denotes the powerset of the set of vectors in $\R^N$. The map $\upsilon$ can be thought of as taking the current state to the set of possible update directions and is thus identified with the differential inclusion

\begin{equation}
\dot{x}\in \upsilon(x).
\end{equation}

To construct an algebra for composing such non-deterministic systems, we first need to review the powerset functor, which lifts functions $X\to Y$ to functions $PX\to PY$.

There is a functor $P\maps \Set\to\Set$ defined by the following maps:

* On objects, $P$ takes a set $X$ to its powerset $P(X)\coloneqq \{A : A\subseteq X\}$.

* Given a function $f\maps X\to Y$, the mapping $P(f)\maps P(X)\to P(Y)$ is the image function

\begin{equation}
A\mapsto \bigcup_{a\in A} f(a)
\end{equation}

for $A\subseteq X$.

See Example 1.3.2.i in [30].

For preservation of identities, let $X$ be an arbitrary set. Then $P(\id_X)$ is the function

\begin{equation}
U\mapsto \bigcup_{u\in U} \id_X(u) = \bigcup_{u\in U} u = U
\end{equation}

for $U\subseteq X$. This is the identity function on $P(X)$. For preservation of composition, let $f\maps X\to Y$ and $g\maps Y\to Z$ be arbitrary functions. Given a $U\subseteq X$, we have

\begin{equation}
P(g\circ f)(U)\coloneqq \bigcup_{u\in U} g(f(u)) = P(g)(\bigcup_{u\in U} f(u)) = (P(g)\circ P(f))(U)
\end{equation}

as desired.

Henceforth, when we speak of the powerset applied to a vector space, we will always mean the powerset of the vector space's underlying set of vectors. We will also need the following lemma, which says that the powerset functor applied to a linear map is again linear with respect to the Minkowski sum. Recall that the Minkowski sum of two sets $A$ and $B$ with an addition defined on them is the set $\{a+b\mid a\in A, b\in B\}$. We denote the Minkowski sum as $A\boxplus B$ to avoid confusion with our notation for coproduct. Likewise, we denote the Minkowski difference $A\boxplus (-B)$ as $A\boxminus B$.

Given vector spaces $X$ and $Y$, subsets $A,B\subseteq X$, and a linear map $T\maps X\to Y$, we have $(PT)(A\boxplus B) = (PT)(A) \boxplus (PT)(B)$.

We have the following

\begin{align}
(PT)(A\boxplus B) &= \{T(a+b)\mid a\in A, b\in B\} \nonumber \\
&= \{Ta + Tb\mid a\in A,b\in B\} \nonumber \\
&= (PT)(A)\boxplus(PT)(B), \nonumber
\end{align}

where the second equality comes from linearity of $T$ and the remaining equalities are definitions.

Composition of non-deterministic systems is similar to that of deterministic systems, but utilizes the powerset functor and Minkowski summation to lift the deterministic parts of $\Dynam$ to their non-deterministic counterparts.

There is a finset algebra $\NDD\maps (\FinSet,+)\to (\Set,\times)$ defined as follows.

* On objects, $\NDD$ takes a finite set $N$ to the set of functions $\{\upsilon \maps \R^N\to P\R^N\}$.

* Given a function $\phi\maps N\to M$, the mapping $\NDD(\phi)\colon \NDD(N)\to\NDD(M)$ is defined by

\begin{equation}
v\mapsto P\phi_*\circ v\circ \phi^*.
\end{equation}

* Given finite sets $N$ and $M$, the product comparison
\begin{equation*}\varphi_{N,M}\maps\NDD(N)\times\NDD(M)\to\NDD(N+M)\end{equation*}
is defined by the function

\begin{equation}
(\upsilon,\rho)\mapsto P\iota_{N*}\circ\upsilon\circ\iota_N^* \boxplus P\iota_{M*}\circ\rho\circ\iota_M^*.
\end{equation}

* The unit comparison $\varphi_0\maps \1\to \NDD(\emptyset)$ is the function $\R^0\to P\R^0$ defined by $0\mapsto \{0\}$.

Functoriality follows straightforwardly from the fact that $P$ and $(-)_*$ are covariant functors while $(-)^*$ is a contravariant functor. In particular, for preservation of identities we have

\begin{equation}
\NDD(\id_N)(v)\coloneqq P(\id_{N*})\circ v\circ \id_N^* = \id_{P\R^N}\circ v\circ \id_{\R^N} = v.
\end{equation}

Similarly, for preservation of composition, given $\phi\maps X\to Y$ and $\psi\maps Y\to Z$, we have

\begin{align}
\NDD(\psi\circ\phi)(v) &\coloneqq P((\psi\circ\phi)_*)\circ v\circ (\psi\circ\phi)^* \\
&= P(\psi_*\circ\phi_*)\circ v\circ \phi^*\circ \psi^* \\
&= P\psi_*\circ P\phi_*\circ v\circ \phi^*\circ \psi^* \\
&= \NDD(\psi)\circ \NDD(\phi)(v).
\end{align}

For the verification of the naturality of the product comparison, we need to show that the diagram

\[\begin{tikzcd}
{\NDD(X)\times\NDD(Y)} &&& {\NDD(N)\times\NDD(M)} \\
{\NDD(X+Y)} &&& {\NDD(N+M)}
\arrow["{\NDD(\phi)\times\NDD(\psi)}", from=1-1, to=1-4]
\arrow["{\varphi_{X,Y}}"', from=1-1, to=2-1]
\arrow["{\varphi_{N,M}}", from=1-4, to=2-4]
\arrow["{\NDD(\phi+\psi)}"', from=2-1, to=2-4]
\end{tikzcd}\]

commutes for all finite sets $X,Y,N,M$ and functions $\phi\maps X\to N$ and $\psi\maps Y\to M$.
So, fix any systems $(\upsilon,\rho)\in\NDD(X)\times\NDD(Y)$. Following the top path yields the system

\begin{equation}\label{eq:system1}
P\iota_{N*}\circ P\phi_*\circ\upsilon\circ\phi^*\circ\iota_N^* \boxplus P\iota_{M*}\circ P\psi_*\circ \rho \circ \psi^*\circ \iota_M^* = P(\iota_{N*}\circ\phi_*)\circ\upsilon\circ\phi^*\circ\iota_N^* \boxplus P(\iota_{M*}\circ\psi_*)\circ\rho\circ\psi^*\circ\iota_M^*,
\end{equation}

where the equality comes from functoriality of $P$. Following the bottom path yields the system

\begin{equation}\label{eq:system2}
\begin{array}{ll@{}ll}
P(\phi + \psi)_* \circ (P\iota_{X*}\circ\upsilon\circ\iota_X^* \boxplus P\iota_{Y*}\circ\rho\circ\iota_Y^*)\circ(\phi+\psi)^*\\= P(\phi_*\oplus\psi_*)\circ (P\iota_{X*}\circ\upsilon\circ\iota_X^* \boxplus P\iota_{Y*}\circ\rho\circ\iota_Y^*)\circ(\phi^*\oplus\psi^*) \\
= (P(\phi_*\oplus\psi_*)\circ P\iota_{X*}\circ \upsilon\circ\iota_X^* \boxplus P(\phi_*\oplus\psi_*)\circ P\iota_{Y*}\circ \rho\circ\iota_Y^*)\circ(\phi^*\oplus\psi^*) \\
= (P((\phi_*\oplus\psi_*)\circ\iota_{X*})\circ\upsilon\circ\iota_X^* \boxplus P((\phi_*\oplus\psi_*)\circ\iota_{Y*})\circ\rho\circ\iota_Y^*)\circ(\phi^*\oplus\psi^*),
\end{array}
\end{equation}

where the first equality comes from the fact that $(-)_*$ and $(-)^*$ are strong monoidal functors, the second equality comes from Lemma <ref>, and the third equality comes from functoriality of $P$.
Finally, the commutativity of the following diagrams

\[\begin{tikzcd}
{\R^X} && {\R^N} && {\R^Y} && {\R^M} \\
{\R^X\oplus\R^Y} && {\R^N\oplus\R^M} && {\R^X\oplus\R^Y} && {\R^N\oplus\R^M}
\arrow["{\phi_*}", from=1-1, to=1-3]
\arrow["{\iota_{X*}}"', from=1-1, to=2-1]
\arrow["{\iota_{N*}}", from=1-3, to=2-3]
\arrow["{\phi_*\oplus\psi_*}"', from=2-1, to=2-3]
\arrow["{\psi_*}", from=1-5, to=1-7]
\arrow["{\iota_{Y*}}"', from=1-5, to=2-5]
\arrow["{\iota_{M*}}", from=1-7, to=2-7]
\arrow["{\phi_*\oplus\psi_*}"', from=2-5, to=2-7]
\end{tikzcd}\]

together with the commutativity of the diagrams in (<ref>) shows that (<ref>) is equivalent to (<ref>), as desired.

The proofs of the associativity and unit diagrams are lengthy but straightforward calculations, with the only non-trivial step being another application of Lemma <ref>.

We can perform a similar extension to define an algebra for composing non-deterministic discrete systems. First note that there is a natural transformation $\eta\maps \id_\Set\Rightarrow P$ with components $\eta_X\maps X\to PX$ defined by

\begin{equation}
x\mapsto \{x\}
\end{equation}

for all $x\in X$.
This will be useful to lift the identity functions in the definition of $\Dynam_D$ (Example <ref>) with their non-deterministic counterparts.

There is a finset algebra $\NDD_D\maps(\FinSet,+)\to(\Set,\times)$ defined as follows.

* On objects, $\NDD_D$ takes a finite set $N$ to the set of functions $\R^N\to P\R^N$.

* Given a map $\phi\maps N\to M$, the map $\NDD_D(\phi)\maps \NDD_D(N)\to\NDD_D(M)$ is defined by the function

\begin{equation}
v\mapsto \eta_{\R^M}\boxplus P\phi_*\circ (v\boxminus\eta_{\R^N})\circ\phi^*.
\end{equation}

* The comparison maps are the same as they are in $\NDD$.

To see that $\NDD_D$ preserves identities, let $X\in\FinSet$ and $v\maps \R^X\to P\R^X$ be arbitrary. Then

\begin{align}
\NDD_D(\id_X)(v) &\coloneqq
\eta_{\R^X}\boxplus P(\id_{X*})\circ (v\boxminus\eta_{\R^X})\circ\id_X^* \nonumber \\
&= \eta_{\R^X} \boxplus \id_{P\R^X}\circ (v \boxminus \eta_{\R^X})\circ\id_{\R^X} \\
&= \eta_{\R^X}\boxplus v\boxminus\eta_{\R^X} \nonumber \\
&=v, \nonumber
\end{align}

where the first equality comes from preservation of identities of the powerset, pushforward, and pullback functors and the second equality comes from identities being left and right units for composition.

To see that $\NDD_D$ preserves composition, let $\phi\maps X\to Y$ and $\psi\maps Y\to Z$ be arbitrary morphisms in $\FinSet$. Then

\begin{align}
\NDD_D(\psi\circ\phi)(v) &\coloneqq \eta_{\R^Z}\boxplus P((\psi\circ\phi)_*)\circ(v\boxminus\eta_{\R^X})\circ(\psi\circ\phi)^* \nonumber \\
&= \eta_{\R^Z}\boxplus P(\psi_*)\circ(P(\phi_*)\circ(v\boxminus\eta_{\R^X})\circ\phi^*)\circ\psi^* \\
&= \eta_{\R^Z} \boxplus P(\psi_*)\circ(\NDD_D(\phi)(v) \boxminus \eta_{\R^Y})\circ\psi^* \nonumber \\
&= (\NDD_D(\psi)\circ\NDD_D(\phi))(v), \nonumber
\end{align}

where the first equality holds by preservation of composition of the powerset and free vector space functors, and the rest hold by definition.

Since the comparison maps are the same as in $\NDD$, the proofs are similar.

Similar to deterministic systems, we can again use Euler's method on non-deterministic systems to map continuous to discrete.

Given $\gamma >0$, there is a monoidal natural transformation $\Euler^\gamma\maps \NDD\Rightarrow\NDD_D$ with components $\Euler^\gamma_N\maps \NDD(N)\to\NDD_D(N)$ given by the function

\begin{equation}
\upsilon\mapsto \eta_{\R^N} \boxplus \gamma \upsilon.
\end{equation}

To verify naturality, we need to prove that the diagram

\[\begin{tikzcd}
{\NDD(N)} && {\NDD(M)} \\
\\
{\NDD_D(N)} && {\NDD_D(M)}
\arrow["{\NDD(\phi)}", from=1-1, to=1-3]
\arrow["{\Euler^\gamma_N}"', from=1-1, to=3-1]
\arrow["{\Euler^\gamma_M}", from=1-3, to=3-3]
\arrow["{\NDD_D(\phi)}"', from=3-1, to=3-3]
\end{tikzcd}\]

commutes for all $N,M\in \FinSet$ and $\phi\maps N\to M$. So, let $\upsilon\maps\R^N\to P\R^N$ be arbitrary. Following the top path yields the system

\begin{equation}\label{eq:euler_top}
\eta_{\R^M} \boxplus \gamma(P(\phi_*)\circ\upsilon\circ\phi^*),
\end{equation}

while following the bottom path yields the system

\begin{equation}
\eta_{\R^M} \boxplus P(\phi_*)\circ (\eta_{\R^N}\boxplus\gamma \upsilon \boxminus \eta_{\R^N})\circ\phi^* = \eta_{\R^M} \boxplus P(\phi_*)\circ\gamma\upsilon\circ\phi^*,
\end{equation}

which equals (<ref>), as desired.
To verify that the transformation is monoidal, we must verify that the diagrams

\[\begin{tikzcd}
{\NDD(N)\times\NDD(M)} &&& {\NDD_D(N)\times\NDD_D(M)} \\
\\
{\NDD(N+M)} &&& {\NDD_D(N+M)}
\arrow["{\varphi^{\NDD_D}_{N,M}}", from=1-4, to=3-4]
\arrow["{\varphi^\NDD_{N,M}}"', from=1-1, to=3-1]
\arrow["{\Euler^\gamma_N\times\Euler^\gamma_M}", from=1-1, to=1-4]
\arrow["{\Euler^\gamma_{N+M}}"', from=3-1, to=3-4]
\end{tikzcd}\]

\[\begin{tikzcd}
{\1} && {\NDD(\emptyset)} \\
&& {\NDD_D(\emptyset)}
\arrow["{\Euler^\gamma_\emptyset}", from=1-3, to=2-3]
\arrow["{\varphi_0^\NDD}", from=1-1, to=1-3]
\arrow["{\varphi_0^{\NDD_D}}"', from=1-1, to=2-3]
\end{tikzcd}\]

commute for all $N,M\in\FinSet$.
For the product comparison diagram, let $(\upsilon,\rho)\in\NDD(N)\times\NDD(M)$ be arbitrary. Following the top path yields the system

\begin{equation}
\begin{array}{ll@{}ll}
P(\iota_{N*})\circ(\eta_{\R^N}\boxplus\gamma\upsilon)\circ\iota_N^* \boxplus P(\iota_{M*})\circ(\eta_{\R^M}\boxplus\gamma\rho)\circ\iota_M^*=\\
P(\iota_{N*})\circ\eta_{\R^N}\circ\iota_N^* \boxplus P(\iota_{M*})\circ\eta_{\R^M}\circ\iota_M^* \boxplus P(\iota_{N*})\circ\gamma\upsilon\circ\iota_N^* \boxplus P(\iota_{M*})\circ\gamma\rho\circ\iota_M^*,
\end{array}
\end{equation}

where the equality comes from application of Lemma <ref> and rearrangement of terms. Following the bottom path yields the system

\begin{equation}
\eta_{\R^{N+M}}\boxplus P(\iota_{N*})\circ\gamma\upsilon\circ\iota_N^* \boxplus P(\iota_{M*})\circ\gamma\rho\circ\iota_M^*.
\end{equation}

So, to complete this part of the proof, we just need to show that $\eta_{\R^{N+M}}=P(\iota_{N*})\circ\eta_{\R^N}\circ\iota_N^* \boxplus P(\iota_{M*})\circ\eta_{\R^M}\circ\iota_M^*$. For this, note that $\R^{N+M}\cong\R^N\times\R^M$ and let $(x,y)\in\R^N\times\R^M$ be arbitrary. Then

\begin{equation}
\begin{array}{ll@{}ll}
(P(\iota_{N*})\circ\eta_{\R^N}\circ\iota_N^* \boxplus P(\iota_{M*})\circ\eta_{\R^M}\circ\iota_M^*)(x,y)=\\
\{(x,0)\} \boxplus \{(0,y)\} = \{(x,y)\}=\eta_{\R^{N+M}}(x,y).
\end{array}
\end{equation}

Finally, for the unit comparison diagram, let $z\maps\R^0\to P\R^0$ denote the zero function $0\mapsto \{0\}$. We have $(\eta_{\R^0}\boxplus\gamma z)(0) = \{0\} \boxplus \gamma\{0\} = \{0\}$, as desired.

§.§ Algebra Morphisms of Subgradient and Supergradient Methods

With UWD algebras of non-deterministic dynamical systems defined, we can turn to proving that subgradient methods decompose non-differentiable convex optimization problems defined on UWDs. This will again allow us to extend the compositional data condition in a natural way to encompass non-differentiable convex problems.

There is a monoidal natural transformation $\subg\maps \Conv\Rightarrow\NDD$ with components

\begin{equation}
\subg_N\maps \Conv(N)\to\NDD(N),\
f \mapsto -\partial f.
\end{equation}

We first need to check naturality, i.e., check that the diagram

\[\begin{tikzcd}
{\Conv(N)} && {\Conv(M)} \\
\\
{\NDD(N)} && {\NDD(M)}
\arrow["{\Conv(\phi)}", from=1-1, to=1-3]
\arrow["{\subg_N}"', from=1-1, to=3-1]
\arrow["{\subg_M}", from=1-3, to=3-3]
\arrow["{\NDD(\phi)}"', from=3-1, to=3-3]
\end{tikzcd}\]

commutes for all $N,M\in \FinSet$ and $\phi\maps N\to M$. So, let $f\in\Conv(N)$ be arbitrary and let $K=\mathcal{M}(\phi^*)$. Following the bottom path yields $PK^T\circ -\partial f\circ K$ while following the top path yields $-\partial(f\circ K)$. A fact about subgradients is that given a linear transformation $K$, the identity $\partial (f\circ K) = K^T\circ \partial f\circ K$ holds ([40], 3.3).

In such literature, there is an implicit application of the powerset functor such that $K^T\circ\partial f\circ K$ is implied to mean $P(K^T)\circ\partial f\circ K$. Applying this identity to the result of following the top path shows that the two paths are equivalent.

Similar to Theorem <ref>, the proof of monoidality follows the same reasoning as the proof of naturality, noting that the subgradient of a sum of functions is given by the Minkowski sum of the subgradients of the summands ([40], 3.2).

A dual result holds for concave functions and supergradients.

There is a monoidal natural transformation $\superg\maps \Conc\Rightarrow\NDD$ with components $\superg_N\maps \Conc(N)\to\NDD(N)$ defined by

\begin{equation}
\superg_N(f)\coloneqq \partial f.
\end{equation}

There is a monoidal natural transformation $\pdsubg\maps \Saddle\to\NDD\circ U$ with components $\pdsubg_{N\xrightarrow{\tau}[2]}\maps \Saddle(\tau)\to\NDD(N)$ defined by

\begin{equation}
\pdsubg_\tau(f)(x)_i\coloneqq \begin{cases}
-\partial_{x_i} f(x) & \tau(i) = 1 \\
\partial_{x_i} f(x) & \tau(i) = 2,
\end{cases}
\end{equation}

for all $x\in\R^N$ and $i\in N$.

Note that there are also corollaries given by composing each of the above natural transformations with the non-deterministic Euler's transformation to derive discrete systems. We omit these for brevity.

With the naturality of these subgradient methods established, we can repeat our examples of primal decomposition (Example <ref>) and dual decomposition (Example <ref>) while relaxing the assumption of strict convexity of subproblems to mere convexity. This relaxation implies that the infima in these examples could be attained at multiple points. However, any such point $x^*\in \argmin f(w,x)$ for a fixed $w$ furnishes a subgradient for $\inf_x f(w,x)$ as $\partial f(w,x^*)$. Thus, subgradient methods give a natural extension of primal and dual decomposition to cases where subproblems are not strictly convex.

§ EXTENDED EXAMPLE: MINIMUM COST NETWORK FLOW

We now illustrate how our framework gives a principled way to convert problem data into solution algorithms that respect the compositional structure of the data. Specifically, we construct a finset algebra for composing flow networks by gluing together vertices and prove that the translation of a given flow network into the associated minimum cost network flow problem is a monoidal natural transformation. This satisfies the compositional data condition (Definition <ref>), and thus lets us derive a distributed algorithm for solving the
minimum cost network flow (MCNF) problem, which is a widely studied class of problem in engineering applications [41, 42, 43, 44, 45].
We will see that the result is a generalization of a standard dual decomposition algorithm for MCNF which respects arbitrary hierarchical decompositions of flow networks.

§.§ Standard Formulation of MCNF and Dual Decomposition

First we review the standard non-compositional formulation of the MCNF problem. A flow network is a directed graph with designated source and sink vertices (each with a respective inflow and outflow) and a cost function associated to each edge that indicates the cost to push a given flow through that edge. The minimum cost network flow problem then involves finding an allocation of flows to the edges of a flow network that minimizes the total flow cost while satisfying the constraint that the amount of flow into a vertex must equal the amount of flow out of that vertex, for all vertices. This is known as the flow conservation constraint. Applications of network flow problems range from determining if sports teams have been eliminated from championship contention to computing how electricity flows in networks of resistors [46, 47].

Formally, a flow network on a finite set $V$ of vertices is a 5-tuple $(E,s,t,\ell,b)$ where

* $E$ is a finite set of edges,

* $s\maps E\to V$ maps each edge to its source vertex,

* $t\maps E\to V$ maps each edge to its target vertex,

* $\ell \maps E\to K$ where $K\coloneqq\{\kappa \maps\R\to\R\mid \kappa\in C^1 \text{ and convex}\}$ defines the flow cost function for each edge,

* $b\maps V\to \R$ defines the incoming or outgoing flow for each vertex: a positive value for $v\in V$ represents an inflow for $v$, a negative value represents an outflow for $v$ and a value of 0 represents no flow. The total inflow of the graph needs to equal to the total outflow of the graph implying that $\sum_{v\in V}b(v)$ must equal 0. Treating $b$ as a vector in $\R^V$, we can write this condition compactly as $\boldsymbol{1}^Tb = 0$.

All this data can be packaged up in the following diagram:

\begin{equation}
K\xleftarrow{\ell} E\overset{s}{\underset{t}{\rightrightarrows}} V\xrightarrow{b}\R.
\end{equation}

Note that there is a unique flow network on 0 vertices given by:

\begin{equation*}
K\xleftarrow{!}\emptyset\overset{!}{\underset{!}{\rightrightarrows}}\emptyset \xrightarrow{!}\R.
\end{equation*}

Thus the set of flow networks on 0 vertices is a singleton set and thus a terminal object in $\Set$.

Suppose we have a flow network $G=(E,s,t,\ell,b)$ on $V$ vertices. We will use the variable $x\in\R^E$ to track flows on each edge. A value of $x_e>0$ indicates flow in the direction of edge $e$ while a value of $x_e<0$ indicates flow in the opposite direction of edge $e$. Thus, the objective of the minimum cost flow problem is to minimize the function

\begin{equation}
\sum_{e\in E}\ell(e)(x_e).
\end{equation}

We also must enforce the flow conservation constraint. To encode this mathematically, let $A\in\R^{V\times E}$ denote the node incidence matrix[The first condition in the definition is required to quotient out self loops.] of $G$, i.e.,

\begin{equation}
A_{v,e} \coloneqq \begin{cases}
0 & \text{ if } s(e)= t(e) = v \\
1 & \text{ if } s(e)=v \\
-1 & \text{ if }  t(e)=v \\
0 & \text{ otherwise.}
\end{cases}
\end{equation}

Then flow conservation can be compactly stated as requiring that $Ax=b$.
Combining the objective function and constraints, the minimum cost network flow problem for the flow network $G$ is

\begin{equation}
\begin{array}{ll@{}ll}
\text{minimize} & \sum_{e\in E}\ell(e)(x_e) & \\
\text{subject to} & Ax=b. \\
\end{array}
\end{equation}

A common first-order solution procedure is to form the Lagrangian and use dual decomposition. The Lagrangian is

\begin{equation}
L(x,\lambda) \coloneqq \sum_{e\in E}\ell(e)(x_e) + \lambda^T(Ax-b).
\end{equation}

Then, the dual function $q_G\maps\R^V\to\R$ is the concave function given by

\begin{equation}
q_G(\lambda)\coloneqq\inf_{x\in\R^E}L(x,\lambda)= \inf_{x\in\R^E}\sum_{e\in E}\ell(e)(x_e) + \lambda^T(Ax-b).
\end{equation}

Applying supergradient ascent to $q_G$ gives the iterative algorithm

\begin{equation}
\begin{array}{ll@{}ll}
x^*&\coloneqq \argmin L(x,\lambda_k)\\
\lambda_{k+1}&\coloneqq \lambda_k + \gamma (Ax^* - b).
\end{array}
\end{equation}

This works because $Ax^*-b$ is a supergradient of $q_G$ at $\lambda_k$. Since $L$ is separable in $x$, the computation of $x^*$ decomposes into $|E|$ scalar minimizations.

§.§ Compositional Formulation of MCNF

To generalize this dual decomposition algorithm to arbitrary hierarchical decompositions of flow networks, we must first define a finset algebra for composing flow networks.

There is a finset algebra[This is technically only a lax symmetric monoidal pseudofunctor because some of the required diagrams only hold up to canonical isomorphism. See [11] for details on this technicality.] $\FG\maps (\FinSet,+)\to(\Set,\times)$ defined by the following maps:

* On objects, $\FG$ takes a finite set $N$ to the set of flow networks with vertex set $N$:

\begin{equation}
\{K\xleftarrow{\ell} E\overset{s}{\underset{t}{\rightrightarrows}} N\xrightarrow{b}\R\mid \textbf{1}^Tb=0\}.
\end{equation}

* Given a morphism $\phi\maps N\to M$ in $\FinSet$, the map $\FG(\phi)\maps\FG(N)\to\FG(M)$ is defined by the function

\begin{equation}
(E,s,t,\ell,b)\mapsto (E,\phi\circ s,\phi\circ t,\ell, \phi_*(b)).
\end{equation}

* The unit comparison $\varphi_0\maps \1\to\FG(\emptyset)$ is the unique arrow since $\FG(\emptyset)$ is a terminal object in $\Set$.

* Given objects $N,M\in\FinSet$, the product comparison

\begin{equation}
\varphi_{N,M}\maps \FG(N)\times\FG(M)\to\FG(N+M)
\end{equation}

takes a pair of flow networks $(E_1,s_1,t_1,\ell_1,b_1)$ and $(E_2,s_2,t_2,\ell_2,b_2)$ to their disjoint union, i.e., $(E_1+E_2,s_1+s_2,t_1+t_2,[\ell_1,\ell_2],[b_1,b_2])$.

$\FG$ is an extension of the labelled graph functor introduced in [11] with the addition of a scalar on each vertex defined by the $b$ vector, so most of their proof carries over. We only need to check that the morphism map and product comparison preserve the property that

$\boldsymbol{1}^Tb=0$. The pairing $[b_1,b_2]$ in the product comparison preserves this property because both $\boldsymbol{1}^T b_1 = 0$ and $\boldsymbol{1}^T b_2 = 0$. For the morphism map, note that for vectors $v = \phi_*(b)$ in the image of the pushforward map, a component $v_i$ is either 0, a single element of $b$, or the sum of one or more elements of $b$. Since the components of $b$ sum to $0$ and every component of $b$ gets mapped under $\phi_*$ either to itself or a sum with other components of $b$, the components of $v$ in the image of $\phi$ must sum to zero. Furthermore, since the components of $v$ not in the image of $\phi$ are 0, the sum of all components of $v$ is 0.

Given a UWD and subgraphs with the appropriate number of nodes for each inner box, the $\FG$ algebra constructs a composite graph by merging vertices which share the same junctions. This is illustrated in Figure <ref>.

An illustration of composing flow networks using the $\FG$ UWD-algebra. $\FG$ is applied to the UWD $\Phi$ and the component subgraphs $G_1,G_2,$ and $G_3$ to yield the resultant flow network on the right. Here, we only illustrate the action of $\FG$ on the underlying directed graph structure of flow networks. Colors were added to emphasize the distinction between vertices which are merged and vertices which are not merged by composition.

Now, our goal is to show that the translation of flow networks into their associated MCNF objective function constitutes a monoidal natural transformation and thus satisfies the compositional data condition.
First note that the translation of a flow network $G$ on $V$ vertices into the dual function $q_G$ of the associated MCNF problem gives us a function $\netflow_V\maps\FG(V)\to\Conc(V)$ defined by $G\mapsto q_G$. Since this translation works for any $V$, we have a family of maps indexed by finite sets which will form the components of our natural transformation.

There is a monoidal natural transformation $\netflow\maps \FG\Rightarrow \Conc$ whose components $\netflow_N\maps \FG(N)\to\Conc(N)$ take a flow network $G\coloneqq (E,s,t,\ell,b)$ on $N$ vertices to the concave function

\begin{equation}
\lambda\mapsto \inf_{x\in\R^E}\sum_{e\in E}\ell(e)(x_e) + \lambda^T(Ax-b),
\end{equation}

where $A$ is the node incidence matrix of $G$.

To verify naturality, we need to show that the diagram

\[\begin{tikzcd}
{\FG(N)} && {\FG(M)} \\
\\
{\Conc(N)} && {\Conc(M)}
\arrow["{\FG(\phi)}", from=1-1, to=1-3]
\arrow["{\Conc(\phi)}"', from=3-1, to=3-3]
\arrow["{\netflow_N}"{description}, from=1-1, to=3-1]
\arrow["{\netflow_M}"{description}, from=1-3, to=3-3]
\end{tikzcd}\]

commutes for all $N,M\in\FinSet$ and $\phi\maps N\to M$. Let $(E,s,t,\ell,b)\in\FG(N)$ be arbitrary, and let $K=\mathcal{M}(\phi^*)$. Because the pushforward is dual to the pullback, we know that $K^T=\mathcal{M}(\phi_*)$.  Now, following the top path results in the function

\begin{equation}
\lambda\mapsto \inf_{x\in\R^E}\sum_{e\in E}\ell(e)(x_e)+\lambda^T(Ax-K^Tb),
\end{equation}

where $A\in\R^{M\times E}$ is defined by

\begin{equation}
A_{e,m}\coloneqq \begin{cases}
0 & \text{ if } \phi(s(e))= \phi(t(e)) = m \\
1 & \text{ if } \phi(s(e))=m \\
-1 & \text{ if }  \phi(t(e))=m \\
0 & \text{ otherwise.}
\end{cases}
\end{equation}

Similarly, following the bottom path yields the function

\begin{equation}
\lambda\mapsto \inf_{x\in\R^E}\sum_{e\in E}\ell(e)(x_e)+(K\lambda)^T(Cx - b) = \inf_{x\in\R^E}\sum_{e\in E}\ell(e)(x_e)+\lambda^T(K^TCx - K^Tb),
\end{equation}

where $C\in\R^{N\times E}$ is defined by

\begin{equation}
C_{e,n}\coloneqq \begin{cases}
0 & \text{ if } s(e)= t(e) = n \\
1 & \text{ if } s(e)=n \\
-1 & \text{ if }  t(e)=n \\
0 & \text{ otherwise.}
\end{cases}
\end{equation}

Thus, to complete the proof, it suffices to show that $A = K^TC$. To see why this is the case, first note that $A$ and $C$ both have $|E|$ columns. So consider an arbitrary $e\in E$. We just need to show that $a_e = K^Tc_e \coloneqq \phi_*(c_e)$, where $a_e$ and $c_e$ are the $e^{th}$ columns of $A$ and $C$, respectively. Letting $m\in M$ be arbitrary and using the definition of pushforward, we know that

\begin{equation}\label{eq:c_e}
\phi_*(c_e)(m) \coloneqq \sum_{n\in\phi^{-1}(m)}c_e(n) = \sum_{n\in\phi^{-1}(m)}\begin{cases}
0 & \text{ if } s(e)= t(e) = n \\
1 & \text{ if } s(e)=n \\
-1 & \text{ if }  t(e)=n \\
0 & \text{ otherwise.}
\end{cases}
\end{equation}

We now consider the three possibilities for the value of $a_e(m)$ and show that in every case they must equal the value of $\phi_*(c_e)(m)$.

First, suppose that $a_e(m) = 1$. Then by definition of $A$, we know that $\phi(s(e))=m$ and $\phi(t(e))\neq m$. These equations imply that $s(e)\in\phi^{-1}(m)$ and $t(e)\notin\phi^{-1}(m)$, and thus (<ref>) says that $\phi_*(c_e)(m)$ must equal $1$. A similar argument shows that if $a_e(m) = -1$, then $\phi_*(c_e)(m) = -1$.

Finally, we must consider the case when $a_e(m) = 1$. There are two possibilities: either $s(e)\notin\phi^{-1}(m)$ and $t(e)\notin\phi^{-1}(m)$, in which case (<ref>) says that $\phi_*(c_e)(m) = 0$, or $s(e)\in\phi^{-1}(m)$ and $t(e)\in\phi^{-1}(m)$. In the latter case, by (<ref>), $\phi_*(c_e)(m)\coloneqq 1 - 1 = 0$, as desired.

To verify that the transformation is monoidal, we need to verify that the diagrams

\[\begin{tikzcd}
{\FG(N)\times\FG(M)} && {} & {\Conc(N)\times\Conc(M)} \\
{\FG(N+M)} &&& {\Conc(N+M)}
\arrow["{\varphi_{N,M}^\FG}"', from=1-1, to=2-1]
\arrow["{\netflow_N\times\netflow_M}", from=1-1, to=1-4]
\arrow["{\varphi_{N,M}^\Conc}", from=1-4, to=2-4]
\arrow["{\netflow_{N+M}}"', from=2-1, to=2-4]
\end{tikzcd}\]

\[\begin{tikzcd}
{\1} && {\FG(\emptyset)} \\
&& {\Conc(\emptyset)}
\arrow["{\netflow_\emptyset}", from=1-3, to=2-3]
\arrow["{\varphi_0^\FG}", from=1-1, to=1-3]
\arrow["{\varphi_0^\Conc}"', from=1-1, to=2-3]
\end{tikzcd}\]

commute for all $N,M\in\FinSet$.

For the first diagram, let $G_1\coloneqq (E_1,s_1,t_1,\ell_1,b_1)\in\FG(N)$ and $G_2\coloneqq (E_2,s_2,t_2,\ell_2,b_2)\in\FG(M)$ be arbitrary, and let $A_{G_1}$ and $A_{G_2}$ denote the node incidence matrices of $G_1$ and $G_2$, respectively. Then, following the top path results in the function

\begin{equation}\label{eq:nf_mon_1}
\lambda\mapsto \inf_{x\in\R^{E_1}}\sum_{e\in E_1}\ell_1(e)(x_e) + \pi_N(\lambda)^T(A_{G_1}x-b_1) + \inf_{x'\in\R^{E_2}}\sum_{e'\in E_2}\ell_2(e')(x'_{e'}) + \pi_M(\lambda)^T(A_{G_2}x'-b_2).
\end{equation}

Likewise, following the bottom path yields the function

\begin{equation}\label{eq:nf_mon_2}
\lambda\mapsto \inf_{y\in\R^{E_1+E_2}}\sum_{e\in E_1+E_2}[\ell_1,\ell_2](e)(y_e) + \lambda^T\left(\begin{bmatrix}
A_{G_1} & 0 \\ 0 & A_{G_2}
\end{bmatrix}y - \begin{bmatrix}
b_1 \\ b_2