  A programmable quantum processor is a fundamental model of quantum
computation. In this model, any quantum channel can be approximated by applying
a fixed universal quantum operation onto an input state and a quantum `program'
state, whose role is to condition the operation performed by the processor. It
is known that perfect channel simulation is only possible in the limit of
infinitely large program states, so that finding the best program state
represents an open problem in the presence of realistic finite-dimensional
resources. Here we prove that the search for the optimal quantum program is a
convex optimization problem. This can be solved either exactly, by minimizing a
diamond distance cost function via semi-definite programming, or approximately,
by minimizing other cost functions via gradient-based machine learning methods.
We apply this general result to a number of different designs for the
programmable quantum processor, from the shallow protocol of quantum
teleportation, to deeper schemes relying on port-based teleportation and
parametric quantum circuits. We benchmark the various designs by investigating
their optimal performance in simulating arbitrary unitaries, Pauli and
amplitude damping channels.
