Programming and Calibrating Meshes

On paper, this module's story is complete: decompose the matrix, set the phases, ship the chip. In the lab, a fabricated mesh greets its first power-up very differently. Every waveguide came out of the fab a few nanometres wide or narrow of nominal, so every MZI sits at an unknown phase offset — set all heaters to zero and the mesh implements not the identity but a random unitary of the universe's choosing. Drive one thermal phase shifter and its heat leaks sideways, nudging its neighbours' phases too. Let the room warm by a degree and every setting drifts. A photonic mesh, in short, is not an FPGA you flash; it is a thousand-string instrument that must be tuned, and kept in tune while playing. This lesson is about the tuning: how a target matrix becomes phase settings, how errors propagate through the computation, and the surprisingly elegant tricks by which a mesh can be made to tune itself.

Programming: the decomposition, run in reverse

The "compiler" was built two lessons ago. Given a target unitary U, run the Clements nulling procedure on the numbers: eliminate entries one Givens rotation at a time, and each elimination hands you the exact knob pair (\theta_k, \varphi_k) of one physical MZI, with the leftover diagonal filling the output phase column. (For a non-unitary target, first split it into U \Sigma V^\dagger and compile the two meshes plus attenuator row of the SVD sandwich.) Milliseconds of CPU time; the output is a list of N^2 phases.

Then reality interposes a translation layer. A phase of "\theta = 1.7 rad" is not a voltage; each shifter has its own response curve (phase vs drive power, roughly linear for heaters, plus that fabrication offset \delta_{\mathrm{fab}}), so the control software keeps a per-device calibration table, measured by sweeping each shifter while watching monitor detectors, and applies \text{drive} = g^{-1}(\theta_{\mathrm{wanted}} - \delta_{\mathrm{fab}}). Building and maintaining that table for thousands of shifters is the unglamorous half of photonic computing — and the half that decides whether the elegant theorem upstairs survives contact with glass.

How error grows: the tyranny of N(N-1)

Suppose calibration leaves each phase with a small independent residual error of standard deviation \sigma radians. How wrong is the implemented matrix \tilde U? Measure closeness by the fidelity F = |\mathrm{tr}(U^\dagger \tilde U)|/N (1 when perfect). Perturbing a single phase by \delta multiplies one gate by e^{i\delta} on one arm; expanding to second order costs fidelity \approx \delta^2/4. Independent errors don't cancel — their variances add — so with N(N-1) phases in the mesh (two per MZI) the losses compound to, in a useful back-of-envelope model,

F \;\approx\; \prod_{\text{phases}} \left(1 - \tfrac{\sigma^2}{4}\right) \;\approx\; \exp\!\left(-\,\frac{N(N-1)\,\sigma^2}{4}\right)

(the exact constant depends on convention and on where in the mesh each error sits — errors in central MZIs hurt more than edge ones — but the scaling is the story). Read the exponent like an engineer: fidelity is set by (number of phases) × (error per phase)². Play with the slider and watch the same per-phase error that is harmless at N = 4 demolish a N = 32 mesh:

The scaling has teeth: quadrupling the mesh's linear size multiplies its phase count —and hence the exponent — by roughly sixteen, demanding per-phase accuracy four times better just to stand still. This is the honest reason photonic processors did not leap from 4×4 demos to 1024×1024 products in a product cycle, and why everything below exists.

Crosstalk, and meshes that tune themselves

Worse than independent errors: the knobs are not even independent. A thermo-optic shifter is a resistor heating a waveguide, and heat diffuses — driving heater j shifts neighbouring phases too, so the true phase vector is \boldsymbol\theta = X \boldsymbol\theta_{\mathrm{set}} with X a crosstalk matrix: near-1 diagonal, small but stubborn off-diagonal terms. Turning one screw slightly turns the neighbours. Fixes come in layers: physical isolation (trenches, spacing), characterising X once and pre-inverting it in software, and lock-in tricks — dither each phase at its own kilohertz tone and read each knob's true effect out of the detector spectrum, even while the mesh is computing.

The most elegant escape, though, dodges the problem entirely: self-configuration. In protocols introduced by David Miller, the mesh is set up one MZI at a time using only local, physical feedback: inject the appropriate input, watch a monitor detector on one port, and adjust the two knobs of one MZI until that detector nulls; repeat down the mesh in the decomposition's own elimination order. The procedure needs no knowledge of any offset, response curve or crosstalk — each null is a physical fact, not a computed setting, so every imperfection is absorbed automatically. It is the Givens elimination executed by photons instead of floating point. The same philosophy scales up in hardware-in-the-loop training: put the physical chip inside the optimisation loop and let gradient descent sculpt drive settings directly — whatever static error the hardware has, the optimiser routes around, because it only ever sees the chip as it truly is.

Which matrices forgive, and which punish

One last twist: the same hardware error hurts different targets unequally. The mesh's phase errors amount to a perturbation \Delta M of the implemented matrix, and the downstream damage to the answer follows the conditioning law: the relative output error can reach

\frac{\|\Delta y\|}{\|y\|} \;\lesssim\; \kappa(M)\, \frac{\|\Delta M\|}{\|M\|}, \qquad \kappa(M) = \frac{\sigma_{\max}}{\sigma_{\min}} .

A well-conditioned target (\kappa near 1 — unitaries are the ideal citizens, \kappa = 1 exactly) passes hardware error through undramatically. An ill-conditioned one is an amplifier for it: components of the answer that ride on small singular values have been attenuated down toward the noise floor inside the SVD sandwich, and on such a channel a phase error's leakage is comparable to the signal itself. Hardware and mathematics deliver the same verdict the pseudoinverse lesson reached numerically: past a point set by your error budget, small singular values are not information to preserve but noise to clip. Photonic processors prefer — and photonic-aware training deliberately produces — well-conditioned weight matrices; it is one of the cleaner examples of hardware physics reaching back to reshape the algorithms that run on it.

Around 2013, Stanford's David Miller — a lifetime deep in the physics of optical interconnects — published a deceptively simple observation. Suppose light arrives at a chip in some arbitrary, even unknown, superposition across several waveguides, and you would like all of its power gathered into one. Put a photodiode on the port you want dark, and adjust the nearest MZI's knobs until that diode reads zero; move to the next MZI and the next diode; repeat. When the last diode nulls, all the light — by pure energy conservation — has been herded into the one remaining port, and the mesh has, without any calculation, physically measured and inverted the unknown input state. No calibration tables, no crosstalk model, no knowledge of the errors the procedure just silently absorbed. Run backwards, the same sweep programs a mesh to any desired unitary, column by column. Miller's protocols turned "calibrate ten thousand analog knobs" from a metrology nightmare into a for-loop over photodiodes, and they are a direct ancestor of the self-configuring, drift-chasing control layers in today's commercial photonic processors — the subject the capstone module's control-and-drift lesson picks back up.

The tempting mental model — characterise the chip at the factory, burn the table to flash, done — fails for photonic meshes on three separate clocks. Seconds to minutes: thermal drift. Phases depend on temperature so strongly that the computation itself disturbs them: reprogram half the mesh and the changed heater load warms the other half off its settings. Hours to days: environment — ambient swings, package stress, humidity creeping into claddings. Months to years: aging of heaters and materials. Production systems therefore treat calibration as a process, not an event: temperature servos on the package, monitor taps sprinkled through the mesh, background dither loops continuously re-nulling while the chip computes, periodic full re-characterisation. Budget the control electronics accordingly — in mature designs the tuning-and-monitoring layer rivals the photonics in complexity and, for thermal meshes, dominates the standing power draw. A mesh is never "calibrated"; it is only ever being calibrated.

Module 4, closed — and the door it opens

Take stock of what this module built: beamsplitters are unitary matrices; two phases make an MZI a programmable 2×2; N(N-1)/2 of them make any unitary; SVD extends the reach to every matrix; one transit of light performs the multiply; and — today — the analog realities of programming the thing, with error scaling that explains the field's engineering agenda. Interference, in short, computes linear algebra. What linear algebra most wants computing, right now, is neural networks — Module 5 puts these meshes to work as AI accelerators, where the missing ingredient (nonlinearity), the precision budget, and the energy accounting each get a lesson of their own.