How post-selection affects device-independent claims under the fair sampling assumption

Device-independent certifications employ Bell tests to guarantee the proper functioning of an apparatus from the sole knowledge of observed measurement statistics, i.e. without assumptions on the internal functioning of the devices. When these Bell tests are implemented with devices having too low efficiency, one has to post-select the events that lead to successful detections and thus rely on a fair sampling assumption. The question that we address in this paper is what remains of a device-independent certification under fair sampling. We provide an intuitive description of post-selections in terms of filters and define the fair sampling assumption as a property of these filters, equivalent to the definition introduced in [Berry et. al., PRA 81(1), 012109 (2010)]. When this assumption is fulfilled, the post-selected data is reproduced by an ideal experiment where lossless devices measure a filtered state which can be obtained from the actual state via local probabilistic maps. Trusted conclusions can thus be obtained on the quantum properties of this filtered state and the corresponding measurement statistics can reliably be used, e.g., for randomness generation or quantum key distribution. We also explore a stronger notion of fair sampling leading to the conclusion that the post-selected data is a fair representation of the data that would be obtained with lossless detections. Furthermore, we show that our conclusions hold in cases of small deviations from exact fair sampling. Finally, we describe setups previously or potentially used in Bell-type experiments under fair sampling and identify the underlying device-specific assumptions.


Introduction
Measurement devices in many quantum experiments, and notably in quantum optics, have a finite non-unit efficiency: such devices may refuse to provide an outcome for the desired measurement, and produce a "no-click" event instead [2]. This lack of detection can usually be explained in simple physical terms, e.g., the photon to be measured is not always absorbed on the chip of the detector. In a simplified physical model of the apparatus, the occurrence of a no-click event is completely independent of the state of the quantum system to be measured. Based on this model, one is tempted to ignore the no-click events altogether and remove them from the measurement data, a.k.a. performing a post-selection.
However, from a black-box perspective, a no-click event must be considered as a measurement outcome, just like the others 1 . This outcome has to be added to the alphabet corresponding to possible values of the measured quantity [3,4,5]. The action of ignoring these events is not always harmless: in the context of testing of Bell inequalities this is known as the detection loophole, and there are explicit examples where the use of post-selection can lead to wrong claims about the performed Bell test, e.g. erroneously deducing the non-locality of a local model [5,6,7]. Such canny local models are not abstract theoretical constructions, but have been produced experimentally with simple optical elements and detectors that are commonly used [8,9,10,11,12]. (a) x ∈ X ρ ∈ S(H) Figure 1: Mathematical model of a lossy device. In panel (a) we illustrate that any device having finite efficiency can always be modelled as a filter acting jointly on the classical setting x ∈ X and on the input quantum state ρ ∈ S(H), followed by by an ideal lossless measurement device. The filter returns a flag f ∈ { , ø } with a probability that depends on x and ρ, and the ideal measurement is performed only if f = . In panel (b) we illustrate the fair sampling condition: the filter factorizes in two components FC and FQ which act independently on the classical and quantum input, respectively, and a detection occurs only when both accept (indicated by a ∧ ≡ logical AND). In panel (c) we illustrate strong fair sampling: the component acting on the quantum input is proportional to the identity channel.
Nevertheless, an accurate physical understanding of the measurement device in the lab may suggest that the no-click events are locally random and independent of system state and measurement settings. If this is really the case, data acquisition and post-selection is equivalent to directly generating the data with an ideal measurement device that has unit efficiency but is otherwise the same as the detector in the lab. Thus, any claim that could be made in the ideal setting carries over when using the experimental post-selected data. This logical step is known as fair sampling assumption (or no-enhancement assumption, at the origins [3,4]). It is important to realize that fair sampling is indeed an assumption and cannot be ensured from the measurement probabilities alone -post-selected local models as mentioned above can reproduce those perfectly.
Thanks to the advancement in quantum technologies we have recently witnessed the first experimental violations of Bell inequalities free of loopholes [13,14,15,16,17], conclusively ruling out that locally causal models could explain the correlations observed in quantum experiments. In the aftermath of achieving this long-standing goal, renewed interest in Bell inequalities was spurred by their technological applications within the framework of device-independent quantum information processing [18,19]. Namely, the sole violation of a Bell inequality can be used to certify devices, to guarantee the randomness of measurement results or the security of a quantum key distribution, without the need to know the internal functioning of the devices used to perform the Bell test [20,21,22,23,24]. Device-independent quantum information processing is at the verge of experimental feasibility [25]. However, performing Bell tests devoid of the detection loophole is still challenging and, as such, most experiments at present still rely on fair sampling. This naturally raises the following question: if assessing fair sampling requires a detailed description of the way the measurement device works, what remains of the device-independent framework in scenarios based on Bell tests relying upon the fair sampling assumption? The aim of our work is to provide a concrete answer to this question.
We first explain how a lossy detector can be understood in terms of filters: we represent a finiteefficiency measurement as a two-step process where first a filter is applied to the classical input and to the quantum state which either accepts or rejects them (corresponding, respectively, to a successful or failed detection) and subsequently a lossless measurement is performed on the filtered quantum state. This is schematically illustrated in panel (a) of Figure 1. An equivalent formulation based on the positive operator-valued measure (POVM) description of the measurement devices is also provided; this formulation allows to directly verify if a detector satisfies fair sampling, given a full specification of its behaviour.
Following the work of Berry et. al. [1], we then give a very general formulation of fair sampling: to have fair sampling, it is sufficient to require that the filter operates independently on the classical input and on the quantum state, see panel (b) of Figure 1. Under this assumption the sampling can be regarded as "fair", since the post-selected data can be seen as being generated from an ideal quantum experiment where lossless devices measure a filtered state 2 . This allows to reach trusted conclusions on the quantum properties of this filtered state and the corresponding measurement statistics can be used reliably for verifiable randomness generation [26,27] or for quantum key distribution [20,21].
In this work, we also discuss a stronger version of the fair sampling assumption, corresponding to what is usually assumed to be the very definition of fair sampling (see e.g. [28,29]). In strong fair sampling, filter operating on the state is proportional to the identity, see panel (c) of Figure 1. We show that, in this case, the post-selected statistics is an unbiased representation of the statistics that would be obtained with unit-efficiency detectors measuring the actual experimental state.
The motivation of the present work is thus to bridge the gap between theoretical studies of device-independent certifications and experimental realizations thereof. To this end, we describe concrete examples of experiments that can be used for device-independent quantum information processing and show that, under fair sampling, these experiments allow one to get semi-deviceindependent conclusions. In fact, even present-day experiments frequently rely upon a fair sampling assumption [30,31,32,33], and this will likely continue to be necessary in future years; however, often there is very little or no theoretical analysis of the consequences that post-selection has in these experiments. Furthermore, we study what happens when small deviations from exact fair sampling are present and we show that the results are robust against small perturbations. Concretely, we provide a prescription for the minimal information that in an actual quantum experiment should be directly assessed in order to verify that a device (approximately) satisfies fair sampling. Assuming that this minimal information is publicly available and trusted, the certification of the device can be safely completed using a standard device-independent protocol with post-selected data.

Paper structure
In Section 1 we describe the general setup and establish part of the notation. In Section 2 we give the general mathematical formulation of lossy measurement devices, as represented in panel (a) of Figure 1. In Section 3 we formalize the definition of fair sampling as depicted in panel (b) of Figure 1 (equivalent to the definition introduced in reference [1]); we then prove that, under this assumption, the post-selected data can be reproduced by an ideal quantum experiment involving only lossless detectors. We then introduce the stronger notion of fair sampling in Section 4, corresponding to panel (c) of Figure 1. In Section 5 we discuss the use of fair sampling in cryptographic settings. In Section 6 we give concrete examples of fair sampling based on a quantum optics setup used to measure the polarization of photons. In Section 7 we investigate the robustness of the results against small perturbations from exact fair sampling, and we show that the deviations in the postselected data are linear in the perturbations from the exact case. We go back to the optical setup in Section 8 and analyse the consequence of approximate fair sampling in this context. Finally, in Section 9 we show that even more general notions of fair sampling are possible, considering cases of fair sampling that are state-dependent. Supplementary material and further considerations are presented in the Appendices.
Quantum framework: We assume that quantum theory provides a valid description of the source and measurements used in the Bell test. To each party k ∈ {A, B, . . . , N } is associated a local Hilbert space H k and the global Hilbert space is H := H A ⊗ H B ⊗. . .⊗ H N . The particles are described by a quantum state Ψ which is in general a density operator (i.e., a mixed quantum state) Ψ ∈ S(H), where S(H) denotes the class of positive semi-definite unit-trace operators on H. The local spaces are denoted as S(H k ), and we usually call ρ a state that is received and measured by a local detector, ρ ∈ S(H k ). The measurement devices are described in terms of general positive operator valued measures (POVMs) and we assume that outcomes in a sequence of measurement rounds are independent and identically distributed (i.i.d.). When one of the parties has only partial information about a measurement device, she will possess a more coarse-grained POVM description. We avoid the use of coarse-grained descriptions, as these open the side to attacks, see Section 5.

Inputs and outputs:
Each party has full control over the setting x ∈ X which can be chosen, e.g., by turning a knob or via digital control. For each measurement, there is a set of possible outcomes a ∈ A. In the following, we will be mainly interested in the case where both the set of inputs and of outputs are finite 3 . For instance, in the standard Clauser-Horne-Shimony-Holt (CHSH) inequality [3,4] the set of inputs is X = {0, 1} and the possible outcomes are A = {+1, −1}, for party A's device and similarly for party B's device. We suppose that along the set of "good" outcomes, labelled by an index a ∈ A, there is a special label ø for the "no-click" event (i.e., a failed detection in correspondence of a trigger signal) so that the entire alphabet of outcomes becomes A := { ø } ∪ A.
Fair sampling for multiple parties: In the following presentation we will often restrict our attention to a single measurement device and to a local Hilbert space (so we can take, e.g., H ≡ H A ). In fact, fair sampling is an assumption on a single apparatus, i.e., can be considered outside of the context of Bell inequalities. For a Bell test involving N measurement devices, we can say that the setup satisfies fair sampling when each of the N devices, considered individually, satisfies the assumption. However, one obtains a completely equivalent mathematical formulation by considering the N devices as a single collective measurement device split across N locations, and then requiring that this global multipartite device satisfies fair sampling. Hence, all the considerations made for a single device will hold also for the global setup, provided that the fair sampling assumption holds for each device.

Quantum model of a lossy detector
We now provide a description of a measurement device having non-unit efficiency. We show in particular that such a measurement can be seen as the combination of a filter and an ideal unitefficiency measurement. We then link this description to the efficiency of the device.

POVM elements
We describe the measurement device M as a set of POVM elements {M a := x∈X |x x| ⊗ M x a } "taking" both x and ρ and returning the outcome a with a certain probability Pr M (a | x, ρ): H X is a Hilbert space with an orthonormal basis {|x } x∈X and D(A ) is the set of probability distributions on A . For each a ∈ A , the channel M x a ( · ) := Tr(M x a · ) is a real-valued completelypositive (CP) map [36] satisfying a∈A Tr(M x a ρ) = 1 for all density operators ρ. We introduce two flags f = and f = ø associated to two complementary operators M x and M x ø which satisfy As we will show later, a description of the operators M x (or equivalently of M x ø ) is all that is required to know if a device satisfies fair sampling, while he full POVM description M x a is not necessary to this end.

Filters
We can now introduce the notion of filtering: for any lossy device M, one can always find a corresponding pair of completely-positive trace-preserving (CPTP) maps Here, H f = span(| ø , | ), F represents the filter operation, andM a lossless measurement device. Notice that for mathematical consistency of the equation M =M•F the set of outputs ofM must be equal to the set of outputs of M and thus also include a "no-click" outcome. We therefore considerM to be lossless if a flag ø has the only effect of "disabling"M, i.e.,M outputs ø if and only if the filter F has already produced a ø flag. We remark that the factorization M =M•F is not unique, since we have freedom in redefining F andM. For instance, we can consider any invertible linear operator A such thatM :=M•A −1 and F := A • F are both CPTP maps and obtain M =M • F =M • F . Observe that completepositivity is surely preserved if A is a unitary channel, thus the decomposition M =M • F is certainly not unique.
Given a measurement device M with POVM elements {M a }, one can construct a decomposition M =M • F as follows 4 . We have M := a∈A M a , so that M + M ø = 1. Then, we define the filter F as a CPTP map having Kraus operators [36]: which satisfy the completeness relation F † F + F † ø F ø = 1. Correspondingly,M is defined as the measurement device acting on the output of F (including the flag) and having POVM elements: where the inverse square roots are defined on the support of the operators 5 . One can immediately verify that a∈AM a = | | ⊗ Π , where Π is the projector on the support of M . This means thatM has unit efficiency when it receives f = and a state ρ in the support of M .
From these definition, we can immediately show that M =M • F ensues. In fact, using the shorthand ξ := |x x| ⊗ ρ, we have: 4 We have in this case Ma = x∈X |x x| ⊗ M x a , but the construction of the decomposition M =M • F does not rely on this property. 5 I.e., an Hermitian operator M = j p j |ψ j ψ j |, with p j ≥ 0, is mapped to (M ) −1/2 = j f (p j ) |ψ j ψ j |, with f (p) = 1/ √ p if p > 0 and f (0) = 0. and thus, using the cyclicity of the trace: for all a ∈ A. Consequently, we also have PrM •F ( ø | ξ) = Pr M ( ø | ξ).

Efficiency
The operator M x allows to compute the efficiency E of the device. The efficiency is, per definition, the probability of obtaining a good outcome (f = ) when using a setting x and an input quantum state ρ: The last equality shows that the efficiency E(x, ρ) can be computed from just the specification of the filter, rather than requiring the full POVM description of M. Moreover, the efficiency of the detector is a physical property which can be assessed experimentally, provided access to a reliable source of quantum states ρ ∈ S(H). Hence, the efficiency does not depend upon the specific decomposition M =M • F =M • F . The efficiency of the detector allows one to compute the post-selected outcome probabilities where a ∈ A are "good" outcomes, so that a∈A Pr p.s. (a|x, ρ) = 1.

The fair sampling assumption
The fair sampling assumption is a restriction on the physical models of lossy detectors. We introduce a definition which is equivalent to the one introduced by Berry et. al. [1]. We then discuss the consequences and the applications of this definition.
where the function ∧ (logical AND) acts only on the flags and it means that the filter F returns if and only if both F C and F Q return .
A few remarks are now in order. First and foremost, the main reason for using this definition stems from Proposition 2. There, we show the following strong result: if the factorization of Eq. (11) holds, for a given (real) quantum experiment involving lossy detectors and post-selection, there is another (ideal) quantum experiment that involves lossless detectors (and possibly a different quantum state) that exactly reproduces the post-selected statistics of the real experiment. In other words, the post-selected statistics are physical.
Second, in Definition 1 we have a decomposition of a filter in two sub-filters. In more general scenarios involving N devices and 2N sub-filters, we assume that a successful round of the experiment is obtained only when all filters return f = . In fact, in most quantum experiments a single detection failure is sufficient to invalidate the current observation round 6 .
Third, although it is not possible to verify if a measurement device satisfies fair sampling in a device-independent way, fair sampling does impose restrictions on the outcome probabilities. If these conditions are violated, the experimenter can directly conclude that fair sampling does not hold. See Appendix A for details.
Last, the classical filter is a stochastic map which, given an input |x x| can generate a probabilistic mixture of settings, i.e., the "real" setting is x Pr(x |x) |x x |. As a physical example, the experimenter may electronically set a rotation angle θ 0 of a polariser, but the polariser actually rotates by an angle θ = θ 0 + δθ (with δθ small and stochastic) [37]. However, without loss of generality, we may assume that F C does not change the setting x, i.e. it only assigns different success probabilities to different settings. In fact, we can simultaneously re-defineM and F C so that the definition of the physical device M remains unchanged while the classical filter takes the form F C, (|x x|) = Pr( | x) |x x|, as we show in Appendix B. 2. The efficiency of the device factorizes as: for some real-valued functions E C and E Q . This is the definition that was given in Ref. [1].

The POVM element M , associated to the set of good outcomes of M, factorizes as in
where M C, acts on the classical setting and M Q, acts on the quantum input. Moreover, Proof. Eq. (11) immediately implies Eq. (12), since: To show that Eq. (12) implies Eq. (13), we use the fact that the efficiency E : S(H X ⊗H) → [0, 1] is a CP linear map, hence E C and E Q are also linear maps (over probabilistic mixtures of inputs) and we can assume, without loss of generality, that both maps take values in [0, 1]. Since any CP linear map E taking value in [0, 1] can be written as E( · ) = Tr(M · ), for some matrix satisfying 0 M 1, we have: for some matrices M C, and M Q, . Hence, defining M : Finally, to show that Eq. (13) implies Eq. (11), we construct filters F C and F Q as in Eq. (5), that is, via the Kraus operators: We then set F(|x x| ⊗ ρ) := ∧ [ F C (|x x|) ⊗ F Q (ρ) ], and defining the POVM elements of a lossless deviceM as in Section 2.2 allows one to show that M =M • F holds. We now provide a result that motivates using the factorization in Eq. (11) as definition of fair sampling. The formalism of filters turns out to be very handy: the essence of the proof Proposition 2 is illustrated in Figure 2.

Proposition 2 (Probabilities achievable under fair sampling). Consider any (real) experiment involving a source that produces an
restricting to the settings x such that Pr− → M ( | x, Ψ) = 0 8 . Moreover, the state Ψ can be obtained probabilistically from Ψ via probabilistic local operations.
Proof. We decompose each measurement device M k , acting on the k-th subsystem, as a filter followed by a lossless measurement, M k =M k • F k . Moreover, each filter F k factorizes as: and each sub-filter can herald either a success or a failure: We then define the normalized quantum state: where E Q (Ψ) = Tr k F k,Q, (Ψ) is the probability that all the filters F k,Q return , and we assume E Q (Ψ) > 0. The physical interpretation of Ψ is as follows: apply to the N sub-systems of Ψ the filters F k,Q and post-select on all of them returning at the same time. That is to say, it is possible to perform a heralded preparation of Ψ .
Analogously, we can define lossless measurement devices M k for each party k through the Here (M k ) a are the POVM elements associated toM k as, e.g., in Eq. (6), and we assume > 0 for all parties 9 . We also remark that, as shown in Appendix B, we can assume without loss of generality that the filters do not change the setting, As the final step of the proof, we have to compute the probability of obtaining a collection of outcomes a given inputs x when measuring the state Ψ with the devices − → M , and verify that Eq. (17) is satisfied. This is a simple formal manipulation, which is given in Appendix C.
Proposition 2 is very powerful and general: it ensures that the post-selected statistics obtained using lossy devices is equal to the data one could collect with ideal lossless devices measuring the filtered state Ψ . This has several interesting consequences.
For example, in a scenario where the post-selected data violates a Bell inequality [3,4], we can conclude under the fair sampling assumption that the state Ψ is Bell-correlated [38]. This implies in particular that Ψ itself contains hidden nonlocality [39]. Additional information about the state Ψ can also be obtained from existing device-independent tools: if the Bell violation is high enough, the post-selected data can be used in the framework of self-testing [18,19], to certify directly the exact structure of Ψ or as a step aiming to certify quantum operations including quantum gates [24] or entangling measurements [40,41,42].
We remark, furthermore, that Proposition 2 can be generalized to cases in which some devices are fully characterized, while others are not. In such cases, one needs to appeal to fair sampling only for the not-fully-characterized devices. For instance, in quantum steering a trusted and an untrusted quantum device jointly measure an entangled quantum state Ψ [43]: here, we need to apply fair sampling only to the (single) untrusted device.
Finally, we note that if Ψ is a separable quantum state, then Ψ is also separable since it can be obtained from Ψ through local probabilistic operations. Consequently, a separable quantum state cannot violate any Bell inequality when using lossy detectors and post-selection, if fair sampling holds. Similarly, under fair sampling it is impossible to violate the quantum bound of a Bell operator with post-selected statistics: in fact, the models and experiments showing that postselection can lead to incorrect conclusions [5,6,7,8,9,10,11,12] do not satisfy fair sampling.

The strong and homogeneous fair sampling assumptions
Now we consider two special cases of fair sampling, which we call strong and homogeneous fair sampling. Incidentally, strong homogeneous fair sampling is what, by and large, is implicitly assumed as the standard definition of fair sampling [1,28,29].
Definition 2 (Strong fair sampling). Consider a measurement device M that satisfies fair sampling, as in Definition 1. The sub-filters F Q and F C herald either a failure or a success, hence they can be written as: We say that M satisfies strong fair sampling if there exists a decomposition M =M • F such that the sub-filter F Q, is proportional to the identity channel: F Q, = P Q, Id, where P Q, > 0 is the success probability. Moreover, if it is possible to write F C, = P C, Id for some success probability P C, > 0, we say that M satisfies homogeneous fair sampling.
The notion of homogeneous fair sampling is introduced in analogy with the notion of strong fair sampling and it means that the detection probability is independent of x. However, not much is to be gained from the homogeneity property. This is because the classical input x is under full control of the experimenter, therefore it is possible to directly estimate the efficiency E C (x) from the experimental data (assuming that fair sampling holds) and one can compensate any inhomogeneity in the efficiency. However, in quantum experiments it often happens that devices that (approximately) satisfy fair sampling naturally also possess the homogeneity property. This is the case, e.g., for the polarization analyser, a measurement device that we examine in Section 6.
In contrast, strong fair sampling does give more stringent guarantees on the experiment. In fact, the state Ψ which reproduces the post-selected statistics is obtained from the state Ψ after the application of the filters F k,Q . But if these filters are all proportional to the identity channel, this implies Ψ = Ψ. That is, under the strong fair sampling assumption, the post-selected statistics is a fair representation of the statistics that would be obtained with unit-efficiency detectors.
More in detail, consider again a N -local quantum experiment involving N detectors each acting on a part of an entangled quantum state Ψ. If all detectors − → M = (M 1 , M 2 , . . . , M N ) satisfy strong fair sampling, then we have that the post-selected probabilities are equal to those that one can obtain acting on the actual experimental state Ψ with some lossless devices − → M : Consequently, if strong fair sampling holds, any claim on Ψ based on the post-selected probabilities will be as good as if the data was produced by lossless devices. That is, the conclusions about non-locality, device-independent entanglement, self-testing, and so on, will hold even if they are based on post-selected data. However, this strong notion of fair sampling comes at a cost: the conditions specified in Definition 2 are very stringent and rarely met in actual quantum experiments. We therefore recommend the usage of weak fair sampling as the default definition to be used in experimental settings. The notion of weak fair sampling is more widely applicable and, as argued in Section 3, it still allows to obtain sharp conclusions based on the post-selected statistics.
Finally, we specialize Proposition 1 to the case of strong fair sampling. Proof. It is an immediate consequence of specializing the proof of Proposition 1 to the cases in which F Q is proportional to the identity map.

Fair sampling in cryptographic scenarios
Under fair sampling, the post-selected measurement results of a Bell test can also be used for cryptographic tasks, e.g., for random number generation or quantum key distribution [21,26,27]. The fair sampling assumption has to be added to the standard no-leakage assumption (i.e., no information about the actual measurement is leaked to the adversary) as required also for fully device-independent quantum cryptography [44]. Moreover, device-independent certifications can be used as subroutines in more complex cryptograhic protocols. If a certification is performed employing the fair sampling assumption, then the larger cryptographic protocol will be secure provided that such certification is securely composable [45] and, naturally, provided that the fair sampling assumption is valid to begin with. It is important to note that different parties can have disparate POVM descriptions of the same measurement device, reflecting the degree of knowledge that each party has; in particular, an attacker might have access to some hidden information about the internal functioning of the devices. This also means that parties having different POVM descriptions of one and the same detector might disagree on whether it satisfies fair sampling. We argue that protocols involving lossy devices and post-selection are secure if fair sampling holds unconditionally, and in particular also according to the POVM description possessed by the adversary.

Explicit attack model
We consider the so-called Makarov attack [46] as an example where fair sampling appears to hold to the honest parties, but is violated according to the fuller description possessed by the adversary. A detector having settings X = {0, 1} and outputs A = { ø , +, −} purportedly performs the following lossy measurement: with |± := (|0 ± |1 )/ √ 2 and thus the no-click events are M 0 ø = M 1 ø = 3 4 1. These measurements are the ones canonically used in CHSH-Bell tests, apart from having efficiency 1/4, and they seem to satisfy (strong and homogeneous) fair sampling. However, the device is maliciously designed by the adversary: in actuality, it draws uniformly a random variable r ∈ {1, 2, 3, 4}, which is unknown to the user, and performs a different measurement depending on r. Specifically: so that tracing out the value of r results in the POVM of Eq. (24). In a cryptographic protocol, the parties must communicate when the detection has succeeded (over a classical authenticated channel). However, this piece of information, together with the knowledge of r 10 , allows the adversary to infer the setting x and the outcome a for each successful detection, completely compromising the security. We emphasize that, in this example, from the point of view of the adversary the POVMs describing the detector have the elements which act on the the quantum input of the detector but also on the random variable r which is chosen uniformly at random by the attacker. Manifestly, the POVMs above violate the fair sampling assumption, which corrupts the security guarantees. However, if the variable r is held by the environment (as a physical realization of the loss channel) and can not be accessed by the adversary, her POVM description of the detector is no better than the one of Eq. (24). Moreover, with two detectors that implement Makarov's attack, it is possible to fake the violation of the CHSH inequality using only separable states, and even saturate the algebraic bound of the operator [7]. That is, calling x, y ∈ {0, 1} the two inputs and a, b ∈ {+, −} the post-selected outputs, these always satisfy a b = (−1) x y . This can be realized by sending to the two detectors a state ρ r A ,r B which explicitly depends on the hidden parameters r A and r B of the first and second device. A possible choice for ρ r A ,r B is given in the following table:  (27) where [p, q] is a shorthand for the separable state |p p| ⊗ |q q|, while "vac" denotes the vacuum state which, naturally, does not trigger the detector; taking into account the detector efficiencies and the vacuum component, the overall detection probability is 1/32 = 1/4 × 1/4 × 1/2. Of course, surpassing the quantum bound of the CHSH operator would reveal that something suspicious is happening. But by adding some white noise in the input states, the expectation value of the CHSH operator can be brought in the region between the classical and quantum limit.
In conclusion, we have to impose that the provided POVM description represents the "true" behaviour of the measurement device and that therefore we can be confident that fair sampling holds also according to the adversary's description of the device. In this way, Proposition 2 can be immediately applied to prove security against this adversary, to whom the post-selected statistics are as good as if it were produced by an ideal device. It may seem rather artificial to impose fair sampling in this form, but we argue that there are cryptographic scenarios where this assumption might be plausible. For example, imagine that a trusted company manufactures and sells lossy measurement devices that are guaranteed to work properly, but no information about the internal functioning is provided to the end-users (e.g., as a way to preserve industrial secrets) so that they can only model the device as a black box. A third-party attacker might be able to study a copy of the device, reverse-engineer its functioning, obtain a full POVM description, and discover that fair sampling holds indeed. This would be a setting were Proposition 2 can be put to use and security guarantees recovered, without further assumptions on the structure or calibration of the measurements.

Extending to non i.i.d. settings
In this Section we briefly discuss what happens when we do not assume that the measurement statistics are independent and identically distributed (i.i.d.), as done in the rest of the paper. Under no-leakage, the most general attack strategy is obtained when the device internally stores all the quantum states that have been received (and measured) in the past, so that the measurement outcome in a certain round can depend on all the states (and measurement results) at previous rounds. Consequently, the device acts on a Hilbert space whose dimension increases in time and it has a different POVM description at every round. This enables very sophisticated and convoluted attack strategies that are very far from the contexts where fair sampling is a reasonable assumption. Nonetheless, considering fair sampling in non i.i.d. settings may be necessary when the measurement devices are not stable in time, e.g. as consequence of thermal drift.
Consider now running a Bell experiment where the state preparation and the measurements are repeated for T rounds, in order to collect statistics, and remove the i.i.d. assumption, i.e., the devices may behave differently in each of the T rounds (and thus the outcomes are not identically distributed) and there may be memory effect (so that the outcomes are not independent). Are the results of Proposition 2 applicable in these cases?
We remark that the fair sampling assumption can be extended to the non i.i.d. case in different ways. To keep the analysis simple, here we propose a redefinition of fair sampling which allows to extend the results of Proposition 2 in a straightforward manner. More general definitions of fair sampling may still be viable, but they would require a more careful analysis. We say that M (T ) satisfies fair sampling if and only if each filter F t acts only on ρ t and x t (i.e., it acts as the identity channel on the internal memory of the device) and moreover F t factorizes as F t = ∧[F t,C ⊗ F t,Q ], as in Eq. (11).
Similarly as done in Proposition 2, we now consider a Bell experiment involving N physically separated non-communicating devices, used for T consecutive rounds, which collectively measure a global quantum state Ψ having N × T subsystems. A round t of the experiment is successful if and only if all the N devices outputs a flag simultaneously; we then collect the sequence of successes/failures in a list f = {f 1 , . . . , f T } with f t ∈ { ø , } for each t. Notice that the probability that all rounds are successful is exponentially small in T and will essentially never occur when T is large, as is required for having a significant statistical sample. Thus, we suppose that only T rounds are successful (with T ≤ T ) and introduce a filtered state Ψ f which is obtained by applying all the N × T local filters corresponding to the successful rounds and tracing out the systems involved in unsuccessful rounds.
Following the line of reasoning given in Proposition 2 we can now see that the post-selected measurement statistics of the real experiment is exactly reproduced by the measurement statistics of an ideal experiment where a filtered state Ψ f is measured by lossless devices 11 . Therefore, in this non i.i.d. version of fair sampling we are able to certify in a device-independent way the properties of a quantum state Ψ f that could have been obtained with local probabilistic operations from the state that was present in the lab. Hence, the security proofs that have been developed for certifiable random number generation [26,27,47,48,49] and device-independent quantum key distribution [21,50,51,52] immediately extend to these devices that satisfy the non i.i.d. version of fair sampling.

Fair sampling in quantum optics experiments
In this Section we provide a concrete example of a measurement apparatus commonly used in quantum optics, with the intent of showing a possible real-world application of our formalism and also to better understand the conditions that are required to satisfy weak and strong fair sampling, illuminating also how to deal with the case where losses are present prior to the measurement. Specifically, we consider a polarization analyser, a device which allows measuring the polarization of incoming photons in arbitrary directions [53,54] and the classical setting is the measurement angle (x ≡ θ). The layout of the apparatus is schematically depicted in Figure 3.

Description of a polarization analyser
We assume that the photons entering the apparatus are described by bosonic operators b † H and b † V for the horizontal and vertical polarization, respectively. These operators satisfy canonical commutation relations A polarizing beam-splitter (PBS) is followed by two non-photon-number-resolving (NPNR) detectors D 1 and D 2 having POVM elements Here, η 1 = 1 − R 1 and η 2 = 1 − R 2 are the efficiencies of detectors D 1 and D 2 . Note also that If we assume, for the moment being, that the two detectors have equal efficiency η 1 = η 2 = η = 1 − R, the four POVM elements of the polarization analyser are: Here, the tensor product represents the bipartition across detectors D 1 and D 2 . In the first line we have used [N θ ,N θ ⊥ ] = 0 and introducedN =N θ +N θ ⊥ .

Fair sampling with polarization analysers
We now show that the polarization analyser previously described (with detectors having equal efficiencies η and no dark counts) satisfies the fair sampling assumption. We consider the general case where an arbitrary number of photons can enter the apparatus and, in particular, the input state ρ may have a zero-photon (i.e. vacuum) component. Notice that no-click events are caused by two distinct physical processes: either the photons are lost before reaching the apparatus, or some photons reached it, but were not detected. Distinguishing between these two processes is not always possible but also, especially in a device-independent context, not necessary. When dealing with states having a vacuum component, no-clicks would thus occur even while using lossless detectors. Consequently, the ideal experiment reproducing the post-selected data (where no ø are present) both requires a lossless detector and a filtered state, in which the vacuum component has been discarded.
The relevant Hilbert space is the Fock space consisting of photons that are only distinguishable in their polarization degree of freedom: where n θ and n θ ⊥ are the number of photons polarized in direction θ and in the orthogonal direction θ ⊥ , respectively. In this Hilbert space, the POVM elements of the polarization analyser are given by 12 where Π n is the (θ-invariant) projector onto the n-photon sector of the Fock space. The expression on the right hand side of Eq. (33) is invariant under change of rotation angle θ: hence, we are in a (homogeneous) fair sampling situation. We also remark that M θ has no overlap with the vacuum, vac| M θ |vac = 0, which immediately implies that the filtered state also does not have overlap with the vacuum. As a special case, notice that when η = 1 (the detector are lossless) we have M θ = 1 − |vac vac| and therefore post-selecting is equivalent to using a filtered state where the vacuum component has been projected out.

Strong fair sampling with polarization analysers
We now look under which conditions the strong version of fair sampling holds. From Eq. (33) it follows that strong fair sampling is formally verified whenever we restrict the Hilbert space to the k-photon sector (for any fixed integer k > 0). However, we consider only the case k = 1, which already corresponds to a very stringent experimental requirement. That is, we imagine that in each round of the experiment exactly one photon enters the detector. Thus we have: with θ and θ ⊥ any two orthogonal polarization directions. This yields: The expression on the right hand side of Eq. (36) is manifestly independent of θ and is proportional to the identity: the (homogeneous) strong fair sampling assumption holds in this case.

Experimental applicability
As discussed, the polarization analyser satisfies strong fair sampling only when the input quantum state consists of exactly one photon. This is a very demanding condition that is not met in any experiment that we know of, as currently there is no technology capable of producing individual photons with high fidelity and (almost) unit efficiency [55,56]. To this end, the best we can achieve is through the heralded preparation of a photon, e.g., by first producing a photon pair and exploit the fact that one of the two photons has triggered a detector to infer the presence of the second one in a separated optical path. Even in this case, though, the applicability of strong fair sampling is debatable, since losses are always present in practice. To this end, we show in Section 9 how to extend the results to input states that can only be approximated as a single-photon states. When the input quantum is not restricted to the single-photon sector, we have shown that the polarization analyser satisfies (weak) fair sampling. This happens, e.g., when the state has a (significant) overlap with the vacuum. However, since the polarization analyser can click only when one or more photons are present in the apparatus, the filtered state does not have overlap with the vacuum.
We could then consider sources that (up to an excellent degree of accuracy) emit at most one photon at a time. In these cases, the filtered state will have exactly one photon entering the polarization analyser. We could also consider sources that could emit multiple photons at a time, as is the case in spontaneous up-and down-conversion processes in non-linear crystals. In these cases, the filtered quantum state does not contain the vacuum, but it does contain multiphoton components. Noticing that the more photons enter the device, the higher is the probability of a detection we deduce that, correspondingly, the filtered state ρ has more weight on large photon-number components, compared to the experimental state ρ.
Finally, we can give a concrete recommendation for proof-of-principle demonstrations of deviceindependent protocols relying on post-selected data. The measurement device should be extensively tested and calibrated. Subsequently, one should publish the best available estimation of the efficiency of the device (the POVM elements M θ ), together with the uncertainty to which they are known. From an abstract perspective, this is less information than having the individual POVM description of M θ 1 , M θ 1 , and M θ 1&2 , which would be required in device-specific protocols (such as, say, the BB84 protocol). Moreover, in some cases the estimation of M x might be experimentally easier than the estimation of all M x a elements, for instance when the number of possible outcomes (the size of the set A) is large. Provided that the fair sampling condition is satisfied, this approach provides the means to demonstrate the fundamental elements of device-independent protocols with post-selected data, avoiding the stringent requirement of having a extremely high detector efficiency.

Approximate fair sampling
Here we investigate what happens when the fair sampling assumption is not satisfied exactly. Intuitively, we expect that the probability distributions that can be obtained after post-selection are close to those that can be obtained measuring the filtered state ρ with a lossless device. And indeed, a small deviation from the exact fair sampling condition induces a small perturbation in the post-selected probability distribution (with linear dependence, to the leading order). In turn, the fact that the post-selected probabilities are close to the ideal ones implies, e.g., that the experimental expectation values of Bell operators are also close to the ideal value.

Bound on the total variation distance
As a starting point, we recall that M C, is diagonal, hence we have M = x E C (x) |x x| ⊗ M Q, or, equivalently, M x = E C (x)M Q, . We can rewrite this as: where Π is the projector onto the support of M Q, (and on the support of M −1/2 Q, as well) and thus we have Here and in the following, the norms are operator norms. We then consider small deviations from fair sampling as expressed in Eq. (37).
where Π is the projector on the support of M Q, . We also assume Π M x Π = M x for all x ∈ X and Π ρ Π = 0 for the experimentally relevant input states.
Then, there exists a normalized quantum state ρ , which can be probabilistically filtered from ρ, and there exists a lossless deviceM such that: When the measurement device M satisfies inequality (39) we say that the -approximate (weak) fair sampling assumption holds.
Proof. See Appendix D.
A few remarks are in order. First, in the limit → 0 approximate fair sampling becomes the condition for (exact) fair sampling. Second, the left hand side of inequality (40) is the total variation distance between the post-selected probability distribution Pr p.s. M (a|x, ρ) and the distribution PrM(a|x, ρ ) obtained by measuring the filtered state ρ with a lossless detector 13 . Finally, we can specialize the Proposition to approximate strong fair sampling by consider the special condition M Q, = 1. In this case, Eq. (39) simply becomes: and the filtered state is equal to the experimental state, ρ = ρ.

Approximate fair sampling in multipartite settings
Proposition 4 links an inequality regarding the POVM of a measurement device to an inequality on the probability distributions that can be observed using such a device. In a multipartite quantum experiment this probability distribution corresponds to the marginal distribution that is observed by a single detector, ignoring the measurement outcomes of all other devices involved in the experiment. Therefore, Proposition 4 does not (directly) bound the deviation for the global distribution over all possible outcome configurations of the devices. However, this shortcoming can be easily amended, using the following simple idea. Consider a quantum experiment where N parties are involved, measuring a multipartite state Ψ with lossy devices M 1 , . . . , M N which approximately satisfy fair sampling. Then, we can equivalently consider the multipartite measurement device − → M consisting of the collection of these N devices, whose settings (and outputs) consists in the collection of settings (and outputs) of the individual devices. It is straightforward to verify that this joint device then satisfies tot -approximate fair sampling; the total approximation error tot is essentially given by the sum of the approximation errors for the individual devices. Therefore, for this multipartite device Proposition 4 directly applies. That is, it is possible to bound to the deviation of the post-selected probability distribution from the result of measuring a filtered state Ψ with N lossless devices. More details can be found in Appendix E. As a further consequence, suppose we want to measure the expectation value of a N -partite Bell operator B. Using the (slightly skewed) post-selected distribution the relative error on B is upper bounded by 2 tot -for the proof, see Appendix F.
Finally, we remark that if the N separated devices satisfy approximate strong fair sampling, then the entire multipartite setting also satisfies approximate strong fair sampling; this implies that the outcome statistics for the collection of devices is close (in total variation distance) to what could be obtained measuring the actual experimental state Ψ with lossless devices. In this case, the global approximation error tot for the multipartite device is also roughly equal the sum of the errors for individual devices.

Approximate fair sampling in quantum optics
In Section 6 we have shown that a polarization analyser satisfies fair sampling provided that the two NPNR detectors have equal efficiency η. Now, we will consider the case where the efficiencies of the NPNR detectors are very similar, but not exactly equal. In this case, we show that the polarization analyser satisfies approximate fair sampling; moreover, if the input state contains exactly one photon, approximate strong fair sampling holds.

Polarization analyser with unequal detectors
We generalize the quantum modelling of the polarization analyser given in Section 6 to the case in which the two detectors have similar (but not exactly equal) efficiencies, η 1 and η 2 . We assume without loss of generality η 2 ≥ η 1 and we write R = R 2 ≤ R 1 = R (1 + δ), with δ ≥ 0. This results in the following four POVM elements:

Approximate fair sampling with a polarization analyser
We now consider photonic states which have a (possibly large) component of vacuum and a certain probability of emitting more than one photon, as common in experiments that use up-or downconversion processes. The Hilbert space is The operator M θ has an explicit (small) dependence from the setting θ: We now have to find a suitable positive semi-definite operator M Q, and a projector Π in order to show that weak fair sampling is approximately satisfied. We choose: In Appendix G we show that, with these definition, the condition holds. Thus, we can directly apply the results on approximate weak fair sampling derived in Proposition 4. The maximum deviation in the post-selected probability and those obtainable from ρ is of order δ (1 − η)/η, in total variation distance. We can also characterize the filtered state ρ that allows to (approximately) reproduce the post-selected probabilities: In particular, the state ρ has no overlap with the vacuum.

Approximate strong fair sampling with a polarization analyser
In this Section, we restrict to cases where exactly one photon is entering the apparatus, i.e., we assume that we are employing an (almost) perfect single-photon source. The Hilbert space is and the POVM elements associated to a failed/successful detection are: The POVM element M θ has an explicit (small) dependence on θ. In fact, we can explicitly show that the condition for approximate strong fair sampling holds. Assuming δ ≥ 0, we obtain and then This result directly allows us to employ Proposition 4, specialized to the case of strong fair sampling. We can conclude that the post-selected statistics obtained with this device can have a deviation (in total variation distance) at most of order δ (1 − η)/η from the statistics obtained measuring the single-photon state with a lossless device.
As previously discussed, single photon sources are not achievable with current technology, heralded photon preparation being the method that comes the closest to this goal. Therefore, in the next Section we analyse what happens in the case in which the input state is only approximately a single-photon state and has a small vacuum and multi-photon component.

Assumptions on the input state
In this final Section, we consider the case in which the quantum state has a small component not belonging to the reference Hilbert space. We show that the outcome statistics is not overly affected by the presence of such perturbations. Next, we extend the fair sampling assumption to the case where the factorization of Eq. (11) holds only for the specific state Ψ that is employed in the (multipartite) quantum experiment. We call this the state-dependent fair sampling assumption.

Effects of imperfections in state preparation
Consider an imperfectly prepared quantum state having the form where ρ and ρ ⊥ are normalized quantum states and c, c † are the coherence terms. The Hilbert space H represents the set of states for which the measurement device has been calibrated, and H ⊥ is an orthogonal space containing all other degrees of freedom. The fair sampling assumption holds for states ρ ∈ S(H), while the behaviour of the measurement device for an input state ρ ⊥ ∈ S(H ⊥ ) can be arbitrary. As a concrete example, consider a photonic stateρ entering a polarization analyser. Strong fair sampling holds when the input consists of exactly one photon, but the experimental stateρ also possess a small component ρ ⊥ which overlaps with the vacuum and with multi-photon states. As a second example, a polarization analyser satisfies (weak) fair sampling whenρ consists of photons that are only distinguishable in polarization. That is, the photons must have the correct frequency, waveform, spatial mode, and so on, consistent with the specifications and calibration of the measurement device. However, the experimental stateρ may have a small component ρ ⊥ of photons that have different properties, for which the behaviour of the device is not known. If is small, the deviation in the post-selected statistics will also be small; quantitatively, we have the following result.

Proof. See Appendix H.
In general, the deviation in the post-selected statistics can be of order √ . However, if the state has no coherence terms (c = 0), then the deviation is only of order . Thermal light is an instance of this case, being completely incoherent in the photon-number basis.
We also remark that in the realistic case where both device calibration and state preparation are not perfect, the bounds given in Proposition 5 and in Proposition 4 can be combined. The deviation from the ideal case is at most the sum of the bounds given in Eq. (40) and in Eq. (54), as can be shown applying the triangle inequality.

State-dependent fair sampling
We suppose that the measurement device M 1 =M 1 • F 1 used by the first party of a Bell-like experiment does not satisfy fair sampling (not even approximately). We require, instead, that the application of the successful branch F 1, : where Id R is the identity channel on the rest of the parties, Ψ is a (normalized) quantum state that can be locally filtered from Ψ, and E 1,Q (Ψ) is proportional to the probability of successfully filtering the state Ψ 1, from Ψ. That is, there exists a CP map F 1,Q, such that: Then, the same results as in Proposition 2 apply in this case. Consider, in fact, the post-selection corresponding to first device clicking (we ignore the post-selection applied by the other parties for now). Then, the post-selected probabilities that one observes in the realized quantum experiment can be reproduced by an ideal experiment where the first device is lossless, defined as in Eq. (21), and the state that has been distributed to the N parties is the filtered state Ψ . We can then apply the same reasoning to each of the parties involved in the experiment. Suppose that all the measurement devices satisfy state-dependent fair sampling; then, the global post-selection (where the devices click contemporaneously) produces probabilities that are equal to those one would obtain when all parties use lossless devices, defined as in Eq. (21), acting on the normalized quantum state: where each F k,Q, is a local extraction map that depends on M k and on Ψ.
We can also consider approximate versions of state-dependent version fair sampling, taking into account detector and state preparation imperfections. The results previously derived for approximate fair sampling would also hold in this case.

Discussion
In this paper, we have analysed the effect of post-selection on the outcome statistics of a measurement apparatus in the context of Bell-like experiments. To this end, we have employed a general and fully quantum model of the measurement device, described in terms of POVM elements. We have identified a condition, equivalent to the one of Ref. [1], which allows the measurement statistics to exactly correspond to the statistics of some ideal quantum experiment, involving ideal lossless detectors and a filtered quantum state. The filtered state is (possibly) different from the actual experimental state but can be obtained from it through local probabilistic filters. In simple terms, this condition amount to the fact that the device acts independently on the classical and quantum inputs it receives, conditioned on having had a successful detection. Differently from what is done in most of the previous literature, it is this condition that we identify as the (weak) fair sampling assumption.
We argue that the weak notion of fair sampling is the most useful and applicable one, especially in the context of quantum optics. In fact, in quantum optics experiments the produced photonic states have a component of vacuum, but the common praxis is to characterize properties (such as fidelity, purity, or expectation values of observables) of a quantum state where the vacuum component has been projected out. This exactly corresponds to the filtering operation induced by fair sampling.
To make the result of this work applicable in real experimental settings, we have investigated the effect of small deviations from exact fair sampling. We have shown that imperfections in the calibration of the device result in a deviation in the post-selected probabilities that scales essentially linearly in the size of the miscalibration, but is amplified by a factor inversely proportional to the efficiency of the device. For a polarization analyser to satisfy fair sampling the two photon detectors are required to have the same efficiency, which could be enforced by artificially decreasing the efficiency of one of the detectors. Our analysis of approximate fair sampling takes care of any remaining efficiency mismatch. We have also considered the effect of imperfect state preparations, which lead the input state to have a small component not belong to the Hilbert space where the measurement device satisfies fair sampling. In this case, the presence of off-diagonal coherence terms in the density matrix can make the error in the statistics to scale (unfavourably) as the square root of the state preparation error.
We have also argued that the measurement devices can be securely used in cryptographic protocols, provided that they satisfy fair sampling. It is paramount in this case that fair sampling holds also from the perspective of the adversary. If, for instance, the adversary possesses a more complete description (a.k.a., a purification) of the measurement devices where fair sampling does not hold, explicit attack strategies can be exhibited.

Appendices A Necessary conditions for fair sampling
Fair sampling is formulated referring to ideal lossless devices, so it is not experimentally testable. However, fair sampling does imply restrictions in the correlations that can be observed, and these provide some consistency checks that the experimenter can perform using the classical outcomes alone. Note that fair sampling gives an independent set of equations from those obtained from the no-signalling condition.
The local quantum state that the one party measures in a multipartite experiment is where the indices imply that the state may depend on the measurement settings x R and outcomes a R obtained by the other parties, a phenomenon known as quantum steering. Fair sampling for the device of a given party requires that the efficiency factorizes in a component dependent on x and in a component dependent on ρ = Ψ x R a R , see Proposition 1. Hence: If impose the strong version of fair sampling, the dependence on ρ disappears, see Proposition 3. Hence we have: Obviously, these are not sufficient conditions to have fair sampling. Even when all devices have constant efficiency for all parties, E(x, x R , a R ) = const, the detection loophole is still open.

B Filter diagonal form
We consider a lossy measurement device M =M • F which satisfies fair sampling, F = F C ⊗ F Q , and we consider the successful branch F C, of F C , which is a (non normalized) probabilistic map. Here, we show that we can use the freedom in defining the filters to bring F C, to a diagonal form T C, which does not change x.
The general form of the probabilistic filter F C, is: where Pr(x |x) are sub-normalized probabilities, i.e., Pr( | x) = x ∈X Pr(x | x) ≤ 1. We define a new filter T C, and a new deviceW (with POVM elementsW x a ) as: We then haveM 14 : and one can immediately verify that the deviceW has unit efficiency:

C Complementary computations for Proposition 2
In the following computation we plug the state Ψ of Eq. (20) into the measurement devices M k defined in Eq. (21), and verify that Eq. (17) holds.
In line (67), we have introduced F C, := k F k,C, and F C, := k F k,C, . In line (68), we defined F := F C, ⊗ F Q, . In line (69), we have used the property that each deviceM k returns a valid outcome a k only when the filter F k returns . Finally, in line (70) and (71) we have used We can then defineM x a as:M where {∆ x a } is an arbitrary set of positive semi-definite operators that satisfy a∈A ∆ x a = ∆ x for all x. Explicitly, we may choose ∆ x a = ∆ x /|A|, where |A| is the size of A, so that we have: and one can immediately verify thatM x a 0 and a∈AM x a = Π . With all the definitions in place, we proceed to verify inequality (40). First, notice that: where we have used Π M x a Π = M x a and Π = M . Then we have: In line (82), we used (

E Approximate fair sampling in multipartite settings
Suppose that in an N -local quantum experiment each party holds a measurement device M k with POVM elements M x k k, which approximately satisfies fair sampling, as in Eq. (39). With the same conventions as in Appendix D, we introduce: so that the approximate fair sampling condition is expressed as ||∆ x k k || ≤ k , for some small k . Equivalently, we can write: We define also the following operators for a setting x := (x 1 , . . . , x N ): We can finally define an operator ∆ x which expresses how much the collection of N measurement devices deviates from the fair sampling assumption: From this follows the bound: which is the approximate strong fair sampling condition given in Eq. (39), where the approximation error is tot . Assuming that all the k are small we have: This means that Proposition 4 can be directly applied to a multipartite setting, and the error is upper bounded by tot , which is roughly equal to the sum of the deviations from exact fair sampling for each one of the individual measurement devices.

F Approximate fair sampling for Bell operators
Consider N spatially separated and non-communicating measurement devices that are used to measure the expectation value of a Bell operator B. This expectation value is entirely determined by the outcome probabilities of the measurement devices and for linear Bell inequalities it can be written as: for some coefficients c x a ∈ R. Two sets of probability distributions are of interest in our case: the post-selected probability distributions Pr p.s. obtained by the device "in the lab", where we consider a "good outcome" one where all the N detectors click in a given experimental round; and the probability distributions Pr ideal that would be obtained with lossless devices. The devices satisfy an approximate fair sampling condition.
We want to bound the quantity where β max is the algebraic bound for the Bell operator B, and is introduced here to compensate for arbitrary rescaling of the coefficients c x a . The algebraic bound is defined as: where the maximum is over the set of probability distributions Pr( a| x). We also suppose that the total variation distance between Pr p.s. (·| x) and Pr ideal (·| x) is bounded by tot for all collections of settings x: Then we have for all x: where q 1 (·| x) and q 2 (·| x) are probability distributions having disjoint support (i.e., q 1 (·| x) = 0 if q 2 (·| x) = 0 and vice-versa) and µ x ∈ [0, tot ] is a re-scaling constant. We can then compute: In line (102) we have used the triangle inequality and in line (103) the definition of β max .

G Computation for approximate fair sampling with a polarization analyser
We want to show that the POVM M θ defined in Eq. Then we can calculate Maximizing over all n-photon subspaces (with n = 0) one obtains the value of the operator norm. But the maximum is always attained for n = 1, since: This finally results in: Proof. We writeρ as a convex mixture of pure states,ρ = i p i |ψ i ψ i |, and define We then have Using the triangle and Cauchy-Schwarz inequalities, we obtain the required result: Now, we prove the following inequality: