Characterising and bounding the set of quantum behaviours in contextuality scenarios

The predictions of quantum theory resist generalised noncontextual explanations. In addition to the foundational relevance of this fact, the particular extent to which quantum theory violates noncontextuality limits available quantum advantage in communication and information processing. In the first part of this work, we formally define contextuality scenarios via prepare-and-measure experiments, along with the polytope of general contextual behaviours containing the set of quantum contextual behaviours. This framework allows us to recover several properties of set of quantum behaviours in these scenarios, including contextuality scenarios and associated noncontextuality inequalities that require for their violation the individual quantum preparation and measurement procedures to be mixed states and unsharp measurements. With the framework in place, we formulate novel semidefinite programming relaxations for bounding these sets of quantum contextual behaviours. Most significantly, to circumvent the inadequacy of pure states and projective measurements in contextuality scenarios, we present a novel unitary operator based semidefinite relaxation technique. We demonstrate the efficacy of these relaxations by obtaining tight upper bounds on the quantum violation of several noncontextuality inequalities and identifying novel maximally contextual quantum strategies. To further illustrate the versatility of these relaxations, we demonstrate monogamy of preparation contextuality in a tripartite setting, and present a secure semi-device independent quantum key distribution scheme powered by quantum advantage in parity oblivious random access codes.


Introduction
The Leibnizian methodological principle of "ontological identity of empirical indiscernibles" [CvLNA56] creates a bridge across the schism dividing the "empiricist", and "realist" viewpoints on physics [Spe19]. Generalised noncontextuality [Spe05] embodies this principle, and serves to characterise operational physical theories that allow for simultaneously realist and Leibnizian explanations.
There is, therefore, both foundational and technological motivation for characterising the peculiar nature of contextual quantum be-1 Quantum theory is said to violate noncontextuality as shorthand for admitting no simultaneously Leibnizian and realist explanation. More explicitly, it cannot be explained by a noncontextual ontological (hidden variable) model [Spe05,Spe19,SSS20] haviour, and quantifying the extent of contextuality in terms of quantum violation of noncontextuality inequalities. In analogy with quantum non-locality [BCP + 14], quantum theory surpasses these noncontextual limitations, but not necessarily to the maximum mathematically possible extent [BBM + 15]. Bounding this violation provides foundational insights, such as establishing how distinct operationally indistinguishable entities must be in order to explain quantum predictions [CS20,Mar20], and finds technological applications in capping quantum advantage. Despite this motivation, the nature and the extent of available quantum contextuality remains largely uncharacterised. The diagram illustrates the relationship between sets of behaviours achievable in different theories in a generic contextuality scenario. In direct analogy with the polytopes of no-signalling and local-causal correlations in Bell experiments, the set of all valid contextual behaviours, C, and the set of noncontextual behaviours, N C, form polytopes. Continuing the analogy, the set of quantum behaviours, Q, although convex, does not form a polytope, and satisfies N C Q C in general. We find contextuality scenarios in which the subsets of behaviours obtained from pure quantum states Q Ψ (possibly convex), and projective measurements Q Π (convex) form strict subsets of the set of quantum contextual behaviours (see Observations 7 and 6), thereby demonstrating that in such scenarios mixed quantum states and unsharp measurements can access greater contextuality.
In an effort to address this shortcoming, in the first part of this work, we explore and eluci-date the rich landscape of contextual behaviours by formally defining contextuality scenarios via prepare-and-measure experiments. This formalism allows us to define the sets of noncontextual, quantum and contextual behaviours. We can then prove some basic facts about the quantum set, summarised in a series of seven observations which incorporate the relevant known results from the literature (see Fig. 1 for a brief overview of these findings).
In the second part of this work, we formulate hierarchies of semidefinite relaxations for bounding the set of quantum contextual behaviours and some natural subsets thereof. Due to the fact that one cannot a priori restrict to pure quantum states and projective measurements, in general contextuality scenarios standard techniques such as the Navascués-Pironio-Acín hierarchy for nonlocal correlations [NPA08] (or straightforward modification thereof) cannot be employed. Instead, we formulate novel semidefinite programming techniques tailored to the requirements of contextuality scenarios, with particular emphasis on efficiency and ease of implementation. Of these, our most significant contribution constitutes a semidefinite relaxation technique which employs moment matrices indexed exclusively by monomials of unitary operators, which may be of independent interest. We benchmark these relaxations by recovering maximal quantum violations of several noncontextuality inequalities, and identifying optimal quantum protocols with respect to several noncontextuality inequalities in a diverse selection of contextuality scenarios. Moreover, equipped with these relaxations, we demonstrate the existence of monogamy of contextuality in a tripartite setting. Finally, to exhibit the relevance of these relaxations to real-world applications, we present a secure, semi-device-independent one-way quantum key distribution scheme powered by preparation contextuality.

Contextuality scenarios 2.1 Prepare-and-measure experiments
In this work, we consider prepare-and-measure experiments consisting of a set of X preparation procedures, {P x } X−1 x=0 , and a set of Y measurement procedures, {M y } Y −1 y=0 . Each measurement is described by K measurement effects, {[k|M y ]} K−1 k=0 , corresponding to K possible outcomes. The experiment yields the observed statistics (or behaviour ), p(k|x, y) ≡ p(k|P x , M y ), i.e., the probability of observing the outcome k, given that the measurement M y was performed on the preparation P x . We may write the statistics as a vector p ∈ R XY K .
One may view prepare-and-measure experiments as one-way communication tasks, wherein the sender (Alice) encodes her input x ∈ [X] (where [X] denotes the set {0, . . . , X − 1}) into the preparations {P x } x , and transmits them to a (spatially separated) receiver (Bob). Bob decodes the message by performing a measurement M y , and obtains an outcome k ∈ [K]. The performance of a behaviour in such tasks is gauged by a linear functional, called a success metric. These are of the form S(p) = c · p = x,y,k c x,y,k p(k|x, y), where c ∈ R XY K is a vector of real coefficients c x,y,k . Accordingly, the performance of an operational theory in such a one-way communication task is measured by maximising the metric S over the behaviours achievable in the theory.

Operational equivalences and contextuality scenarios
First, note that we assume that the preparation and measurement procedures in our experiment are modelled by some operational theory in which probabilistic mixtures of procedures are possible. Hence the preparations, measurements and effects are elements of convex sets, denoted by P, M and E, respectively Experimental tests of generalised contextuality require the presence of equivalences between the preparations and/or measurement effects. In an operational theory, two preparations, P 1 , P 2 ∈ P, are said to be operationally equivalent, P 1 P 2 , if they yield identical statistics for all measurements and outcomes, i.e., p(k|P 1 , M ) = p(k|P 2 , M ) for all effects [k|M ] ∈ E. Similarly, two measurement effects, , if all preparations assign identical probability of occurrence to them, i.e., p(k 1 |P, M 1 ) = p(k 2 |P, M 2 ) for all P ∈ P.
We define a contextuality scenario as a prepare-and-measure experiment with certain operational equivalences imposed on the involved preparations and measurements. A scenario is therefore identified by a five-tuple, T ≡ (X, Y, K, OE P , OE M ) where the first three elements specify the number of preparations, measurements, and effects, while OE P and OE M describe operational equivalences of preparations, and measurement effects, respectively.
A single preparation equivalence in a contextuality scenario consists of two distinct decompositions of an identical hypothetical 2 preparation Q ∈ P in terms of the experimental prepa- where α 1 and α 2 are distinct probability distributions on [X] corresponding to the two distinct convex decompositions of Q.
In general, a contextuality scenario comprises Thus, for any given contextuality scenario, all operational equivalences of preparations are summarised as, where the index j iterates over the V v ≥ 2 distinct convex decompositions of a given hypothetical preparation Q v , and α v j is a probability distribution on [X] specifying the convex decompo-

Contextual polytope
The operational equivalences (2) and (3) yield the following constraints on any behaviour p appearing in a given contextuality scenario: where q v , e w ∈ [0, 1]. As these constraints are linear on the observed behaviour, the set of behaviours p that satisfy these constraints forms a convex polytope C ⊂ R XY K , referred to as the contextual polytope (note that this set depends on the tuple T specifying the contextuality scenario, but we will not reflect this in the notation for simplicity). Moreover, for any given contextuality scenario, evaluating the maximal value, S C = max p∈C {S(p)}, of any success metric S on this set constitutes a linear program [BV04].
3 Note that the effects of multiple measurements always satisfy a trivial operational equivalence deriving from the completeness of the measurements, i.e., that the probabilities of all the outcomes of a measurement sum to unity. We consider this equivalence part of the definition of a measurement and thus do not include it in the set OEM . The notation OEM = ∅ therefore signifies the presence of only these trivial measurement equivalences. 4 We have formulated the equivalences as in Eqs.
(2) and (3)-as opposed to pairwise-to enable easy distinction between scenarios which can be mapped to Bell scenarios, and those which cannot. Specifically, only contextuality scenarios with a single hypothetical preparation, V = 1, and only trivial equivalences of measurements, W = 0 can be mapped to Bell scenarios [SS18].

Noncontextual polytope and inequalities
A noncontextual ontological model for an operational theory consists of the following three elements: (i) a measurable space, Λ, known as the ontic state space, (ii) a probability measure µ P on Λ describing the epistemic state of the system for each preparation P ∈ P, satisfying µ P = µ P if P P , and (iii) for every ontic state λ ∈ Λ and measurement M ∈ M, a probability distribution ξ M (·|λ) over the possible outcomes of M , referred to as a response scheme, satisfying Consequently, in a given contextuality scenario with operational equivalences of the form (2), noncontextuality imposes the following constraints on the epistemic states and response schemes, For any given contextuality scenario, the set of behaviours p that admit a noncontextual explanation, i.e., for which p(k|x, y) = Λ ξ My (k|λ)µ Px (λ)dλ for some epistemic states and response schemes satisfying the constraints (5), forms a convex polytope, N C ⊂ R XY K , referred to as the noncontextual polytope [SSW18]. Consequently, finding the maximal value, S N C = max p∈N C {S(p)}, of any success metric S on the noncontextual ontological behaviours, also constitutes a linear program [SSW18]. In general, N C C, which can be witnessed by some success metric. Inequalities of the form S(p) ≤ S N C are typically referred to as noncontextuality inequalities, and their violation S(p) > S N C implies that the observed behaviour is contextual, i.e., p ∈ C \ N C.

Quantum contextual set and subsets
In quantum theory, both preparations and measurement effects are elements of the set of bounded positive semidefinite operators B + (H) on some separable Hilbert space H that we assume to be finite dimensional. Preparations are described by density operators, i.e., elements of B + (H) with unit trace. Measurements are defined by sets {M k ∈ B + (H)} k of measurement operators such that k M k = I, where I is the identity operator on H. Such a set is often referred to as a positive-operator-valued measure (POVM). The operational equivalences (2) and (3) imply the following constraints on quantum states {ρ x } X−1 x=0 and measurements {{M y where σ v are hypothetical quantum states and F w are hypothetical measurement operators. The set of behaviours with a quantum realisation, i.e., those in which p(k|x, y) = tr ρ x M y k for some quantum states {ρ x } X−1 x=0 and measurements {{M y k } K−1 k=0 } Y −1 y=0 satisfying the constraints (6), form the quantum contextual set Q.
It is known that there exist contextuality scenarios in which Q C, specifically those which can be mapped to Bell scenarios [SS18] (where this statement is equivalent to quantum theory not being maximally non-local). We demonstrate that this strict inclusion continues to hold in more general scenarios, for example, see Table 1.
Apart from Q itself, we study two natural subsets of it: (i) the set of behaviours realised by pure quantum states ρ 2 x = ρ x , denoted by Q Ψ , and (ii) the set of behaviours realised by projective (sharp) measurements, i.e., those in which (M y k ) 2 = M y k denoted by Q Π . We now collect some observations regarding the set of quantum behaviours in contextuality scenarios expressed in the notation we have laid out. Some of these observations are already known or partially known, as indicated subsequently.
Observation 1. For all contextuality scenarios the set of quantum behaviours Q is convex.
Observation 2. For all contextuality scenarios the subset of quantum behaviours Q Π is convex.  Observation 5. For all contextuality scenarios with only trivial equivalences of measurement effects T ≡ (X, Y, K, OE P , ∅), projective measurements are sufficient to recover the quantum set, i.e., Q = Q Π .
Observation 6. In general, for contextuality scenarios with non-trivial equivalences of preparations, pure states cannot produce all quantum contextual behaviours, i.e., Q Ψ Q.
Observation 7. In general, for contextuality scenarios with non-trivial equivalences of measurement effects, projective measurements cannot produce all quantum contextual behaviours, i.e., Q Π Q.
The proofs have been deferred to Appendix A for brevity. In Observation 3, the fact that N C = Q follows from Spekkens' original work [Spe05]. The second part of the result, Q = C, can be seen as a generalisation (from one preparation to multiple preparations) of the fact that in a hypergraph contextuality scenario all probabilistic models trivially have a quantum realisation when one allows for POVMs, as discussed in Ref. [Kun19]. In Observation 4, the fact that N C = Q was shown for two binary measurements in Ref. [Pus18] and generally in Ref. [CS20]. Finally, Observation 7 is implied by the connection between compatibility scenarios and Kochen-Specker contextuality scenarios [ATC18] (which can further be translated to generalised contextuality scenarios [KS18]), together with the fact that certain compatibility scenarios necessitate unsharp measurements [KHF14]. These observations yield a rich landscape of contextual behaviours (see Fig. 1). Due to the fact that the Hilbert space dimension of the quantum systems remains unbounded in contextuality scenarios 5 , evaluating the maximum value of 5 In general, one cannot expect to be able to bound the dimension of the quantum systems necessary for the maximal violation of a given noncontextuality inequality. This is due to known connections between contextuality scenarios and nonlocal scenarios [LSW11,SS18,SSW18], and the fact that there exist nonlocal correlations that require infinite dimensional quantum systems [CS18]. a generic success metric over all quantum realisations, S Q = max p∈Q {S(p)}, is a remarkably hard problem. However, internal maximisation techniques, such as the see-saw semidefinite programming method, yield efficient dimensiondependent lower bounds, S Q ≥ S Q L , for any success metric S.
3 Semidefinite programming relaxations of quantum contextual sets In order to outer approximate the set Q and provide upper bounds on success metrics, we formulate semidefinite relaxation techniques. A crucial concept underpinning these relaxation techniques is that of moment matrices. For a given density operator, ρ, and a sequence of linear op- Due to the positivity of ρ, any such moment matrix is positive semidefinite 7 , Γ O ρ ≥ 0. We may use the existence of such moment matrices, satisfying additional constraints, as a necessary condition for a behaviour to be contained in the quantum set in a given contextuality scenario, as follows. Given a contextuality scenario, (X, Y, K, OE P , OE M ), and a behaviour, p ∈ Q, let {ρ x } x∈[X] be density operators and be POVMs, on some finite dimensional Hilbert space H, satisfying (6), respectively, such that p(k|x, y) = tr ρ x M y k . It follows that for any finite sequence of linear operators O on H, the moment matrices where {Θ v } are hypothetical moment matrices hinged on the hypothetical quantum states {σ v } from Eq. (6), which generally do not appear in 6 Note that in the index of (Γ O ρ )O j ,O k , Oj and O k represent unique labels of the operators from the sequence O, not the operators themselves. 7 Any positive operator ρ can be written as its spectral decomposition ρ = k λ k |ψ k ψ k |, where |ψ k ψ k | is the rank-1 projection onto the span of |ψ k ∈ H, and λ k ≥ 0 for all k. The moment matrix hinged on |ψ k ψ k |, Γ O k , is the Gram matrix of the vectors {O |ψ k }O∈O, and is therefore positive semidefinite. It follows that is also positive semidefinite.
the program 8 . If we take O to be a sequence of monomials of the operators M y k (that includes all the length-zero (I) and length-one (M y k ) monomials), then we also find that the moment matrices Γ x satisfy the constraints (Γ O x ) I,I = 1 and satisfying these constraints and (7) is a necessary condition for p to be in the quantum set, and constitutes a semidefinite feasibility problem. These problems can be solved using semidefinite programs (SDP), for which efficient algorithms exist [BV04]. However, using only the constraints above, the diagonal terms of the matrices Γ O x remain unbounded. This unboundedness renders the above necessary condition for p to be in Q trivial. When bounding the set of quantum correlations in Bell scenarios, this issue can be resolved by restricting to projective measurement operators [NPA08], resulting in extra constraints on the diagonal elements.
However, in contextuality scenarios we cannot assume that our measurement operators are projections, since there are quantum behaviours that cannot be realised with projective measurements (see Observation 7). This fact poses one of the main challenges in formulating semidefinite relaxations for contextuality scenarios. To tackle this issue, we make use of the following lemma 9 . Lemma 1. Any operator 0 ≤ M ≤ I on a finite dimensional Hilbert space H can be written as The proof is straightforward, and has been deferred to Appendix A. This lemma allows us to introduce the following modification of standard semidefinite relaxation techniques. Instead of 8 Notice that the constraints (7) on the moment matrices form a direct semantic extension of the operational equivalences of preparations in (2) and (6). These constraints are therefore independent of the list of operators indexing the moment matrices. 9 Note that there exist methods to tackle such scenarios in the literature on non-commuting polynomial optimisation, entailing introduction of additional moment matrices hinged on the positive semidefinite measurement operators M y k (localisation) [BV04,Wit15,Mir15], however, the resultant SDPs are rather tedious to implement, and are relatively inefficient.
taking O to be monomials of measurement operators M y k , we take O to be monomials of unitary operators U y k (and U y k † ) (along with I) such that The resulting moment matrices, Γ O x , still satisfy (7), and additionally we now have and for all x ∈ [X] and O ∈ O. Imposing this final condition alleviates the problem of having unbounded diagonal terms. Firstly, we consider the sequence of monomials of length at most one, i.e., the sequence where denotes the concatenation of sequences (due to the relations In addition to Eqs. (7), (8), and (9) with O = U 1 , the measurement equivalences OE M imply the following additional constraints: where q v , n w ∈ C, and we define and for all O ∈ U 1 and x ∈ [X].
We denote by Q 1 the set of behaviours p such that there exist positive semidefinite matrices Γ U 1 x satisfying Eqs. (7), (8), (9) and (10). This problem is again a semidefinite feasibility problem. It is further important to note that maximising a success metric, S, over the set Q 1 ⊃ Q also constitutes an SDP. We will denote this maximum by S Q 1 , and evidently, it is an upper bound on the maximum quantum value, S Q . Note that for the feasibility SDP the constraints deriving from normalisation of the probabilities are implicitly included in Eq. (8), assuming the behaviour is properly normalised. On the other hand, in the optimisation SDP we can impose such constraints by excluding the operators corresponding to the final outcome of each measurement-as in the feasibility SDPand imposing the non-negativity of the probabilities, i.e., for all k ∈ [K − 2] and x ∈ [X], along with their subnormalisation, The success metric should also be re-expressed using The upper bounds S Q 1 ≥ S Q are in general non-trivial, as we will demonstrate in Sec. 4. Moreover, in many of the cases we consider, these bounds coincide with the lower bounds obtained from see-saw methods, i.e., S Q 1 = S Q L , and are therefore tight (up to machine precision). To demonstrate the ease of implementation and high efficiency of this unitary-based SDP relaxation, we provide a code tutorial in Appendix B.
The set Q 1 can be considered as the first level of a hierarchy of sets characterised by an SDP hierarchy. Level one of an SDP hierarchy employs moment matrices with some operator sequence O 1 , e.g., O 1 = (I, A, B). Then level l ∈ N employs moment matrices with operator sequence O l consisting of monomials of elements of O 1 with length at most l , e.g., O 2 = (I, A, B, AB, BA). Accordingly, we may define a hierarchy of outer approximations of the quantum set, Q 1 ⊇ Q 2 ⊇ . . . ⊇ Q, characterised by the unitary-based SDP hierarchy in which level l is characterised by the operator sequence U l .
Next, in order to bound the set Q Π , we revert to the standard projection-based SDP relax-ations involving operator lists composed of projections. Specifically, we consider moment matrices Γ P 1 x x with operator sequence P 1 = (I) where Π y k are projections. Apart from (7), and the trivial constraints (Γ P 1 x ) I,I = 1 for all x ∈ [X], we have additional constraints that follow from the projectivity of measurement operators, and k, k ∈ [K]. Further constraints emerge from operational equivalences of measurement effects (similar to (10)). Hence, for all contextuality scenarios, one can define the hi- Finally, in order to bound the set Q Ψ , we need not even invoke multiple moment matrices, instead we employ an unhinged moment matrix It is straightforward to see that such a moment matrix is necessarily positive semidefinite. In addition to the constraints similar to the ones described above, we have constraints of the form (Γ) I,|ψx ψx| = (Γ) |ψx ψx|,|ψx ψx| = 1 that follow from the purity of the quantum preparations, along with constraints that ensue from operational equivalences of preparations (similar to (10)). We refer to this formulation as the purestate based SDP relaxation. For all contextuality scenarios, we may define the hierarchy of sets

Tight bounds on the quantum set
The primary application of the relaxations introduced in the previous section is finding numerical proofs for the maximal quantum value S Q of any success metric S. Such a proof is possible when the lower bound S Q L obtained from internal maximisation techniques, such as the see-saw semidefinite programming method [ABC + 19, Mir15], matches the upper bound obtained from some finite level l of the suitable semidefinite relaxation hierarchy, i.e., S Q L = S Q l (up to machine precision). We begin by considering the simplest nontrivial single parameter family of contextuality scenarios [Pus18], (4, 2, 2, OE P (α), ∅), wherein the preparation setting x is composed of two bits x = (x 0 , x 1 ) ∈ {0, 1} 2 , and we consider a family  Figure 2: Plot of bounds on the maximal value of S rac (p) for behaviours p in various sets in the scenario (4, 2, 2, OE P (α), ∅). Here the solid black curve represents the tight upper bound, S rac C , for the polytope C of contextual behaviours. The solid red and green curves represent the upper bounds, Q Π 1 and Q Π 2 , on S rac Q given by the first and second levels of the projection-based relaxation, respectively. The circled black curve represents the lower bounds S rac Q L on S rac Q obtained via the see-saw semidefinite programming method, the solid orange curve corresponds to the upper bounds S rac Q Ψ 1 on the values S rac Q Ψ obtained from the first level of the pure-state based relaxation, and the solid purple curve corresponds to the tight upper bounds S rac N C for the noncontextual polytope N C. As the lower bounds on the value S rac Q from internal maximization coincide (up to numerical precision) with the upper bounds from the second level of the projection-based relaxation, we obtain proofs of optimality, S rac Notice for a range of the scenario parameter α, S rac Q > S rac Q Ψ 1 ≥ S rac Q Ψ , which constitutes a proof of Observation 6, demonstrating that certain extremal quantum contextual behaviours can only be realised through the explicit use of mixed quantum states in the experiment.
of operational equivalence conditions of the form 1 2 P 00 + 1 2 P 11 αP 01 + (1 − α)P 10 , parameterised by the coefficient α ∈ [0, 1], along with the success metric S rac (p) = 1 8 x,y p(x y |x, y). In light of Observation 5, for preparation contextuality scenarios, we employ the projection-based relaxation Q Π l , as for such scenarios one can in general take the measurement operators to be projections. While the first level Q Π 1 retrieves nontrivial upper bounds S rac Q Π 1 < S rac C , the bounds obtained from the second level of the relaxation Q Π 2 saturate the lower bounds obtained by internal maximisation, thus we find S rac Moreover, for this case we employed the purestate based relaxation Q Ψ 1 to bound the set Q Ψ . Remarkably, for a range of the scenario parameter α, we find that pure states are not sufficient to violate the noncontextual bound, i.e., which constitutes a numerical proof of Observation 6 (see Fig. 2).
It is helpful to recognise that the metric S rac gives the average success probability when the contextuality scenario is cast as the following communication task. A party (Alice) encodes two random bits, x = (x 0 , x 1 ), in a preparation P x and sends it to a second party (Bob). Bob must guess the bit x y , where y ∈ {0, 1} is chosen at random. He does so by performing a measurement M y on the preparation, the outcome of which constitutes his guess. The probability of winning given x and y is therefore p(x y |P x , M y ). This task is an example of random access coding. In general, we refer to an analogous task in which Alice must encode n dits into her preparations, subject to some constraints, as an (n, d)rac. The relevant contextuality scenario for an (n, d)-rac is (d n , n, d, OE P , OE M ), for some operational equivalences OE P and OE M .
Next, we consider a cryptographically appealing family of preparation noncontextuality inequalities based on (n, 2)-racs that impose parity obviliousness, known as (n, 2)-poracs, and introduced in Ref.
The average success probability of a strategy in the (n, 2)-porac is given by the suc-cess metric S rac (p) = 1 2 n n x,y p(x y |x, y) on its behaviour p in the contextuality scenario (2 n , n, 2, PO(n, 2), ∅). The noncontextual upper bound on the success metric is S rac N C = 1 2 (1 + 1 n ). The first levels of both relaxations, the projection-based Q Π 1 and the unitary-based Q 1 , match the known optimal quantum bounds for n ∈ {2, . . . , 7}, i.e., S rac Q = S rac Thus far we have considered contextuality scenarios with only trivial equivalences of measurement effects. Moving to tests of universal contextuality, we consider the scenario (6, 3, 2, U P , U M ) where we have the operational equivalences 1 2 (P 0 + P 1 ) 1 2 (P 2 + P 3 ) 1 2 (P 4 + P 5 ), and Here the noncontextual polytope has six distinct non-trivial facets up to relabelling symmetries [SSW18], each corresponding to a distinct noncontextuality inequality. We give the maximal quantum violation of all these facet inequalities in Table 1, obtained from the first level of the unitary-based relaxation. Moreover, we retrieve optimal states and measurements that saturate the bounds, displayed in Fig. 6.
Next, we considered universal noncontextuality inequalities obtained from n-cycle Kochen-Specker (KS) graphs [XSS + 16, LSW11]. In this case also, level one of the unitary-based relaxation retrieves tight quantum bounds (up to machine precision), S ks Q = 3 + n cos π n 1+cos π n for n ∈ {5, 7, 9, 11}, where S ks is the success metric given in Ref.
Finally, we considered a class of novel universal noncontextuality inequalities, termed (n, 2)mporacs, based on the (n, 2)-porac. In addition to the preparation equivalence conditions that ensue from parity obliviousness, we introduce measurement equivalences given by 1  Table 3).   p(0|x, y), for contextual behaviours (S C ), noncontextual behaviours (S N C ), along with lower bounds on the maximal quantum values S Q obtained from the see-saw semidefinite programming method (S Q L ), and upper-bounds on S Q obtained from the first and second levels of the unitarybased relaxation (S Q1 and S Q2 ). Notice that for the six facet inequalities the lower bounds, S Q L , coincide with the upper bounds, S Q1 , up to seven decimal places, which provides a numerical proof for the optimal quantum value, S Q . Furthermore, while for the first facet inequality the quantum bound saturates the contextual bound, S Q = S C , for all other inequalities quantum behaviours fail to reproduce extremal contextual behaviours, i.e., S Q < S C . The seventh inequality is not a facet inequality, but a contextuality inequality stemming from a typing error in Ref. [SSW18], wherein it is stated to be a facet inequality a . We include this inequality in our results table, since it presents an example of the quantum upper bound upon restricting ourselves to projective measurements, S Q Π 1 = S Q Π L = 3.4641016, being lower than even the noncontextual bound, S N C = 3.5, thus forming a numerical proof of Observation 7. The seventh inequality also presents a case in which the second level of our hierarchy was required to find a tight bound.
a The error was confirmed by private communication and the noncontextual bound of 3.5 for this success metric was calculated only in the present work.

Monogamy of contextuality
A new feature that we uncover using the relaxations described in the previous sections is that of monogamy of contextuality. Consider a prepare-and-measure scenario with two measuring parties, Bob and Charlie, whose actions are space-like separated. The preparation party, Alice, shares a preparation according to her setting x between Bob and Charlie. The observed statistics in such a case are described by p BC (k B , k C |x, y B , y C ), where y B (y C ) and k B (k C ) are the measurement settings and outcomes of Bob (Charlie), respectively. The spacelike separation implies no-signalling between Bob  Table 2: Maximal values for generalised noncontextuality inequalities based on n-cycle KS graphs for contextual behaviours (S ks C ), noncontextual behaviours (S ks N C ), along with lower bounds obtained from the see-saw semidefinite programming method (S ks Q L ) and upper bounds obtained from the first level of the unitary-based relaxation (S ks Q1 ). Again, in each case the lower bounds (S ks Q L ) coincide with the upper bounds (S ks Q1 ) up to seven decimal places, which provides a numerical proof for the optimal quantum value, S ks Q .
n S rac  Table 3: Maximal values for the success probability in the (n, 2)-mporac tasks for contextual behaviours (S rac C ), noncontextual behaviours (S rac N C ), along with lower bounds obtained from the see-saw semidefinite programming method (S rac Q L ), and upper bounds obtained from the first level of the unitary-based relaxation (S rac Q1 ). Again, in each case the lower bounds (S Q L ) coincide with the upper bounds (S rac Q1 ) up to seven decimal places, which provides a numerical proof for the optimal quantum value, S rac Q , and demonstrates the efficacy of the unitary-based relaxation.
and Charlie [BCP + 14], that is, where p B and p C are the marginal distributions of Bob and Charlie, respectively.
We consider the tripartite version of the (3, 2)porac task, wherein Alice's preparations adhere to the operational equivalences of preparations ensuing from parity obliviousness (15), (16), and the two measuring parties, Bob and Charlie, are both aiming to maximise their average suc-cess probabilities, S rac B and S rac C , respectively, expressed by where Z denotes either B or C, and p Z is the respective marginal probability distribution. We find that, say, Charlie's maximum success probability is limited by that of Bob, i.e., their maximum success probabilities satisfy certain monogamy relations. For any behaviour in C also satisfying no-signalling (NS), we obtain the relation S rac B + S rac C ≤ 3 2 for the (3, 2)-porac (see Fig. 3). Note that this relation is more restrictive than simply adding up the maximal success probabilities attainable in C, S rac C = 1, hence the term monogamy.
Quantum behaviours in this setup, p ∈ Q, are described by are the measurement operators of Bob and Charlie, respectively, and one might assume without loss of generality that they are projections, in light of Observation 5. In order to obtain monogamy relations in the quantum case, we employ our projectionbased semidefinite relaxation for the set Q Π , and implement the relaxation Q Π 1+BC 10 , built from monomials of the projections of Bob, Charlie, and products of Bob's and Charlie's projections, M y B k B N y C k C (but not employing monomials corresponding to products of different operators of Bob or Charlie only, e.g. ). Besides the constraints that ensue from parity obliviousness, the relaxation Q Π 1+BC includes commutation relations (CR) [NPA08] that ensue from the spatial separation between Bob and Charlie. This relaxation gives us the monogamy relation S rac B + S rac C ≤ 1.392. For the complete monogamy relation, see Fig. 3, where we plot the maximum attainable S rac C given a fixed S rac B .

Semi-device-independent quantum key distribution
We introduce the following semi-device- 10 The set Q Π 1+BC emulates the intriguing physical scenario wherein Alice distributes almost quantum correlations [NGHA15] to Bob and Charlie. independent quantum key distribution protocol based on the (3, 2)-porac: Alice and Bob play many rounds of the (3,2)-porac game, in each round uniformly randomly choosing their settings, x = (x 0 , x 1 , x 2 ) and y, and each of Bob's outcomes forms a bit of his raw key, b = k. After accumulating statistics from many rounds, Bob announces his input setting, y, for each round via a classical public channel (that can be read but not modified by any third party). After learning these values, Alice only keeps her bit a = x y to create her raw key, and discards the other two. Bob then announces a part of his output bits, to allow for the parties to estimate the success metric of the porac task. Based on this estimate, they either abort the protocol-if the success metric does not reach a certain threshold-or proceed to extract perfectly correlated key bits from their remaining bits b and a, by means of one-way classical communication.
The monogamy relations derived in the previous section imply the potential application of preparation contextuality to quantum key dis-tribution. In particular, we might replace the trusted party Charlie with a malicious eavesdropper Eve, who is trying to read the shared key. In a particularly paranoid scenario, we might assume that Eve is responsible for the manufacturing of the devices of Alice and Bob, and therefore she has perfect control and knowledge of the states ρ x that Alice is able to prepare, as well as the measurements M y b that Bob is able to perform. However, we assume that Alice's preparations, whatever they may be, respect the operational equivalences necessary to guarantee parity obliviousness. Further, for simplicity, we assume that the devices behave in the same way every round (i.i.d. assumption [AF18]), and that while running the porac protocol, Alice and Bob have free will and can choose their settings x and y independently of Eve (free will assumption [ABG + 07]). We further assume that Eve measures her part of the quantum state in each round-assuming no quantum memory of Eve [AF18]-and produces a classical output e. The resulting general tripartite correlation is of the form p ABE|XY (a, b, e|x, y (x, y)p ABE|XY (a, b, e|x, y), and we will assume the uniform distribution p XY (x, y) = 1 24 for all x, y. According to the seminal result by Csiszár and Körner [CsK78], the extractable key, r, between Alice and Bob from the above distribution is lower bounded by where H min is the min-entropy and S rac E is Eve's success probability in the same porac task that Alice and Bob perform. In Eq. (21), the second equality is assuming an optimal guessing strategy for Eve, and the inequality follows from the concavity of the logarithm.
The term H(A|B) can always be computed from the observed behaviour, which Alice and Bob are able to estimate in the protocol. However, the monogamy relations derived in the previous section suggest that it might be advantageous to express H(A|B) in terms of Bob's success probability, which potentially allows us to bound Eve's success. In order to be able to express H(A|B) in terms of Bob's success probabil-ity, we assume that independently of the settings x and y, Bob's output is b = x y with probability S rac B and b = x y with probability 1 − S rac B (this holds in the case of the optimal quantum success probability, or when one assumes a noisy scenario with uniform noise, e.g. employing the noisy statesρ where ρ x are the optimal states and d is the dimension). Under these assumptions, H(A|B) = h(S rac B ), where h is the binary entropy, and we obtain a bound on the key rate in terms of the success probabilities of Eve and Bob, Since the logarithm is monotonically increasing, in order to obtain a lower bound on the . We see that for success probabilities S rac B 0.776 close to the optimal one, Alice and Bob are able to extract a secure key. If the parties find the success metric to be lower than this threshold value, the parties abort the protocol in light of the potential presence of an eavesdropper.
key rate in terms of Bob's success probability, S rac B , it is enough to upper bound S rac E in terms of S rac B . This can be done using our semidefinite relaxation techniques, analogously to the monogamy relations obtained in Section 5.1. We employed the projection-based relaxation Q Π 1+BE , and found that for a nontrivial region, S rac B 0.776, below the optimal success probability S rac Q ≈ 0.7886751, it is possible to extract a secure key from the observed behaviour (see Fig. 4). Therefore, we have demonstrated that preparation contextuality leads to secure semi-device-independent quantum cryptographic protocols 11 .

Summary
In this work, we sought to characterise the behaviours appearing in generalised contextuality scenarios with operational equivalences of preparations and measurements. To this end, we laid down a framework for rigorously defining contextuality scenarios and the associated polytope 11 We note that in Ref. [SBA17] the authors study quantum key distribution based on the monogamy of the Klyachko-Can-Binicioglu-Shumovsky-type contextuality, and in Ref. [TF15] the authors propose a quantum key distribution protocol based on generalised measurement contextuality. However, up to our knowledge, our proposed protocol is the first demonstration of the potential of preparation contextuality for semi-device-independent quantum key distribution. of valid contextual behaviours, C, in prepareand-measure experiments. We studied the set of quantum contextual behaviours, Q. Moreover, we defined subsets of quantum contextual behaviours, namely, Q Π and Q Ψ , wherein the experimental preparation and measurement procedures are restricted to pure states, and projective measurements, respectively. We established a number of general properties of these sets of contextual behaviours, namely, the convexity of Q (Observation 1), the convexity of Q Π (Observation 2), and the absolute absence of contextuality in scenarios with only trivial operational equivalences of preparations (Observation 3) and in prepare-and-measure experiments with three or fewer preparations (Observation 4). Moreover, in contextuality scenarios with only trivial operational equivalences of measurement effects, it is enough to consider projective measurements (Observation 5). We also find that in some scenarios the preparations and measurements actually appearing in an experiment (as opposed to their hypothetical counterparts appearing only in operational equivalences) must be mixed states and unsharp measurements, respectively, in order to violate noncontextuality, or to produce maximally contextual quantum behaviours (Observations 6 and 7).
With the framework in place, we focused on developing semidefinite programming techniques to bound the amount of quantum contextuality, as measured by the maximum quantum violation of noncontextuality inequalities. However, the fact that one needs to consider mixed states and unsharp measurements presents new challenges. In particular, one cannot employ simple modifications of the known semidefinite programming techniques such as that of Ref. [NPA08]. To address these issues, we formulate novel semidefinite programming relaxations. First, to address the inadequacy of pure states in contextuality scenarios, our relaxation employs multiple moment matrices hinged on the corresponding quantum preparations. The operational equivalences of preparations then semantically extend to linear constraints on the moment matrices themselves. These constraints are notably independent of the particulars of the operators indexing the moment matrices. Second, to address the inadequacy of projective measurements, we devise a novel formulation of semidefinite program-ming relaxations, entailing moment matrices indexed exclusively by monomials of unitary operators. This unitary operator parameterisation may be of independent interest to readers interested in noncommuting polynomial optimisation methods. Our formulation allows one to retrieve upper bounds on the quantum violation of noncontextuality inequalities with arbitrary operational equivalences.
The resulting hierarchies of semidefinite programs are efficient, as they provide tight bounds already at low levels. Consequently, we retrieve upper bounds on maximum quantum values, along with numerical proofs of their tightness, for more than twenty-one distinct noncontextuality inequalities, spanning a diverse selection of contextuality scenarios. To demonstrate the ease of implementation of these techniques, we provide a code tutorial (Appendix B) for the avid reader.
Moreover, these techniques also allow us to bound functionals that are relevant for applications, specifically, to derive monogamy relations for preparation contextuality, and to lower bound secure key rates of a novel semi-deviceindependent quantum key distribution scheme fuelled by quantum advantage in the (3, 2)-porac task and the monogamy of preparation contextuality.
While in this work we have considered contextuality scenarios with operational equivalences of preparations and measurements, in general, contextuality scenarios may also include operational equivalences of transformations [Spe05]. Extending the framework and the SDP technique so as to include operational equivalences of transformations forms an essential future research avenue. Additionally, proving (or disproving) the convergence of our SDP hierarchy to the set of quantum contextual behaviours (in analogy with the convergence of the Navascués-Pironio-Acín hierarchy, approximating the quantum set of behaviours in Bell scenarios [NPA08]) presents another immediate research direction.

Note added
While finalising this article, we became aware of the related work in Ref. [TCUA21], which also features a hierarchy of SDP relaxations for bounding the set of quantum contextual behaviours. The hierarchy in Ref. [TCUA21] is considerably different from the one presented here. The authors employ a single unhinged moment matrix, and to accommodate the inadequacy of pure states and projective measurements, they utilise additional localising moment matrices, each hinged on a positive semidefinite operator. For contextuality scenarios with only trivial measurement equivalences, their hierarchy should, to the best of our knowledge, perform at least as well as the one presented here. However, in the test cases we considered, the present hierarchy yielded tight bounds with a smaller number of total variables. Furthermore, in general contextuality scenarios with non-trivial operational equivalences our approach employing unitary operators provides faster convergence. On the other hand, the hierarchy in Ref. [TCUA21] admits an interesting generalisation to quantifying the simulation cost of contextuality.

A Proofs
In this section we recall the statements from the main text and provide their proofs.

Observation 1. For all contextuality scenarios the set of quantum behaviours Q is convex.
Proof. Let us consider two quantum behaviours appearing in an arbitrary contextuality scenario, p,p ∈ Q, such that p(k|x, y) = tr ρ x M y k andp(k|x, y) = tr ρ xM y k , where ρ x and M y k are quantum states and measurements on a Hilbert space H, andρ x andM y k are quantum states and measurements on a Hilbert spaceH, respectively. Furthermore, the quantum preparations ρ x andρ x and the quantum measurement operators M y k andM y k satisfy operational equivalences of form (6). Consider an arbitrary convex combination,p = λp + (1 − λ)p, where λ ∈ [0, 1], i.e., p(k|x, y) = λp(k|xy) + (1 − λ)p(k|x, y) ∀x, y, k.
We show thatp ∈ Q by providing explicit states and measurements, such thatp(k|x, y) = tr ρ xM y k . In particular, consider the states,ρ and the measurement operators,M It is straightforward to verify that these direct sums constitute valid quantum states and measurements onĤ = H⊕H, satisfy the same operational equivalence constraints (6), and that they indeed reproduce the desired behaviour,p(k|xy) = tr ρ xM y k . Proof. Let p C ∈ C in scenario T be a generic contextual behaviour with elements p C (k|x, y). Firstly, consider the quantum strategy in which ρ x = |x x| where {|x } x∈ [X] is an orthonormal basis of C X and M y k = x∈[X] p C (k|x, y) |x x|. Since each 0 ≤ p C (k|x, y) ≤ 1 we have that 0 ≤ M y k ≤ I, and since k∈ [K] p C (k|x, y) = 1 we find k∈[K] M y k = I for all x ∈ [X] and y ∈ [Y ]. Moreover, it is straightforward to verify that this strategy reproduces the given behaviour. Finally, noting that since p C ∈ C and therefore satisfies Eq. (4), we find that these measurements satisfy operational equivalence conditions (6) as, and y ∈ [Y ]. Clearly, this strategy reproduces the observed behaviour as λ∈[X] µ x (λ)ξ My (k|λ) = p C (k|x, y). Finally, we find this strategy satisfies the measurement equivalences in (5) since

Observation 2. For all contextuality scenarios the subset of quantum behaviours
for all x ∈ [X], w ∈ [W ] and all j ∈ [W w ].
Proof. Notice that in such contextuality scenarios, up to relabelling, there is only one non-trivial family of sets of operational equivalences of preparations when X = 3, namely, for some α ∈ [0, 1]. We will show the result directly, however note that it could also be shown using Observation 3 and showing that since one of the preparations is a convex combination of the other two, the scenario reduces to that with two preparations and no preparation equivalences. Given a behaviour p C ∈ C, one can verify that the quantum preparations represented by the density matrices ρ 0 = |0 0|, ρ 1 = |1 1| and ρ 2 = αρ 0 + (1 − α)ρ 1 and the operators M y k = p C (k|0, y) |0 0| + p C (k|1, y) |1 1| satisfying 0 ≤ M y k ≤ I, and k∈[K] M y k = I, reproduces the observed behaviour as tr ρ x M y k = p C (k|x, y). Moreover, these quantum preparations satisfy operational equivalences (28). Hence, we have shown Q = C.
for all x, y, k. Starting from this construction, we show that there also exists a set of density operators {ρ x } X−1 x=0 satisfying the same operational constraints OE P , and projective measurements satisfy the operational constraints OE P , due to the linearity of the transformation ρ x → ρ for all k, x, and y, which concludes the proof.
Observation 6. In general, for contextuality scenarios with non-trivial equivalences of preparations, pure states cannot produce all quantum contextual behaviours, i.e., Q Ψ Q.
Proof. In the simplest non-trivial contextuality scenario (4, 2, 2, OE P , ∅), consider the (2, 2)-setup with an operational equivalence of the form 1 2 P 00 + 1 2 P 11 P 01 . Now, if we demand that the involved preparations are pure quantum states, i.e., ρ 2 x 0 ,x 1 = ρ x 0 ,x 1 for all x 0 , x 1 ∈ {0, 1}, it is straightforward to see that the constraints implied by the given operational equivalence can only be satisfied when the three quantum preparations featuring in the operational equivalence condition are identical. This observation in turn leads to the upper bound on the performance of pure states in the task, S rac Q Ψ = 3 4 , saturated by the strategy, ρ 1,0 = |0 0| and ρ 1,1 = ρ 0,0 = |1 1| and M 0 0 = M 1 1 = |1 1|. One can see that this strategy is indeed optimal from the upper bound retrieved from the first level of our pure-state based relaxation, S rac Q Ψ 1 = 3 4 , or analytically. Now, the noncontextual bound, quantum lower bound, and the upper bound obtained via the first level of our projection-based and unitary-based hierarchy are identical S rac S rac Q and hence Q Ψ Q. Alternatively, we obtain a numerical proof by considering the scenario (4, 2, 2, OE P (α), ∅) and noting that there exist non-empty intervals of the value α for which S rac Q Ψ 1 < S rac Q as shown in Fig. 2 Figure 5: A quantum strategy for (2, 3)-mporac task, in the contextuality scenario (3 2 , 2, 3, OE P , OE M ), wherein the nine preparation settings are indexed by two trits x 0 , x 1 ∈ [3], the set OE P entails operational equivalences of preparations such that the parity trit (x 0 + x 1 ) mod 3 remains a secret, and OE M entails operational equivalences of measurement effects of the form (40). This strategy violates the noncontextual bound and attains S rac Q L = 0.5257834 > S rac N C = 0.5 > S rac Q Π = 1 3 . Here, the displayed projections (right) Π y k are scaled down to become measurement operators M y k = 2 3 Π y k for all y ∈ [2] and k ∈ [3], which allows for the violation of the noncontextual bound, and a success metric gain of S rac Q L ≈ 0.5257834−0.3333333 = 0.1924501. This constitutes a part of the proof of Observation 7, wherein we show that a any strategy wherein all effects are projections is simply not allowed in this task, thereby demonstrating that in certain universal contextuality scenarios unsharp measurements can outperform the sharp measurements.
where the second equality follows from the projectivity assumption (M 0 k ) 2 = M 0 k . On the other hand the assumption (M 1 , 1, 2}, which is not a projection, and therefore contradicts our initial projectivity assumption. The maximal noncontextual success probability of (2, 3)-mporac is greater than 1 3 , i.e., S N C = 1 2 . Finally, there exist POVMs satisfying the constraints (41), such as those depicted in Fig. 5. The states and POVMs in Fig.  5 show that Q is non-empty which concludes the proof (the strategy also surpasses the noncontextual bound S N C = 1 2 and achieve a success probability of S Q L ≈ 0.5257834, while the first level of our unitary-based hierarchy returns the bound S Q 1 = 0.5555555).
We stumbled upon another numerical proof for the desired thesis while testing our relaxations on the facet inequalities in the contextuality scenario (6, 3, 2, U P , U M ) from [SSW18]. Specifically, the seventh inequality in Table 1 (which was listed as a facet inequality in [SSW18] due to a typing error) has a lower value when we restrict ourselves to projective measurements S Q Π 1 = S Q Π L = 3.4641016, as compared to even the noncontextual bound S N C = 7 2 , and to the quantum lower bound S Q L = 7 2 , and the bounds obtained from the first and second level of our unitary based relaxation S Q 1 = 3.5552760 and S Q 2 = 3.5. Proof. Every such operator M can be written in terms of its spectral decomposition, is an orthonormal basis on H (the eigenbasis of M ), and 0 ≤ λ j ≤ 1 for all j. Then, consider the unitary operator, such that λ j = 1 2 (1 + cos α j ). Notice that such a set {α j } j can always be found for any set {λ j } j satisfying 0 ≤ λ j ≤ 1 for all j. Therefore, it holds that Lemma 2. The maximal noncontextual success probability of (n, 2)-mporac remains the same as the maximal noncontextual success probability of the (n, 2)-porac, that is, S rac N C = 1 2 (1 + 1 n ).

B Tutorial code
As a demonstration of the ease of implementation of the relaxations presented in this work, we provide a basic verbose code for the universal contextuality scenario (6, 3, 2, U P , U M ), where we have the following operational equivalences, Here we will be employing Matlab in conjunction with a standard optimization toolbox YALMIP, and SDPT3 as our SDP solver. For this scenario we will employ the operator sequence O = (I) (U y k , U y k † ) Y −1,K−2 y=0,k=0 . We begin by declaring the specifications of the prepare-and-measure experiment, the total number of operators, empty arrays for the constraints, a probability cell for storing the observed behaviour, an empty array to for the results, and X SDP variables, X = 6; % six settings for the preparation device Y = 3; % three settings for the measurement device K = 2; % binary outcomes O = 2 * Y * (K−1)+1; % total number of operators in our list conP = []; % an empty list for constraints on the moment matrix level conM = []; % an empty list for constraints on the substrate level Prob = cell(X,Y,K−1); % a cell for probabilities S = []; % an empty list for upper bounds G = cell(X,1); % cell for X moment matrices It is a feature of our formulation that one can easily segregate constraints on abstract moment matrices, from those that depend specifically on the operators in the operator list. The former includes the following constraints that ensue from the positive semidefiniteness of the quantum states, and the equivalence conditions of the preparations (44), Now, let us collect constraints that are specific to the operator list we are employing. First, we create an indexing function which returns the position of the operator in each moment matrix, given the operator specifiers, idx = @(y, k, u) 2 * (K−1) * y + 2 * k + u + 2; % function to return the position of the ... operators where U y,u=0 k = U y k , and U y,u=1 k = U y k † . Let us now specify how the operators {U y k † } Y −1,K−2 y=0,k=0 are related to {U y k } Y −1,K−2 y=0,k=0 , along with the constraints that ensue from the unitarity of the operators in our list, for x = 0:X−1 for y = 0:Y−1 for k = 0:K−2 conM = [conM; G{x+1}(1,idx(y,k,0)) == G{x+1}(idx(y,k,1),1)]; conM = [conM; G{x+1}(idx(y,k,0),1) == G{x+1}(1,idx(y,k,1))]; end end for j = 1:O conM = [conM; G{x+1}(j,j) == 1]; % unitarity constraints end end The measurement equivalences (45) amount to additional constraints on the unitary operators, specifically, which can be enforced in the following way, specific to our operator list, for x = 0:X−1 for j = 1:O sum1 = 0; sum2 = 0; for y = 0:Y−1 for k = 0:K−2 sum1 = sum1 + G{x+1}(j,idx(y,k,0)) + G{x+1}(j,idx(y,k,1)); sum2 = sum2 + G{x+1}(idx(y,k,0),j) + G{x+1}(idx(y,k,1),j); end end conM = [conM; sum1 == 0; sum2 == 0]; % measurement equivalences end end We can now collect the observed data, p(k|x, y) = 1 2 + 1 4 (tr ρ x U k y + tr ρ x U k y † ), for x = 0:X−1 for y = 0:Y−1 for k = 0:K−2 Prob{x+1,y+1,k+1} = 0.5 + 0.25 * (G{x+1}(1, idx(y,k,0)) + G{x+1}(1, ... idx(y,k,1))); end end end Now we are in the position to retrieve quantum bounds on facet inequalities in Table 1  where the first six expressions correspond to the facet inequalities of the noncontextual polytope in this scenario (see Table 1), while the seventh expression from equation (26)   p 00 − p 04 + 2p 11 + 2p 24 Figure 6: Quantum protocols that attain maximal quantum values (upto machine precision) for all six facet inequalities in the contextuality scenario (6, 3, 2, U P , U M ), where p yx = p(0|x, y). The states and the measurements are depicted on a plane of the Bloch sphere. In each case, the states ρ 0 , ρ 2 , ρ 4 are depicted with solid black arrows, the states ρ 1 , ρ 3 , ρ 5 are represented by dashed black arrows, and the projections Π 0 0 , Π 1 0 , Π 2 0 are represented by dashed red arrows. In each case, ρ 0 + ρ 1 = ρ 2 + ρ 3 = ρ 4 + ρ 5 = I, according to U P . Observe that for the second, fourth and sixth inequalities, we have skipped pairs of states that do not feature in the expression of the respective facet inequalities, as these can be arbitrary, as long as they add up to I. Finally, the measurements remain unaltered for all six facet inequalities, that is, Π 0 0 + Π 1 0 + Π 2 0 = 3I 2 , according to U M .