## Introduction

Large-scale programmable photonic circuits are opening up radical new possibilities for optics. Of key importance in many devices is the universal multiport interferometer, which functions as an N × N reconfigurable feedforward linear circuit. This device, typically constructed with a compact mesh of Mach–Zehnder interferometers (MZIs, Fig. 1a, b)1,2, is widely employed in applications ranging from spatially multiplexed optical communications to machine learning and quantum computing3,4,5,6,7. Sadly, component errors (Fig. 1c) are a critical factor limiting the size of such circuits. Since the circuit depth of MZI meshes scales as O(N), the effect of errors grows with mesh size, meaning that, in practice, even modestly sized circuits cannot be programmed to high accuracy. Motivated by this challenge, a large body of recent work has focused on “correcting” hardware errors by global optimization8,9,10, self-configuration11,12,13,14,15,16,17,18, or local correction19,20. For conventional MZI meshes, correction reduces errors by a quadratic factor16,19; however, the effect of errors still grows with mesh size and poses a fundamental limit to the scaling of these circuits.

To overcome this limit, various alternative mesh architectures have been proposed. Non-compact structures such as binary trees avoid the extreme splitting-ratio requirements21,22, but suffer from large chip area and the need for many crossings. A complementary approach is to stick to conventional geometries1,2, but insert redundant MZIs to realize the full range of splitting ratios even in imperfect hardware23,24,25. This solves the scaling problem, but at the cost of a 1.5–2× increase in the number of splitters and phase shifters. The resulting effects on chip area (particularly on emerging high-speed platforms where phase shifters have a large footprint26,27), waveguide length (which affects insertion loss and latency28), and electronic complexity (number of pads, traces, DACs/drivers, etc.) make this option unappealing.

In this paper, we propose two mesh architectures that achieve the same perfect scaling without significant added complexity: a 3-splitter MZI that corrects all hardware errors (Fig. 1d) and an MZI+crossing design that only corrects correlated errors, but has the added advantage of broader bandwidth (Fig. 1e). These designs take up significantly less chip area than the “perfect” redundant MZIs23,24, and do not require additional phase shifters. Moreover, the proposed architectures support progressive self-configuration16,17, allowing for error correction even when the hardware errors are unknown. This work will enable the development of freely scalable, broadband, and compact linear photonic circuits.

This paper is structured as follows: first we introduce the formalism of error correction in MZI meshes, focusing on the self-configuration approach. Splitting ratios are visualized as points on the Riemann sphere, where forbidden regions emerge as a result of hardware imperfections; these regions are centered at the poles (bar- and cross-state), where the probability density is at a maximum. To avoid this unfortunate coincidence, our architectures “rotate” the Riemann sphere to move the forbidden regions away from this peak, so that a larger fraction of MZIs are perfectly realized. Based on this concept, we introduce the 3-splitter MZI, which can correct arbitrary errors by rotating the forbidden regions to the equator. Using a benchmark optical neural network, we show that this modified MZI mesh is >3× more robust to hardware errors, enabling accurate inference in a regime where standard interferometric circuits struggle. Finally, we introduce the MZI+crossing, which flips the poles of the Riemann sphere. While this design is only robust against correlated errors, it has the added advantage of broader intrinsic bandwidth. For both architectures, we compare the matrix fidelity to the standard MZI to demonstrate the scaling advantage of both schemes.

## Results

### Error correction formalism

To correctly configure an MZI mesh in the presence of errors, one uses a nulling method based on physical measurements16,17. Figure 2a illustrates the case of the triangular mesh1, where the procedure is more straightforward. The transfer matrix for this system is a product of a phase screen D and a sequence of 2 × 2 unitaries W:

$$U=D\underbrace{\mathop{\prod}\limits_{mn}{T}_{mn}}_{\begin{array}{c}W\end{array}}$$
(1)

where Tmn is the nth MZI of the mth rising diagonal.

We program the mesh using a sequence of steps (Givens rotations), which build up W in order to diagonalize the “target” matrix X = UW. For every step, we add one 2 × 2 unitary to W, performing the update W → TmnW, which right-multiplies the target matrix $$X\to X{T}_{mn}^{{{{\dagger}}} }$$ (Fig. 2b). The 2 × 2 unitary Tmn is chosen to null a specific matrix element v → 0 (shaded green in Fig. 2b), which is equivalent to the equation (indices m, n suppressed for notational simplicity):

$$[u\,\,v]{T}^{{{{\dagger}}} }=[ * \,\,0]\,\,\,\iff \,\,\,\frac{{T}_{11}}{{T}_{12}}=\frac{u}{v}$$
(2)

This condition is visualized in Fig. 2c. In hardware, nulling of the (i, j) element of X is implemented by inputting the field $${w}_{j}^{*}$$ (jth column of W) and adjusting the MZI parameters (θ, ϕ) to zero the output power at the ith port. If all nulling steps are performed exactly, the mesh will perfectly realize the target matrix U (see Methods and Supplementary Section 1 for details).

Mathematically, nulling involves setting the (complex-valued) splitting ratio $$s\equiv {T}_{11}/{T}_{12}=-{({T}_{22}/{T}_{21})}^{*}$$ of the physical MZI to match the target value $$\hat{s}\equiv u/v$$ required for diagonalization. In many cases, this is not possible, because the range of admissible splitting ratios $$\tan|\alpha+\beta|\le|s|\le \cot|\alpha -\beta|$$ is restricted in the presence of hardware imperfections, namely the splitting-angle errors for the 50:50 couplers in a real MZI (α, β in Fig. 1c). Owing to these imperfections, forbidden regions emerge for small and large s where perfect nulling is impossible (Fig. 2d). It is also instructive to view this chart on the Riemann sphere, which shows that these forbidden regions are centered around the poles (Fig. 2b), highlighting the well-known fact that imperfect MZIs generally have finite extinction ratio and cannot realize a perfect cross (s = 0) or bar (s = ) state.

If in a given nulling step $$\hat{s}$$ falls within the forbidden region, nulling is imperfect, and an off-diagonal residual prevents perfect diagonalization of the matrix, leading to an “uncorrectable” error. This residual is proportional to $$d(s,\hat{s})$$, the Euclidean distance on the Riemann sphere between the target ratio and the closest realizable s. The overall error is the quadrature sum of all such residuals.

For linear photonic circuits, two important fidelity figures of merit are (1) the coverage $${{{{{{{\mathcal{C}}}}}}}}$$, i.e., the probability that a matrix is realized exactly, and (2) the normalized matrix error $${{{{{{{\mathcal{E}}}}}}}}=\langle|{{\Delta }}U{|}_{{{{{{{{\rm{rms}}}}}}}}}\rangle /\sqrt{N}$$, a scaled Frobenius norm which is approximately equal to the average relative error for a given matrix element. $${{{{{{{\mathcal{C}}}}}}}}$$ and $${{{{{{{\mathcal{E}}}}}}}}$$ depend on the error model and the distribution of target matrices. Here, consistent with prior work16,17,19,29, we sample target matrices randomly over the Haar measure30,31 and consider an uncorrelated Gaussian error model 〈αrms = 〈βrms = σ.

Analytic expressions for $${{{{{{{\mathcal{E}}}}}}}}$$ and $${{{{{{{\mathcal{C}}}}}}}}$$ are derived in the Methods, which we summarize here. If a mesh is straightforwardly programmed without taking any account of the imperfections (“uncorrected” error), the normalized error is $${{{{{{{{\mathcal{E}}}}}}}}}_{0}=\sqrt{2N}\sigma$$16,19. The coverage $${{{{{{{\mathcal{C}}}}}}}}={e}^{-{N}^{3}{\sigma }^{2}/3}$$ (Eq. (16)) decreases sufficiently fast that even moderately sized meshes have vanishingly small coverage, and error correction is generally imperfect. In this case, the residual “corrected” error $${{{{{{{{\mathcal{E}}}}}}}}}_{c}=(2/3)N{\sigma }^{2}$$ (Eq. (19)) is the more relevant metric. Since $${{{{{{{{\mathcal{E}}}}}}}}}_{c}\propto {({{{{{{{{\mathcal{E}}}}}}}}}_{0})}^{2}$$, self-configuration correction affords a quadratic suppression of errors, which is a significant advantage when errors are below a threshold. However, for sufficiently large meshes N 1/σ2, error correction will be ineffective and the mesh cannot realize most matrices at high fidelity. Thus, even with error correction, hardware imperfections set a fundamental scaling limit for standard MZI meshes.

### Asymptotically perfect photonic circuits

The main challenge limiting error correction here is that the forbidden regions overlap with the peak of the probability distribution, which clusters tightly around the cross state s = 0 (Fig. 2e)29. This clustering happens because light must propagate all the way down a mesh’s diagonals to realize generic unitaries; the forbidden regions disrupt this ballistic transport leading to clipping of off-diagonal matrix elements10. Adding redundant components (MZI doubling) solves this problem by eliminating the forbidden regions altogether23,24, but at the cost of added optical and electrical complexity. Here, we take the alternative approach of displacing the forbidden regions away from the cross state. This can be performed by placing a third splitter at the input of the MZI, as shown in Fig. 3a. The extra splitter performs a Möbius transformation $$s\to (s+i\tan \eta )/(1+is\tan \eta )$$, which for a 50:50 splitting ratio (η = π/4) maps the bar and cross states to s = ±i (Fig. 3b). This can be visualized as a 90° rotation on the Riemann sphere, which pushes the forbidden regions to the equator, while the probability density is still concentrated at the poles (small errors γ in the third splitter perturb this rotation angle slightly, but this does not change the structure of the forbidden regions and has little effect on the error correction).

This “3-splitter MZI” (3-MZI) can therefore access the complete range of splitting-ratio magnitudes s [0, ), and can thus function as a high-contrast optical switch24,32. However, forbidden regions are still present for the 3-MZI, which implies that for some configurations, the relative phase of the splitter $$\arg (s)$$ is constrained by hardware errors (unlike the MZI-doubled “perfect” couplers of refs. 23,24,25, which cure this defect with redundant phase shifters). However, from the distributions in Fig. 2e, for large meshes $$\hat{s}$$ will fall into the 3-MZI’s forbidden regions only rarely. The normalized matrix error, calculated in the Methods (Eq. (22)), takes the following form:

$${{{{{{{{\mathcal{E}}}}}}}}}_{c}\, \approx \,8{\sigma }^{2}{\left[2\frac{\log (N)-1.366}{N}\right]}^{1/2}$$
(3)

In Fig. 3c, d, we numerically simulate self-configuration on imperfect meshes using the MESHES package (see Methods and Supplementary code); the realized $${{{{{{{{\mathcal{E}}}}}}}}}_{c}$$ shows good agreement with Eq. (3). For large meshes N 64, the matrix error is approximately 1–2 orders of magnitude lower with the 3-MZI. Moreover, the 3-MZI exhibits more favorable error scaling, with the error remarkably decreasing with mesh size as $${{{{{{{{\mathcal{E}}}}}}}}}_{c}\propto \sqrt{\log (N)/N}$$. This leads to asymptotically fault-tolerant hardware error correction: in the limit N → , matrices can be programmed perfectly.

This non-intuitive effect arises from the fact that, under the Haar measure, only a small fraction of MZIs have significant probability density near s = ±i, where the forbidden regions are centered29. This probability decreases exponentially with the distance from the triangle’s base (see Methods for details). Therefore, although the mesh has N(N − 1)/2 MZIs, only O(N) contribute significantly to the matrix error under self-configuration. A naïve estimate assuming uncorrelated errors would give $$|{{\Delta }}U|\propto \sqrt{N}{\sigma }^{2}$$, which would lead to a constant $${{{{{{{{\mathcal{E}}}}}}}}}_{c}$$. However, during the self-configuration process, subsequent MZIs can partially correct for errors in earlier MZIs that cannot be properly configured; the end result is to reduce the overall error of each MZI by a factor proportional to $$\sqrt{\log (N)/N}$$ (see Methods), yielding the result Eq. (3).

A second benefit to the 3-MZI is its higher threshold for perfect error correction. One obtains this threshold by computing the coverage $${{{{{{{\mathcal{C}}}}}}}}={e}^{-16N{\sigma }^{2}}$$ (see Methods, Eq. (20)). This is much larger than the coverage of the regular MZI mesh, and the threshold scales as σthN−1/2, in contrast to the N−3/2 dependence seen for the conventional mesh. Consequently, errors are perfectly correctable under a much broader range of circumstances, as shown in Fig. 3e.

### Error-resilient optical neural networks

To highlight the significance of this error reduction, consider as a concrete example deep neural network (DNN) inference on coherent optical hardware. A DNN is a sequence of layers, consisting of linear synaptic connections and nonlinear neuron activations. An emerging application of photonics seeks to use optical interference to accelerate this process, encoding neuron activations in coherent optical amplitudes, while a programmable MZI mesh implements the synaptic weights and activations are performed with an all-optical or electo-optic nonlinearity5. Scaling remains the major challenge to constructing practical optical neural networks, as large mesh sizes (N > 100) are required to achieve a significant advantages over electronic hardware, and such large meshes are especially susceptible to fabrication errors. A recent numerical study showed that even with state-of-the-art process tolerances, hardware errors can significantly degrade DNN inference accuracy33, a difficulty that has spurred investigations into alternatives to the MZI mesh, which all have their own limitations34,35,36,37.

Figure 4a depicts a benchmark neural network. Here, 28 × 28 images from the MNIST digit dataset38 are preprocessed by a Fourier transform and cropped to a window of size $$\sqrt{N}\times \sqrt{N}$$, which forms the input to a two-layer unitary DNN. The DNN can be implemented optically with rectangular MZI meshes for synaptic weighting2 and electro-optic nonlinearities for the activation (see refs. 17,39 for details). Models with inner-layer sizes N = 64 and N = 256 are pre-trained using the NEUROPHOX package40, and inference accuracy is subsequently simulated on imperfect meshes with Gaussian splitter errors to calculate the classification accuracy.

This accuracy is plotted in Fig. 4b for three cases: straightforwardly programming an MZI mesh without error correction, with error correction, and with the modified 3-MZI architecture. Even for small device errors σ = 1–2%, which is considered state-of-the-art for directional couplers in highly controlled fabrication processes41, hardware errors significantly degrade the model’s inference accuracy relative to its canonical value (σ = 0). For small σ, this is recovered using error correction17,19. However, many broadband coupler designs42,43,44,45,46,47 trade bandwidth for fabrication sensitivity and are in practice very sensitive to process variations, meaning larger splitter errors σ 5% are common. In this moderate-error regime, error correction alone is not sufficient and the network shows reduced accuracy, a problem that becomes more pronounced as the size N increases. Moving to the 3-MZI architecture overcomes this limitation, enabling effectively error-free inference (relative to the canonical model) even out to very large splitter errors σ ≈ 10–15%, far beyond what is likely to be encountered in practice.

### Broadband mesh for correlated errors

For generic, uncorrelated component errors the 3-splitter MZI is well-suited. However, since the correlation lengths of process variations tend to be larger than a single MZI48, errors are correlated in practice. This is especially true for broadband couplers based on multimode interference (MMI)42,43, subwavelength gratings44,45, and asymmetric designs46,47, all of which are highly dependent on the device geometry, which can vary slightly from run to run. Moreover, even with perfect 50:50 couplers, the splitting ratios are still wavelength-dependent. Operating the mesh away from its design wavelength leads to correlated device errors, so sensitivity to these errors is closely tied to the operational bandwidth of the device.

Consider the case of a constant offset μ for all splitting ratios: α = β = μ. In a standard MZI, the bar-state forbidden region (around s = ) disappears since α − β = 0, while the cross-state region (around s = 0, the peak of the probability distribution) remains in place (Fig. 2). This is consistent with the common observation that the extinction ratio in an MZI is much higher in the cross port than in the bar port. The optimal error reduction strategy, illustrated in Fig. 5a, was previously proposed in the context of broadband optical switching: place a waveguide crossing before the MZI49. The added crossing performs the Möbius transformation s → 1/s, rotating the Riemann sphere by 180° to move the forbidden region to the minimum of the probability distribution (Fig. 5b, c).

As before, we can calculate the coverage and matrix error of this “MZI+crossing” (MZI+X) mesh by performing the nulling procedure on target unitaries, obtaining $${{{{{{{\mathcal{C}}}}}}}}$$ from the probabilities that splitting ratios fall within the forbidden regions, and $${{{{{{{{\mathcal{E}}}}}}}}}_{c}$$ from the residuals arising from imperfect diagonalization. In this case, there is only one forbidden region, centered at s = . The calculation is worked out in the Methods. For the normalized error, we find (Eq. (27)):

$${{{{{{{{\mathcal{E}}}}}}}}}_{c}=4{\mu }^{2}{\left[\frac{2}{3}\frac{\log (N)-0.423}{N}\right]}^{1/2}$$
(4)

This is plotted in Fig. 6. Like the 3-MZI design, this metric scales as $${{{{{{{{\mathcal{E}}}}}}}}}_{c}\propto \sqrt{\log (N)/N}{\mu }^{2}$$, in contrast to the trend $${{{{{{{{\mathcal{E}}}}}}}}}_{c}=(4/{3}^{3/2})N{\mu }^{2}$$ calculated for the standard MZI under correlated errors. The coverage also increases (Eq. (25)), so that the threshold for perfect correction likewise scales as μthN–1/2, in contrast to the μthN–3/2 dependence seen in the standard mesh.

Ultimately, the scalability of the MZI+X architecture is limited by differential errors α − β that arise from local fluctuations in waveguide dimensions. The effect of such errors is analyzed in Supplementary Section 2. For typical photonic process variations, α − βμ and differential errors are insignificant for mesh sizes up to at least N = 512.

As an added bonus, the MZI+X design also reduces the effect of errors in the absence of correction. To see how, we can make an analogy to Bloch-sphere rotations. The transfer matrix of a standard MZI is (up to a phase factor) the product of four rotations:

$$T(\theta,\, \phi )\propto {R}_{x}\left(\frac{\pi }{4}+\mu \right){R}_{z}(\theta ){R}_{x}\left(\frac{\pi }{4}+\mu \right){R}_{z}(\phi )$$
(5)

where $${R}_{k}(\eta )={e}^{i{\sigma }_{k}\eta }$$ is a Pauli rotation and σk is a Pauli matrix. For the cross state (θ = 0), the errors μ add up constructively, while for the bar state (θ = π), they cancel out (the latter is a simple example of dynamical decoupling of spins using a pulse sequence). Most crossings in large meshes are close to the cross state, which leads to constructive addition of the errors in the standard MZI mesh. However, for the MZI+X, the input ports of each MZI are exchanged, so the physical MZIs are close to the bar state where the errors cancel out. The resulting uncorrected matrix error is (see Methods):

$${{{{{\mathcal{E}}}}}}_{0}=\left\{\begin{array}{ll}2\sqrt{N}\mu \hfill &({{{{{{{\rm{MZI}}}}}}}}) \hfill \\ 2\sqrt{2(\log N - 1.423)}\mu &({{{{{{{\rm{MZI}}}}}}}}+{{{{{{{\rm{X}}}}}}}})\end{array}\right.$$
(6)

Correlated errors (both corrected and uncorrected) are important because they are tightly connected to the operational bandwidth of the mesh, a critical design parameter for machine learning schemes that require broadband operation, e.g., for parallel processing on wavelength-multiplexed data50,51,52,53. All beamsplitters are dispersive, and this dispersion leads to a correlated wavelength-dependent splitter error, which can usually be expanded to first order μ ≈ (dμ/dλλ. Two important wavelength-dependent figures of merit are (1) the tuning range, which refers to the range of λ over which the mesh can be programmed to a given accuracy, Fig. 7a, c, and (2) the bandwidth, which is related to the number of wavelength channels that can be (simultaneously) processed by the mesh, Fig. 7b, d. The tuning range is limited by the corrected error $${{{{{{{{\mathcal{E}}}}}}}}}_{c}$$, while the bandwidth is limited by the uncorrected error $${{{{{{{{\mathcal{E}}}}}}}}}_{0}$$, since a mesh cannot simultaneously error-correct at two different wavelengths. Since the MZI+X design reduces both $${{{{{{{{\mathcal{E}}}}}}}}}_{0}$$ and $${{{{{{{{\mathcal{E}}}}}}}}}_{c}$$, it leads to enhancements in both the bandwidth and tuning range. The enhancement factors scale as

$${F}_{{{{{{{{\rm{BW}}}}}}}}}\propto \sqrt{N/\log N},\,\,\,{F}_{{{{{{{{\rm{TR}}}}}}}}}\propto {({N}^{3}/\log N)}^{1/4}$$
(7)

and are listed for several mesh sizes in Table 1 (see Methods for details). As Fig. 7c, d illustrates, the MZI+X architecture enjoys a significantly larger tuning range, in addition to modestly greater bandwidth.

Real crossings have a small amount of nonzero crosstalk, quantified by the S-matrix element S21; scattering into the forward-facing port leads to a perturbation $${R}_{x}(\frac{\pi }{2})\to {R}_{x}(\frac{\pi }{2}+\gamma )$$ in the transfer matrix, where $$\gamma=1{0}^{-{S}_{21}[{{{{{{{\rm{dB}}}}}}}}]/20}$$. This does not degrade the effectiveness of self-configuration, since the additional scattering angle merely rotates the Riemann sphere Fig. 5c by an additional angle γ 1, and the forbidden region is still far from s = 0. In-plane crossings in silicon can achieve sub-40 dB crosstalk suppression (γ < 0.01) with insertion losses well below 0.1 dB54,55,56,57,58. Unlike directional couplers, crossings are inherently broadband; the insertion loss and crosstalk depend only very weakly on λ, so any crossing imperfections can be treated as (correctable) wavelength-independent errors that do not affect the bandwidth enhancements of the MZI+crossing scheme. In addition to the forward-scattered light, a 90° crossing will scatter light into the backward-facing port. Back-reflected light can be subsequently reflected in other crossings, leading to a spurious signal that interferes with the forward-propagating light. Provided that the phases of reflected beams are random, these add in quadrature: with amplitude γ2 and O(N2) scattering paths, we expect this to induce an O(Nγ2) error, which may be uncorrectable and set a limit on scaling. However, if this effect is small, gradient-based methods or iterative self-configuration may enable correction of these errors.

## Discussion

As photonic circuits grow larger, error tolerance becomes increasingly important. Many techniques exist to manage hardware errors, but all involve a tradeoff between accuracy and complexity. At opposite poles lie “zero-change” error correction, which has limited scalability16,17,19,59, and “perfect” photonic circuits, which require a larger number of photonic and electronic components23,24. This paper has introduced two designs for programmable circuits that strike a tradeoff between these extremes, as shown in Fig. 8 and Table 2, achieving performance that is almost as good as the perfect designs, but with less added complexity (see Supplementary Section 3 for details).

The main insight from this paper is that, by adding a single passive component (either a splitter or a waveguide crossing) to the MZI, we can recover behavior that is asymptotically perfect—that is, the average normalized matrix error decreases with size. Our design choices are motivated by the elegant theory of self-configuration by matrix diagonalization17, where splitting ratios are set to successively zero the off-diagonal elements of the target unitary. By visualizing the MZI state on the Riemann sphere, we can intuitively understand the increased error robustness of our designs in terms of “rotating” the forbidden regions away from the peak probability density. This leads to a several-orders-of-magnitude reduction in post-correction errors compared to the standard MZI mesh. The ability to achieve near-perfect and freely scalable MZI meshes with less complexity than the MZI-doubled designs23,24 (especially with respect to the number of active components and pads) removes a major roadblock to the realization of very-large-scale nanophotonic systems.

An interesting direction for future work is to explore to what extent multiport interferometers can be made robust to imperfections in the absence of error correction. For example, previous studies of 3-MZI splitters have noted a wavelength-independent coupling ratio for certain parameter choices32. Likewise, the near-cancellation of correlated errors in the MZI+crossing architecture explains the $$O(\sqrt{N/\log N})$$ reduction in the uncorrected error, and corresponding increase in bandwidth. Further design modifications based on the theory of composite pulse sequences60,61,62 may allow this imperfect cancellation to be made exact, further improving the bandwidth (and multiplexing capabilities) of linear photonics.

## Methods

### Unitaries and the Riemann sphere

A generic 2 × 2 complex-valued matrix has eight degrees of freedom, and a 2 × 2 unitary has four. However, the space of 2 × 2 unitaries can be divided into equivalence classes based on the splitting ratio s = T11/T12. Specifically, any two unitaries are equivalent up to output phases, i.e., $$T={{{{{{{\rm{diag}}}}}}}}({e}^{i{\psi }_{1}},{e}^{i{\psi }_{2}})\hat{T}$$, if and only if the splitting ratios are the same, $$s=\hat{s}$$. As a complex number, s can be visualized on the Riemann sphere (Fig. 2d), where the mapping is performed by the stereographic projection s = (x + iy)/(1 + z) (which inverts to x + iy = 2s/(1 + s2), z = (1 + s2)/(1 − s2)).

Ordinarily, the distance between matrices is defined as the Frobenius (L2) norm $$|{{\Delta }}U|={({\sum }_{mn}|{{\Delta }}{U}_{mn}{|}^{2})}^{1/2}$$. However, since output phases are corrected in subsequent steps, the most relevant distance metric for a 2 × 2 block is the Frobenius norm modulo these phase shifts,

$$d(T,\, \hat{T})\equiv {\min }_{\psi }\left|T-\left[\begin{array}{cc}{e}^{i{\psi }_{1}}\,&\\ &{e}^{i{\psi }_{2}}\end{array}\right]\hat{T}\right|=\frac{d(s,\, \hat{s})}{\sqrt{2}}$$
(8)

where $$d(s,\, \hat{s})=2|s-\hat{s}|/\sqrt{(|s{|}^{2}+1)(|\hat{s}{|}^{2}+1)}$$ is the Euclidean distance between two points on the Riemann sphere.

A common parameterization is $$s={e}^{i\phi }\tan (\theta /2)$$, which represents the splitting ratio of the standard MZI, Fig. 1b. On the Riemann sphere, (θ, ϕ) map to the standard polar coordinates, i.e., $$x=\sin (\theta )\cos (\phi )$$, $$y=\sin (\theta )\sin (\phi )$$, $$z=\cos (\theta )$$.

### Coverage and matrix error derivation

The nulling method relies on successive zeroing of off-diagonal elements to diagonalize the matrix X (initialized to U). Each nulling step zeros a single element, increasing the size of the zeroed-out off-diagonal region. Nulling steps are performed in a particular order to ensure that zeroed-out elements remain zero after all subsequent steps1,2,17. In a given step, if nulling cannot be achieved perfectly, the “zeroed-out” region of matrix X is left with a residual of magnitude:

$$r=|{T}_{11}v-{T}_{12}u |=\sqrt{|u{|}^{2}+|v{|}^{2}}\frac{d(s,\, \hat{s})}{2}$$
(9)

where $$\hat{s}$$ is the target splitting ratio, s is the closest physically realizable value, and $$d(s,\hat{s})$$ is the Euclidean distance on the Riemann sphere, the same metric used in Eq. (8). The coverage and matrix error depend on (1) the distribution P(s) of target splitting ratios, a function of the distribution of target unitaries, and (2) the locations and sizes of the forbidden regions, a function of the specific mesh implementation (MZI, 3-MZI, MZI+X). For the Haar measure, P(s) depends on an MZI’s location in the mesh; for a given Tmn it takes the following form29:

$${P}_{mn}(s)=\frac{n}{4\pi }{\left(\frac{z+1}{2}\right)}^{n-1}=\frac{n}{4\pi {(1+|s{|}^{2})}^{n-1}}$$
(10)

Here, the density is defined with respect to the area measure on the Riemann sphere

$$d\mu=\sin (\theta ){{{{{{{\rm{d}}}}}}}}\theta {{{{{{{\rm{d}}}}}}}}\phi=\frac{4}{(1+|s{|}^{2})}{{{{{{{{\rm{d}}}}}}}}}^{2}s$$
(11)

so that ∫Pmn(s)dμ(s) = 1. Note that, under Eq. (10), Pmn is uniform for the lowest row of crossings, and becomes increasingly concentrated as one approaches the triangle’s apex; as a result, the overall distribution is strongly biased towards the cross state for large meshes, as shown in Fig. 2e (the same distribution also holds for the rectangular mesh, up to a reordering of the MZIs).

The forbidden regions $${{{{{{{{\mathcal{F}}}}}}}}}_{\pm }$$ are centered at opposite poles of the Riemann sphere

$$({s}_{+},\,{s}_{-})=\left\{\begin{array}{ll}(0,\,\infty )\hfill\quad &({{{{{{{\rm{MZI}}}}}}}}) \hfill\\ (+i,\,-i)\hfill \quad &({{\mbox{3-MZI}}})\\ (\infty,\,0)\hfill \quad &({{\mbox{MZI+X}}})\end{array}\right.$$
(12)

and have radii R± = 2α ± β. In the case of small hardware errors, where P(s) ≈ P(s±) inside each $${{{{{{{{\mathcal{F}}}}}}}}}_{\pm }$$, the probability that $$\hat{s}$$ falls inside the region is given by $$\pi {R}_{\pm }^{2}P({s}_{\pm })$$. The coverage $${{{{{{{\mathcal{C}}}}}}}}$$ is the probability that every $$\hat{s}$$ avoids the forbidden regions, and is well approximated by

$${{{{{{{\mathcal{C}}}}}}}}=\exp \left(-\mathop{\sum}\limits_{mn}\pi ({P}_{mn}({s}_{+})\langle {R}_{+}^{2}\rangle+{P}_{mn}({s}_{-})\langle {R}_{-}^{2}\rangle )\right)$$
(13)

The normalized matrix error $${{{{{{{{\mathcal{E}}}}}}}}}_{c}=\langle|{{\Delta }}U{|}_{{{{{{{{\rm{rms}}}}}}}}}\rangle /\sqrt{N}$$ is approximately the quadrature sum of the residuals accumulated during nulling:

$${({{{{{{\mathcal{E}}}}}}}_{c})}^{2}=\frac{\langle|{{\Delta }}U{|}^{2}\rangle }{N}=\frac{2}{N}\mathop{\sum}\limits_{mn}\langle {r}_{mn}^{2}\rangle$$
(14)

Here, 〈…〉 refers to the ensemble average over both Haar-distributed target unitaries U30,31 and the distribution of hardware errors α, β. We calculate the mean residual 〈r2〉 by averaging Eq. (9) over the distribution P(s). This is simplified in the case of small hardware errors, because the forbidden region is correspondingly small and where we can assume P(s) is approximately constant:

$$\langle {r}_{mn}^{2}\rangle=\frac{\pi }{24}\underbrace{\langle|u{|}^{2}+|v{|}^{2}\rangle }_{\begin{array}{c}{q}_{mn}\end{array}}[{P}_{mn}({s}_{+}){\langle {R}_{+}\rangle }^{4}+{P}_{mn}({s}_{-}){\langle {R}_{-}\rangle }^{4}]$$
(15)

This residual depends on the quantity qmn = 〈u2 + v2〉, where (u, v) are the highlighted in green in Fig. 2b. Following the Gaussian elimination procedure of a Haar matrix, this evaluates to qmn = (n + 1)/(N + 1 − m).

A detailed description of the nulling algorithm, including a comparison to the local method19 and global optimization8,9,10 (which has a much longer convergence time), is presented in Supplementary Section 1.

### Gaussian errors: MZI and 3-MZI

For the uncorrelated Gaussian perturbation model with 〈αrms = 〈βrms = σ, the forbidden regions are (statistically) symmetric, with moments $$\langle {R}_{\pm }^{2}\rangle=8{\sigma }^{2}$$ and $$\langle {R}_{\pm }^{4}\rangle=192{\sigma }^{4}$$.

For the MZI mesh, the coverage expression Eq. (13) is dominated by the s = 0 term, where Pmn(0) = n/4π. Considering only this term, we calculate:

$${{{{{{{{\mathcal{C}}}}}}}}}_{{{{{{{{\rm{MZI}}}}}}}}}=\exp \left(-\frac{\langle {R}_{+}^{2}\rangle }{4}\mathop{\sum}\limits_{mn}n\right)\to {e}^{-{N}^{3}{\sigma }^{2}/3}$$
(16)

where we have replaced the discrete sum by an integral

$$\mathop{\sum}\limits_{mn}(\ldots )\to \int\nolimits_{0}^{N}\int\nolimits_{0}^{N-m}(\ldots ){{{{{{{\rm{d}}}}}}}}n\,{{{{{{{\rm{d}}}}}}}}m$$
(17)

which is valid in the limit of large N. Likewise, the top forbidden region dominates the matrix error, so we evaluate Eq. (15) including only the first term in the sum:

$${\langle {r}_{mn}^{2}\rangle }_{{{{{{{{\rm{MZI}}}}}}}}}\to \frac{n(n+1)}{N+1-m}\frac{\langle {R}_{+}^{4}\rangle }{96}$$
(18)

Converting the sum to an integral and substituting $$\langle {R}_{+}^{4}\rangle$$, we find:

$${({{{{{{{{\mathcal{E}}}}}}}}}_{c})}_{{{{{{{{\rm{MZI}}}}}}}}}=\sqrt{\frac{{N}^{2}}{432}\langle {R}_{+}^{4}\rangle }\to \frac{2}{3}N{\sigma }^{2}$$
(19)

Now we redo the calculation for the 3-MZI. In this case, the forbidden regions are located at s± = ± i and contribute equally to the problem. Following Eq. (13), the coverage is given by:

$${{{{{{{{\mathcal{C}}}}}}}}}_{3 - {{{{{\rm{MZI}}}}}}}=\exp \left(-2\times \mathop{\sum}\limits_{mn}\pi \langle {R}_{\pm }^{2}\rangle {P}_{mn}(\pm i)\right)\to {e}^{-16N{\sigma }^{2}}$$
(20)

Applying Eq. (15), the mean residual left by crossing Tmn is:

$$\langle {r_{mn}^{2}} \rangle_{3 - {{{{{\rm{MZI}}}}}}}=2 \times \frac{\pi}{24} \underbrace{\frac{n+1}{N+1 - m}}_{q_{mn}}\, \underbrace{\frac{n}{2^{n+1}\pi}}_{P_{mn}(\pm i)}\, \underbrace{\vphantom{\frac{n}{2^1}}(192\sigma^{4})}_{\langle R_+^{4} \rangle }$$
(21)

The factors of two in Eqs. (20)–(26) arise because both forbidden regions contribute equally. This $$\langle {r}_{mn}^{2}\rangle$$ is not slowly-varying with (m, n), so we cannot convert the sums to integrals. We first perform the summation over n, which converges rapidly due to the 1/2n+1 factor (approximating the upper bound to infinity because of the rapid convergence), followed by summation over m. We find the normalized error:

$${({{{{{{{{\mathcal{E}}}}}}}}}_{c})}_{{{{{{{{\rm{3-MZI}}}}}}}}}={\left(\frac{128{\sigma }^{4}}{N}\left[\mathop{\sum }\limits_{n=1}^{N}\frac{1}{n}-\frac{5}{4}-\log (2)\right]\right)}^{1/2}\\ \approx \; 8{\sigma }^{2}{\left[2\frac{\log (N)+{\gamma }_{e}-\frac{5}{4}-\log (2)}{N}\right]}^{1/2}$$
(22)

where the discrete sum is approximated using the relation $$\mathop{\sum }\nolimits_{n=1}^{N}{n}^{-1}\approx \log (N)+{\gamma }_{e}$$, which defines the Euler–Mascheroni constant γe ≈ 0.5772.

### Correlated errors: MZI and MZI+X

Under a correlated error model, α = β = μ. In this case, there is only one forbidden region, which for the MZI is centered at s+ = 0, with R+ = 4μ. The coverage and matrix error for the standard MZI can then be calculated from Eqs. (16) and (19) with the appropriate substitutions for $$\langle {R}_{+}^{2}\rangle$$, $$\langle {R}_{+}^{4}\rangle$$:

$${{{{{{{{\mathcal{C}}}}}}}}}_{{{{{{{{\rm{MZI}}}}}}}}}={e}^{-(2/3){N}^{3}{\mu }^{2}}$$
(23)
$${({{{{{{{{\mathcal{E}}}}}}}}}_{c})}_{{{{{{{{\rm{MZI}}}}}}}}}=(4/{3}^{3/2})N{\mu }^{2}$$
(24)

Now consider the MZI+X. The additional crossing rotates the forbidden region to s+ → . Only the MZIs in the bottom row of the triangle (n = 1) contribute to the sums in Eqs. (13) and (14), because the probability distribution Eq. (10) vanishes at s =  for the upper rows.

As before, we use the residual formula Eq. (15) to calculate the matrix error. In this case, there is only one forbidden region, centered at s+ = , with R+ = 4μ. Only the MZIs in the bottom row contribute to the sum, because the probability distribution Eq. (10) vanishes at s =  for the upper rows. The coverage is:

$${{{{{{{{\mathcal{C}}}}}}}}}_{{{{{{{{\rm{MZI+X}}}}}}}}}=\exp \left(-\mathop{\sum}\limits_{m}\pi \langle {R}_{+}^{2}\rangle {P}_{m1}(\infty )\right)\to {e}^{-4N{\mu }^{2}}$$
(25)

With the mean residual given by

$$\langle {r_{m1}^{2}} \rangle_{{{{{{\rm{MZI+X}}}}}}}=\frac{\pi}{24} \underbrace{\frac{2}{N+1-m}}_{q_{m1}} \,\underbrace{\vphantom{\frac{2}{N+1-m}} \frac{1}{4\pi}}_{P_{m1}(\infty)} \,\underbrace{\vphantom{\frac{2}{N}}(256\mu^4)}_{\langle R_+^4\rangle}$$
(26)

and $$\langle {r}_{mn}^{2}\rangle=0$$ for n > 1, the matrix error evaluates to:

$${({{{{{{{{\mathcal{E}}}}}}}}}_{c})}_{{{{{{{{\rm{MZI+X}}}}}}}}}=4{\mu }^{2}{\left[\frac{2}{3}\frac{\log (N)+{\gamma }_{e}-1}{N}\right]}^{1/2}$$
(27)

Now we consider the uncorrected matrix error. For the standard MZI mesh, this is $${{{{{{{{\mathcal{E}}}}}}}}}_{0}=2\sqrt{N}\mu$$17. Using the transfer matrix of the standard MZI

$${T}_{\alpha,\beta }(\theta,\, \phi )={R}_{x}\left(\frac{\pi }{4}\,+\,\beta \right)\left[\begin{array}{cc}{e}^{i\theta }&0\\ 0&1\end{array}\right]{R}_{x}\left(\frac{\pi }{4}\,+\,\alpha \right)\left[\begin{array}{cc}{e}^{i\phi }&0\\ 0&1\end{array}\right]$$
(28)

to first order in (α, β), the norm of the matrix error is:

$$|{{\Delta }}T{|}_{{{{{{{{\rm{MZI}}}}}}}}}^{2}=2[{\cos }^{2}(\theta /2)(\alpha+\beta )+{\sin }^{2}(\theta /2){(\alpha -\beta )}^{2}]$$
(29)

which is maximized when the MZI is in the cross state θ = 0. For the MZI+crossing (Fig. 5a), we find:

$${T}_{\alpha,\beta }^{{{{{{{{\rm{(X)}}}}}}}}}(\theta,\, \phi )= {R}_{x}\left(\frac{\pi }{4}\,+\,\beta \right)\,\left[\begin{array}{cc}{e}^{-i\theta }&0\\ 0&-1\end{array}\right]\,{R}_{x}\left(\frac{\pi }{4}\,+\,\alpha \right)\,\left[\begin{array}{cc}{e}^{-i\phi }&0\\ 0&1\end{array}\right]\,{R}_{x}\left(\frac{\pi }{2}\right)\\ ={e}^{-i(\theta+\phi )}\left[\begin{array}{cc}1&0\\ 0&-1\end{array}\right]{T}_{\alpha,-\beta }(\theta,\,\phi )$$
(30)

Up to irrelevant output phases, the effect of the crossing is to flip the relative sign of α and β, so the component errors appear anticorrelated. As a result, $$|{{\Delta }}T{|}_{{{{{{\rm{MZI+X}}}}}}}\propto \sin (\theta /2)\mu$$, which is zero for the cross state. The actual error is found by adding the ΔTmn in quadrature and averaging over the probability distribution $${P}_{mn}(\theta )=n\sin (\theta /2)\cos {(\theta /2)}^{2n-1}$$ (equivalent to Eq. (10)):

$${{{{{{{{\mathcal{E}}}}}}}}}_{0}=2\sqrt{2(\log N+{\gamma }_{e}-2)}\mu$$
(31)

For a wavelength-dependent splitter error μ ≈ (dμ/dλλ, the tuning range and bandwidth can be calculated from the expressions for $${{{{{{{{\mathcal{E}}}}}}}}}_{c}$$ (Eq. (27)) and $${{{{{{{{\mathcal{E}}}}}}}}}_{0}$$ (Eq. (31)), respectively: the tuning range is the range over which $${{{{{{{{\mathcal{E}}}}}}}}}_{c}(\lambda )\, < \,{{{{{{{{\mathcal{E}}}}}}}}}_{\max }$$, while the bandwidth is the range over which $${{{{{{{{\mathcal{E}}}}}}}}}_{0}(\lambda ) \, < \, {{{{{{{{\mathcal{E}}}}}}}}}_{\max }$$:

$${{\Delta }}{\lambda }_{{{{{{{{\rm{TR}}}}}}}}}=\frac{\sqrt{{{{{{{{{\mathcal{E}}}}}}}}}_{\max }}}{|{{{{{{{\rm{d}}}}}}}}\lambda /{{{{{{{\rm{d}}}}}}}}\mu|}\left\{\begin{array}{ll}\frac{{3}^{3/4}}{\sqrt{N}}\hfill &{{{{{({{\rm{MZI}}})}}}}}\hfill\\ \sqrt{\frac{3N}{2(\log N - 0.42)}}\quad &({{\mbox{MZI+X}}})\end{array}\right.$$
(32)
$${{\Delta }}{\lambda }_{{{{{{{{\rm{BW}}}}}}}}}=\frac{{{{{{{{{\mathcal{E}}}}}}}}}_{\max }}{|{{{{{{{\rm{d}}}}}}}}\lambda /{{{{{{{\rm{d}}}}}}}}\mu|}\left\{\begin{array}{ll}\frac{1}{\sqrt{N}}\hfill &{{{{{({{\rm{MZI}}})}}}}}\hfill\\ \frac{1}{\sqrt{2(\log N - 1.42)}}\quad &({{\mbox{MZI+X}}})\end{array}\right.$$
(33)

From these expressions, we derive the enhancement factors reported in Eqs. (7) and Table 1.

### Neural network model

The optical neural network model is based on the architecture described in ref. 11. Input images are first Fourier transformed, and cropped to a $$\sqrt{N}\times \sqrt{N}$$ window, where N is the DNN’s inner layer size. The signal from this window (N input neurons) passes through two optical layers, with unitary connectivity realized with rectangular meshes. The activation function at the inner layer is realized electro-optically: a fraction of each output field is tapped off and sent to a detector, whose photocurrent modulates the remaining output light28,39, implementing the activation function:

$$f(E)=\sqrt{1-\alpha }\,{e}^{-i(g|E{|}^{2}+\phi -\pi )/2}\cos \left(\frac{1}{2}(g|E{|}^{2}+\phi )\right)$$
(34)

where α is the power tap fraction, g is the modulator response, and ϕ is the phase at zero power. Here, we choose α = 0.1, g = π/20, and ϕ = π, so that f(E) approximates a leaky ReLU in the right power regime. Models of sizes N = 64 and N = 256 were trained using the NEUROPHOX package40.

### Simulations and data analysis

All simulations were performed using the MESHES package, an open-source simulator for feedforward photonic circuits that can account for hardware imperfections63. Figures 3, 4, 6, and 7 plot multiple instances (usually ≥100) per point; dots show medians while shaded regions show the interquartile range. Source code to produce the plots for this manuscript is provided in the Supplementary material.