  We show how techniques from machine learning and optimization can be used to
find circuits of photonic quantum computers that perform a desired
transformation between input and output states. In the simplest case of a
single input state, our method discovers circuits for preparing a desired
quantum state. In the more general case of several input and output relations,
our method obtains circuits that reproduce the action of a target unitary
transformation. We use a continuous-variable quantum neural network as the
circuit architecture. The network is composed of several layers of optical
gates with variable parameters that are optimized by applying automatic
differentiation using the TensorFlow backend of the Strawberry Fields photonic
quantum computer simulator. We demonstrate the power and versatility of our
methods by learning how to use short-depth circuits to synthesize single
photons, Gottesman-Kitaev-Preskill states, NOON states, cubic phase gates,
random unitaries, cross-Kerr interactions, as well as several other states and
gates. We routinely obtain high fidelities above 99\% using short-depth
circuits, typically consisting of a few hundred gates. The circuits are
obtained automatically by simply specifying the target state or gate and
running the optimization algorithm.
