  A fundamental model of quantum computation is the programmable quantum gate
array. This is a quantum processor that is fed by a program state that induces
a corresponding quantum operation on input states. While being programmable,
any finite-dimensional design of this model is known to be nonuniversal,
meaning that the processor cannot perfectly simulate an arbitrary quantum
channel over the input. Characterizing how close the simulation is and finding
the optimal program state have been open questions for the past 20 years. Here,
we answer these questions by showing that the search for the optimal program
state is a convex optimization problem that can be solved via semidefinite
programming and gradient-based methods commonly employed for machine learning.
We apply this general result to different types of processors, from a shallow
design based on quantum teleportation, to deeper schemes relying on port-based
teleportation and parametric quantum circuits.
