1. A photonic integrated circuit for performing quantum information processing, the photonic integrated circuit comprising: a semiconductor substrate; a plurality of interconnected variable beam splitters, fabricated in the semiconductor substrate, to perform at least one linear optical transformation on a plurality of optical modes coupled into the plurality of interconnected variable beam splitters; a plurality of detectors, in optical communication with the plurality of variable beam splitters, to measure an output state of the plurality of optical modes; and control circuitry, operably coupled to the plurality of interconnected variable beam splitters and to the plurality of detectors, to determine a fidelity of the output state of the plurality of optical modes to an ideal output state of the plurality of optical modes and to adjust a phase setting of at least one variable beam splitter in the plurality of interconnected variable beam splitters so as to increase the fidelity of the output state of the plurality of optical modes to the ideal output state of the plurality of optical modes.