  Gaussian Boson Sampling (GBS) is a near-term platform for photonic quantum
computing. Applications have been developed which rely on directly programming
GBS devices, but the ability to train and optimize circuits has been a key
missing ingredient for developing new algorithms. In this work, we derive
analytical gradient formulas for the GBS distribution, which can be used to
train devices using standard methods based on gradient descent. We introduce a
parametrization of the distribution that allows the gradient to be estimated by
sampling from the same device that is being optimized. In the case of training
using a Kullback-Leibler divergence or log-likelihood cost function, we show
that gradients can be computed classically, leading to fast training. We
illustrate these results with numerical experiments in stochastic optimization
and unsupervised learning. As a particular example, we introduce the
variational Ising solver, a hybrid algorithm for training GBS devices to sample
ground states of a classical Ising model with high probability.
