Introduction

Both NP and #P are well-known complexity classes that computing resources for solving an NP or a #P problem grow exponentially as the size grows1,2. NP and #P problems have distinct purposes: While an NP problem usually focuses on determining whether a solution exists, #P addresses counting solutions, which is generally considered computationally harder. Counting the number of perfect matchings of a graph, also called the perfect matchings problem, as one of the famously #P-complete problems3, has a broad range of applications, including stable marriage problem4, Fries number of a fullerene5, dimer problem6, and Hosoya index7. A perfect matching is a match that covers all vertices in an undirected graph. There is no polynomial exact algorithm nor a fully polynomial approximation algorithm for the perfect matchings counting of a general graph. The most efficient existing exact algorithm is proposed by Andreas with a polynomial space and a time complexity of O(poly(n)2n/2)8.

Optical methods based on classical light fields have been proposed for solving NP problems9, such as the max-cut problem10,11,12, the max-clique problem13, and the Hamilton path problem14,15. However, classical methods are inefficient in hard counting tasks. The quantum multiphoton source can introduce special properties beyond classical light fields for solving perfect matchings problem16,17. Due to the fact that the number of perfect matchings of an undirected graph equals the hafnian value of the graph’s adjacency matrix, the number of perfect matchings can be estimated by Gaussian boson sampling with a specific setting16. Recently, such a theoretical scheme was experimentally realized in a silicon photonic chip17. Alternately, hafnian can also be achieved from multi-photon coincidence of the cascade nonlinear crystals by the path identity method18,19,20, that experiments of interference up to four-photon were reported21,22. However, due to the strict requirements of coherence, including the high purity of photonic source, the stabilization of relative phase, and the difficulty for path and arrival-time identity, realizing large-scale photonic hardware by these two methods remains challenging. Though a smart scheme simplifies the experiment by avoiding the cascade of photon sources, it introduces an extra exponential attenuation because of the beam combination of photons from different sources23.

In this work, we focus on solving the perfect matchings problem and introduce the frequency degrees of freedom as an auxiliary to circumvent the strict challenges. We propose an optical perfect matching solver based on frequency grouping and multi-photon coincidence. We group a frequency-entangled photon-pair source to several outputs according to different frequencies, to configure the given graph. Then, the coincidence measurement of the outputs will automatically keep states corresponding to perfect matchings and filter out unwanted states. Owing that multi-photon terms are different in frequency, this method avoid destructive interference and do not need to consider the indistinguishability of photons. In the experiment, we utilize a silicon waveguide to produce broad photon pairs and a wavelength-selective switch(WSS) to group photons. We configure graphs up to sixteen vertices and recorded coincidences up to six photons. The distribution fidelities are more than 90%, showing a significant improvement compared to previous experiments. It is convenient to transform or scale up the graph by programming wavelength-selective switch without changing the photonic source. Moreover, we show the samples generated from the perfect matching solver can enhance classical stochastic algorithms for solving Boolean satisfiability(SAT) and densest subgraph. Our work takes surprising advantages of frequency dimension and provides a promising tool for solving the perfect matchings problem.

Results

In elegant theories from Krenn et al., perfect matchings of graphs are related to quantum experiments, and optical setups are mapped to undirected graphs18,19,20. The photon pairs produced from nonlinear crystals correspond to the graph’s edges, and the output paths are regarded as the graph’s vertices. Erasing the source information of the photon pairs by path identity and arrival time indistinguishability, then an n-fold coincidence with one and only one photon per output can be seen as a subset of edges that contains every vertex only once, that is, a perfect matching of an n-vertex graph. The n-fold coincidence will correspond to Hafnian2, that is, when all the relative phases of n-photon terms are zero, it will become #PM2. A simple example is shown in Fig. 1a, b, where the photon pairs are respectively produced by four crystals, and form four edges of the 4-vertex graph, respectively. The four-fold coincidence can happen only when crystals I and III or crystals II and IV motivate together20. The four-fold counts will be proportional to #PM2 = 4 if the relative phase between two perfect matchings is zero.

Fig. 1: Principle and experimental setup of perfect matching solver.
figure 1

a A path-identity experimental setup with four crystals producing horizontally polarized photon pairs. b The corresponding undirected graph of the setup. All the perfect matchings construct the final quantum state. c Broadband photon pairs produced by optically nonlinear process. d An artistic figure depicts the process that photons are grouped according to frequency and the corresponding graph after the frequency grouping. e Multi-photon coincidence rate with one and only one photon each output is determined by the number of perfect matchings of the graph. f Experimental setup for estimating perfect matchings by frequency grouping of a broadband photon-pair source. FPC fiber polarization controller, DWDM dense wavelength division multiplexing module, PD power detector, WSS wavelength selective switch, SNSPDs superconducting nanowire single photon detectors, CLM coincidence logic module.

However, due to the strict requirements of coherence and stability, increasing the graph’s scale in practical experiments is challenging. For example, the required high purity of photon sources will dramatically reduce the effective photon or complicate the structure of photonic source. Besides, coherent interference caused by inevitable phase deviation will destroy the perfect matchings, that is, the multi-fold counts in the practical experiment will be proportional to the value vibrating from 0 to #PM2. Therefore, in this work, we consider to introduce frequency dimension to simplify the experiment and avoid destructive interference while the consistency of the arrival times of photons must be maintained. Frequency can support very large dimensions and naturally transmit in a single-mode optical fiber or waveguide24. We take frequency degree of freedom as an auxiliary and propose a multi-photon perfect matching solver based on the frequency grouping of broadband photon pairs, which mainly consists of three parts: 1) Generate a broadband photon-pair source, as shown in Fig. 1c; 2) Group the photon pairs at different frequency channels according to the given graph which achieves the frequency-distinguishable path identity, as shown in Fig. 1d. Each frequency-associated photon pair constructs an edge, and such two photons are distributed respectively to two outputs which are seen as the two vertices linked by this edge. As a critical step, frequency grouping can be realized by WSS. 3) Count the multiphoton coincidence with one and only one photon per output, which is naturally proportional to the number of perfect matchings, as shown in Fig. 1e. The correspondence between graph theory and optical setups of our method are listed in Table 1. See detailed theoretical description in Methods.

Table 1 The correspondence between graph theory and optical setups of our perfect matching solver

Figure 1f shows the main experimental devices of our demonstrations. A pulse laser was injected into a silicon waveguide, and then broadband photon pairs were generated in the waveguide by the spontaneous four-wave mixing(SFWM). The original two-photon generation rates of 15 pairs of channels with 60 GHz bandwidth are shown in Fig. 2a. Photon pairs entered a WSS for frequency grouping and then were detected at superconducting nanowire single-photon detectors(SNSPDs). WSS is an important device in our scheme, which can freely control the outputs and attenuations of photons in different frequencies. Compared with multi-layer cascaded DWDMs25,26, WSS has higher programmability, and more importantly, it barely brings delays between different frequency channels, and the time cost and the insertion loss of each channel in the process of frequency grouping are almost constant independent of the graph size27. As a simple example, a four-vertex graph can be configured by frequency grouping and multiphoton coincidence as shown in Fig. 1d, e, where the frequency grouping should be implemented in WSS by distributing channels {1, 2} to output a, {−1,−4} to b, {−2, −3} to c, and {3, 4} to d. And the four-fold counts of outputs {a–d} will correspond to two, i.e. the number of perfect matchings of this four-vertex graph. See detailed experimental setup in Methods.

Fig. 2: Experimental results for calculating the number of perfect matchings.
figure 2

a Two-fold counts of channels in 20 s where the central wavelengths of channels 15 ~ 1 correspond to CH21 ~ CH35 of the standard DWDM and channels −1 ~ −15 correspond to CH39 ~ CH53. be The channel groups of two-vertex graphs (b) and four-vertex graphs (d). The two-photon (c) counts in 20 seconds and four-photon (e) counts in 30 min in the experiments for corresponding graphs when pump is fixed in 200 μW. The error bars (±1σ) are estimated from Poissonian photon statistics.

Fixing the average power of pump with 200 μW in front of chip, we group the photon pairs to configure four 2-vertex graphs and five 4-vertex graphs as shown in Fig. 2b, d, respectively. The bandwidth of every channel is 60 GHz. The two-fold and four-fold coincidences are directly mapped to the graph’s perfect matching numbers, as shown in Fig. 2c, e, respectively. The right Y-axis aligns 1 of the counts of graph G1 and graph G5, respectively, meaning the basic unit of coincidence of one perfect matching. We find that the estimated values can basically correspond to the number of perfect matchings.

Next, we configure two six-vertex graphs, an eight-vertex graph and a ten-vertex graph, and record all four-fold events in 1 hour, respectively. As a simple example for understanding, we configure the six-vertex graph in Fig. 3a by frequency grouping in WSS which distributes channels {−2, −4} to output a, {−3, −5} to b, {1, 2, 3} to c, {4, 5, 6} to d, −1 to e, and −6 to f. The transmission state of outputs of WSS is shown in Fig. 3b. We obtained raw four-photon distributions of these four graphs as shown in Fig. 3. We use the similarity of the distributions \(F=| {\vec{D}}_{exp}\cdot {\vec{D}}_{the}| /(| {\vec{D}}_{exp}| \cdot | {\vec{D}}_{the}| )\) to characterize the results. We obtain F = 99.33% and F = 99.48% for the sparse and dense six-vertex graphs, respectively, F = 97.68% and F = 95.27% for the eight-vertex graph and the ten-vertex graph, respectively. Dashed lines are y = 0.5, y = 1.2, and y = 2.5 to separate the data to the perfect matchings number of {0, 1, 2, 3}. An accuracy of 100% is achieved for these simple graphs under the criteria. We further configured an eight-vertex graph and recorded six-photon events. For obtaining enough six-fold counts, we properly brighten the pump and add the run time to 18 hours. The normalized six-photon distribution is shown in Fig. 3g, with a fidelity of 94.54%.

Fig. 3: Experimental results for calculating the number of perfect matchings of subgraphs.
figure 3

ac The channel groups of a sparse six-vertex graphs (a) and the transmission setting of WSS, which result in the four-photon distribution (c), recording 1584 four-fold counts. A six-vertex (d), an eight-vertex (e), and a ten-vertex (f) graph, which are constructed in the experiment. Experimental (green) and theoretical (orange) four-photon distributions (gi) in one hour, for the graphs in (ac), respectively. There are 3909, 6919 and 7419 four-fold counts recorded, respectively. j An eight-vertex configured in the experiment. k The six-photon distribution in 18 hours for the graph in (j), with 1042 six-fold counts recorded in total. The error bars (±1σ) are estimated from Poissonian photon statistics.

In addition, multi-photon processors can enhance classical stochastic algorithms for solving NP problems, such as SAT28, max-clique28,29,30, and dense subgraph31,32,33. The enhancement comes from the positive correlation between perfect matchings counts and the density of the graph31. Thus, we can use biased randomness from perfect matchings sampler to enhance stochastic algorithms for these problems. The SAT is the problem of finding an assignment that satisfy the given Boolean formula. A clausal formula can be converted into a graph, and one SAT solution will correspond to a clique of the graph28. We set a clausal formula with four clauses, \(F=({x}_{1}+\overline{{x}_{3}})\cdot (\overline{{x}_{2}}+{x}_{1})\cdot ({x}_{2}+{x}_{3})\cdot (\overline{{x}_{1}}+\overline{{x}_{2}})\). It can be reduced to a 4-Clique problem of an eight-vertex graph shown in Fig. 4a. The four-photon distribution in 2 h is shown in Fig. 4b, with a fidelity of 98.25%. The four-vertex subgraph with the most samples is a clique, plotted with the red line in Fig. 4a. It means that the formula F is satisfiable, and the corresponding assignment is x1 = True, x2 = False, and x3 = True. On the other hand, the densest subgraph problem is defined to find the densest k-vertex subgraph with the largest density from a given n-vertex graph(k < n)34. No polynomial-time approximation scheme exists for the problem. To avoid being fooled by special graph structures, stochastic algorithms that employ uniform randomness for exploration are always preferable in solving the densest subgraph of a general graph35. We verify the enhancement of random search by perfect matchings samples. For example, to find the densest subgraph of a 16-vertex graph with weighted edges as shown in Fig. 4c, we experimentally obtained the four-photon distribution in 2 h shown in Fig. 4d, with a fidelity of 92.49%. Note that the perfect matching number of an edge-weighted graph is a more general definition, that the weight of every perfect matching contains a coefficient of the multiplication of the weights of related edges. Then, we use the samples to identify the densest four-vertex subgraph via random search31,32. In the random search, we draw several samples, each containing four vertices, compare the density of the samples, and select the one with the maximum density. We vary the number of samples drawn from 1 to 300 and repeat 400 times for each value. Figure 4e shows the mean density obtained with a different number of samples. The ideal curve corresponds to the loss-free case. We can see that the protocol whose samples are drawn from the perfect matching solver performs markedly better than the uniform sampling.

Fig. 4: Enhancing solving algorithms for graph-related searching problems.
figure 4

a An eight-vertex graph related to the SAT problem. b Experimental and theoretical four-photon distribution for the graph of SAT problem in (a). The error bars (±1σ) are estimated from Poissonian photon statistics. c A sixteen-vertex weighted graph for finding densest subgraph. d Experimental and theoretical four-photon distribution for the graph in (c). e Mean density of the four-vertex subgraph as a function of the number of samples drawn. The blue line indicates a random search with uniform sampling. The red and purple lines use ideal and experimental samples from distributions of perfect matching sampler in (d), respectively. The shadows represent one standard deviation. The dashed line indicates the density of the densest four-vertex subgraph.

The experiments achieve high fidelities beyond 90%, significantly higher than the previous experiments for perfect matching tasks with coherent interferences17,28, present the conveniences and scalability of graph configuration, and show the potentials for practical applications. The imperfection of distributions should be caused by the accidental coincidences of single photons and inexhaustive filtering.

Discussion

The solving process of the proposed perfect matching solver is not a conventional search or optimization but to naturally reserve and count perfect matchings from the superposition of all possible states arriving at detectors simultaneously, which is incapable in classical methods. On the other hand, different from common path-encoded experiments in which the depth of optical operation and the number of photon sources need to increase when the graph scales up15,17,28, in our optical perfect matching solver, the photon source is fixed and the optical length of nonlinear process is a constant, independent of the problem’s size. Moreover, it is simple to transform the graph by WSS without changing the optical paths or crystals.

In the experiments, the dispersion of the waveguide and fibers is much less than 1 ps, thus do not need to be considered, because the resulting time difference is much smaller than the coincidence window. On the other hand, our scheme avoids destructive interference between perfect matchings, so it can achieve high fidelity, and moreover, the experiment do not need to consider the indistinguishability of photons. Therefore, it avoids the requirement of additional filtering process or structural design for photon’s spectral purity36. And thus it also prevents the decrease of performance in common interference methods caused by inevitable distinguishability of photons.

Due to the method being purity-independent, one can continuously divide the channels at arbitrary intervals, which means that the available channels can be greatly increased by reducing the bandwidth of each channel and supplementing the pump light intensity. The size of the graph, specifically, the maximum numbers of edges and vertices are determined by the total bandwidth of the photon pair and the number of outputs of the WSS, respectively. The bandwidth of photon pairs is more than 5 THz in our chip, and the minimum transmission bandwidth of WSS is 10 GHz, which means it can support about 500 edges at most theoretically. Moreover, schemes for ultrabroadband phase-matching up to hundreds of nanometers in various materials have been reported37,38,39, which can support larger experiments. On the other hand, the number of outputs of our WSS in hand is 16, but there is no theoretical limit to the number of outputs, which can be increased as required. As with the other multiphoton experiments, our experiment exists the tradeoff between the brightness of the photon-pair source and the strengh of high-order excitation. Reducing the loss rate, raising the filtering level, or increasing the repetition rates of the pulse can promote the signal-to-noise rate to obtain coincidence with more photons. When optimize the experiment conditions and extend the graph, the event of hundreds of photons can be detected, which may lead to computational superiority due to the hardness of the exact simulation of a perfect matchings sampler, even though constantly developing approximation methods with errors may minish the advantage.

For the problems that may be more hard to simulate, such as estimating the Hafnian of a complex-value matrix, multiphoton interference may be required. It is promising to engineer different nonlinear processes to construct graphs40,41,42, which can take advantages of frequency dimension while maintain the coherence. In this case, the high-purity source is required that the microresonator structure may help36,43,44.

In summary, we have proposed and experimentally demonstrated a multi-photon scheme for solving perfect matching problems utilizing broadband photon pairs and frequency grouping. Our perfect matching sampler can enhance the random search in solving NP problems, including SAT and dense subgraph, showing potential for practical applications. The experimental scale of the graph in this work reaches 16 vertices. Additionally, in terms of the coincidence scale, we measure the six-photon distribution. Meanwhile, the detected distributions have high fidelities beyond 90% for all configured graphs. Our work provides a promising tool to take advantage of frequency dimension for perfect matching solving, which can simply transform or scale up the object graph by programming a WSS. A wider photon pair source and a WSS with more outputs are required when extending the experiment. More explorations are needed to further develop the potential applications and find the practical benefit of the proposed perfect matching solver.

Methods

Theoretical description

Broadband photon-pair source can be realized by χ(2) nonlinear processes such as spontaneous parametric down-conversion, or χ(3) nonlinear process such as spontaneous four-wave mixing(SFWM). We take SFWM on the silicon waveguide for example. Silicon waveguide pumped by pulse laser probabilistically creates photon pairs in a broad range of spectrum from SFWM. We can describe the creation process as

$$\hat{U}\approx 1+g\left(\iint \,d{\omega }_{s}d{\omega }_{i}{\hat{a}}_{{\omega }_{s}}^{{{\dagger}} }{\hat{a}}_{{\omega }_{i}}^{{{\dagger}} }\right)+\frac{{g}^{2}}{2}{\left(\iint d{\omega }_{s}d{\omega }_{i}{\hat{a}}_{{\omega }_{s}}^{{{\dagger}} }{\hat{a}}_{{\omega }_{i}}^{{{\dagger}} }\right)}^{2}+O({g}^{3}),$$
(1)

where \({\hat{a}}_{{\omega }_{s}}^{{{\dagger}} }\) and \({\hat{a}}_{{\omega }_{i}}^{{{\dagger}} }\) are single-photon creation operators with frequency ωs and ωi, and g 1 is the four-wave mixing amplitude. We partition the spectrum of photons to discrete frequency modes, that the state can be be approximate to

$$| \psi \left.\right\rangle=\hat{U}| vac\left.\right\rangle \approx \left[1+g\left(\sum\limits_{k}{\hat{a}}_{{\omega }_{k}}^{{{\dagger}} }{\hat{a}}_{{\omega }_{-k}}^{{{\dagger}} }\right)+\frac{{g}^{2}}{2}{\left(\sum\limits_{k}{\hat{a}}_{{\omega }_{k}}^{{{\dagger}} }{\hat{a}}_{{\omega }_{-k}}^{{{\dagger}} }\right)}^{2}+O({g}^{3})\right]| vac\left.\right\rangle \\ =g\left(\sum\limits_{k}| {\omega }_{k},{\omega }_{-k}\left.\right\rangle \right)+\frac{{g}^{2}}{2}{\left(\sum\limits_{k}| {\omega }_{k},{\omega }_{-k}\left.\right\rangle \right)}^{2}+\left[1+O({g}^{3})\right]| vac\left.\right\rangle,$$
(2)

where \(| vac\left.\right\rangle\) is the vacuum state, and k = 1, 2, 3, … represent the frequency modes. Then these modes will be send to different paths according to the target graph. The total n-fold(n is even in our description) coincidence rate of any n paths {abcd, …} can be expressed as

$$\begin{array}{rcl}{R}_{n}^{tot}& =&M\frac{{R}_{ab}^{tot}}{M}\frac{{R}_{cd}^{tot}}{M}\cdots+\cdots+M\frac{{R}_{ac}^{tot}}{M}\frac{{R}_{bd}^{tot}}{M}\cdots+\cdots \\ &&+M\frac{{R}_{ad}^{tot}}{M}\frac{{R}_{bc}^{tot}}{M}\cdots+\cdots \,,\end{array}$$
(3)

which contains (n − 1)!! terms in total, that is, the number of perfect matchings of an n-vertex complete graph. In the Eq. (3), M is the repetition rate of the pulse for pumping, and

$${R}_{ij}^{tot}={R}_{ij}+\frac{{R}_{i}}{M}\cdot \frac{{R}_{j}}{M}\cdot M$$
(4)

is the total two-fold coincidence of two paths {ij} (ij = abac, …). The first term of Eq. (4), Rij, is the true coincidence of two path ij produced by SFWM, and the second term is the accidental coincidence of the single photons in two paths ij. If M is large enough and Ri(j)/M is too small to be considered, the second term can be neglected, that is \({R}_{ij}^{tot}\approx {R}_{ij}\).

Assuming that the two-photon counts of each edge have been balanced to R2, that is

$${R}_{ij}=\left\{\begin{array}{cc}{n}_{e}{R}_{2},&{n}_{e}\,\,{{{\rm{edges}}}}\, {{{\rm{between}}}}\, {{{\rm{vertices}}}}\,\,i\&j\\ 0,&\,{{{\rm{no}}}}\, {{{\rm{edge}}}}\, {{{\rm{between}}}}\, {{{\rm{vertices}}}}\,\,i\&j\end{array}\right.,$$
(5)

we can calculate or experimentally measure a standard unit of n-fold coincidence corresponding to one perfect matching, which is

$${R}_{n,s}\approx {\left(\frac{{R}_{2}}{M}\right)}^{n/2}\cdot M.$$
(6)

Then we can estimate the number of perfect matchings by Eqs. (3) and (6) as

$$\#{{{\rm{PM}}}}\approx \frac{{R}_{n}^{tot}}{{R}_{n,s}}.$$
(7)

We then take the frequency grouping shown in Fig. 1d for example, where frequency modes ω1 and ω2 are distributed to path a, frequency modes ω−1 and ω−4 are distributed to path b, frequency modes ω−2 and ω−3 are distributed to path c, and frequency modes ω3 and ω4 are distributed to path d. The effect caused by high-order terms in Eq. (2) can be neglected because of the small coefficient g. Thus we keep only the four-fold terms for second-order SFWM and neglect the other terms in Eq. (2), that the state after frequency grouping can be expressed as

$$| \psi \left.\right\rangle = \frac{{g}^{2}}{2}\left(| {\omega }_{1,a},{\omega }_{-1,b},{\omega }_{1,a},{\omega }_{-1,b}\left.\right\rangle+| {\omega }_{2,a},{\omega }_{-2,c},{\omega }_{2,a},{\omega }_{-2,c}\left.\right\rangle \right.\\ +\left.| {\omega }_{3,d},{\omega }_{-3,c},{\omega }_{3,d},{\omega }_{-3,c}\left.\right\rangle+| {\omega }_{4,d},{\omega }_{-4,b},{\omega }_{4,d},{\omega }_{-4,b}\left.\right\rangle \right)\\ +{g}^{2}\left(| {\omega }_{1,a},{\omega }_{-1,b},{\omega }_{2,a},{\omega }_{-2,c}\left.\right\rangle+| {\omega }_{1,a},{\omega }_{-1,b},{\omega }_{3,d},{\omega }_{-3,c}\left.\right\rangle \right.\\ +| {\omega }_{1,a},{\omega }_{-1,b},{\omega }_{4,d},{\omega }_{-4,b}\left.\right\rangle+| {\omega }_{2,a},{\omega }_{-2,c},{\omega }_{3,d},{\omega }_{-3,c}\left.\right\rangle \\ \left.+| {\omega }_{2,a},{\omega }_{-2,c},{\omega }_{4,d},{\omega }_{-4,b}\left.\right\rangle+| {\omega }_{3,d},{\omega }_{-3,c},{\omega }_{4,d},{\omega }_{-4,b}\left.\right\rangle \right),$$
(8)

where ωk,h represents a photon at path h with frequency ωk that k = ±1, ±2, ±3, ±4, and h = abcd. If we do the coincidence measurement that each path has one and only one photon, only the sixth and the ninth terms in Eq. (8) can be detected which are correspond to two perfect matchings as shown in the right figure of Fig. 1d. Thus the coincidence rate should be proportional to the number of perfect matchings of the target graph. If we have balanced the two-photon coincidences, the number of perfect matchings can be estimated as

$$\#{{{{\rm{PM}}}}}_{abcd}\approx \frac{{R}_{abcd}^{tot}}{{R}_{4,s}}\approx \frac{\frac{{R}_{ab}}{M}\cdot \frac{{R}_{cd}}{M}\cdot M+\frac{{R}_{ac}}{M}\cdot \frac{{R}_{bd}}{M}\cdot M}{{\left(\frac{{R}_{2}}{M}\right)}^{2}\cdot M}=2.$$
(9)

This theory can also be extended to cases of more than one photon in the same output. In general, when construct an N-vertex graph with an N × N adjacency matrix A, the measurement probability is given by

$$\Pr (\bar{n})=\frac{1}{Z}\#{{{\rm{PM}}}}({A}_{s}),$$
(10)

where \(\bar{n}=\{{n}_{1},{n}_{2},\ldots,{n}_{N}\}\) means nj photons in the j-th output(j = 1, 2, …, N) and Z is the normalization coefficient. When constraining nj = {0, 1}, As is the sub-matrix of A that keeps the j-th row and column of A for all nj = 1. If we lift the the constraint of photon numbers in the outputs, As is the matrix that repeats the jth row and column of A with nj times, for all j from 1 to N.

Experimental details

A pulsed laser with a repetition rate of 60 MHz, a bandwidth of 0.11 nm, and a central wavelength of 1547.68 nm is filtered by a dense wavelength division multiplexing module(DWDM) at first to filter noises except the pump laser. The filtered pump passes through a fiber polarization controller before being coupled to the on-chip grating coupler. Broadband photon pairs are generated by the spontaneous four-wave mixing(SFWM) in the silicon waveguide. Then, three cascaded single-channel DWDMs are set to filter out the pump. Photons in different frequency channels are grouped into specific outputs simultaneously in the WSS, which consists of a grating mirror, a liquid crystal, and a cylindrical mirror, for configuring graphs. We adjust the attenuation of WSS to make the two-photon counts of each channel as equal as possible. After frequency grouping, photons in each output are adjusted by a polarization controller and then detected by a superconducting nano-wires single-photon detector(SNSPD). Photons are converted into electrical signals in detectors and are analyzed by a coincidence logic module.

The chip was fabricated on a silicon-on-insulator material system, where the single-mode waveguide was designed with a length of about 1.5 cm, a width of 500 nm, and a thickness of 220 nm. The average losses of photons from generation to detection are about 1.5 dB for transmission loss in the waveguide, 5 dB for coupling loss of the grating coupler, 4.5 dB for the WSS, 2 dB for the total insertion loss of three DWDMs and polarization controller, and 0.7 dB for the single-photon detectors.