## Introduction

Contextuality has gained great importance in the development of quantum information and computation1,2,3. This key characteristic feature of quantum mechanics represents one of the most valuable quantum resources4,5,6,7. The well-known Bell–Kochen–Specker theorem8,9,10,11,12,13 states that no non-contextual hidden-variable theory is able to reproduce the predictions of quantum mechanics. Peres12 and Mermin13 presented a simpler proof that became known in the literature as the Peres–Mermin square. Tests of quantum contextuality have been undertaken with various physical systems14,15,16,17,18,19,20,21,22. However, these tests required the generation of special quantum states. Cabello23 and Yu et al.24 derives a set of inequalities that are satisfied by a non-contextual hidden-variable theory but are violated by quantum mechanics for any quantum state. This provides an opportunity to test non-contextuality with finite-precision experiments25,26,27,28,29 without the requirement of special quantum states.

In this paper, we show an experimental proof of the Kochen–Specker theorem in a four-dimensional Hilbert space. We perform an experiment with single photons that demonstrates a state-independent conflict with non-contextuality23. Despite imperfections and possible measurement disturbance, our results cannot be explained in non-contextual models. We also provide a theoretical analysis of test of contextuality with a coherent light field and show how the definitions affect the emergence of non-classical correlations.

## Results

Consider nine binary ±1 observables that can be measured on a single system. Based on the compatibility relations, these measurements can be performed in the following triples {A, a, α}, {B, b, β}, {C, c, γ}, {A, B, C}, {a, b, c}, {α, β, γ}. Any theory in which the nine observables have predefined non-contextual outcomes −1 or 1 must satisfy the following inequality

$$\begin{array}{ll}\chi \quad=&\langle A\cdot a\cdot \alpha \rangle +\langle B\cdot b\cdot \beta \rangle +\langle C\cdot c\cdot \gamma \rangle \\ &+\,\langle A\cdot B\cdot C\rangle +\langle a\cdot b\cdot c\rangle -\langle \alpha \cdot \beta \cdot \gamma \rangle \le 4,\end{array}$$
(1)

where 〈ABC〉 denotes the ensemble average of the product of the three outcomes of measuring the mutually compatible observables A, B, and C.

For any four-dimensional system, there is a set of observables for which the prediction of quantum mechanics is χ = 6 for any quantum state of the system23,25. We take

$$\begin{array}{rcl}&&A=X\otimes {\mathbb{1}},a={\mathbb{1}}\otimes X,\alpha =X\otimes X,\\ &&B={\mathbb{1}}\otimes Y,b=Y\otimes {\mathbb{1}},\beta =Y\otimes Y,\\ &&C=X\otimes Y,c=Y\otimes X,\gamma =Z\otimes Z\end{array}$$
(2)

as examples where X, Y, and Z are Pauli operators and test the prediction on different quantum states of a single-photon system.

### Experimental test of state-independent contextuality

We demonstrate experimental test of the state-independent non-contextuality inequality. The purpose of the experiment is to test the prediction on different quantum states of a single-particle system. The physical system employed for this experiment is a single photon carrying two qubits of quantum information. The bases of quantum states are encoded as $$\{\left|0\right\rangle =\left|UH\right\rangle ,\left|1\right\rangle =\left|UV\right\rangle ,\left|2\right\rangle =\left|DH\right\rangle ,\left|3\right\rangle =\left|DV\right\rangle \}$$, where U and D denote the upper and lower spatial mode of single photons, respectively, and H and V denote their horizontal and vertical polarizations, respectively.

First, we generate 26 photonic states shown in Table 1 to be tested. Photon pairs are generated via the spontaneous parametric down-conversion process as illustrated in Fig. 1. One of the photon is treated as a trigger and the other is the heralded single photon30,31,32,33,34,35,36. A polarization beam splitter (PBS), a beam displacer (BD), and half-wave plates (HWPs) are used to prepare photonic qudits in total with 15 pure quantum states being tested. To generate the rest 9 mixed states, we use a quartz crystal (QC) placed in front of the first BD to reduce the coherence of the photons in different spatial modes. After the first BD, the photons are separated into the upper and lower path depending on their polarizations37,38. Then QCs are inserted into two path and reduce the coherence of the photons with different polarizations. The coherence length of the photons is Lc ≈ λ2λ, where λ is the central wavelength of the source and Δλ is the spectral width of the source. Hence, the thickness of QCs should be at least 23.97 mm. In our experiment, it is about 28.77 mm.

Then we apply sequential measurements of three compatible observables on the 26 states shown in Table 1, where “measurement−i” (i = 1, 2, 3) describes the set-up for measuring one of the nine observables. After the preparation stage, the photons enter the device measurement−1 and result in one of the two possible outcomes of the measurement. The device measurement−i maps eigenstates of the observable to a fixed spatial mode and polarization. Then we need to recreate the eigenstates of the measured observable on the photonic qudit before photons entering measurement−2. After the third measurement is performed, finally, the photons are detected by the single-photon avalanche photodiode (APD) placed at the outputs of the devices.

The measurements of observables a and B are just polarization rotations $${U}_{M}=|H\rangle\langle {\psi }^{+}|+|V\rangle \langle {\psi }^{-}|$$, which can be implemented by wave plates at certain setting angles and a PBS performing the projective measurement of $$Z=|H\rangle \langle H|-|V\rangle \langle V|$$. Here $$\left|{\psi }^{\pm }\right\rangle$$ are the eigenstates of X for the observable a and those of Y for B, respectively, whereas the measurements of observables A and b are performed only on the spatial modes. We use BDs to split and then combine the photons with certain polarizations into the same spatial mode, which equals to a transformation from the spatial mode to the polarization mode, and apply the polarization rotation via wave plates. After that, the projective measurement of Z is performed on the basis $$\{\left|H\right\rangle ,\left|V\right\rangle \}$$. For the other observables α, β, C, c, and γ that are the products of two Pauli operators, those measurements can be implemented by a polarization rotation, a transformation between spatial and polarization modes, and another polarization rotation followed by a projective measurement of Z.

As illustrated in Fig. 1, we use the sequential measurement {A, a, α} as an example. The first step is to realize the measurement of A with HWPs (H4–H7), BDs (BD2–3), and PBS2, where two BDs and H4 and H5 build a Mach–Zehnder interferometer for a transformation from spatial to polarization modes, and H6 and H7 are used for a rotation on the polarization modes. Then, with HWPs (H8–13) and BDs (BD4–5), we recreate the corresponding eigenstates of A for further measurements. The second step is to realize the measurement of a with HWPs (H14–15 for a rotation on the polarization modes) and PBS3 and to recreate the eigenstates of a with HWPs (H16–17). The last step is to realize the measurement of α with HWPs, BDs, and PBS4, where H18 and H21–23 are used to realize polarization rotations before and after the basis transformation via BD6–7 and H19–20. We repeat this for eight times. For each time, by choosing proper angles of the HWPs (H7–8, H15–16, H22–23), the outcome of the measurement is one of {1, 1, 1}, {1, 1, −1}, {1, −1, 1}, {1, −1, −1}, {−1, 1, 1}, {−1, 1, −1}, {−1, −1, 1}, and {−1, −1, −1}. The probability of the outcome is obtained by the coincidence counts of the APDs. We record clicks for 2 s and register about 20,000 single photons. The probability for more than one photon pair is <10−4, hence neglected. Coincidence counts are used to construct the measured probabilities of eight outcomes of each set of measurements.

The set-up in Fig. 1 only corresponds to one of the eight possible paths and that the input–output statistics have been obtained by repeating the experiment, with the appropriate choices of optical elements, for eight times and recording the number of photons in the detection time 2 s. The detection efficiency of APDs is about 60% and the efficiency of the coincidence detection is then 36%. The efficiency of free-space-to-single-mode-fiber coupling is about 75%. The efficiency of the set-up involving all the optical elements is about 59%. Thus, the global detection efficiency in the experiment is about 15.9%. The imperfections in the experiment include the imperfections of the interferometers and inaccuracies of wave plates. The visibility of the interferometer is about 99.8%. The accuracy of the wave plates is about ±1°.

To test the prediction of the state-independent violation of non-contextuality inequality χ23, we repeat the experiment for 26 quantum states. With the measured probabilities, the corresponding violations evaluated using the collected data are shown in Fig. 2a. We find that all values χ for the non-contextuality inequality fall within the range from 5.784(5) to 5.877(3), which meets the prediction of quantum mechanics. The inequality (1) is violated by at least 387 standard deviations. We also present measurement results for each experimental set-up for two states $$\left|{\psi }_{1}\right\rangle$$ and $$\left|{\psi }_{15}\right\rangle$$ (in Table 1). Probabilities for each outcome as well as values of the correlations are shown in Fig. 2b, c.

The compatibility of measurements in contexts is an important issue in the experimental test of contextuality. Here, to resolve the compatibility problem, in the case of imperfect measurements from a hidden variable viewpoint, we test a violation of the disturbed hidden-variable inequality first presented in ref. 26 that determines jointly the probabilities of the results of all sequences of measurements

$$\begin{array}{ll}\chi ^{\prime} =&\!\!\langle A\cdot \alpha \rangle +\langle B\cdot \beta \rangle +\langle A\cdot B\rangle -\langle \alpha \cdot \beta \rangle -2p(\alpha \cdot A\cdot \alpha )\\& -\, 2p(\beta \cdot B\cdot \beta )-2p(B\cdot A\cdot B)-2p(\beta \cdot \alpha \cdot \beta )\le 2,\end{array}$$
(3)

where 〈Aα〉 denotes the ensemble average if A is measured before a and p(αAα) denotes the probability that measuring A introduces a change in the value of α if the sequential measurement of αAα is measured. We use the state $$\left|{{\Psi }}\right\rangle \propto \left|UH\right\rangle +(\sqrt{2}-1)\left|UV\right\rangle +i(\sqrt{2}-1)\left|DH\right\rangle +i\left|DV\right\rangle$$ to test this inequality. For the inequality (1), we have χ = 5.831(4) > 4, which violates the inequality by 448 standard deviations. For the inequality (3), we have $$\chi ^{\prime} =2.501(11)\, > \,2$$, which violates the inequality by 45 standard deviations. This proves that even disturbances of the hidden variables during not perfectly compatible measurements cannot explain the given experimental data.

We provide another method26 to characterize the compatibility of different measurement by switching the orders of the measurements. We take $$\left|{\psi }_{8}\right\rangle =(\left|1\right\rangle +\left|2\right\rangle )/\sqrt{2}$$ as an example. In Fig. 3, we show the measured absolute values of the ensemble average of the products of observables for six possible permutations within rows and columns of the Peres–Mermin square, which fall within the range from 0.957(2) to 0.986(1) and agree with theoretical prediction 1. We find that all values for the non-contextual inequality fall within the range from 5.786(5) to 5.868(4). Even with experimental imperfections, the experimental violation of the non-contextual inequality still agrees with the quantum-mechanical prediction.

All experimental tests of hidden-variable theories are subject to various possible loopholes. In our experiment, photon loss opens up a detection efficiency loophole. Thus, fair-sampling assumption is taken here, which assumes that the event selected out by the photonic coincidence is an unbiased representation of the whole sample17,18,19.

### Theoretical analysis of test of contextuality with a coherent light field

Although contextuality is considered as intrinsic signature of non-classical behavior, a question on if or not classical light can be used to test contextuality has been always raised. We follow the idea in ref. 25, which have been tested in refs. 21,39, and show a different result by replacing the heralded single photons by the classical light. Compared to single photons providing a well-defined measurement event as for each set of measurements photons are all detected by D1 associated with trigger photons at D0, the probability for multiple photons is not negligible for a coherent light field $$\left|\alpha \right\rangle$$ as photon source as illustrated in Fig. 4. Thus, we need to redefine measurement events as E1 for only one detector clicking and E2 for more than one detector clicking (There is also a probability that no detector clicks due to the vacuum component of the coherent light. However, we can still use fair-sampling assumption to exclude this case and then only registered photons count.). For a perfect single photon source, E1 = E2, whereas, for a coherent light, E1 E2. Based on the definition of the measurement events, we use the conditional probabilities P(aiajakE$$\iota$$) ($$\iota$$ = 1, 2) under E$$\iota$$ instead of P(aiajak) to calculate the contribution from non-classical correction. The numerical simulations of the left- and right-hand sides of the inequality under E1 and E2 are shown in Fig. 5. We find that the violation of the non-contextuality inequality under E1 is similar to that of single photons, which reaches the quantum bound. That is because only one detector clicks and the coherent light is postselected into an imperfect single photon source with a small postselection probability, whereas, for E2, a significant violation is observed when $$\bar{n}$$ is small enough (<0.519). The violation disappears with the increase of $$\bar{n}$$ because the multi-photon probability cannot be negligible.

We derive the theoretical predictions of test of contextuality with a coherent light field $$\left|\alpha \right\rangle ={\sum }_{n}{e}^{-\frac{| \alpha {| }^{2}}{2}}\frac{{\alpha }^{n}}{{(n!)}^{1/2}}\left|n\right\rangle$$. The probability of detecting n photons subjects to the Poissonian distribution $$P(n)={\left|\langle n| \alpha \rangle \right|}^{2}={e}^{-| \alpha {| }^{2}}\frac{| \alpha {| }^{2n}}{n!}$$. Assume that the initial state is

$$\left|{{\Psi }}\right\rangle ={\left|\alpha \right\rangle }_{1}{\left|0\right\rangle }_{2}{\left|0\right\rangle }_{3}{\left|0\right\rangle }_{4},$$
(4)

where the subscripts indicate the modes of the input light. After passing through the set-up of four sets of measurements {A, a, α}, {B, b, β}, {A, B, C} and {a, b, c}, the final state is

$$\left|{{\Psi }}^{\prime} \right\rangle ={\left|\frac{\alpha }{2}\right\rangle }_{{D}_{1}}{\left|0\right\rangle }_{{D}_{2}}{\left|0\right\rangle }_{{D}_{3}}{\left|\frac{\alpha }{2}\right\rangle }_{{D}_{4}}{\left|0\right\rangle }_{{D}_{5}}{\left|\frac{\alpha }{2}\right\rangle }_{{D}_{6}}{\left|\frac{\alpha }{2}\right\rangle }_{{D}_{7}}{\left|0\right\rangle }_{{D}_{8}}.$$

For the measurement {C, c, γ}, the final state is

$$\left|{{\Psi }}^{\prime\prime} \right\rangle ={\left|\frac{\alpha }{\sqrt{2}}\right\rangle }_{{D}_{1}}{\left|0\right\rangle }_{{D}_{2}}{\left|0\right\rangle }_{{D}_{3}}{\left|0\right\rangle }_{{D}_{4}}{\left|0\right\rangle }_{{D}_{5}}{\left|0\right\rangle }_{{D}_{6}}{\left|\frac{\alpha }{\sqrt{2}}\right\rangle }_{{D}_{7}}{\left|0\right\rangle }_{{D}_{8}}.$$

Whereas, for {α, β, γ}, the final state is

$$\left|{{{\Psi }}}^{\prime\prime\prime }\right\rangle ={\left|0\right\rangle }_{{D}_{1}}{\left|0\right\rangle }_{{D}_{2}}{\left|\frac{\alpha }{\sqrt{2}}\right\rangle }_{{D}_{3}}{\left|0\right\rangle }_{{D}_{4}}{\left|\frac{\alpha }{\sqrt{2}}\right\rangle }_{{D}_{5}}{\left|0\right\rangle }_{{D}_{6}}{\left|0\right\rangle }_{{D}_{7}}{\left|0\right\rangle }_{{D}_{8}}.$$

According to the definitions of measurement events, for E1, we can derive the conditional probabilities of the set of measurement {α, β, γ}

$$P(\alpha \cdot \beta \cdot \gamma =1| E1)=0,P(\alpha \cdot \beta \cdot \gamma =-1| E1)=1.$$

For the other five sets of measurements {Ai, Aj, Ak} = {A, a, α}, {B, b, β}, {C, c, γ}, {A, B, C}, {a, b, c}, we have

$$P({a}_{i}\cdot {a}_{j}\cdot {a}_{k}=1| E1)=1,P({a}_{i}\cdot {a}_{j}\cdot {a}_{k}=-1| E1)=0.$$

For the event E2, we have

$$\begin{array}{rcl}&&P(\alpha \cdot \beta \cdot \gamma =1| E2)=P(C\cdot c\cdot \gamma =-1| E2)=\frac{-1\,+\,{e}^{\frac{| \alpha {| }^{2}}{2}}}{1\,+\,{e}^{\frac{| \alpha {| }^{2}}{2}}},\\ &&P(\alpha \cdot \beta \cdot \gamma =-1| E2)=P(C\cdot c\cdot \gamma =1| E2)=\frac{2}{1\,+\,{e}^{\frac{| \alpha {| }^{2}}{2}}}.\end{array}$$

For the other four sets of measurements {Ai, Aj, Ak} = {A, a, α}, {B, b, β}, {A, B, C}, {a, b, c}, we have

$$\begin{array}{rcl}&&P({a}_{i}\cdot {a}_{j}\cdot {a}_{k}=1| E2)=\frac{4\,-\,4{e}^{\frac{| \alpha {| }^{2}}{4}}}{1\,-\,{e}^{| \alpha {| }^{2}}},\\ &&P({a}_{i}\cdot {a}_{j}\cdot {a}_{k}=-1| E2)=\frac{-3\,+\,4{e}^{\frac{| \alpha {| }^{2}}{4}}\,-\,{e}^{| \alpha {| }^{2}}}{1\,-\,{e}^{| \alpha {| }^{2}}}.\end{array}$$

We use the conditional probabilities P(aiajakE$$\iota$$) ($$\iota$$ = 1, 2) under E$$\iota$$ instead of P(aiajak) to calculate the contribution from non-classical correction. For the measurement event E1, we have

$$\begin{array}{lll}\langle \alpha \cdot \beta \cdot \gamma | E1\rangle &=&-1,\\\langle A\cdot a\cdot \alpha | E1\rangle &=&\langle B\cdot b\cdot \beta | E1\rangle =\langle C\cdot c\cdot \gamma | E1\rangle \\ &=&\langle A\cdot B\cdot C| E1\rangle =\langle a\cdot b\cdot c| E1\rangle =1,\end{array}$$

and then

$${\chi }_{E1}=6.$$
(5)

Hence, the violation of the inequality (1) under E1 is similar to that of single photons, which reaches the quantum bound.

For the measurement event E2, we have

$$\begin{array}{lll}\langle \alpha \cdot \beta \cdot \gamma | E2\rangle &=&\frac{-3\,+\,{e}^{\frac{| \alpha {| }^{2}}{2}}}{1\,+\,{e}^{\frac{| \alpha {| }^{2}}{2}}},\langle C\cdot c\cdot \gamma | E2\rangle =\frac{3\,-\,{e}^{\frac{| \alpha {| }^{2}}{2}}}{1\,+\,{e}^{\frac{| \alpha {| }^{2}}{2}}},\\ \langle A\cdot a\cdot \alpha | E2\rangle &=&\langle B\cdot b\cdot \beta | E2\rangle =\langle A\cdot B\cdot C| E2\rangle \\ &=&\langle a\cdot b\cdot c| E2\rangle =\frac{7\,-\,8{e}^{\frac{| \alpha {| }^{2}}{4}}\,+\,{e}^{| \alpha {| }^{2}}}{1\,-\,{e}^{| \alpha {| }^{2}}},\end{array}$$

and then

$${\chi }_{E2}=\frac{34+2{e}^{\frac{| \alpha {| }^{2}}{4}}-6{e}^{\frac{| \alpha {| }^{2}}{2}}-6{e}^{\frac{3| \alpha {| }^{2}}{4}}}{1+{e}^{\frac{| \alpha {| }^{2}}{4}}+{e}^{\frac{| \alpha {| }^{2}}{2}}+{e}^{\frac{3| \alpha {| }^{2}}{4}}}.$$
(6)

Thus, for E2, a significant violation is observed when $$\bar{n}$$ is small enough (<0.519). The violation disappears with the increase of $$\bar{n}$$ because the multi-photon probability cannot be negligible.

## Discussion

The Kochen–Specker theorem states that no non-contextual hidden-variable theory can reproduce the predictions of quantum mechanics for correlations between measurement outcomes of some sets of observables. In this work, we experimentally demonstrate a test of state-independent contextuality in a four-dimensional Hilbert space with single photons. We show that 26 different single-photon states violate an inequality that involves correlations between results of sequential compatible measurements by at least 387 standard deviations. Despite imperfections and possible measurement disturbance, under the assumption of fair sampling, our results cannot be explained in non-contextual models. We also provide a theoretical analysis of test of contextuality with a coherent light field and show how the definitions affect the emergence of non-classical correlations. Compared to single photons that manifest contextuality, contextuality for classical coherent light strongly depends on the specific definition of measurement events, which is equivalent to projecting the components of the inputs into the non-classical states. Our theoretical analysis shows the importance of the definition of measurement events to demonstrate contextuality. By this method, it is possible to figure the boundary between the non-classical photon source and the classical light field. Our theoretical analysis provides the new meaning of the classical simulations of the fundamental phenomena of quantum systems. This work sheds new light on the role of quantum mechanics in quantum information processing. We expect this result to stimulate new applications of quantum contextuality for quantum information processing40,41,42.

## Methods

In the process of projection measurement, it is very important to select the appropriate projection basis. In our experimental conditions, the PBS we used allows horizontally polarized light to be projected and vertically polarized light to be reflected. Therefore, we need to perform polarization rotations $${U}_{M}=|H\rangle \langle {\psi }^{+}|+|V\rangle \langle {\psi }^{-}|$$ to convert the eigenstates of polarization and spatial modes of the observables to the eigenstates of $$Z=|H\rangle \langle H|-|V\rangle \langle V|$$. After performing the projection measurement, the probability of obtaining measurement outcome 1 or −1 is equal to the probability of the photons being measured in the basis state $$\left|i\right\rangle \in \{\left|H\right\rangle ,\left|V\right\rangle \}$$.

Since in Fig. 3 it is clear that the outcome of each measurement of the sequence is encoded in the upper or lower path, thus which of the 23 = 8 possible outcomes for each sequence is given by which detector clicks. However, our experimental set-up corresponds to one of the eight paths, and the probability distributions of the eight outcomes are obtained by repeating the experiment. This experimental design will reduce the error caused by more experimental elements and make our experimental results more robust.