  Experimental setups based on linear optical circuits and single photon
sources offer a promising platform for near-term quantum machine learning.
However, current applications are all based on support vector machines and
gradient-free optimization methods. Differentiating an optical circuit over a
phase parameter poses difficulty because it results in an operator on the Fock
space which is not unitary. In this paper, we show that the derivative of the
expectation values of a linear optical circuit can be computed by sampling from
a larger circuit, using one additional photon. In order to express the
derivative in terms of expectation values, we develop a circuit extraction
procedure based on unitary dilation. We end by showing that the full gradient
of a universal programmable interferometer can be estimated using polynomially
many queries to a boson sampling device. This is in contrast to the qubit
setting, where exponentially many parameters are needed to cover the space of
unitaries. Our algorithm enables applications of photonic technologies to
machine learning, quantum chemistry and optimization, powered by gradient
descent.
