Introduction

There is strong reason to believe that quantum devices can outperform their classical counterparts on various fronts1. Yet, certifying that a quantum device is functioning as intended (or claimed) becomes challenging as the device becomes increasingly complex2. More concretely, consider the two traditional methods for characterising a quantum system—tomography and classical simulation. Both methods fail for large systems. Tomography requires resources which scale exponentially (in the size of the quantum system being characterised)3. Similarly, since we have strong evidence showing that quantum computations are intractable for classical computers, characterisation by classical simulation also fails for large systems4. Thus, methods for characterising quantum systems are crucial for building useful large-scale quantum devices. Many such methods are known with varying strengths and weaknesses. Restricting to efficient methods, one can classify them according to several parameters, such as the assumptions they make about the system (the weaker the better) and the knowledge they provide about the system (the more the better). In this work, we focus on self-testing and related methods, which solely aim to minimise the assumptions needed.

Self-testing is a property of a configuration—a state and a set of measurements—which requires that every other configuration which produces the same measurement statistics is, in fact, identical to it up to (local) isometries. (Self-testing initially was defined to be a property of a quantum state alone (and not the measurements)). Clearly, without some assumption about the underlying system, no configuration can be self-tested (this is simply because the device could classically store and reproduce whatever statistics the self-test is required to satisfy. One of these assumptions is that the system is bipartite, and the two parts of the system cannot communicate). Indeed, the term “self-testing” was coined in 2004 by Mayers and Yao5, who showed that (in the bipartite no-communication setting) this property holds for a pair of maximally entangled qubits. The underlying ideas, however, were already present in earlier works6,7,8,9,10. Self-testing has since been an area of active investigation11 and the notion has been extended to various settings, such as bipartite (all pure states can be self-tested12,13,14), multi-partite (various families can be self-tested15,16,17,18), Bell state measurement19,20, prepare-and-measure21,22, steering23,24,25, among others.

Returning to device characterisation, a central technological challenge of our times is the construction of a large-scale quantum computer—a single complex quantum system, where the aforementioned results do not hold. Thus, it is natural to ask if one can extend self-testing to the single system setting.

Results

Here, we tackle this question by approaching self-testing via non-contextuality inequalities—linear inequalities26,27, similar to Bell inequalities, the experimental violation of which28,29 can be used to witness non-classicality. Their advantage is precisely that they can be tested in a single system. Unlike the aforementioned self-testing schemes based on Bell nonlocality, which assume no communication (between parts of the device), we make a mild assumption on the measurements that we call KCBS orthogonality. Similar self-testing schemes, based on non-contextuality inequalities, have recently been proposed30,31,32,33. However, these works can only be applied when the experimental statistics exactly match the ideal statistics. (While some of the works prove that their self-test is “robust” in principle, they fail to show how to apply their result for any experiment which even mildly deviates from the ideal case). We remedy this stifling shortcoming by providing the first contextuality self-testing robustness curve, which enables one to self-test single quantum systems in the laboratory—the curve quantifies the fidelity of the system’s configuration (to the ideal configuration) as a function of the deviation of the observed statistics (from the ideal statistics). We then perform an experiment on a single 40Ca+ ion and apply this self-test scheme to characterise the system. We find that our characterisation is consistent with that obtained by conventional tomography. We emphasise that even though our self-test scheme was designed to minimise the assumptions one needs to make, it is nevertheless crucial to ensure that these are satisfied by the experiment. In addition to the KCBS orthogonality condition, one must ensure that the detection efficiency is nearly perfect and that the measurement settings are chosen randomly (to assure that non-contextual models are not simulating contextual correlations34). In our experimental setup, we quantify the deviation from these requirements and find that they are, indeed, negligible (see Supplementary Note 1).

Overview and organisation

We first outline our theoretical contributions (“Results: The self-test scheme”). We informally introduced self-testing but did not explain the KCBS orthogonality condition (Assumption 1). Informally, for any odd number n of measurements, the condition requires that the measurements are projective and satisfy the relations of orthogonality corresponding to an n-cycle graph (vertices represent measurements and edges relations of orthogonality). For simplicity, we henceforth implicitly take n = 5 (It turns out that, in this setup, n = 5 is the smallest cyclic graph which separates quantum behaviour from its classical counterpart). We denote our self-test by \({{{\mathcal{I}}}}\) (Equation 1), which is a linear expression in the input/output probabilities associated with the device. \({{{\mathcal{I}}}}\) can be made 0 by a quantum device, but every classical device must yield \({{{\mathcal{I}}}}\ge Q-C \,>\, 0\), where Q and C are constants, independent of the device once n is fixed. It is known30 that the configuration (the states and measurements associated with the device) are unique for any device which yields \({{{\mathcal{I}}}}=0\); the uniqueness is up to a global isometry. Such a configuration is termed the Klyachko-Can-Binicioğlu-Shumovsky (KCBS) configuration. Note that, using a global isometry, one can trivially change any state \(\left\vert \phi \right\rangle\) to any other state \(\left\vert \xi \right\rangle\). This might prompt one to think that showing equivalence up to global isometries is meaningless. This is not true. If there are two configurations that attain \({{{\mathcal{I}}}}=0\), we require the same global isometry to map the state as well as the measurement settings from one configuration to another (see Fig. 2). (For readers familiar with Bell nonlocality-based self-testing: for a single system, the notion of local isometry anyway does not make sense).

Consider a configuration for which \({{{\mathcal{I}}}}\) is close to zero. To quantify the closeness of it to the KCBS configuration, we define the total fidelity, F (Equation 5). F = 6 for the KCBS configuration. (In general, F = n + 1 as it sums the fidelity to n measurements and one state. For the (simplest) KCBS configuration, n = 5). We give a lower bound on F as a function of \({{{\mathcal{I}}}}\). The idea is to define an isometry in terms of the measurement operators of the device itself, which maps a device’s configuration to the KCBS configuration when \({{{\mathcal{I}}}}=0\). The expression for F when \({{{\mathcal{I}}}}\, >\, 0\) becomes an optimisation problem which can be relaxed to a hierarchy of semidefinite programs (SDPs). This, in turn, can be solved numerically to obtain lower bounds on F. The details of the proof appear in “Methods: Lower bound using an SDP relaxation” and those of the numerical solution in “Methods: Numerics to evaluate fidelity lower bounds”. Obtaining the numerical solution was challenging. This is primarily because the description of the SDP we obtained is implicit. Therefore, we first find this explicit description by performing symbolic computation and, subsequently, solve the resulting SDP (with over 15,000 constraints).

We now outline the experiment. We apply this self-test to an experimental setup based on a single trapped 40Ca+ion. The KCBS configuration can be realised using a qutrit and projective measurements (see Fig. 2). In the experiment, the three levels of the qutrit are formed by the ground state and the first excited state, which is further split by the presence of a magnetic field. The measurements are executed by rotating between the ground state and the excited state using 729 nm lasers, performing a photon number measurement (via fluorescence detection), followed by an inverse of the rotation (see Fig. 1 and “Results: Experimental Setup”). The initial state and the rotation angles can be chosen such that they correspond directly to the KCBS configuration (“Results: Realising the KCBS configuration”). The actual experimental setup, of course, requires numerous details to be first addressed (“Results: Experimental Setup”) for this correspondence to work. Using this setup, we perform two types of experiments (“Results: Experiments that are self-tested”), both of which are deviations from the KCBS configuration, constructed to ensure the KCBS orthogonality condition (Assumption 1) still holds. First, we leave the measurements unchanged but progressively depolarise the initial state. Second, we change the measurement settings, parameterised by an angle θ and tilt the initial state. In effect, these experiments determine \({{{\mathcal{I}}}}\), and the robustness curve immediately lower-bounds the total fidelity of the underlying configuration to the KCBS configuration. By performing conventional tomography, we determine the actual fidelity to the KCBS configuration and find that the lower bound is indeed satisfied, as expected (Fig. 1, Table 2).

Fig. 1: Experimental results.
figure 1

ac represents the 40Ca+ ion experimental setup, while d illustrates the agreement of the observations with the theory. a The energy level diagram of the 40Ca+ ion. b A schematic of the experimental setup. c The sequence of operations used in our experiment to measure pi via Pr(10ij), i.e., the probability of obtaining (a, b) = (1, 0) when Mi and Mj are measured. We choose (i, j) E (edges of a five-cycle graph) at random using a quantum random number generator. Each measurement Mi is implemented by performing a rotation Ui, a fluorescence measurement (performed using a photo-multiplier tube), and undoing the rotation. For each measurement, the experiment is repeated over 10,000 times. d The x-axis represents ∑kpk (which we call the KCBS value), while the y-axis represents the total fidelity, F, to the ideal KCBS configuration. Recall that \({{{\mathcal{I}}}}={Q}_{n}-{\sum }_{k}{p}_{k}\). The bottom curve (blue), obtained by solving a semidefinite program, lower bounds F as a function of ∑kpk. The top curve (orange) is similarly obtained by assuming, in addition, that p1 = p2 =  = p5. The points represent various experiments which (nearly) satisfy Assumption 1. The x coordinates of these points represent ∑kpk, while the y coordinate is evaluated by performing tomography and computing the fidelity to the ideal KCBS configuration. We note that ∑kpk exceeds \(\sqrt{5}\) (the maximum quantum value for projective measurements). This is warranted because our experiments are nearly perfect, and even small deviations from the underlying assumptions cause the KCBS value to deviate from the ideal one. It is worth noting that the left end of the error bar (±1.96σ, where σ denotes standard deviation), however, is well within the \(\sqrt{5}\) limit.

Relation to prior work

Before delving into the details, we give a brief comparison to prior works.

Comparison to another single-system self-testing scheme

Self-testing in a single system has recently been studied under cryptographic assumptions35; however, such proposals require over a thousand qubits and thus remain elusive in practice (see Supplementary Note 6 for details).

Comparison to other contextuality experiments

In our experiment, we simultaneously quantify and minimise divergence from the basic assumptions—perfect detection, random selection of measurements, compatibility and sharpness—which, to the best of our knowledge, makes it the most comprehensive contextuality experiment to be reported (see Table 1). Compared to other contextuality experiments, the terminology used here is slightly different since our approach here is more pragmatic—our KCBS orthogonality condition may be seen as the analogue of compatibility and sharpness of measurements (see Supplementary Note 6).

Table 1 A comparison of our experiment to previous experimental results on contextuality.

Swap isometry

One of our theoretical constructions (the swap isometry, explained in “Methods: Lower bound using an SDP relaxation”) is motivated by the corresponding construction in ref. 36. While the construction in ref. 36 works for Bell scenarios, our construction applies to the single-party setting.

The self-test scheme

Suppose we have a set of (independent) identical devices, each of which takes a string as input and produces a string as output. Let pi denote the probability of event i, where an event is an instance of an input-output. Let \({{{\mathcal{I}}}}:= {\sum }_{i}{q}_{i}{p}_{i}\) denote a linear combination of these probabilities, where \({q}_{i}\in {\mathbb{R}}\). We say that \(({{{\mathcal{I}}}},c)\), for some \(c\in {\mathbb{R}}\), self-tests the device if the following holds—if the device satisfies \({{{\mathcal{I}}}}=c\), then the device is uniquely described as containing a specific quantum state, the inputs corresponding to selecting specific measurements, the outputs correspond to the action of the measurement on the aforementioned quantum state, up to a global isometry. (Later, we use “self-tests the device” to succinctly say “self-tests the configuration in the device”).

As stated earlier, no self-test can exist without additional assumptions. We make the following assumption about the device we wish to self-test. To describe it, we set up some notation. We denote the ith binary measurement by Mi (Π0i, Π1i), where Π0i denotes the measurement operator corresponding to the zeroth output and Π1i denotes that corresponding to the first output. Being measurement operators, they satisfy the probability conservation condition \({{{\Pi }}}_{0| i}^{{\dagger} }{{{\Pi }}}_{0| i}+{{{\Pi }}}_{1| i}^{{\dagger} }{{{\Pi }}}_{1| i}={\mathbb{I}}\). We say the binary measurement is repeatable and Hermitian if \({{{\Pi }}}_{b| i}^{2}={{{\Pi }}}_{b| i}\) for b 0, 1 and \({{{\Pi }}}_{b| i}^{{\dagger} }={{{\Pi }}}_{b| i}\), respectively.

Assumption 1

For an odd n, the quantum state in the device is ρ and the measurements M1, M2, …, Mn are repeatable and Hermitian binary measurements (as described above) satisfying Π1i Π1j = 0 for {i, j}  {{1, 2}, {2, 3}, …, {n − 1, n}, {n, 1}} = : E.

At first, one might think that restricting to projective measurements, instead of POVMs, is without loss of generality due to Naimark’s theorem (according to which the statistics of any quantum measurement can also be obtained using a projective measurement since any positive-operator-valued measure can be seen as a projective-valued measure in a larger Hilbert space). However, this conclusion no longer holds for sequential measurements where post-measurement states become relevant. (To properly address this issue, one must consider quantum instruments instead and define the notion of orthogonality accordingly. In the present work, we do not pursue this direction). In any case, the aforementioned is a mild requirement and our experimental setup almost perfectly satisfies it (see Supplementary Note 1).

For a device satisfying Assumption 1, we consider the self-test \({{{\mathcal{I}}}}\)

$${{{\mathcal{I}}}}:= {Q}_{n}-\mathop{\sum }\limits_{i=1}^{n}{p}_{i},$$
(1)

where \({p}_{i}:= {{{\rm{tr}}}}({{{\Pi }}}_{i}\rho )=\left\langle {{{\Pi }}}_{i}\right\rangle\) and \({Q}_{n}:= \frac{n\cos (\pi /n)}{1+\cos (\pi /n)}\) is the “quantum value”. This particular form is of interest because, informally, any classical (i.e., non-contextual) model satisfying Assumption 1 cannot result in \(\mathop{\sum }\nolimits_{i = 1}^{n}{p}_{i}\, >\, {C}_{n}\), where Cn (n − 1)/2 while quantumly, for the KCBS configuration (see Definition 3) one obtains \(\mathop{\sum }\nolimits_{i = 1}^{n}{p}_{i}={Q}_{n}\), the highest possible37. The self-test measures how close one is to the maximum quantum value, Qn. The maximum value of ∑ipi that is classically achievable (i.e., when all measurements commute) is (n − 1)/2. The quantum value Qn is achieved by \({\sum }_{i}\left\langle {{{\Pi }}}_{i}\right\rangle\) for the KCBS configuration (\({\rho }^{{{{\rm{KCBS}}}}},\{{{{\Pi }}}_{i}^{{{{\rm{KCBS}}}}}\}\)), where ρKCBS is a qutrit in a pure state and \({{{\Pi }}}_{i}^{{{{\rm{KCBS}}}}}\) are projectors (see Definition 3 below), yielding \({{{\mathcal{I}}}}=0\).

Definition 2

(An ideal KCBS configuration) Consider a three-dimensional Hilbert space spanned by the basis \(\{\left\vert 0\right\rangle ,\left\vert 1\right\rangle ,\left\vert 2\right\rangle \}\). Let

$$\left\vert {u}_{l}\right\rangle := \cos \theta \left\vert 0\right\rangle +\sin \theta \sin {\phi }_{l}\left\vert 1\right\rangle +\sin \theta \cos {\phi }_{l}\left\vert 2\right\rangle ,$$
(2)

where ϕllπ(n − 1)/n for 1 ≤ l ≤ n and \({\cos }^{2}\theta =\frac{\cos (\pi /n)}{1+\cos (\pi /n)}\). Define

$$\left\vert {\psi }^{KCBS}\right\rangle := \left\vert 0\right\rangle ,$$
(3)
$${{{\Pi }}}_{i}^{KCBS}:= \left\vert {u}_{i}\right\rangle \left\langle {u}_{i}\right\vert .$$
(4)

It was shown in ref. 30 that any quantum realisation (ρ, {Πi}) which satisfies Assumption 1 and yields \({{{\mathcal{I}}}}=0\), must be the same as the KCBS configuration, up to a global isometry. (In fact, they also showed that if \({{{\mathcal{I}}}}=\epsilon\) is close to zero, then the quantum realisation must be close to the KCBS configuration. However, their analysis did not yield the exact function corresponding to Equation (5)—they only had an asymptotic bound (on the fidelity to the KCBS configuration) of the form \({{{\mathcal{O}}}}(\sqrt{\epsilon })\)).

Recall that for clarity, we restricted to n = 5 but the arguments readily generalise. Suppose the device corresponds to a quantum realisation (ρ, {Πi}) for which \({{{\mathcal{I}}}}=\epsilon\) is small but not exactly zero. In this case, we derive a lower bound on the fidelity of (ρ, {Πi}) to \(({\rho }^{{{{\rm{KCBS}}}}},\{{{{\Pi }}}_{i}^{{{{\rm{KCBS}}}}}\})\) (up to a global isometry). More precisely, we lower bound the value of the following function

$$F:= \mathop{\min }\limits_{\rho ,\{{{{\Pi }}}_{i}\}}\mathop{\max }\limits_{V}\left[\mathop{\sum }\limits_{i=1}^{5}{{{\mathcal{F}}}}({{{{\rm{tr}}}}}_{{{{\mathcal{H}}}}}[V{{{\Pi }}}_{i}\rho {{{\Pi }}}_{i}{V}^{{\dagger} }],{{{\Pi }}}_{i}^{{{{\rm{KCBS}}}}}{\rho }^{{{{\rm{KCBS}}}}}{{{\Pi }}}_{i}^{{{{\rm{KCBS}}}}})+{{{\mathcal{F}}}}({{{{\rm{tr}}}}}_{{{{\mathcal{H}}}}}[V\rho {V}^{{\dagger} }],{\rho }^{{{{\rm{KCBS}}}}})\right],$$
(5)

where \((\rho ,{\{{{{\Pi }}}_{i}\}}_{i = 1}^{5})\) is a quantum realisation of \({\{{p}_{i}\}}_{i = 1}^{5}\) satisfying \({{{\mathcal{I}}}}=\epsilon\), V is an isometry from \({{{\mathcal{H}}}}\) to \({{{\mathcal{H}}}}\otimes {{{{\mathcal{H}}}}}^{{{{\rm{KCBS}}}}}\), i.e., from the space on which \(\rho ,{\{{{{\Pi }}}_{i}\}}_{i = 1}^{5}\) are defined, to itself tensored with the 3-dimensional space where \({\rho }^{{{{\rm{KCBS}}}}},{\{{{{\Pi }}}_{i}^{{{{\rm{KCBS}}}}}\}}_{i = 1}^{5}\) are defined, and \({{{\mathcal{F}}}}(\sigma ,\tau ):= {{{\rm{tr}}}}\sqrt{\left\vert {\sigma }^{1/2}{\tau }^{1/2}\right\vert }\) is the fidelity of ρ ≥ 0 to σ ≥ 0. This lower bound can be approximated by a sequence of semidefinite programs and can be evaluated for any \({{{\mathcal{I}}}}=\epsilon\), yielding the robustness curve (see Fig. 1). We defer the detailed analysis to “Methods: Lower bound using an SDP relaxation”. (Instead of the sum ∑ipi, one could impose constraints on the values of pi individually. In fact, this is what we do in our analysis as it yields a better bound).

Experimental setup

We describe our experimental setup, which is designed to realise the ideal KCBS configuration. We use a 40Ca+ ion trapped in a blade-shaped Paul trap. The qutrit basis states are encoded into three Zeeman sub-levels of the 40Ca+ ion, with

$$\left\vert 0\right\rangle =\left\vert {S}_{1/2},{m}_{J}=-1/2\right\rangle ,$$
(6)
$$\left\vert 1\right\rangle =\left\vert {D}_{5/2},{m}_{J}=-3/2\right\rangle ,$$
(7)
$$\left\vert 2\right\rangle =\left\vert {D}_{5/2},{m}_{J}=-1/2\right\rangle ,$$
(8)

as shown in Fig. 1a. Unitary operations on these qutrits are performed by shining a linear polarised narrow-linewidth 729 nm laser beam, propagating along the trap axis at an angle of 45° with respect to the quantisation axis. For k {1, 2}, the laser can be frequency modulated to be in resonance with the specific transition between the states \(\left\vert 0\right\rangle\) and \(\left\vert k\right\rangle\) by an acousto-optic modulator (AOM). The coupling strength Ωk, duration t and phase ϕk of this laser pulse then can be controlled by the AOM to perform a rotation, Rk(θk, ϕk) between the states \(\left\vert 0\right\rangle\) and \(\left\vert k\right\rangle\), where θk = Ωkt and ϕk represent the polar angle and the azimuthal angle respectively, i.e.,

$${R}_{1}({\theta }_{1},{\phi }_{1})=\left(\begin{array}{lll}\cos \frac{{\theta }_{1}}{2}&-i\sin \frac{{\theta }_{1}}{2}{e}^{-i{\phi }_{1}}&0\\ -i\sin \frac{{\theta }_{1}}{2}{e}^{i{\phi }_{1}}&\cos \frac{{\theta }_{1}}{2}&0\\ 0&0&1\\ \end{array}\right),$$
(9)
$${R}_{2}({\theta }_{2},{\phi }_{2})=\left(\begin{array}{lll}\cos \frac{{\theta }_{2}}{2}&0&-i\sin \frac{{\theta }_{2}}{2}{e}^{-i{\phi }_{2}}\\ 0&1&0\\ -i\sin \frac{{\theta }_{2}}{2}{e}^{i{\phi }_{2}}&0&\cos \frac{{\theta }_{2}}{2}\end{array}\right).$$
(10)

The parameters of the rotation are controlled by varying the duration and phase of the corresponding laser pulse under constant intensity via the acoustic-optic modulator with high fidelity. Using R1 and R2, one can perform an arbitrary rotation in the qutrit space. Measurements in our setup are performed by fluorescence detection, i.e., counting photons.

Realising the KCBS configuration

The preceding operations can be combined to perform various experiments that (nearly) satisfy Assumption 1. Here, we describe, at a high level, the procedure for realising the KCBS configuration (see Definition 3). Detailed experimental steps are deferred to “Methods: Experimental setup”.

Using the notation introduced in Assumption 1, we denote the binary measurements of interest by Mi (Π0i, Π1i) and the quantum state of our system by ρ. To realise the KCBS configuration, we require \({{{\Pi }}}_{1| i}=\left\vert {u}_{i}\right\rangle \left\langle {u}_{i}\right\vert\) and \(\rho =\left\vert 0\right\rangle \left\langle 0\right\vert\). To implement the measurement Π1i, as a composition of the operations our setup permits, we first compute a qutrit rotation Ui which maps \(\left\vert {u}_{i}\right\rangle\) to \(\left\vert 0\right\rangle\). This, in turn, is used to compute the parameters θ1,i, θ2,i and ϕ1,i, ϕ2,i such that Ui = R2(θ2,i, ϕ2,i) R1(θ1,i, ϕ1,i). Observe that defining \({{{\Pi }}}_{1| i}:= {U}_{i}\left\vert 0\right\rangle \left\langle 0\right\vert {U}_{i}^{{\dagger} }\) and \({{{\Pi }}}_{0| i}:= {U}_{i}({\mathbb{I}}-\left\vert 0\right\rangle \left\langle 0\right\vert ){U}_{i}^{{\dagger} }\) results in the KCBS configuration.

Neglecting experimental imperfections (which are indeed negligible in our experiment; see Supplementary Note 1), it is evident that Assumption 1 is satisfied, i.e., Π1i Π1j = 0 for (i, j) E and \({{{\Pi }}}_{1| i}^{2}={{{\Pi }}}_{1| i}\). Further, it is clear that

$${p}_{i}=\Pr (1| i)=\Pr (10| ij)={{{\rm{tr}}}}({{{\Pi }}}_{0| j}\cdot {{{\Pi }}}_{1| i}\rho {{{\Pi }}}_{1| i}^{{\dagger} }\cdot {{{\Pi }}}_{0| i}^{{\dagger} }),$$
(11)

where Pr(abij) denotes the probability of obtaining outcomes (a, b) when measurements (Mi, Mj) are performed and Pr(ai) denotes the probability of obtaining outcome a given Mi was measured. Finally, we note that Pr(10ij) = Pr(01ji).

As illustrated in Fig. 1, ∑kpk is estimated randomly (using a quantum random number generator; see Supplementary Note 1) by choosing (i, j) E, measuring Mi followed by Mj and counting N(10ij), the number of times the output was (1, 0), i.e.,

$${p}_{i}\approx \frac{N(10| ij)}{{\sum }_{a,b\in \{0,1\}}N(ab| ij)}.$$
(12)

Experiments that are self-tested

To study the self-testing property of a device, we perform experiments which deviate from the standard KCBS configuration in two qualitatively different ways.

  1. (a)

    p-configuration. Consider the realisation \(({\rho }^{{\prime} }(p),\{{M}_{i}\})\) parametrised by 0 ≤ p ≤ 1. Here, Mi correspond to projectors along \(\left\vert {u}_{i}\right\rangle\) as before, but instead of initialising the state of the device to \(\rho =\left\vert 0\right\rangle \left\langle 0\right\vert\), we initialise it to a mixture of ρ and the maximally mixed state, i.e.,

    $${\rho }^{{\prime} }(p):= (1-p)\left\vert 0\right\rangle \left\langle 0\right\vert +\frac{p}{9}{\mathbb{I}}.$$
    (13)

    For p = 0, we recover the ideal KCBS configuration for which \({{{\mathcal{I}}}}=0\). However, for p > 0, Assumption 1 still holds (neglecting the imperfections in the measurements) but \({{{\mathcal{I}}}}=\epsilon\, >\, 0\). The experiment was performed for p = 0, 0.1, and 0.2.

  2. (b)

    θ-configuration. Consider the realisation \((\left\vert {u}_{0}^{{\prime} }\right\rangle \left\langle {u}_{0}^{{\prime} }\right\vert ,\{{M}_{i}^{{\prime} }(\theta )\})\) parametrised by the vector \(\left\vert {u}_{0}^{{\prime} }\right\rangle\) and the angle θ. Here, unlike the previous case, the state is pure. Further, the measurements \({M}_{i}^{{\prime} }=({{{\Pi }}}_{1| i}^{{\prime} },{{{\Pi }}}_{0| i}^{{\prime} })\) now correspond to projections on \(\left\vert {u}_{i}^{{\prime} }\right\rangle\) for i {1, 2…5}. (The projections are defined exactly as Mi was defined using \(\left\vert {u}_{i}\right\rangle\); \({{{\Pi }}}_{1| i}^{{\prime} }={U}_{i}^{{\prime} }\left\vert 0\right\rangle \left\langle 0\right\vert {U}_{i}^{{\prime} {\dagger} }\) and \({{{\Pi }}}_{0| i}^{{\prime} }={U}_{i}({\mathbb{I}}-\left\vert 0\right\rangle \left\langle 0\right\vert ){U}_{i}^{{\prime} {\dagger} }\) with \({U}_{i}^{{\prime} }\) encoding a rotation from \(\left\vert {u}_{i}^{{\prime} }\right\rangle\) to \(\left\vert 0\right\rangle\)). These vectors \(\left\vert {u}_{i}^{{\prime} }\right\rangle\) are chosen to be

    $$\left\vert {u}_{1}^{{\prime} }\right\rangle ={(1,0,0)}^{T},$$
    (14)
    $$\left\vert {u}_{2}^{{\prime} }\right\rangle ={(0,0,1)}^{T},$$
    (15)
    $$\left\vert {u}_{3}^{{\prime} }\right\rangle ={(-\cos (\theta ),\sin (\theta ),0)}^{T},$$
    (16)
    $$\left\vert {u}_{4}^{{\prime} }\right\rangle =\frac{{(\sin (\theta ),\cos (\theta ),\sin (\theta ))}^{T}}{\sqrt{1+{\sin }^{2}(\theta )}},$$
    (17)
    $$\left\vert {u}_{5}^{{\prime} }\right\rangle ={(0,\sin (\theta ),-\cos (\theta ))}^{T},$$
    (18)

    which ensures that Assumption 1 holds for all angles θ. We take \(\left\vert {u}_{0}^{{\prime} }\right\rangle\) to be the eigenvector of \({\sum }_{k}{{{\Pi }}}_{k}^{{\prime} }\) with the largest eigenvalue. We performed the experiment for θ = 22.041 and 150.612.

Table 2 summarises our findings for experiments implementing both p and θ-configurations, which are in agreement with our theoretical results. Here, we briefly explain how the data was obtained and analysed, deferring the details to “Methods: Analysing the data”.

Table 2 Summary of our experimental and numerical results (see “Methods: Analysing the data”).

For a given configuration, we performed 10,000 sequential measurements and used Equation (12) to estimate the mean μ(pi) and standard deviation σ(pi) for each pi. Note, for instance, to measure p2, one could measure in normal order: M2 followed by M3, or in reverse order: M2 followed by M1. We used a quantum random number generator to choose the measurement and its order.

To apply our self-test, we have two options: impose the constraint corresponding to either (1) ∑kpk or (2) pk for each k individually. Option (2) would be unequivocally better than option (1) if σ was 0 (illustrated by the orange curve in Fig. 1, Right). As σ > 0, we use both methods and pick the best-performing among them. When σ > 0 for a random variable, we evaluate μ − 1.96σ to get an estimate for the random variable, which lower bounds its value with over 95% confidence (assuming the data is normally distributed). When such an estimate is used, sometimes option (1) can give a better bound than option (2).

Discussion

Quantifying deviations from assumptions

In all self-testing experiments, deviations from the assumptions must be quantitatively accounted for in the robustness curve. All reported self-test schemes, to the best of our knowledge, have neglected this aspect in their analysis.

In more detail, for our setting, the lower bounds on total fidelity obtained using semidefinite programming only hold when Assumption 1 is satisfied. Relaxing this assumption (see Supplementary Note 1) to allow for measurements with errors ϵ in repeatability (i.e., quantifying \(| {{{\Pi }}}_{a| i}^{2}-{{{\Pi }}}_{a| i}|\)) and δ in orthogonality (i.e., quantifying Π1i Π1i+1) is left as an open question. A full analysis should yield a lower bound on the total fidelity as a function of the KCBS value, δ and ϵ.

Note that the experimental points in Fig. 1 lie above our robustness curve. The robustness curve obtained via the full analysis cannot be above the present curve and thus will still lower bound the total fidelity for the experimental data points. Similarly, the existing robustness curves in the Bell setting also only consider fidelity lower bound as a function of quantum value. Their analogous full analysis ought to include errors emanating from detection and locality loopholes.

A naïve application of current techniques fails because Algorithm 4 no longer yields a valid isometry. Complementary to this, improving the sharpness (i.e., projectiveness) and exclusivity of measurements in the experiment is also an obvious yet important goal, which, if properly achieved, may render the aforesaid irrelevant.

Future directions

Extending the analysis to n > 5 (by making the algorithm more efficient), adapting it to more involved settings (possibly to anti-cycles), dropping the IID assumption (perhaps by using martingale analysis), obtaining analytic bounds (possibly via techniques from convex optimisation), we believe, are interesting avenues for further exploration.

Methods

Lower bound using an SDP relaxation

We briefly describe our algorithm for estimating F and outline an argument which shows that this algorithm always yields a lower bound (on F). First, we drop the maximisation over V in Equation 5 and replace it with a particular isometry V which is expressed in terms of \(\rho ,{\{{{{\Pi }}}_{i}\}}_{i = 1}^{5}\). Then, as we shall see, the expression for fidelity appears as a sum of terms of the following form. Let w be a word created from the letters\(\{{\mathbb{I}},{{{\Pi }}}_{1},{{{\Pi }}}_{2},\ldots ,{{{\Pi }}}_{5},\hat{P}\}\), with \({\hat{P}}^{{\dagger} }\hat{P}={\mathbb{I}}\), \({{{\Pi }}}_{i}^{2}={{{\Pi }}}_{i}\), and ΠiΠj = 0 if (i, j) E, i.e., when i, j are exclusive. (We introduced \(\hat{P}\) for completeness; its role is explained later). The fidelity is a linear combination of these words, i.e., \(F=\mathop{\min }\nolimits_{\left\{\left\langle w\right\rangle \right\}}{\sum }_{w}{\alpha }_{w}\left\langle w\right\rangle\), where \({{{\rm{tr}}}}[w\rho ]=:\left\langle w\right\rangle\), subject to the constraint that \({\{\left\langle w\right\rangle \}}_{w}\) corresponds to a quantum realisation. The advantage of casting the problem in this form is that one can now relax the problem to a sequence of semidefinite programs. i.e., construct an NPA-like hierarchy38.

The idea is simple to state. Treat \({\left\{\left\langle w\right\rangle \right\}}_{w}\) as a vector. Denote by Q the set of all such vectors which correspond to a quantum realisation (of \({\left\{{p}_{i}\right\}}_{i = 1}^{5}\)). It turns out that one can impose constraints on words with k letters, for instance. Under these constraints, denote by Qk the set that is obtained. Note that QkQ for it may contain vectors which do not correspond to the quantum realisation. In fact, Qk can be characterised using semidefinite programming constraints (which, in turn, means they are efficiently computable). Intuitively, one expects that \(\mathop{\lim }\nolimits_{k\to \infty }{Q}_{k}=Q\). Further, it is clear that \(F=\mathop{\min }\nolimits_{{\{\left\langle w\right\rangle \}}_{w}\in Q}{\sum }_{w}{\alpha }_{w}\left\langle w\right\rangle \ge \mathop{\min }\nolimits_{{\left\{\left\langle w\right\rangle \right\}}_{w}\in {Q}_{k}}{\sum }_{w}{\alpha }_{w}\left\langle w\right\rangle\) as we are minimising over a larger set on the right-hand side.

We now proceed formally. We begin with defining the ideal KCBS configuration referred to above.

Definition 3

(An ideal KCBS configuration). Consider a three-dimensional Hilbert space spanned by the basis \(\{\left\vert 0\right\rangle ,\left\vert 1\right\rangle ,\left\vert 2\right\rangle \}\). Let

$$\left\vert {u}_{l}\right\rangle := \cos \theta \left\vert 0\right\rangle +\sin \theta \sin {\phi }_{l}\left\vert 1\right\rangle +\sin \theta \cos {\phi }_{l}\left\vert 2\right\rangle ,$$
(19)

where ϕllπ(n − 1)/n for 1 ≤ l ≤ n and \({\cos }^{2}\theta =\frac{\cos (\pi /n)}{1+\cos (\pi /n)}\). Define

$$\left\vert {\psi }^{KCBS}\right\rangle := \left\vert 0\right\rangle ,$$
(20)
$${{{\Pi }}}_{i}^{KCBS}:= \left\vert {u}_{i}\right\rangle \left\langle {u}_{i}\right\vert .$$
(21)

For concreteness, we first consider a unitary USWAP instead of an isometry, which acts on two spaces \({{{\mathcal{A}}}}\) and \({{{{\mathcal{A}}}}}^{{\prime} }\), i.e., \({U}_{{{{\rm{SWAP}}}}}:{{{\mathcal{A}}}}\otimes {{{{\mathcal{A}}}}}^{{\prime} }\to {{{\mathcal{A}}}}\otimes {{{{\mathcal{A}}}}}^{{\prime} }\). The space \({{{{\mathcal{A}}}}}^{{\prime} }\) is three-dimensional and \({{{\mathcal{A}}}}\) is an arbitrary Hilbert space. Informally, we want to construct the unitary USWAP to be such that it takes a realisation in \({{{\mathcal{A}}}}\) and maps it to a realisation in \({{{{\mathcal{A}}}}}^{{\prime} }\) which has a large overlap with the KCBS configuration. To this end, we first assume that \({{{\mathcal{A}}}}\) is three-dimensional. In particular, suppose that the \({{{\mathcal{A}}}}\) register is in the state

$$\sigma\in\mathop{\underbrace{\{\left|\psi^{KCBS}\right\rangle \left\langle \psi^{KCBS}\right|\}\cup \{ {{{\mathrm{\Pi}}}}_{i}^{KCBS} \left|{\psi^{KCBS}}\right\rangle \left\langle{\psi^{KCBS}}\right| {{{\mathrm{\Pi}}}}_i^{KCBS} \} _{i=1}^{5}}}\limits_{\substack{:= {{\mathcal{S}}}^{KCBS}}}.$$
(22)

Then, at the very least, we want USWAP to map \({\sigma }_{{{{\mathcal{A}}}}}\otimes \left\vert 0\right\rangle {\left\langle 0\right\vert }_{{{{{\mathcal{A}}}}}^{{\prime} }}\) to \(\left\vert 0\right\rangle {\left\langle 0\right\vert }_{{{{\mathcal{A}}}}}\otimes {\sigma }_{{{{{\mathcal{A}}}}}^{{\prime} }}\) (see Fig. 2). Our strategy is to construct USWAP in this seemingly trivial case and then express it in terms of the state and measurement operators on \({{{\mathcal{A}}}}\). The rationale is that by construction, USWAP will work for the ideal case and therefore should also work for cases close to the ideal. This should become clear momentarily. Note that any circuit that swaps two qutrits should let us achieve our simplified goal (because all elements of SKCBS are defined on a three-dimensional Hilbert space). One possible qutrit swapping unitary/circuit (a special case of the general qudit swapping unitary/circuit defined in ref. 36) may be defined as \({S}_{{{{\rm{SWAP}}}}}^{{\prime\prime} }:= TUVU\), where

$$\begin{array}{ll}T\,:= {{\mathbb{I}}}_{{{{\mathcal{A}}}}}\otimes \mathop{\sum }\limits_{k=0}^{2}\left\vert -k\right\rangle {\left\langle k\right\vert }_{{{{{\mathcal{A}}}}}^{{\prime} }},\\ U\,:= \mathop{\sum }\limits_{k=0}^{2}{P}_{{{{\mathcal{A}}}}}^{k}\otimes \left\vert k\right\rangle {\left\langle k\right\vert }_{{{{{\mathcal{A}}}}}^{{\prime} }},\\ V\,:= \mathop{\sum }\limits_{k=0}^{2}\left\vert \bar{k}\right\rangle {\left\langle \bar{k}\right\vert }_{{{{\mathcal{A}}}}}\otimes {P}_{{{{{\mathcal{A}}}}}^{{\prime} }}^{-k},\end{array}$$
(23)

where \(P:= \mathop{\sum }\nolimits_{i = 0}^{2}\left\vert \overline{k+1}\right\rangle \left\langle \bar{k}\right\vert\) is a translation operator, the arithmetic operations are modulo 3 and \(\{\left\vert \bar{0}\right\rangle ,\left\vert \bar{1}\right\rangle ,\left\vert \bar{2}\right\rangle \}\) is a basis for the qutrit space \({{{\mathcal{A}}}}\). We omit the proof that \({S}_{{{{\rm{SWAP}}}}}^{{\prime\prime} }\) indeed performs a swap operation (for a proof see ref. 36). To generalise this idea and to construct an isometry, we relax the assumption that \({{{\mathcal{A}}}}\) is a three-dimensional Hilbert space. We re-express/replace the operations in T, U, V, which act on the \({{{\mathcal{A}}}}\) space by linear combinations of monomials in \({\{{{{\Pi }}}_{i}\}}_{i = 1}^{5}\). We obtain the coefficients used in these linear combinations by assuming the space \({{{{\mathcal{A}}}}}^{{\prime} }\) is three-dimensional. The idea is simply that this map reduces to a swap operation when we re-impose the assumptions, and for cases close to it, we expect it to behave appropriately. We describe this procedure more precisely below.

Fig. 2: Swap isometry.
figure 2

In this illustration, A and \({A}^{{\prime} }\) are three-dimensional Hilbert spaces. The KCBS configuration is denoted by \(\left\vert {\psi }^{{\prime} }\right\rangle\) and \(\{\left\vert {n}_{i}^{{\prime} }\right\rangle \}\) which represent the state and measurements (projectors along the vectors), respectively. The transformation illustrates how USWAP acts on an arbitrary configuration (in A) and produces the KCBS configuration (in \({A}^{{\prime} }\)). In general, USWAP is expressed in terms of the measurement operators specifying the arbitrary configuration to begin with. It serves as a key ingredient in obtaining a bound on the total fidelity.

Algorithm 4

(Constructing an isometry). Let

  • \({{{{\mathcal{A}}}}}^{{\prime} }\) be a three-dimensional Hilbert space spanned by an orthonormal basis \(\left\{{\left\vert 0\right\rangle }_{{{{{\mathcal{A}}}}}^{{\prime} }},{\left\vert 1\right\rangle }_{{{{{\mathcal{A}}}}}^{{\prime} }},{\left\vert 2\right\rangle }_{{{{{\mathcal{A}}}}}^{{\prime} }}\right\}\),

  • \({\rho }^{KCBS},{\{{{{\Pi }}}_{i}^{KCBS}\}}_{i = 1}^{5}\) be an ideal KCBS configuration (see Definition 3) on \({{{{\mathcal{A}}}}}^{{\prime} }\),

  • \({{{\mathcal{A}}}}\) be a Hilbert space with dimension at least 3 containing orthonormal vectors \(\left\{{\left\vert \bar{0}\right\rangle }_{{{{\mathcal{A}}}}},{\left\vert \bar{1}\right\rangle }_{{{{\mathcal{A}}}}},{\left\vert \bar{2}\right\rangle }_{{{{\mathcal{A}}}}}\right\}\),

  • \(\rho ,{\{{{{\Pi }}}_{i}\}}_{i = 1}^{5}\) be an arbitrary quantum realisation defined on \({{{\mathcal{A}}}}\).

Define T, U, V as in Equation 23 and let \({S}_{{{{\rm{SWAP}}}}}^{{\prime} }:= TUVU\) with the following changes. Let

$${{{{\mathcal{W}}}}}^{KCBS}:= \{{\{{{{\Pi }}}_{i}^{KCBS}\}}_{i = 1}^{5},{\{{{{\Pi }}}_{i}^{KCBS}{{{\Pi }}}_{j}^{KCBS}\}}_{i,j = 1}^{5},\ldots \,\}$$
(24)

and

$${{{\mathcal{W}}}}:= \{{\{{{{\Pi }}}_{i}\}}_{i = 1}^{5},{\{{{{\Pi }}}_{i}{{{\Pi }}}_{j}\}}_{i,j = 1}^{5},\ldots \,\}$$
(25)

be the set of “words” formed by the KCBS projectors and those of the arbitrary quantum realisation, respectively.

  • Translation operator:

    • Express \({P}_{{{{{\mathcal{A}}}}}^{{\prime} }}\) as a linear combination of elements in \({{{\mathcal{W}}}}\), i.e., \({P}_{{{{{\mathcal{A}}}}}^{{\prime} }}={\sum }_{{l}^{KCBS}\in {{{{\mathcal{W}}}}}^{KCBS}}{\alpha }_{l}{l}^{KCBS}\).

    • Define \({P}_{{{{\mathcal{A}}}}}:= {\sum }_{l\in {{{\mathcal{W}}}}}{\alpha }_{l}l\).

  • Basis projectors: Formally replace, in V, the operators

    1. (a)

      \(\left\vert \bar{0}\right\rangle {\left\langle \bar{0}\right\vert }_{{{{\mathcal{A}}}}}\) by Π1,

    2. (b)

      \(\left\vert \bar{1}\right\rangle {\left\langle \bar{1}\right\vert }_{{{{\mathcal{A}}}}}\) by Π2, and

    3. (c)

      \(\left\vert \bar{2}\right\rangle {\left\langle \bar{2}\right\vert }_{{{{\mathcal{A}}}}}\) by \(({\mathbb{I}}-{{{\Pi }}}_{1})({\mathbb{I}}-{{{\Pi }}}_{2})\).

Thus, V now becomes \({{{\Pi }}}_{1}\otimes {{\mathbb{I}}}_{{{{{\mathcal{A}}}}}^{{\prime} }}+{{{\Pi }}}_{2}\otimes {P}_{{{{{\mathcal{A}}}}}^{{\prime} }}^{-1}+({\mathbb{I}}-{{{\Pi }}}_{1})({\mathbb{I}}-{{{\Pi }}}_{2})\otimes {P}_{{{{{\mathcal{A}}}}}^{{\prime} }}^{-2}\).

We found an explicit linear combination for step 1 (a) of Algorithm 4. (Using prior results, we expect one can prove the existence of such a linear combination, but we do not pursue this here). Thus, the algorithm always succeeds at constructing \({S}_{{{{\rm{SWAP}}}}}^{{\prime} }\). We must show that \({S}_{{{{\rm{SWAP}}}}}^{{\prime} }\) is in fact an isometry. This is important because of the following reason. Recall that our objective was to lower bound the fidelity given in Equation (II.2) of the main text. To this end, we said we drop the maximisation over all possible Vs (for a given quantum realisation \((\rho ,{\left\{{{{\Pi }}}_{i}\right\}}_{i = 1}^{5})\)) and instead insert a specific isometry \({S}_{{{{\rm{SWAP}}}}}^{{\prime} }\) (which is a function of \((\rho ,{\{{{{\Pi }}}_{i}\}}_{i = 1}^{5})\)). Note that this argument for lower bounding fidelity breaks if \({S}_{{{{\rm{SWAP}}}}}^{{\prime} }\) is not an isometry. In fact, \({P}_{{{{\mathcal{A}}}}}\) as produced by the algorithm is not necessarily unitary (viz. \({P}_{{{{\mathcal{A}}}}}^{{\dagger} }{P}_{{{{\mathcal{A}}}}}={{\mathbb{I}}}_{{{{\mathcal{A}}}}}\) may not hold). To address this, we use the localising matrix technique introduced in ref. 39. Let \({\hat{P}}_{{{{\mathcal{A}}}}}\) be unitary matrix satisfying \(\hat{P}P\ge 0\), where we dropped the subscript for clarity. Consider the case where P is not unitary. In that case, one can use polar decomposition to write \(P=\left\vert P\right\vert U\) (not to be confused with the U above; where \(\left\vert P\right\vert \ge 0\) and \({U}^{{\dagger} }U={\mathbb{I}}\)) so choosing \(\hat{P}={U}^{{\dagger} }\) satisfies \(\hat{P}P\ge 0\). Thus for each P, the constraint can be satisfied. Consider the other case, i.e., where P = U is unitary. Then (explained below), \(\hat{P}={U}^{{\dagger} }\). Thus, in the ideal case, we recover the same unitary and for the case close to ideal, we are guaranteed that there is some solution (which we expect should also work reasonably). Combining these, we can construct SSWAP, which is an isometry.

(To see why \(\hat{P}={U}^{{\dagger} }\), write the polar decomposition of \(\hat{P}=\left\vert \hat{P}\right\vert E\) (where \(\left\vert \hat{P}\right\vert \ge 0\) and \({E}^{{\dagger} }E={\mathbb{I}}\)). Then, \(\hat{P}U=\left\vert \hat{P}\right\vert EU\), which is a polar decomposition of \(\hat{P}U\). The polar decomposition of a positive semidefinite matrix M always has the form \(M\cdot {\mathbb{I}}\). Using \(M=\hat{P}U\), and identifying EU with \({\mathbb{I}}\), we have E = U).

Lemma 5

(SSWAP is indeed an isometry). Let \({S}_{{{{\rm{SWAP}}}}}^{{\prime} }\) be the map produced by Algorithm 4 and define SSWAP to be \({S}_{{{{\rm{SWAP}}}}}^{{\prime} }\) with \({P}_{{{{\mathcal{A}}}}}\) replaced by \({\hat{P}}_{{{{\mathcal{A}}}}}\). Then SSWAP is an isometry if the following conditions hold

$${\hat{P}}_{{{{\mathcal{A}}}}}^{{\dagger} }{\hat{P}}_{{{{\mathcal{A}}}}}={{\mathbb{I}}}_{{{{\mathcal{A}}}}},$$
(26)
$${\hat{P}}_{{{{\mathcal{A}}}}}{P}_{{{{\mathcal{A}}}}}\ge 0.$$
(27)

Proof

It suffices to show that \({\left\langle \psi \right\vert }_{{{{{\mathcal{A}}}}}^{{\prime} }{{{\mathcal{A}}}}}{S}_{{{{\rm{SWAP}}}}}^{{\dagger} }{S}_{{{{\rm{SWAP}}}}}{\left\vert \psi \right\rangle }_{{{{{\mathcal{A}}}}}^{{\prime} }{{{\mathcal{A}}}}}=1\) for all normalised \({\left\vert \psi \right\rangle }_{{{{{\mathcal{A}}}}}^{{\prime} }{{{\mathcal{A}}}}}\). We express SSWAP = TUVU, where T is as in Equation 23, \(U:= \mathop{\sum }\nolimits_{k = 0}^{2}{\hat{P}}_{{{{\mathcal{A}}}}}^{k}\otimes \left\vert \bar{k}\right\rangle {\left\langle \bar{k}\right\vert }_{{{{{\mathcal{A}}}}}^{{\prime} }}\) and \(V:= {{{\Pi }}}_{1}\otimes {{\mathbb{I}}}_{{{{{\mathcal{A}}}}}^{{\prime} }}+{{{\Pi }}}_{2}\otimes {P}_{{{{{\mathcal{A}}}}}^{{\prime} }}^{-1}+({\mathbb{I}}-{{{\Pi }}}_{1})({\mathbb{I}}-{{{\Pi }}}_{2})\otimes {P}_{{{{{\mathcal{A}}}}}^{{\prime} }}^{-2}\). Observe that \({T}^{{\dagger} }T={{\mathbb{I}}}_{{{{\mathcal{A}}}}{{{{\mathcal{A}}}}}^{{\prime} }}={U}^{{\dagger} }U\) since \({\hat{P}}_{{{{\mathcal{A}}}}}^{{\dagger} }{\hat{P}}_{{{{\mathcal{A}}}}}={{\mathbb{I}}}_{{{{\mathcal{A}}}}}\). Further, we have that

$$\begin{array}{ll}{V}^{{\dagger} }V={{{\Pi }}}_{1}\otimes {{\mathbb{I}}}_{{{{{\mathcal{A}}}}}^{{\prime} }}+{{{\Pi }}}_{2}\otimes {{\mathbb{I}}}_{{{{{\mathcal{A}}}}}^{{\prime} }}+({\mathbb{I}}-{{{\Pi }}}_{1})({\mathbb{I}}-{{{\Pi }}}_{2})\otimes {{\mathbb{I}}}_{{{{{\mathcal{A}}}}}^{{\prime} }}\\\because {{{\Pi }}}_{1}{{{\Pi }}}_{2}=0,{P}_{{{{{\mathcal{A}}}}}^{{\prime} }}^{{\dagger} }{P}_{{{{{\mathcal{A}}}}}^{{\prime} }}={{\mathbb{I}}}_{{{{{\mathcal{A}}}}}^{{\prime} }}\end{array}$$
(28)
$$={{\mathbb{I}}}_{{{{\mathcal{A}}}}{{{{\mathcal{A}}}}}^{{\prime} }}.$$
(29)

Hence, \({S}_{{{{\rm{SWAP}}}}}^{{\dagger} }{S}_{{{{\rm{SWAP}}}}}={{\mathbb{I}}}_{{{{\mathcal{A}}}}{{{{\mathcal{A}}}}}^{{\prime} }}\) establishing that SSWAP is, in fact, unitary and thus also an isometry.□

We can now combine all the pieces to write the final optimisation problem we solve. We use \({{{\mathcal{G}}}}(\{{a}_{i}\})\) to denote the set of all letters

Algorithm 6

(The SDP for lower bounding the fidelity of a given realisation with the ideal KCBS realisation) The algorithm proceeds in two parts.Notation: Let

  • \({{{\mathcal{A}}}}\) represent an arbitrary Hilbert space and \({{{{\mathcal{A}}}}}^{{\prime} }\) represent a three-dimensional Hilbert space,

  • \(\bar{{{{\mathcal{W}}}}}\) be the set of “words” constructed using \({\{{{{\Pi }}}_{i}\}}_{i = 1}^{5}\), \(\hat{P}\) and \({\hat{P}}^{{\dagger} }\), i.e., \(\bar{{{{\mathcal{W}}}}}={{{\mathcal{G}}}}({\{{{{\Pi }}}_{i}\}}_{i = 1}^{5},\hat{P},{\hat{P}}^{{\dagger} })\), and

  • define \(\left\langle w\right\rangle := t{r}_{{{{\mathcal{A}}}}}(\rho w)\) and assume (Without loss of generality, one can purify a state by increasing the dimension and have the operators leave that space unaffected (for any given quantum realisation)). \(\rho =\left\vert \psi \right\rangle \left\langle \psi \right\vert\) so that \(\left\langle w\right\rangle =\left\langle \psi \right\vert w\left\vert \psi \right\rangle\) for all \(w\in {{{\mathcal{W}}}}\).

Input:

  • (Implicit) Πi .Πj = 0 for all i, jE(G), where G is a five-cycle graph and E are its edges, indexed [1, 2, …, 5].

  • Observed statistics: (To obtain a better bound, one can add more fine-grained statistics as well, such as the values of pi individually for each i).

Evaluation Part 1.

  • Evaluate SSWAP as described in Lemma 5 using Algorithm 4.

  • Define the objective function f as

    $$f\left(\rho ,{\left\{{{{\Pi }}}_{i}\right\}}_{i = 1}^{5}\right)=\mathop{\sum }\limits_{i=1}^{5}{{{\mathcal{F}}}}\left(t{r}_{{{{\mathcal{A}}}}}\left[{S}_{{{{\rm{SWAP}}}}}\left({{{\Pi }}}_{i}{\rho }_{{{{\mathcal{A}}}}}{{{\Pi }}}_{i}\otimes \left\vert 0\right\rangle {\left\langle 0\right\vert }_{{{{{\mathcal{A}}}}}^{{\prime} }}\right){S}_{{{{\rm{SWAP}}}}}^{{\dagger} }\right],{{{\Pi }}}_{i}^{KCBS}{\rho }_{{{{{\mathcal{A}}}}}^{{\prime} }}^{KCBS}{{{\Pi }}}_{i}^{KCBS}\right)$$
    (30)
    $$+{{{\mathcal{F}}}}\left(t{r}_{{{{\mathcal{A}}}}}\left[{S}_{{{{\rm{SWAP}}}}}\left({\rho }_{{{{\mathcal{A}}}}}\otimes \left\vert 0\right\rangle {\left\langle 0\right\vert }_{{{{{\mathcal{A}}}}}^{{\prime} }}\right){S}_{{{{\rm{SWAP}}}}}^{{\dagger} }\right],{\rho }_{{{{{\mathcal{A}}}}}^{{\prime} }}^{KCBS}\right)$$
    (31)

    and evaluate the coefficients fw so that (This was done using symbolic computation).

    $$f=\mathop{\sum}\limits_{w\in {{{\mathcal{W}}}}}{f}_{w}\left\langle w\right\rangle .$$
    (32)
  • Again, from Algorithm 4, evaluate \({P}_{{{{\mathcal{A}}}}}\) as a linear combination of \(\left\langle w\right\rangle\).

Evaluation Part 2. Solve the following SDP:

$$\begin{array}{llr} F_{{{\rm{noiseless}}}}= & \mathop{\min}\limits_{\{\left\langle w\right\rangle \}_{w\in{{\mathcal{W}}}}}\sum\limits_{w\in{{\mathcal{W}}}}f_{w}\left\langle w\right\rangle \\ \qquad{{{\rm{s.t.}}}} & {{{{\Gamma}}}}^{(k)}({{\mathbb{I}}}) \ge 0 & \because {\rm{all}}\,{\rm{gram}}\,{\rm{matrices}}\,{\rm{are}} \ge0\\ & {{{{\Gamma}}}}^{(k)}({{\mathbb{I}}})_{v,w}={{{{\Gamma}}}}^{(k)}({{\mathbb{I}}})_{v^{\prime},w^{\prime}} & {{\rm{if}}}\,v^{\dagger}w=v^{\prime\dagger}w^{\prime}\\ & {{{{\Gamma}}}}^{(k)}({{\hat{P}}}_{{{\mathcal{A}}}}P_{{{\mathcal{A}}}})\ge0 & ({\rm{localising}}\,{\rm{matrix}})\\ & {{{{\Gamma}}}}^{(k)}({{\hat{P}}}_{{{\mathcal{A}}}}P_{{{\mathcal{A}}}})_{v,w}={{{{\Gamma}}}}^{(k)}({{\hat{P}}}_{{{\mathcal{A}}}}P_{{{\mathcal{A}}}})_{v^{\prime},w^{\prime}} & \quad{{\rm{if}}}\,v^{\dagger}{{\hat{P}}}_{{{\mathcal{A}}}}P_{{{\mathcal{A}}}}w=v^{\prime\dagger}{{\hat{P}}}_{{{\mathcal{A}}}}P_{{{\mathcal{A}}}}w^{\prime}\\ & \sum\limits_{i=1}^{5}\left\langle {{{\mathrm{\Pi}}}}_{i}\right\rangle =c & ({\rm{observed}}\,{\rm{statistic}}) \end{array}$$

where Γ(k)(X) is a matrix which is

  • indexed by letters w,

  • whose matrix elements are given by \({{{\Gamma }}}^{(k)}{(X)}_{v,w}=\left\langle \psi \right\vert {v}^{{\dagger} }Xw\left\vert \psi \right\rangle\),

  • where k defines the maximum number of letters that appear in the words w which index the matrix Γ(k), and,

where in the first two equality constraints, we use the following relations:

  • Πi .Πj = 0 for all i, jE(G) and

  • \({\hat{P}}_{{{{\mathcal{A}}}}}^{{\dagger} }{\hat{P}}_{{{{\mathcal{A}}}}}={\hat{P}}_{{{{\mathcal{A}}}}}{\hat{P}}_{{{{\mathcal{A}}}}}^{{\dagger} }={{\mathbb{I}}}_{{{{\mathcal{A}}}}}\).

Output: Fnoiseless(c).

Remark 1

Note that \(\hat{P}P\ge 0\ \Rightarrow \ {{{\Gamma }}}^{(k)}(\hat{P}P)\ge 0\). This follows readily by letting \({A}^{{\dagger} }A=\hat{P}P\) for some A (which must exist for any positive semidefinite matrix; one can use spectral decomposition). Then Γ(k)(AA) is a Gram matrix and thus ≥0.

Remark 2

We solved this SDP with \(\left\langle w\right\rangle\) restricted to being real, but it has been shown that this is without loss of generality (see, e.g., §V.A in ref. 36).

We thus have an algorithm which can calculate the required lower bound on fidelity, given the observed value of the KCBS operator.

Experimental setup

The calcium ions, in which two dark states and one bright state are chosen to encode the states {\(\left\vert 1\right\rangle\),\(\left\vert 2\right\rangle\)} and \(\left\vert 0\right\rangle\), respectively. Every experimental sequence starts with 1 ms Doppler cooling using a 397 nm laser and a resonant 866 nm laser. The 397 nm laser is red detuned approximately half a natural linewidth from resonating with the cycling transition between S1/2 and P1/2 manifolds. This is followed by a 300 μs electromagnetically induced transparency (EIT) cooling sequence, which cools the ion down to near the motional ground state. After that, a 10 μs optical pumping laser is applied to initialise the qutrit to the \(\left\vert 0\right\rangle\) state with 99.5% fidelity. When needed, a 729 nm pulse sequence is applied to prepare a certain initial state. Measurements of the observables {Ai} are performed through coherent rotations R2(θ2, ϕ2)R1(θ1, ϕ1), a fluorescence detection followed by the operation \({R}_{1}^{{\dagger} }({\theta }_{1},{\phi }_{1}){R}_{2}^{{\dagger} }({\theta }_{2},{\phi }_{2})\) which undoes the previous rotation. The first fluorescence detection lasts for 220 μs and uses laser settings close to those of Doppler cooling to minimise the motional heating due to photon recoil (in case of a bright state). However, this brings the temperature of the bright state close to the Doppler limit. Therefore, a 150 μs EIT cooling sequence followed by 10 μs optical pumping pulses is applied to cool the bright state ion. The detection and cooling time are greatly suppressed to minimise the random phase accumulation between the sequential measurement. Neither fluorescence detection nor the EIT cooling process affects the temperature of a dark state ion, which is slightly heated at a rate of 140 quanta per second due to electronic noise. The second fluorescence detection uses a resonant laser pulse and 300 μs integrating time, which lowers detection error. The result is acquired by counting the number of photons collected from the photo-multiplier tube (PMT) within the detection time. The statistical probability is calculated by repeating the same measurement 10,000 times.

In our experiments, the 2π pulse time for both transitions is adjusted to around 142 μs; that is, the Rabi frequency is as low as Ω1/2 = (2π)7 KHz, making the AC-Stark shift below 100 Hz. The separation between \(\left\vert 1\right\rangle\) and \(\left\vert 2\right\rangle\) is ω2 − ω1 = (2π)8.69 MHz with corresponding magnetic field B = 5.18 G. The maximum probability of off-resonant excitation \({{{\Omega }}}^{2}/{({\omega }_{2}-{\omega }_{1})}^{2}\) is about 6.5 × 10−7, small enough to ensure the independence of each Rabi oscillation40,41.

Analysing the data

The data

The complete data set can be accessed on GitHub42. Table 2 shows a summary of our experimental and numerical results. In the table, configuration refers to the p and θ configurations discussed in “Results: Experiments that are self-tested”. Each row represents the statistics obtained after running 10,000 experiments. White (grey) rows represent normal (reverse) order (again, see “Results: Experiments that are self-tested”). The values in the last two columns show lower bounds on the total fidelity obtained using our self-test scheme (i.e., solving the semidefinite programme in Algorithm 6), evaluated in two slightly different ways. These arise as we consider μ − 1.96σ (where μ is the mean and σ is the standard deviation) to estimate the smallest possible value of our observed variables, with 95% confidence. Note the lower bounds on fidelity (last two columns) are satisfied by the value obtained using conventional tomography. For the normal (reverse) ordered case, the results are plotted in Fig. 1 (Supplementary Fig. 1).

Why two curves?

As noted earlier, there are two robustness curves in the aforementioned figures. We now detail why. Notice that the observed statistic constraint in the SDP corresponding to Algorithm 6 can be tightened by specifying the value of each \(\left\langle {{{\Pi }}}_{i}\right\rangle\) term. Obviously, if one specifies the value of \(\left\langle {{{\Pi }}}_{i}\right\rangle\), the value for their sum automatically gets fixed. Based on the experimental data, we have access to the value of each of the \(\left\langle {{{\Pi }}}_{i}\right\rangle\) and thus we can always obtain a tighter bound compared with the bound obtained via the sum constraint in the SDP for Algorithm 6. We illustrate this by plotting the robustness curve obtained in the special case p1 = p2 = p3 = p4 = p5 (pi and 〈Πi〉 are interchangeable). One could have just as easily taken a different choice for the values of pi such that their sum remains equal to the appropriate KCBS value and obtain a different robustness curve. All such curves, obtained by providing the value for pis, will be lower bound by the curve obtained via the sum constraint (the blue curve). For our experimental data point with mean μ and standard deviation σ, we base our analysis on μ − 1.96σ, which is the smallest possible value with 95% confidence for normally distributed data.

Analysing the p-configuration

As mentioned above, we base our analysis on μ − 1.96σ for the appropriate values of μ and σ. This, however, has consequences on the constraint that we impose via the observed statistics. For our experimental data, we observe that \({\sum }_{i}(\mu \left({p}_{i}\right)-1.96\sigma \left({p}_{i}\right))\) is upper bounded by \(\mu \left({\sum }_{i}{p}_{i}\right)-1.96\sigma \left({\sum }_{i}{p}_{i}\right)\). Since our robustness curves are very sensitive to minor changes near the region of maximum KCBS value \(\left({\sum }_{i}{p}_{i}\right)\), the lower bound on the fidelity provided by the sum constraint can be better than the (nearly) equal statistic constraint (p1 ≈ p2 ≈ p3 ≈ p4 ≈ p5). Since our goal is to provide tight lower bounds, we take the largest value, which is the one obtained from the sum constraint close to the region of the maximum KCBS value. Away from the maximum KCBS value region, (nearly) equal statistic constraint provides a better estimate (as is evident from the plots in Fig. 1). We also computed the fidelity of these quantum realisations to the ideal KCBS configuration by performing state and measurement tomography. We found that the self-testing lower bounds are satisfied.

Results for p-configuration

For p = 0, 0.1, and 0.2, we obtained ∑kpk to be 2.233, 2.186, and 2.118, respectively, for the normal ordered case. By solving the SDP outputted by Algorithm 6 with these values as inputs, the self-testing lower bounds on the total fidelity of these realisations to the KCBS configuration are 5.296, 3.002, and 2.343, respectively. For the reverse-ordered experiments the corresponding values for ∑kpk are 2.236, 2.182, and 2.124, respectively. The self-testing lower bound on the total fidelity for these cases were 5.892, 2.933, and 2.386, respectively. On the other hand, conventional tomography yielded 5.965, 5.901, and 5.812, respectively. The values are the same for normal and reverse-ordered experiments (because an experiment being normal or reverse is determined by a quantum random number generator and has no explicit difference otherwise at the level of measurements and the state involved). As expected, the total fidelity obtained from conventional tomography is indeed above the lower bound on it obtained using our self-test.

Analysing the θ-configuration

To obtain the self-test lower bounds, we proceeded as before. However, finding a lower bound on the fidelity using conventional tomography is slightly more involved in this case. The idea is to first find the fidelity between the experimental setup and the θ configuration and then between θ configuration and the KCBS configuration (up to an isometry). Using a form of triangle inequality, one can lower bound the total fidelity.

In more detail, our goal is to find the total fidelity of the experimentally realised configuration with a configuration which is related to the KCBS configuration via an isometry. In the previous case, this isometry was an identity matrix (a trivial isometry). Since the optimal configuration is unique up to an isometry, any configuration which is related to the KCBS configuration via an isometry can be considered an optimal configuration. Our goal is to calculate the total fidelity of the experimental realisation of \((\left\vert {u}_{0}^{\theta }\right\rangle \left\langle {u}_{0}^{\theta }\right\vert ,{\left\{\left\vert {u}_{i}^{\theta }\right\rangle \left\langle {u}_{i}^{\theta }\right\vert \right\}}_{i = 1}^{5})\), say \(({\rho }_{0}^{E},{\left\{{M}_{i}^{E}\right\}}_{i = 1}^{5})\) to an optimal configuration, say \((\left\vert {u}_{0}^{O}\right\rangle \left\langle {u}_{0}^{O}\right\vert ,{\left\{\left\vert {u}_{i}^{O}\right\rangle \left\langle {u}_{i}^{O}\right\vert \right\}}_{i = 1}^{5})\). Let us denote the fidelity of \(\left\vert {u}_{i}^{E}\right\rangle\) to \(\left\vert {u}_{i}^{O}\right\rangle\) as \({F}_{i}^{E,O}\). Here, \({F}_{i}^{E,O}\) denotes the fidelity of the ith component of the experimental realisation to that of the ideal configuration. Similarly, other fidelities are denoted by \({F}_{i}^{E,\theta }\) and \({F}_{i}^{\theta ,O}\). We know that fidelity is not a valid metric, and hence, we will not be able to apply triangle inequality directly. However, we can use trace distance as a proxy to relate the aforementioned three configurations. After some simple calculations, we obtain the following expression for the lower bound on the total fidelity \(\left(\mathop{\sum }\nolimits_{i = 0}^{5}{F}_{i}^{E,O}\right)\) (see Supplementary Note 4 for details)

$$\mathop{\sum }\limits_{i=0}^{5}{F}_{i}^{E,I}\ge 6-\left(\mathop{\sum }\limits_{i=0}^{5}\sqrt{1-{F}_{i}^{E,\theta }}\right)-\left(\mathop{\sum }\limits_{i=0}^{5}\sqrt{1-{F}_{i}^{\theta ,O}}\right).$$
(33)

Based on the experimental data, we can calculate \(\left(\mathop{\sum }\nolimits_{i = 0}^{5}\sqrt{1-{F}_{i}^{E,\theta }}\right)\). The second total fidelity expression \(\left(\mathop{\sum }\nolimits_{i = 0}^{5}\sqrt{1-{F}_{i}^{\theta ,O}}\right)\) can be evaluated using numerical optimisation.

Results for the θ-configuration

We obtained ∑kpk to be 2.058 and 2.043, respectively, for the normal ordered case. For the reverse-ordered experiments, the corresponding values were 2.057 and 2.048, respectively. The self-testing lower bound on the total fidelity for the normal ordered case was 2.561 and 2.222, and the corresponding values for the reverse ordered case were 2.579 and 2.579, respectively. Conventional tomography, on the other hand, yielded 3.956 and 4.050, respectively (for both normal normal and reverse order). Again, the self-testing lower bounds are satisfied, as expected.

Numerics to evaluate fidelity lower bounds

As previously stated, obtaining the numerical solution was quite involved, owing to the fact that the description of the semidefinite program we obtain is implicit. Consequently, one first needs to find this explicit description through symbolic computation and then solve the resulting semidefinite program. After performing the symbolic computation to find the objective and constraints, we solve an SDP over a 192 × 192 matrix with 16,859 constraints. The terms in the objective function must appear in the SDP matrix in order for us to impose appropriate constraints. This is because the optimisation program would otherwise be undefined. The unusually large size of the SDP matrices (compared to similar self-test schemes) reflects the complexity of the objective function in our case, which would have been difficult to obtain without symbolic computation. To capture all the terms that appear in the objective, we needed words with three letters (the matrices involved scale exponentially in the number of letters). Further, we require 769 localising matrix constraints.

We used Jupyter notebooks (based on Python) as our programming environment. We used sympy43 for symbolic computations and cvxpy44,45 for translating the resulting SDP into an instance that MOSEK (an SDP solver) could solve. Our implementation is available on GitHub42.