Measuring magic on a quantum processor

Magic states are the resource that allows quantum computers to attain an advantage over classical computers. This resource consists in the deviation from a property called stabilizerness which in turn implies that stabilizer circuits can be efficiently simulated on a classical computer. Without magic, no quantum computer can do anything that a classical computer cannot do. Given the importance of magic for quantum computation, it would be useful to have a method for measuring the amount of magic in a quantum state. In this work, we propose and experimentally demonstrate a protocol for measuring magic based on randomized measurements. Our experiments are carried out on two IBM Quantum Falcon processors. This protocol can provide a characterization of the effectiveness of a quantum hardware in producing states that cannot be effectively simulated on a classical computer. We show how from these measurements one can construct realistic noise models affecting the hardware.


INTRODUCTION
In the era of Noisy Intermediate Scale Quantum Computers (NISQs) [1] it is of paramount importance to be able to characterize the proposed quantum hardware in order to check how good these machines are in performing quantum computation with the purpose of attaining an advantage over classical computers. This paper shows how to perform accurate and robust measurements of the stabilizer Rényi entropy, which in turn is known to quantify the resource known as 'magic' [2] It is well known that the preparation of stabilizer states, the implementation of Clifford gates and measurements in the computational basis can be made fault tolerant [3][4][5][6][7][8][9]. However, computers based on the Clifford resources can be efficiently simulated on classical computers [10][11][12][13], similarly to what happens for matchgate circuits(MGCs). This means that the power of quantum advance requires resources beyond the Clifford group, like the Phase π/8 gate (T gate) or the Toffoli gate and non-Gaussian states for the MCGs [14,15]. The precious resource that makes quantum computers special is colloquially dubbed as 'magic' and a resource theory of magic has been developed in recent years [2][3][4][16][17][18][19][20][21][22][23][24][25][26][27].
It is a striking fact that these resources are difficult to implement [3,5,[28][29][30][31][32][33]. The very reason why these resources are powerful makes them fragile. Moreover, the amount of these resources that needs to be used in a computation must be calibrated accurately: just like entanglement [34], too much magic is not useful for quantum computation (see Supplementary Note 1), see also [21]. Moreover, decoherence is not magic preserving, and it can both increase or decrease the amount of magic in a system, as we will show in the experiments. To the extent that decoherence is spoiling quantum computation, then one needs the amount of magic created and manipulated throughout the computation to be accurate: in this paper, we prove that an excess amount of unwanted magic makes the task of distinguishing the state ψ from a random state an exponentially difficult task, see Supplementary Note 1 for the proof. Moreover, since inaccurate Clifford gates can produce magic, the presence of excess magic is in fact a signal of noise. We exploit this fact to show that the measurement of magic can be used to quantify and characterize the noise in the quantum circuit. It is thus important to be able to quantify this resource and measure it to characterize the fitness of real quantum hardware. Unfortunatelyuntil recently -proposed measures of magic [4,17,22,35] have been based on extremization procedures and no experimental measurement scheme has been proposed.
As M 2 depends on the state ψ, a direct evaluation of M 2 would be possible by knowing all the expectation values tr(Pψ) of multi-qubit Pauli strings in the state ψ. This, of course, is equivalent to tomography and it is very expensive as it involves the evaluation of d 2 expectation values for a total cost in resources scaling as O(d 3 ).
Here, we employ a protocol based on randomized measurements which does not rely on tomographic techniques. Remarkably, randomized measurement protocols are highly favorable compared to state tomography [38,39,41,43]. As we shall see, we will employ a number of resources scaling as O( −2 d 2 ) for an estimate with error .

The protocol
The protocol consists in first drawing a string of random one-qubit Clifford operations, namely C = n i=1 c i and applying it to four copies of the state of interest. The protocol extracts correlations between these copies. Indeed, the quantity of interest in the first term of Eq. (1) can then be computed as − log 2 tr(Qψ ⊗4 ) = − log 2 s (−2) − s E C P(s 1 | C)P(s 2 | C)P(s 3 | C)P(s 4 | C) The formula above features the expectation value over the randomized measurements of the Clifford operator C on states of the computational basis s a and the Hamming weight s of the string s 1 ⊕ s 2 ⊕ s 3 ⊕ s 4 . The quantity P(s a | C) = tr(CψC † s a ) represents the probability of finding the computational basis state s a when measuring the state CψC † . The second term in Eq. (1) is the usual 2-Rényi entropy and can be measured by randomized measurements using the techniques of Ref. [41]. An important feature of our protocol is the fact that it only needs randomized operations over the Clifford group instead of the full unitary group as in Ref. [38]. In fact, by collecting the occupation probabilities P(CψC † | s a ) one can estimate both W(ψ) and the purity P(ψ) together thanks to the fact that the Clifford group forms a 2-design. See Methods. The operational meaning of the protocol is the following: randomized measurement protocols are usually conducted on a (Haar) random basis. Here we select a (local) stabilizer basis. Clifford rotations constitute the free resources for magic state resource theory. General unitaries would result in a change in quantum magic. Clifford orbits of a given quantum state instead are filled out by iso-magic states. A Clifford randomized measurement protocol measures the magic of the entire Clifford orbit, rather than of a single quantum state. The experiments have been conducted on two IBM Quantum Falcon processors: a 5 qubit system, ibmq_quito and a 7 qubit system ibmq_casablanca [50].
The experiment can be schematized as follows (see Fig. 1). Starting with a n-qubit state initialized in the | 0 ⊗n state, we pass it through a unitary quantum circuit U resulting in the state preparation |ψ . We want to characterize the fitness of such a circuit in providing a state with the promised magic. At this point, one extracts n one-qubit Clifford operations c i , applies them to the state| ψ , and measures the state in the computational basis.
Noisy State Preparation Noisy Measurement Apparatus Figure 1: Schematic of the implementation of the experiment for measuring magic on a quantum processor. From left to right: Initialization of the system in the state|0 ⊗n ; preparation of the target state | ψ by a unitary quantum circuit U t containing a number t of non-Clifford gates; intervention of the noise N p affecting the system effectively prepares the (mixed) state ψ p ; measurement. The measurement apparatus is composed of n local Clifford operators C = n i=1 c i randomly sampled from the single qubit Clifford group c i ∈ C 1 , followed by n measurements in the computational basis {| s } which are performed to estimate the occupation probabilities At this point, we want to analyze the scaling of the cost of necessary resources, both analytically and numerically. The experiment is repeated N M times for every string C = n i=1 c i in order to collect statistics to compute the occupation probabilities P(CψC † | s a ). Then, in order to compute the expectation value over the whole Clifford group E C , one samples the Clifford group with N U elements. In order to sample the Clifford group properly and to build sufficient statistics we simulate numerically the total number of measurements needed for M 2 , i.e. N T OT = N M × N U . By evaluating the variance of the estimator for W, through the use of standard statistical analysis (Bernstein inequality), one can bound the probability of making an error as a function of the total resources N U × N M employed. In Methods, we prove that by employing a total number of resources O( −2 d 2 ) the randomized measurement protocol is able to estimate the purity within an error and the stabilizer purity within an error d −1 . These theoretical bounds can be optimized by numerical analysis. The optimal number of unitaries N U and of measurements N M is found by numerical simulations imposing that the relative error on the theoretical value of stabilizer purity to be below 12% and an average value of the purity greater than 0.88, thus imposing a relative error of 12% on the purity as well. An important remark is that both N U and N M depend on the state ψ. Remarkably, low-magic states (like the states in the computational basis -which have exactly zero magic) require a higher N U × N M compared to states with high magic, see Supplementary Table I in Supplementary Note 4.
In order to characterize the fitness of a quantum processor in producing resources beyond stabilizer states, we adopt the model of a t-doped Clifford circuit [51][52][53]. This circuit consists of a block of Clifford gates in which t non-Clifford gates are injected. The non-Clifford gates we inject are P ϑ =|0 0| +e iϑ |1 1| gates: these constitute the resources that are injecting magic in the system, while the Clifford circuits are free resources. For ϑ = π/2 one obtains the phase flip gate that still belongs to the Clifford group and thus is a free resource. The value ϑ = π/4 instead, the so-called T gate, yields the maximal amount of magic achievable for a P ϑ gate. The T -gates will be called the "magic seeds" of the quantum circuit. These circuits are efficient in entangling so the output state of the circuit is in general not a trivial product state but a state that is both entangled and possesses magic.

Measuring magic
We start with the characterization of the quantum processor on single-qubit states, and thus without entanglement. The single-qubit magic states are obtained by applying P ϑ on the states |+ = 1 , achieving its maximum for M 2 (|P π/4 ) = 1 − log 2 3/2 and its minimum for M 2 (|P π/2 ) = 0.
The results of the experiment on the ibmq_quito are shown in Fig. 2. As we can see, the experimental data are in very good accordance with the theoretical prediction for the target state, showing the fitness of ibmq_quito in preparing single-qubit magic states. Decoherence effects are also very low, as we can see from the purity, see

Pur (|Pϑ )
Theoretical Purity Experimental Purity Figure 2: Stabilizer 2-Rényi entropy for | P ϑ . Plot of the magic of the single qubit | P ϑ -states, for θ = 0, π 16 , π 8 , π 6 , π 5 , π 4 . The data displayed (blue dots) are obtained from the quantum processor ibmq_quito. The blue dashed curve represents the theoretical value of the magic for |P ϑ -states, i.e. M 2 (|P ϑ ) = 3 − log 2 (7 + cos(4ϑ)). Additionally, a plot of the purity for these states is displayed in the upper right corner: as the data show, the purity is 1 within the experimental errors, showing that the decoherence affecting the system is negligible for n = 1 and also the experimental values of magic are in perfect agreement with the theoretical ones. See Supplementary Table II in the Supplementary Note 4 for the data.
We now proceed to the more difficult task of characterizing a quantum processor capable of preparing entangled states. Starting from the computational basis state |0 ⊗n , i.e. the input state of the quantum processor, we first apply a layer of Hadamard H-gates to obtain | + ⊗n = H ⊗n |0 ⊗n . Then, we apply T -gates on n 1 qubits, with n 1 = 0, . . . , n. The T -gates inject magic into the system. For n 1 = n, the state obtained is the maximal magic product state achievable. If one wants to pump more magic into the system, one needs to create some entanglement between the qubits. To do so, we apply a layer of CX-gates, i.e. Clifford entangling 2-qubit gates defined as CX i,j = I i ⊗ (I j + X j ) + Z i ⊗ (I j − X j ) and nested in the following way: CX n−1,n CX n−2,n−1 · · · CX 1,2 . Then we can inject some more magic in the system by applying another layer of n 2 T -gates with n 2 = 1, . . . , n − 1 followed by another layer of CX: CX 1,2 · · · CX n−2,n−1 CX n,n−1 . For the pictorial representation of the previously described architecture see Fig. 3. At the end of the state preparation, the magic seeds in the circuit are t = n 1 + n 2 and the state prepared is the |Γ (n) (n1,n2) -state, where 1 t 2n − 1. In the following, we fill in T -gates starting from (0, 1), then (n 1 , 1) with (n 1 , = 1, . . . , n; n 2 = 1), and finally (n, n 2 ), with n 2 = 2, . . . , n − 1. With this prescription, the label t uniquely describes the circuit. For example, t = 4 on a system with n = 6 qubits means three T -gates on the first layer and one T -gate on the second layer, see Fig. 3. The optimal number of N U , N M for a system with n = 3, 4, 5 qubits can be found in Supplementary Table I    2n−1 which is the final doped Clifford circuit which we consider in this paper.
In a system with n qubits we can prepare the states |Γ (n) t with t = 1, . . . , 2n − 1. The results of the experiment for n = 3, 4, 5 are shown in Figs. 4, 5,6, respectively. We can see that, for larger values of n, the purity of the prepared state is compromised, due to decoherence. The measured experimental values of magic shoot off the theoretical prediction, especially for low magic states. Somewhat counterintuitively, the experimental value of magic is higher than the theoretical one. As we mentioned above, spurious injection (or subtraction) of magic can happen for two reasons. Inaccurate implementation of the Clifford gates -and thus turning them into non-free resources -or noise affecting them, or decoherence. That is, our experimental characterization of how magic is created in a quantum circuit tests not only the quantity of magic, but the accuracy with which the desired magic is created. The fact that the circuit must not only create magic, but must do it so with a certain accuracy, allows us to use the experimental data obtained from our protocol to characterize the noise affecting the system. A first insight comes from the realization, see Figs. 4, 5, 6 that the noise is affecting more the preparation of low-magic states than that of high-magic states, mostly because of imperfection in the implementation of the resource-free Clifford gates like the CX gate. Let us see how we can characterize the noise affecting the system. A very general error model for the target state ψ is through a quantum channel E(ψ) := i q i P i ψP i . Random states are a good model for high-magic states [2] and thus, to understand why the noise affecting the system does not disturb the magic injected in high-magic states, we compute the average difference in magic between a random state ψ and the noisy state E(ψ) as: δM Haar := | M(E(ψ)) − M(ψ) | Haar . Calculation shows (see Supplementary Note 2) that δM Haar = O(S 2 (q)). In other words, at high levels of magic, this quantity is robust under the noise model provided that the distribution q = {q i } is low in entropy S 2 (q).    Fig. 7 in Methods. Note that the experimentally observed magic can beand typically is -higher than the theoretically predicted magic. This is because imperfectly performed Clifford gates are no longer exactly Clifford and can inject uncontrolled/unwanted magic into the system. This effect is enhanced for more qubits and deeper circuits.   Fig. 7 in Methods. Note that the experimentally observed magic can beand typically is -higher than the theoretically predicted magic. See the caption of Fig. 4 for an explanation.  Fig. 7 in Methods. Note that the experimentally observed magic can be -and typically is -higher than the theoretically predicted magic. See the caption of Fig. 4 for an explanation.
Guided by this result, we model the noise in two factors (i) noise in state preparation due to decoherence and (ii) imperfection in the realization of the c i gates in the randomized measurement. This latter error is unitary. We then tune the factors quantifying the noise in our model to match the difference between the experimentally measured and the theoretically predicted amounts of magic.
The ansatz for the (non-unitary) quantum channel N p affecting the state preparation is where Z i is a phase flip error on the i-th qubit happening with probability (1 − p)/n. This channel is not the simple phase-flip channel as the probability p in principle depends on the target state | ψ . The imperfection in the gates c i is modeled by the unitary phase displacement c i → c ε i ≡ c i P ε c i , where use the P ε -gate described above. The measured stabilizer purity will be denoted by W exp (| ψ ).
Our ansatz on how the noise affects the measurement results is then represents the correction to the projector onto the single-qubit stabilizer code due to the gate imperfection error ε.
The two free parameters p and ε can be determined experimentally, see Supplementary Note 2. Several points are in order here. First, notice that the purity tr ψ 2 p is protected against gate imperfection errors, so it can be measured independently. Second, one can measure the ε error directly by measuring the purity of the initial state |0 ⊗n , thus avoiding the decoherence effect altogether. The values of the stabilizer 2-Rényi entropy given by the noise model are represented by the Grey squares in Figs.4, 5 and 6 which show that they provide a better approximation to the experimental data, an approximation which in fact improves as the number of T gates in the circuit increases. By measuring the stabilizer 2-Rényi entropy, thus, we provide a characterization of the noise model and an estimate of its parameters p, ε.

DISCUSSION
Magic is a quantity of central importance for quantum computation: no quantum advantage can be obtained without it. This paper showed how to measure the amount of magic produced by a quantum circuit in terms of stabilizer Rényi entropy, and evaluated experimentally how that amount of magic scales as a function of the number of T-gates in the circuit. A central result of our experimental demonstration is that it is not enough just to create magic: the circuit must create an "accurate amount" of magic. Imperfectly implemented Clifford gates inject or subtract uncontrolled/unwanted magic into the circuit: just as excess entanglement can hinder the ability of a quantum circuit to perform some desired task [34], uncontrolled excess magic can result in the degradation of the performance of a quantum computation. Generating the correct amount of stabilizer Rényi entropy is thus an important component of the certification process for quantum hardware. More generally, in a quantum device, e.g. a circuit based on superconducting qubits, there can be errors beyond decoherence, like gate implementation errors, or other unitary errors. Typically, these errors are investigated through gate fidelity while the loss of purity is a good figure of merit to quantify decoherence. However, not always gate fidelity is available as a tool. As we can see in Figs. 4, 6, an inaccurate level of magic compared to the theoretical one signals the presence of unitary errors: a measurement of magic can then be used as a further tool to evaluate the accuracy of an experimental setup.

Theoretical framework
In [2] we proved that a global randomized measurements protocol can be employed to measure the stabilizer 2-Rényi entropy for multiqubit states.
Here, we make a decisive improvement by establishing a protocol that only requires local measurements. Local measurements are usually the best measurements in terms of quantum control an experimenter has access to. Let us recall the definition of stabilizer 2-Rényi entropy: for ψ a n-qubit quantum state, the stabilizer 2-Rényi entropy of ψ is defined as and the operator T is the swap operator while Q := d −2 P P ⊗4 . The local randomized measurements protocol we introduce here aims at measuring W(ψ) and P(ψ) by only using single qubit gates and then measuring the qubits in the computational basis. In this way, we reduce access to multi-qubit gates that are typically noisier and whose control is poorer. The logic behind any randomized measurement protocol is to reconstruct operators (e.g. the swap operator for the purity or higher order permutations for higher order purities, see [36, 38-40, 43, 54, 55]) from correlations between randomized measurements. The measurement is randomized by means of Clifford single qubit gates. It is fundamental to use Clifford gates as magic is invariant under these unitary operations. The ideal experimental protocol for measuring simultaneously W(ψ) and P(ψ) is (see Fig.1 for a pictorial schematization): are single qubit Clifford gates. For each C do: (i) obtain the desired state ψ from the quantum circuit U, (ii) apply C on the state ψ C ≡ CψC † , (iii) measure in the computational basis, (iv) redo steps (i), (ii) and (iii) N M times to estimate the occupation probabilities Pr(ψ C | s) ≡ tr(|s s| ψ C ) for s = 1, . . . , 2 n , (II) Estimate the probabilitiesPr(ψ C | s) by measuring the frequencies of obtaining the bit-string s 2 in the state ψ C . The estimatorPr(ψ C | s) for such probability converges to the true probability Pr(ψ C | s) in the limit N M → ∞.
(III) Obtain P(ψ) and W(ψ) can be computed from the ideal probabilities Pr(ψ C | s) by: the weighting coefficients O 2 (s 1 , s 2 ) and O 4 (s 1 , s 2 , s 3 , s 4 ) are obtained in the following way. First, define two diagonal operators defined in H ⊗2 and H ⊗4 respectively: O 4 (s 1 , s 2 , s 3 , s 4 ) |s 1 s 2 s 3 s 4 s 1 s 2 s 3 s 4 | Let us now prove Eqs. (4) and (5) (4) and (5) writing the purity as P(ψ) = tr(T ψ ⊗2 ) and W(ψ) = tr(Qψ ⊗4 ) from the above equation is clear that the task is to find two diagonal operatorsÔ 2 andÔ 4 whose local Clifford average gives T and Q respectively. Recalling that T = 1 2 n (1l ⊗2 + X ⊗2 + Y ⊗2 + Z ⊗2 ) ⊗n , and Q = 1 4 n (1l ⊗4 + X ⊗4 + Y ⊗4 + Z ⊗4 ) ⊗n , it is sufficient to find two single qubit diagonal operatorsô 2 andô 4 living in C 2⊗2 and C 2⊗4 respectively, such that their Clifford average gives respectively. At this point, it is straightforward to verify that one should choosê o 2 ,ô 4 to beô To conclude the proof is sufficient to writeô 2 andô 4 in the computational basis to restore the forms of Eqs. (4) and (5). It's easy to verify: where s k = s 1 k s 2 k . . . s n k a n-length bit string for k = 1, 2, 3, 4 and ⊕ is the logic sum between bits.

Statistical analysis
In this section, we discuss the effect of a finite number of realizations of the experiment. In our scheme, statistical errors arise from two factors: (i) a partial sampling of the local (single qubit) Clifford group, that is, N U < 24 n , and (ii) the finite number of measurement shots N M per unitary selected to estimate the occupation probabilitỹ Pr(ψ C | s), introduced in the previous section, that converge to the true probability only in the limit N M → ∞. The total number of resources is thus N U × N M . We assume that different rounds of random local unitary and different shots for a given unitary are generated independently and identically distributed. One describes the i-th shot for a given sampled unitary C ass C (i) which takes value |s s| with probability Pr(ψ C |s) ≡ tr(|s s| CψC † ). An unbiased estimator for the stabilizer purity is given by: . Let us prove that it is an unbiased estimator: where we used the fact that E ssU (i) ≡ s |s s| Pr(ψ C |s) = ψ C . Our task now is to bound the number of resources needed to estimate W within an error . We compute the variance given a finite number of shot measurements N M and a finite sample N U of the local Clifford group. The variance of the estimatorW(ψ) can be written as: After some lengthy algebra (see Supplementary Note 3) it is possible to bound the above variance as: Finally, we make use of Bernstein's inequality to bound the probability of an estimation within an error : In the regime of interest, i.e. . Therefore, employing a total number of resources the randomized measurement protocol is able to estimate the purity within an error and the stabilizer purity within an error d −1 . In the next section, we describe the experimental protocol used to perform the experiments on IBM quantum processors.

Experimental protocol
To measure the magic of multiqubit states on a quantum processor via statistical correlations between randomized measurements we need three steps: (i) state preparation, (ii) the application of N U random local Clifford unitaries to sample the local n-qubit Clifford group, whose dimension is |C loc (2 n )|= 24 n , and (iii) N M projective measurements to estimate the probabilitiesP M (ψ C | s). Then, the experimental purity and stabilizer purity are measured as: We proved that one needs N U × N M = O( −2 d 2 ) total measurements to estimate the stabilizer purity within a error −1 d −1 . Since we obtained such an accuracy guarantee through crude bounds, we expect fewer resources to be spent. We thus follow the protocol employed in [41] to find the optimal number of unitaries N U and measurements N M . We first build a preliminary 10 × 10 grid and make 100 numerical simulation for To obtain the optimal number of N U and N M for the given states |0 ⊗n and |Γ (n) 2n−1 , we set a threshold on the average distance δ NU,NM and on the average purity P NU,NM (| ψ ): M ] for fixed n; then we make 100 numerical simulations and pick the optimal number of resources satisfying conditions (i) and (ii). In this way, we are able to determine the optimal number of resources state by state, see Supplementary Table I in Supplementary Note 4 for the results. The data are fitted to depend exponentially upon the number t of magic-seeds, as N T OT = 2 a+b[(2n−1)−t] , see Fig. 7. The experimental errors on the estimated P(ψ) and W(ψ) are chosen to be the standard error of the average over N U , i.e. over the local Clifford operators used to estimate these two quantities from randomized measurements (see Supplementary Note 4).

Data Availability
The authors declare that the main data supporting the findings of this study are available within the article and its Supplementary Information files. Extra data sets are available upon reasonable request.

Supplementary Information for "Measuring magic on a quantum processor"
Salvatore F.E. Oliviero, 1, * Lorenzo Leone, 1 Alioscia Hamma, 1, 2, 3 and Seth Lloyd 4, 5 The stabilizer Rényi entropy has been introduced and defined in Ref. [1]. This section is devoted to a brief review of the quantity, and its relation to quantum chaos and quantum certification. As an original result, here we prove that the stabilizer Rényi entropy quantifies the resources necessary to extract useful information from a given quantum state.
Let ψ be a n-qubit state and P(n) the Pauli group on n qubit. Define the following probability distribution where P (ψ) := tr ψ 2 is the purity of the state ψ. The above is a probability distribution because Ξ ψ (P ) ≥ 0 and P Ξ ψ (P ) = 1. A family of magic monotones is given by the α-Rényi entropy of Ξ ψ plus the log of the purity of the state ψ: where S α (Ξ ψ ) := 1 1−α log P Ξ ψ (P ). M α (ψ) is called α-Stabilizer Rényi entropy. The above family of measures obeys the following properties: (i) It follows a hierarchy, i.e. M α (ψ) ≥ M α (ψ) for α < α .

(iii) It is invariant under Clifford rotations
Across this family of magic measures, the 2-Stabilizer Rényi entropy plays an important role. Indeed it distinguishes itself from the others because it can be experimentally measured via statistical correlations between randomized measurements, see Methods. Explicit calculations show that the 2-Stabilizer Rényi entropy can be expressed in terms of the stabilizer purity -W (ψ) := tr(Qψ ⊗4 ) where Q = d −2 P P ⊗4 is the projector onto the stabilizer code -and can be written as in Eq. 1.
The introduction of the stabilizer Rényi entropy revealed the intriguing connection between the resource theory of magic states and chaos. In these settings, a unitary operator U is said to be chaotic iff attains the Haar value of general multipoint (2k) Out-Of-Time-Order correlators (OTOCs) defined as: where A(U ) := U † AU . In order to see such a connection, consider a unitary operator U , and its Choi isomorphism [4], i.e. consider two copies of the Hilbert space and apply 1l ⊗ U on the Bell state |I := 1 d i |i ⊗ |i ∈ H ⊗2 . The Choi state is defined as: A lemma proved in Ref. [5] shows that the α-Stabilizer Rényi entropy of |U is proportional to the log of the general 4α-point OTOC: where the above OTOCs are average and nasty OTOCs defined as OT OC 2α := d −2 P,P otoc 2α (P, P ), and d × otoc 4α (P, P ) := tr[ P 4α 4α i=1 P (U )P P i−1 P i ] with P 0 ≡ 1l, · the average over P 1 , . . . , P 4α and P (U ) ≡ U P U † . Let us comment Eq. (5): (i) it establishes a direct connection to the theory of magic states and chaos. The more the magic in the Choi state associated with U , the more chaotic the evolution generated by U . And (ii), for α = 2 allows the direct measurement of the 8 point OTOC via statistical correlations between randomized measurements, the protocol analyzed and proven in the present paper.
The stabilizer Rényi entropy is nothing but an entropy in the operator basis of Pauli operators, let us say the operator-computational basis. The more a state ψ is spread in the Pauli basis, the more the Stabilizer Rényi entropy (and, consequently, the more the magic). Here is the thing: a state too spread in the Pauli basis cannot be used for a fruitful quantum computation when measured in the computational basis. Intuitively, in the case of almost maximal spreading, an exponential number of measurement shots is needed to distinguish the state ψ from a random state. This means that a state possessing an excessive amount of magic could be worse for quantum computation, as already pointed out in Ref. [6]. Here we want to show that a similar conclusion can also be made by looking at stabilizer Rényi entropies. The above intuition is formalized as follows: consider a state ψ and sample a Pauli operator P , to be measured at the end of a quantum computation, according to the state-dependent probability distribution Ξ ψ . This choice of probability distribution has the following operational meaning: across all the Pauli operators, Ξ ψ promotes the collection of Pauli operators having a large component on ψ. The probability that |tr(P ψ)|≥ is upper bounded by depends on the 2-stabilizer Rényi entropy M 2 (ψ) where we used Markov's inequality, and the fact that |tr(Pψ)| Ξψ ≤ tr 2 (P ψ) Ξψ = 2 −M2(ψ)/2 . Thus, given an extensive amount of magic M 2 (ψ) = αn, for some 0 < α < 1, the probability to pick a Pauli operator P such that |tr(P ψ)|≤ 2 − α 4 n is overwhelming ∼ 1 − 2 − α 4 n . This simple fact puts the above considerations in a rigorous fashion, showing that an excess amount of unwanted magic makes the task of distinguishing the state ψ from a random state an exponentially difficult task. We can prove the converse statement also: the less distinguishable a state ψ is from a random state, the more magic the state ψ contains. Consider a pure state ψ. We define the amount of distinguishability as the maximum expectation value over the set of Pauli operators, i.e. max P =1l |tr(P ψ)|, which quantifies the minimum number of resources necessary to distinguish ψ from a random state. Indeed, if max P =1l | tr(P ψ) |= then a number O( −2 ) of measurement shots is necessary for the evaluation of any expectation value of Pauli operators P . We have the following bound: see Supplementary Note 3. III for a proof. The above inequality tells us that, if max P =1l | tr(P ψ) |= 2 −αn , i.e. the state is not distinguishable from a random state with a polynomial number of shot measurements, then the 2-Stabilizer Rényi entropy M 2 (ψ) = O(n) is maximal. The task of distinguishing a state from a random one is central in the theory of quantum certification. A quantum certificate is a guarantee of the correct preparation of a given quantum state. Among the plethora of proposed certification protocols, one of the more efficient protocols to directly measure the fidelity between the desired state ψ and the prepared oneψ, i.e. tr(ψψ), is the Monte Carlo fidelity estimation introduced by Flammia and Liu [7]. The core of their protocol is to sample Pauli operators P according to the probability distribution Ξ ψ and measure them. Let N ψ the total number of resourcesincluding both the number of Pauli operators extracted and the finite number of shot measurementsnecessary to compute the fidelity up to an error , then: i.e. the resources are directly quantified by stabilizer Rényi entropies (see [5] for more details).

A. Magic is robust under noisy preparations
In this section, we explain why the amount of magic in high magical states is protected against a noisy state preparation. This result is completely inspired by experimental results. Indeed, looking at Figs. 3, 4, 5 one can note that the theoretical magic, the experimental value, and the noise model get closer and closer the more magic seeds are injected into the circuit. Here we prove that, for high magical and entangled states, this is indeed the case, provided that the noise model is enough well-behaving. Let ψ =|ψ ψ| the state one aims to prepare on the quantum processor; we can model (almost) any noisy state preparation with the following quantum channel [8]: where q i s form a probability distribution and P i are Pauli strings. Note that the noise model employed will fit the above definition. We model a high magical and entangled state as a Haar random state ψ, and evaluate the (average) difference in magic due to a noisy state preparation: We can exploit the typicality of Pur(E(ψ)), tr(Qψ ⊗4 ) and tr(QE(ψ) ⊗4 ) (see [1]), and take the average of every single term in the log, committing an error exponentially small in n: δM Haar − log tr(Qψ ⊗4 ) Haar Pur(E(ψ)) Haar tr(QE(ψ) ⊗4 ) Haar Let us evaluate term by term, starting from Pur(E(ψ)) Haar : where Π sym := 1l + T . Then: × i,j,k,l,P q i q j q k q l tr(P i P P i ⊗ . . . ⊗ P l P P l Π (4) sym ) note that the term P i P P i ⊗ . . . ⊗ P l P P l is invariant under the conjugacy classes of S 4 and therefore: where we defined X := P d −1 i q i tr(P i P P i P ) 4 . Note that 1 ≤ X ≤ d 2 and X = d 2 iff q i = 1 for some i (i.e. in presence of unitary stabilizer noise) and X = 1 iff E is the completely dephasing channel 3 E(ψ) ∝ 1l (i.e. for bad noise). Thus, in the large d limit we have tr(QE(ψ) ⊗4 ) Haar αd −2 where 1 ≤ α ≤ 4. Putting it all together we have: Neglecting the O(1) factor and expanding the log, we can write the following relation: where q is the probability distribution of the q i s and S 2 (q) its 2-Rényi entropy. Thus, the experimental data are telling us that the noise affecting the hardware features S 2 (q) ≤ O(poly(log n)). In the following we set up a noise model having S 2 (q) = O(log n).

B. Noise model
In what follows we introduce a noise model aimed to correct experimental values of magic, see Fig. 1 in the main text for a pictorial representation. A single run of our experiment consists of three steps: (i) state preparation, (ii) application of a random Clifford gate on each qubit, and (iii) local projective measurements in the computational basis. We aim to measure the magic in the quantum state at the end of the state preparation. We keep track of decoherence in the system, by measuring the purity of the output state P (ψ) along with W (ψ). We observe that the purity is more than 30% less than one, revealing the presence of errors with non-negligible probability. Let us first discuss errors during the state preparation, i.e. step (i). We model the effect of decoherence in the state preparation by a state-aware, self-correcting phase flip error occurring on every qubit with probability (1 − p)/n. Suppose one aims to prepare the state | ψ . Because of noise, the state actually prepared on the quantum computer is mixed and we postulate it to be: where Z i := 1l ⊗ · · · ⊗ Z ⊗ · · · ⊗ 1l. Id est, our ansatz is that during the state preparation phase flip occurs on every qubit with the same probability (1 − p)/n. Here 0 ≤ p ≤ 1 is a state-dependent (and run-dependent) constant that will be experimental measured for each state | ψ from the outcome probabilities, as explained in what follows. In step (ii), we apply n local Clifford gates, one on each qubit. Contrary to the case of universal gates (cfr. [9]), Clifford gates are fine-tuned and this can be a problem during an experiment aimed to measure magic. To understand this, consider a simple Clifford gate, e.g. phase-gate S :=|0 0| +e iπ/2 |1 1 |. It does belong to the Clifford group, but a small displacement of the π/2 angle makes S ±ε :=|0 0| +e iπ/2±ε |1 1 | not belonging to the Clifford group anymore. Although S ±ε is ε-away from being a Clifford gate, a small error ε in the gate implementation can result in affecting the results substantially. Indeed, since only Clifford operators are magic-preserving transformations, the application of a non-Clifford gate (despite being ε-away from being Clifford) would result in a biased measurement of the magic of the state | ψ . By applying n Clifford gates before collecting the outcome probabilities, also a small gate-imperfection error can pump magic into the system reflecting in an erroneous measurement of magic. This gate-imperfection error is more visible in low-magic states, compared to high-magic states, and the reason why is clear: while pumping some magic in low-magic states comes easy, it becomes harder and harder the more the state becomes a high-magic state. To collect unbiased measurements of the magic of quantum states prepared by the quantum processor, we need to get rid of these spurious contributions only due to the experimental apparatus. In what follows we build up a model that helps us to correct the experimental value of the magic. Let C = n i=1 c i , where c i ∈ C(2) are random local Clifford operators applied after the state ψ p is prepared on the quantum processor and before the collection of the outcomes. To take into account gate-imperfection errors, let us suppose that each Clifford gate c i is affected by the same small phase displacement ε: where P ε =|0 0| +e iε |1 1 | is a ε-phase gate, that aims to model the phase imperfections when applying S-gates. The outcome probabilities are therefore: where C ε := n i=1 c ε i . Recall that the magic is computed by statistical correlations between measurements, averaging over the local Clifford operators C applied at each run. Because of gate-imperfection errors modeled by C ε and the decoherence in the state preparation modeled by ψ p , the stabilizer purity computed is: where s ≡ (s 1 , s 2 , s 3 , s 4 ). Note that the average is no longer taken on the single qubit Clifford group, but rather in the P ε -doped Clifford gates, defined in [10,11]. Now, Eq. (20) can be written as: where we exploited the cyclic property of the trace, the locality of the doped Clifford operator C ε and the fact that Q = Q ⊗n 1 , where Q 1 = 1 4 (1l ⊗4 + X ⊗4 + Y ⊗4 + Z ⊗4 ); then we defined: By Theorem 1 in [10] one can compute Q ε 1 as where T (ijkl) are permutation operators defined on 4 copies of C 2 and T (ij) := T (12) + T (23) + T (34) + T (13) + T (14) + T (24) is a fast notation for the summation over the full conjugacy class, similarly for T (1) (ij)(kl) and T (1) (ijkl) . Then, by making the n-th tensor power to reconstruct Q ε⊗n 1 , the only term containing tr(Qψ ⊗4 p ) is the one (coming from the n-th tensor power) with coefficient g(ε) := 1 6 n (5 + cos(4ε)) n ; the other contributions constitute a correction to W (ψ p ) and depend on the state | ψ , the shift-angle and the decoherence parameter p. We define this contribution as: Thus, according to our noise model, W (ψ) measured in the experiment W ε (ψ p ) is a combination of the stabilizer purity of the noisy-prepared mixed state W (ψ p ) and an error term depending on the shift angle ε, which constitutes a spurious contribution to the magic due to the measurement apparatus. Finally, making the ansatz: we can estimate the corrected experimental stabilizer purity W corr exp (| ψ ) of the state ψ prepared on the quantum computer as: where Ω(p, ε, | ψ ) is defined in Eq. (24). So far, so good, but what about p and ε? Alongside with the magic, having collected the outcome probabilities P (ψ C p | s) allows us to compute the purity as: again, note that the average is taken on the P ε -doped Clifford group. The purity though involves just the second tensor power of the doped Clifford average, and since the Clifford group forms a unitary 3-design [12][13][14] the P ε -doping gets absorbed thanks to the left/right invariance of the Haar measure over groups [15,16]. Thus, we can simply write: in other words, the estimation of the purity via statistical correlations between randomized measurements is protected against gate-imperfection errors due to the non-exact implementation of Clifford gates. This feature makes the purity a perfect candidate to estimate the state-aware parameter p governing the noise model during the state preparation. Simple algebra leads to Then, making the ansatz that: one can determine p as the positive solution of the above second-order equation: where Z := i tr 2 (Z i ψ). As it is clear from the above equation, the constant p does depend on the state | ψ and can be computed once having measured the purity of the outcome state P exp (| ψ ). Further note that if the experimental purity is one, i.e. the state preparation has not been affected by decoherence, Eq. (31) gives p = 1. Now, what about the error ε? It does not depend on the state preparation, but rather on the experimental apparatus. We can therefore determine it once and for all from the experimental data coming from the input state |0 ⊗n . Since this state, unlike any other state, does not need to be prepared, according to our noise model, the measurements in such a state are not affected by decoherence. As usual, we apply n Clifford gates c i , one for each qubit i = 1, . . . , n, then we estimate the occupation probabilities P ( n i=1 (c i |0 0| c † i )| s) and compute P (ψ) and W (ψ) via statistical correlations between randomized measurements. Modeling the error in Clifford gates implementation through the model introduced before (cfr. Eq. (18)): since W (ψ) is multiplicative, note that W ε (|0 ⊗n ) = (W ε (|0 )) n and thus we can just work on W ε (|0 ). Thanks to the absence of the state preparation, we expect the purity computed via statistical correlations to be one; unfortunately, we also observe a small discrepancy of the experimental results with respect to one which reveals some error occurring during the projective measurements, i.e. read-out error during measurements. We model the readout error with a non-null probability (1 − q) that just after the application of the Clifford gate c ε i and before the measurement the bit is flipped, see Fig. 1 in the main text. Since we are dealing with a product state, we can just work on the single qubit state |0 . The parameter q can be estimated, just as the parameter p, from a purity measurement. The single qubit state just before the measurement is: note that the spin flip X occur after the P ε -doped Clifford gate has been applied to the input state |0 . The probability to find the outcome |s is: wheres is the not of the classical bit s due to the spin-flip X. When combining the outcome probabilities to compute the purity via statistical correlations: where we denoted · ε ≡ c ε⊗2 · c ε †⊗2 rangle C ε , then recall that: O x 2 := (1l ⊗ X)Ô 2 (1l ⊗ X) and used the fact that (X ⊗ X)Ô 2 (X ⊗ X) =Ô 2 . The doped Clifford averages read: where T 1 is the single qubit swap operator. One thus can rewrite Eq. (36) as: Finally, making the ansatz one can determine q by the positive solution of the second-order equation: note that if P exp (|0 ⊗n ) = 1, then q = 1. Now that we know the read-out error parameter q, we turn to compute W (χ ε q ) to estimate the shift angle ε: W (χ ε q ) = s1,s2,s3,s4 o 4 (s 1 , s 2 , s 3 , s 4 )P r(χ ε q |s 1 )P r(χ ε q |s 2 )P r(χ ε q |s 3 )P r(χ ε q |s 4 ) C ε Denotingô 4 ≡ s1,s2,s3,s4 o 4 (s 1 , s 2 , s 3 , s 4 ) |s 1 s 2 s 3 s 4 s 1 s 2 s 3 s 4 |= 1 4 1l ⊗4 + 3 4 Z ⊗4 , we have the following rules: from which we can update Eq. (41) as: where we defined W ε (|0 ) := tr(|0 0| ⊗4 Q ε 1 ). Now, from Eq. (23) we can compute W ε (|0 ) as: and finally, making the ansatz from Eqs. (43) and (44) we can estimate ε: this concludes the section.

III. SUPPLEMENTARY NOTE 3: SOME PROOFS
This section is devoted to some lengthy proofs.
A. Proof of Eq. (7) In this section, we prove Eq. (7). The first step of the proof is to introduce the following probability distribution (valid for pure states only): which is obtained by the probability distribution Ξ ψ without the identity component. Define the α-Rényi entropies of Ξ reg ψ , S α (Ξ reg ψ ), and note that By hierarchy of Rényi entropies, we can write the following bound: Let us now bound the r.h.s. of the above equation with the stabilizer Rényi entropy.
We are just left to bound the last term. Note that W (ψ) ≥ 2 d(d−1) (see [1]), and thus which proves the inequality, i.e.
| tr(P ψ) |≤ M 2 (ψ) + 1 (53) B. Bound on the variance of the stabilizer purity In this section, we compute the variance Var(W (ψ)). To this aim, let us look at the variance ofW C (ψ): The first term of the variance is equal to j<k<l<m n<o<p<q E C E s {tr s C (j) ⊗s C (k) ⊗s C (l) ⊗s C (m)Ô 4 ×tr s C (n) ⊗s C (o) ⊗s C (p) ⊗s C (q)Ô 4 } 8 In the summation, there may be repeated indexes between the sets of indexes {j, k, l, m} and {n, o, p, q}. Let us label with α the number of repeated indexes between the two sets and with K α the term of the sum corresponding to the α repeated indexes. E C E s (W 2 C (ψ)|C) can be written in term of K α as: Let us compute each term separately, K 0 reads: where P n := 1 d 2 P ∈P (n) P ⊗8 , Q n := 1 d 2 P ∈P(n) P ⊗4 and 1l n := 1l ⊗n . It is not difficult to observe that P 1 and (Q 1 ⊗ 1l 4 + 1l 4 ⊗ Q 1 ) commutes, meaning that there exists a basis in which both are diagonal. Then if then K 0 can be written as where {·} k labels all the possible tensor product of 1l ⊗n−k 8 P k 1 . To prove the bound we used the following properties: positivity of P 1 , (Q 1 ⊗ 1l 4 + 1l 4 ⊗ Q 1 ), 1l 8 , eigenvalues of (Q 1 ⊗ 1l 4 + 1l 4 ⊗ Q 1 ) bounded between 0 and 2, and that tr P n ρ ⊗8 ≤ tr Q n ρ ⊗4 ≤ 1 2 n (the proof of this inequality is a direct consequence of −1 ≤ tr P ψ ≤ 1).
The second term K 1 can be written as:  that sinceÔ 4 is a diagonal operator, R 1 is also a diagonal operator and then we can rewrite the term K 1 as the average of expectation values C †⊗7 R 1 C ⊗7 over the state ψ ⊗7 . As before, we can upper bound K 1 with the highest eigenvalue of R 1 that, since it is defined as a diagonal operator whose components are given by the product of components ofÔ 4 , is equal to 1. The third term is equal to: The proof is a direct consequence of the arguments given for the second term. The fourth term can be rewritten as: The last term is equal to = tr(ψ ⊗4 C †⊗4Ô2 C ⊗4 ) The last equivalence is due to the fact thatÔ is diagonal. Let us take a step back and compute the average ofô 2 4 , where with {·} k we labeled all the tensor product permutations of 1l ⊗n−k ⊗ Q ⊗k 2 and used the following inequality tr(Q d ψ) ≤ 1 d . The term E C E s (W 2 C (ψ)|C) reads: In this section, we compute the variance Var(Pur(ψ)).
Var(Pur C (ψ)) = E C E s (Pur Similarly to what done for the stabilizer purity, we label with α the number of repeated indexes between the two sets and with J α the term of the sum corresponding to the α repeated indexes. E C E s (Pur 2 C (ψ)|C) can be written in term of J α as: