Choosing a template

The template is the family the node functions are drawn from. In the program that certify solves, it gives the variables and sets the kind of program: semidefinite, linear or second-order cone. With the graph, it influences how good the certificate can be and how much it costs (see How a certificate works). This page shows what a template changes, lists the templates, and helps you choose.

The code on this page uses the running example of Systems and problems: system, problem = StabilityProblem(system) and graph = common_graph(system), solved with Clarabel and HiGHS.

What a template changes

The template fixes the shape of the node functions. It changes the bound and the kind of program, and so the solver:

quadratic = certify(QuadraticTemplate(), graph, problem; optimizer = Clarabel.Optimizer)
copositive = certify(LinearCopositiveTemplate(), graph, problem; optimizer = HiGHS.Optimizer)
quadratic.rate, copositive.rate
(0.9586944580078125, 0.9269752502441406)

The quadratic template solves a semidefinite program, with Clarabel, and the linear copositive template a linear program, with HiGHS. The latter applies here because the matrices have nonnegative entries (see What works with what).

The unit sets $\{x : V(x) \le 1\}$ of the certificates that four templates find on the running example show their shapes:

Example block output

The data of a template matter too. Given a matrix per node, DualPiecewiseLinearTemplate fixes the normals of the faces of its functions to the rows of the matrix. With the axes, and with the diagonals of the figure:

on_axes = DualPiecewiseLinearTemplate(n_nodes(graph), 2)
on_diagonals = DualPiecewiseLinearTemplate([[1.0 1.0; -1.0 1.0]])
[certify(t, graph, problem; optimizer = HiGHS.Optimizer).rate for t in (on_axes, on_diagonals)]
2-element Vector{Float64}:
 1.3048381805419922
 0.9188051223754883

The templates

ConstructorNode function $V_s(x)$Variables$\delta$Unit set $\Omega_s$
QuadraticTemplate()$x^\top P_s x$$P_s$2$\mathcal{E}(P_s)$
PiecewiseQuadraticTemplate(P)$x^\top P_{s,k} x$ on $\mathcal{C}_{s,k}$$P_{s,k}$, all $k$2$\operatorname{Pw}_s\big((\mathcal{E}(P_{s,k}))_k\big)$
SumOfSquaresTemplate(r)$b_r(x)^\top Q_s \, b_r(x)$$Q_s \succeq 0$$2r$$\{x : V_s(x) \le 1\}$
PiecewiseLinearTemplate(P)$a_{s,k}^\top x$ on $\mathcal{C}_{s,k}$$a_{s,k}$, all $k$1$\operatorname{Pw}_s\big((\mathcal{H}(a_{s,k}))_k\big)$
DualPiecewiseLinearTemplate(P)$g_{\Omega_s}(x)$$a_{s,k}$, all $k$1$\operatorname{Pw}_s\big((\mathcal{H}(a_{s,k}))_k\big)^\circ$
LinearCopositiveTemplate()$c_s^\top x$, on $\mathbb{R}^n_+$$c_s \ge 0$1$\mathcal{H}(c_s) \cap \mathbb{R}^n_+$
DualCopositiveTemplate()$\max_j x_j / v_{s,j}$, on $\mathbb{R}^n_+$$v_s > 0$1$\prod_j \, [0, v_{s,j}]$

The table writes $\mathcal{E}(P) = \{x : x^\top P x \le 1\}$ for an ellipsoid and $\mathcal{H}(a) = \{x : a^\top x \le 1\}$ for a half-space, and $\delta$ is the degree of the node functions. The constructors also make the node functions symmetric, and normalize them to exclude $V_s \equiv 0$, which the table does not show. What works with what gives the systems and problems each template supports, the program it gives for each, and where refine applies. The sum-of-squares and piecewise quadratic templates need the SumOfSquares package loaded (see Installation). The templates fall into four groups.

Quadratic and polynomial. The quadratic template gives ellipsoids. For SumOfSquaresTemplate(r), $b_r(x)$ is the vector of the monomials of degree $r$, and $Q_s \succeq 0$ makes $V_s$ a sum of squares (Parrilo and Jadbabaie, 2008): $r = 1$ gives the quadratic forms, and each higher $r$ adds variables. convex = true also makes each node function convex, for optimal control (see What works with what).

Piecewise. A polytope $\mathcal{P}_s$ containing the origin in its interior defines a cone on each of its facets $\mathcal{F}_{s,k}$, and a piecewise set keeps one set $Z_k$ on each cone:

\[\mathcal{C}_{s,k} = \{t y : t \ge 0,\ y \in \mathcal{F}_{s,k}\}, \qquad \operatorname{Pw}_s\big((Z_k)_k\big) = \textstyle\bigcup_k \big(Z_k \cap \mathcal{C}_{s,k}\big).\]

On each cone, the piecewise quadratic template keeps an ellipsoid and the piecewise linear template a half-space, so that $V_s$ is quadratic or linear on each cone. Continuity and convexity are imposed across adjacent cones. The argument P gives the polytopes $\mathcal{P}_s$, one per node, and planar_conic_partition(q) builds a planar one with $8 \cdot 2^{q-1}$ facets.

Dual piecewise linear. The dual piecewise linear template is the polar of the piecewise linear one, on the same polytopes, and dual maps each to the other (see Duality). Fixing the directions of the vertices of one fixes the normals of the faces of the other: these are the two polyhedral parameterizations of Athanasopoulos and Jungers (2019). Two other constructors build the polytopes from matrices. DualPiecewiseLinearTemplate(matrices), with one invertible matrix $G_s$ per node, takes the rows of $G_s$ and their opposites as the vertices of $\mathcal{P}_s$, so that the unit sets are parallelotopes with faces normal to the rows of $G_s$. DualPiecewiseLinearTemplate(n_nodes, n) sets $G_s = I$, which gives boxes.

Copositive. For positive systems, the nonnegative orthant is invariant, and the copositive templates restrict the node functions to it (Debauche et al., 2022; Def. 11). The linear copositive template has unit set $\mathcal{H}(c_s) \cap \mathbb{R}^n_+$. The dual copositive template takes its polar within the orthant, the box $\prod_j [0, v_{s,j}]$.

How to choose

  • Start with QuadraticTemplate(). It applies to every system and every problem.
  • For the stability of a positive system, LinearCopositiveTemplate() and DualCopositiveTemplate() solve linear programs.
  • For a polyhedral function on any system, PiecewiseLinearTemplate(P) or DualPiecewiseLinearTemplate(P), whose data change the bound, as above.
  • For a polynomial function, SumOfSquaresTemplate(r), of degree $2r$.
  • For a function quadratic on each cone, PiecewiseQuadraticTemplate(P).

Which template gives the lowest bound depends on the system, and a template with more variables builds a larger program: try several.

Templates are SetProg families

Each constructor returns a SetProg family of sets, or, for the templates with data per node, a vector of families, one per node: QuadraticTemplate() is SetProg.Ellipsoid(symmetric = true), and PiecewiseLinearTemplate([P]) is [SetProg.Polytope(symmetric = true, piecewise = P)]. A SetProg family can also be passed directly, without a constructor (see Try a richer template). To write one, run Pkg.add("SetProg") and import SetProg. The package depends on SetProg, so nothing new is downloaded, but your environment must list it for Julia to load it by name. Load it with import rather than using, which would hide the package's dual, is_valid and lift behind SetProg's.

Adding a template

A new template is a SetProg family: see Extending the package.