Sum-of-squares decompositions for a family of noncontextuality inequalities and self-testing of quantum devices

Violation of a noncontextuality inequality or the phenomenon referred to `quantum contextuality' is a fundamental feature of quantum theory. In this article, we derive a novel family of noncontextuality inequalities along with their sum-of-squares decompositions in the simplest (odd-cycle) sequential-measurement scenario capable to demonstrate Kochen-Specker contextuality. The sum-of-squares decompositions allow us to obtain the maximal quantum violation of these inequalities and a set of algebraic relations necessarily satisfied by any state and measurements achieving it. With their help, we prove that our inequalities can be used for self-testing of three-dimensional quantum state and measurements. Remarkably, the presented self-testing results rely on a single assumption about the measurement device that is much weaker than the assumptions considered in Kochen-Specker contextuality.

relations obtained from the statistics of commuting measurements that are performed on a single quantum system [KS75,Cab08,CSW14,KCBbuS08]. Indeed, the recent study [BRV + 19b, IMOK20, BRV + 19a] provides self-testing statements based on contextual correlations (or correlations that violate noncontextuality inequality). Since quantum contextual correlations are essential in many aspects of quantum computation [HWVE14,Rau13] and communication [GHH + 14, SHP19], selftesting statements are crucial for certifying quantum technology [BRV + 19a]. Apart from that, it is, nonetheless, fundamentally interesting to seek the maximum information one can infer about the quantum devices only from the observed statistics in a contextuality experiment.
In the context of nonlocality, sum-of-squares (SOS) decomposition of quantum operators associated with local-realist inequalities has been the key mathematical tool in recent years to obtain optimal quantum values and self-testing properties of quantum devices [BP15, ŠASA16, SAT + 17, KŠT + 19, SSKA19, ASTA19, Kan19,CMMN19]. Whether this line of study, albeit, restricted to nonlocal correlations, can further be extended to contextuality scenario is of great interest from the perspective of unified approach to non-classical correlations [CSW14,AC18].
In this work, we consider Klyachko-Can-Binicioğlu-Shumovsky (KCBS) scenario which comprises of one preparation and n (where n 5 is odd) number of measurements [KCBbuS08, AQB + 13, LSW11]. This is the simplest scenario capable to exhibit contextual correlations using a three-dimensional quantum system and five binary outcome measurements. It also has several implications in quantum foundation and quantum information [GBC + 14, GHH + 14, SBA17, Cab13, KanCK14, SR17, XSS + 16]. We first introduce a modified version of KCBS expression for n = 5 involving correlation between the outcomes of two sequential measurements, along with an SOS decomposition of the respective quantum operator. We describe our methodology to obtain SOS and simultaneously, generalize for n-cycle KCBS scenario where n = 2 m + 1, m ∈ N. Interestingly, the SOS decomposition holds even without the idealizations that the measurements satisfy commutativity conditions in a cyclic order. By virtue of this decomposition, we obtain the maximum quantum value of our modified n-cycle expression and a set of algebraic relations involving any quantum state and measurements that yield those maximum values. By solving those relations, we show the existence of a three-dimensional vector-space invariant under the algebra of measurement operators. Subsequently, we prove the uniqueness of the projected threedimensional measurements and state up to unitary equivalence, that is, self-testing property of the quantum devices. The presented self-testing statement relies on the premise that the measurement device returns only the post-measurement system and has no memory, while it does not rely on the commutativity relations between observables.

Preliminaries
We begin by illustrating our scenario and specifying the assumptions.
Sequential-measurement set-up. Each run of the experimental observation comprises of preparation of a physical system followed by two measurements in a sequence using one non-demolishing measurement device as depicted in Fig. 1. The measurement device has n (odd) different settings, each of which yields ±1 outcome. Let's denote the first and second measurement settings by A i and A j where i, j ∈ {1, . . . , n}. The settings are chosen such that j = i ± 1, where from now on the subscript i is taken modulo n, that is, A i±n = A i . We make the following assumption about the measurement device.

Assumption. The measurement device has no memory and returns only the actual post-measurement state.
This assumption is necessary, otherwise, any quantum statistics can be reproduced by classical systems.
By repeating this experiment many times we can obtain joint probabilities p(a i , a i±1 |A i , A i±1 ) of two measurements and single probabilities p(a i |A i ) of the first measurement, and consequently, their correlation functions, where the measurement outcomes are denoted as a i = ±1. In quantum theory the two-outcome measurements A i can be in general non-projective. However, since we do not restrict the dimension of these measurements, an extension of Naimark's dilation theorem [IMOK20] allows us to consider these measurements to be projective. Thus, we can represent the measurements by the following operators where P i are projectors acting on some finite-dimensional Hilbert space H. The preparation is represented by a quantum state that, by the same reason, can be considered pure; we denote it by |ψ .
Kochen-Specker contextuality [CSW14] pertains to the assumption that the projectors satisfy certain orthogonality relations, particularly in this scenario, Such prerequisite about the measurement device are difficult to justify in practice. Since we aim to characterize the quantum devices from their minimal features, we do not make this assumption. We will see later that orthogonality relations between projectors will be derived facts from the maximal violation of our inequality.
A general linear expression that can be considered to test nonclassicality (or noncontextuality in the usual scenario) in this set-up is given by, Using the quantum expression of the joint probabilities under the aforementioned Assumption, for example, (4) Subsequently, the optimal quantum value of the expression (3) is defined as is the quantum operator associated with the expression B and A i are of the form (2). Notice that in the usual scenario, due to commutativity relations, {A i , A i+1 } can be replaced by 2A i A i+1 . The maximal classical value η C (or noncontextual value in the usual scenario 2 ) is defined as KCBS inequality. The well known n-cycle KCBS noncontextuality inequality [AQB + 13] is of the form The maximal quantum violation of this inequality is η Q = 3 cos (π/n) − 1 1 + cos (π/n) n (8) 2 Since any noncontextual value assignment pertains to certain orthogonality conditions, here we refer to η C as the classical value for the relaxed scenario. Note that, under the aforesaid Assumption, the optimal value of B in classical theory or any other theory where measurement does not affect the system is given by Eq. (6). With the orthogonality conditions, η C reduces to the maximal noncontextual value. and it is achieved by the following quantum state and observables where | v i are three-dimensional real vectors defined as where θ is defined as cos θ = 1/(1 + 2α), where α = 1 2 sec π n (12) and Note that α and φ i are functions of n, which for the sake of simplification is not explicitly specified in their notation. Let us also remark that | ψ ∈ C 3 and A i acting on C 3 denote a particular example of quantum realizations achieving the maximal quantum value of the KCBS inequality (7). The self-testing properties of the above-mentioned state and measurements based on the violation of KCBS inequality are shown in [BRV + 19b]. The proof is based on the optimization method of semidefinite programming under the usual assumptions of contextuality, along with an additional assumption that P i in Eq.
Sum-of-squares decomposition. Let us finally discuss the concept of sum-of-squares decompositions. Consider a quantum operator B corresponding to some noncontextuality expression B like the one in (5). Now, if for any choice of quantum measurements A i and some η ∈ R one can decompose the shifted operator η1 − B as the maximal quantum value of B is upper bounded by η, i.e., ψ|B|ψ η for any quantum state |ψ . We call (14) a sum-of-squares decomposition associated to B. Typically E k are constructed from the measurement operators A i . The bound η is realized by a state and a set of measurements if and only if the following algebraic relation holds true for all k, Our self-testing proofs heavily rely on the above relations. Let us remark that Ref. [LSW11] provides an SOS decomposition for the conventional KCBS operator under the assumptions that the measurements satisfy In what follows we derive an alternative noncontextuality inequality together with the corresponding SOS decomposition of the form (14) which does not require making this assumption. Furthermore, our SOS is designed in such a way that the algebraic relations (15) it implies can be used for self-testing.

Modified KCBS inequality with sum-ofsquares decomposition
We are now ready to present our results. For pedagogical purposes we begin with the simplest case of n = 5 and consider the following modified KCBS expression where α is given in (12) with n = 5. Following (6) it is not difficult to find the maximal classical value of B is Result 1 (Modified KCBS inequality with SOS). The maximal quantum value of B given in Eq.
Proof. To prove this statement we present the SOS decomposition for the modified KCBS operator Let us first define the following Hermitian operators for i = 1, . . . , 5, and observe that they satisfy the following relations and where we have used the identities α 2 + α = 1 for α given in Eq. (12) with n = 5 and A 2 i = 1. With the aid of these relations it is straightforward to verify that where B is given in Eq. (17). Thus, the above equation constitutes a SOS decomposition (14) of the modified KCBS operator in which for k = 1, . . . , 5; for k = 6, . . . , 10; and 3 + 3α 2 = 4.146 is the quantum bound of B. We can validate that the state and measurements in dimension three (9)-(10) responsible for optimal value of KCBS inequality achieve this bound.
Inspired by the above n = 5 case, let us now derive our modified KCBS expression for more measurements. Our aim is to obtain a general expression for which the sumof-squares decomposition can easily be constructed as the one in Eq. (21) and later directly used for self-testing.
To reach this goal, let us consider n two-outcome quantum measurements represented by operators A i (2) acting on some Hilbert space of unknown but finite dimension. Let us then consider the expression (14) in which the operators E k are of the form 1 − M k with some positive multiplicative factors, where M k are constructed from A i . Notice that for such a choice, Eq. (15) implies that M k must be stabilizing operators of the state |ψ maximally violating our modified KCBS expression, that is, M k |ψ = |ψ . Now, to design the explicit form of M k we can use the optimal quantum realization (9)-(10) of the n-cycle KCBS inequality (7), which gives us (see Appendix A for details of the derivation) where i = 1, . . . , n and k = 1, . . . , (n − 1)/2, whereas the coefficients β k andᾱ are given by where α, φ k are defined in Eqs. (12) and (13), respectively. Let us remark that M i,k ,ᾱ, β i are all functions of n which for the sake of simplification is not specified explicitly. Moreover, the operators M i,k defined in (24) act on unknown Hilbert space H of finite dimension. We now go back to the SOS decomposition (14) which is deemed to be of the form with some non-negative parameters c k to be determined. By plugging the expression of M i,k (24) into it and after some rearrangement of indices, we obtain where We want to choose the coefficient c k so that they are nonnegative and all the anti-commutators It follows from (28) that our requirement is fulfilled if the following set of equations is satisfied Since sec(φ 2 j ) is positive for all j 3 , c 2 x /c 1 is also positive. Now, to provide a plausible solution of c 2 x , it suffices to choose a positive c 1 . Due to (30) the remaining anti- For simplicity we choose this factor to be 1/2 which implies that c 1 is such that After substituting c 2 m−1 from Eq. (31), the above gives One can readily verify that c 1 is positive. Finally, due to 3 Note that cos φ 2 j = cos (π2 j /n) and 0 < π2 j /n < π/2, ∀j = 1, 2, . . . , m − 1.
(30) and (33), Eq. (28) reads as, where and and c k , M i,k are defined in (31), (34) and (24). From Eq. (25) we know thatᾱ is a negative quantity and hence γ is positive. Thus, our modified n-cycle KCBS inequality is (39) whose quantum bound is η n (38) and the classical value η C n is provided in Result 3. It follows from the construction of the SOS (35) that the qutrit quantum state and measurements defined in Eqs. (9)-(13) satisfy the stabilizing relations M i,k |ψ = |ψ , implying the bound η n is tight, or, in other words, the maximal quantum value of (39) equals η n .
To put the above mathematical analysis in a nutshell, the expression of the noncontextuality inequality (39) is derived such that it meets a SOS decomposition (14) of certain form. This leads us to the following result. Proof. The classical value can be obtained by assigning ±1 values to the observables appearing in (39), that is, where γ is positive. Let us say in the optimal assignment there are k number of a i which are −1. We first assume k > n/2. When there are k number of −1, and n − k number of +1, the minimum value of i a i a i+1 = 4k − 3n, and the quantity i a i = n − 2k. Substituting these values in (40) we see Therefore, the optimal value of η C n is obtained for the minimum value of k, that is, for k = (n + 1)/2. This implies the right-hand-side of (41) is n + γ − 2. Similarly, if k < n/2, then we have (n − k) > n/2, and following a similar argument we can obtain the same bound.
3 Self-testing of quantum devices An exact self-testing statement provides us the certification of quantum devices, given that we observe an optimal violation of a noncontextuality inequality. However, the observed statistics are unchanged in the presence of auxiliary degrees of freedom (or auxiliary systems) and a global unitary. Therefore, self-testing in the context of state-dependent quantum contextual correlation [BRV + 19b,IMOK20] infers unique state and measurements up to these equivalences.
Here, we take the definition of self-testing stated in [IMOK20]. Formally, self-testing of preparation |ψ ∈ C d and a set of measurements {A i } n i=1 acting on C d is defined as follows: if a set of observables {A i } n i=1 acting on unknown finite-dimensional Hilbert space H and a state |ψ ∈ H maximally violate a noncontextuality inequality, then there exists a projection P : H → C d and a unitary operation U on C d such that To obtain self-testing only from the reduced Assumption mentioned in section 1, we consider a modified version of the expression B n (39) of the following form (42) Since the additional term is non-positive, the classical and quantum bounds ofB n are the same as for B n . Moreover, it follows from (35) that the SOS decomposition of B n is and η n is again the optimal quantum value ofB n . Let us now show that our inequality (42) can be used to make a self-testing statement, according to the above definition, for the state and observables (9)-(10) maximally violating it.
Result 4 (Self-testing such that where | v i are defined in (11).
Proof. Taking the expectation value of the state |ψ on both side of the SOS decomposition (43) of B, we obtain by virtue of (15) that for any i and k, In the particular k = 1 case this condition when combined with the explicit form of M i,1 given in Eq. (24) together with the fact that β 1 = α/(1 + 2α), leads to the following relations for all i = 1, . . . , n, Similarly, from the last two terms of the SOS decomposition (43) we get that for all i = 1, . . . , n, Given the relations (47) and (48), the next Theorem provides the proof for the self-testing statement.
The self-testing property implies our modified inequality (42) are non-trivial since any classical value assignment is not equivalent to the realization given in (45).

Theorem. If a set of quantum observables
(where n is odd) of the form (2) acting on arbitrary finitedimensional Hilbert space H and a unit vector |ψ ∈ H satisfy the relations (47) and (48), then there exists a projection operator P : H → C 3 and a unitary U acting on C 3 such that (45) holds true.
Proof. We prove this theorem in two steps.
Step 1. In the first step, we deduce the effective dimensionality of the observables A i and the state |ψ . Let us define a vector space V = Span{|ψ , A 1 |ψ , A 3 |ψ }. Due to Lemma 1 (stated in Appendix B), it suffices to consider the observables A i and the state |ψ restricted to V . In other words, Lemma 1 points out that the Hilbert space H can be decomposed as V ⊕ V ⊥ and all the operators A i have the following block structure whereinÃ i , A i are acting on V, V ⊥ , respectively; in particular, A i |ψ = 0 for any i. This allows us to definẽ where P is the projection operator from H to V ,P i = PP i P † 0 and 1 is the identity operator acting on V .
It follows from Eq. (2) and Eqs. (47) and (48) that the projected measurementsP i and the state |ψ satisfy the following sets of relations for all i = 1, . . . , n, Step 2. In the second step, we characterize the observ-ablesÃ i . With the help of Lemma 2 given in Appendix B, we first show that all observablesÃ i are of the form for some normalized vectors |v i ∈ C 3 such that v i |v i±1 = 0. The remaining part is the characterization of |v i . By plugging Eq. (53) into Eq. (52) we obtain that for all i, We use the fact that |v i , |v i±1 are orthogonal and multiply v i−1 | and v i+1 | with Eq. (54), which lead us to the following equations and for all i. By substituting the term v i−1 |ψ from the first equation to the second one, we arrive at the following conditions Note that, here we use the fact that v i+1 |ψ = 0 4 . Considering the absolute value of both side of (56) and using (57) we obtain another set of conditions And since n is odd, as a consequence of the above equation, Let us try to see what is the most general form of |v i compatible with the above conditions. First let us exploit the fact that observed probabilities do not change if we rotate the state and measurements by a unitary operation. We thus choose it so that U |ψ = (1, 0, 0) T ≡ |0 . We also notice that any unitary of the following form with U being any 2 × 2 unitary does not change |0 . Later we will use this freedom. Due to the fact that we are characterizing projectors |v i v i | rather than the vectors themselves, we can always assume the first element of the vector is positive, that is, |v i has the form, The condition (59) implies that all cos θ i are equal and therefore let us denote θ i = θ. Plugging these forms of |v i and |ψ = |0 into Eq. (54), the first element of the vector equation leads to 4 If v j+1 |ψ = 0 for some j, then (55) implies v j−1 |ψ is also 0, and further (54) implies |v j v j |ψ = |ψ . Substituting these in (54) taking i = j + 1, we arrive at a relation |v j+2 v j+2 |ψ = (1 − α)/α|ψ which cannot be true for any finite n since |v j+2 v j+2 | has eigenvalues 1,0.
Using this freedom we can bring one of the vectors, say |v n , to (cos θ, 0, sin θ) T by taking sin φ n = 0, e ibn = 1. (63) Then, due to the condition v 1 |v n = v n−1 |v n = 0 we infer e ib1 , e ibn−1 are real and without loss of generality we can take e ib1 = e ibn−1 = 1 (64) by absorbing the sign in cos φ 1 , cos φ n−1 . Further, we can get rid one of the phases in |v 1 , that is, and take sin(φ 1 ) to be non-negative by applying another unitary of the form (60), that does not change the simplified form of |v n . Equating the second and third element of the vector equation (54), we obtain the relations and With the aid of (63) and (65), Eq. (67) for i = n points out sin(φ 1 ) = −e ian−1 sin(φ n−1 ) which allows us to consider e ian−1 = 1. Taking i = 1 in Eqs. (67) and (68) and replacing the values of sin φ n , cos φ n , e ia1 , e ib1 , e ibn we obtain, cos φ 1 + α + αe ib2 cos φ 2 = 0.
Thus, e ia2 , e ib2 are real and can be taken to be 1. Note, here we use the fact that sin φ 1 = 0 5 . Similarly, by taking i = 2, . . . , n − 2 we conclude for all i e iai = e ibi = 1.

Conclusion
Kochen-Specker contextuality captures the intrinsic nature of quantum theory that essentially departs from classicality. It also offers a generalization of quantum correlations beyond nonlocality to a larger class of quantum systems and minimizes the demands to test nonclassicality. Therefore, it is a fundamental problem to understand what is the maximal information about the underlying quantum system that can be inferred from the correlations observed in a contextuality experiment, and whether this information can be used for certification of quantum devices from minimal assumptions of their internal functioning.
In this work, we derive self-testing statements for ncycle scenario using weaker assumptions than those made in previous approaches based on Kochen-Specker contextuality [CSW14, BRV + 19b, IMOK20, BRV + 19a]. In particular, we do not assume orthogonality relations between measurement effects. Instead, we consider general twooutcome measurements which nevertheless obey a single assumption that the measurement device does not return any additional information except the post-measurement system and does not possess any memory. Moreover, we take a different approach, that is, we use the sumof-squares 'technique' that has successfully been used in the Bell scenario to derive maximal quantum violation of certain Bell inequalities as well as in making self-testing statements [BP15, ŠASA16, SAT + 17, KŠT + 19, SSKA19, CMMN19, Kan19, ASTA19], but has never been explored for self-testing in the contextuality scenario.
We further remark that self-testing from quantum contextuality is not fully device-independent as far as its original definition is concerned, while, its experimental test does not require space-like separation. The assumption is critical to verify for practical purposes, however, in future studies, one may try to overcome it by restricting the computational power or the memory of the measurement device. Nonetheless, it is way more powerful than the usual process of tomography. It is also distinct from the self-testing approach in prepare-and-measure scenario [TKV + 18, FK19] since no restriction on the dimensionality of the preparation is imposed here.
Although the SOS decompositions hold for a certain number of measurements, a suitable adaptation of our approach in future studies may lead to SOS decompositions for an arbitrary odd number of measurements. Another direction for further study is to explore whether our approach can be applied to states and measurements of higher dimension than three and whether our self-testing statements can be made robust to experimental imperfections. From a more general perspective, it would be interesting to design a unifying approach to self-testing based on Bell nonlocality and quantum contextuality.
ropean Regional Development Fund.

A Obtaining the stabilizing operators
To guess the stabilizing operators M i,k we use the stabilizing operators in the optimal quantum realization of n-cycle KCBS inequality (7). Let us assume that these operators are in the following form where the coefficients a, b and b are to be determined as a solution to the equation and | ψ , A i are given in Eqs. (9)-(10). To solve the above we first notice the following relation, which when substituted into Eq. (74) leads one to a system of equations Assuming that a = 0 and taking into account that sin 2θ = 0, the last two equations in the above system can be rewritten as After multiplying the above equation from left by and using the fact φ i+k − φ i = φ k , Eq. (77) simplifies to, In this way we remark that the dependence of i in (77) disappears and the system of equations (79) imply Substitution of above in the first vector equality of (76) leads to and thus, we obtain a unique solution of a, b, b . Finally, substituting a, b, b into Eq. (74) we can conveniently state M i,k operators in the following way where B Lemma 1-2 In this appendix, we provide two Lemmas that are used in the proof of the Theorem.
is invariant under the algebra generated by A i .
Proof. To prove this statement it suffices to show that A i |ψ for all i = 1, . . . , n as well as all A i A j |ψ with i = j can be expressed as linear combinations of the basis vectors |ψ , A 1 |ψ and A 3 |ψ . Let us begin by noting that Eq. (47) for i = 2 gives us directly such a linear combination for A 2 |ψ and so A 2 |ψ ∈ V . Then, the fact that A i |ψ ∈ V for i = 4, . . . , n follows from Eq. (47); it is enough to rewrite the latter as Let us now move on to showing that A i A j |ψ ∈ V for all i = j. To this end, we first observe that using (48) we obtain which due to the fact that A i |ψ ∈ V , allows us to conclude that for all i, A i A i±1 |ψ ∈ V . Let us then consider the vectors A i A j |ψ for pairs i, j such that |i − j| = 2. Using the property of involution and the fact [A i , A i±1 ]|ψ = 0 which is a consequence of Eq. (48), we get Since we have already shown A i A i±1 |ψ ∈ V , the above equation implies A i A i±2 |ψ ∈ V . Given that A i A j |ψ ∈ V for |i − j| = 1 and |i − j| = 2 we can then prove, applying the same argument as above, that A i A j |ψ belong to V for any pair i, j such that |i − j| = 3. In fact, following this approach recursively we can prove that A i A j |ψ ∈ V for i, j such that |i − j| = k with k = 3, . . . , n − 1, which completes the proof.
Let us remark that the subspace V is in fact spanned by any triple of the vectors |ψ , A i |ψ and A j |ψ with i = j. This is a consequence of the fact that, as proven above, any vector A i |ψ is a linear combination of |ψ , A 1 |ψ and A 3 |ψ .
Lemma 2. If a set of projectors {P i } n i=1 acting on C 3 and a vector |ψ satisfy the relations (51) and (52), then each P i has rank one, that is, for each i there exists a normalized vector |v i ∈ C 3 such thatP i = |v i v i | and, moreover, v i |v i±1 = 0.
Let us now show that all the operatorsP i are of rank one. We first prove that none of them can be of rank three. Assume for this purpose that rank(P j ) = 3 for some j. Then, the condition (88) givesP j |ψ = |ψ . This, after taking into account thatP j+1Pj |ψ = 0 impliesP j+1 |ψ = 0, which contradicts the factP i |ψ = 0 for all i, as shown before.
As a result all the operatorsP i are of rank one and therefore they can be expressed as for some |v i ∈ C 3 . Furthermore, sinceP i |ψ = 0, Eq. (51) implies v i |v i±1 = 0. This completes the proof.