# Quantum contextuality

Quantum contextuality is a feature of the phenomenology of quantum mechanics whereby measurements of quantum observables cannot simply be thought of as revealing pre-existing values. Any attempt to do so in a realistic hidden-variable theory leads to values that are dependent upon the choice of the other (compatible) observables which are simultaneously measured (the measurement context). More formally, the measurement result (assumed pre-existing) of a quantum observable is dependent upon which other commuting observables are within the same measurement set.
Contextuality was first demonstrated to be a feature of quantum phenomenology by the Bell–Kochen–Specker theorem. The study of contextuality has developed into a major topic of interest in quantum foundations as the phenomenon crystallises certain non-classical and counter-intuitive aspects of quantum theory. A number of powerful mathematical frameworks have been developed to study and better understand contextuality, from the perspective of sheaf theory, graph theory, hypergraphs, algebraic topology, and probabilistic couplings.
Nonlocality, in the sense of Bell's theorem, may be viewed as a special case of the more general phenomenon of contextuality, in which measurement contexts contain measurements that are distributed over spacelike separated regions. This follows from Fine's theorem.
Quantum contextuality has been identified as a source of quantum computational speedups and quantum advantage in quantum computing. Contemporary research has increasingly focused on exploring its utility as a computational resource.

## Kochen and Specker

The need for contextuality was discussed informally in 1935 by Grete Hermann, but it was more than 30 years later when Simon B. Kochen and Ernst Specker, and separately John Bell, constructed proofs that any realistic hidden-variable theory able to explain the phenomenology of quantum mechanics is contextual for systems of Hilbert space dimension three and greater. The Kochen–Specker theorem proves that realistic noncontextual hidden-variable theories cannot reproduce the empirical predictions of quantum mechanics. Such a theory would suppose the following.
* All quantum-mechanical observables may be simultaneously assigned definite values (this is the realism postulate, which is false in standard quantum mechanics, since there are observables that are indefinite in every given quantum state). These global value assignments may deterministically depend on some "hidden" classical variable, which in turn may vary stochastically for some classical reason (as in statistical mechanics). The measured assignments of observables may therefore finally stochastically change. This stochasticity is, however, epistemic and not ontic, as in the standard formulation of quantum mechanics.
* Value assignments pre-exist and are independent of the choice of any other observables, which, in standard quantum mechanics, are described as commuting with the measured observable, and they are also measured.
* Some functional constraints on the assignments of values for compatible observables are assumed (e.g., they are additive and multiplicative, there are, however, several versions of this functional requirement).
In addition, Kochen and Specker constructed an explicitly noncontextual hidden-variable model for the two-dimensional qubit case in their paper on the subject, thereby completing the characterisation of the dimensionality of quantum systems that can demonstrate contextual behaviour. Bell's proof invoked a weaker version of Gleason's theorem, reinterpreting the theorem to show that quantum contextuality exists only in Hilbert space dimension greater than two.

## Frameworks for contextuality
### Sheaf-theoretic framework

The sheaf-theoretic, or Abramsky–Brandenburger, approach to contextuality initiated by Samson Abramsky and Adam Brandenburger is theory-independent and can be applied beyond quantum theory to any situation in which empirical data arises in contexts. As well as being used to study forms of contextuality arising in quantum theory and other physical theories, it has also been used to study formally equivalent phenomena in logic, relational databases, natural language processing, and constraint satisfaction.
In essence, contextuality arises when empirical data is locally consistent but globally inconsistent.
This framework gives rise in a natural way to a qualitative hierarchy of contextuality:
* (Probabilistic) contextuality may be witnessed in measurement statistics, e.g. by the violation of an inequality. A representative example is the KCBS proof of contextuality.
* Logical contextuality may be witnessed in the "possibilistic" information about which outcome events are possible and which are not possible. A representative example is Hardy's nonlocality proof of nonlocality.
* Strong contextuality is a maximal form of contextuality. Whereas (probabilistic) contextuality arises when measurement statistics cannot be reproduced by a mixture of global value assignments, strong contextuality arises when no global value assignment is even compatible with the possible outcome events. A representative example is the original Kochen–Specker proof of contextuality.
Each level in this hierarchy strictly includes the next. An important intermediate level that lies strictly between the logical and strong contextuality classes is all-versus-nothing contextuality, a representative example of which is the Greenberger–Horne–Zeilinger proof of nonlocality.

### Graph and hypergraph frameworks

Adán Cabello, Simone Severini, and Andreas Winter introduced a general graph-theoretic framework for studying contextuality of different physical theories. Within this framework experimental scenarios are described by graphs, and certain invariants of these graphs were shown have particular physical significance. One way in which contextuality may be witnessed in measurement statistics is through the violation of noncontextuality inequalities (also known as generalized Bell inequalities). With respect to certain appropriately normalised inequalities, the independence number, Lovász number, and fractional packing number of the graph of an experimental scenario provide tight upper bounds on the degree to which classical theories, quantum theory, and generalised probabilistic theories, respectively, may exhibit contextuality in an experiment of that kind. A more refined framework based on hypergraphs rather than graphs is also used.

### Contextuality-by-default (CbD) framework

In the CbD approach, developed by Ehtibar Dzhafarov, Janne Kujala, and colleagues, (non)contextuality is treated as a property of any system of random variables, defined as a set ${\mathcal {R}}=\{R_{q}^{c}:q\in Q,q\prec c,c\in C\}$ in which each random variable $R_{q}^{c}$ is labeled by its content $q$ – the property it measures, and its context $c$ – the set of recorded circumstances under which it is recorded (including but not limited to which other random variables it is recorded together with); $q\prec c$ stands for "$q$ is measured in $c$". The variables within a context are jointly distributed, but variables from different contexts are stochastically unrelated, defined on different sample spaces. A (probabilistic) coupling of the system ${\mathcal {R}}$ is defined as a system $S$ in which all variables are jointly distributed and, in any context $c$, $R^{c}=\{R_{q}^{c}:q\in Q,q\prec c\}$ and $S^{c}=\{S_{q}^{c}:q\in Q,q\prec c\}$ are identically distributed. The system is considered noncontextual if it has a coupling $S$ such that the probabilities $\Pr[S_{q}^{c}=S_{q}^{c'}]$ are maximal possible for all contexts $c,c'$ and contents $q$ such that $q\prec c,c'$. If such a coupling does not exist, the system is contextual. For the important class of cyclic systems of dichotomous ($\pm 1$) random variables, ${\mathcal {C}}_{n}={\big \(R_{1}^{1},R_{2}^{1}),(R_{2}^{2},R_{3}^{2}),\ldots ,(R_{n}^{n},R_{1}^{n}){\big \}}$ ($n\geq 2$), it has been shown that such a system is noncontextual if and only if $D({\mathcal {C}}_{n})\leq \Delta ({\mathcal {C}}_{n}),$ where $\Delta ({\mathcal {C}}_{n})=(n-2)+|R_{1}^{1}-R_{1}^{n}|+|R_{2}^{1}-R_{2}^{2}|+\ldots +|R_{n}^{n-1}-R_{n}^{n}|,$ and $D({\mathcal {C}}_{n})=\max {\big\lambda _{1}\langle R_{1}^{1}R_{2}^{1}\rangle +\lambda _{2}\langle R_{2}^{2}R_{3}^{2}\rangle +\ldots +\lambda _{n}\langle R_{n}^{n}R_{1}^{n}\rangle {\big )},$ with the maximum taken over all $\lambda _{i}=\pm 1$ whose product is $-1$. If $R_{q}^{c}$ and $R_{q}^{c'}$, measuring the same content in different context, are always identically distributed, the system is called consistently connected (satisfying "no-disturbance" or "no-signaling" principle). Except for certain logical issues, in this case CbD specializes to traditional treatments of contextuality in quantum physics. In particular, for consistently connected cyclic systems the noncontextuality criterion above reduces to $D({\mathcal {C}}_{n})\leq n-2,$ which includes the Bell/CHSH inequality ($n=4$), KCBS inequality ($n=5$), and other famous inequalities. That nonlocality is a special case of contextuality follows in CbD from the fact that being jointly distributed for random variables is equivalent to being measurable functions of one and the same random variable (this generalizes Arthur Fine's analysis of Bell's theorem). CbD essentially coincides with the probabilistic part of Abramsky's sheaf-theoretic approach if the system is strongly consistently connected, which means that the joint distributions of $\{R_{q_{1}}^{c},\ldots ,R_{q_{k}}^{c}\}$ and $\{R_{q_{1}}^{c'},\ldots ,R_{q_{k}}^{c'}\}$ coincide whenever $q_{1},\ldots ,q_{k}$ are measured in contexts $c,c'$. However, unlike most approaches to contextuality, CbD allows for inconsistent connectedness, with $R_{q}^{c}$ and $R_{q}^{c'}$ differently distributed. This makes CbD applicable to physics experiments in which no-disturbance condition is violated, as well as to human behavior where this condition is violated as a rule. In particular, Vctor Cervantes, Ehtibar Dzhafarov, and colleagues have demonstrated that random variables describing certain paradigms of simple decision making form contextual systems, whereas many other decision-making systems are noncontextual once their inconsistent connectedness is properly taken into account.

### Operational framework

An extended notion of contextuality due to Robert Spekkens applies to preparations and transformations as well as to measurements, within a general framework of operational physical theories. With respect to measurements, it removes the assumption of determinism of value assignments that is present in standard definitions of contextuality. This breaks the interpretation of nonlocality as a special case of contextuality, and does not treat irreducible randomness as nonclassical. Nevertheless, it recovers the usual notion of contextuality when outcome determinism is imposed.
Spekkens' contextuality can be motivated using Leibniz's law of the identity of indiscernibles. The law applied to physical systems in this framework mirrors the entended definition of noncontextuality. This was further explored by Simmons et al, who demonstrated that other notions of contextuality could also be motivated by Leibnizian principles, and could be thought of as tools enabling ontological conclusions from operational statistics.

### Extracontextuality and extravalence

Given a pure quantum state $|\psi \rangle$, Born's rule tells that the probability to obtain another state $|\phi \rangle$ in a measurement is $|\langle \phi |\psi \rangle |^{2}$. However, such a number does not define a full probability distribution, i.e. values over a set of mutually exclusive events, summing up to 1. In order to obtain such a set one needs to specify a context, that is a complete set of commuting operators (CSCO), or equivalently a set of N orthogonal projectors $|\phi _{n}\rangle \langle \phi _{n}|$ that sum to identity, where $N$ is the dimension of the Hilbert space. Then one has $\sum _{n}|\langle \phi _{n}|\psi \rangle |^{2}=1$ as expected. In that sense, one can tell that a state vector $|\psi \rangle$ alone is predictively incomplete, as long a context has not been specified. The actual physical state, now defined by $|\phi _{n}\rangle$ within a specified context, has been called a modality by Auffèves and Grangier
Since it is clear that $|\psi \rangle$ alone does not define a modality, what is its status ? If $N\geq 3$, one sees easily that $|\psi \rangle$ is associated with an equivalence class of modalities, belonging to different contexts, but connected between themselves with certainty, even if the different CSCO observables do not commute. This equivalence class is called an extravalence class, and the associated transfer of certainty between contexts is called extracontextuality. As a simple example, the usual singlet state for two spins 1/2 can be found in the (non commuting) CSCOs associated with the measurement of the total spin (with $S=0,\;m=0$), or with a Bell measurement, and actually it appears in infinitely many different CSCOs - but obviously not in all possible ones.
The concepts of extravalence and extracontextuality are very useful to spell out the role of contextuality in quantum mechanics, that is not non-contextual (like classical physical would be), but not either fully contextual, since modalities belonging to incompatible (non-commuting) contexts may be connected with certainty. Starting now from extracontextuality as a postulate, the fact that certainty can be transferred between contexts, and is then associated with a given projector, is the very basis of the hypotheses of Gleason's theorem, and thus of Born's rule. Also, associating a state vector with an extravalence class clarifies its status as a mathematical tool to calculate probabilities connecting modalities, which correspond to the actual observed physical events or results. This point of view is quite useful, and it can be used everywhere in quantum mechanics.

### Other frameworks and extensions

A form of contextuality that may present in the dynamics of a quantum system was introduced by Shane Mansfield and Elham Kashefi, and has been shown to relate to computational quantum advantages. As a notion of contextuality that applies to transformations it is inequivalent to that of Spekkens. Examples explored to date rely on additional memory constraints which have a more computational than foundational motivation. Contextuality may be traded-off against Landauer erasure to obtain equivalent advantages.

## Fine's theorem

The Kochen–Specker theorem proves that quantum mechanics is incompatible with realistic noncontextual hidden variable models. On the other hand Bell's theorem proves that quantum mechanics is incompatible with factorisable hidden variable models in an experiment in which measurements are performed at distinct spacelike separated locations. Arthur Fine showed that in the experimental scenario in which the famous CHSH inequalities and proof of nonlocality apply, a factorisable hidden variable model exists if and only if a noncontextual hidden variable model exists. This equivalence was proven to hold more generally in any experimental scenario by Samson Abramsky and Adam Brandenburger. It is for this reason that we may consider nonlocality to be a special case of contextuality.

## Measures of contextuality
### Contextual fraction

A number of methods exist for quantifying contextuality. One approach is by measuring the degree to which some particular noncontextuality inequality is violated, e.g. the KCBS inequality, the Yu–Oh inequality, or some Bell inequality. A more general measure of contextuality is the contextual fraction.
Given a set of measurement statistics e, consisting of a probability distribution over joint outcomes for each measurement context, we may consider factoring e into a noncontextual part e$^{NC}$ and some remainder e',
$e=\lambda e^{NC}+(1-\lambda )e'\,.$
The maximum value of λ over all such decompositions is the noncontextual fraction of e denoted NCF(e), while the remainder CF(e)=(1-NCF(e)) is the contextual fraction of e. The idea is that we look for a noncontextual explanation for the highest possible fraction of the data, and what is left over is the irreducibly contextual part. Indeed, for any such decomposition that maximises λ the leftover e' is known to be strongly contextual. This measure of contextuality takes values in the interval [0,1], where 0 corresponds to noncontextuality and 1 corresponds to strong contextuality. The contextual fraction may be computed using linear programming.
It has also been proved that CF(e) is an upper bound on the extent to which e violates any normalised noncontextuality inequality. Here normalisation means that violations are expressed as fractions of the algebraic maximum violation of the inequality. Moreover, the dual linear program to that which maximises λ computes a noncontextual inequality for which this violation is attained. In this sense the contextual fraction is a more neutral measure of contextuality, since it optimises over all possible noncontextual inequalities rather than checking the statistics against one inequality in particular.

### Measures of (non)contextuality within the Contextuality-by-Default (CbD) framework

Several measures of the degree of contextuality in contextual systems were proposed within the CbD framework, but only one of them, denoted CNT$_2$, has been shown to naturally extend into a measure of noncontextuality in noncontextual systems, NCNT$_2$. This is important, because at least in the non-physical applications of CbD contextuality and noncontextuality are of equal interest. Both CNT$_2$ and NCNT$_2$ are defined as the $L_{1}$-distance between a probability vector $\mathbf {p}$ representing a system and the surface of the noncontextuality polytope $\mathbb {P}$ representing all possible noncontextual systems with the same single-variable marginals. For cyclic systems of dichotomous random variables, it is shown that if the system is contextual (i.e., $D\left({\mathcal {C}}_{n}\right)>\Delta \left({\mathcal {C}}_{n}\right)$),
$\mathrm {CNT} _{2}=D\left({\mathcal {C}}_{n}\right)-\Delta \left({\mathcal {C}}_{n}\right),$
and if it is noncontextual ( $D\left({\mathcal {C}}_{n}\right)\leq \Delta \left({\mathcal {C}}_{n}\right)$),
$\mathrm {NCNT} _{2}=\min \left(\Delta \left({\mathcal {C}}_{n}\right)-D\left({\mathcal {C}}_{n}\right),m\left({\mathcal {C}}_{n}\right)\right),$
where $m\left({\mathcal {C}}_{n}\right)$ is the $L_{1}$-distance from the vector $\mathbf {p} \in \mathbb {P}$ to the surface of the box circumscribing the noncontextuality polytope. More generally, NCNT$_2$ and CNT$_2$ are computed by means of linear programming. The same is true for other CbD-based measures of contextuality. One of them, denoted CNT$_3$, uses the notion of a quasi-coupling, that differs from a coupling in that the probabilities in the joint distribution of its values are replaced with arbitrary reals (allowed to be negative but summing to 1). The class of quasi-couplings $S$ maximizing the probabilities $\Pr \left[S_{q}^{c}=S_{q}^{c'}\right]$ is always nonempty, and the minimal total variation of the signed measure in this class is a natural measure of contextuality.

## Contextuality as a resource for quantum computing

Recently, quantum contextuality has been investigated as a source of quantum advantage and computational speedups in quantum computing.

### Magic state distillation

Magic state distillation is a scheme for quantum computing in which quantum circuits constructed only of Clifford operators, which by themselves are fault-tolerant but efficiently classically simulable, are injected with certain "magic" states that promote the computational power to universal fault-tolerant quantum computing. In 2014, Mark Howard, et al. showed that contextuality characterizes magic states for qubits of odd prime dimension and for qubits with real wavefunctions. Extensions to the qubit case have been investigated by Juani Bermejo Vega et al. This line of research builds on earlier work by Ernesto Galvão, which showed that Wigner function negativity is necessary for a state to be "magic"; it later emerged that Wigner negativity and contextuality are in a sense equivalent notions of nonclassicality.

### Measurement-based quantum computing

Measurement-based quantum computation (MBQC) is a model for quantum computing in which a classical control computer interacts with a quantum system by specifying measurements to be performed and receiving measurement outcomes in return. The measurement statistics for the quantum system may or may not exhibit contextuality. A variety of results have shown that the presence of contextuality enhances the computational power of an MBQC.
In particular, researchers have considered an artificial situation in which the power of the classical control computer is restricted to only being able to compute linear Boolean functions, i.e. to solve problems in the Parity L complexity class ⊕L. For interactions with multi-qubit quantum systems a natural assumption is that each step of the interaction consists of a binary choice of measurement which in turn returns a binary outcome. An MBQC of this restricted kind is known as an l2-MBQC.

#### Anders and Browne

In 2009, Janet Anders and Dan Browne showed that two specific examples of nonlocality and contextuality were sufficient to compute a non-linear function. This in turn could be used to boost computational power to that of a universal classical computer, i.e. to solve problems in the complexity class P. This is sometimes referred to as measurement-based classical computation. The specific examples made use of the Greenberger–Horne–Zeilinger nonlocality proof and the supra-quantum Popescu–Rohrlich box.

#### Raussendorf

In 2013, Robert Raussendorf showed more generally that access to strongly contextual measurement statistics is necessary and sufficient for an l2-MBQC to compute a non-linear function. He also showed that to compute non-linear Boolean functions with sufficiently high probability requires contextuality.

#### Abramsky, Barbosa and Mansfield

A further generalization and refinement of these results due to Samson Abramsky, Rui Soares Barbosa and Shane Mansfield appeared in 2017, proving a precise quantifiable relationship between the probability of successfully computing any given non-linear function and the degree of contextuality present in the l2-MBQC as measured by the contextual fraction. Specifically, $(1-p_{s})\geq \left(1-CF(e)\right).\nu (f)$where $p_{s},CF(e),\nu (f)\in [0,1]$ are the probability of success, the contextual fraction of the measurement statistics e, and a measure of the non-linearity of the function to be computed $f$, respectively.

### Further examples

* The above inequality was also shown to relate quantum advantage in non-local games to the degree of contextuality required by the strategy and an appropriate measure of the difficulty of the game.
* Similarly the inequality arises in a transformation-based model of quantum computation analogous to l2-MBQC where it relates the degree of sequential contextuality present in the dynamics of the quantum system to the probability of success and the degree of non-linearity of the target function.
* Preparation contextuality has been shown to enable quantum advantages in cryptographic random-access codes and in state-discrimination tasks.
* In classical simulations of quantum systems, contextuality has been shown to incur memory costs.