Inverse-design of high-dimensional quantum optical circuits in a complex medium

Programmable optical circuits form a key part of quantum technologies today, ranging from transceivers for quantum communication to integrated photonic chips for quantum information processing. As the size of such circuits is increased, maintaining precise control over every individual component becomes challenging, leading to a reduction in the quality of the operations performed. In parallel, minor imperfections in circuit fabrication are amplified in this regime, dramatically inhibiting their performance. Here we show how embedding an optical circuit in the higher-dimensional space of a large, ambient mode-mixer using inverse-design techniques allows us to forgo control over each individual circuit element, while retaining a high degree of programmability over the circuit. Using this approach, we implement high-dimensional linear optical circuits within a complex scattering medium consisting of a commercial multi-mode fibre placed between two controllable phase planes. We employ these circuits to manipulate high-dimensional spatial-mode entanglement in up to seven dimensions, demonstrating their application as fully programmable quantum gates. Furthermore, we show how their programmability allows us to turn the multi-mode fibre itself into a generalised multi-outcome measurement device, allowing us to both transport and certify entanglement within the transmission channel. Finally, we discuss the scalability of our approach, numerically showing how a high circuit fidelity can be achieved with a low circuit depth by harnessing the resource of a high-dimensional mode-mixer. Our work serves as an alternative yet powerful approach for realising precise control over high-dimensional quantum states of light, with clear applications in next-generation quantum communication and computing technologies.

A programmable optical circuit is an essential element for applications in fields as diverse as sensing, communication, neuromorphic computing, artificial intelligence, and quantum information processing [1][2][3].The production of large, reprogrammable circuits is of paramount importance for coherently processing information encoded in light.However, there remain many challenges associated with the design, manufacture, and control of such circuits, which normally require a sophisticated mesh of interferometers constructed with bulk or integrated optics [2,4].Conventional construction of these circuits exploits universal programmability on two-dimensional unitary spaces to construct arbitrary high-dimensional unitary transformations [5][6][7][8], herein referred to as the "bottom-up" technique (Fig. 1a).Over the past two decades, the technological development of integrated programmable circuits has enabled universal programmability in up to 20 path-encoded modes, containing a few hundreds of optical components on the same chip [9][10][11][12].
Imperfections in optical circuits such as scattering loss, unbalanced mode-mixing, and undesired cross-talk between modes are problematic as they reduce the accuracy and success probability of the implemented circuit [13][14][15][16][17].These issues become increasingly challenging in large dimensions, as the number of optical elements grows quadratically with the size of the circuit [2,4].Such imperfections can be addressed to some extent by increasing the depth of the circuit through the introduction of additional phase shifters and beamsplitters [13-15, 18, 19].However, these additional components necessitate additional control, further increasing the demands associated with circuit complexity.
In this work, we present an alternative solution where the optical circuit is embedded in a higher-dimensional space of a large ambient mode-mixer such as a random scattering medium, placed between reprogrammable phase planes (Fig. 1b).This "top-down" approach harnesses the complicated scattering process within a large mode-mixer to forgo control over each individual circuit element.Instead, an inverse-design approach is used that employs algorithmic techniques to program an optical circuit with a desired functionality within the random scattering medium [20,21].Similar approaches based on inverse-design have been used in multi-plane light converters (MPLC) for spatial-mode manipulation [22][23][24], where free-space propagation is commonly used in place of a random scattering medium (Fig. 1c).Furthermore, inverse-design techniques have also enabled a variety of optical circuits tailored towards specific functionalities, ranging from designs of on-chip photonic devices [25] to arrangements of bulk optical elements for fundamental quantum experiments [26][27][28][29].
The capability to manipulate quantum states of light using large-scale programmable circuits promises a myriad of applications in quantum information science, ranging from the demonstration of computational advantage [30] to the realisation of quantum networks [31].In this regard, high-dimensional quantum systems offer significant advantages in terms of increased information capacity and noise-resistance in quantum commu-    1: Design of programmable optical circuits: A general linear transformation T can be implemented via (a) the conventional "bottom-up" approach, where the circuit is constructed from units consisting of beamsplitters (BS) and phase shifters (P), or (b) the herein proposed "top-down" approach, where a target d-dimensional linear circuit is embedded within a large ambient mode-mixer with dimension n > d, where n − d auxiliary modes serve as an additional resource.The technique harnesses random unitaries Uj (such as a complex scattering system) interspersed with controllable phase planes Pj implemented via spatial light modulators (SLMs), which provide programmability over the target circuit.A similar approach is used in (c) multi-plane light converters, where the random unitaries are replaced with free-space propagation F .nication [32][33][34][35], reducing multi-qubit circuit complexity [36], while also enabling more practical tests of quantum nonlocality [37,38].While methods for the transport [39,40] and certification [41][42][43] of high-dimensional entanglement have seen rapid progress over the past few years, scalable techniques for its precise manipulation and measurement are still lacking.As an alternative to the bottom-up approach normally implemented on integrated platforms [10], inverse-design techniques have been used for realising quantum gates in dimensions up to d = 4 using bulk optical interferometers [44,45] and in d = 5 with multi-plane light conversion [46,47].In parallel, recent advances in control over light scattering in complex media [48,49] have enabled linear optical circuits for classical light [50,51] and demonstrations of programmable two-photon quantum interference [52][53][54], showing their clear potential to serve as a highdimensional quantum photonics platform.
In this article, we harness light scattering through an off-the-shelf multi-mode fibre to program generalised quantum circuits for transverse spatial photonic modes in dimensions up to seven.We apply these circuits for the manipulation of high-dimensional entangled states of light in multiple spatial-mode bases, demonstrating highdimensional Pauli-Z and X gates, discrete Fourier transforms, and random unitaries in the macro-pixel and OAM spatial-mode bases [43,55].Furthermore, in contrast with single-outcome projective measurements that are inherently inefficient [56], our technique realises generalised transformations to a spatially localised "pixel" basis, effectively turning the channel itself into a generalised multi-outcome measurement device.By harnessing this functionality, we show how the on-demand programmability of our gates enables us to both transport and certify entanglement within the same complex medium.Such multi-outcome measurements can be easily integrated with next-generation single-photon-detector arrays [57] and provide a key functionality in many quantum information applications, such as allowing one to overcome fair-sampling assumptions [58].

I. Top-Down Programmable Circuits
An optical circuit is described by a linear transformation T that maps a set of input optical modes onto a set of output modes [59,60].The linear circuit T of dimension d is built from a cascade of optical mode mixers, U , and phase shifters, P .A deterministic construction can be based on a cascade of reconfigurable Mach-Zehnder interferometers, wherein U j represents the embedded balanced two-mode mixer, i.e. a 50:50 beam splitter, and the P j are phase shifters (Fig. 1a) [5,7].As an alternative to this deterministic bottom-up construction, the top-down design presented here relies on the capability to harness large, complex, inter-modal mode mixers U j of dimension n (U j ∈ U(n)) and reconfigurable phase planes P j = diag(e iθ ) to construct a programmable target circuit T of a smaller size (d ⩽ n) embedded within the larger mode-mixers (Fig. 1b).The decomposition of such a top-down programmable circuit is represented as where L is the depth of the circuit (the number of layers), and the target circuit T is embedded in the total transfer matrix of the system T. Optimal choices for the large mode-mixer dimension (n) and the circuit depth (L) for a  given target circuit dimension (d) are discussed in Section III.
We experimentally construct the programmable optical circuit with a 2-metre-long graded-index multi-mode fibre (MMF) positioned between two programmable phase planes, P 1 and P 2 , implemented on spatial light modulators (SLMs) as depicted in Fig. 2a.The MMF serves as a large, complex mode-mixer with dimension n ≈ 200 that provides complicated inter-modal coupling [61][62][63], while the SLMs provide programmability over the circuit to be implemented.The circuit can be decomposed as T = U 2 P 2 U 1 P 1 , where U 1 represents the transfer matrix of the optical system consisting of the MMF and the associated coupling optics and U 2 is the 2f lens system.To construct the circuit, we begin by characterising U 1 in a referenceless manner via our developed technique [64].Random phase patterns are displayed on the planes P 1 and P 2 and the resulting intensity speckle images are measured at the output.The data set is then used to optimise the machine learning model that describes the optical system of our experiment using a gradient descent method, which takes ∼ 1 minute to be calculated on a GPU.Once we have complete knowledge of the mode-mixer U 1 , a given target circuit is then programmed using a solution of phase patterns obtained from the wavefront-matching (WFM) algorithm [25,65,66].The WFM algorithm is an inversedesign technique that calculates the reconfigurable phase planes by iterating through each of them in order to maximise the overlap between a set of input fields with the desired output ones, and repeating this procedure several times [64].The process of finding the optimal phase patterns takes a few seconds for a 2-dimensional circuit to ∼ 1 minute for a 7-dimensional circuit.For further details on transfer matrix acquisition or circuit construction, please refer to Methods.
Using the WFM algorithm, we implement a variety of different target circuits T on our system including the identity-I, high-dimensional analogues of Pauli-Z and X, Fourier-F, and random unitaries-R in dimensions d = {2, 3, 5, 7} for two different input transverse spatial mode bases (macro-pixel [43] and orbital-angular-momentum [55]).Our circuits perform generalised basis transformations to a localised output "pixel" basis with a maximum theoretical efficiency of unity (see Section III), enabling multi-outcome measurements in any given basis.The target output modes are randomly selected from the set of all possible foci at the output of the circuit.As an example of this, Fig. 2b shows intensity images demonstrating the operation of the Fourier F circuit in d = {2, 3, 5}.This circuit simultaneously transforms the first mutually unbiased basis (µ = 1) of input macropixel modes (indistinguishable by their amplitude) into a basis of spatially localised output modes that can be detected on a camera or suitable single-photon detector array.This can be compared with conventional singleoutcome projective measurements Πµ a shown in Fig. 2a (Alice), which project a photon in a particular mode a in basis µ via the combination of a holographic spatial light modulator (SLM 3 ) and single mode fibre [56,67].Such measurements require one to perform d projections to realise a complete measurement, giving them a maximum effective efficiency of 1/d, which is normally even lower due to device loss.We characterise our circuits by preparing a tomographically complete set of classical input modes and performing quantum process tomography (QPT, see Methods), allowing us to calculate their purity and fidelity to an ideal circuit.As a representative example, the Fourier-F circuit achieves fidelities of F = {96.9%,90.5%, 89.3%, 81.4%} in macro-pixel dimensions d = {2, 3, 5, 7} (see Supplementary Information for extended results).

II. Applications of Quantum Gates
We utilise our programmable circuits to manipulate and certify spatially entangled two-photon states in a range of dimensions, d = {2, 3, 5, 7}.As shown in Fig. 2a, the two photons are generated via the process of spon-taneous parametric down-conversion (SPDC) and sent to two parties, Alice and Bob.Bob's photon is locally manipulated by the programmable circuit T, while Alice's photon is detected via single-outcome projective measurements Πµ a .While we have verified the operation of our circuits T with classical light, it is important to repeat this process with our entangled source due to slight differences between their spectral/spatial modes and experimental alignment.Here, instead of using standard quantum process tomography (QPT), we use the lesser-known method of ancilla-assisted quantum process tomography (AA-QPT) [39,68].AA-QPT uses a single, well-characterised, and sufficiently strongly correlated state supported on an extended Hilbert space, along with a tomographically complete measurement, to fully characterise a process.This exploits channel-state duality, in which a channel, acting only on one photon from an ideal maximally entangled biphoton state, is fully characterised by the resultant output state, called the Choi state.In the case of non-ideal input states, the Choi state of the channel can still be recovered [69].For more details on QST and AA-QPT, please see Methods.
We first characterise the input state in each dimension using quantum state tomography (QST).We then use these states to recover the Choi states of the processes corresponding to the programmed circuits via AA-QPT.We also perform QST of the output states after operation by the circuits, directly enabling certification of properties contingent on both the input state and process, such as their entanglement and purity.Once the input states, output states, and Choi states of the processes are characterised, one can verify and quantify their performance via their fidelity to the ideal states (as defined in Methods).In this manner, our process fidelities quantify how close to ideal our circuits are, taking into account the nonmaximally entangled nature of the input entangled state, whilst our output state fidelities allow independent verification that they preserve high-dimensional entanglement.To quantify the effect of measurement imperfections on our tomographic procedures, we perform an independent characterisation of the measurement apparatus, as well as a Monte-Carlo sampling of these imperfections in QST and AA-QPT (See Supplementary Information) to arrive at realistic error bounds on these fidelities.
To showcase the versatility of our platform, we program 296 instances of all gates, sampling from different output foci in different dimensions and input bases.Fig. 3 (top row) shows examples of normalised twophoton coincidence count data in all mutually unbiased bases (MUBs) for five-dimensional I, Z, X, F, and R gates programmed for the macro-pixel basis.Fig. 3 (bottom row) shows the density matrices of the Choi states reconstructed from these data, presenting a clear agreement with the theoretical prediction (insets).The fidelity of the processes, quantified through the fidelity of the experimental Choi states to the ideal Choi states is reported in Table I for all dimensions in the macro-pixel basis.The fidelity of the output biphoton states to an  via projective measurements at Alice and Bob.Due to state-channel duality, measurements on the input and output twophoton states can be used to perform ancilla-assisted process tomography of the gates themselves [39,68].The fidelities of the reconstructed Choi states are reported in Table I.The Identity and Fourier gates enable our circuit to be used as a multioutcome measurement device in MUBs µ ∈ {0, 1} (red squares), allowing us to certify five-dimensional entanglement using the channel itself as a measurement device (see main text for details).The density matrix legend captures both the amplitude (brightness, normalised for clarity) and phase (colour).
ideal transformed state, their purity, and certified entanglement dimensionality are presented in the Supplementary Information, along with an estimation of the systematic errors arising from the measurement apparatus.
It is noteworthy that all output states are seen to preserve high-dimensional entanglement after operation by the gates.For instance, the output state after the identity gate I has a fidelity of F(ρ o , |Φ + ⟩⟨Φ + |) = 85.3±0.7% to the maximally entangled state, which exceeds the bound of 80% necessary to certify five-dimensional entanglement (the fidelity of any state ρ to a maximally entangled target state F (ρ, |Φ + ⟩⟨Φ + |) > k/d implies an entanglement dimensionality of at least k + 1 [41]).Results for gates implemented in the OAM basis are also presented in the Supplementary Information.
While we have verified that these gates are able to manipulate and preserve high-dimensional entanglement, we now demonstrate how they can be used for the certification of high-dimensional entanglement.Our programmable circuit functions as a generalised multioutcome measurement device, allowing measurements to be made both in the pixel basis µ = 0 (via the identity gate I), as well as its first mutually unbiased basis (MUB) µ = 1 (via the Fourier gate F) with an appropriate single-photon detector array.The coincidence counts data corresponding to a two-basis measurement obtained by programming the circuit in this manner are highlighted in Fig. 3 (red squares).However, as can be seen in Table I, our gates are not perfect.Recent work has shown how even slight imperfections in a measurement can compromise entanglement witnesses that normally assume perfect measurements [70].Thus, it becomes necessary to take these imperfections into account when investigating the detection of entanglement.As described in the Methods, we employ a computational approach using semidefinite programming to show that our experimentally measured data can only be reproduced by a quantum model that relies on five-dimensional entanglement.Our method takes reasonable statistical and systematic errors into account and yields a quantitative certificate of the entanglement dimension that is also robust to noise.In this manner, we demonstrate how the multi-mode optical fibre can be used to both transport as well as certify high-dimensional entanglement.It is important to note that in general, the programmability of our circuit allows for measurements in multiple or even "tilted" MUBs [41] corresponding to a non-maximally entangled target state, which would lead to increased fidelities and robustness to noise.
The coincidence image in Fig. 2 (inset) also provides information about scattering loss outside the output modes of interest.This allows us to measure the success probability of the gate operation, which is defined as the ratio of coincidence counts in the target output modes over the total coincidence counts integrated over all outputs in one polarisation channel.We perform this measurement on three randomly chosen implementations of the F gate in 2, 3, and 5 dimensions and measure a success probability of 0.36 ± 0.01, 0.27 ± 0.03, and 0.18 ± 0.04 respectively (see Methods for additional details).It is worth noting that for this proof-of-concept demonstration, we only control a single polarisation channel of the multi-mode fibre, thus reducing the success probability by about half.Controlling both polarisation channels of the multi-mode fibre can increase the success probability by almost a factor of two as well as improve the fidelity of the implemented circuits.Errors in the fidelities are calculated by taking into account photon counting statistics as well as systematic errors due to misalignments.A detailed analysis of misalignments in the measurement apparatus and their effect on the reported fidelities [71] for both QST and AA-QPT is presented in the Supplementary Information.

III. Programmability and Scalability
We have successfully demonstrated the ability to perform various gates in multiple spatial-mode bases in dimensions 2, 3, 5, and 7.However, as the dimension of the target gate increases, maintaining high fidelities and success probabilities becomes increasingly challenging.It is thus imperative to examine the programmability and scalablility of our design and address ways to improve its performance and target practical experimental regimes to work in.We investigate these numerically by simulating a circuit based on Eq. 1 and varying three major design parameters-the dimension of the mode mixers, n, the dimension of the target gate, d, and the depth of the circuit, L. Multiple implementations of the I, X, Z, F, and R gates are simulated for specific values of the design parameters by changing the random-unitary mode mixers and the sets of input and output modes for each instance.For each gate, we calculate the fidelity with respect to the ideal target gate and the success probability.
The key design considerations we address are: what dimension of mode mixers (n) should be chosen?And how many layers (L) is it practical to use, given the optical losses usually present at interfaces, and the experimental overhead involved?Figs.4a-d

depict simulation results
showing how the fidelity and success probability of the top-down design (n > d) scale as a function of either the dimension of mode mixers (n) or the depth of circuit (L), while keeping other design parameters constant.The first observation is that increasing the size of the mode mixers (n) increases the circuit fidelity (Fig. 4a).This demonstrates that even when implementing practical low depth circuits, such as we have presented here, high fidelities can be reached, with high-dimensional mode mixers serving as a key resource for this behaviour.Furthermore, for d/n < 0.1 the success probability is approximately constant with n (Fig. 4b), allowing high-dimensional mode mixers to be employed without affecting the success probability.
Alongside this, we observe that increasing the depth of the circuit (L) increases both fidelity and success probability (Figs.4c-d), generalising recent results into the n > d regime [72,73].In practise, however, scaling up the circuit depth introduces experimental overheads in the form of propagation and interface losses and accumulation of errors.In general, we observe that the fidelity increases and converges to unity (Fig. 4e for d/n < 0.1) when the total number of reconfigurable elements nL exceeds the requirement for parameterising a d-dimensional unitary transform O(d 2 ), thereby showing a high level of programmability of the top-down design.Furthermore, the convergence of the success probability to unity occurs when the circuit depth is approximately twice the circuit dimension (L ≈ 2d).This is because there are d(n − d) amplitudes in the transformation which correspond to scattering to modes outside of the target output modes.To achieve unit success probability these must all vanish, requiring at least these many controllable parameters.The top-down approach thus presents a powerful route towards realising high-fidelity circuits by harnessing the resource of a high-dimensional mode-mixing space (n > d), while operating in a practical, low circuit depth regime (L ⩽ O(d)).Full details of these simulations are presented in the Supplementary Information.

IV. Discussion
We have demonstrated that programmable optical circuits in the transverse-spatial domain can be reliably implemented using the top-down approach that incorporates complex scattering processes between reconfigurable phase planes.We verified that these gates preserve quantum coherence by certifying that high-dimensional entanglement persists after gate operations.We also demonstrate how our gates function as a generalised multi-outcome measurement device, enabling the MMF channel to both transport, manipulate, and certify highdimensional entanglement.While our numerical simulations demonstrate the scalability of our technique, finding practical physical platforms for its implementation remains an open challenge.Fundamental aspects of circuit design also present important questions, such as proving  that the technique can be used for the universal implementation of unitary transformations, deterministic calculations for setting phase shifters, and optimising these circuits for better performance.
Beyond the transverse spatial degree-of-freedom, our methods readily generalise to other platforms where phase shifters and mode-mixers can be realised.For instance, implementations of top-down designs in integrated optics will be forthcoming as random-mixed waveguides develop and low-loss reconfigurable phase shifters become available [74][75][76].Further developments must also address practical issues including modal dispersion and spatio-temporal mixing that are present in long multi-mode fibres and thick scattering media.These obstacles, however, also enable the extension of the top-down circuit design into the spectral-temporal domain [77][78][79][80][81][82].By demonstrating the practical realisation of high-dimensional programmable optical circuits-within the transmission channel itself-our work overcomes a significant hurdle facing the adoption of high-dimensional encoding in quantum communication systems, and paves the way for practical implementations of programmable optical circuits in various near-term photonic and quantum technologies including sensing and computation.

Experimental Details
A continuous-wave grating-stabilised laser (Toptica DL Pro HP) at 405 nm is used to pump a periodically poled Pottasium Titanyl Phosphate (ppKTP) crystal (1 mm × 2 mm × 15 mm) at 125 mW to generate a pair of orthogonally polarised photons at 810 nm entangled in their transverse position-momentum degree-offreedom (DoF) through the process of Type-II spontaneous parametric down conversion (SPDC).A telescope system of lenses is used to shape the pump beam and focus it on the crystal with a 1/e 2 beam diameter of 1.2 mm.Phase-matching conditions are achieved via temperaturetuning the crystal in a custom-built oven that keeps it at 38 ○ C. For more details on the high-dimensional entanglement source, please see the Supplementary Information.
After the crystal, the pump is filtered out using a dichroic mirror and a band-pass filter (F), while the pair of produced photons are separated by a polarising beam splitter (PBS).The reflected photon (corresponding to Alice) has its polarisation rotated from vertical to horizontal with a half-wave plate (HWP) and made incident on a phase-only SLM (SLM 3 , Hamamatsu X10468-02, effective area size of 15.8 × 12 mm, pixel pitch of 20 µm, resolution of 792 × 600, reflection efficiency of approximately 90 %, and diffraction efficiency of approximately 75 %) that is placed in the Fourier plane of the crystal using a 400 mm lens.The transmitted photon (corresponding to Bob) is sent to a top-down programmable circuit constructed from a 2 m graded-index multimode fibre (MMF, Thorlabs M116L02) placed between two programmable phase-only spatial light modulators (SLM 1,2 ).After reflection from the SLMs, a telescope system and an aspheric lens are used for modematching the photons to either single-mode fibre (SMF) or MMF collection modes.
Local projective measurements of the transverse spatial photonic modes are made with computer-generated holograms (CGH) displayed by the parallel-aligned liquid-crystal-on-silicon (LCOS) layer of the SLMs.The CGH for a particular spatial mode is displayed on the SLM at each party.If the incident spatial mode is the complex conjugate of the target mode displayed on the hologram, it is converted into a Gaussian mode, which couples efficiently into an SMF positioned in the far-field of the first-order diffraction spot.The SMFs guide the filtered photons to superconducting nanowire single-photon detectors (Quantum Opus, Opus One, efficiency >90% at 810 nm).Coincidence events between the detection of signal and idler photons in the selected modes are registered by a coincidence counting logic (Swabian Time Tagger Ultra) within a coincidence window of 0.2 ns.

Acquisition of transfer matrix
The optical apparatus used for constructing our circuits is described by the transfer matrix (TM): T = U 2 P 2 U 1 P 1 , where U 2 is a 2f lens system and P j is the j-th phase plane displayed on SLM j .In order to construct the circuits, we need to know the transfer matrix U 1 of the 2 m-long graded-index multi-mode fiber (Thorlabs-M116L02, core diameter = 50.0± 2.5 µm, NA = 0.200 ± 0.015).This is measured using the recently developed multi-plane neural network (MPNN) technique [64], which uses random phase patterns displayed at both ends of the MMF to acquire the fibre TM without using an external reference field.In contrast with the main experiment, here we use a superluminiscent diode along with a 810±1.5nmfilter (Semrock LL01-810-12.5)for TM characterisation.The number of spatial modes (n) of a graded-index fiber at wavelength λ in both polarisations depends on its V -number as V = 2πaNA/λ, which is a function of the core radius (a) and numerical aperture (NA).We search for the transfer matrix U 1 by optimising The optimisation is based on the gradient descent method fitting the acquired characterisation data consisting of random phase patterns on each plane (P 1 k , P 2 k ) displayed on SLM 1 and SLM 2 and the corresponding measured output speckle intensity images {I k } k [64].The model of the optical apparatus is implemented in Keras using Tensorflow2 and complex-number layers developed in [84].The dataset is prepared in three parts.First, each input mode in a given basis that is supported by the fiber is displayed on SLM 1 .This data provides accurate information of |U 1 |.In the second part, random superpositions of these input modes are prepared on SLM 1 and sent through the fibre.The output intensity speckles in this part allow for the recovery of the relative phase and amplitude of the transmission coefficient corresponding to a particular output mode.Finally, both SLMs are used for displaying random superpositions of the input and output modes.This final part of the dataset allows for accurate reconstruction of U 1 , including calibration of the unknown relative phases across the output modes.Note that U 1 includes the associated coupling optics between the first and second phase planes and our measurement is limited to one polarisation channel of the MMF.The entire measurement takes ∼ 90 minutes, primarily limited by the SLM refresh rate and hologram calculation time, which together take up 90% of the total measurement time.The optimization time is ∼ 1 minute performed on a GPU (GeForce RTX 3060, CPU Intel Core i7-8700, RAM 16 GB).

Construction of linear circuits
Primarily, programming a circuit T is achieved by calculating the phase solutions {P j } L j=1 at each phase plane.The wavefront matching algorithm (WFM) can do so by iteratively matching the wavefronts of target input and output optical modes propagating through the device across all phase planes [25,65,66].First, input arguments that contain a set of input spatial modes {| ψ a (q) ⟩} d−1 a=0 labelled in the logical basis by {| a ⟩ in } d−1 a=0 , a corresponding set of output spatial modes {| ϕ a (q) ⟩} d−1 a=0 that is related to the inputs via | a out ⟩ = T | a in ⟩, and a set of transfer functions {U j } between phase planes are provided to the WFM algorithm.
For each i-th iteration, a phase solution at the p-th plane is updated in a cyclic manner starting from the first to the last L-th plane and then back from the last plane to the first.At a particular reconfigurable phase plane P p , the transfer matrix of the optical device T represented in the spatial q basis is decomposed into two sections: where B p = ∏ L j=p P j+1 U j and F p = ∏ p−1 j=1 U j P j such that the forward-propagating input mode onto the p-th phase plane is represented by | ψ a,(p) ⟩ = F p | ψ a ⟩ and the backward-propagating output mode onto the p-th phase plane is The phase mismatch between these input and output modes can then be adjusted by P p : Considering all d-target modes of interest, the matching matrix: tures the mode mixing at each phase plane.The WFM algorithm maximise Tr (M p ) by calculating a phase solution P

[i]
p from the weighed average of overlapped fields over all d-target modes as follows: where ⊙ is an element-wise multiplication on the q coordinate (SLM pixels) and ϕ [latest] a,(p) (q) and ψ * [latest] a,(p) (q) is the latest update of output and input optical fields at the p-th phase plane taking into account all other previous updated phase planes {P [i] p } in the current iteration in both forward and backward directions.The algorithm is iterated until an appropriate value of gate fidelity (Eq.12) is achieved or saturated.
In our experiment, the following gates are implemented and defined as: where is the random unitary which is sampled from the Haar measure for each implementation.
Quantum state tomography (QST) The characterisation of the entangled state both before and after manipulation by the circuits is performed via quantum state tomography (QST).QST is implemented via an informationally complete set of measurements and numeric inversion of the data, subject to physical constraints.Our projective measurements are related to the ideal measurements by incorporating the detection efficiency η µ a of measuring a particular spatial mode, | ψ µ a ⟩ (corresponding to the a-th element of the µ-th basis).This is estimated through knowledge of the CGH and its effect on an incoming spatial mode.The resulting projective measurements are given by Πµ a = η µ a Πµ a , where Πµ a = |ψ µ a ⟩⟨ψ µ a | is the ideal projector.We perform QST via semidefinite programming (SDP) on both input and output states after manipulation by the optical circuits.The SDP imposes data fitting of the non-normalised measurements subject to positive semidefinitness of the state ρ, and unit trace, and reads as where C µν ab is the frequency of the outcome (coincidence count rate) and R is the count rate per integration window.Our local measurement bases are complete sets of mutually unbiased bases (MUBs) [85], which are informationally complete for QST [86], and constructed as : | m ⟩ on the basis of each implemented circuit, and ω d = exp(2πi/d) is a d-th root of unity.All SDPs are implemented in CVX, running the commercial solver MOSEK.In the experiments, the holograms corresponding to the local measurements made by Bob are displayed on SLM 1 in case of the QST of initial state, whereas in case of the QST of output state, the corresponding holograms are displayed on SLM 2 .For all cases, holograms corresponding to projections made by Alice are displayed on SLM 3 .
Quantum process tomography (QPT and ancilla-assisted QPT) A single, well-characterised, and sufficiently strongly correlated state supported on an extended Hilbert space, along with a tomographically complete measurement, can also achieve quantum process tomography.This process is known as ancilla-assisted quantum process tomography (AA-QPT) [39,68].On average, our initial state is close but not exactly equal to a maximally entangled state (Extended Data Fig. 1).In order to determine the underlying quantum process we must invert the dependence on the initial state to recover the Choi state of the channel, i.e., an optical circuit.The initial state can be written as a linear operation, A, acting only on party A of a maximally entangled state ρ + , The output state we tomograph depends on both the initial state and the channel, ξ, which acts on party B. The channel and the operator generating the initial state thus commute, so the output state can be written as the linear operator, A (from Eqs. 8 above) acting on the Choi state [68,69], Providing A is invertible, this linear equation can be inverted to recover the Choi state, ρ ξ .The channel's Choi state can be recovered by operating the inverse, (A ⊗ I) −1 , on the output state, however, the resultant Choi state may not correspond to a physical channel.In practise, the channels we program are necessarily completely positive, requiring that the Choi state is positive semi-definite, ρ ξ ≥ 0.
If our transformations were lossless, the channel would also be trace-preserving and the Choi state would obey Tr B [ρ ξ ] = I.However, in our case of non-trace preserving channels, we characterise the normalised Choi state, Tr[ρ ξ ] = 1.
In order to impose positivity of the recovered Choi state in ancilla-assisted quantum process tomography, the semi-definite program is optimised directly over pos- The fidelity of such a non-trace preserving process then corresponds to that of the process, excluding explicit dependence on global loss [87].
Alternatively, quantum process tomography (QPT) can be achieved by preparing and inputting a set of tomographically complete input states into a given process and performing measurements on the output states.This prepare and measure QPT can be accommodated in the same formalism by noting that measurement of a perfect maximally entangled input state is equivalent, up-to-normalisation, to state preparation.This allows classical characterisation of our gates via the same SDP Eqs. 10.

Fidelity, success probability, and optical losses
We use two figures of merit to characterise the implemented circuits-fidelity F and success probability S. The first is the Uhlmann-Josza fidelity between two density matrices: where ρ 0 and ρ can refer to the experimentally recovered normalised but non-trace preserving Choi state, ρξ * , and the ideal target Choi state, ρ ξ = (I ⊗ T)ρ + (I ⊗ T † ).The fidelity thus implies an accuracy of the implemented circuits.Note that, in the case when the experimental and target Choi states are pure (P ∶= Tr (ρ 2 ) = 1), the implemented circuit can be represented by a rank-one Kraus operator T, and the fidelity reduces to: which is normalised by the transmittance due to the scattering from the d-dimensional space of a circuit into other optical modes.The transmittance is quantified by the second figure of merit, the success probability, S, of an implemented circuit:

S ∶=
Tr ( T † T) The implemented d-dimensional circuit T is embedded in T which lives in the n-dimensional space of the apparatus such that: T = P o TP i , where P o is the output dimensional reduction and P i is the input dimensional expansion, which map the circuit from d inputs of interest to n inputs of the optical device and from n outputs of the optical device to the d output modes of circuit, respectively.We aim to use S to measure the scattering loss which stems from the effect of the top-down circuit design, whereas another optical loss of the apparatus is analysed in the last part of this section.Experimentally, the success probability S (Eq.13) is estimated on the output x space as S = where tab is a transmission coefficient given that T = ∑ Noting that the optical flux I ab can be moved outside the bracket because the target outputs are foci which are spatially separated and conveniently detected using a coherent light source.For a two-photon entangled state, the success probability is then calculated in a similar way using the outcomes of joint measurements between Alice and Bob, the latter of whom performs the measurements Π(x) ∶= η(x) | x ⟩ ⟨ x | across the output spatial x space: where the coincidence counts (C µ,ν=0 ab and C µ a (x)) are calibrated by the detection efficiencies for both parties and C µ a (x) is defined as Note that since we perform the experiment in all input spatial mode bases, the success probability is averaged over all input bases, S = ∑ d µ=0 S µ /(d + 1).Moreover, one can show that Eq. 15 can be reformulated back to Eq. 13 in the case that the input maximally entangled state and process (circuit) are pure.
Finally, the overall transmittance T of a circuit is measured using the two-photon entangled state at the input and output of a circuit, where C * µ,ν=0 ab is the coincidence counts at the initial state.The overall transmittance, T = S × T o , includes the success probability, S, of a circuit and other optical transmittance of the apparatus, T o .

High-dimensional entanglement certification with systematic errors
The fidelity and purity of the gates (see Table I and Supplementary Information) show that our circuits are not perfect (F<100%).Recent work has shown that even slight imperfections in measurements can compromise entanglement witnesses that normally assume perfect measurements [70].Here we investigate whether entanglement can be detected and quantified from the relative frequencies corresponding to our data measured in two approximately conjugate bases (red squares in Fig. 3).Focusing on the case of dimension five, we address the question of whether there exists some bipartite quantum state, ρ AB , whose Schmidt number is no more than s, that can model the measured relative frequencies.Since the data must admit a quantum model with some quantum state, which has a corresponding Schmidt number, a negative answer implies that the state is entangled and that its Schmidt number is at least s + 1.
Knowledge of the precise noise present in our experiment can lead to stronger entanglement criteria [88,89] but since we do not know the relevant noise, we adopt an approach where the state is treated as uncharacterised.In our analysis, we assume that Alice's measurements correspond to the computational basis and the first MUB respectively.Thus we associate to her the measurement operators A a|0 = |a⟩⟨a| for the first setting and a ⟩⟨M 1 a |, for the the second setting.Here, her outcome can take values a = 0, . . ., d − 1.On Bob's side, the POVMs {B b|ν } for ν = 0, 1 are inferred from tomographic data.Importantly, Bob's measurement operators corresponding to the relevant outcomes b = 0, . . ., d−1 are incomplete because the measurement features outcomes that are not accessible in the lab.We therefore ad-hoc complete his measurements by associating the additional measurement operator, B d|ν = 1 1 − ∑ d−1 b=0 B b|ν , to the inaccessible outcome.In a quantum model, we expect the probabilities to follow Born's rule, where B abk = A a|k ⊗ B b|k .Naturally, however, neither Alice's nor Bob's above measurements are characterised flawlessly.In other words, the probabilities p lab (a, b|k) inferred from the measured relative frequencies for the events a, b ∈ {0, . . ., d − 1}, will not exactly correspond to the given POVMs.Consequently, when addressing whether the underlying state must be entangled, we cannot even expect that there exists any quantum state such that p Q (a, b|k) = p lab (a, b|k).This is the well-known drawback of standard entanglement witnessing.To address this issue, we must allow for p Q to reproduce p lab up to a reasonable accuracy, which accounts for the imperfections in the estimation of the lab POVMs of Alice and Bob and the photon counting statistics.Specifically, we introduce for each probability associated with the tuple We determine the tolerances due to systematic and statistical errors in our experiment from both our measurement devices and our gates' tomography, via a Monte Carlo simulation of our experiment as detailed in Supplementary Information.From multiple simulations of the experiment, corresponding to p j (a, b|k), we compute for each (a, b, k) the mean deviation from p lab and its standard deviation, i.e.
where X (j) abk = |p lab (a, b|k) − p j (a, b|k)| is the deviation in the sample j for the tuple (a, b, k).We evaluate the standard deviation of p j (a, b|k) 0<j<N for all a, b, k and find that this converges at N ≈ 1500, allowing us to safely choose N = 2000.We then choose the tolerance for each and every tuple (a, b, k) to be three standard deviations above the mean deviation from p lab .Hence we put t abk = ∆ abk + 3σ abk .
With reasonable errors accounted for in the quantum model, we now wish to address whether entanglement is necessary to model the results of the experiment.Specifically, does there exist a p Q as given in (18) generated from a state ρ AB whose Schmidt number is at most s, such that it reproduces p lab within the tolerances (19)?This question is both hard to solve and phrased as a binary decision.While we will soon address the former, we first emphasise that it is favourable to replace the latter with a quantitative statement because then one can also estimate the confidence in the falsification of the hypothesis (namely that the answer is positive).For that purpose, we introduce additional noise to our measured data p lab .Specifically, we consider a mixture of our experimental results, p lab , with the probabilities obtained from probing the POVMs of Alice and Bob with a maximally mixed state.The mixing parameter is v ∈ [0, 1].This gives the artificially noisy probability distribution Clearly, the experimental data corresponds to v = 1.Now, we can use v as a quantifier for a model in which ρ AB has Schmidt number at most s.That is, we solve where S s is the set of all bipartite states of local dimension d with Schmidt number at most s.Note that any value v < 1 implies that an amount of noise corresponding to a rate 1 − v must be additionally added to the experimental data in order for it to admit a model for Schmidt number s.In other words, it implies that no model based on Schmidt number s is possible and hence a Schmidt number at least s + 1 is necessary.
As mentioned previously, it is difficult to solve (23) because the characterisation of S s is challenging.However, it is sufficient for our purposes to relax S s into a larger set but over which computations can be done efficiently.It is well known that ρ AB ∈ S s implies that [90,91]; where R α (ρ) = Tr (ρ) 1 1 d − αρ is the generalised reduction map.If we replace the condition ρ AB ∈ S s with (24), we will obtain an upper bound on (23) that is computable as a semidefinite program.We have evaluated this semidefinite program for Schmidt numbers s = 1, 2, 3, 4, 5 and obtained the results Note that s = 1 corresponds to a separable model and that s = 5 corresponds to a generic five-dimensional entangled state, as was used in the experiment.We conclude that within the estimated tolerances no quantum model for p lab exists that relies on less than fivedimensional entanglement.Thus, we certify Schmidt number s = 5.Notably, only an additional noise rate of 0.0076 is needed to make possible a model based on s = 4. Thus, if we were to somewhat increase the tolerance interval, e.g. from to 3σ above the mean to 4σ above the mean, then the certified Schmidt number would decrease to s = 4.In either case, the data obtained by applying the I and F gates on our input state certify high-dimensional entanglement.0.040 ± 0.006, 0.026 ± 0.004, and 0.028 ± 0.003 for 2, 3, 5, and 7-dimensional gates respectively.We measure the success probability for 3 randomly chosen implementations of Fourier-F gates in 2, 3, and 5 dimensions and observe an S of 0.36 ± 0.014, 0.27 ± 0.03, and 0.18 ± 0.04, respectively.We thus infer an average optical transmittance of T o = 0.14 ± 0.02 which is attributed to the optical insertion and propagation losses, diffraction efficiency of the two SLMs, and other interface losses at the lenses and mirrors.We note that the main contribution to the loss is due to the success probability arising from control of only a single polarisation channel of the multi-mode fiber, which can be further improved when all polarisation-spatial modes of the optical system are controlled.

S.3. Manipulation of high-dimensional spatially entangled states
To study the programmabiltiy of our quantum circuits, we program many types of unitary gates, namely, the identity-I, Pauli-Z, Pauli-X, Fourier-F, and random unitaries-R, in 2, 3, 5, and 7 dimensions in both the macro-pixel and OAM input bases.For each implementation, we randomly appoint a set of target output foci to encode the circuit with.We then use these circuits to locally transform the d-dimensional spatially entangled two-photon state, which is then characterised by performing AA-QPT.Table S.2 shows the fidelity and purity of the best-case gates in each dimension.The measured tomography data and reconstructed density matrices of these processes are shown in Figs.S.5 and S.6 for the macro-pixel and OAM bases.The process fidelity quantifies how close to ideal our gates are, taking into account the non-maximally entangled nature of the input state.As a separate metric, the fidelities of the output state to an ideal transformed state allows independent verification that the gates preserve high-dimensional entanglement.Tables S.3 and S.4 show the output state fidelity, purity, and entangement dimensionality for all best-case gates.
In theory, the process fidelity of a circuit in a given dimension should be independent of the type of circuit and input/output modes used.In practice, however, experimental imperfections relating to the measurement apparatus and characterisation of the MMF result in a spread of fidelities with a lower average over all circuit instances, which are reported in Table .Basis T F( ρξ * , ρ ξ ) P( ρξ * ) Macro-Pixel I 96.7 ± 0.9 % 97.4 ± 0.7 % 88.0 ± 0.7 % 71.9 ± 1.1 % 94.5 ± 0.4 % 99.5 ± 0. , after being operated on by gate T in d dimensions in the macro-pixel and OAM bases.These results correspond to the data and density matrices presented in Fig. S.5 and S.6.The reported errors are due to misalignment of measurement apparatus as well as photon counting statistics as discussed in S.5.In this section, we characterise our measurement apparatus and gate transformations independent of our entangled input source.This allows us to study how imperfections in the measurement apparatus limit the quality of our measured states and transformations.

Basis
Our measurements are characterised by performing a classical prepare-and-measure experiment in situ in the experimental setup.We unfold our setup about the nonlinear crystal by replacing it with a mirror and analyse it in the Klyshko advanced-wave picture [94].As shown in Fig. S.7(a), a weak coherent state (superluminiscent diode filtered at 810 ± 1.5nm ) with the identical wavelength as the entangled photons is back-propagated from the idler photon measurement stage and prepared in a chosen state (precisely those used in our QST measurements).This state is then directed to the signal measurement stage by a mirror placed at the crystal plane, and subsequently projected by the signal photon measurement stage and recorded by an avalanche photo-diode.The measurements performed with the unfolded classical setup are identical to those performed in the main experiment, and allow us to gauge the reduction in the quality of entangled state and gates due to the imperfect measurement apparatus.

M0 M1 M2 M3 M4 M5
Output MUB   ).The imperfections in the coupling matrices can be attributed to misalignments in the experimental setup, as well as imperfections in the computer generated holograms (CGHs) due to pixelisation and non-unit fill fraction.The effect of CGH-induced imperfections can be seen to be more pronounced in the OAM basis since superpositions of modes in this basis require amplitude modulation, while macro-pixel measurements can be performed with phase-only modulation.
Treating these measurements as analogous to (folded) two-photon measurements allow us to upper-bound the quality of a maximally entangled state that can be measured with this setup.We use this procedure to obtain cross-talk matrices in the macro-pixel and OAM bases in 2, 3, 5, and 7 dimensions.We then perform QST on this data to calculate an upper bound on the fidelity (F) to a maximally entangled state, purity (P), and entanglement dimensionality that can be measured with this setup as shown in Table S.6.Next, we perform a similar prepare-and-measure experiment on the gate transformations to verify their performance independent of the input entangled state.As shown in Fig. S.7(b), a filtered superluminiscent diode is sent through the programmable circuit consisting of the multimode fiber sandwiched between two SLMs.In this experiment, SLM 1 is used to prepare the classical input states sent into the gates while also contributing to the construction of the gate operation.The output states are measured on a camera, which allows multiple outcomes to be measured simultaneously.
We construct various optical circuits as described in Methods and perform quantum process tomography (QPT) on these gate operations.In order to perform QPT on the gate operation, SLM 2 is used to display the output-mode holograms that correspond to local measurements made by Bob.The resultant data is then processed in the same manner as in AA-QPT, while choosing the input state to be the ideal maximally entangled one, as described in Methods.
Table S.7 shows the performance of these gates.When compared with results shown in Table S.2, one sees that these gates perform better on classical input states than on an entangled input state.This can be attributed to the fact that we use the same classical source (identical wavelength and bandwidth) to characterise our fiber transmission matrix.In addition, slight differences in alignment can result in imperfect mode-matching between our input entangled state and classical light source.When performing QST and AA-QPT, errors in the measurement apparatus can lead to erroneous state reconstruction [71], which often tends to be the systematic type.As demonstrated above in S.4, the measurements in our laboratory conditions are not perfect, so here we address the problem by using the above prepare-and-measure experiment to estimate the distribution of errors in our measurement settings, and use these to estimate the consequent errors in state and process reconstruction using QST and AA-QPT.
The prepare-and-measure experiment described in S.4 is repeated 50 times, following realignment procedures used in the actual experiment.The realignment consists of performing a knife-edge scan to find the center of incident beams on the SLM, as well as performing a raster-scan on the fiber facet by displaying different gratings on the SLM.In each trial, the tomography of measurements is used to fit model parameters pertaining to the experimental sources of misalignment, i.e. tilt and displacement of projected optical fields on the SMF, as shown in Fig. S.9(a).The results of these fitted experimental parameters are presented in histograms Fig. S.9(b), which provide distributions of the experimental misalignments.Given these distributions, we perform error propagation by numerically sampling from the ensemble of misalignments and calculating the resultant imperfect measurement projectors ( Πi ), which correspond to the actual measurement errors that can occur in our experiment.
To assess the resultant estimation errors on our QST/AA-QPT fidelity, fidelity to target state, and state purity, we simulate the effects of these measurement errors on our experimentally estimated state, ρ * , in the following manner.For QST, given an estimated state ρ * , in the ith trial we generate a sample measurement, Πi , from the ensemble of misaligned measurements containing a set of tomographic measurement projectors.We calculate the measured detection statistics of Πi on ρ * , and perform the QST reconstruction via SDP to obtain a recovered state estimate, ρi .For AA-QPT, we first perform this sampling procedure to generate the input state, then repeat the procedure for Choi state estimation using that particular input state sample.We repeat these steps 200 times, and record the QST/AA-QPT fidelities, {F(ρ i , ρ * )} i , the fidelities to target state {F( ρi , ρ target )} i , and the purities {P( ρi )} i .These distributions then correspond to the measurement errors of our actual state estimation procedure, providing that the ground-truth state (which we cannot know) undergoes similar reconstruction errors to the state estimate ρ * .The fidelity of QST (AA-QPT), the fidelity to the target (target Choi) state, and the purity are presented in For the 5-dimensional input state, we find that the fidelity of the QST procedure, exemplified by {F( ρi , ρ * )} i , has sample mean fidelity 99.48% indicating a slight infidelity of QST caused by the measurement error.For the fidelity to the maximally entangled target state ({F( ρi , ρ target )} i ), we observe that measurement errors almost exclusively lead to a reduction, demonstrating that the measurement errors likely cause systematically an underestimation of the true initial state quality.The standard error of this fidelity to target state, ∆ M = 0.57%, is calculated with respect to the underlying state fidelity (F( ρ * , ρ target )), and we conservatively cite this as the symmetric error on our recorded fidelities in the main text.Similarly, the purity of the recovered state under these measurement errors ({P( ρi )} i ) almost exclusively decreases (albeit very slightly), leading to a likely underestimation of state purity, though we again cite this standard deviation in the main text and Table S.1, and these results are summarised in Table S.8.
For AA-QPT, where both the input state and the recovered Choi state are sampled as above, we observe somewhat different behaviours.The fidelity of the AA-QPT procedure for a 5-dimensional random gate,{F(ρ ξi , ρξ * )} i has a sample mean of 99.81% indicating reasonably stable process recovery given our measurement errors.The fidelity to target Choi state shows a broadened distribution featuring both over-and under-estimation of fidelity to target Choi state (unlike the QST case), with a standard deviation ∆ M = 0.62%.The purity of the recovered Choi states is also broadened about the underlying Choi state purity P( ρξ * ).We cite the standard deviation with respect to the measured values in the main text and Table S.2 and summarise in Table S.8.
In some cases, particularly where the input state basis suffers more detrimental impurity caused by measurement errors than the output state, we can observe a slight systematic tendency to over-estimate Choi state fidelities and purities.This discrepancy between QST and AA-QPT behaviours can be explained by noting that an over-estimation of noise in an input state would lead to misattribution of output state noise to the input state and not to the Choi state, thus under-estimating Choi state noise.We demonstrate this effect symbolically when performing a direct inversion to solve for the Choi state in the case of white noise mixing of the input state in Supplementary S.6.S.2 using AA-QPT, with respect to the reported values (black line).

S.6. Misestimation of initial state in linear inversion
Perfect recovery of the underlying Choi state of a channel requires accurate estimation of the initial state.Suppose the true initial state given by Eqs. 8 were misestimated by, where B is some additive noise.When attempting the linear inversion of the Choi state, ρ ξ , it would be misestimated by, Fidelity ( ( * , target )) Purity ( ( * ))  S.2 using AA-QPT, with respect to the reported values (black line).
which may be unphysical.In the case of additive white noise, B ⊗ I is rank one (in the sense that its matrix representation when acting on vectorised states has rank one).We use the Sherman-Morrison formula to arrive at, where g ∶= To investigate the programmability and scalability of our approach, we numerically construct many instances of the high-dimensional circuits by varying our design parameters, i.e., dimension of circuit d, dimension of mode-mixers n, depth of circuit L, using the model  where the n reconfigurable phase elements at each P j are found using the wavefront-matching algorithm as explained in Methods given a set of n × n unitary matrices {U j } j and a set of d input and output modes of interest.The codes for these simulations are available in [92].Once a circuit is implemented, we classify its performance by measuring fidelity (Eq.12 ) and success probability (Eq.13 ).For a given set of design parameters n, L and d, we implement multiple realisations of the Identity I, Pauli-X, Pauli-Z, Fourier-F, and random unitary R gates (Eq.6 ), by varying the set of d input and output modes of interest which are randomly selected.We simulate these circuits by treating the mode-mixers {U j } j as either a set of random unitaries or discrete Fourier transforms (DFT).
As presented in the main text, when the dimension of the circuit, d, is less than the dimension of mode-mixers, n (d/n < 0.1), both fidelity and success probability reduce as the circuit dimension increases.Fig. S.12 conveys these trends in detail.For all these realisations, all random mode-mixers {U j } correspond to the same random unitary matrix, and the positions of input/output modes of interest are randomly selected for each implementation.The behaviour reported in Fig. S.12 is also observed either when different random mode-mixers are used in each layer, or input/output modes are specifically assigned to the first d modes of the U j .Interestingly, the same trends for fidelity and success probability are observed for all gate types, indicating that there is no advantage when programming specific types of gates using this method.The same holds for both DFT and random mode-mixers with randomly selected inputs and outputs, indicating that a DFT is similar to a random unitary in this regime.
For a circuit described by Eq.S.7.1, the total number of degrees of freedom (DOFs) is given by the number of reconfigurable elements nL.On the other hand, the constraint on the number of DOFs required to program a ddimensional circuit T is O(d 2 ) [6,95].A larger d leads to loss of performance because the number of DOFs required to program the circuit increases.Thus, as d increases, the number of reconfigurable elements does not change.Improving the figures of merit of a d-dimensional circuit can therefore be addressed in two primary ways: increasing the dimension of mode-mixers, n, or the depth of circuit, L.
To study the region where the fidelity and success probability converge to unity, we have plotted our simulation data on a log-log plot (Fig. .The point at which (1 − F ) → 0 depends on the ratio of d/n.In the case where d = n, the number of reconfigurable elements required is optimal, and the infidelity rapidly converges to zero.In the regime where d/n < 1 however, the number of elements necessary for full programmability increases as d/n decreases.For instance, when d/n < 0.1 the infidelity converges to zero slower as a function of the number of elements (normalised by dimension).In Fig. S.13b, we observe that the failure probability decreases as a function of the circuit depth and rapidly converges to zero (capped at 10 −16 ) when L ≈ O(d) in all cases of d ≤ n.In this regime, full programmability is achieved and is seen to be relatively independent of d/n.Note that the failure probability for d = n is always zero.
These results show that in order to achieve both high fidelity and success probability, one does not need to solely rely on the number of reconfigurable elements, but also on their distribution across the circuit.Ideally, one would want to implement a fully programmable circuit using the full dimension of mode-mixers (d = n) constructed from 2 × 2 beam splitters or n × n mode-mixers, since this achieves the minimum number of reconfigurable elements [5,7].However, it is known that in the presence of imperfections, an increase in the depth of the circuit is required to improve the fidelity in such schemes [13][14][15].Scaling the depth of circuit in practice may nonetheless not be the most viable option due to a variety of experimental reasons, namely, propagation and interface losses and accumulation of errors.Instead of considering errors and scattering losses as a problem, the top-down approach presents a reasonable alternative (d < n and L ≲ O(d)) where randomness is exploited to implement a circuit with a low depth.Here, both fidelity and success probability are acceptably high, while n can increase to improve the fidelity without reducing the success probability from unity when L > 2d, or with a trade-off on the success probability when L ≤ 2d.Many optical devices, for instance, computer-generated holograms and MPLC devices [22,96] can be considered to fall in this category where mode-mixing can be implemented by free-space propagation, a 2f lens system, or another transformation such as a circulant matrix [97,98].
Finally, while the deterministic construction of programmable circuits from discrete Fourier transforms is known for d = n [99, 100], a proof of universal programmability of unitary circuits using random-unitary mode-mixers remains open to the best of our knowledge, and the deterministic construction of such circuits is yet to be discovered.

S.8. Effects of randomness and symmetry
A pertinent point to address is the role that randomness plays in the implementation of an optical circuit using the top-down approach.For instance, instead of having a random unitary evolution between phase planes, one could have another transformation such as a discrete Fourier transform (DFT) or a circulant matrix, which normally have a symmetric structure [97,98].In practice, such transformations can be difficult to implement on an integrated platform, normally requiring a high degree of accurate control.Due to inherent imperfections and bending, a commercial multimode fiber is much closer to a random matrix in our basis of interest than a symmetric transformation.In this section, we investigate the effect of randomness on the gates performance, by comparing circuit implementations using random

Figure 1 .
Figure 1.Figure1: Design of programmable optical circuits: A general linear transformation T can be implemented via (a) the conventional "bottom-up" approach, where the circuit is constructed from units consisting of beamsplitters (BS) and phase shifters (P), or (b) the herein proposed "top-down" approach, where a target d-dimensional linear circuit is embedded within a large ambient mode-mixer with dimension n > d, where n − d auxiliary modes serve as an additional resource.The technique harnesses random unitaries Uj (such as a complex scattering system) interspersed with controllable phase planes Pj implemented via spatial light modulators (SLMs), which provide programmability over the target circuit.A similar approach is used in (c) multi-plane light converters, where the random unitaries are replaced with free-space propagation F .

Figure
Figure 1.Figure1: Design of programmable optical circuits: A general linear transformation T can be implemented via (a) the conventional "bottom-up" approach, where the circuit is constructed from units consisting of beamsplitters (BS) and phase shifters (P), or (b) the herein proposed "top-down" approach, where a target d-dimensional linear circuit is embedded within a large ambient mode-mixer with dimension n > d, where n − d auxiliary modes serve as an additional resource.The technique harnesses random unitaries Uj (such as a complex scattering system) interspersed with controllable phase planes Pj implemented via spatial light modulators (SLMs), which provide programmability over the target circuit.A similar approach is used in (c) multi-plane light converters, where the random unitaries are replaced with free-space propagation F .

Figure 2 .
Figure 2.Figure 2: Experimental setup.a) A high-dimensional spatially entangled two-photon state is generated via Type-II spontaneous parametric downconversion (SPDC) in a periodically poled Potassium Titanyl Phosphate (ppKTP) crystal.The two photons are spatially separated by a polarising beamsplitter (PBS) and sent to two parties, Alice and Bob.Alice performs single-outcome projective measurements Πµa that measure whether a photon is carrying spatial mode a from modal basis µ.These are performed by a combination of a spatial light modulator (SLM3), single-mode fibre (SMF), and a single-photon avalanche photodiode (APD).Bob implements a top-down programmable circuit that is constructed from a multi-mode optical fibre (MMF) placed between two programmable spatial light modulators (SLM1,2).The circuit is used to program a variety of high-dimensional quantum gates and serves as a generalised multi-outcome device.(Circular inset) A coincidence image depicting a five-outcome measurement in basis µ = 1 performed with the Fourier-F gate at Bob.The image is obtained by scanning a detector across the output of the circuit, conditioned on a measurement of Πµ=1 a=0 at Alice, and shows a large intensity in mode 0 due to strong spatial-mode correlations.Coincidence detection events between Alice and Bob are registered by time-tagging electronics.b) CCD images demonstrating the operation of the Fourier-F gate as a multi-outcome measurement of classical macro-pixel modes prepared in basis µ = 1 in dimensions d = {2, 3, 5}.Note that while the input modes have the same amplitude for a given d, they are orthogonal in phase (not seen in intensity images).(L: lens, F: filter, HWP: half-wave plate).

Figure 3 .
Figure 3.Figure 3: Manipulation and certification of high-dimensional entanglement: Normalised two-photon coincidence counts (top row) and reconstructed Choi state density matrices (bottom row) corresponding to operation of the Identity I, Pauli-Z, Pauli-X, Fourier F, and random unitary R gates on an input two-photon, five-dimensional entangled state in the macro-pixel basis.The two-photon coincidences are measured in all six mutually unbiased bases (MUBs µ ∈ {0...5})via projective measurements at Alice and Bob.Due to state-channel duality, measurements on the input and output twophoton states can be used to perform ancilla-assisted process tomography of the gates themselves[39,68].The fidelities of the reconstructed Choi states are reported in TableI.The Identity and Fourier gates enable our circuit to be used as a multioutcome measurement device in MUBs µ ∈ {0, 1} (red squares), allowing us to certify five-dimensional entanglement using the channel itself as a measurement device (see main text for details).The density matrix legend captures both the amplitude (brightness, normalised for clarity) and phase (colour).

Figure 3 :
Figure 3.Figure 3: Manipulation and certification of high-dimensional entanglement: Normalised two-photon coincidence counts (top row) and reconstructed Choi state density matrices (bottom row) corresponding to operation of the Identity I, Pauli-Z, Pauli-X, Fourier F, and random unitary R gates on an input two-photon, five-dimensional entangled state in the macro-pixel basis.The two-photon coincidences are measured in all six mutually unbiased bases (MUBs µ ∈ {0...5})via projective measurements at Alice and Bob.Due to state-channel duality, measurements on the input and output twophoton states can be used to perform ancilla-assisted process tomography of the gates themselves[39,68].The fidelities of the reconstructed Choi states are reported in TableI.The Identity and Fourier gates enable our circuit to be used as a multioutcome measurement device in MUBs µ ∈ {0, 1} (red squares), allowing us to certify five-dimensional entanglement using the channel itself as a measurement device (see main text for details).The density matrix legend captures both the amplitude (brightness, normalised for clarity) and phase (colour).

Figure 4 .
Figure 4.Figure 4: Programmability and Scalability of top-down optical circuits: (a-b) Fidelity (F) and success probability (S) of a d-dimensional quantum optical circuit as a function of the dimension of mode-mixers (n) for a circuit depth of L = 2. (c-d) F and S as a function of L for n = 200.(e) A plot of Fidelity versus the parameter nL/d 2 in the regime where d/n < 0.1.The plot shows a converging trend towards unit Fidelity (F = 1), demonstrating that full programmability can be achieved by increasing either the mode-mixer dimension n or the circuit depth L. (Inset) A plot of Success probability versus the parameter L/d shows convergence to unity when the number of phase planes approaches L ≈ O(d).A sample size of 200 is used to derive the statistics of each data-point.The data is presented as mean values ±1 standard deviation.

Figure 4 :
Figure 4.Figure 4: Programmability and Scalability of top-down optical circuits: (a-b) Fidelity (F) and success probability (S) of a d-dimensional quantum optical circuit as a function of the dimension of mode-mixers (n) for a circuit depth of L = 2. (c-d) F and S as a function of L for n = 200.(e) A plot of Fidelity versus the parameter nL/d 2 in the regime where d/n < 0.1.The plot shows a converging trend towards unit Fidelity (F = 1), demonstrating that full programmability can be achieved by increasing either the mode-mixer dimension n or the circuit depth L. (Inset) A plot of Success probability versus the parameter L/d shows convergence to unity when the number of phase planes approaches L ≈ O(d).A sample size of 200 is used to derive the statistics of each data-point.The data is presented as mean values ±1 standard deviation.

d− 1 a
,b=0 tab | b ⟩ ⟨ a | and ϕ b (x) is the b-th standard output optical field of circuit on the output x space.The normalisation of tab is measured by the ratio of optical flux inside the b-th output mode of a circuit, I ab ∝ | tab | 2 , to total output optical flux transmitting through the system given the a-th input mode, I a ∶= ∫ d 2 xI a (x) where

Figure S. 1 .
Figure S.1.Generated high-dimensional entangled two-photon states in the macro-pixel basis.Measured coincidence counts in all mutually unbiased bases (MUBs) and reconstructed density matrices via quantum state tomography in dimensions, d = [2, 3, 5, 7].The amplitude and phase of density matrix elements are represented by the height of the bars and their colour, respectively.The ideal amplitude is represented by a transparent bar overlaid on the experimental result.

Figure S. 2 .
Figure S.2.Generated high-dimensionally entangled two-photon states in the OAM basis.Measured coincidence counts in all mutually unbiased bases (MUBs) and reconstructed density matrices via quantum state tomography in dimensions, d = [2, 3, 5, 7].The amplitude and phase of density matrix elements are represented by the height of the bars and their colour, respectively.The ideal amplitude is represented by a transparent bar overlaid on the experimental result.

S. 5 .
This shows the average fidelities and purities of circuits for various types of gates sampled over different sets of output foci.The histogram of fidelities of all the implemented gates are shown in Fig. S.4.Table S.2: Fidelity F and purity P of the channel, ρξ * implemented by a gate T in d dimensions in the macro-pixel and OAM bases corresponding to the results presented in Fig. S.5 and S.6.The reported errors are due to misalignment of measurement apparatus as well as photon counting statistics as discussed in S.5.

Figure S. 5 .
Figure S.5.Manipulation of 2, 3, and 7-dimensional spatially entangled two-photon states in the macro-pixel basis using the I, Pauli-Z, Pauli-X, Fourier F, and random unitary R gates.In each panel, the upper part shows the two-photon coincidence counts in all MUBs and the lower part depicts reconstructed density matrices of the Choi states ρξ * .The density matrix legend captures both the amplitude (brightness, normalised for clarity) and phase (colour).

Figure S. 6 .Figure S. 7 .
Figure S.6.Manipulation of 2, 3, 5, and 7-dimensional spatially entangled two-photon states in the OAM basis using the I, Pauli-Z, Pauli-X, Fourier F, and random unitary R gates.In each panel, the upper part shows the two-photon coincidence counts in all MUBs and the lower part depicts reconstructed density matrices of the Choi states ρξ * .The density matrix legend captures both the amplitude (brightness, normalised for clarity) and phase (colour).

Figure S. 8 .
Figure S.8.Characterisation of measurement apparatus: Cross-talk matrices corresponding to (a) ideal measurements in the macro-pixel/OAM bases, and imperfect measurements in the (b) macro-pixel basis and (c) OAM basis characterised with a classical prepare-and-measure setup.

Fig. S. 8
Fig. S.8 shows the measured cross-talk matrices for five-dimensional state preparations and measurements for every MUB in the macro-pixel and OAM basis.Fig. S.7(c) shows CCD images of the prepared input modes (image plane denoted by dotted lines in Fig S.7).The imperfections in the coupling matrices can be attributed to misalignments in the experimental setup, as well as imperfections in the computer generated holograms (CGHs) due to pixelisation and non-unit fill fraction.The effect of CGH-induced imperfections can be seen to be more pronounced in the OAM basis since superpositions of modes in this basis require amplitude modulation, while macro-pixel measurements can be performed with phase-only modulation.Treating these measurements as analogous to (folded) two-photon measurements allow us to upper-bound the quality of a maximally entangled state that can be measured with this setup.We use this procedure to obtain cross-talk matrices in the macro-pixel and OAM bases in 2, 3, 5, and 7 dimensions.We then perform QST on this data to calculate an upper bound on the fidelity (F) to a maximally entangled state, purity (P), and entanglement dimensionality that can be measured with this setup as shown in Table S.6.
Fig. S.8 shows the measured cross-talk matrices for five-dimensional state preparations and measurements for every MUB in the macro-pixel and OAM basis.Fig. S.7(c) shows CCD images of the prepared input modes (image plane denoted by dotted lines in Fig S.7).The imperfections in the coupling matrices can be attributed to misalignments in the experimental setup, as well as imperfections in the computer generated holograms (CGHs) due to pixelisation and non-unit fill fraction.The effect of CGH-induced imperfections can be seen to be more pronounced in the OAM basis since superpositions of modes in this basis require amplitude modulation, while macro-pixel measurements can be performed with phase-only modulation.Treating these measurements as analogous to (folded) two-photon measurements allow us to upper-bound the quality of a maximally entangled state that can be measured with this setup.We use this procedure to obtain cross-talk matrices in the macro-pixel and OAM bases in 2, 3, 5, and 7 dimensions.We then perform QST on this data to calculate an upper bound on the fidelity (F) to a maximally entangled state, purity (P), and entanglement dimensionality that can be measured with this setup as shown in Table S.6.

Figure S. 9 .
Figure S.9.Misalignment-induced systematic errors: (a) Sources of misalignment in spatial single-outcome projective measurements performed with a spatial light modulator (SLM), lens (L), and a single-mode fiber (SMF).(b) Histograms of errors in positions of holograms displayed on the SLM and positions of the SMF.The misalignments are characterised using multiple prepare-and-measure experiments.(c) Histograms of errors propagating through QST and AA-QPT in fidelity and purity of states and processes.Here we show the example of a 5-dimensional entangled state and a random-unitary gate in the macro-pixel basis.The black lines indicate the values reported in the main experiment.
Fig. S.9(c), for QST of the 5-dimensional macro-pixel entangled input state and AA-QPT of the 5-dimensional Random gate.These show representative behaviour of the sampling procedure.Complete results for each estimated state are presented in Fig. S.10 and Fig. S.11.We also mark the corresponding property of the underlying experimental state estimate, ρ * , as black lines in Fig. S.9(c).

FidelityFigure S. 10 .
Figure S.10.Measurement error analysis for macro-pixel basis: Histogram of fidelity and purity of reconstructed input state ρ (in) using QST as well as quantum gates reported in TableS.2 using AA-QPT, with respect to the reported values (black line).

Figure S. 11 .
Figure S.11.Measurement error analysis for OAM basis: Histogram of fidelity and purity of reconstructed input state ρ (in) using QST as well as quantum gates reported in TableS.2 using AA-QPT, with respect to the reported values (black line).
S.13), replacing fidelity with infidelity (1 − F ) and success probability with failure probability (1 − S).As shown in Fig. S.13a, the infidelity converges to zero (capped at 10 −16 due to the floating-point precision used) when the total number of reconfigurable elements exceeds the number required to program a unitary operation (O(d 2 ))

Figure S. 12 .
Figure S.12.Simulated fidelity F and success probability S for all gates implemented in a circuit with random unitary mode-mixers: (a-c) F and S as a function of the dimension of mode-mixers, n, with a circuit depth L = 2 and (d-f) F and S as function of circuit depth L while using mode-mixers with dimension n = 200.A sample size of 200 is used to derive the statistics of each data-point.The data is presented as mean values ±1 standard deviation.

Table I :
Quantum process fidelities of inversedesigned experimental gates to the ideal gates in the macro-pixel basis.

Table S . 1 :
Generated high-dimensionally entangled two-photon states: State purity P, Entanglement dimensionality dent, Fidelity to maximally entangled state F, Entanglement of Formation (E oF ).The reported errors are due to misalignment of measurement apparatus as well as photon counting statistics as discussed in S.5.

Table S .
6: Expected reduction in state purity P, entanglement dimensionality dent, and fidelity F of a d-dimensional maximally entangled state due to imperfect measurements characterised using a classical prepare-and-measure experiment.The measured input state fidelities Fexp(ρ (in) , ρ + ) from TableS.1 are shown for comparison.

Table S .
8: Results of errors from photon counting statistics and imperfect measurement settings on the input state, ρ(in)in QST and the Choi states of gates, ρ ξ , in AA-QPT.We report the sample mean of the QST/AA-QPT fidelities (F( ρi, ρ * )), and the one standard deviation Poisson error (∆ P ) and measurement error (∆ M ) of the fidelity to target state (F( ρ * , ρ target )) and purity (P( ρ * )).