Self-testing quantum states and measurements in the prepare-and-measure scenario
Armin Tavakoli Jędrzej Kaniewski Tamás Vértesi Denis Rosset Nicolas Brunner
quant-ph















Département de Physique Appliquée, Université de Genève, CH-1211 Genève, Switzerland



QMATH, Department of Mathematical Sciences, University of Copenhagen,
	Universitetsparken 5, 2100 Copenhagen, Denmark



Institute for Nuclear Research, Hungarian Academy of Sciences, P.O. Box 51, 4001 Debrecen, Hungary



Perimeter Institute for Theoretical Physics, 31 Caroline St. N, Waterloo, Ontario, Canada, N2L 2Y5
Institute for Quantum Optics and Quantum Information (IQOQI), Boltzmangasse 3, 1090 Vienna, Austria



Département de Physique Appliquée, Université de Genève, CH-1211 Genève, Switzerland





The goal of self-testing is to characterise an a priori unknown quantum system based solely on measurement statistics, i.e. using an uncharacterised measurement device. Here we develop self-testing methods for quantum prepare-and-measure experiments, thus not necessarily relying on entanglement and/or violation of a Bell inequality. We present noise-robust techniques for self-testing sets of quantum states and measurements, assuming an upper bound on the Hilbert space dimension. We discuss in detail the case of a 2 → 1 random access code with qubits, for which we provide analytically optimal self-tests. The simplicity and noise robustness of our methods should make them directly applicable to experiments. 





Self-testing quantum states and measurements in the prepare-and-measure scenario

    Nicolas Brunner
    December 30, 2023
=================================================================================






Introduction.— Predicting the results of measurements performed on a given physical system has traditionally been the main concern of physics. However, with the advent of device-independent quantum information processing <cit.>, the opposite question has become relevant. More specifically, given an initially unknown system and an uncharacterised measurement device, what can be inferred about the physics of the experiment based solely on the observed measurement statistics? Despite the apparent generality of this question, certain cases do allow for a precise characterization of the system. This is referred to as self-testing <cit.>.  

The possibility to self-test quantum states and measurements usually relies on quantum nonlocality. Consider two distant observers performing local measurements on a shared quantum state. When the resulting statistics leads to violation of a Bell inequality <cit.>, it is necessarily the case that the shared quantum state is entangled, and moreover, that the local quantum measurements are incompatible; see e.g. <cit.>. Furthermore, for specific Bell inequalities, maximal violation (i.e. the largest possible value in quantum theory) implies that the quantum state and the measurements can be uniquely identified (up to local isometries). For instance, a maximal violation of the Clauser-Horne-Shimony-Holt (CHSH) Bell inequality <cit.> implies maximally incompatible measurements (two anti-commuting Pauli observables) and a shared maximally entangled two-qubit state <cit.>. More recently, it has been demonstrated that all bipartite pure entangled states can be self-tested <cit.>, as well as certain multipartite entangled states <cit.>. Another important progress is the development of self-testing methods robust to noise <cit.>. For instance, given a certain level of violation of a Bell inequality (but not necessarily maximal), the fidelity between the initially unknown state and a given target state can be lower-bounded. 

Self-testing thus offers promising perspectives for the certification of quantum systems in experiments (see e.g. <cit.>), as well as for device-independent quantum information protocols <cit.>. It is therefore natural to ask whether the concept of self-testing can be applied to more general quantum experiments, beyond those based on entanglement and nonlocality. 


In the present work, we develop self-testing methods tailored to the prepare-and-measure scenario. This covers a broad class of experiments, where quantum communication schemes (e.g. the BB84 quantum key distribution (QKD) protocol) are prominent examples. In this setting, a preparation device initially prepares a quantum system in different possible states. The system is then transmitted to a measurement device, which performs different possible measurements on it. While it is still possible in this case to characterise certain physical properties of the system based only on statistics, this requires in general an assumption on the devices. One possibility, which we will follow here, is to assume that the set of quantum states and measurements admit a full description in a Hilbert space of given dimension <cit.>. Intuitively this means that the amount of information communicated from the preparation device to the measurement device is assumed to be upper bounded. Such a scenario considering quantum systems of fixed dimension, but otherwise uncharacterised, is referred to as semi-device-independent, and opens interesting possibilities for quantum information processing <cit.>. 



Here we demonstrate techniques for robustly self-testing sets of prepared quantum states, as well as sets of quantum measurements. These methods allow one to (i) assess the compatibility of given sets of preparations and measurements with the observed statistics, and (ii) lower-bound the average fidelity between the unknown preparations (measurements) and a set of ideal quantum states (measurements). We discuss in detail a simple prepare-and-measure scenario, namely the 2 → 1 random access code (RAC). This allows us to provide analytically optimal self-tests for a pair of anti-commuting Pauli observables, and for a set of four qubit states corresponding to the eigenstates of two anti-commuting Pauli observables. We then generalise these results to other prepare-and-measure scenarios. The simplicity and robustness of our methods should make them directly applicable to experiments. We conclude with a number of open questions.




Scenario.— We consider a quantum prepare-and-measure experiment. Upon receiving input x, a preparation device emits a physical system in a quantum state ρ_x. The system is then transmitted to a measurement device, which, upon receiving an input y, performs a quantum measurement returning an outcome b. Formally, the measurement is described by a set of positive operators M_y^b, that equal identity when summed over b. Importantly both the specific states ρ_x and measurements M_y^b are a priori unknown to the observer. The statistics of the experiment is then given by P(b|x,y) = (ρ_x M_y^b).
In this setting, any possible probability distribution can be obtained, given that the prepared states ρ_x can be taken in a sufficiently large Hilbert space. This is however no longer the case when we limit the Hilbert space dimension; specifically we impose that ρ_x∈ℒ(ℂ^d) for some given d< |x| (where |x| denotes the number of possible inputs x). In this case, limits on the set of possible distributions can be captured via inequalities of the form

    𝒜 = ∑_x,y,bα_xyb P(b  | x, y) ≤  Q_d,

where α_xyb are real coefficients. These “dimension witnesses” allow one to place device-independent lower bounds on the dimension of the quantum system <cit.>.


Subsequently, one can ask what the limitations are on the set of distributions P(b|x,y) given that the preparations admit a classical d-dimensional representation, i.e. there exists a d-dimensional basis such that all states ρ_x are diagonal in this basis. We denote by C_d the maximal value of the quantity 𝒜 in this case. Interestingly, for well-chosen quantities 𝒜, one finds that C_d < Q_d. Thus, for a given system dimension d

, quantum systems outperform classical ones, in the sense that certain quantum distributions cannot be reproduced classically <cit.>. This quantum advantage can be viewed as the origin for the possibility of developing self-testing methods for the prepare-and-measure scenario; in analogy to Bell inequality violation being the root for self-testing entangled states. 

In the following we present robust self-testing techniques based on specific dimension witnesses 𝒜. Based only on the value of 𝒜, which is directly accessible from the experiment statistics, we characterise the (initially unknown) prepared states and measurements. In particular, when the maximal value of the witness is obtained, i.e. 𝒜 = Q_d, then a specific set of pure states ρ_x = |ψ_x⟩⟨ψ_x| and a specific set of projective measurements M_y^b must have been used (up to a unitary). Moreover, when a non-maximal value 𝒜 < Q_d is obtained, the compatibility of given sets of preparations and measurements can be assessed. Finally, one can efficiently lower bound the fidelity between the prepared states and measurements and the ideal (or target) states and measurement leading to 𝒜 = Q_d. 

Note that a recent series of works followed a related though conceptually different approach, based on hypothesis testing <cit.>. This method does however not allow for self-testing.
	 
The 2→ 1 random access code.— We discuss in detail a simple prepare-and-measure experiment. This involves four possible preparations, denoted by x = (x_0, x_1) (where x_j ∈{0,1} ), and two possible binary measurements, y∈{0,1} and b∈{0,1}. The score is given by 

    𝒜_2 = 1/8∑_x_0,x_1,y P(b=x_y | x_0,x_1,y)  .
 
This means that, upon receiving input y, the measurement device should return the output b=x_y, i.e. the y-th bit of the input bit-string x received by the preparation device. Hence the name of a 2→ 1 RAC <cit.>. Note that all inputs are assumed to be chosen uniformly at random. Indeed, this task is nontrivial only when d<4; here we will consider the case d=2, i.e. qubits. In this case, one finds the tight bounds C_2 = 3/4 and Q_2 = (1+1/√(2))/2 ≈ 0.85 <cit.>. The classical bound C_2 can be obtained by simply always sending the bit x_0. The quantum bound Q_2 is obtained via the following “ideal” strategy. The four qubit preparations correspond to the pure states 

    ρ_00^ideal=+σ_x/2   ρ_01^ideal=+σ_z/2
       ρ_11^ideal=-σ_x/2   ρ_10^ideal=-σ_z/2.
	
These are simply the eigenstates of the Pauli observables σ_x and σ_z. Next, the measurements are projective and given by two anti-commuting Pauli observables 

    M_y^ideal = (M_y^0)^ideal - (M_y^1)^ideal  = σ_x  + (-1)^y   σ_z/√(2).


These qubit preparations and measurements represent the ideal situation, where the maximal value 𝒜_2 = Q_2 is achieved. In the following we will determine what restrictions apply to the possible preparations and measurements, given that a particular value of 𝒜_2 is observed. In particular, when the maximal value 𝒜_2 = Q_2 is attained, both the states and the measurements must be the ideal ones as given above (up to a unitary).



Self-testing preparations.— Here we find restrictions on the set of prepared states given an observed value of 𝒜_2. For convenience, we write the qubit preparations as ρ_x_0x_1=(+m⃗_x_0x_1·σ⃗)/2, where m⃗_x_0x_1 denotes the Bloch vector (satisfying |m⃗_x_0x_1|≤ 1) and σ⃗ = (σ_x,σ_y, σ_z) denotes the vector of Pauli matrices. 

The first step consists in re-expressing   

    𝒜_2=1/2+1/8∑_y(M_y^0V_y)
    ≤1/2+1/8∑_y √((M_y^0V_y^2)(M_y^0))

where V_y=∑_x_0,x_1(-1)^x_yρ_x_0x_1. In the second step we used that for a positive semi-definite O and a Hermitian operator R, it holds that |(OR)|^2≤(OR^2)(O) <cit.>. Without loss of generality, we can restrict to extremal qubit measurements, which are here projective rank-one operators. Consequently, we have that (M_y^0)=1. Next, we obtain V_y^2 = 1/2(β + (-1)^y α), where

    β=1/2∑_x_0,x_1|m⃗_x_0x_1|^2-m⃗_00·m⃗_11-m⃗_01·m⃗_10
       α=(m⃗_00-m⃗_11)·(m⃗_01-m⃗_10).

Finally, we find that Eq. (<ref>) reduces to

    𝒜_2 ≤1/2+1/8√(2)[√(β+α)+√(β-α)].


This provides a tight self-test of the prepared states (in terms of their Bloch vectors), for any given value of 𝒜_2. Let us start with the case 𝒜_2 = Q_2. Since √(β+α)+√(β-α)=√( 2β+2√(β^2-α^2)), we see that Eq. (<ref>) is maximal iff α=0 and β is maximal. This turns out to be achievable. In order to maximise β, we need (i) ∀ x_0x_1: |m⃗_x_0x_1| =1, i.e. that all preparations are pure states, and (ii) that m⃗_00·m⃗_11=m⃗_01·m⃗_10=-1, i.e. the states correspond to (pairwise) antipodal Bloch vectors. We define r⃗_0=m⃗_00=-m⃗_11 and r⃗_1=m⃗_01=-m⃗_10. Consequently, we find α=4r⃗_0·r⃗_1. Therefore, in order to have α=0, we must choose r⃗_0·r⃗_1=0. This implies that the right-hand-side of Eq. (<ref>) is upper-bounded by Q_2. Therefore, we conclude that when observing maximal value 𝒜_2 = Q_2, the set of four prepared states must be equivalent (up to a unitary rotation) to the set of four ideal states; we note that this was also shown in Ref. <cit.> in the context of QKD.

More generally, for any value 𝒜_2, one can find a set of preparations (and corresponding measurements) such that the inequality (<ref>) is saturated, see Supplementary Material (SM) part A. For the case of classical preparations (i.e. diagonal in a given basis), the Bloch vectors can simply be replaced by numbers m_x_0x_1∈ [-1,1], and we get 𝒜_2 ≤ C_2.




Self-testing measurements.— Let us now consider self-testing of measurements. Using that M_y = M_y^0 - M_y^1, we write


    𝒜_2    =1/2+1/16∑_x_0,x_1( ρ_x_0x_1 [ (-1)^x_0M_0+(-1)^x_1M_1] )
       ≤1/2+1/16∑_x_0,x_1[(-1)^x_0M_0+(-1)^x_1M_1],


where [X] is the largest eigenvalue of the (Hermitian) operator X. Since the upper bound corresponds to choosing the optimal preparations for a fixed pair of observables, it simply quantifies the optimal performance achievable using these observables. If M_0 and M_1 are qubit observables the upper bound can be evaluated exactly (see SM part A) to give


    𝒜_2 ≤1/2 + 1/16( √( 2 μ + 2 ν - η_+^2) + √( 2 μ - 2 ν - η_-^2)),


where μ = ( M_0^2 + M_1^2), ν = {M_0, M_1} and η_± =  (M_0± M_1). The right-hand side reaches the optimal value Q_2 iff μ = 4, η_± = 0 and ν = 0, which implies anti-commuting projective observables (i.e. projective measurement operators). In other words, observing 𝒜_2 = Q_2 implies that the measurements are unitarily equivalent to the ideal ones. Moreover, note that inequality (<ref>) is tight; for any value of 𝒜_2 one can find measurements (and corresponding states) such that inequality is saturated (see SM part A). It follows that any pair of projective, rank-one observables that is incompatible (|ν| < 4) can lead to 𝒜_2>C_2.


Robust self-testing of the preparations.— 
We now discuss the problem of characterizing the fidelity between the realised preparations and the ideal ones. This will allow us to quantify the distance of the prepared states with respect to the ideal ones. Again, we want to develop self-testing methods which are based only on the value of 𝒜_2.


More formally, given an arbitrary set of preparations, we define the average fidelity with the ideal preparations to be S({ρ_x_0x_1})=max_Λ∑_x_0,x_1 F(ρ_x_0x_1^ideal,Λ[ρ_x_0x_1])/4, where Λ is a quantum channel i.e. a completely positive trace-preserving map. Here the fidelities F(ρ,σ)=(√(√(ρ)σ√(ρ))) simplify to F(ρ^ideal_x_0x_1,Λ[ρ_x_0x_1])=(Λ[ρ_x_0x_1]ρ^ideal_x_0x_1), as the ρ^ideal_x_0x_1 are pure states.  We derive lower bounds on the smallest possible value of S given a value of 𝒜_2,	 i.e.,

    ℱ(𝒜_2)= min_{ρ_x_0x_1}∈ R(𝒜_2) S[{ρ_x_0x_1}].

Note that this involves a minimisation over all sets of four preparations R(𝒜_2) that are compatible with an observed value 𝒜_2.  



In order to lower bound ℱ, we use an approach inspired by Ref. <cit.>. From Eq. (<ref>), we have 𝒜_2= 1/2+∑_x_0,x_1(W_x_0x_1ρ_x_0x_1), where  W_x_0x_1=1/16∑_y(-1)^x_yM_y. 
We define operators corresponding to some suitably chosen channel acting on the ideal preparations:

    K_x_0x_1(M_0,M_1)= Λ^†(M_0,M_1)[ρ^ideal_x_0x_1],

where Λ^† is the channel dual to Λ. We aim to construct operator inequalities of the form 

    K_x_0x_1(M_0,M_1)≥ s W_x_0x_1+t_x_0x_1(M_0,M_1),

for all inputs (x_0,x_1), for any given measurements, where s and t_x_0x_1(M_0,M_1) are real coefficients. Finding such inequalities, as well as a suitable channel Λ allows us to lower bound S as follows: 


    S ≥1/4∑_x_0,x_1(K_x_0x_1ρ_x_0x_1)≥s/4∑_x_0,x_1(W_x_0x_1ρ_x_0x_1)
    
    +1/4∑_x_0,x_1t_x_0x_1=s/4(𝒜_2-1/2)+1/4∑_x_0,x_1t_x_0x_1,

Applying a minimisation over M_0 and M_1 to the right-hand-side, the above inequality becomes valid for all preparations. Consequently,  

    ℱ(𝒜_2)≥s/4(𝒜_2-1/2)+t≡ L(𝒜_2),

where t ≡ 1/4  min_M_0,M_1∑_x_0,x_1 t_x_0x_1(M_0,M_1). In SM part B, we construct explicitly the channel and derive an operator inequality leading to a lower bound, given by s=4(1+√(2)) and t=(2-√(2))/4. 

This provides a robust self-testing for the preparations. A maximal value 𝒜_2 = Q_2 implies ℱ=1, i.e. the preparations must be the ideal ones (up to a unitary). For 𝒜_2 = C_2, i.e. a maximal value given a set of classical states, we get that ℱ≥ 3/4. This bound can be attained via the set of pure states ρ_x_0x_1 = (  + (-1)^x_0x_1σ_z)/2 (diagonal in the same basis, hence classical), combined with the measurements M_0= M_1 = σ_z. Therefore, we see that our bound ℱ(𝒜_2) ≥ L(𝒜_2) is optimal, as far as linear inequalities are concerned (see Fig. 1). It is then interesting to consider the intermediate region C_2 <𝒜_2 < Q_2. First, focusing on strategies involving a single set of states and measurements, we observe numerically that the linear bound ℱ(𝒜_2) ≥ L(𝒜_2) cannot be saturated anymore, and conjecture the form of optimal states and measurements; see red curve in Fig. 1 and SM part C for details. Second, allowing for shared randomness between the preparation and measurement device (such that convex combinations of qubit strategies are now possible), the linear bound becomes tight, a direct consequence of the linearity of ℱ and 𝒜_2 in terms of the states and measurements. 









Robust self-testing of the measurements.— 
Similarly, we can quantify the average fidelity of the measurements with respect to the ideal ones: S'({M_y^b})=max_Λ∑_y,b F((M_y^b)^ideal,Λ[M_y^b])/4, where Λ must be a unital channel (i.e. mapping the identity to itself), in order to ensure that measurements are mapped to measurements. In analogy with the case of preparations, our goal is to lower bound the following quantity:

    ℱ'(𝒜_2)= min_{M_y^b}∈ R'(𝒜_2)  S'({M_y^b}),

where R'(𝒜_2) represents all sets of measurements compatible with a certain value of 𝒜_2.

We first rewrite 𝒜_2=∑_y,b (M_y^b Z_yb ), where Z_yb= 1/8∑_x_0,x_1ρ_x_0x_1δ_b,x_y. 
Next, we construct operator inequalities 

    K_yb({ρ_x_0x_1})≥ sZ_yb+t_y({ρ_x_0x_1}) ,

given the unital channel K_yb=Λ^†[(M_y^b)^ideal]. Similarly to the case of preparations, strong operator inequalities can be derived by choosing carefully the channel; all details are given in SM part D. Finally, this leads to a lower bound on the average fidelity

    ℱ'(𝒜_2)    ≥min_{ρ_x_0x_1}1/4∑_y,b(K_ybM_y^b)  ≥ L(𝒜_2).

That is, we find that ℱ' can be lower-bounded by a linear expression in terms of 𝒜_2, which turns out to be the same as for the case of preparations. 

This provides a robust self-test for the measurements. Observing 𝒜_2=Q_2 implies that ℱ'=1, hence the measurements are equivalent to the ideal ones (up to a unitary). For 𝒜_2=C_2, we have that ℱ≥ 3/4. This lower bound can be attained by choosing M_0 = σ_z and M_1 =, with the states ρ_00=ρ_01 = (+ σ_z)/2 and ρ_10=ρ_11 = (- σ_z)/2. For C_2<𝒜_2<Q_2, we find numerically that the inequality (<ref>) cannot be saturated using a single set of measurements and states (see Fig. 1). Details, in particular a conjecture for the form of the optimal measurements, are given in SM part C. Similarly as for the case of states, when allowing for convex combinations of qubit strategies, our linear bound is tight.  









Generalisations.— The above results can be generalised in several directions. Firstly, a generalisation of the 2 → 1 RAC enables self-testing of any pair of incompatible Pauli observables (see SM part E). Secondly, we derive compatibility relations for the N → 1 RAC with qubits (see SM part F). Thirdly, we self-test qutrit preparations and projective measurements in the 2 → 1 RAC (see SM part G).

Finally, we present a numerical method for robust self-testing of preparations applicable in scenarios beyond RACs. The method is based on semi-definite programing and combines (i) the swap-method <cit.> used for self-testing in Bell scenarios with (ii) the hierarchy of finite-dimensional quantum correlations <cit.>. The idea is to first construct a swap operator, based on the measurement operators, which maps the state of the preparation onto an ancilla. The average fidelity between the ancilla and the ideal states can then be expressed in terms of strings of products of measurements operators and the extracted states. The last step is to miminize this average fidelity over all quantum realisations that are compatible with a given witness value, using the hierarchy of Refs <cit.>. Although typically returning sub-optimal bounds on ℱ, this method is widely applicable. In SM part H, we describe in detail the methodology and apply to two examples, including the 2 → 1 RAC.







Outlook.— We presented methods for self-testing quantum states and measurements in the prepare-and-measure scenario. These techniques demonstrate strong robustness to noise, and should therefore be directly amenable to experiments, providing useful certification techniques in a semi-device-independent setting. Moreover, these ideas should find applications in quantum communications. Our methods apply to the states and measurements used in QKD (e.g. in BB84), as well as in semi-device-independent QKD and randomness generation protocols <cit.>.



It would be interesting to develop robust self-testing techniques for more general scenarios, e.g. for higher dimensional quantum systems. Another direction would be to consider scenarios beyond prepare-and-measure, for instance adding between the preparation and measurement devices a transformation device <cit.>, and self-test the latter.


Finally, while we have focused here on self-testing based on an assumption on the dimension, one could develop methods based on different assumptions, such as a bound on the mean energy <cit.>, the overlap <cit.>, or the entropy <cit.>.






Acknowledgements.—
This work was supported by the Swiss national science foundation (Starting grant DIAQ, QSIT, and Early Postdoc Mobility fellowship P2GEP2_162060), the European Union's Horizon 2020 research
and innovation programme under the Marie Skłodowska-Curie Action
ROSETTA (grant no. 749316), the European Research Council (grant
no. 337603), the Danish Council for Independent Research (Sapere Aude), VILLUM FONDEN via the QMATH Centre of Excellence (grant no. 10059), and the National Research, Development and Innovation Office NKFIH (Grants No. K111734, and No. KH125096).

99
	
	

ABG07	
A. Acín, N. Brunner, N. Gisin, S. Massar, S. Pironio, and V. Scarani. 

Phys. Rev. Lett., 98, 23 (2007).

Col07
R. Colbeck,

PhD thesis, University of Cambridge, 2007. ArXiv: 0911.3814.


PAM10
S. Pironio, A. Acín, S. Massar, A. Boyer  De La Giroday, N. D. Matsukevich, P. Maunz, S. Olmschenk, D. Hayes, L. Luo, T. A. Manning, and C. Monroe,

Nature 464 10 (2010).



MY98
D. Mayers, and A. Yao,

Proc. 39th FOCS (Washington, DC: IEEE Computer Society) p 503 (1998).

MY04
D. Mayers, and A. Yao,

Quantum Information and Computation, 4(4):273-286, July 2004

bell J. S. Bell, Physics 1, 195 (1964).

review N. Brunner, D. Cavalcanti, S. Pironio, V. Scarani, and S. Wehner, Rev. Mod. Phys. 86, 419 (2014).


CHSH69
J. F. Clauser, M. A. Horne, A. Shimony, and R. A. Holt,

Phys. Rev. Lett., 23 (15), 1969.


SW87
S. J. Summers, and R. Werner

J. Math. Phys. 28 2440 (1987).


PR92
S. Popescu and D. Rohrlich,

Phys. Lett. A, 169(6), 1992.


T93
B. S. Tsirelson,

Hadronic J. Suppl., 8, 329 (1993).

RUV B. W. Reichardt, F. Unger and U. Vazirani, Nature 496, 456 (2013).








CG17
A. Coladangelo, K. T. Goh, and V. Scarani,

 Nature Communications 8, 15485 (2017).
 
 
M14
M. McKague,

Proc. TQC'11, LNCS, 6745, 2014.

 
PVN14
K. F. Pál, T. Vértesi, and M. Navascués,

Phys. Rev. A, 90, 042340  (2014).
 
WCY14
X. Wu, Y. Cai, T. H. Yang, H. N. Le, J.-D. Bancal,
and V. Scarani. 

Phys. Rev. A, 90, 042339 (2014).





BLM09
C.-E. Bardyn, T. C. H. Liew, S. Massar, M. McKague, and V. Scarani. 

Phys. Rev. A 80, 062327 (2009). 

MYS12
M. McKague, T. H. Yang, and V. Scarani,

J. Phys. A: Math. Theor., 45 455304 (2012).


YN13
T. H. Yang, and M. Navascués,

Phys. Rev. A, 87, 050102(R)  (2013).

BP15
C. Bamps and S. Pironio. 

Phys. Rev. A, 91, 052111  (2015).



swaptrick
T. H. Yang, T. Vértesi, J-D. Bancal, V. Scarani, and M. Navascués,

Phys. Rev. Lett. 113, 040401 (2014).












Kan16
J. Kaniewski,

Phys. Rev. Lett., 117, 070402 (2016).


Kan17
J. Kaniewski,

Phys. Rev. A 95, 062323 (2017).


wineland T. R. Tan, Y. Wan, S. Erickson, P. Bierhorst, D. Kienzler, S. Glancy, E. Knill, D. Leibfried, and D. J. Wineland, 
Phys. Rev. Lett. 118, 130403 (2017).

supic I. Supic, R. Augusiak, A. Salavrakos, A. Acin,

New J. Phys. 18, 035013 (2016).



GB10
R. Gallego, N. Brunner, C. Hadley, and A. Acin,

Phys.Rev.Lett. 105, 230501, (2010).

Hendrych  M. Hendrych, R. Gallego, M. Micuda, N. Brunner, A. Acin, and J. P. Torres, Nature Physics 8, 588 (2012).

Ahrens J. Ahrens, P. Badziag, A. Cabello, and M. Bourennane, Nature Physics 8, 592 (2012).


PB11
M. Pawłowski and N. Brunner,

Phys. Rev. A 84, 010302(R) (2011).

LYW11
H-W Li, M. Pawłowski, Z-Q. Yin, G-C. Guo, and Z-F. Han,

Phys. Rev. A 84, 034301 (2011).

WP15
E. Woodhead, and S. Pironio,

Phys. Rev. Lett. 115, 150501 (2015).

Lunghi T. Lunghi, J. B. Brask, C. C. W. Lim, Q. Lavigne,
J. Bowles, A. Martin, H. Zbinden, and N. Brunner,

Phys. Rev. Lett. 114, 150501 (2015).

MT16
P. Mironowicz, A. Tavakoli, A. Hameedi, B. Marques, M. Pawłowski, and M. Bourennane,

 New J. Phys. 18, 065004 (2016).


michele1 M. Dall'Arno, S. Brandsen, F. Buscemi, V. Vedral,

Phys. Rev. Lett. 118, 250501 (2017). 

michele2 M. Dall'Arno, S. Brandsen, F. Buscemi,

Proc. R. Soc. A 473, 20160721 (2017).

michele3 M. Dall'Arno,

arXiv:1702.00575. 


ANTV99
A. Ambainis, A. Nayak, A. Ta-Shama, U. Vazirani,

in Proceedings of 31st ACM Symposium on Theory of Computing, pp. 376-383, 1999.


N99
A. Nayak,

in Proceedings of the 40th IEEE Symposium on Foundations of Computer Science (FOCS'99), pp. 369-376, 1999.




TH15
A. Tavakoli, A. Hameedi, B. Marques, and M. Bourennane,

Phys. Rev. Lett. 114, 170502 (2015).

Woodhead
E. Woodhead, C. Lim, and S. Pironio,

Proc. TQC'12, LNCS, 7582, 107.




NV
M. Navascués and Tamás Vértesi,

Phys. Rev. Lett. 115, 020501 (2015).

NV2
M. Navascués, A. Feix, M. Araújo, and A. Vértesi,

Phys. Rev. A 92, 042117 (2015).
Symmetry
A. Tavakoli, D. Rosset, and M. O. Renou,
arXiv:1808.02412.


TS05
P. Trojek, C. Schmid, M. Bourennane, C. Brukner, M. Żukowski, and H. Weinfurter,

Phys. Rev. A 72, 050305(R) (2005).

bowles15 J. Bowles, N. Brunner, M. Pawłowski, Phys. Rev. A 92, 022351 (2015).


thomas T. Van Himbeeck, E. Woodhead, N. J. Cerf, R. García-Patron, S. Pironio, Quantum 1, 33 (2017).


BME17
J. B. Brask, A. Martin, W. Esposito, R. Houlmann, J. Bowles, H. Zbinden, and N. Brunner,

Phys. Rev. Applied 7, 054018 (2017).

chaves R. Chaves, J. Bohr Brask, and N. Brunner, 

Phys. Rev. Lett. 115, 110501 (2015).









§ SELF-TESTING RELATIONS FOR PREPARATIONS AND MEASUREMENTS


In this section we provide a simple example of preparations that saturate the compatibility bound for 𝒜_2 given in the main text. Moreover, we derive the upper bound for compatibility of measurements given in the main text.

First, we consider the case of preparations. 
Consider preparations such that ρ_00 and ρ_11, and ρ_01 and ρ_10 correspond to antipodal Bloch vectors with a relative angle θ, the maximal quantum value of 𝒜_2, is obtained from

    𝒜_2=1/2+1/8∑_y[V_y],

where V_y=∑_x_0,x_1(-1)^x_yρ_x_0x_1. We represent the preparations on the Bloch sphere as ρ_x_0x_1=1/2(+m⃗_x_0x_1·σ⃗), where m⃗_00=[cos(θ/2),0,sin(θ/2)] and m⃗_01=[cos(θ/2),0,-sin(θ/2)], with m⃗_11=-m⃗_00 and m⃗_10=-m⃗_01. This gives V_0=2cos(θ/2)σ_x and V_1=2sin(θ/2)σ_z. The respective largest eigenvalues are [V_0] = 2cos(θ/2) and [V_1] =2sin(θ/2), leading to 

    𝒜_2= 1/2+ 1/4√(2)[√(1+cosθ)+√(1-cosθ)].
 
It is straightforward to see that this achieves the upper bound in the main text; indeed the above choice of preparations leads to β=4 and α=4cosθ.



In order to derive the upper bound on 𝒜_2 for compatibility of measurements in the main text we evaluate


    ∑_x_0 ,x_1[ (-1)^x_0 M_0+(-1)^x_1 M_1]


for arbitrary qubit observables M_0, M_1. We take advantage of the fact that


    [ T ] +  [ -T ] =  [ T ] - λ_min [ T ],


which for a 2 × 2 matrix can be evaluated analytically. More specifically, if T is a 2 × 2 Hermitian matrix with eigenvalues λ_0≥λ_1, let


    χ   :=  T = λ_0 + λ_1,
    
    ζ   :=  T^2 = λ_0^2 + λ_1^2


and then


    λ_0 - λ_1 = √( 2 ζ - χ^2).


Evaluating this expression for T = M_0± M_1 gives the desired upper bound given.









§ OPERATOR INEQUALITIES FOR ROBUST SELF-TESTING OF PREPARATIONS


In this section we provide a detailed derivation of the lower bound on the average fidelity ℱ(𝒜_2).



For a real constant s > 0, to be chosen later, consider for each pair (x_0, x_1) the operator K_x_0 x_1 - s W_x_0 x_1, where W_x_0x_1=1/16∑_y(-1)^x_yM_y and K_x_0x_1= Λ^†[ρ^ideal_x_0x_1], for some channel Λ.
Suppose now that t_x_0 x_1∈ℝ is a lower bound on its eigenvalues, or, equivalently, that the operator inequality

    K_x_0 x_1≥ s W_x_0x_1 + t_x_0x_1

holds. Then, computing the trace of this inequality with ρ_x_0 x_1 and averaging over inputs leads to

    S ≥1/4∑_x_0, x_1 F(ρ^ideal_x_0 x_1, Λ[ρ_x_0 x_1]) ≥s/4 (𝒜_2 - 1/2 ) + t,      t ≡1/4∑_x_0, x_1 t_x_0 x_1 ,

where the first inequality holds because S is defined as maximisation over all possible channels, and the Λ used there is one possible choice.
In turn, if (<ref>) holds as an operator inequality, it is valid for any set of preparations {ρ_x_0 x_1}, and thus ℱ(𝒜_2) ≥s/4( 𝒜_2 - 1/2) + t. Note that (<ref>) has a dependence on M_0, M_1 through W_x_0 x_1. If (<ref>) holds for a particular choice of measurement operators M_0, M_1, then the bound on ℱ(𝒜_2) holds for all preparations, for that particular choice of M_0, M_1. However, if (<ref>) holds for all possible M_0, M_1, then the bound on ℱ(𝒜_2) is valid for all quantum setups and is thus a robust self-testing inequality. To derive the appropriate constants s and t_x_0 x_1, we first allow t_x_0 x_1 and Λ to have a dependence on M_0 and M_1. We then minimise over M_0 and M_1 the constants t_x_0 x_1, for a suitable choice of s, such that, at the end, (<ref>) holds regardless of the choice of measurement operators.

We choose a dephasing channel of the form

    Λ_θ(ρ)=1+c(θ)/2ρ+1-c(θ)/2Γ(θ)ρΓ(θ),

where for 0≤θ≤π/4 we use Γ=σ_x, while for π/4< θ≤π/2 we use Γ=σ_z. The function c(θ) ∈ [-1, 1] will be specified later.

In the interval 0≤θ≤π/4, the action of the channel leads to

    K_00=+σ_x/2     K_01=+c(θ)σ_z/2        K_10=-c(θ)σ_z/2         K_11=-σ_x/2,

whereas in the interval π/4< θ≤π/2, we have 

    K_00=+c(θ)σ_x/2     K_01=+σ_z/2       K_10=-σ_z/2       K_11=-c(θ)σ_x/2.


As discussed in the main text, for any given set of preparations, the optimal measurements are projective and rank-one. Furthermore, any two such measurements can be represented on an equator of the Bloch sphere. Due to the freedom of setting the reference frame, we can without loss of generality represent the two measurements in the xz-plane, i.e.

    M_0=cosθσ_x+sinθσ_z      M_1=cosθσ_x-sinθσ_z .

We can therefore write W_x_0x_1 as

    W_00=1/8cosθσ_x     W_01=1/8sinθσ_z        W_10=-1/8sinθσ_z        W_11=-1/8cosθσ_x.

We can reduce the number of operator inequalities (<ref>) by exploiting the apparent symmetries in the expressions for W_x_0x_1 and K_x_0x_1: we restrict ourselves so that t_o≡ t_01=t_10 and t_e≡ t_00=t_11. Thus, we have to consider two operator inequalities in each interval θ∈ [0,π/4] and θ∈ (π/4,π/2]. In the first interval, the two operator inequalities are

    1+σ_x/2-s/8cosθσ_x-t_e≥ 0       1+c(θ)σ_z/2-s/8sinθσ_z-t_o≥ 0.

In the second interval, the two operator inequalities are

    1+c(θ)σ_x/2-s/8cosθσ_x-t_e≥ 0       1+σ_z/2-s/8sinθσ_z-t_o≥ 0.

We now focus on the former interval. Solving the two inequalities for t_o and t_e we obtain

    t_e≤ 1-s/8cosθ,    t_o   ≤1/8(4+4c(θ)-ssinθ),
       t_e≤s/8cosθ,    t_o   ≤1/8(4-4c(θ)+s sinθ).


Any choice of t_o and t_e satisfying these constraints gives rise to valid operator inequalities. In order to obtain the strongest bound, we choose the largest values of t_o and t_e consistent with their respective constraints, i.e.,

    t_e=min{1-s/8cosθ ,s/8cosθ}    t_o=min{1/8(4+4c(θ)-ssinθ),1/8(4-4c(θ)+s sinθ)}.

A similar procedure for the interval θ∈ (π/4,π/2] leads to 

    t_e=min{1/8(4+4c(θ)-scosθ),1/8(4-4c(θ)+s cosθ)}    t_o=min{1-s/8sinθ ,s/8sinθ}.

It is worth pointing out that the two intervals only differ by exchanging t_e↔ t_o and sinθ↔cosθ. Hence, for any given θ, we have constructed operator inequalities of the form (<ref>). 

As shown in the main text, we obtain our lower bound on the average fidelity from

    ℱ(𝒜_2)≥s/4(𝒜_2-1/2)+min_M_0,M_1t(M_0,M_1)≡ L(𝒜_2),

where t(M_0,M_1)=(t_e+t_o)/2. To compute this quantity we fix the value of s to be


    s=4(1+√(2))


and choose the dephasing function as c(θ)=min{1,s/4sinθ} whenever θ∈ [0,π/4], and c(θ)=min{1,s/4cosθ} whenever θ∈ (π/4,π/2]. It is easy to see that c(θ) ∈ [0, 1], which ensures that Λ_θ is a valid quantum channel, and that c(θ) is continuous at θ=π/4. A simple calculation shows that in this case


    t=2-√(2)/4,

which gives the lower bound

    ℱ(𝒜_2)≥(1+√(2))𝒜_2-3/2√(2)≡ L(𝒜_2).


One can check that choosing distinct values of s will not lead to improved lower bounds.




§ TIGHTNESS OF FIDELITY BOUNDS


In the main text, we have derived fidelity bounds for both the preparations and the measurements, based on operator inequalities. Specifically, we obtain a lower bound on the average fidelity ℱ of the prepared states (with respect to the ideal ones) given by the linear expression

    ℱ(𝒜_2)≥(1+√(2))𝒜_2-3/2√(2)≡ L(𝒜_2).

For measurements, a similar bound is obtained on the average fidelity ℱ' with respect to the ideal ones. In the present appendix, we discuss the tightness of these bounds. 

We start with our bound on the fidelity of the states. As discussed in the main text, obtaining 𝒜_2 = Q_2 implies ℱ=1, i.e. the states are the ideal ones (up to a unitary). Let us refer to the optimal strategy (with the ideal states) as strategy S_1. Then, for 𝒜_2 = C_2, our bound gives ℱ≥ 3/4. This bound is tight and can be obtained via the set of pure states ρ_x_0x_1 = (  + (-1)^x_0x_1σ_z)/2 (diagonal in the same basis, hence classical), combined with the measurements M_0= M_1 = σ_z. Let us refer to this strategy as S_2. 

The above shows that our bound (<ref>) is tight as far as linear inequalities are concerned. More generally, the bound is in fact tight in general, when shared randomness between the preparation and measurement devices is taken into account. In this case, taking a convex combination between strategies S_1 and S_2 allows us to get any point on the line (i.e. pair of values ℱ and 𝒜_2) between S_1 and S_2.



It is also interesting to understand what happens when shared randomness between the devices is not taken into account. In this case, the end points (𝒜_2 = Q_2, ℱ=1) and (𝒜_2 = C_2, ℱ=3/4) can still be obtained. To understand what happens in the intermediate region C_2 <𝒜_2 < Q_2, we first performed a numerical analysis. Specifically, we chose randomly four qubit states, and compute (i) the maximal value of 𝒜_2 (optimizing over the measurements), and (ii) the average fidelity ℱ (where the optimization over channels is restricted here to unitaries). The resulting points are shown on Fig. 2 (blue circles). This indicates that for C_2 <𝒜_2 < Q_2, the bound (<ref>) cannot be saturated anymore. Moreover, we conjecture that an optimal class of strategies is given by the pure states

    |ψ_00⟩ = |0⟩  |ψ_11⟩ = |1⟩  |ψ_01⟩ =  cosθ|0⟩ + sinθ|1⟩  |ψ_10⟩ =  cosθ|0⟩ - sinθ|1⟩

and the measurements M_y = cos(φ) σ_z  + (-1)^y sin(φ) σ_x. Straightforward calculations show that, taking tanφ= sin2θ, leads to 

    𝒜_2 = 1/2 + 1/4√(1 + tan^2(φ))  and  ℱ = 1/4 (3 + tanφ )   .

This gives a parametric curve, as a function of φ∈ [0 , π/4], given by the red curve in Fig. 2. This  curve is in excellent agreement with the numerical results obtained before. Note that this class of strategies interpolates between the strategies S_1 (setting φ =0) and S_2 (setting φ = π/4).







Next we discuss the bound on the average fidelity of measurements. As discussed in the main text, the linear bound ℱ'(𝒜_2)≥  L(𝒜_2) is optimal as far as linear inequalities are concerned. Moreover, when allowing for shared randomness the bound is tight in general for C_2 ≤𝒜_2 ≤ Q_2. This is obtained by considering convex combinations of strategy S_1' (defined as the optimal strategy S_1, up to a rotation of π/8 around the y axis; see below), and the following strategy (referred to as S_3): take M_0 = σ_z and M_1 =, with the states ρ_00=ρ_01 = (+ σ_z)/2 and ρ_10=ρ_11 = (- σ_z)/2. 

Similarly to the case of states, we now consider the situation where shared randomness between the devices is not allowed. Performing a numerical analysis similar to the one described above (except that measurements are no generated randomly), we observe that the accessible region (in terms of ℱ' vs 𝒜_2) appears to be exactly the same as for the case of states (i.e. the blue region in Fig. 2). We conjecture that the lower bound is given by the following class of optimal strategies: take the measurements:

    M_0 = σ_z      and     M_1 = ησ_x + (1-η)

with the states |ψ_00⟩ =  cosθ|0⟩ + sinθ|1⟩, |ψ_01⟩ =  cosθ|0⟩ - sinθ|1⟩, |ψ_10⟩ =  cosθ|1⟩ + sinθ|0⟩, and |ψ_11⟩ =  cosθ|1⟩ - sinθ|0⟩. Setting η = tan2 θ, we get

    𝒜_2 = cos^2(θ)/2 + 1/4 + sin^2(2θ)/cos(2θ)  and  ℱ = 1/4 (3 + tan(2θ) )   .

This gives a parametric curve, as a function of θ∈ [0 , π/8], given by the red curve in Fig. 2. This  curve is in excellent agreement with the numerical results obtained before. Also, this curve turns out to be exactly the same as the curve we obtained above for the case of states. Note that this class of strategies interpolates between the strategies S_1' (setting θ =π/8) and S_3 (setting θ = 0).

Finally, note that the numerics also suggests that there is a linear upper bound on the average fidelities ℱ (ℱ') as a function of 𝒜_2 (see Fig. 2); specifically ℱ≤1-Q_2/Q_2 - 3/4𝒜_2 + Q_2^2 -3/4/Q_2 - 3/4 and similarly for ℱ'. It would be interesting to provide a proof of these upper bounds.






§ OPERATOR INEQUALITIES FOR ROBUST SELF-TESTING OF MEASUREMENTS


In this section, we account for the detailed derivation of the lower bound on the average fidelity of the measurements ℱ'(𝒜_2). The approach bears significant resemblance to the case of robustly self-testing preparations, as outlined in Appendix <ref>. 

We aim to derive operator inequalities of the form

    K_yb({ρ_x_0x_1})≥ sZ_yb+t_y({ρ_x_0x_1}),

where  Z_yb= 1/8∑_x_0,x_1ρ_x_0x_1δ_b,x_y and K_yb({ρ_x_0x_1})=Λ^†[(M_y^b)^ideal]. For the sake of simplicity, we first apply a unitary channel to (M_y^b)^ideal align these operators with the eigenstates of σ_x and σ_z. Then, we adopt the same (unital, trace-preserving) channel Λ as specified in the main text, with the same coefficients as used to robustly self-test the preparations: c(θ)=min{1,s/4sinθ} when θ∈ [0,π/4] and c(θ)=min{1,s/4cosθ} when θ∈(π/4,π/2].

It is straightforward to see that, for any given pair of measurements, the optimal choice of preparations are four pure qubit states, such that ρ_00 and ρ_11, and ρ_01 and ρ_10 respectively, correspond to antipodal vectors on the Bloch sphere. Therefore, we can without loss of generality restrict to such preparations since these impose the weakest constraints on the measurements of our interest. We can therefore parametrise the preparations ρ_x_0x_1=1/2(+m⃗_x_0x_1·σ⃗) by Bloch vectors

    m⃗_00=[cosθ,0,sinθ]    m⃗_11=-[cosθ,0,sinθ]       m⃗_01=[cosθ,0,-sinθ]       m⃗_10=[-cosθ,0,sinθ].

Expressing Z_yb in terms of these preparations gives

    Z_00=1/8(+cosθσ_x)     Z_01=1/8(-cosθσ_x) 
           Z_10=1/8(+sinθσ_z) σ_z        Z_11=1/8(-sinθσ_z).

Due to symmetries, we restrict ourselves so that t_o≡ t_01=t_10 and t_e≡ t_00=t_11. Thus, we have to consider two operator inequalities in each interval θ∈ [0,π/4] and θ∈ (π/4,π/2]. In the first interval, the two operator inequalities are

    1+σ_x/2-s/8(+cosθσ_x) -t_e≥ 0       1+c(θ)σ_z/2-s/8(+sinθσ_z)-t_o≥ 0.

In the second interval, the two operator inequalities are

    1+c(θ)σ_x/2-s/8(+cosθσ_x)-t_e≥ 0       1+σ_z/2-s/8(+sinθσ_z)-t_o≥ 0.

Just as in Appendix <ref>, we solve these inequalities for t_e and t_o, and choose the largest value compatible with the solutions. In the first interval, this gives

    t_e=min{1/8(8-s-scosθ) ,s/8(cosθ-1)}    t_o=min{1/8 (4 c(θ)-s sinθ-s+4),1/8 (-4 c(θ)+s sinθ-s+4)}.

A similar procedure for the interval θ∈ (π/4,π/2] leads to 

    t_e=min{1/8 (4 c(θ)-s cosθ-s+4),1/8 (-4 c(θ)+s cosθ-s+4)}    t_o=min{s/8 (sinθ -1) ,1/8 (8-s -ssinθ)}.

For any choice of θ, we have constructed operator inequalities of the form (<ref>). 

In order to obtain our lower bound on ℱ', we must minimise the quantity t(θ)=(t_e+t_o)/2 for a specific choice of s. In analogy with the procedure in Appendix <ref>, we choose s=4(1+√(2)), which returns min_θ t(θ)=-3/(2√(2)). Hence, we have obtained the lower bound  

    ℱ'(𝒜_2)≥(1+√(2))𝒜_2-3/2√(2) = L(𝒜_2) .





§ SELF-TESTING ALL PAIRS OF INCOMPATIBLE PAULI OBSERVABLES


Consider a generalisation of the 2→ 1 RAC, in which we introduce a bias on the score associated to certain inputs. Specifically, whenever the game is successful, i.e. b=x_y, the awarded score is q/2 if x_0 ⊕ x_1=0, and (1-q)/2 if x_0 ⊕ x_1=1, for some q∈ [0,1]. The average score reads

    𝒜_2^q=1/2∑_x_0,x_1,yr(x_0,x_1)P(b=x_y|x_0,x_1,y),
 
where r(x_0,x_1)=q/2 if x_0 ⊕ x_1=0 and r(x_0,x_1)=(1-q)/2 if x_0 ⊕ x_1=1. Note that for q=1/2, we recover the standard 2→ 1 RAC. Based on the quantity 𝒜_2^q, we will now see how to derive a self-testing condition for any pair of incompatible Pauli observables, i.e. any pair of non-commuting projective rank-one qubit measurements.

We start by expressing 𝒜_2^q for a quantum strategy:

    𝒜_2^q=1/2+1/4∑_x_0,x_1r(x_0,x_1)(ρ_x_0x_1((-1)^x_0M_0+(-1)^x_1M_1))≤1/2+1/4∑_x_0,x_1r(x_0,x_1)λ_max[(-1)^x_0M_0+(-1)^x_1M_1].

Denoting μ_k=λ_min[M_0+(-1)^kM_1] and ν_k=λ_max[M_0+(-1)^kM_1], for k=0,1, we obtain

    𝒜_2^q≤1/2+1/8[q(μ_0-ν_0)+(1-q)(μ_1-ν_1)].
 
Following a derivation analogous to that appearing in Appendix <ref> to obtain, we obtain

    𝒜_2^q≤1/2+1/8[q√(β+α)+(1-q)√(β-α)],

where β=2(M_0^2+M_1^2)-(M_0)^2-(M_1)^2 and α=2({M_0,M_1})-2(M_0)(M_1). Treating α and β as independent variables, we obtain the largest value of the right-hand-side of Eq. (<ref>) by demanding that the derivative with respect to α equals zero, and checking that the second derivative is negative at this point. We obtain the optimality constraint

    α=2q-1/1-2q+2q^2β.

Inserting this value back into Eq. (<ref>), we find an upper bound on 𝒜_2^q as obtained by independent variables α and β. It turns out that this bound can be saturated by the de facto coupled variables α and β. From Eq. (<ref>), it is clear that a necessary condition for optimality is to maximise β. This amounts to the observables M_0 and M_1 being traceless and such that M_0^2=M_1^2=, leading to β=8. This implies that the observables represent projective rank-one measurements. Hence, we can write M_y=n⃗_y·σ⃗ where the Bloch vector satisfies |n⃗_y|=1. Hence, we have α=8n⃗_0·n⃗_1. Thus, Eq.(<ref>) becomes

    n⃗_0·n⃗_1=2q-1/1-2q+2q^2,

which has a solution for any choice of q. Note that setting q=1/2 reduces the above to  n⃗_0·n⃗_1=0 which we recognise as the optimality constraint for the standard 2→ 1 random access code. In conclusion, for any pair of incompatible Pauli observables (characterised by the scalar product n⃗_0·n⃗_1), we have a game 𝒜_2^q (where q is chosen in order to satisfy the above equation), such that the maximal score can only be attained by using that specific pair of Pauli observables. We thus obtain a general class of self-tests for any pair of Pauli observables, corresponding to saturating the maximal quantum value of 𝒜_2^q for a given value of q:

    𝒜_2^q≤1/2(1+√(1-2q+2q^2)).







§ SELF TESTING FOR THE N→ 1 RANDOM ACCESS CODE


In this appendix, we extend the results presented in the main text to self-test the preparations and measurements in an N→ 1 RAC. The latter is a straightforward generalisation of the 2→ 1 RAC considered in the main text. The input of the preparation device is a random N-bit string x≡ (x_1,…,x_N), while the input of the measurement device is y∈{1,…,N}. The average score is

    𝒜_N=1/N2^N∑_x,yP(b=x_y|x,y).

Considering qubit states ρ_x, and measurement observables M_y, we get

    𝒜_N=1/2+1/N2^N+1∑_x,y(-1)^x_y(ρ_xM_y).






 §.§ Compatibility of measurements

We determine whether a set of measurements can explain (i.e. are compatible with) a given value of 𝒜_N. Since rank-one projective measurements are optimal for any set of preparations, we choose for simplicity to restrict our consideration to such measurements. However, it is straightforward to consider general measurements using the method outlined in the main text and Appendix <ref>.

Specifically, we first write

    𝒜_N=1/2+1/N2^N+1∑_x(ρ_x W_x) ≤1/2+1/N2^N+1∑_x[W_x],

where W_x=∑_y(-1)^x_yM_y. 


Note [W_x] = λ_min[W_x̅], where x̅ = (x̅_1,...,x̅_N) the bit string obtained from x by flipping all bits. Thus it is sufficient to only calculate eigenvalues for the strings not obtainable from each other under a full bit-flip operation. To this end let z=x_1… x_N-1,0 and λ_z,0 (λ_z,1) be the largest (smallest) eigenvalue of W_z. Thus we write

    𝒜_N≤1/2+1/N2^N+1∑_z[λ_z,0-λ_z,1].

Since λ_z,0^2 and  λ_z,1^2 are eigenvalues of W_z^2, we have λ_z,0^2+λ_z,1^2=(W_z^2), which is equivalent to 

    λ_z,0^2+λ_z,1^2=∑_y=1^N(M_y^2)+∑_k<l (-1)^z_k+z_l({M_k,M_l}).

This equation, together with the relation (λ_z,0-λ_z,1)^2≤ 2(λ_z,0^2+λ_z,1^2), imply that Eq. (<ref>) becomes 

    𝒜_N≤1/2+√(2)/N2^N+1∑_z[∑_y=1^N(M_y^2)+∑_k<l (-1)^z_k+z_l({M_k,M_l})]^1/2.


This provides a robust self-testing condition, allowing one to determine whether a given set of measurements is compatible with the observed value of 𝒜_N. Furthermore, we can derive an upper bound on the maximal value of 𝒜_N by assuming (incorrectly for N>3) that there exists N mutually unbiased bases in ℂ^2. This means that all measurements are maximally incompatible, i.e. that ({M_k,M_l})=0 for k≠ l. Consequently, Eq. (<ref>) reduces to

    𝒜_N≤1/2(1+1/√(N)).

We emphasise that only three mutually unbiased bases exist in ℂ^2 and hence this bound is only tight for N=2,3. For N=2, we recover the result presented in the main text. For N=3, this implies that a maximal value of 𝒜_3 (i.e. achieving the right-hand side of the above inequality) ensures that the measurements are three mutually unbiased qubit observables, such as the three Pauli observables σ_x, σ_y and σ_z.

Going one step further, we can then also self-test the preparations (still assuming maximal value of 𝒜_3). Indeed, each preparation ρ_x must be pure, and correspond to the eigenvector of W_x associated to its largest eigenvalue. Such a set of preparations correspond to a set of Bloch vectors forming a cube on the surface of the Bloch sphere. 



 §.§ Compatibility of preparations


We ask whether a given value of 𝒜_N can be explained by a particular set of preparations. We suitably express (<ref>) in a quantum model and subsequently apply the Cauchy-Schwarz inequality for operators to obtain

    𝒜_N=1/2+1/N2^N∑_y=1^N[M_y^0∑_x (-1)^x_yρ_x]
    ≤1/2+1/N2^N∑_y=1^N√([M_y^0(∑_x (-1)^x_yρ_x)^2]).

In the last expression, the squared operator is evaluated to

    (∑_x (-1)^x_yρ_x)^2=∑_xρ_x^2+∑_k<l(-1)^k_y+l_y{ρ_k,ρ_l}.

If necessary, the anticommutators can be evaluated using Bloch sphere representation with the relation {ρ_k,ρ_l}=1/2( (1+m⃗_k·m⃗_l)+(m⃗_k+m⃗_l)·σ⃗). However, it is more convenient to consider a basis-independent representation. Importantly, note that since an equal number of positive and negative terms appear inside the square, the operator ∑_x (-1)^x_yρ_x is a linear combination of {σ_x,σ_y,σ_z} and hence its square is proportional to the identity operator. Therefore, when re-inserting Eq. (<ref>) into Eq. (<ref>), we find

    𝒜_N≤1/2+1/N2^N∑_y=1^N[∑_x(ρ_x^2)+∑_k<l(-1)^k_y+l_y({ρ_k,ρ_l})]^1/2.

This is a self-testing condition for preparations, assessing whether a given set of preparations is compatible with a given value of 𝒜_N.  In particular, a classical strategy in which the preparations are binary messages corresponds to ∀ x: (ρ_x^2)=1 and  ({ρ_k,ρ_l})=2δ_E(k),E(l), where E is the specific classical encoding strategy, i.e. a function E:{0,1}^N→{0,1}. 









§ SELF-TESTING WITH THREE-LEVEL SYSTEMS

In the main text, we have considered self-testing in the 2 → 1 random access code when the physical system transmitted from Alice to Bob is a qubit. Clearly, if that system is allowed to carry two bits of information, the task is trivial since Alice can send both her inputs to Bob. Here, we consider the remaining non-trivial case of Alice communicating a three-level quantum system. To simplify the analysis we restrict ourselves to projective measurements for which all possible arrangements admit a compact characterisation. We show that the optimal quantum value equals 𝒜_2 = (5+√(5)) / 8 ≈ 0.9045 and find all the optimal arrangements of observables (we argue that the optimal value is achieved only if both measurements are projective). Our argument is robust in the sense that we are able to certify incompatibility of M_0 and M_1 whenever the success probability exceeds the classical bound for three-level systems, which turns out to be 𝒜_2≤ 7/8.

To obtain a statement which only depends on the observables we follow the main text and evaluate the sum


    ∑_x_0, x_1[ (-1)^x_0 M_0+(-1)^x_1 M_1].


Jordan's lemma states that any two projective observables can be simultaneously diagonalised such that the resulting blocks are 1 × 1 or 2 × 2. For observables acting on a qutrit, we only need to consider two cases: (a) three 1-dimensional subspaces or (b) one subspace of each type. Case (a) corresponds to classical strategies and it is easy to check that these satisfy 𝒜_2≤ 7/8. In case (b) the observables (up to a unitary) can be written as


    M_0 = (
    [ cosα σ_x + sinα σ_z;                                       r ])
    
      and  
    M_1 = (
    [ cosα σ_x - sinα σ_z;                                       s ])


for some angle α∈ [0, 2 π] and r, s ∈{± 1}. A simple calculation yields


    [ M_0 + M_1 ] = max{ 2 | cosα|, r + s },
    
       [ M_0 - M_1 ] = max{ 2 | sinα|, r - s },
    
       [ - M_0 + M_1 ] = max{ 2 | sinα|, - r + s },
    
       [ - M_0 - M_1 ] = max{ 2 | cosα|, - r - s }


and, therefore,


    ∑_x_0, x_1[ (-1)^x_0 M_0+(-1)^x_1 M_1] =
    
    
    2 + 4 | sinα| + 2 | cosα|   if   r = s,
    
    2 + 2 | sinα| + 4 | cosα|   if   r ≠ s.


For r = s the right-hand side is maximised for α∈{ c_1, c_1 + π, - c_1 + π, - c_1 + 2 π}, where c_1 is the unique solution to tan c_1 = 2 in the interval [0, π/2]. Similarly, for r ≠ s the right-hand side is maximised for α∈{ c_2, c_2 + π, - c_2 + π, - c_2 + 2 π}, where c_2 is the unique solution to tan c_2 = 1/2 in the interval [0, π/2].

While the different optimal arrangements are not unitarily equivalent, they are of similar form. The optimal arrangement characterised by r = s = 1 and α = c_1 yields the following optimal preparations


    ρ_00 = (
    [ 0;   1 ]),   
    ρ_01 = (
    [ ( + σ_z)/2;                     0 ]),   
    ρ_10 = (
    [ ( - σ_z)/2;                     0 ]),   
    ρ_11 = (
    [ ( - σ_x)/2;                     0 ]).


Indeed, it is always the case that one preparation lives in the 1 × 1 subspace, whereas the other three occupy the 2 × 2 subspace (two of them form a basis to which the last one is unbiased). To see that the optimal winning probability requires projective measurements note that for every set of preparations the optimal observables can be chosen projective. However, all sets of preparations optimal for projective observables are of the form given above and one can check that for these preparations the optimal measurements must be projective (a direct consequence of the fact that the operators ρ_00 + ρ_01 - ρ_10 - ρ_11 and ρ_00 - ρ_01 + ρ_10 - ρ_11 are full-rank).

It is the presence of multiple inequivalent maximisers that prevents us from writing down a simple self-testing statement. However, Eq. (<ref>) allows us to deduce the range of α compatible with the observed value of 𝒜_2 (note that the conclusion will be stronger if we know whether r = s or r ≠ s). In particular, any value exceeding the classical bound of 7/8 implies a lower bound on the incompatibility between M_0 and M_1 on the 2 × 2 subspace.








	

§ NUMERICAL METHOD FOR ROBUST SELF-TESTING

	In the main text, we focused on the RAC and derived an optimal robust self-test. However, robust self-testing is relevant also for many other tasks that are not RACs. Here, we outline a numerical method based on semi-definite programming for inferring lower bounds on the worst-case average fidelity of preparations ℱ in more general tasks. Specifically, we adapt the so-called swap-method of <cit.> (constructed for Bell scenarios) to prepare-and-measure scenarios by combining it with the hierarchy of dimensionally bounded quantum correlations <cit.>. For sake of instruction, we first present the method by applying it to the RAC, and then use it to robustly self-test preparations in another prepare-and-measure scenario.
	
	The preparations in the random access code are self-tested up to a collective unitary transformation. A robust self-test must therefore be valid under this degree of freedom. However, one can only consider the fidelity of the unknown preparations with respect to the optimal states in some choosen basis. Therefore, in order to achieve a robust self-test, one needs to find a way to avoid the possibility of a collective unitary misaligning the bases.  This can be done by supplying Bob's measurement device with an auxillary system, say it is initialised in the state |0⟩_A, into which the unknown received preparations can be swaped <cit.>. In the RAC, the optimal measurements are anticommuting Pauli measurements. Therefore, with inspiration from this ideal case, Bob's swap operator S can be composed as follows: S=UVU, where
	
    U=⊗|0⟩⟨0|+B_1⊗|1⟩⟨1|    V=1+B_0/2⊗+1-B_0/2⊗σ_x,

	where B_0 and B_1 denote the observables of Bob. If B_0 and B_1 correspond to σ_z and σ_x respectively, the above returns the two-qubit swap operator. Bob applies S to the joint system of received preparation (labeled B) and ancilla (labeled A). The state swaped into Bob's ancilla reads
	
    ρ^SWAP_x_0x_1=_B[S(ρ_x_0x_1⊗|0⟩_A_A⟨0|)S^†].

	Consequently, the worst-case average fidelity of Alice's preparations with her optimal preparations is
	
    ℱ(𝒜_2^*)=min_ρ∈ R(𝒜_2^*)max_Λ1/4∑_x_0x_1[Λ[ρ^ideal_x_0x_1]ρ^SWAP_x_0x_1]=min_ρ∈ R(𝒜_2^*)max_Λ1/4∑_x_0x_1[S(Λ[ρ_x_0x_1]⊗|0⟩_A_A⟨0|)S^†(⊗ρ^ideal_x_0x_1)],

	where R(𝒜_2^*) is the set of all preparations that are compatible with the value 𝒜_2^*, and Λ is the extraction channel, the duality of which is used above.
	
	We may write the operator S in terms Bob's observables as follows:
	
    S=1/2∑_ijs_ij⊗|i⟩_A_A⟨j|,

	where 
	
    s_00=+B_0  s_01=B_1-B_0B_1  s_10=B_1-B_1B_0  s_11=+B_1B_0B_1.

	Inserting this into (<ref>) we find
	
    ℱ(𝒜_2^*)   =min_ρ∈ R(𝒜^*)max_Λ1/16∑_x_0x_1∑_ijkl[(s_ij⊗|i⟩_A_A⟨j|)(Λ[ρ_x_0x_1]⊗|0⟩_A_A⟨0|)(s_kl⊗|k⟩_A_A⟨l|)^†(⊗ρ^ideal_x_0x_1)]
       =min_ρ∈ R(𝒜_2^*)max_Λ1/16∑_x_0x_1∑_ijkl[s_ijΛ[ρ_x_0x_1] s_kl^†][|i⟩⟨j|0⟩⟨0|l⟩⟨k|ρ^ideal_x_0x_1]
       =min_ρ∈ R(𝒜_2^*)max_Λ1/16∑_x_0x_1∑_ik[s_k0^† s_i0Λ[ρ_x_0x_1]]⟨k|ρ^ideal_x_0x_1|i⟩
       =min_ρ∈ R(𝒜_2^*)max_Λ1/16∑_x_0x_1∑_ik[T_ikΛ[ρ_x_0x_1]]⟨k|ρ^ideal_x_0x_1|i⟩,

	where we defined T_ik=s_k0^† s_i0. The four elements of T are straightforwardly computed to
	
    T_00=2(+B_0),  T_01=B_1(-B_0)+B_0B_1(-B_0), 
       T_11=2(-B_0),   T_10=B_1(+B_0)-B_0B_1(+B_0) .

	
	
	
	In the calculation of the fidelity, the same channel is applied to all Alice's preparations. We may simply consider that as four other valid preparations ρ̅_x_0x_1=Λ[ρ_x_0x_1]. The fidelity in (<ref>) is then a linear combination of variables {(ρ̅_x_0x_1),(ρ̅_x_0x_1B_0),…,(ρ̅_x_0x_1B_0B_1B_0)}. Therefore, we may establish a lower bound on (<ref>) using the dimensionally bounded hierarchy of quantum correlations <cit.>. The accuracy of this bound depends on the level of the hierarchy employed. We choose to consider the following level: we define a moment matrix 
	
    χ_ijkl=[R^†_j Q_i^† Q_kR_l] whereQ=(, B_0, B_1, B_0B_1, B_1B_0) and R=(, ρ̅_00, ρ̅_01,ρ̅_10,ρ̅_11),

	for i,j,k,l=1,…,5. From the moment matrix we calculate all terms needed to evaluate the average fidelity (<ref>), using the labels x=2x_0+x_1+2,
	
    [T_00ρ̅_x_0x_1]=2χ_111x+2χ_112x   [T_11ρ̅_x_0x_1]=2χ_111x-2χ_112x
       [T_01ρ̅_x_0x_1]=χ_113x+χ_114x-χ_115x-χ_215x   [T_10ρ̅_x_0x_1]=χ_113x-χ_114x+χ_115x-χ_215x .

	In order to enforce that the average fidelity is extremised for a particular value 𝒜_2^* of the random access code, we write the probability distribution of Bob's outcomes in terms of the moment matrix as 
	
    P(b| x_0,x_1,y)=1+(-1)^bχ_1,1,y+2,x/2.

	Thus, we can evaluate 𝒜_2 as a linear combination of moment matrix elements. Fixing the value of  𝒜_2 corresponds to introducing an affine constraint on the moment matrix. Therefore, the following semi-definite program establishes a lower bound on  ℱ(𝒜_2):
	
    ℱ(𝒜_2^*)≥min_χ1/16∑_x_0x_1∑_i,k=0^1(T_ikρ̅_x_0x_1)⟨ k|ρ^ideal_x_0x_1| i⟩
    such that χ≥ 0   and  𝒜_2≥𝒜_2^*.

	
	We have implemented the semi-definite program and the results are presented in Fig. <ref>, together with the lower bound on ℱ(𝒜_2) obtained from the analytical method presented in the main text. Evidently, the swap method returns a sub-optimal but still non-trivial result. Using the swap method, we find a higher-than-classical value of ℱ(𝒜_2), i.e., ℱ(𝒜_2)>3/4,  whenever 𝒜_2>0.802. 
	
	
	The advantage of the swap method is that it applies also to other prepare-and-measure scenarios beyond RACs. The drawback of the method is that the self-tests are typically not optimal, and that the complexity of evaluating the dimensionally bounded hierarchy of quantum correlations increases exponentially with the number of preparations and measurements, thus making more complicated scenarios infeasible to study. 
	
	
	
	To examplify the usefulness of this method also for other prepare-and-measure scenarios, we present  a second example. Consider a prepare-and-measure scenario in which Alice has a random input x∈{0,1,2} and Bob has a random input y∈{0,1}. Alice may only communicate a qubit to Bob. The objective of the scenario reads
	
    𝒜=∑_x,yc_x,yE(x,y),

	where E(x,y)=p(b=0| x,y)-p(b=1| x,y) and c_x,0=[1,1,-1] and c_x,1=[√(3),-√(3),0]. One straightforwardly finds that the maximal classical value  is 𝒜=1+2√(3). We wish to robustly self-test Alice's preparations solely based on the value of 𝒜. From numerical brute-force maximisations of 𝒜, we find that its maximal value is 𝒜=5 and that this value is saturated using anticommuting Pauli measurements and preparations forming an equilateral triangle in a disk of the Bloch sphere. Such preparations can up to a unitary be written
	
    ρ_0^ideal=1/2(+σ_x)       ρ_1^ideal=1/2(+√(3)/2σ_z-1/2σ_x)        ρ_2^ideal=1/2(-√(3)/2σ_z-1/2σ_x).

	We make the ansatz that this constitutes a self-test of the preparations. We supply Bob with an ancilla state and define the swap operator as done in the RAC. Performing calculations fully analogous to the case of the RAC, we obtain a semi-definite program that gives a lower bound on the worst-case average fidelity 
	
    ℱ(𝒜)=min_ρ∈ R(𝒜)max_Λ1/3∑_x[Λ[ρ^ideal_x]ρ_x],

	where ℛ(𝒜) is the set of preparations compatible with the value 𝒜 and Λ is the extraction channel. We have used an intermediate level of the hierarchy of dimensionally bounded quantum correlations (sometimes referred to as 1+AB+BB+BBA) corresponding to an SDP matrix of size 20. The corresponding lower bound on ℱ(𝒜) is presented in Fig. <ref>.
	
	We first see that that the maximal value 𝒜=5 indeed self-tests (up to numerical precision) the preparations of Alice to form an equilateral triangle on the Bloch sphere (the fidelity is one). For non-maximal values of 𝒜, we still obtain a non-trivial bound on the average fidelity of Alice's preparations with the optimal ones.







