  Linear optics underpins tests of fundamental quantum mechanics and computer
science, as well as quantum technologies. Here we experimentally demonstrate
the longstanding goal of a single reprogrammable optical circuit that is
sufficient to implement all possible linear optical protocols up to the size of
that circuit. Our six-mode universal system consists of a cascade of 15
Mach-Zehnder interferometers with 30 thermo-optic phase shifters integrated
into a single photonic chip that is electrically and optically interfaced for
arbitrary setting of all phase shifters, input of up to six photons and their
measurement with a 12 single-photon detector system. We programmed this system
to implement heralded quantum logic and entangling gates, boson sampling with
verification tests, and six-dimensional complex Hadamards. We implemented 100
Haar random unitaries with average fidelity 0.999 $\pm$ 0.001. Our system is
capable of switching between these and any other linear optical protocol in
seconds. These results point the way to applications across fundamental science
and quantum technologies.
