Patent Publication Number: US-11038537-B2

Title: Magic state distillation with low space overhead and asymptotic input count

Description:
CROSS REFERENCE TO RELATED APPLICATIONS 
     This application is a continuation of U.S. patent application Ser. No. 15/627,190 entitled “Magic State Distillation With Low Space Overhead and Asymptotic Input Count,” and filed on Jun. 19, 2017, which claims the benefit of U.S. Provisional Application No. 62/473,915 entitled “Magic State Distillation With Low Space Overhead and Asymptotic Input Count,” and filed on Mar. 20, 2017, which are hereby incorporated herein in their entirety. 
    
    
     FIELD 
     This application relates generally to quantum computing. In particular, this application discloses example architectures for quantum circuits that perform magic state distillation protocols. 
     SUMMARY 
     Disclosed herein are example embodiments of protocols to distill magic states for T-gates. Particular examples have low space overhead and use an asymptotically optimal number of input magic states to achieve a given target error. The space overhead, defined as the ratio between the physical qubits to the number of output magic states, is asymptotically constant, while both the number of input magic states used per output state and the T-gate depth of the circuit scale linearly in the logarithm of the target error. Unlike other distillation protocols, examples of the disclosed protocol achieve this performance without concatenation and the input magic states are injected at various steps in the circuit rather than all at the start of the circuit. Embodiments of the protocol can be modified to distill magic states for other gates at the third level of the Clifford hierarchy, with the same asymptotic performance. Embodiments of the protocol rely on the construction of weakly self-dual Calderbank-Shor-Steane codes (“CSS codes”) with many logical qubits and large distance, allowing one to implement control-Swaps on multiple qubits. This code is referred to herein as the “inner code”. The control-Swaps are then used to measure properties of the magic state and detect errors, using another code that is referred to as the “outer code”. Alternatively, one can use weakly-self dual CSS codes which implement controlled Hadamards for the inner code, reducing circuit depth. Several specific small examples of this protocol are disclosed herein. 
    
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
         FIG. 1  shows an example embodiment of suitable computing environment for implementing several of the described embodiments. 
         FIG. 2  shows an example of a possible network topology (e.g., a client-server network) for implementing a system according to the disclosed technology. 
         FIG. 3  shows another example of a possible network topology (e.g., a distributed computing environment) for implementing a system according to the disclosed technology. 
         FIG. 4  shows an exemplary system for implementing embodiments of the disclosed technology. 
         FIG. 5  shows results of numerical simulations relating to the disclosed technology. 
         FIG. 6  is a diagram showing an example pipelined circuit using [[16, 6, 4]] code. 
         FIG. 7  is a diagram showing an example pipelined circuit using [[17, 1, 5]] code. 
         FIG. 8  is a diagram showing an example pipelined circuit using [[16, 2, 4]] code. 
         FIG. 9  is a diagram showing an example circuit using [[21, 3, 5]] code 
         FIG. 10  is a flowchart of an example method for distilling magic states in a quantum computing device in accordance with embodiments of the disclosed technology. 
         FIG. 11  is a flowchart of an example method for distilling magic states in a quantum computing device in accordance with embodiments of the disclosed technology. 
     
    
    
     DETAILED DESCRIPTION 
     I. General Considerations 
     Disclosed below are representative embodiments of methods, apparatus, and systems for magic state distillation in quantum computing devices, including quantum computing circuit architectures for performing such distillation. 
     Any of the disclosed example embodiments can be performed by a system comprising a classical processor and memory and/or at least in part by a quantum computing device (quantum computer) itself. The disclosed methods, apparatus, and systems should not be construed as limiting in any way. Instead, the present disclosure is directed toward all novel and nonobvious features and aspects of the various disclosed embodiments, alone or in various combinations and subcombinations with one another. Furthermore, any features or aspects of the disclosed embodiments can be used in various combinations and subcombinations with one another. For example, one or more method acts or features from one embodiment can be used with one or more method acts or features from another embodiment and vice versa. The disclosed methods, apparatus, and systems are not limited to any specific aspect or feature or combination thereof, nor do the disclosed embodiments require that any one or more specific advantages be present or problems be solved. 
     Although the operations of some of the disclosed methods are described in a particular, sequential order for convenient presentation, it should be understood that this manner of description encompasses rearrangement, unless a particular ordering is required by specific language set forth below. For example, operations described sequentially may in some cases be rearranged or performed concurrently. Further, some of the methods described herein can be altered by changing the ordering of the method acts described, by splitting, repeating, or omitting certain method acts, etc. Moreover, for the sake of simplicity, the attached figures may not show the various ways in which the disclosed methods can be used in conjunction with other methods. Additionally, the description sometimes uses terms like evaluate, “determine”, or “choose” to describe the disclosed technology. Such terms are high-level abstractions of the actual operations that are performed. The actual operations that correspond to these terms may vary depending on the particular implementation and are readily discernible by one of ordinary skill in the art. 
     As used in this application and in the claims, the singular forms a, an, and the include the plural forms unless the context clearly dictates otherwise. Additionally, the term includes means comprises. Further, as used herein, the term and/or means any one item or combination of any items in the phrase. 
     II. Introduction to Disclosed Technology 
     Large scale quantum computers rely on fault-tolerant architectures, in which errors are corrected faster than they are created. The standard approach is to use stabilizer codes to protect logical qubits from noise, and perform quantum gates at the encoded level. The overhead of the fault-tolerance is only polynomial in the logarithm of the desired accuracy, but in practice the overhead is estimated to be overwhelmingly large. 
     Particularly expensive operations are non-Clifford gates such as the π/4-rotation (T-gate) and Toffoli gate. A compelling approach is to inject a special state, called a magic state, into a Clifford-only circuit, and pass the cost of implementing the non-Clifford operation to the preparation of the magic states, which are distilled from noisy ones. 
     There exist several distillation protocols for the magic state for T gate using specialized quantum error correcting codes. See, e.g., E. Knill, “Fault-tolerant postselected quantum computation: Schemes,” (2004), quant-ph/0402171v1; Sergei Bravyi and Alexei Kitaev, “Universal quantum computation with ideal Clifford gates and noisy ancillas,” Phys. Rev. A 71, 022316 (2005), quant-ph/0403025; Adam M. Meier, Bryan Eastin, and Emanuel Knill, “Magic-state distillation with the four-qubit code,” Quant. Inf. Comp. 13, 195 (2013), 1204.4221; Sergey Bravyi and Jeongwan Haah, “Magic state distillation with low overhead,” Phys. Rev. A 86, 052329 (2012), 1209.2426. Each code can provide a fixed degree of fidelity improvement that is given by the code distance. In order to achieve arbitrary good fidelity, one typically concatenates small routines. In terms of the number of input magic states of low fidelity per one output magic state of high fidelity, some protocols are those in Sergey Bravyi and Jeongwan Haah, “Magic state distillation with low overhead,” Phys. Rev. A 86, 052329 (2012), 1209.2426; and Cody Jones, “Multilevel distillation of magic states for quantum computing,” Phys. Rev. A 87, 042305 (2013), 1210.3388v2. However, these protocols require a large batch of thousands of magic states to be useful. 
     In this disclosure, a family of distillation protocols is disclosed (e.g., an infinite family). Example embodiments of the disclosed protocol produce n T-magic states using at most cm qubits and achieve at least c′ n-th order error suppression under the assumption that the sole noise source is the T gate, where c, c′ are small universal constants. Since the degree of error suppression is high, there is no need to concatenate small routines, reducing the space overhead significantly. 
     Example embodiments of the disclosed protocol are also asymptotically superior (conjectured to be optimal) in terms of noisy T count. For any fixed odd d≥5, it is shown that the number of noisy T gate per one output magic state with error suppressed to d-th order converges to d exactly in the large code length limit. Beyond the magic states for T gates, examples of the disclosed protocol can distill magic states for rotation by π/2 k  for k=3, 4, . . . adapting the idea of Guillaume Duclos-Cianci and David Poulin, “Reducing the quantum computing overhead with complex gate distillation,” Phys. Rev. A 91, 042315 (2015), 1403.5280v1 and any gate in the third level of Clifford hierarchy (see Isaac L. Chuang and Daniel Gottesman, “Demonstrating the viability of universal quantum computation using teleportation and single-qubit operations,” Nature 402, 390393 (1999)) For the latter, the asymptotic performance is similar to the T gate case. 
     Small instances of the disclosed family appear to outperform any other previous protocols. If noisy π/4 rotations can be directly done on qubits, an instance of the disclosed family operates on 34 qubits including measurement ancillas, produces 15 T-magic states with 5th order error suppression, and requires 29 noisy T gates per output. 
     Recent innovations show that the π/4-rotation and Toffoli gate can be implemented transversally on a class of error correcting codes. See Adam Paetznick and Ben W. Reichardt, “Universal fault-tolerant quantum computation with only transversal gates and error correction,” Phys. Rev. Lett. 111, 090505 (2013), 1304.3709; Serge y  Bravyi and Andrew Cross, “Doubled color codes,” 1509.03239v1; Theodore J. Yoder, Ryuji Takagi, and Isaac L. Chuang, “Universal fault-tolerant gates on concatenated stabilizer codes,” Physical Review X 6, 031039 (2016), 1603.03948. Transversal gates are inherently fault-tolerant, and hence this approach removes the need for magic states. 
     The organization of the remainder of the disclosure is as follows. In Section III, a basic explanation of the disclosed technology is given by exhibiting examples of small sizes. Section IV explains how to convert magic state distillation protocols for T gates into those for Toffoli gates. In section V, it is shown that any weakly self-dual CSS code can be used in distillation protocols by implementing measurement of Clifford operators. In section VI, asymptotic constructions of the codes are given, in the limit of either large distance or large code length. In section VII, results of numerical simulations are given; in this section, some specific additional small size protocols are disclosed that are not described elsewhere in the disclosure. Section IX provides some further discussion of the disclosed technology. In Section X, details are given, including stabilizer checks, for some of the specific codes used in this disclosure. Section XI gives circuits for some of the protocols used. Section XII describes unexpected relations among different distillation protocols. Section XIII explains an extension to qudits using classification of symmetric forms over finite fields in Section XIV. 
     Throughout this disclosure, all classical codes that are considered will be linear codes over the binary field    2  and all quantum codes will be qubit stabilizer codes. Given a bit vector v, |v| is used to denote its Hamming weight. Our magic state is the 
                 (     +   1     )     ⁢     -     ⁢   eigenstate   ⁢           ⁢        H   〉       =         cos   8   π     ⁢           ⁢        0   〉       +       sin   8   π     ⁢           ⁢        1   〉               
of the Hadamard operator H. The following matrices are used
 
     
       
         
           
             
               
                 
                   
                     X 
                     = 
                     
                       ( 
                       
                         
                           
                             0 
                           
                           
                             1 
                           
                         
                         
                           
                             1 
                           
                           
                             0 
                           
                         
                       
                       ) 
                     
                   
                   , 
                   
                     Y 
                     = 
                     
                       ( 
                       
                         
                           
                             0 
                           
                           
                             
                               - 
                               i 
                             
                           
                         
                         
                           
                             i 
                           
                           
                             0 
                           
                         
                       
                       ) 
                     
                   
                   , 
                   
                     Z 
                     = 
                     
                       ( 
                       
                         
                           
                             1 
                           
                           
                             0 
                           
                         
                         
                           
                             0 
                           
                           
                             
                               - 
                               1 
                             
                           
                         
                       
                       ) 
                     
                   
                   , 
                 
               
               
                 
                   ( 
                   
                     II 
                     ⁢ 
                     .1 
                   
                   ) 
                 
               
             
             
               
                 
                   
                     H 
                     = 
                     
                       
                         
                           
                             1 
                           
                         
                         
                           
                             
                               √ 
                               2 
                             
                           
                         
                       
                       ⁢ 
                       
                         ( 
                         
                           
                             
                               1 
                             
                             
                               1 
                             
                           
                           
                             
                               1 
                             
                             
                               
                                 - 
                                 1 
                               
                             
                           
                         
                         ) 
                       
                     
                   
                   , 
                   
                     T 
                     = 
                     
                       
                         e 
                         
                           
                             - 
                             i 
                           
                           ⁢ 
                           
                               
                           
                           ⁢ 
                           π 
                           ⁢ 
                           
                               
                           
                           ⁢ 
                           
                             Y 
                             / 
                             8 
                           
                         
                       
                       = 
                       
                         
                           ( 
                           
                             
                               
                                 
                                   cos 
                                   8 
                                   π 
                                 
                               
                               
                                 
                                   - 
                                   
                                     sin 
                                     8 
                                     π 
                                   
                                 
                               
                             
                             
                               
                                 
                                   sin 
                                   8 
                                   π 
                                 
                               
                               
                                 
                                   cos 
                                   8 
                                   π 
                                 
                               
                             
                           
                           ) 
                         
                         . 
                       
                     
                   
                 
               
               
                 
                   ( 
                   
                     II 
                     ⁢ 
                     .2 
                   
                   ) 
                 
               
             
           
         
       
     
     A self-orthogonal subspace of some vector space is a subspace such that the inner product of any two vectors in the subspace vanishes. A weakly self-dual CSS code is a quantum code whose stabilizer group is invariant under conjugation by the product of the Hadamard operator on all qubits; this is product is called a “transversal Hadamard”. 
     III. Basic Distillation Protocols 
     Distillation protocols for magic states to date can be put roughly into two classes. Those in the first class implement a non-Clifford π/4-rotation to a stabilizer state such as |+  or |0 . See Sergei Bravyi and Alexei Kitaev, “Universal quantum computation with ideal Clifford gates and noisy ancillas,” Phys. Rev. A 71, 022316 (2005), quant-ph/0403025; Sergey Bravyi and Jeongwan Haah, “Magic state distillation with low overhead,” Phys. Rev. A 86, 052329 (2012), 1209.2426; Andrew J. Landahl and Chris Cesare, “Complex instruction set computing architecture for performing accurate quantum Z rotations with less magic,” (2013), 1302.3240. The non-Clifford rotation is desirably done fault-tolerantly, so the protocols in this class focus on finding error correcting codes that admits a transversal non-Clifford rotation. This requires the underlying code to have a special symmetry, which is rather rare. The protocols in the second classimplement measurements of “stabilizers” of the magic state, based on the fact that a magic state in the third level of Clifford hierarchy is an eigenstate of a Clifford operator. See, e.g., E. Knill, “Fault-tolerant postselected quantum computation: Schemes,” (2004), quant-ph/0402171v1; E. Knill, “Fault-tolerant postselected quantum computation: Threshold analysis,” (2004), quantph/ 0404104v1; Adam M. Meier, Bryan Eastin, and Emanuel Knill, “Magic-state distillation with the four-qubit code,” Quant. Inf. Comp. 13, 195 (2013), 1204.4221; Cody Jones, “Multilevel distillation of magic states for quantum computing,” Phys. Rev. A 87, 042305 (2013), 1210.3388v2; Guillaume Duclos-Cianci and David Poulin, “Reducing the quantum computing overhead with complex gate distillation,” Phys. Rev. A 91, 042315 (2015), 1403.5280v1; Earl T. Campbell and Joe O&#39;Gorman, “An efficient magic state approach to small angle rotations,” Quantum Science and Technology 1, 015007 (2016), 1603.04230v2. To measure a Clifford operator, one can use a non-Clifford operation which has been implemented fault-tolerantly by a distance-two code. 
     The example schemes in this disclosure belong to the second class. There are two levels of error correcting codes in examples of the disclosed scheme, which are referred to as inner and outer codes. Roughly speaking, the outer codes specify a certain set of measurements of Clifford operators on a set of input magic states, and the inner codes specify how to implement these measurements. Aspects of the disclosed technology can be described by two examples. These examples are for illustration purposes only, as they involve a relatively small number of non-Clifford gates and states, but help illustrate certain principles of the disclosed technology. The disclosed technology is highly scalable and a more general class of protocols is presented in later sections. 
     Without loss of generality, by a standard Clifford twirling argument, one can assume that each π/4 rotation and undistilled magic state suffers from independent Y errors with probability ϵ. This error model is referred to as the stochastic error model. 
     A. Trivial Outer Code 
     If one could implement the control-Hadamard, then the distillation is relatively straightforward: Prepare an ancilla qubit in |+  state, apply the control-Hadamard with the control on the ancilla and the Hadamard on an arbitrary target qubit, and measure the ancilla in X-basis to accept +1 outcome. The accepted target qubit is projected onto the magic state. 
     The control-Hadamard belongs to the third level of Clifford hierarchy, and thus cannot be implemented with Clifford operations. To obtain an approximate control-Hadamard with noisy non-Clifford rotations, one can use an error correcting code that can implement H on the logical qubits fault-tolerantly. 
     1. [[7,1,3]] Inner Code 
     To this end, observe that the Steane code admits a transversal Hadamard. See, e.g., A. M. Steane, “Error correcting codes in quantum theory,” Physical Review Letters 77, 793797 (1996); E. Knill, “Fault-tolerant postselected quantum computation: Schemes,” (2004), quant-ph/0402171v1. 
     The stabilizers are 
                         I       I       I       X       X       X       X           I       X       X       I       I       X       X           X       I       X       I       X       I         X   ,           ⁢           ⁢         I       I       I       Z       Z       Z       Z           I       Z       Z       I       I       Z       Z           Z       I       Z       I       Z       I         Z   ,                   (     III   ⁢   .1     )               
the group generated by which is fixed under the H 237 7 : X i ↔Z i , and the logical operator pair is
 
ZZZZZZZ XXXXXXX   (III,2)
 
which are interchanged by the transversal Hadamard. Using an identity
 
 H=TZ·T   †   =e   −iπY/8   Z e   iπY/8    (III,3)
 
one can see that the logical control-Hadamard is possible by replacing the middle Z by the control-Z. The T gate can be noisy as they act on the physical qubits of the Steane code.
 
     This way, a Hadamard measurement routine has been created that is fault-tolerant. Then, one example magic state distillation protocol is as follows:
         1. Prepare a noisy magic state in the “data” register, and |0  in 6 check registers, and embed them into the Steane code   2. Prepare an ancilla in |+  and implement control-H ⊗7  using Eq. (III.3), where the control is the ancilla and the targets are the physical qubits of the Steane code.   3. Inverse the embedding of the Steane code.   4. Measure the ancilla in the X basis, the check qubits in the Z basis.   5. Upon +1 outcome in all 7 measurements, a distilled magic state is in the data qubit.
 
Now examine the pattern of errors that may go undetected. There are two possibilities.
   The initial magic state is faulty, and this is undetected due to malfunction of the control-Hadamard.   The noisy π/4 rotations induce a logical error.
 
The first possibility is because a pair of simultaneous errors sandwiching the control-Z can alter the ancilla measurement:
       

                          0   〉     ⁢           ⁢     〈     0   ⁢            ⊗   I     +          ⁢   1     〉     ⁢           ⁢       〈   1        ⊗     e       -   i     ⁢           ⁢   π   ⁢           ⁢     Y   /   8           ⁢   Y   ⁢           ⁢   Z   ⁢           ⁢   Y   ⁢           ⁢     e     i   ⁢           ⁢   π   ⁢           ⁢     Y   /   8           =       (     Z   ⊗   I     )     ⁢           ⁢       (          0   〉     ⁢           ⁢     〈     0   ⁢            ⊗   I     +          ⁢   1     〉     ⁢           ⁢       〈   1        ⊗     e       -   i     ⁢           ⁢   π   ⁢           ⁢     Y   /   8           ⁢           ⁢   Z   ⁢           ⁢     e     i   ⁢           ⁢   π   ⁢           ⁢     Y   /   8           )     .               (     III   ⁢   .4     )               
Thus, the first possibility occurs with probability ϵ 3  to leading order. One can easily see that this is the only possibility for weight 2 errors from the control-Hadamard to escape. The second possibility occurs at order ϵ 3  since Steane&#39;s code has distance 3.
 
     It is useful to think of the above protocol as a Hadamard measurement (H-measurement) routine that introduces a new error of order ϵ 3  to the target, and another error of order ϵ 2  to the control. The error on the control is easy to fix; repeat the measurement. This corresponds to having redundant checks in the outer code. The error on the target is inherent to the choice of the inner quantum code, and should thus be overcome by another quantum code. 
     2. [[17,1,5]] Inner Ccode 
     There exists a distance 5 code on 17 qubits with H ⊗7  being the logical Hadamard. It is an instance of the color code. H. Bombin and M. A. Martin-Delgado, “Topological quantum distillation,” Physical Review Letters 97, 180501 (2006), quant-ph/0605138; Sergey Bravyi and Andrew Cross, “Doubled color codes,” 1509.03239v1. The binary matrix for this code is included in Section X. In a similar way as above, this H-measurement routine has error rate O(ϵ 5 ) on the target, and O(ϵ 2 ) on the control. By repeating the H-measurement twice using this inner code, the control&#39;s error rate becomes O(ϵ 4 ). The control error goes undetected only if the initial magic state is faulty. Overall, only weight 5 errors may be undetected. 
     In fact, one can pipeline the two H-measurement routines: First, H-measure a noisy magic state using [[7, 1, 3]] code, and then H-measure the outcome using [[17, 1, 5]] code.(Interestingly, the protocol using Steane code, and the pipelined protocol appear to have deep relation with triply even codes. See Section XII.) Hence, a distillation routine has been obtained with fifth order error suppression that operates on 18 qubits in total. The circuit is in  FIG. 7  in Section XI. 
     B. Repetition Outer Code 
     Imagine one has p outer  noisy magic states that are to be distilled. Under the stochastic error model, one can think of the noisy magic states as an ensemble of n outer -bit strings where 0 denotes a good magic state, and 1 denotes a bad one. The protocol in the previous subsection examines one qubit at a time, and in terms of the bit strings, this amounts to checking individual bits. If the goal is to suppress the overall error to d-th order where d&lt;n outer , the bit-wise check might be unnecessary. A better way is to devise a measurement routine that can check the parity of several bits. 
     1. [[4, 2, 2]] Inner Code 
     The simplest case is when n outer =2 and the desired error suppression is quadratic. If one can measure H ⊗2 , then by postselecting on +1 outcome the noisy state is projected to the even parity subspace, which is O(ϵ 2 ) away from the pair of perfect magic states. One can describe the situation by saying that one has a repetition code on n outer =2 bits with one parity check. This is an outer code. 
     A corresponding inner code should implement control-H ⊗2  to accuracy O(ϵ 2 ), both in the target and the control. Meier, Eastin, and Knill have designed such a measurement routine. See Adam M. Meier, Bryan Eastin, and Emanuel Knill, “Magic-state distillation with the four-qubit code,” Quant. Inf. Comp. 13, 195 (2013), 1204.4221. The four qubit code [[4, 2, 2]] whose stabilizers are X ⊗4  and Z ⊗4  admits the transversal Hadamard  H =H ⊗4  as a logical operator. If one chooses the logical operators as 
                         {         X       X       I       I           I       Z       Z       I                 {         Z       Z       I       I           I       X       X       I                       (     III   ⁢   .5     )               
then the transversal Hadamard swaps the two logical qubits. Using Eq. (III.3), this means that one can implement control-Swap to accuracy O(ϵ 2 ). Now, in one example embodiment, the control-Swap is used twice sandwiching the Hadamard:
 
[ C Swap 12 ] H   1 [ C Swap 12 ]=[ C ( H   1 ⊗ H   2 )] H   1    (III.6)
 
where the superscript C denotes the control that is common for both control-Swaps, and the subscripts 1 and 2 denote the qubits the operator acts on. The extra H 1  does no harm since the magic state is its eigenstate. The obtained control-H ⊗2  is accurate up to error O(ϵ 2 ) on the target since the distance of the four-qubit code is 2, and also O(ϵ 2 ) on the control due to Eq. (III.4). (Meier, Eastin, and Knill compresses the circuit for the control-H ⊗2 . See Adam M. Meier, Bryan Eastin, and Emanuel Knill, “Magic-state distillation with the four-qubit code,” Quant. Inf. Comp. 13, 195 (2013), 1204.4221; see also Earl T. Campbell and Joe O&#39;Gorman, “An efficient magic state approach to small angle rotations,” Quantum Science and Technology 1, 015007 (2016), 1603.04230v2.) This is a quadratic distillation protocol.
 
     2. [[16,6, 4]] Inner Code and Pipelining 
     The classical Hadamard code [16, 5, 8] has a property that every code word has even overlap with any other code word. By the CSS construction, using these classical codewords as stabilizers, one obtains a [[16, 6, 4]] code; see section X A 2 for the stabilizers. It will later be shown that there is a choice of logical operators such that the transversal Hadamard H ⊗16  implements simultaneous pairwise swaps on the three pairs of logical qubits. This implies that one can measure any even product {tilde over (H)} ⊗2 , or {tilde over (H)} ⊗4 , or {tilde over (H)} ⊗6  of Hadamards on k inner =6 magic states. For example, one can generalize Eq. (III.6) to
 
[ C Swap 12 ][ C Swap 34   ]H   1   H   3 [ C Swap 12 ][ C Swap 34 ]=[ C ( H   1   ⊗H   2   ⊗H   3   ⊗H   4 )] H   H   3 .    (III.7)
 
     The classical Hadamard code [16, 5, 8] has a property that every code word has even overlap with any other code word. By the CSS construction, using these classiCal codewords as stabilizers, one obtains a [[16, 6, 4]] code; see section X A 2 for the stabilizers. The H-measurement routine puts quadratic error to the control and quartic error to the target. 
     Imagine that n outer =6 magic states are laid on a ring. One can measure H ⊗2  on every nearest neighboring pair of the magic states. There are six checks in total. The measurement pattern follows the parity checks of the classical repetition code; there is a redundancy in the checks, which turns out to be necessary. Now consider how this achieves quartic error suppression. In order for an error on one of  outer  magic states to pass the measurement routines, the two checks that involve that input state must both be faulty. This process gives an O(ϵ 5 ) error, e.g., the probability of both checks being faulty is O(ϵ 4 ), so including the error on the input magic state the error is O(ϵ 5 ). Note that if one did not have a redundancy in the checks of the outer code, using only 5 checks, one qubit would be checked only once and one would achieve only third order error suppression. More generally, any process involving one or more input magic state errors gives an error which is at most O(ϵ 5 ). The dominant error after all the H-measurements is then from the logical error by the H-measurement routine, which happens with probability O(ϵ 4 ). 
     One can pipeline the [[4, 2, 2]] code routine in front of the [[16, 6, 4]] code routine to lower the complexity of the distillation circuit. For instance, one can run the three H-measurement routines by the [[4, 2, 2]] code on pairs of magic states (12), (34), and (56), and then run the three H-measurement routines by [[16, 6, 4]] code on pairs of magic states (23), (45), and (61). It is straightforward to show that the modified version also achieves quartic error suppression. The modified version has been simulated, and the results can be found in Section VII. The circuit is in  FIG. 6  in Section XI. 
     IV. Third Level of Clifford Hierarchy 
     The protocol above can be straightforwardly generalized to distilling other magic states to implement gates at the third level of the Clifford hierarchy. Consider a state |ψ  on q qubits such that |Ψ =U|ϕ  where U is a gate at the third level of the Clifford hierarchy and |ϕ  is a stabilizer state. See Isaac L. Chuang and Daniel Gottes man, “Demonstrating the viability of universal quantum computation using teleportation and single-qubit operations,” Nature 402, 390393 (1999). An example of such a state 10) is the magic state to produce a CCZ gate, which is equivalent to the Toffoli gate up to a Hadamard on the target. See Peter W. Shor, “Fault-tolerant quantum computation,” in Foundations of Computer Science, 1996. 
     
       
         
           
             
               
                 
                   
                     
                       | 
                       ψ 
                     
                     〉 
                   
                   = 
                   
                     
                       
                         
                           
                               
                           
                           CC 
                         
                         ⁢ 
                         Z 
                       
                       
                         ︸ 
                         U 
                       
                     
                     ⁢ 
                     
                       
                         
                           
                             ( 
                             
                               
                                 
                                    
                                   0 
                                   〉 
                                 
                                 + 
                                 
                                    
                                   1 
                                   〉 
                                 
                               
                               
                                 2 
                               
                             
                             ) 
                           
                           
                             ⊗ 
                             3 
                           
                         
                         
                           ︸ 
                           
                              
                             ϕ 
                             〉 
                           
                         
                       
                       . 
                     
                   
                 
               
               
                 
                   ( 
                   
                     IV 
                     ⁢ 
                     .1 
                   
                   ) 
                 
               
             
           
         
       
     
     As |ϕ  is a stabilizer state, one can identify q operators, S(1), S(2), . . . , S(q), which are products of Paulis, generating the stabilizer group of |ϕ , so that |ϕ  is the unique (up to global phase) +1 eigenstate of those operators. For the CCZ, one can see S(1)=X 1 , S(2)=X 2 , and S(3)=X 3 . Then, the state |ψ  is the unique +1 eigenstate of the operators
 
 W ( a )≡ US ( a ) U   † , for  a= 1, . . . ,  q.    (IV.2)
 
These operators W(a) commute with each other by construction, and belong to the second level of the hierarchy, the Clifford group. For the CCZ, one can see W(1)=X 1 ( C Z) 23 , W(2)=X 2 ( C Z) 13 , and W(3)=X 3 ( C Z) 12 .
 
     Here is an example protocol for CCZ state distillation using three copies of the [[4, 2, 2]] code. In this example, the three copies are regarded as a single [[12, 6, 2]] code and the logical qubits are indexed by 1, . . . , 6. One can encode one CCZ state stabilized by W(a) into logical qubits 1,3, 5 and another stabilized by W′(a) into 2, 4, 6 where a=1, 2, 3. Consider a variant of Eq. (III.6)
 
[ c (Swap 12 Swap 34 Swap 56 )](W(a) 135 ⊗I 246 )[ C (Swap 12 Swap 34 Swap 56 )]=[ C (W(a) 135 ⊗W(a) 246 )](W(a) 135 ⊗I)  (IV .3)
 
where the control qubit is common for every gate. The simultaneous control-Swaps are implemented by the control-H ⊗12  on the [[12, 6, 2]] code, where the control-H ⊗12  in turn is implemented by noisy T gates. Thus, one can obtain a measurement routine for W(a)⊗W′(a). (Since W(1), W(2), W(3) are the same up to permutations of qubits, the measurement routine can in fact measure any product W(a)⊗W′(b) for a, b=1, 2,3 on the pair of CCZ states.)
 
     Then the protocol is to measure W(1)W′(1), W(2)W′(2), and W(3)W′(3). 
     By applying the Clifford stabilizers W uniformly at random to a noisy magic state for CCZ, it becomes a mixture of eigenstates of W&#39;s. Hence one may assume an error model where an error flips at least one of W(1), W(2), W(3) with probability 6. Since the measurement routine puts measurement error at rate O(ϵ 2 ) and logical error at rate O(ϵ 2 ), the protocol achieves quadratic error reduction for CCZ state. For higher order reduction, one should use inner and outer code of higher distances. 
     A related discussion on error model for the T state is given in Section VII A. 
     In passing, it is noted that the Clifford unitary V 123 =( C     1   Z 2 )( C     1   X 2 )X 2 X 3  on three qubits 1, 2, 3 is a stabilizer of the CCZ state 
                  CCZ   〉     =           1             8           ⁢       ∑     a   ,   b   ,     c   =   0     ,   1       ⁢           ⁢         (     -   1     )     abc     ⁢          abc   〉     .                 
Since the CCZ state is permutation invariant, one can obtain six such stabilizers. They do not commute, but any triple of them uniquely determines the CCZ state. The controlled version can be implemented with only four T gates. See Bryan Eastin, “Distilling one-qubit magic states into toffoli states,” Phys. Rev. A 87, 032321 (2013), 1212.4872v2; see also Cody Jones, “Low-overhead constructions for the fault-tolerant toffoli gate,” Physical Review A 87, 022328 (2013), 1212.5069.  C     0   V 123 =T 2  ( C     1   Z 2 )T 2  ( C     0   Z 2 )T 2   † ( C   1 Z 2 )T 2   † ( C     0   X 3 ). It might be possible to use these stabilizers with odd codes, but because they do not commute the resulting measurement routine rejects faulty inputs with a probability less than 1, even in the limit ϵ→0.
 
     V. Inner Codes 
     In this section, a general class of inner codes is disclosed that can be used in any of the distillation protocols disclosed herein. 
     A. Symmetric Forms Over  2    
     Consider finite dimensional vector spaces over the binary field    2 . The space    2   n  is equipped with a symmetric dot product v·w=Σ i v i w i ∈   2 . This dot product on    2   n  is non-degenerate, e.g., for any nonzero vector v∈   2   n  there is a vector w∈   2   n  such that v·w=1. Let S be a null (self-orthogonal) subspace of    2   n , on which the dot product identically vanishes. Since S is null, the dot product of    2   n  canonically induces a dot product on the quotient space    2   n /S by [v]·[w]:=v·w where [v] and [w] denote the equivalence classes (members of the quotient space) represented by v and w, respectively. Let S ⊥  denote the orthogonal complement of S with respect to the dot product. 
     Lemma 1. The induced dot product on S ⊥ /S is non-degenerate. 
     Proof. First, it is claimed that (S ⊥ ) ⊥ =S. It is clear by definition that S⊆(S ⊥ ) ⊥ . Interpreting the orthogonal complement as the solution space of a system of linear equations, one sees that the claim holds by dimension counting. For [v]∈S ⊥ /S, if [v]·[w]=0 for any w, then v belongs to (S 195  ) ⊥ =S, implying that [v]=0∈S ⊥ /S. 
     For any basis {[v (1) ], . . . , [v (k) ]} of S ⊥ /S, consider the symmetric matrix Λ representing the dot product:
 
Λ ab   =v   (a)   ·v   (b) .   (V.1)
 
Lemma 1 is equivalent to saying that the matrix Λ is non-singular. Any basis change of S ⊥ /S induces a congruent transformation Λ→M T ΛM. One considers equivalence classes of Λ under the congruent transformations.
 
Lemma 2 (Classification of symmetric forms over    2 ). A non-degenerate symmetric form over    2  is equivalent to one of the two non-equivalent choices:
 
                       I   n     =     (         1                                               ⋱                                               1         )       ,       λ   n     =       I     n   /   2       ⊗       (         0       1           1       0         )     .                 (     V   ⁢   .2     )               
Proof. The two options are not equivalent since X means that the every vector is self-orthogonal, whereas I n  implies that not every vector is self-orthogonal. For completeness, an elementary algorithmic proof is given by manipulating symmetric matrices.
 
     First, it is claimed that any symmetric matrix can be brought to a direct sum of I P  and λ q  for some p≥0 and q≥0, where q is even. If there is a nonzero diagonal element one can bring this to the top-left by permutation. Gaussian elimination on the first column and row reveals that I 1  is a direct summand. Induction gives a direct summand I p , and one is left with a symmetric matrix Λ′ with the zero diagonal. Any column cannot be zero since Λ′ is non-singular, and thus some permutation brings 1 to (2, 1) and (1, 2) entries of Λ′. Gaussian elimination on the first and second columns and rows reveals a direct summand λ 2 . By induction, the first claim is proved. 
     The second claim is that I p+2 ⊗λ q−2 ≅I p ⊗λ q  whenever p, q&gt;0, whose proof is immediate: 
                       (         1       1       1           1       1       0           1       0       1         )     ⁢     (         1                                               1                                               1         )     ⁢     (         1       1       1           1       1       0           1       0       1         )       =     (         1       0       0           0       0       1           0       1       0         )             (     V   ⁢   .3     )               
Therefore, whenever p&gt;0, one has I p ⊗λ q ≅I p+q . If p=0, there is nothing more to prove.
 
     The classification motivates the following notion of bases. 
     Definition 1. Given a null subspace S⊆   2   n , a basis of S ⊥ /S is called (p, q)-magic if the symmetric matrix A representing the dot product on S ⊥ /S among the basis vectors is equal to I p ⊗λ q  for some p≥0 and q≥0. A magic basis odd exists if p&gt;0, or even if p=0. 
     One can summarize the results of this section into a theorem. 
     Theorem 1. For any self-orthogonal subspace S⊆   2   n , there exists a (p, q)-magic basis for S ⊥ /S, where p+q= S ⊥ /S. If p&gt;0 and q&gt;0, then a (p+2, q−2)-magic basis exists. 
     B. CSS Codes From Self-Orthogonal Matrices 
     It is standard to associate a bit string v=(v 1 , . . . , v n ) to a Pauli operator: X(v)=X 1   v     1    . . . X n   v     n    where X j  is the Pauli σ z  on qubit j, and Z(v)=Z 1   v     1    . . . Z n   v     n    where Z n   v     n    is the Pauli σ z  on qubit j. The commutation relation is that
 
 X ( v ) Z ( w )=(−1) v·w   Z ( w ) X ( v ).   (V.4)
 
The CSS construction of quantum codes applies to a self-orthogonal (null) subspace S⊆   2   n : For every vector v∈S, one can define an X-stabilizer X(v) as well as Z-stabilizer Z(v). The set of equivalence classes of X-type (Z-type) logical operators is then in one-to-one correspondence with S ⊥ /S. The number of logical qubits is thus
 
 k=     S   ⊥   /S=n− 2    S.    (V.5)
 
     One can encode logical qubits by choosing a complete set of logical operators {tilde over (X)} (j)  and {tilde over (Z)} (j)  as follows. Choose a (p, q)-magic basis {v (1) , . .. , v (p) , w (1) , . . . , w (q) } of S ⊥ /S.(Here an adapted notation is used to denote an equivalence class (a member of the quotient space) by a representative.) Then, one defines 
                               {               X   ~       (   i   )       =     X   ⁡     (     v     (   i   )       )                       Z   ~       (   i   )       =     Z   ⁡     (     v     (   i   )       )                                       for   ⁢           ⁢   i     =   1     ,   …   ⁢           ,   p   ,               {               X   ~       (     p   +     2   ⁢           ⁢   j     -   1     )       =     X   ⁡     (     w     (       2   ⁢           ⁢   j     -   1     )       )                       Z   ~       (     p   +     2   ⁢           ⁢   j     -   1     )       =     Z   ⁡     (     w     (     2   ⁢           ⁢   j     )       )                       {               X   ~       (     p   +     2   ⁢           ⁢   j       )       =     Z   ⁡     (     w     (       2   ⁢           ⁢   j     -   1     )       )                       Z   ~       (     p   +     2   ⁢           ⁢   j       )       =     X   ⁡     (     w     (     2   ⁢           ⁢   j     )       )                           for   ⁢           ⁢   j     =   1     ,   …   ⁢           ,     q   ⁢     /     ⁢   2.                   (     V   ⁢   .6     )                 
By definition of the magic basis, these logical operators obey the canonical commutation relation of Pauli operators on k qubits:
 
 {tilde over (X)}   (a)   {tilde over (Z)}   (b)=(− 1) δ     ab     {tilde over (Z)}   (b)   {tilde over (X)}   (a) .   (V.7)
 
Note that the commutation relation can be realized with arbitrary signs±in the choice of the logical operators, but induced Clifford logical operators will depend on the signs. (V.6) is enforced in order for the transversal Hadamard  H =H n     inner    to be the logical Hadamard Π a=1   k     inner   {tilde over (H)} (a) .
 
     CSS codes are defined based on self-orthogonal subspaces over    2 : 
     Theorem 2. Let S⊆   2   n  be a self-orthogonal subspace with a (p, q)-magic basis of S ⊥ /S. Then, there exists a CSS code on n qubits with p+q logical qubits and a choice of logical operators such that transversal Hadamard H ⊗n  implements the logical Hadamard for the logical qubits 1, . . . , p, and simultaneously the swaps between the logical qubit p+2j−1 and p+2j where j=1, . . . , q/2. 
     In this disclosure, a weakly self-dual CSS code is called “odd” if the magic basis is odd, and even otherwise. It is possible for an odd code to have an even number of logical qubits, an even number of physical qubits, and an even distance. Every even code, however, has an even number of logical qubits, an even number of physical qubits, and an even distance. 
     It is noted that the CSS codes derived from a self-orthogonal matrices are not too restrictive. By representing each qubit in any stabilizer code of parameters [[n, k, d]] by Majorana modes, one can obtain a weakly self-dual CSS code of parameters [[4n, 2k, 2d]]. See Sergey Bravyi, Bernhard Leemhuis, and Barbara M. Terhal, “Majorana fermion codes,” New J. Phys. 12, 083039 (2010), 1004.3791. This mapping is briefly reviewed in Section VI B. Other families of such codes with improved rate are also presented. 
     VI. Coding Theory and Asymptotic Performance 
     A. Asymptotic Performance 
     In this section, the asymptotic properties of the class of protocols defined above are considered, for appropriate choice and inner and outer codes. Here, possibilities of pipelining are ignored, and only a single inner and outer code to define each protocol are used; this will reduce the question of asymptotic properties to the question of the existence of code families with certain properties. 
     In this discussion, “asymptotic” will refer to one of two limits. In the first limit, consider a family of protocols parametrized by d, the order of reduction in error. An instance in the family reduces error probability from ϵ to a constant times ϵ d  in the limit of small ϵ. It can be proven that 
     Theorem 3. There is a family of protocols parametrized by an integer d≥1 to obtain a d-th order reduction in error, using a total of ⊖(d) physical qubits, producing n outer =⊖(d) magic states. The total number of T gates used is n T =⊖(d 2 ), so that the number of T gates per magic state is ⊖(d). The T-gate depth of the circuit is also ⊖(d), where the T-gate depth refers to the circuit depth assuming that an arbitrary Clifford can be executed in depth 1. 
     In the second limit, one can fix d and consider a family of protocols parametrized by n outer , the number of magic states produced. Here it is proven that 
     Theorem 4. For any odd d≥5, there is a family of protocols using n outer ·(1+o(1)) physical qubits, producing n outer  magic states with a d-th order reduction in error. The total number of T gates used is
 
 n   T =(1+ o (1)) n   outer .   (VI.1)
 
     Given one particular protocol with ϵ out =Cϵ in   d  consuming n T /n outer  T gates per output, an infinite family of protocols can be defined by concatenation with itself. For this concatenated family, the number of T gates to achieve an arbitrarily small error rate δ in output magic states scales like O((log 1/δ) γ ) where the scaling exponent is
 
γ=log d ( n   T   /n   outer ).   (VI.2)
 
See Sergei Bravyi and Alexei Kitaev, “Universal quantum computation with ideal Clifford gates and noisy ancillas,” Phys. Rev. A 71, 022316 (2005), quant-ph/0403025; Sergey Bravyi and Jeongwan Haah, “Magic state distillation with low overhead,” Phys. Rev. A 86, 052329 (2012), 1209.2426.
 
     Smaller values of γ reflect asymptotically more efficient distillation protocols. The triorthogonal codes (see Sergey Bravyi and Jeongwan Haah, “Magic state distillation with low overhead,” Phys. Rev. A 86, 052329 (2012), 1209.2426) achieve γ→log 2 (3), and “multilevel” protocol (see Cody Jones, “Multilevel distillation of magic states for quantum computing,” Phys. Rev. A 87, 042305 (2013), 1210.3388v2) achieves γ→1 + . It was conjectured that no protocol could achieve  7  &lt;1. Both families in Theorems 3 and 4 achieve γ→1 + . 
     It can be noted that the measure γ slightly underestimates the T-count efficiency of the family in Theorem 3. In order to achieve an arbitrary small final error rate δ from a fixed initial error rate, say, ϵ=0.01, one can pick a member P d  of the family of error reduction degree d such that δ&gt;C d (ϵ/2d 2 ) d . Here C d  is the leading coefficient of the output error probability of the protocol P d , which is at most the number of ways that weight d errors occur among n T =O(d 2 ) T gates; C d ≤α(d 2d ) for some α&gt;0 independent of d. For the condition δ&gt;C d (ϵ/d 2 ) d , it suffices that d&gt;(log(1/δ)+log α)/log(1/ϵ). One can initially distill magic states to suppress the error rate from ϵ to ϵ′=ϵ/d 2 , by using a concatenated protocol P init . This takes n init =O(log d) γ  input magic states per output magic states for some γ&gt;1. One can then feed P d  with the outputs from P init  at error rate ϵ′. It follows that
 
 n   T   n   outer   =O ( d )· n   init   =O (log(1/δ)(log log 1/δ) γ )   (VI.3)
 
magic states at error rate ϵ suffice to achieve final accuracy δ. Thus, the scaling of n T /n outer  is linear in log(1/δ) up to a logarithmic correction. (One can iterate the argument recursively to further slow down the dependency on 1/δ.)
 
     Theorem 4 will use odd codes. The reduced number of T gates required to implement checks with an odd code is essential to obtaining the number of T gates in the theorem (one would need roughly twice as many using even codes). This explains why d is chosen odd. The case of d=1 is of course trivial: no codes are needed. 
     Theorems 3, 4 will follow almost immediately given certain families of inner and outer codes obeying certain properties of the codes that are defined below. These theorems are proven given these properties in this subsection and families of inner and outer codes are constructed with these properties in subsections VIB and VIC. 
     Consider first the inner code. This code will have k inner  logical qubits and n inner  physical qubits. The distance of the inner code will be at least d. Consider then the effect of errors in the T gates inside the inner code; e.g., in the T gates acting on the encoded state. To obtain d-th order reduction in error, it suffices to consider the case that fewer than d errors occur in such T gates. Since the inner code distance is at least d, these errors cannot produce a logical error. There is one way, however, in which these errors can have an effect without being detected by the inner code. It is possible that a pair of errors act inside the inner code, both on T gates acting on the same qubit. The effect of these errors is to cause an error in the check being measured by the inner code, e.g., if the check was measuring a given product of W operators specified by the outer code, one can instead measure the opposite sign; referred to herein as “measurement error”. 
     The possibility of measurement errors affects some of the properties that are attributes of the outer code. Desirably, the outer code has a distance of at least d, as otherwise a pattern of fewer than d errors in the input magic states could cause an undetectable error, but this is not sufficient. It is desirable that a pattern of fewer than d errors causes enough checks to be violated so that even a small number of measurement errors will lead to an error detected by the code. This is defined by the property of “sensitivity” that is now defined. 
     The outer code will have m parity checks, encoded in an m-by-n outer  parity check matrix M, where each row of the matrix indicates a given check. One can measure rows of this matrix with even weight using an even inner code and rows with odd weight using an odd inner code. For simplicity, and without limitation, all rows can have even weight or all rows can use use odd weight so that one can use the same inner code for all checks. (More generally, one could use both an inner and an outer code). Then, this inner code must have k inner  greater than or equal to the maximum row weight of M. In this case, one can say that the inner code can implement the checks of the outer code. 
     Definition 2. An m-by-n outer  parity check matrix M for a classical linear code is said to be ( d , s)-sensitive if any nonzero bit vector v of length n outer  with |v|≤ d . It follows that |Mv|≥s. That is, for any such vector, the number of violated parity checks is at least s. 
     It can be emphasized that sensitivity is a property of the check matrix of the outer code, rather than the codewords of the outer code, and in some examples the rows of the check matrix may be linearly dependent. 
     A ( d , s)-sensitive parity check matrix is ( d −1, s)-sensitive by definition. 
     Lemma 3. Given a parity check matrix M such that 2|Mv|+|v|≥d for an nonzero v 
               (       e   .   g   .           ⁢     (       d   -   1     ,           d   -   1             2           )       ⁢     -     ⁢   sensitive   ⁢           ⁢   M     )     ,         
and given an inner code of distance d that can implement the checks defined by M, the protocol yields d-th order reduction in error.
 
Proof. Any error pattern inside the inner codes with weight less than d cannot cause a logical error. Thus, if an error pattern inside the inner code does not violate a stabilizer of the inner code, it either has no effect or it leads to an error in measurement of a check of the outer code; the latter possibility requires at least two errors inside the inner code. Any input state with |v|≥1 errors will violate at least |Mv|≥(d−|v|)/2 checks of the outer code. If no violation of these checks is detected, there must be at least 2|Mv| errors on T gates inside the inner code. Thus, there must be at least d errors in total.
 
     Now, some asymptotic properties of the codes are defined. 
     Definition 3. A family of quantum error correcting codes with increasing number of qubits n has good rate if the number of encoded qubits k is ⊖(n) and has good distance if the distance d is ⊖(n). 
     Definition 4. Given a family of outer codes with increasing n outer , one can say that this family has good sensitivity if each code in the family is ( d , s)-sensitive for  d =⊖(n outer ) and s=⊖(n outer ). 
     Definition 5. Given a family of outer codes with increasing n outer , one can say that this family has good check rate if the parity check matrix is m-by-n outer  with m=⊖(n outer ). 
     Proof of Theorem 3. In subsection VI B, it is shown that families of both even and odd inner codes with good rate and distance exist, and in subsection VI C, it shown that families of outer codes with good check rate, good sensitivity, and even row weight exist. Combining these results with Lemma 3, theorem3 follows.
 
Proof of Theorem 4. In subsection VIB., it is shown that, for any d, there exist families of both even and odd inner codes with increasing n inner  such that k inner /n inner →1. To prove this theorem, one will only need the result for odd inner codes. Consider some code from this family with given k inner , n inner . In subsection VIC, Lemma 9 is shown, which is reproduced here:
 
Lemma. Given integers  d , w≥1 and s≥2, there exists an m×n outer  parity check matrix M that is ( d , s)-sensitive where m=n outer ·s/w and every row of M has weight w exactly.
 
     Choose w=k inner . Choosing  d ≥d−1 and s=(d−1)/2, this gives an outer code such that the checks can be performed by the given inner code and one can perform n outer  (s/w)=n outer  (S/k inner ) checks with the inner code. Each such check with the inner code requires using 2n inner  T gates, so that the total number of T gates needed to perform the checks with the inner code is equal to 2n outer s(n inner /k inner ). Additionally, one can perform n outer  T gates to create the input magic states to the outer code. Thus, the total number of T gates is 
                           n   T     =       ⁢       n   outer     ⁡     (     1   +     2   ⁢           ⁢       sn   inner     /     k   inner           )                   =       ⁢         n   outer     ⁡     (     d   +       (     d   -   1     )     ⁢     (         n   inner     /     k   inner       -   1     )         )       .                   (     VI   ⁢   .4     )               
Taking n inner  large so n inner /k inner →1, it can be concluded that n T →n outer d.
 
     One can now see better why d≥5 was used in Theorem 4. This is because for d=3, one has s=1 and lemma 9 does not apply. It will be explained later why the case s=1 is excluded from that lemma; roughly, this is because in this case, each bit participates in only a single check and one would lack certain expansion properties for a certain graph defined later. 
     B. Inner Codes 
     In this subsection, asymptotic constructions of inner codes are disclosed. Also in this subsection, a few constructions of weakly self-dual codes with good rate and distance are discussed as well as improvements to these schemes offered by the disclosed technology. 
     First, A. R. Calderbank and Peter W. Shor, “Good quantum error-correcting codes exist,” Phys. Rev. A 54, 10981105 (1996), quant-ph/9512032 shows that, given any ratio d/n, one can find a family of weakly self-dual CSS codes with 17 qubits and distance d and given ratio d/n achieving a rate k/n→1−2H 2 (d/n), where H 2  is the binary entropy function. The codes found in that paper all are even codes. However, the disclosed technology can obtain odd codes from them by a “puncturing procedure” (see also section 3.5 of Daniel Gottesman, “Stabilizer codes and quantum error correction,” (1997), quant-ph/9705052: 
     Definition 6. Given an even weakly-self-dual CSS code C on n qubits with k logical qubits, define a “punctured code” C′ as follows. Choose a qubit i (the code C′ may depend upon the choice of i). Write the stabilizer generators of C such that only one X-type and one Z-type generator is supported on i. Define C′ by removing qubit i and removing the stabilizer generators support on i. Then C′ has n′=n−1 qubits and k+1 logical qubits. The code C′ is an odd code by construction. 
     If C is non-degenerate with distance d, then C′ has distance d′≥d−1. More generally, d′+1 is greater than or equal to the minimum weight of an operator which commutes with the stabilizer group of C, because given an X-type logical operator O in C′ then either O or OX i  must commute with the stabilizer group of C. Indeed, one may show that puncturing the codes of A. R. Calderbank and Peter W. Shor, “Good quantum error-correcting codes exist,” Phys. Rev. A 54, 10981105 (1996), quant-ph/9512032 reduces the distance by at most 1. 
     The only disadvantage of this proof is that it is a greedy proof that is not known how to implement efficiently. One example of doing this is a randomized construction which allows one to give codes which, with high probability, have the desired distance. Unfortunately, this construction will only achieve k/n→½−H 2 (2d/n). This construction uses a general method to construct weakly self-dual CSS codes in Sergey Bravyi, Bernhard Leemhuis, and Barbara M. Terhal, “Majorana fermion codes,” New J.Phys. 12, 083039 (2010), 1004.3791. 
     Consider a stabilizer code C qubit  which acts on n physical qubits and has k logical qubits and distance d. From this code, one can derive a code for Majorana fermions C Majorana  which acts on 4n Majorana modes and has k logical qubits and distance 2d, where now the distance refers to minimum weight of a product of Majorana operators that is a logical operator. The code C Majorana  is derived in the following way: For each physical qubit of C qubit , one introduces four Majorana modes, γ 0 , γ 1 , γ 2 , γ 3 , and declares that the product γ 0 γ 1 γ 2 γ 3  is a stabilizer of C Majorana . For each stabilizer of C qubit , one defines a stabilizer of C Majorana  by replacing X on a qubit by iγ 0 γ 1 , Y by iγ 0 γ 2 , and Z by iγ 0 γ 3 . The stabilizer generators of C Majorana  are given by bit strings of length 4n such that the dot product over    2  of any pair of such bit strings is 0. Thus, from C Majorana , one can define a weakly self-dual CSS code C wsd  with 4n physical qubits, 2k logical qubits and distance 2d. Since a randomized construction (see, for example, Eq. 7.200 of John Preskill, “Lecture notes on quantum computation,” Caltech Ph219.) gives stabilizer codes C qubit  with k/n→1−H 2  (d/n)−(d/n) log 2 (3), mapping these stabilizer codes C qubit  to weakly-self dual codes C wsd  gives k/n→(½)[1−H 2  (2d/n)−(2d/n) log 2 (3)]. Since the randomized construction gives a lower bound to the weight of any operator commuting with the stabilizer group, one can puncture these codes and reduce the distance by at most 1. 
     Another proof of the existence of such good weakly self dual-codes is given below. This next proof will lead to rate k/n→1−2H 2 (d/n). For any fixed distance d, one can obtain families of stabilizer codes with n physical qubits and k logical qubits with the ratio k/n→1 as n→∞. While this improvement is only by constant factors over the construction via Majorana codes, it will lead to nice asymptotic expressions for the number of T-gates, n T , required to attain d-th order suppression in error. It is also a randomized construction, showing that codes in a certain ensemble have the desired properties with high probability. 
     Define a random ensemble of n-by-c weakly self-orthogonal matrices as follows, where a matrix M is defined to be self-orthogonal if MM T =0. Choose the first row of the matrix to be the all 1s vector {right arrow over (1)}. Choose the second row uniformly at random subject to the constraint that it have vanishing dot product with the first row. Continue in this fashion, choosing the j-th row uniformly at random subject to the constraint that it have vanishing dot product with the first j−1 rows. (Remark: the restriction that the first row be the all is vector is simply chosen to simplify some notation, so that one does not need to add the requirement that each row have even weight.) 
     Lemma 4. Consider a fixed n-component vector v, with v≠0 and v≠{right arrow over (1)}. For a random c-by-n self-orthogonal M, the probability that Mv=0 is at most 2 −c+1 +2 −n+c+1 . 
     Proof. Let w 1 , . . . , w c  be the rows of M. Let V j  be the self-orthogonal subspace which is the span of the first j rows of M. One can estimate the desired probability by a union bound, considering separately the event that v∈V c   ⊥  and v∉V c , and the event that v∈V c   ⊥  and v∈V c . 
     Consider the first event. Let j&gt;1. Then 
                       Pr   ⁡     [         w   j     ·   v     =     0   ❘     v   ∉     V     j   -   1             ]       =         1           2           ,           (     VI   ⁢   .5     )               
because the constraint that (v, w j )=0 is independent of the constraints on the vector w j . Thus, for any k,
 
                       Pr   ⁡     [     v   ∈       V   k   ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∉     V   k       ]       ≤       ∏     j   =   2     k     ⁢           ⁢         1           2             =       2       -   k     +   1       .             (     VI   ⁢   .6     )               
For k=c, one can find in particular that
 
 Pr[v∈V   c   ⊥  and v∉V c ]≤2 −c+1 .   (VI.7)
 
     Now one can estimate the probability of the second event. Note that if v∈V c , there is a least j such that v∈V j . So, 
                     Pr   ⁡     [     v   ∈       V   c   ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∈     V   c       ]       ≤       ∑     j   =   2     c     ⁢           ⁢       Pr   ⁡     [     v   ∈       V   j     ⁢           ⁢   and   ⁢           ⁢   v     ∈       V     j   -   1     ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∉     V     j   -   1         ]       .               (     VI   ⁢   .8     )               
We have
 
                       Pr   ⁡     [     v   ∈       V   j     ⁢           ⁢   and   ⁢           ⁢   v     ∈       V     j   -   1     ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∉     V     j   -   1         ]       =         Pr   ⁡     [     v   ∈       V     j   -   1     ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∉     V     j   -   1         ]       ·     Pr   ⁡     [       v   ∈     V   j       ❘     v   ∈       V     j   -   1     ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∉     V     j   -   1           ]         ≤       2       -   j     +   2       ⁢     Pr   ⁡     [       v   ∈     V   j       ❘     v   ∈       V     j   -   1     ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∉     V     j   -   1           ]             ,           (     VI   ⁢   .9     )               
where Eq. (VI.6) was used.
 
     Now one can estimate the probability Pr[v∈V j |v∈V j−1   ⊥  and v∉V j−1 ]. This is possibly nonzero only if v·v=0. Consider the space of all n-component vectors modulo vectors in V j−1 ; this quotient space has dimension at least n−(j−1). Let π be the natural map from the space of all vectors to this quotient space. The vector 711) is nonzero by assumption. The vector w j  is subject to at most j−1 independent constraints from V j−1 . Consider the space of possible πw j , given that w j  obeys those constraints; this space has dimension at least n−2(j−1) and so the probability that a random vector in this space is equal to πv is at most 2 −(n−2j+2) . Hence, Pr[v∈V j |v∈V j−1   ⊥  and v∉V j−1 ]≤2 −(n−2j+2) , so Pr[v∈V j  and v∈V j−1   ⊥  and v∉V j−1 ]≤2 −n+j . So by Eq. (VI.8), 
                     Pr   ⁡     [     v   ∈       V   c   ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∈     V   c       ]       ≤       ∑     j   =   2     c     ⁢           ⁢     2       -   n     +   j         ≤       2       -   n     +   c   +   1       .             (     VI   ⁢   .10     )               
By a union bound, adding probabilities in Eqs. (VI.7,VI.10), the lemma follows.
 
Lemma 5. Let n, c, d be such that
 
                       (       2       -   n     +   c   +   1       +     2       -   c     +   1         )     ⁢       ∑     w   =   1     d     ⁢           ⁢     (         n           w         )         &lt;   1.           (     VI   ⁢   .11     )               
Then, there exists an c-by-n matrix M such that MM T =0 and such that Mv≠0 for any v≠0 with v having Hamming weight at most d.
 
Proof. This follows from lemma 4 and by a first moment bound. For random M from the above ensemble, the average number of vectors v≠0 with Hamming weight at most d such that M T v=0 is at most
 
                     ⁢       (       ∑     w   =   1     d     ⁢     (         n           w         )       )     ·       (       2       -   n     +   c   +   1       +     2       -   c     +   1         )     .             
Lemma 6. For any fixed d, one can find a family of M with increasing n such that the ratio c/n tends asymptotically to zero and such that Eq. (VI.11) is obeyed. Hence, for any distance d, one can find a family of even or odd weakly self-dual CSS codes such that the ratio k inner /n inner →1 as n inner →∞.
 
Proof. Immediate for the even case. Since the lemma 4 upper bounds the probability that an operator commutes with the stabilizer group one can also puncture these codes to obtain an odd code.
 
     C. Outer Codes 
     In this subsection, families of outer codes are constructed with good check rate and sensitivity. The discussion begins with a randomized construction, and then it is shown how to construct explicit families using previous results in coding theory. 
     Lemma 7. There exist families of outer codes with good check rate and sensitivity and even row weight. 
     Proof. Consider a random m-by-n outer  parity check matrix M. Let  d =n outer −1. Choose each row independently but with the constraint that it should be of even weight. For any vector v with |v|≤ d , the syndrome vector Mv has independent entries from the uniform distribution. Thus, the probability that |Mv|≤s for s≤m/2 is bounded by 
                   2     -   m       ⁢       ∑     i   ≤   s       ⁢     (         m           i         )         =       𝔒   *     ⁡     (     2     m   ⁡     (       H   ⁡     (     s   /   m     )       -   1     )         )         ,         
where H(p)=−plog 2 (p) (1−p) log 2 (1−p) is the binary entropy function. The number of such vectors v is bounded by 2 n     outer   . By a union bound, the probability that there is an error vector v of weight less than d such that the syndrome has weight less than s is bounded by
 
 *(2 m(H (s/m)−1) 2 n     outer   = *(2 n     outer     ·(1+(m/n     outer     )(H(s/m)−1) ).
 
For sufficiently large ratio m/n outer  and sufficiently small ratio s/m, this quantity is exponentially small in n outer .
 
     The above randomized construction is very similar to randomized constructions of classical codes with good rate and distance, where it is defined 
     Definition 7. A family of classical error correcting codes with increasing number of bits n has good rate if the number of encoded bits k is ⊖(n) and has good distance if the distance d is ⊖(n). 
     That is, even though very different properties are being considered (number of violated checks rather than distance of the code), the first moment argument above is very similar to standard first moment arguments to construct such codes with good rate and distance, with some additional technicalities required to ensure even weight of the parity checks. This is not a coincidence. As will now be shown, given a family of codes with good rate and distance, one can construct a family of codes with good check rate and sensitivity. 
     Lemma 8. Let C be a classical error correcting code that encodes k bit messages into n bit code-words. Let C have distance d. Let v 1 , . . . , v k  be a basis for the codewords of C. Let M be the n-by-(k+1) matrix whose columns are the vectors v 1 , . . . , v k , w where w=v 1 + . . . +v k . Then, all rows of M have even weight and M is a parity check matrix for a code with n outer =k+1 bits which is ( d , s) sensitive with s=d and  d =n outer −1. Thus, the code with parity checks encoded by M has only two codewords (the all 0 vector and the all 1 vector) and any message which is not a codeword will violate at least d checks.
 
Proof. For any (k+1)-bit vector v, the vector Mv is a codeword of C. If v is nonzero and is not equal to the all 1 vector, then Mv is a nonzero codeword of C and hence has weight at least d.
 
     Since n outer =k+1, in order to obtain an even n outer , if C has k even, one can simply define a new code C′ which encodes k−1 bit messages into n bit codewords by using any (k−1)-dimensional subspace of the codewords of C, in this way obtaining a parity check matrix for a code with n outer −k−1+1=k. 
     Using lemma 8, one can construct explicit families of codes with good check rate and good sensitivity given any explicit family of codes with good rate and good distance. As an example of such a code family, one can use the expander codes of Michael Sipser and Daniel A Spielman, “Expander codes,” IEEE Transactions on Information Theory 42, 17101722 (1996). 
     Lemma 9. Given integers  d , w≥1 and s≥2, there exists an m×n nouter  parity check matrix M that is ( d , s)-sensitive where m=n outer ·s/w and every row of M has weight w exactly. 
     Proof. A parity check matrix M defines a bipartite graph G, often called a Tanner graph. One set of vertices of the graph (which we call B labeled by the columns of M) corresponds to bits of the code and the other set (which we call C labeled by the rows of M) corresponds to checks, with an edge between a pair of vertices if M is nonzero in the corresponding entry. Equivalently, given such a bipartite graph G, this defines a parity check matrix. It can be claimed that given a bipartite graph with all vertices in B having degree s and all vertices in C having degree w and with girth&gt;2 d , the corresponding parity check matrix defines a code with the desired properties. Once this has been shown, the lemma follows, since Z Furedi, Felix Lazebnik, A Seress, Vasiliy A Ustimenko, and Andrew J Woldar, “Graphs of prescribed girth and bi-degree,” Journal of Combinatorial Theory, Series B 64, 228-239 (1995) shows the existence of such graphs. 
     Note first that the degree of vertices in C corresponds to the row weight of M. Next, note that if all vertices in C have degree w and all in B have degree s, then 
             m   =          C        =     n     outer   w   s               
with n outer =|B|.
 
     To prove the claim, let V⊆B be a nonempty set of erroneous bits. By assumption, 1≤|V|≤ d . Consider a subgraph H of G defined by all vertices of V and its neighbors. By the girth condition on G, the subgraph H has to be a collection of disjoint trees. Thus, it suffices to prove the claim in case where H is connected. If |V|=1, then the error violates s checks, and the proof is done. If |V|≥2, let v 1 , v 2 ∈V be a pair that are the furthest apart. The choice of the pair ensures that each of v 1  and v 2  has s−1 leaves attached to it. Therefore, V violates at least 2s−2≥s checks. 
     Note that the ratio m/n outer =s/w in lemma 9 is the best possible, because each bit must participate in at least s checks (e.g., every column of the parity check matrix must have weight at least s). 
     Now consider the question of finding small Tanner graphs with the desired properties. It will now be shown that any such Tanner graph with girth 6 or more (which implies that the checks are non-overlapping) and which defines a code with distance 7 or more will give an outer code that gives seventh order reduction in error when used with an inner code of distance 7 or more. First, any single input error will violate 3 checks, since every bit is in three checks. Any pair of input errors on qubits q 1 , q 2  must violate at least 4 checks (each qubit is in 3 checks, and since the checks are nonoverlapping, there is at most one check containing both q 1 , q 2 ). Any three input errors on qubits q 1 , q 2 , q 3  must also violate at least 3 checks (there is at most one check containing q 1 , q 2  and at most one check containing q 2 , q 3  and at most one check containing q 1 , q 3 ). Any four input errors on qubits  qi,  q 2 , q 3 , q 4  must violate at least 2 checks (the number of violated checks must be even since there are an even number of input errors, and by the distance assumption, there is no pattern on four qubits that violates no checks). By the distance assumption, any five or six input errors must violate at least one check. 
     Numerical searches were performed for graphs with the needed girth which defined a code with the needed distance as follows: an integer m was chosen and an outer code searched with mk inner  qubits and 3m checks. The search was an iterative randomized procedure. The graph was initialized by taking m copies of the complete bipartite graph on k inner  qubits and 3 checks. This initial graph clearly does not obey the girth bound (all three of the checks in each copy are identical). An iterative random search was performed to find a graph with girth 6 or more; this search proceeded by first finding a 4-cycle, then choosing an edge (q, C) between a qubit q and an edge C in that 4-cycle, then choosing another random edge (q′, C′) and replacing the pair (q, C) and (q′, C′) with (q, C′) and (q′, C). This procedure was repeated until the graph had girth 6 or more. Then, an additional random search was performed; this search also replaced pairs of edges (q, C) and (q′, C′) with (q, C′) and (q′,C); in this case, the pairs were chosen randomly subject to the constraint that no 4-cycle is created. After a large number of such steps, the determination of whether the resulting code had distance 7 was tested; this test was done by searching for an error pattern of weight 6 or less that does not violate an outer code check; some tricks were done to speed this search (for example, if a qubit q has an error, and if q is in checks C 1 , C 2 , C 3  then there must be qubits q 1 ∈C 1 , q 2 ∈C 2 , q 3 ∈C 3  with q 1 , q 2 , q 3 ≠q such that q 1 , q 2 , q 3  all have errors). 
     For k inner =5, 7, 9, 11, 13, for m=k inner +1, graphs were found with girth 6 by random search. Note that there exist graphs with girth 6 with m=k inner  (the grid code with horizontal, vertical, and one diagonal is an example of such). The graphs give concrete examples of outer codes which obey the distance and sensitivity bounds. 
     Outer codes were also found that obey the distance and sensitivity bounds with n outer =mk inner  qubits for smaller values of m by taking more checks. This was done by finding graphs of girth 6 or more as described above and then performing a large number of random updates of these graphs keeping girth≥6. Then, if the resulting code had distance 5 or 6, attempts were made to numerically find whether one could add a small number of checks to that code to obtain a code with distance 7, repeating the search until success. The resulting code then gives seventh order reduction and, since only a few checks are added, has close to the minimum number of input magic states. 
     The results of these searches are shown in table I. 
     
       
         
           
               
             
               
                 TABLE I 
               
             
            
               
                   
               
               
                 For given degree equal to k inner , the second column labelled m shows  
               
               
                 the minimum m at which we found a constant degree Tanner graph  
               
               
                 giving a code obeying the weight and sensitivity bounds. The third  
               
               
                 column m with added checks shows the minimum m giving a code  
               
               
                 obeying the weight and sensitivity bounds where we add one or  
               
               
                 two checks to a constant degree Tanner graph. 
               
            
           
           
               
               
               
            
               
                 k inner    
                 m  
                 m with added checks 
               
               
                   
               
            
           
           
               
               
               
            
               
                 5 
                 7 
                   
               
               
                 7 
                 13 
                 10 
               
               
                 9 
                 19 
                 14 
               
               
                 11 
                 33 
                 20 
               
               
                 13 
                 45 
                 29 
               
               
                   
               
            
           
         
       
     
     VII. Numerical Simulation 
     In this section, results of numerical simulations are given. The discussion begins with an explanation of the error model used for simulations. The discussion also includes an explanation of two protocols that are simulated and that have not been explained previously; one of these protocols uses a [[21, 3, 5]] code. Simulation results are the given. One interesting result of the simulation is how little effect the subleading terms have, even at fairly large noise values. 
     A. Magic State Fidelity 
     When one injects a magic state μ for π/4 rotation into a quantum circuit, there is a probability for correction K by angle π/2 to be applied. If one represents the overall procedure by a quantum channel C μ , it is C μ (ρ)=Π + (ρ⊗μ)Π + +KΠ − (ρ⊗μ)Π − K † , where Π ±  denotes the measurement combined with a control-Pauli on the magic state and a target data qubit. Let |μ 0    be the ideal magic state, and |μ 0   ⊥    be the orthogonal state. Then, it is straightforward to calculate that C |μ     0       μ 0   ⊥ |+|μ 0   ⊥     μ 0 |(ρ)=0. 
     This implies that for any initial approximate magic state μ, the result of the injection is the same as if μ had been through a twirling channel ϵ that dephases the magic state in the basis {|μ 0   , |μ 0   ⊥   }: 
                   μ   =         (           1   -   ϵ         *           *       ϵ         )     ⁢     ⟶   ϵ     ⁢     (           1   -   ϵ         0           0       ϵ         )       .             (     VII   ⁢   .1     )               
The twirled state is e away from the ideal state in the trace distance,resulting in error at most ϵ to the quantum circuit&#39;s outcome. (The trace distance is defined as
 
                 T   ⁡     (     ρ   ,   σ     )       =           1           2         ⁢              ρ   -   σ          1     .         )         
The error ϵ can be expressed by the squared fidelityas
 
1−ϵ= F   2  (μ 0 , μ)= μ 0 |μ|μ 0   = μ 0 |ϵ(μ)|μ 0   .   (VII.2)
 
(The fidelity is defined as F(ρ, σ)=∥√ρ√σ∥ 1 , which is equal to | ρ|σ | for pure ρ and σo.) This formula is convenient in that it yields the same answer regardless of whether or not twirling is applied to μ (this is the last equality in the above formula). When a state μ n  that approximates μ 0   ⊗n  is injected, the error from this multi-qubit magic state is given by 1−F 2 (μ 0   ⊗n , μ n ). Note that F 2 (μ 0 ,μ) is linear in μ. Below, 1−F 2  is used as the probability of error to report the simulation results.
 
     B. Error Models 
     The typical model to analyze distillation protocols is the stochastic error model. In typical distillation protocols, one has only a single output magic state, and so one is interested in the probability that the output magic state has an error as a function of the input, conditioned on no error being detected by the code; the error probability is a ratio of polynomials in ϵ, with the leading term being of order ϵ d  for some d, with an integer coefficient. 
     For purposes of this discussion, since the codes used are fairly large, enumeration of all possible error patterns becomes difficult, especially if one wishes to go beyond leading order in e. For this reason, numerical simulation is used. One could simulate a mixed state, using a quantum channel to describe an approximate T-gate; however, this is numerically prohibitive and it is preferred to use an approach that involves only pure states. One could numerically simulate pure states using the stochastic error model by choosing errors to occur with probability p, and sampling the output error probability. However, this simulation also becomes difficult, precisely because the codes lead to a high suppression in the error. For example, if the target error probability is 10 −10 , one would require ˜10 10  samples, with a fairly large number of qubits needed to be simulated in each run, to determine the output error probability accurately. 
     While there may be ways to overcome this sampling issue using importance sampling, in certain embodiments of the disclosed technology, another method is used. Instead of rotating by either π/4 or by 5π/4 as in the stochastic error model, each T gate rotates by an angle chosen uniformly in the interval [π/4−θ, π/4+θ], for some angle θ&gt;0. Then, conditioned on the code not detecting an error, one can determine the error in the output state. 
     In fact, the model with input angles [π/4−θ, π/4+θ] and the stochastic error model describe the same average input state, assuming an appropriate choice of ϵ and θ. 
                             1             2   ⁢           ⁢   θ           ⁢       ∫     [       -   θ     ,     +   θ       ]               ⁢     dx   ⁡     (           cos   2     2   ⁢   x               sin   2   x     ⁢     cos   2   x                   sin   2   x     ⁢     cos   2   x             sin   2     2   ⁢   x             )           =         (     1   -   ϵ     )     ⁢     (         1       0           0       0         )       +     ϵ   ⁡     (         0       0           0       1         )           ⁢     
     ⁢           ⁢             1           2         -           sin   ⁢           ⁢   θ               2   ⁢           ⁢   θ             =   ϵ             (     VII   ⁢   .3     )               
Hence, one wants ϵ≈θ 2 /12. (It is emphasized that this is in a notation where θ is the rotation angle in the Bloch sphere; the T-gate is a rotation by π/4, not by π/8.) From this equation, it is evident that the sample average in the random angle model converges faster to its true average. In the stochastic error model with small ϵ, one must do roughly 1/ϵ runs to obtain meaningful statistics, while here, one needs only a constant number of runs.
 
     C. Other Protocols 
     1. [[16, 2, 4]] Inner Code 
     In subsubsection III B 2 it was explained that a protocol using a [[16, 6, 4]] inner code. This required using a total of 17 physical qubits, namely 16 for the code and one ancilla. One can also modify this inner code to a [[16, 2, 4]] inner code by turning some of the logical operators into checks. This inner code suffices to implement the H-measurements on pairs of states (23), (45), (61) and so it can implement the checks of the outer code used in subsubsection III B 2. Using a [[16, 2, 4]] inner code, if one wants to have n outer =6, a total of 21 physical qubits can be used, since one needs 16 for the code, plus 4 for the logical qubits not encoded in the code, plus one ancilla. Thus, this requires additional physical qubits compared to the [[16, 6, 4]] code. The reason for considering the [[16, 2, 4]] code in numerics is to see if it reduces the prefactor in the error, since the [[16, 2, 4]] code has fewer logical operators than the [[16, 6, 4]] code. The protocol can be pipelined e.g., with the [[16, 2, 4]] inner code in the same way as done with the [[16, 6,4]] inner code. 
     See FIG. 6 in Section XI. 
     2. [[21, 3, 5]] Inner Code 
     Another inner code that was used is a [[21, 3, 5]] inner code. This allows one to obtain fifth order reduction in error. r outer  =4 was used with the outer code having check matrix 
                   M   =       (         1       1       1       0           1       1       0       1           1       0       1       1           0       1       1       1         )     .             (     VII   ⁢   .4     )               
It uses 4 checks for 4 qubits. This matrix is not (4, 2)-sensitive, but is sufficient to achieve fifth order reduction in error since 2|Mv|+|v|≥5 for every nonzero v. See  FIG. 9  in Section XI.
 
     A simple pipelining can reduce the noisy T gate count compared to this protocol. Distill three independent magic states using [[7, 1, 3]] inner code. (The outer code is trivial in this case.) The three distilled magic states are then pipelined into the [[21, 3, 5]] inner code. This produces 3 magic states with error O(ϵ 5 ), consuming, per output, 28 T gates and one T state with error E. 
     Without pipelining, but using weight 3 checks from [[21, 3,5]], one can find an outer code that is (4, 2) sensitive using (2/3)n outer  checks. This produces n outer  magic states with fifth order error suppression, consuming 42·⅔=28 T gates and one T state, per output. The smallest such outer code is explained elsewhere herein, where it is called the Petersen graph code. 
     D. [[23, 1, 7]] Inner Code 
     A [[23, 1, 7]] inner code is also given in this disclosure. Pipelining this code with a [[7, 1, 3]] and a [[17, 1, 5]] inner code gives n outer =1 with error O(ϵ 7 ). One could also apply this code to each of the output bits of any of the other fifth order protocols of section VII C 2 to obtain error O(ϵ 7 ). 
     E. Results 
     The results of the simulations are shown in  FIG. 5 . Note that the plots are close to linear on a log-log plot, with only small deviations at high error rate. Each data point represents the average of at least 10 4  runs, with statistical fluctuations negligible on the scale of the plot. The asymptotic behavior is within statistical error of that given by an enumeration of minimum weight error patterns. The protocol using [[16, 2, 4]] inner code has a slightly reduced output error, compared to the protocol using the [[16, 6, 4]] inner code. 
     It is emphasized that g out  indicates the probability that there is any error in the output state which is a multi-qubit state. Suppose that two protocols give the same value of ϵ out  for a given ϵ in , but one protocol has a large n outer . If the total number of magic states is large compared to n outer , the number of times one desirably calls the protocol is inversely proportional to n outer , and so the protocol with the larger n outer  for the given ϵ out  is less likely to produce an error. 
     The probability that no error is detected by the protocol is roughly (1−ϵ in ) n T. This result would be exact if any error in an input T gate led to the protocol detecting an error. Instead, some high weight error patterns do not lead to any error detected by the code, leading to slight corrections to this formula. 
       FIG. 5  shows results of numerical simulations. ϵ in  represents input error; this is the error e of Eq. (VII.3) for the given θ. ϵ out  is the average of 1− μ 0 |μ|μ 0    over runs. The numbers labelling curves indicate the number of physical qubits, not including the ancilla qubit. Specifically, 4 indicates protocol using [[4, 2, 2]] inner code. 7 indicates protocol using [[7, 1, 3]] inner code. 15 is the Bravyi-Kitaev 15-to-1 protocol included for comparison purposes; 7 and 15 have almost identical performance. 16 is pipelined protocol using [[16, 6, 4]] inner code; 20 is pipelined protocol using [[16, 2, 4]] inner code. 17 is pipelined protocol using [[17, 1, 5]] inner code. 22 is protocol using [[21, 3, 5]] inner code with n outer  =4. 21 is protocol using [[21, 3, 5]] inner code pipelined with [[7, 1, 3]] inner code. 17, 21, and 22 have almost identical performance. 23 is protocol using [[23, 1, 7]] inner code. 
     VIII. Protocols at Intermediate Size 
     In this section, a family of protocols that work well at intermediate sizes is presented. These protocols achieve a ratio n T /n outer  that is fairly close to asymptotically optimal (e.g., close to 6) even for modest sizes. They also achieve a high success rate by a modification of the previous protocols: the usual approach is that if an error is detected, either by a stabilizer measurement of the inner code or by a measurement of the outer code, a failure is declared and the process is tried again. Instead, in certain embodiments, an error correction scheme is used in some cases to fix errors while maintaining seventh order reduction in error. 
     The first ingredient is an inner code. In certain example embodiments, quantum BCH codes are used. See Markus Grassi and Thomas Beth, “Quantum bch codes,” arXiv preprint quant-ph/9910060 (1999). There are quantum BCH codes that are weakly self-dual CSS codes, with parameters such as [[63, 27, 7]] or [[63, 39, 5]] or [[127, 85, 7]] or [[127, 99, 5]]. Thus, the ratio k inner /n inner  is fairly large for these codes even at modest sizes for distance 5 or 7. 
     The second ingredient is an outer code. Here, a few possibilities can be considered. Before generalizing, consider the following example. Let n outer =mn, for some m, n, and imagine the qubits as arranged in an m-by-n grid. One can take m =D inner  for some given inner code and n=k inner  for some other inner code. The outer code has two types of checks, corresponding to rows and columns of the grid. These checks can be parallelized, so that all checks of a given type are performed at the same time. In particular embodiments, the rows are done first, then the columns (though other embodiments use the reverse order); the row measurements can be done in parallel, as can the column measurements. 
     This outer code has distance four, and this protocol will achieve fourth order reduction in error. One can say that a row or column detects an error if there is an error detected by either the stabilizer measurements of the inner code for that column or by the check of the outer code for that column. One can also say that there is a measurement in the check of an outer code if the check shows no error but there is indeed an error. 
     In certain example embodiments, the following protocol is performed:
         1. Check the rows using any inner code of distance at least 2. If there is an error detected by any given row R, re-initialize the qubits in that row to approximate magic states and repeat the measurement on the row. At this point, the rows are independent (unentangled with each other), so repeating the measurements on a given row has no effect on the other rows.   2. Check the columns using any inner code of distance at least 4. If there is an error detected by any column, discard the qubits in that column.   3. The remaining qubits are approximate magic states with error O(ϵ 4 ).       

     Before analyzing the output error rate, a distinction will first be discussed. Previously, when showing that an output error was reduced to fourth order (for example), it sufficed to show that any pattern of T-gate errors which led to no error being detected and which led to an output error had at least four T-gate errors. Now, however, one is conditioning on the fact that some errors did occur: for example, if an error is detected by a stabilizer measurement in some column, it is known that at least one T-gate error occurred when acting on the encoded state (and possibly more occurred); thus, it should be shown that the number of T-gate errors required to produce an output error is at least four more than the number of T-gate errors known to occur. This will be assumed in what follows, without being stated explicitly, so that all counts of number of T-gate errors do not include the known errors. 
     There are two points to consider. The first is to show that the output error is indeed O(ϵ 4 ). Consider any output magic state in qubit q. Qubit q is in some row R and column C. Consider the following possibilities. First, suppose that there is no logical error in row R. This breaks into two subcases. In the first subcase, suppose that there is no error in measurement of the outer code in row R. Then, there must be some other qubit q′ in row R which is also input with an error. No error is detected by column C, so either there is a measurement error of the outer code in column C (in which case the total number of T-gate errors is at least 4, given 1 for q, 1 for q′, and 2 for the measurement error) or there is another qubit q″ in column C which also has an error. However, since q″ is in some row R′≠R, and R′ does not detect an error, again the total number of T-gate errors is at least 4. In the second subcase, suppose that there is an error in measurement of the outer code in row R. Then, since q has an error also, the total number of T-gate errors is at least 3, and further q will also be measured in some column C so if not error is detected there, the weight must be more than 3. 
     Suppose instead there is a logical error in row R. Thus, one can have a situation where qubit q has an error after measuring the row and only two T-gate errors have occurred. However, then q is measured in some column and again the total number of errors must be at least 4. 
     The second point is the success rate: in this case, one does not mind discarding all qubits in a row R as this affects only that row. The number of T-gates in a row is ˜n, and so for ϵn≲1, there is a good probability of accepting each row. If instead one had discarded all rows when any single error was detected, one would need mnϵ≲1. 
     The above procedure can be generalized to a three dimensional grid; for simplicity, consider size n 3 , although one may also consider different sizes in each direction. This discussion refers to rows, columns, and verticals to denote the three directions. The outer code again measures each of the three directions in turn, first rows, then columns, then verticals. This outer code has distance 8, but one can achieve seventh order reduction in error. This is the best possible outcome given that each qubit is in only three checks. 
     At this point, a new modification is introduced to the protocol: error correction. In particular embodiments, the following protocol is used:
         1. Check the rows using any inner code of distance at least 3. If there is an error detected by any given row R, re-initialize the qubits in that row to approximate magic states and repeat the measurement on the row. At this point, the rows are independent (unentangled with each other), so repeating the measurements on a given row has no effect on the other rows.   2. Check the columns using any inner code of distance at least 7. If the inner code stabilizers detect an error in any column C, and that error syndrome can be caused by at most 1 error inside the inner code, apply an error correction to fix those errors, and then repeat the measurement in that column, continuing until no errors are detected. If the outer code check detects an error, discard all qubits in the vertical plane which contains that given column and repeat steps 1, 2 on the qubits in that plane.       

     3. Check the verticals using any code of distance at least 7. If any error is detected by a measurement of an outer code check, discard all qubits and repeat the protocol from the beginning. Otherwise, if an error is detected by an inner code stabilizer, discard the qubits in that diagonal but not in the other diagonals where no inner code stabilizer detects an error. Return all qubits which are not discarded as approximate magic states; they have error O(ϵ 7 ). 
     Note that in step 2, if an error syndrome can be caused by at most 1 error, and a correction is applied, it is possible that a logical error is produced. It is possible that there were actually 6 or more errors inside the inner code, and the correction led to a weight 7 logical error. In this case, the difference between the known number of T-gate errors (1) and the actual number (at least 6) is at least 5, so the effect of the correction is to make it as if the inner code in step 2 only had distance 5. 
     Thus, one should analyze a protocol as if the codes has distance 3, 5, 7 for rows, columns, verticals. However, such a code indeed leads to a seventh order reduction in error. 
     The reason for the error correction step is to reduce the change of having to discard all qubits in a given plane. The number of T-gates applied in checking columns in any given plane is ˜n 2 , and so if one discarded all qubits in a plane whenever any error was detected by the inner code, one would need ϵn 2 ≲1. Instead, discarding can be performed in a plane due to inner code errors if there are at least 2 errors in a given column; to make this probability small, one needs (ϵn) 2 n=ϵ 2 n 3 ≲1. 
     Finally, consider the probability of having to discard a plane due to errors in an outer code measurement in a column. After the first round of row measurements, the error probability for qubits in any row is ˜ϵ 2  for any given qubit, so the probability of discarding a plane is ˜ϵ 2 n 2 , rather than ϵn 2  as one might have guessed. 
     A final interesting outer code to consider is a modification of the two dimensional grid, where now one can add an additional check on the diagonals. This outer code has distance 6. Distance 6 or higher codes can be used to perform the checks. In such cases, the rows can be checked, then the columns, then the diagonals (different orders are also possible). The same error correction as in the three dimensional grid can be used: one can correct column measurements with at most 1 error in the inner code. 
     IX. Discussion 
     In this disclosure, a general scheme has been given to construct distillation protocols using inner and outer codes. If desired, these protocols can be concatenated with other protocols. However, on their own, they achieve optimal asymptotic behavior, as well as having small size examples which perform well. 
     One of the advantages of these protocols is the small number of qubits that they use, as they maintain a constant ratio of physical to logical qubits in the asymptotic limit. In Cody Jones, “Multilevel distillation of magic states for quantum computing,” Phys. Rev. A 87, 042305 (2013), 1210.3388v2, another family of protocols giving γ→1 was constructed. However, this protocol, like most distillation protocols involving concatenation, required a large overhead of physical to logical qubits. The benefits of reduced overhead may be even more important if possible errors in the Clifford gates are taken into account. 
     It is interesting to consider the asymptotics of this overhead between physical and logical qubits. Note that given any distillation protocol, there is a trivial way to define a new protocol with a fixed ratio of physical to logical qubits. Suppose, for example, that some protocol uses n phys  qubits to produce 1 output magic state. Call this protocol P. One can define a new protocol P′ that works on 2n phys  qubits to produce n phys  output magic states, which simply consists of applying P a total of n phys  times sequentially. However, the T-gate circuit depth of P′ now is proportional to n phys  times the T-gate depth of P. In constrast, in Theorem 3, a d-th order error reduction is obtained at fixed ratio of physical to logical with a T-gate depth proportional to d. That is, the protocols that are discussed herein are space and time efficient. 
     X. Example Small Inner and Outer Codes 
     In this section, some specific inner and outer codes are given, either giving the stabilizers or referring to the literature. Some of these codes are explained in the basic distillation section III or in numerical simulations VII in the body of this disclosure. Other codes have other useful properties that are described for specific codes. 
     When stabilizers for an inner code are given, each row gives one stabilizer generator. Each row consists of a binary string, of length equal to the number of qubits, with a 1 indicating that that stabilizer acts on that qubit (the parity check matrix is given). 
     A. Inner Codes 
     1. [[4, 2, 2]] Inner Code 
     This is explained in Section III. 
     2. [[16, 6, 4]] Inner Code 
     The stabilizer matrix is the classical Hadamard code [16, 5, 8]. 
     
       
         
           
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
           
         
       
       
         
           
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
           
         
       
       
         
           
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
           
         
       
       
         
           
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
           
         
       
       
         
           
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
           
         
       
     
     3. [[7,1, 3]] Inner Code 
     This is explained in Section III. 
     4. [[17, 1, 5]] Inner Code 
     This code is the smallest odd code that was found with k inner =1 and distance 5. The stabilizers are: 
     
       
         
           
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
           
         
       
       
         
           
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
           
         
       
       
         
           
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
           
         
       
       
         
           
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
           
         
       
       
         
           
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
           
         
       
       
         
           
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
           
         
       
       
         
           
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
           
         
       
       
         
           
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
           
         
       
     
     5. [[21, 3, 5]] and [[23, 1, 7]] Inner Codes 
     The (extended) Golay code is a classical self-dual code which is [24,12, 8]. Puncturing a bit by collecting all code words that has zero on that bit, one obtains a self-orthogonal [23,11, 7]. From this, one can obtain a weakly self-dual CSS code which is [[23, 1, 7]]. There are many positions to puncture, but due to high symmetry of the Golay code, the resulting codes have the same weight enumerators. One can pipeline the [[23, 1, 7]] code after the protocol of section IIIA 2 to give a protocol with one output magic state and seventh order suppression in error. 
     By puncturing the [[23, 1, 7]] code twice, one obtains a [[21, 3, 5]] code. In a numerical search, a smaller odd code with k inner =3 and distance 5 was found. The stabilizers of the [[21, 3,5]] code are: 
     
       
         
           
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
           
         
       
       
         
           
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
           
         
       
       
         
           
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
           
         
       
       
         
           
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
           
         
       
       
         
           
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
           
         
       
       
         
           
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
           
         
       
       
         
           
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
           
         
       
       
         
           
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
           
         
       
       
         
           
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             0 
             ⁢ 
             
                 
             
             ⁢ 
             1 
             ⁢ 
             
                 
             
             ⁢ 
             1 
           
         
       
     
     
       
         
           
               
             
               
                 TABLE II 
               
               
                   
               
               
                 Parameters of small even weakly self-dual CSS codes 
               
               
                   
               
             
            
               
                   
               
            
           
           
               
               
               
               
               
               
               
               
               
               
            
               
                   
                 n inner   
                 16 
                 20 
                 24 
                 28 
                 30 
                 20 
                 28 
                 30 
               
               
                   
                 k inner   
                 6 
                 8 
                 12 
                 14 
                 16 
                 2 
                 4 
                 6 
               
               
                   
                 d 
                 4 
                 4 
                 4 
                 4 
                 4 
                 6 
                 6 
                 6 
               
               
                   
                   
               
            
           
         
       
     
     The code [[20, 2, 6]] can be constructed from the five-qubit code [[5, 1, 3]] by going through the Majorana operators, while the others cannot be constructed in this way. See Sergey Bravyi, Bernhard Leemhuis, and 
     Barbara M. Terhal, “Majorana fermion codes,” New J.Phys.12, 083039 (2010), 1004.3791 
     6. Other Inner Codes 
     Some other examples of inner codes can be found in M. B. Hastings, “Small majorana fermion codes,” 1703.00612, from which one can reproduce optimal k inner  found for given distance and W inner  in Table II. For stabilizers, see M. B. Hastings, “Small majorana fermion codes,” 1703.00612. 
     B. Outer Codes 
     1. Petersen Graph Code 
     The outer code in section VII C 2 has 4 qubits, uses weight-3 checks and is (4, 2) sensitive. However, from Lemma 9, it is known that there is some n outer  such that there is a code which is (4, 2) sensitive with weight-3 checks, which has only (⅔)n outer  checks. This code is now explained. The proof of Lemma 9 reduces the problem of finding such a code to finding a bipartite graph G. Since the set B of that lemma has degree 2, one can equivalently define the code by a graph H such that the vertices of the graph H correspond to checks and the edges correspond to bits; e.g., in the case that B has degree 2, the possible bipartite graphs G are in one-to-one correspondence with degree-3 graphs H. Then, from the proof of Lemma 9, it is known that if H has girth at least 5, then the corresponding code is (4, 2) sensitive. The smallest such graph H is known to be the Petersen graph.This is a degree-3 graph with 15 vertices and 10 edges. 
     Note that the girth being 5 is optimal in this case, because if H has girth 4, then there is a weight 4 error that violates no checks. 
     XI. Example Circuits 
     In this section, example circuits for some of the protocols above are disclosed. Boxes labelled Enc or Enc′ denote encoding and decoding circuits, which are Cliffords. The number in the box indicates what code is used. H denotes Hadamard, M denotes measurement in Z basis, JM z  denotes measurement in X basis, Czs denotes control-Z operations. 
       FIG. 6  is a block diagram 600 of an example pipelined circuit using [[16, 6, 4]] code described in section III B 2. Further, the legend in  FIG. 6  applies to the  FIGS. 7-9  as well. 
       FIG. 7  is a block diagram 700 of an example pipelined circuit using [[17, 1, 5]] code described in section IIIA 2. 
       FIG. 8  is a block diagram 800 of an example pipelined circuit using [[16, 2, 4]] code described in section VII C 1. 
       FIG. 9  is a block diagram 900 of an example circuit using [[21, 3, 5]] code described in section VII C 2. 
     XII. Coincidence Among Protocols 
     The Steane code has 7 Y-logical operators of weight 3. In the distillation protocol using the Steane code as the inner code, each logical error may appear in 4 different ways in the column that implements control-H ⊗7 . The measurement error at the lowest order can happen in 7 ways. Overall, the cubic error can happen in 7·4+7=35 ways. This number matches the number of logical operators of weight 3 in the Bravyi-Kitaev 15-to-1 protocol. See Sergei Bravyi and Alexei Kitaev, “Universal quantum computation with ideal Clifford gates and noisy ancillas,” Phys. Rev. A 71, 022316 (2005), quant-ph/0403025. 
     When [[7, 1, 3]] to [[17, 1, 5]] were pipelined, there are 48 T gates and 1 T state. The number of logical operators of weight 5 in [[17, 1, 5]] is 51. Each logical operator can appear in 16 different configurations in the column that implements control-H ⊗17 . The measurement error from the 17-qubit code routine occurs in 17 ways at the leading order. Thus, the output error probability has leading term (51·16+35·17)ϵ 5 =1411ϵ 5 . The coefficient matches the number of Z-logical operators of weight 5 in the [[49, 1, 5]] code, as reported in Sergey Bravyi and Jeongwan Haah, “Magic state distillation with low overhead,” Phys. Rev. A 86, 052329 (2012), 1209.2426. 
     Bravyi and Cross (see Sergey Bravyi and Andrew Cross, “Doubled color codes,” 1509.03239v1) gave a recursive construction for triply even codes. They showed how to convert a pair of a (classical) triply even code of length n t−1  with dual distance 2t−1 and some (classical) self-orthogonal code of length m t  with dual distance 2t+1 into a triply even code of length n t =2m t +n t−1  with dual distance 2t+1. The formula gives another coincidence with the pipeline. n t−i  is the number of T gates/states, sitting before the final H-measurement routine in the pipeline, and m t  is the code length of the final H-measurement routine. Thus, the recursive formula n t =2m t +n t−1  correctly counts the number of T gates/states used in the pipeline. 
     A similar coincidence was observed by Jones (see Cody Jones, “Multilevel distillation of magic states for quantum computing,” Phys. Rev. A 87, 042305 (2013), 1210.3388v2), where the leading error probabilities of the distillation protocols by a family of weakly self-dual [[k+4, k, 2]] codes with (k, 0)-magic basis and those by a family of triorthogonal codes (see Sergey Bravyi and Jeongwan Haah, “Magic state distillation with low overhead,” Phys. Rev. A 86, 052329 (2012), 1209.2426) are shown to be the same as (3k+1)ϵ 2 . The total number of T gates/states were also the same as 3k+8. 
     XIII. Qudits 
     In this section, an extension to qudits is considered with local Hilbert space dimension p&gt;2, with p a prime. Consider a basis of state |j , where j=0, 1, . . . , p−1 is periodic mod p. The following operators and phase factor are used 
                     ω   =     e     2   ⁢           ⁢   π   ⁢           ⁢     i   /   p           ,           ⁢     Z   =       ∑   j     ⁢       ω   j     ⁢        j   〉     ⁢           ⁢     〈   j              ,           ⁢     X   =       ∑   j     ⁢            j   +   1     〉     ⁢           ⁢     〈   j              ,     
     ⁢     H   =           1             √   p           ⁢       ∑     j   ,   k       ⁢       ω   jk     ⁢        j   〉     ⁢           ⁢     〈   k                ,           ⁢     S   =       ∑   j     ⁢       ω       j   ⁡     (     j   -   1     )       /   2       ⁢        j   〉     ⁢           ⁢     〈   j              ,     
     ⁢             C     ⁢   X     =       ∑   j     ⁢          j   〉     ⁢           ⁢       〈   j        ⊗     X   j             ,           ⁢       U   ⁡     (   n   )       =       ∑   j     ⁢          nj   〉     ⁢           ⁢     〈   j        ⁢           ⁢     (     n   ≠   0     )                   (     XIII   ⁢   .1     )               
which generate the Clifford group. It holds that ZX=ωXZ.
 
     In this section, a generalization of odd codes is used throughout, ignoring even codes. One reason is that one cannot achieve control-Swap in the same way as one could previously. The general method in the qubit case was to use some non-Clifford operation such as a T gate, conjugating controlled Pauli to obtain control-Swap on the code space of some code. However, Swap is of order 2 while control-Z is of order p. For odd codes, implementation of the control-Hadamard was not tired as before, because Hadamard is of order 4 for p&gt;2, and hence is not conjugate to control-Z. 
     A. Preliminary 
     Let one first define a T-gate. The cases p=3 and p&gt;3 are going to be different. Define 
                       g   ⁡     (   j   )       :=         ∑     k   =   0     j     ⁢           1           2         ⁢     k   ⁡     (     k   -   1     )           =           1           6         ⁢     (       j   3     -   j     )           ,           (     XIII   ⁢   .2     )                 g   ⁡     (     j   +   p     )       =         g   ⁡     (   j   )       ⁢           ⁢   mod   ⁢           ⁢   p   ⁢           ⁢   if   ⁢           ⁢   p     &gt;   3             (     XIII   ⁢   .3     )               
where the second line is because 6 is invertible in    p&gt;3 , and ensures that g is a well defined function on    p&gt;3 . All arithmetic in the exponent of ω, Z, X, and S will be over    p  for both p=3 and p&gt;3. Define the T-gate as
 
                           T   =       ∑     j   =   0       p   -   1       ⁢       ω     g   ⁡     (   j   )         ⁢        j   〉     ⁢           ⁢     〈   j              ,               TXT     -   1       ⁢     X     -   1         =   S               if   ⁢           ⁢   p     &gt;   3     ,                 (     XIII   ⁢   .4     )                           T   =            0   〉     ⁢           ⁢     〈   0          +     e       -   2     ⁢           ⁢   π   ⁢           ⁢     i   /   9                                1   〉     ⁢     〈   1          +       e     2   ⁢           ⁢   π   ⁢           ⁢     i   /   9         ⁢        2   〉     ⁢           ⁢     〈   2            ,                     TXT     -   1       ⁢     X     -   1         =       e       -   2     ⁢           ⁢   π   ⁢           ⁢     i   /   9         ⁢   S               if   ⁢           ⁢   p     =   3.                 (     XIII   ⁢   .5     )               
These show that in both cases the T gate is at the third level of the generalized Clifford hierarchy.
 
     More generally, it is observed that 
                       T   m     ⁢     XT     -   m         =     {             S   m     ⁢   X               for   ⁢           ⁢   p     &gt;   3     ,                 e       -   2     ⁢           ⁢   π   ⁢           ⁢     im   /   9         ⁢     S   m     ⁢   X             for   ⁢           ⁢   p     =   3.                     (     XIII   ⁢   .6     )               
For both p=3 and p&gt;3, define |ψ m    for m=0, 1, . . . , p−1 be the (+1)-eigenstate of T m XT −m :
 
 T   m   XT   −m |ψ m   −|ψ m   .   (XIII.7)
 
Any state |ψ m    for m=1, ,p−1 will be a “magic state.”
 
     How would one use these magic states? Suppose p&gt;3. Consider a pair of qudits in a state Σ j a j |j ⊗|ψ m   . Apply a control-X operation with the first qudit as source and the second qudit as target. This maps the state to 
                         1             √   p           ⁢       ∑     j   ,   k       ⁢       a   j     ⁢     ω     m   ⁢           ⁢     g   ⁡     (   k   )           ⁢            j   ,     k   +   j       〉     .                 (     XIII   ⁢   .8     )               
Now measure the second qudit in the computational basis, obtaining a result l. This gives a state on the first qudit Σ j a j ω mg(l−j) |j . Thus, the transformation implemented on the first qudit is Σ j ω mg(l−j) |j   j|. Expanding the exponent, one has
 
                           m   ⁢           ⁢     g   ⁡     (     l   -   j     )         =       ⁢       m   ⁢           ⁢     g   ⁡     (   l   )         -     m   ⁢           ⁢     g   ⁡     (   j   )         +           m           2         ⁢     (       lj   2     -       l   2     ⁢   j       )                     =       ⁢       m   ⁢           ⁢     g   ⁡     (   l   )         -     m   ⁢           ⁢     g   ⁡     (   j   )         +     m   ⁢           ⁢   l   ⁢           j   ⁡     (     j   -   1     )               2           -     m   ⁢           l   ⁡     (     l   -   1     )               2         ⁢     j   .                       (     XIII   ⁢   .9     )               
The first term on the right-hand side of Eq. (XIII.9) corresponds to an irrelevant global phase factor. The second term, −mg(j), corresponding to implementing transformation T −m  on the first qudit. The third term gives a phase factor that can be corrected by applying a power of the S gate and the last term gives phase factors that can be corrected by a power of the Z gate. Thus, the state injection procedure works, in that one can use a magic state |ψ m    to produce a transformation T −m  in up to Clifford corrections.
 
     When p=3, the same state injection can be used, with m=1. One finds after some calculation that if the measurement outcome is l=0, the implemented operations is T −1  to the source, if l=1, it is e −2πi/9 ST −1 , and if l=2, it is e 2πi/9 Z −1 S −1 T −1 . Thus, in all cases, the implemented operation is T −1  up to a Clifford correction. 
     Note that T m  and T −m  are interconvertible by Cliffords. More generally, it is possible to use Clifford operations to convert a gate T m  into another gate T m′  with m′=mn 3  for n≠0, by U=U(n)=Σ j |nj   j| gate. For p&gt;3, we have U † T m U=Σ j w mg(nj) |j   j| where 
     
       
         
           
             
               
                 
                   
                     g 
                     ⁡ 
                     
                       ( 
                       nj 
                       ) 
                     
                   
                   = 
                   
                     
                       
                         
                           
                             1 
                           
                         
                         
                           
                             6 
                           
                         
                       
                       ⁢ 
                       
                         ( 
                         
                           
                             
                               n 
                               3 
                             
                             ⁢ 
                             
                               j 
                               3 
                             
                           
                           - 
                           nj 
                         
                         ) 
                       
                     
                     = 
                     
                       
                         
                           n 
                           3 
                         
                         ⁢ 
                         
                           g 
                           ⁡ 
                           
                             ( 
                             j 
                             ) 
                           
                         
                       
                       + 
                       
                         
                           
                             
                               
                                 
                                   n 
                                   3 
                                 
                                 - 
                                 n 
                               
                             
                           
                           
                             
                               6 
                             
                           
                         
                         ⁢ 
                         
                           j 
                           . 
                         
                       
                     
                   
                 
               
               
                 
                   ( 
                   
                     XIII 
                     ⁢ 
                     .10 
                   
                   ) 
                 
               
             
           
         
       
     
     Thus 
                   U   †     ⁢     T   m     ⁢   U     =       T     mn   3       ⁢     Z     m   6       n   3     -   n             ,         
and so indeed T m =C 1 T m′ C 2  for some Cliffords C 1 , C 2 . For p=3, we see T=U(−1)T −1 U(−1). Now, for which pairs m, m′ can we find an n such that m′=mn 3 ? The multiplicative group    p   ×  is cyclic of order p−1. Therefore, when p−1 is not a multiple of 3, then    p   ×   n n 3 ∈   p   ×  is a bijection, and any T m  can be interconverted into any other T m′ . If p−1 is a multiple of 3, there are three distinct classes of T gates. Since −1=(−1) 3 , T m  and T −m  are always interconvertible.
 
     B. Inner Codes 
     For arbitrary vector v∈   p   n     inner    one can write X(v)=X v     1   ⊗ . . . 
                 X   ⁡     (   v   )       =       X     V   1       ⊗           ⁢   …   ⁢           ⊗     X     v     n   inner             ,         
and Z(v)=Z v     1   ⊗ . . .
 
               Z   ⁡     (   v   )       =       Z     v   1       ⊗           ⁢   …   ⁢           ⊗       Z     v     n   inner         .             
As in the weakly self-dual CSS code construction for qubits, it is straightforward to define a stabilizer code starting from a self-orthogonal subspace S⊂S ⊥ ⊂   p   n     inner   : The stabilizer group is generated by X(v) and Z(v) where v∈S. The quotient space S ⊥ /S is in one-to-one correspondence with the set of X-type (Z-type) logical operators, and the induced dot product on S ⊥ /S is non-degenerate. In Section XIV below, it is shown that there is a basis {v (1) , . . . , v (k     inner     ) } of S ⊥ /S such that v (i) ·v (j) =α j δ ij  where the scalars α j  are all 1 possibly except the last one. For simplicity, the discussion is focused on cases where
 
(1,1, . . . ,1)∈S,   (XIII.11)
 
 v   (i)·   v   (j) =δ ij .   (XIII.12)
 
e.g., the second condition is that all scalars α j  are equal to 1 The first condition demands that n inner  to be a multiple of p. The second is a mild restriction, since (S⊗) ⊥ /(S⊗S) always has a basis such that (XIII.12) holds. Given a basis {v (j) } satisfying (XIII.12), one can define logical operators of the inner code as
 
   X     (j)   =X ( v   (j) ).
 
   Z     (j)   =Z ( v   (j) ),   (XIII.13)
 
which indeed obey the commutation relation
 
   Z     (a)     X     (b)   =w   δ     ab       X     (b)     Z     (a)    (XIII.14)
 
of the generalized Pauli operators on k inner  qudits. Thus, this is a generalization of the odd codes in the qubit case. Due to (XIII.11), the transversal gate  S =S ⊗n     inner    is a logical operator:
 
 S   j   X   k   S   −j   =w   −jk(K+1)/2   Z   jk   X   k    (XIII.15)
 
   S X ( v )   S     −1   =w   −(v·v+v·1)/2   Z ( v ) X ( v )   (XIII.16)
 
where, in the second equation, the phase factor vanishes when v∈S.
 
     One can implement the measurement of the stabilizer T m XT −m  of the magic state |ψ m Ψ using the inner codes. The measurement becomes feasible if  C (T m XT −m ) can be implemented for logical qudits. Searching for its fault-tolerant implementation can begin by observing an identity  C (T m XT −m )=T m ( C X)T −m  that enables one to implement some controlled Clifford on logical qudits. The actual action on logical qubits depends on the inner code, but conditions (XIII.11, XIII.12) will make it uniform across all logical qudits. 
     Recall T m XT −m =η −1 S m X where η=1 if p&gt;3 and η=e 2πi/9  if p=3. The action of the transversal gate  T   m   X   T   −m  can be deduced by looking at the logical operators and phase. The answer is 
     
       
         
           
             
               
                 
                   
                     
                       
                         T 
                         _ 
                       
                       m 
                     
                     ⁢ 
                     
                       X 
                       _ 
                     
                     ⁢ 
                     
                       
                         T 
                         _ 
                       
                       
                         - 
                         m 
                       
                     
                   
                   = 
                   
                     
                       
                         η 
                         
                           - 
                           
                             n 
                             inner 
                           
                         
                       
                       ⁢ 
                       
                         
                           S 
                           _ 
                         
                         m 
                       
                       ⁢ 
                       
                         X 
                         _ 
                       
                     
                     ≅ 
                     
                       
                         η 
                         
                           
                             k 
                             inner 
                           
                           - 
                           
                             n 
                             inner 
                           
                         
                       
                       ⁢ 
                       
                         
                           ∏ 
                           
                             a 
                             = 
                             1 
                           
                           
                             k 
                             inner 
                           
                         
                         ⁢ 
                         
                           
                             
                               η 
                               
                                 - 
                                 1 
                               
                             
                             ( 
                             
                               
                                 
                                   
                                     S 
                                     ~ 
                                   
                                   
                                     ( 
                                     a 
                                     ) 
                                   
                                 
                                 ⁡ 
                                 
                                   ( 
                                   
                                     
                                       Z 
                                       ~ 
                                     
                                     
                                       ( 
                                       a 
                                       ) 
                                     
                                   
                                   ) 
                                 
                               
                               
                                 1 
                                 / 
                                 2 
                               
                             
                             ) 
                           
                           m 
                         
                       
                     
                   
                 
               
               
                 
                   ( 
                   
                     XIII 
                     ⁢ 
                     .17 
                   
                   ) 
                 
               
             
             
               
                 
                   
                       
                   
                   ⁢ 
                   because 
                 
               
               
                 
                     
                 
               
             
             
               
                 
                   
                       
                   
                   ⁢ 
                   
                     { 
                     
                       
                         
                           
                             
                               
                                 
                                   
                                     S 
                                     _ 
                                   
                                   m 
                                 
                                 ⁢ 
                                 
                                   
                                     X 
                                     ~ 
                                   
                                   
                                     ( 
                                     a 
                                     ) 
                                   
                                 
                                 ⁢ 
                                 
                                   
                                     S 
                                     _ 
                                   
                                   
                                     - 
                                     m 
                                   
                                 
                               
                               = 
                               
                                 
                                   
                                     
                                       ω 
                                       
                                         
                                           - 
                                           m 
                                         
                                         / 
                                         2 
                                       
                                     
                                     ⁡ 
                                     
                                       ( 
                                       
                                         
                                           Z 
                                           ~ 
                                         
                                         
                                           ( 
                                           a 
                                           ) 
                                         
                                       
                                       ) 
                                     
                                   
                                   m 
                                 
                                 ⁢ 
                                 
                                   
                                     X 
                                     ~ 
                                   
                                   
                                     ( 
                                     a 
                                     ) 
                                   
                                 
                               
                             
                           
                         
                         
                           
                             
                               
                                 
                                   
                                     S 
                                     _ 
                                   
                                   m 
                                 
                                 ⁢ 
                                 
                                   
                                     Z 
                                     ~ 
                                   
                                   
                                     ( 
                                     a 
                                     ) 
                                   
                                 
                                 ⁢ 
                                 
                                   
                                     S 
                                     _ 
                                   
                                   
                                     - 
                                     m 
                                   
                                 
                               
                               = 
                               
                                 
                                   Z 
                                   ~ 
                                 
                                 
                                   ( 
                                   a 
                                   ) 
                                 
                               
                             
                           
                         
                         
                           
                             
                               
                                 
                                   
                                     
                                       S 
                                       _ 
                                     
                                     m 
                                   
                                   ⁢ 
                                   
                                     
                                       
                                         ∑ 
                                         
                                           v 
                                           ∈ 
                                           S 
                                         
                                         
                                             
                                         
                                       
                                       ⁢ 
                                       
                                         
                                           
                                             X 
                                             ⁡ 
                                             
                                               ( 
                                               v 
                                               ) 
                                             
                                           
                                           
                                             
                                                
                                               S 
                                                
                                             
                                           
                                         
                                         ⁢ 
                                         
                                           
                                              
                                             0 
                                             〉 
                                           
                                           
                                             ⊗ 
                                             
                                               n 
                                               inner 
                                             
                                           
                                         
                                       
                                     
                                     
                                       ︸ 
                                       
                                         
                                           
                                             | 
                                             
                                               0 
                                               ~ 
                                             
                                           
                                           〉 
                                         
                                         
                                           ⊗ 
                                           
                                             k 
                                             inner 
                                           
                                         
                                       
                                     
                                   
                                 
                                 = 
                                 
                                   
                                      
                                     
                                       0 
                                       ~ 
                                     
                                     〉 
                                   
                                   
                                     ⊗ 
                                     
                                       k 
                                       inner 
                                     
                                   
                                 
                               
                               , 
                             
                           
                         
                       
                       ⁢ 
                       
                         
 
                       
                       ⁢ 
                       
                           
                       
                       ⁢ 
                       
                         { 
                         
                           
                             
                               
                                 
                                   
                                     ( 
                                     
                                       
                                         S 
                                         m 
                                       
                                       ⁢ 
                                       
                                         Z 
                                         
                                           m 
                                           / 
                                           2 
                                         
                                       
                                     
                                     ) 
                                   
                                   ⁢ 
                                   
                                     
                                       X 
                                       ⁡ 
                                       
                                         ( 
                                         
                                           
                                             S 
                                             m 
                                           
                                           ⁢ 
                                           
                                             Z 
                                             
                                               m 
                                               / 
                                               2 
                                             
                                           
                                         
                                         ) 
                                       
                                     
                                     
                                       - 
                                       1 
                                     
                                   
                                 
                                 = 
                                 
                                   
                                     ω 
                                     
                                       
                                         - 
                                         m 
                                       
                                       / 
                                       2 
                                     
                                   
                                   ⁢ 
                                   
                                     Z 
                                     m 
                                   
                                   ⁢ 
                                   X 
                                 
                               
                             
                           
                           
                             
                               
                                 
                                   
                                     ( 
                                     
                                       
                                         S 
                                         m 
                                       
                                       ⁢ 
                                       
                                         Z 
                                         
                                           m 
                                           / 
                                           2 
                                         
                                       
                                     
                                     ) 
                                   
                                   ⁢ 
                                   
                                     
                                       Z 
                                       ⁡ 
                                       
                                         ( 
                                         
                                           
                                             S 
                                             m 
                                           
                                           ⁢ 
                                           
                                             Z 
                                             
                                               m 
                                               / 
                                               2 
                                             
                                           
                                         
                                         ) 
                                       
                                     
                                     
                                       - 
                                       1 
                                     
                                   
                                 
                                 = 
                                 Z 
                               
                             
                           
                           
                             
                               
                                 
                                   
                                     ( 
                                     
                                       
                                         S 
                                         m 
                                       
                                       ⁢ 
                                       
                                         Z 
                                         
                                           m 
                                           / 
                                           2 
                                         
                                       
                                     
                                     ) 
                                   
                                   ⁢ 
                                   
                                      
                                     0 
                                     〉 
                                   
                                 
                                 = 
                                 
                                   
                                      
                                     0 
                                     〉 
                                   
                                   . 
                                 
                               
                             
                           
                         
                       
                     
                   
                 
               
               
                 
                   ( 
                   
                     XIII 
                     ⁢ 
                     .18 
                   
                   ) 
                 
               
             
           
         
       
     
     Suppose p&gt;3. In order to implement  C ( S   m   X ), one can consider an equation and a solution
 
 C ( S   m   X )=( C   X   1−y )( C   Z   u )( C   S   x )(HU C X   v )( C   S   z )( C   Z   s ( c   w   t )   (XIII.19)
 
 C ( S   m   X )=( C   Z   1/3 [( C   Z   3m/8 )( C   Z   3m/4 )]( C   X   2/3 )[( C   S   m/4 )( C   z   m/8 )]( C   w   −m/6 )   (XIII.20)
 
where the control is common for every gate, and u, x, y, z, s, t are variables. (Using
 
                         C     ⁢   A   =       ∑   j             ⁢          j   〉     ⁢       〈   j        ⊗     A   j             ,         
one can evaluate matrix elements on both sides.) Note that the operators in the brackets are powers of  C (S m Z m/2 ). This implies that indeed simultaneous  C ( S   m   X ) on all logical qudits can be implemented using  T   m ( C   X   3m/4 ) T   −m ,  T   m ( C   X   m/4 ) T   −m , controlled Pauli logical operators, and a power of Z on the control.
 
     When p=3 it suffices to consider m=1. To remove the phase factor η k     inner     −n     inner    the k inner  can be a multiple of 3. This can be achieved by considering three copies of a given code if necessary. n inner  is already a multiple of 3 due to (XIII.11). One can implement 
                 ∏     a   =   1       k   inner       C     ⁢     (       η     -   1       ⁢       S   ∼       (   a   )       ⁢       X   ~       (   a   )         )           
by an identity
 
 C (η −   SX )=( C   X   −1 )( C (η −1   SZ   −1 ))( C   Z )( C   X   −1 )( C   Z   −1 )( C   w   2 ).   (XIII.21)
 
     It has been shown that it is possible to build a fault-tolerant routine to measure {tilde over (T)} m {tilde over (X)}{tilde over (T)} −m  One can show the existence of good qudit codes, so asymptotic properties remain the same as for the qubit case. 
     It is possible to generalize Lemma 4 to the case of matrices over a field    p  for p&gt;2; however, the generalization is more difficult since the self-orthogonality constraint implies a nonlinear constraint on the rows of the matrix so that each row is null; see Lemma 13. An alternative construction is now given that achieves the scaling similar to Lemma 6, namely that for any distance d, one can find a family of odd weakly self-dual qudit CSS codes with X({right arrow over (1)}) in the stabilizer group such that the ratio k inner /n inner →1 as n inner →∞: This construction is derived from Reed-Muller codes. Let C=RM F     p   (r, m) be a classical Reed-Muller code over    p ; the codewords have length p m . The dual code C ⊥ = (m(p−1)−r−1, m); see Theorem 5.4.2 of Edvard F Assmus and Jennifer D Key, Designs and their Codes, 103 (Cambridge University Press, 1992). For any fixed r, for large enough m, C⊂C ⊥ , so the codespace of C is self-orthogonal, and {right arrow over (1)} is in the codespace of C. One can use the codespace of C as the space S, and use the CSS construction to define a weakly self-dual code. For fixed r, the rate of C tends to zero at large m, so the rate of the resulting weakly self-dual tends to 1. See S Vijay and L. Fu, “Quantum error correction for complex and majorana fermion qubits,” 1703.00459 for weakly self-dual qubit codes derived from Reed-Muller codes. To make (XIII.12) hold, it may be necessary to use S⊗S instead of S. 
     C. Outer Codes 
     If the inner code has code distance d, then one should use an outer code with a parity check matrix that is 
               (       d   -   1     ,     ⌈           d   -   1             2         ⌉       )     ⁢     -     ⁢     sensitive   .           
in full generality, one would want to use a parity check matrix with entries in    p , where an entry β≠0 would mean a stabilizer (η −1 S m X) β . This makes it necessary to have a different logical operator choice than used above.
 
     However, a check matrix that is given by the adjacency matrix of a biregular graph with large girth is sufficient. Such a check matrix has only 0 and 1 entries, so no other choice of logical operator is necessary beyond what is given above. Recall that a graph with large girth is locally a tree. Hence, a bad magic state will be caught by many checks because it flips a single stabilizer in these checks, and the required sensitivity is guaranteed. 
     XIV. Symmetric Forms Over Finite Fields 
     The classified nondegenerate symmetric forms have been classified over the binary field    2  in Section V. Over a field of odd characteristic, the set of all finite dimensional vector spaces with nondegenerate symmetric forms (quadratic spaces for short) constitute an abelian group under the direct sum, after identifying hyperbolic planes as the identity. This group is known as the Witt group of the field, and the group structure is well known. Here a self-contained and elementary treatment of the Witt group of    p  is presented, and the quadratic spaces over fields of odd characteristic is classified. 
     It is natural to distinguish two cases depending on whether −1∈   p  is a square, since a one-dimensional quadratic space is classified by    p   × /(   p   × ) 2 , where    p   × :   p \{ 0} and (   p   × ) 2 :={χ 2 χ∈   × }. Since the multiplicative group    p   ×  is a cyclic group of order p−1, the element −1 being the unique element of    ×  with multiplicative order 2, is a square if and only if p=1 mod 4. 
     The part of the argument in Section. V applies here without any change where any non-degenerate symmetric matrix was inductively converted to a direct sum of a diagonal matrix and blocks of 
               (         0       1           1       0         )     ,         
which represents a hyperbolic plane. Below, it is assumed that symmetric matrices are block diagonal in this form. It is then easy to explain why quadratic spaces constitute a group:
 
                         (         1       1           1         -   1           )     T     ⁢     (         a       0           0         -   a           )     ⁢     (         1       1           1         -   1           )       =       (         0         2   ⁢   a               2   ⁢   a         0         )     ≃     (         0       1           1       0         )               (     XIV   ⁢   .1     )               
This means that the one-dimensional quadratic space with form (−a) is the inverse of the space with form (a). 2 is an invertible element of the field.
 
     It is noted that the determinant of the symmetric form up to squares is a nontrivial invariant valued in the multiplicative group    p   × /(   p   × ) 2  which is isomorphic to the additive group  /2 . Let α∈   p  be a non-square. 
     Case I: p=1 mod 4 so that −1∈(   p   × ) 2 . Consider a block diag(a, a) of the symmetric matrix. Since −1 is a square, it can be seen diag(a, a)≃diag(a, −a)≃diag(1, −1)≃diag(1, 1) under congruent transformations. Therefore, there are four classes of symmetric matrices up to hyperbolic planes: diag(1), diag(α), diag(1, α), and diag(1, 1). By looking at the determinant of the form and the parity of the dimension, it can be seen that the four classes are distinct elements of the Witt group, which is hence isomorphic to  /2 ⊗ /2 . Given a dimension of quadratic spaces, there are only two exclusive possibilities:
 
diag(1, 1, . . ., 1, 1), and diag(1, 1, . . ,1,α).   (XIV.2)
 
     Case II: p=3 mod 4 so that −1∉(   p   × ) 2 . In this case, one can set α=−1. it is claimed that diag(1, 1) is not hyperbolic. If v=av 1 +bv 2  is ϵ vector in this two-dimensional space, where v 1 , v 2  are basis vectors with v i   2 =1 and a, b∈   p , then v·v=a 2 +b 2 . Since −1 is not a square, the equation a 2 +b 2 =0 does not have any nonzero solution, and this proves the claim. Next, it is shown that diag(1, 1)≃diag(−1, −1). To this end, a solution to a 2 +b 2 +1=0 over    p  is found. Once such a solution is found, then it can be seen that 
                         (         a       b           b         -   a           )     T     ⁢     (         1       0           0       1         )     ⁢     (         a       b           b         -   a           )       =       (           -   1         0           0         -   1           )     .             (     XIV   ⁢   .3     )               
The existence of the solution follows from (   p   × ) 2 +(   p   × ) 2 ⊆(   p   x× ) 2 , which implies that (   p   × ) 2 +(   p   × ) 2   −1. If (   p   × ) 2 +(   p   × ) 2 ⊆*   p   × ) 2 , then (   p   × ) 2  would be a monoid under addition contained in a finite group, and hence would be a group itself, which must contain 0∈(   p   × ) 2 . Therefore, quadratic spaces given a dimension are classified by the determinant of the form up to squares.
 
diag(1, 1, . . . ,1, 1), and diag(1, 1, . . . ,1, −1)   (XIV.4)
 
The Witt group of    p  is isomorphic to  /4  generated by diag(1).
 
     Now, certain facts and proofs are provided about quadratic spaces. 
     Lemma 10 (Chapter XV Theorem 10.2 of Serge Lang, Algebra, revised 3rd ed. (Springer, 2002).). Let Q be a nondegenerate quadratic space. If two subspaces V and U are isomorphic by an isometry σ: V→U, then there exists an isometry  σ : Q→Q such that σ|v=σ. 
     Lemma 11. Let N be a null subspace (on which the symmetric form vanishes) of a nondegenerate quadratic space Q over    p . Then, Q is isometric to the orthogonal sum of N ⊥ /N and a minimal hyperbolic subspace that contains N. 
     Proof. Applying Lemma 10 to the identity map o, one can conclude that any orthogonal set of vectors extends to an orthogonal basis. Since the form is nondegenerate, there exists a minimal hyperbolic subspace that includes N (hyperbolic extension), and the symmetric form can be written as Λ′⊗λ. where λ is hyperbolic, and Λ′ is nondegenerate. It is then clear that N ⊥ /N has the symmetric form Λ′.
 
Lemma 12. Let Q be a nondegenerate quadratic space of dimension n over    p  . Every maximal null subspace of Q has the same dimension m. Given any null subspace N of dimension k≤m, the number of null vectors of Q that are orthogonal to N is
 
# ( Q,N )= p   n−k−1   +p   m   −p   n−m−1 =:ζ( n,m,k ).   (XIV.5)
 
Proof. To prove the first claim, suppose M, M′ are maximal null subspaces. If dim M≤dim M′, then any injection from M to M′ is an isometry, which can be extended to Q as  σ . Then,  σ   −1 (M′) is a null superset of M, and hence is M itself since M is maximal. Thus, dim M=dim M′.
 
     Let Z(Q, N) be the set of all null vectors of Q that are orthogonal to N. (Z is not a subspace in general.) Consider 0 : Z(Q,N)+Z(N 1 1N, 0), a restriction of the canonical projection map Q→Q/N. The map ϕ is surjective by definition of ζ. If x, y∈Z(Q, N) are mapped to the same element, then x−y∈N. This implies that 0 maps exactly # N elements to one. (Here, # denotes the number of elements of the finite set.) Therefore,
 
# Z ( Q, N )=(# N )(# Z ( N   ⊥   /N,  0)).   (XIV.6)
 
Due to the preceding lemma, the dimension of a maximal null subspace of N ⊥ /N is m k. Thus, it remains only to prove the lemma when k=0 since
 
# ( Q,k ) =p   k ( p   n−2k−1   −p   n−m−k−1   +p   m−k ) =p   n−k−1   −p   n−m−1   p+   m .   (XIV.7)
 
     A definite quadratic space is one in which w·w=0 implies w=0. (A definite space corresponds to a nontrivial element of the Witt group; for example, a one-dimensional space is always definite; If α is not a square, then the symmetric form diag(1, −α) is definite.) To count all null vectors, one can work in a basis such that the n-by-n symmetric matrix is
 
Λ=Λ′⊗Λ 2m ,   (XIV.8)
 
where Λ′ definite, and
 
               Λ     2   ⁢   m       =           1           2         ⁢       (         0       1           1       0         )     ⊗     I   m               
is an orthogonal sum of m hyperbolic planes. In this basis, let one write any vector x as x′⊗(u, u′). The nullity is then expressed by a quadratic equation of coordinates
 
 x′·x′+u·u′ =0   (KIVV.9)
 
The solutions of this equation are divided into two classes: x′·x′=0 or x′·x′ ≠0. In the former case, x′=0 and u u′=0. Given arbitrary u there is u′ such that this equation holds. The number of solutions is p m +(p m −1)p m−1 . In the latter case, one has u≠0, and u·u′=c=x′·x′0 is a inhomogeneous equation in u′, whose solution always exists. For any given nonzero c, there are thus (p m −1)p m−1  choices of (u, u′). x′ can be any nonzero vector, so there are p n−2m −1 choices. In sum, the number of null vectors in an n-dimensional quadratic space Q over    p  is
 
# ( Q, 0)= p   m +( p   m −1)p m− 1+( p   n−2m −1)( p   m −1) p   m−1   =p   n−1   −p   n−m-1   +p   m .   (XIV.10)
 
Lemma 13. Let w 1 ={right arrow over (1)}∈   p   n  be the all-1 vector where n is a multiple of p≥3. Assume c&lt;(n−2)/2, and let w 2 , . . . , w c  be null vectors of    p   n  chosen inductively such that w j  is chosen uniformly at random from      p   n , V j−1 ) where V j−1 =span(w 1 , . . . , w j−i ). Let M be a c-by-n matrix M with rows w j .
 
     Consider a fixed n-component vector v, with v≠0 and v≠{right arrow over (1)}. The probability that Mv=0 is bounded from above by 
                     20   ⁢       (         3           5         )       n   -   c         +         (         11           15         )       c   -   1       .             (     XIV   ⁢   .11     )               
Proof. The desired probability is estimated by a union bound, considering separately the event that v∈V c   ⊥  and v∉V c , and the event that v∈V c   ⊥  and v ∈V c . The second event is possible only if v·v=0. By the classification of symmetric forms, a maximal null space of    p   n  has dimension m such that n−2≤2m≤n. The assumption that c&lt;(n−2)/2 implies that
 
 k   j :-=dim  V   j   ≤j≤c≤m− 1.   (XIV.12)
 
     Consider the first event, assuming v·v=0. Let j&gt;1. Then 
                     Pr   ⁡     [       v   ∈       V   j   ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∉     V   j       ❘     v   ∈       V     j   -   1     ⊥     ⁢   \   ⁢     V     j   -   1             ]       ≤           ζ   ⁡     (     n   ,   m   ,       k     j   -   1       +   1       )                 ζ   ⁡     (     n   ,   m   ,     k     j   -   1         )             ≤         p               2   ⁢   p     -   1           ≤         3           5                 (     XIV   ⁢   .13     )               
because w j  has to be orthogonal to span(v)+V j−1 , which is null and is a proper superset of V j−1 . Thus, for any t,
 
                     Pr   ⁡     [     v   ∈       V   t   ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∉     V   t       ]       =         Pr   ⁡     [     v   ∈       V   1   ⊥     ⁢   \   ⁢     V   1         ]       ⁢       ∏     j   =   2     t     ⁢           ⁢     Pr   ⁡     [       v   ∈       V   j   ⊥     ⁢   \   ⁢     V   j         ❘     v   ∈       V     j   -   1     ⊥     ⁢   \   ⁢     V     j   -   1             ]           ≤       ∏     j   =   2     t     ⁢           ⁢           ζ   ⁡     (     n   ,   m   ,       k     j   -   1       +   1       )                 ζ   ⁡     (     n   ,   m   ,     k     j   -   1         )               ≤         (         3           5         )       t   -   1       .               (     XIV   ⁢   .14     )               
For t=c, one finds in particular that
 
     
       
         
           
             
               
                 
                   
                     Pr 
                     ⁡ 
                     
                       [ 
                       
                         v 
                         ∈ 
                         
                           
                             V 
                             c 
                             ⊥ 
                           
                           ⁢ 
                           
                               
                           
                           ⁢ 
                           and 
                           ⁢ 
                           
                               
                           
                           ⁢ 
                           v 
                         
                         ∉ 
                         
                           V 
                           c 
                         
                       
                       ] 
                     
                   
                   ≤ 
                   
                     
                       
                         ( 
                         
                           
                             
                               3 
                             
                           
                           
                             
                               5 
                             
                           
                         
                         ) 
                       
                       
                         c 
                         - 
                         1 
                       
                     
                     . 
                   
                 
               
               
                 
                   ( 
                   
                     XIV 
                     ⁢ 
                     .15 
                   
                   ) 
                 
               
             
           
         
       
     
     Now assume v·v≠0. The event that v∈V j   ⊥  happens only if w j  is chosen from v ⊥ . The decomposition is bound as follows: Pr[v∈V c   ⊥ ]=Pr[v∈V 1   ⊥ ]Π j=2   c Pr[v∈V j   ⊥ |v∈V j−1   ⊥ ]. The first term is bounded by 1 trivially. For other factors, it is observed that the dimension of v ⊥  is n−1, and a maximal null subspace in v 1  has dimension m′≤m. Under the conditioning v∈V j−1   ⊥ , the null space V j−1  is a subspace of v ⊥ , and # (v ⊥ , V j−1 ) =ζ(n−1, m′, k j−1 )≤ζ(n−1, m, k j−1 .) Hence, 
                     Pr   ⁡     [     v   ∈     V   c   ⊥       ]       =         Pr   ⁡     [     v   ∈     V   1   ⊥       ]       ⁢       ∏     j   =   2     c     ⁢           ⁢     Pr   ⁡     [       v   ∈     V   j   ⊥       ❘     v   ∈     V     j   -   1     ⊥         ]           ≤       ∏     j   =   2     c     ⁢           ⁢           ζ   ⁡     (       n   -   1     ,   m   ,     k     j   -   1         )                 ζ   ⁡     (     n   ,   m   ,     k     j   -   i         )               ≤       (             p   2     +   p   -   1                 2   ⁢     p   2       -   p           )       c   -   1       ≤       (         11           15         )       c   -   1                 (     XIV   ⁢   .16     )               
where in the second inequality, the assumption that k j−1 ≤c&lt;(n−2)/2≤m was used.
 
     Turn now to the second event and assume v·v=0. Note that if v∈V c , there is a least j such that v∈V j . So, 
                     Pr   ⁡     [     v   ∈       V   c   ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∈     V   c       ]       ≤       ∑     j   =   2     c     ⁢       Pr   ⁡     [     v   ∈       V   j     ⁢           ⁢   and   ⁢           ⁢   v     ∈       V     j   -   1     ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∉     V     j   -   1         ]       .               (     XIV   ⁢   .17     )               
One has
 
                       Pr   ⁡     [     v   ∈       V   j     ⁢           ⁢   and   ⁢           ⁢   v     ∈       V     j   -   1     ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∉     V     j   -   1         ]       =         Pr   ⁡     [     v   ∈       V     j   -   1     ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∉     V     j   -   1         ]       ·     Pr   ⁡     [       v   ∈     V   j       ❘     v   ∈       V     j   -   1     ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∉     V     j   -   1           ]         ≤         (         3           5         )       j   -   2       ⁢     Pr   ⁡     [       v   ∈     V   j       ❘     v   ∈       V     j   -   1     ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∉     V     j   -   1           ]             ,           (     XIV   ⁢   .18     )               
where Eq. (XIV.14) was used. The second factor is bounded as
 
                     Pr   ⁡     [       v   ∈     V   j       ❘     v   ∈       V     j   -   1     ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∉     V     j   -   1           ]       ≤           p     1   +     k   j     -   1                 ζ   ⁡     (     n   ,   m   ,     k     j   -   1         )             &lt;         3             2   ⁢     p     n   -     2   ⁢   j                         (     XIV   ⁢   .19     )               
because w j  belongs to span(v)+V j−1 . Hence, Pr[v∈V j  and v∈V j−1   ⊥  and
 
               Pr   ⁡     [     v   ∈       V   j     ⁢           ⁢   and   ⁢           ⁢   v     ∈       V     j   -   1     ⊥     ⁢           ⁢   and   ⁢           ⁢   v     ∉     V     j   -   1         ]       ≤     5   ⁢         (         3           5         )       n   -   j       .             
So by Eq. (XIV.17),
 
     
       
         
           
             
               
                 
                   
                     Pr 
                     ⁡ 
                     
                       [ 
                       
                         v 
                         ∈ 
                         
                           
                             V 
                             c 
                             ⊥ 
                           
                           ⁢ 
                           
                               
                           
                           ⁢ 
                           and 
                           ⁢ 
                           
                               
                           
                           ⁢ 
                           v 
                         
                         ∈ 
                         
                           V 
                           c 
                         
                       
                       ] 
                     
                   
                   ≤ 
                   
                     
                       ∑ 
                       
                         j 
                         = 
                         2 
                       
                       c 
                     
                     ⁢ 
                     
                       5 
                       ⁢ 
                       
                         
                           ( 
                           
                             
                               
                                 3 
                               
                             
                             
                               
                                 5 
                               
                             
                           
                           ) 
                         
                         
                           n 
                           - 
                           j 
                         
                       
                     
                   
                   &lt; 
                   
                     20 
                     ⁢ 
                     
                       
                         
                           ( 
                           
                             
                               
                                 3 
                               
                             
                             
                               
                                 5 
                               
                             
                           
                           ) 
                         
                         
                           n 
                           - 
                           c 
                         
                       
                       . 
                     
                   
                 
               
               
                 
                   ( 
                   
                     XIV 
                     ⁢ 
                     .20 
                   
                   ) 
                 
               
             
           
         
       
     
     Summing the probabilities of (XIV.16) and (XIV.20), the proof is complete. 
     XV. Example Computing Environments 
       FIG. 1  illustrates a generalized example of a suitable computing environment  100  in which several of the described embodiments can be implemented. The computing environment  100  is not intended to suggest any limitation as to the scope of use or functionality of the disclosed technology, as the techniques and tools described herein can be implemented in diverse general-purpose or special-purpose environments that have computing hardware. 
     With reference to  FIG. 1 , the computing environment  100  includes at least one processing device  110  and memory  120 . In  FIG. 1 , this most basic configuration  130  is included within a dashed line. The processing device  110  (e.g., a CPU or microprocessor) executes computer-executable instructions. In a multi-processing system, multiple processing devices execute computer-executable instructions to increase processing power. The memory  120  may be volatile memory (e.g., registers, cache, RAM, DRAM, SRAM), non-volatile memory (e.g., ROM, EEPROM, flash memory), or some combination of the two. The memory  120  stores software  180  implementing tools for implementing the quantum circuit (e.g., the Magic state distillation circuits and associated techniques) as described herein. 
     The computing environment can have additional features. For example, the computing environment  100  includes storage  140 , one or more input devices  150 , one or more output devices  160 , and one or more communication connections  170 . An interconnection mechanism (not shown), such as a bus, controller, or network, interconnects the components of the computing environment  100 .l Typically, operating system software (not shown) provides an operating environment for other software executing in the computing environment  100 , and coordinates activities of the components of the computing environment  100 . 
     The storage  140  can be removable or non-removable, and includes one or more magnetic disks (e.g., hard drives), solid state drives (e.g., flash drives), magnetic tapes or cassettes, CD-ROMs, DVDs, or any other tangible non-volatile storage medium which can be used to store information and which can be accessed within the computing environment  100 . The storage  140  can also store instructions for the software  180  implementing the quantum circuits and techniques described herein. 
     The input device(s)  150  can be a touch input device such as a keyboard, touchscreen, mouse, pen, trackball, a voice input device, a scanning device, or another device that provides input to the computing environment  100 . The output device(s)  160  can be a display device (e.g., a computer monitor, laptop display, smartphone display, tablet display, netbook display, or touchscreen), printer, speaker, or another device that provides output from the computing environment  100 . 
     The communication connection(s) 170 enable communication over a communication medium to another computing entity. The communication medium conveys information such as computer-executable instructions or other data in a modulated data signal. A modulated data signal is a signal that has one or more of its characteristics set or changed in such a manner as to encode information in the signal. By way of example, and not limitation, communication media include wired or wireless techniques implemented with an electrical, optical, RF, infrared, acoustic, or other carrier. 
     As noted, the various methods for generating the disclosed circuits (e.g., for compiling/synthesizing the circuits) can be described in the general context of computer-readable instructions stored on one or more computer-readable media. Computer-readable media are any available media (e.g., memory or storage device) that can be accessed within or by a computing environment. Computer-readable media include tangible computer-readable memory or storage devices, such as memory  120  and/or storage  140 , and do not include propagating carrier waves or signals per se (tangible computer-readable memory or storage devices do not include propagating carrier waves or signals per se). 
     Various embodiments of the methods disclosed herein can also be described in the general context of computer-executable instructions (such as those included in program modules) being executed in a computing environment by a processor. Generally, program modules include routines, programs, libraries, objects, classes, components, data structures, and so on, that perform particular tasks or implement particular abstract data types. The functionality of the program modules may be combined or split between program modules as desired in various embodiments. Computer-executable instructions for program modules may be executed within a local or distributed computing environment. 
     An example of a possible network topology  200  (e.g., a client-server network) for implementing a system according to the disclosed technology is depicted in  FIG. 2 . Networked computing device  220  can be, for example, a computer running a browser or other software connected to a network  212 . The computing device  220  can have a computer architecture as shown in  FIG. 1  and discussed above. The computing device  220  is not limited to a traditional personal computer but can comprise other computing hardware configured to connect to and communicate with a network  212  (e.g., smart phones, laptop computers, tablet computers, or other mobile computing devices, servers, network devices, dedicated devices, and the like). In the illustrated embodiment, the computing device  220  is configured to communicate with a computing device  230  (e.g., a remote server, such as a server in a cloud computing environment) via a network  212 . In the illustrated embodiment, the computing device  220  is configured to transmit input data to the computing device  230 , and the computing device  230  is configured to implement any of the quantum circuits disclosed herein (e.g., compiling/synthesizing the quantum circuit from a higher-level circuit description) and outputting results to the computing device  220 . Any of the data received from the computing device  2930  can be stored or displayed on the computing device  2920  (e.g., displayed as data on a graphical user interface or web page at the computing devices  220 ). In the illustrated embodiment, the illustrated network  212  can be implemented as a Local Area Network (LAN) using wired networking (e.g., the Ethernet IEEE standard 802.3 or other appropriate standard) or wireless networking (e.g. one of the IEEE standards 802.11a, 802.11b, 802.11g, or 802.11n or other appropriate standard). Alternatively, at least part of the network  212  can be the Internet or a similar public network and operate using an appropriate protocol (e.g., the HTTP protocol). 
     Another example of a possible network topology  300  (e.g., a distributed computing environment) for implementing a system according to the disclosed technology is depicted in  FIG. 3 . Networked computing device  320  can be, for example, a computer running a browser or other software connected to a network  312 . The computing device  320  can have a computer architecture as shown in  FIG. 1  and discussed above. In the illustrated embodiment, the computing device  320  is configured to communicate with multiple computing devices  330 ,  331 ,  332  (e.g., remote servers or other distributed computing devices, such as one or more servers in a cloud computing environment) via the network  312 . In the illustrated embodiment, each of the computing devices  330 ,  331 ,  332  in the computing environment  300 l is used to perform at least a portion of any of the quantum circuits disclosed herein. In other words, the computing devices  330 ,  331 ,  332  form a distributed computing environment in which the quantum circuit implementation process is shared across multiple computing devices. The computing device  320  is configured to transmit input data to the computing devices  330 ,  331 ,  332 , which are configured to distributively implement any of the quantum circuit processes disclosed herein (e.g., compiling/synthesizing the quantum circuit from a higher-level circuit description) and to provide results to the computing device  320 . Any of the data received from the computing devices  330 ,  331 ,  332  can be stored or displayed on the computing device  320  (e.g., displayed as data on a graphical user interface or web page at the computing devices  320 ). The illustrated network  312  can be any of the networks discussed above with respect to  FIG. 2 . 
     With reference to  FIG. 4 , an exemplary system for implementing embodiments of the disclosed technology includes computing environment  400 . In computing environment  400 , a compiled quantum computer circuit description, including a circuit description for one or more magic state distillation circuits as disclosed herein, can be used to program (or configure) one or more quantum processing units such that the quantum processing unit(s) implement the circuit described by the quantum computer circuit description. The quantum computer circuit description can implement any of the magic state distillation circuits discussed herein. 
     The environment  300  includes one or More quantum processing units  302  and one or more read-out device(s)  308 . The quantum processing unit(s) execute quantum circuits that are precompiled and described by the quantum computer circuit description. The quantum processing unit(s) can be one or more of, but are not limited to: (a) a superconducting quantum computer; (b) an ion trap quantum computer; (c) a fault-tolerant architecture for quantum computing; and/or (d) a topological quantum architecture (e.g., a topological quantum computing device using Majorana zero modes). The precompiled quantum circuits, including any of the disclosed circuits comprising quantum Boltzmann machines, can be sent into (or otherwise applied to) the quantum processing unit(s) via control lines  306  at the control of quantum processor controller  320 . The quantum processor controller (QP controller)  320  can operate in conjunction with a classical processor  310  (e.g., having an architecture as described above with respect to  FIG. 1 ) to implement the desired quantum computing process. Further, the classical processor  310  can be programmed to implement any of the disclosed Boltzmann machine training methods. 
     In the illustrated example, the QP controller  320  gurther implements the desired quantum computing process via one or more QP subcontrollers  304  that are specially adapted to control a corresponding one of the quantum processor(s)  302 . For instance, in one example, the quantum controller  320  facilitates implementation of the compiled quantum circuit by sending instructions to one or more memories (e.g., lower-temperature memories), which then pass the instructions to low-temperature control unit(s) (e.g., QP subcontroller(s)  304 ) that transmit, for instance, pulse sequences representing the gates to the quantum processing unit(s)  302  for implementation. In other examples, the QP controller(s)  320  and QP subcontroller(s)  304  operate to provide appropriate magnetic fields, encoded operations, or other such control signals to the quantum processor(s) to implement the operations of the compiled quantum computer circuit description. The quantum controller(s) can further interact with readout devices  308  to help control and implement the desired quantum computing process (e.g., by reading or measuring out data results from the quantum processing units once available, etc.) 
     With reference to  FIG. 4 , compilation is the process of translating a high-level description of a quantum algorithm into a quantum computer circuit description comprising a sequence of quantum operations or gates, which can include any of the magic state distillation circuits as disclosed herein. The compilation can be performed by a compiler  322  using a classical processor  310  (e.g., as shown in  FIG. 1 ) of the environment  300  which loads the high-level description from memory or storage devices  312  and stores the resulting quantum computer circuit description in the memory or storage devices  312 . 
     In other embodiments, compilation can be performed remotely by a remote computer  300  (e.g., a computer having a computing environment as described above with respect to  FIG. 1 ) which stores the resulting quantum computer circuit description in one or more memory or storage devices  362  and transmits the quantum computer circuit description to the computing environment  300  for implementation in the quantum processing unit(s)  302 . Still further, the remote computer  300  can store the high-level description in the memory or storage devices  362  and transmit the high-level description to the computing environment  300  for compilation and use with the quantum processor(s). In any of these scenarios, results from the computation performed by the quantum processor(s) can be communicated to the remote computer after and/or during the computation process. Still further, the remote computer can communicate with the QP controller(s)  320  such that the quantum computing process (including any compilation and/or QP processor control procedures) can be remotely controlled by the remote computer  360 . In general, the remote computer  360  communicates with the QP controller(s)  320  and/or compiler/synthesizer  322  via communication connections  350 . 
     In particular embodiments, the environment  300  can be a cloud computing environment, which provides the quantum processing resources of the environment  300  to one or more remote computers (such as remote computer  360 ) over a suitable network (which can include the internet). 
     XVI. General Embodiments 
     This section describes several example embodiments for implementing embodiments of the disclosed technology. The disclosed tools and techniques are not to be construed as limiting in any way, as an one or more of the illustrated method acts can be performed alone or in various other combinations and subcombinations with one another. Further, any one or more of the disclosed method acts can be performed with one or more other method acts disclosed herein. 
       FIG. 10  is a flowchart of an example method  1000  for distilling magic states in a quantum computing device in accordance with embodiments of the disclosed technology. The illustrated embodiment should not be construed as limiting, as the disclosed method acts can, in some cases, be performed alone, in different orders, or at least partially simultaneously with one another. Further, any of the disclosed methods or method acts can be performed with any other methods or method acts disclosed herein. 
     In some embodiments, the methods below are performed (at least in part) by a classical computer configured to communicate with and control a quantum computer. Still further, the method acts can be embodied as computer-executable instructions which when executed by a computer cause the computer to perform the methods. 
     At  1010 , an inner code is applied (e.g., to qubits or qudits in a quantum computing device). In the illustrated embodiment, the inner code comprises a weakly self-dual error correcting code to implement control-Swap operations on the plurality of qubits or qudits. 
     At  1012 , the control-Swap operations are used to test properties of the magic states on the plurality of qubits or quidits so that a distance of the code scales proportional to the number of logical qubits or quidits. 
     In some embodiments, the method suppresses errors exhibited by magic states by a power (e.g., a selected or chosen target power). For example, at  1014 , an outer code is applied (e.g., to the qubits or qudits in the quantum computing device). In the illustrated embodiment, the outer code comprises an error-correcting code with a sensitivity selected to test the properties of the magic states such that measurement errors are also suppressed by the power. The power can, for example, be selected or chosen by a designer of the quantum circuit and can choose the power based on a variety of factors, including the size of the quantum circuit to be implemented, the desired accuracy of the result to be produced by the circuit, and the available quantum circuit overhead to implement the error-correcting code. 
     In some embodiments, the inner code uses 16 physical qubits, obtains 6 logical qubits, and has a code distance of 4. In certain embodiments, the inner code uses 30 physical qubits, obtains 6 logical qubits, and has a code distance of 6. In some embodiments, the inner code uses 64 physical qubits, obtains 12 logical qubits, and has a code distance of 8. 
     In further embodiments, the magic states are implemented by T-gates. In some embodiments, the quantum computing device is a topological quantum computer. In certain embodiments, the error correcting codes are Calderbank-Shor-Steane codes that implement controlled Hadamards for the inner code and reduce circuit depth. In some embodiments, the inner code and the outer code are implemented by a single concatenated circuit (e.g., implemented by the quantum computing device and configured to communicate with/control the plurality of qubits or qudits). 
     In some embodiments, at least two of the magic states are input at different stages from one another. 
     In certain embodiments, the inner code implements controlled-Hadamard operations, and the number of physical qubits or qudits used is odd. For example, in certain implementations, the inner code uses 17 physical qubits, obtains 1 logical qubits, and has a code distance of 5. In other implementations, the inner code uses 21 physical qubits, obtains 3 logical qubits, and has a code distance of 5. 
     Relatedly, circuits configured to distill magic states in a quantum computing device (e.g., circuits operating within or in concert with the quantum computing device) are also disclosed. Some embodiments comprise: quantum circuit elements configured to implement an inner code and an outer code, the inner code providing a weakly self-dual error correcting code to implement control-Swap operations on a plurality of logical qubits or qudits and provide error suppression to a target power (e.g., a selected or chosen power), the outer code providing an error-correcting code with a sensitivity selected to test the properties of the magic states such that measurement errors are also suppressed by the target power. The target power can, for example, be selected or chosen by a designer of the quantum circuit and can choose the power based on a variety of factors, including the size of the quantum circuit to be implemented, the desired accuracy of the result to be produced by the circuit, and the available quantum circuit overhead to implement the error-correcting code. 
     In some embodiments, the inner code uses 16 physical qubits, obtains 6 logical qubits, and has a code distance of 4. In further embodiments, the inner code uses 30 physical qubits, obtains 6 logical qubits, and has a code distance of 6. In some embodiments, the inner code uses 64 physical qubits, obtains 12 logical qubits, and has a code distance of 8. 
     In certain embodiments, the circuit comprises a plurality of T-gates configured to implement the magic states. In some embodiments, the circuit is part of a topologically protected quantum computer using Majorana zero modes to implement qubits or qudits. 
     In further embodiments, the error correcting codes are Calderbank-Shor-Steane codes that implement controlled Hadamards for the inner code and reduce circuit depth. In some embodiments, the circuit is concatenation-free. In certain embodiments, the circuit is configured to input at least two of the magic states at different circuit stages from one another. 
     In some embodiments, the inner code implements controlled-Hadamard operations, and the number of physical qubits or qudits used is odd. For example, the inner code uses 17 physical qubits, obtains 1 logical qubits, and has a code distance of 5. In other examples, the inner code uses 21 physical qubits, obtains 3 logical qubits, and has a code distance of 5. 
     In further embodiments, the outer code gives seventh order reduction in error when used with an inner code of distance 7 or more. And, in some implementations, the outer code is obtained from a Tanner graph of girth 6 or more and the outer code has distance 7 or more. Such outer codes may have each qubit participating in exactly 3 checks or may have a small number of additional checks to give the needed distance with a smaller code. 
       FIG. 11  is a flowchart of an example method  1100  for distilling magic states in a quantum computing device in accordance with embodiments of the disclosed technology. The illustrated embodiment should not be construed as limiting, as the disclosed method acts can, in some cases, be performed alone, in different orders, or at least partially simultaneously with one another. Further, any of the disclosed methods or method acts can be performed with any other methods or method acts disclosed herein. 
     In some embodiments, the methods below are performed (at least in part) by a classical computer configured to communicate with and control a quantum computer. Still further, the method acts can be embodied as computer-executable instructions which when executed by a computer cause the computer to perform the methods. 
     At  1110 , applying an inner code and outer code to distill a plurality of the magic states in the quantum computing device, and thereby possible error in the magic states. In the illustrated embodiment, the inner code comprises Bose-Chaudhuri-Hocquenghem (“BCH”) codes to implement operations on a plurality of physical qubits or quidits in the quantum computing device. 
     In some embodiments, the outer codes are determined by arranging the qubits or qudits in a two dimensional or three dimensional code. In certain embodiments, the inner code further comprises error correcting codes. 
     Relatedly, circuits configured to distill magic states in a quantum computing device (e.g., circuits operating within or in concert with the quantum computing device) are also disclosed. Some embodiments comprise: quantum circuit elements configured to implement an inner code and an outer code for suppressing error in physical qubits or qubits that implement the magic states, the quantum circuit elements for the inner code being configured to apply Bose-Chaudhuri-Hocquenghem (“BCH”) codes on one or more of the physical qubits or quidits of the quantum computing device. 
     In some embodiments, the outer codes are determined by representing the qubits or qudits as arranged in a two dimensional or three dimensional grid. In certain embodiments, the circuit is further configured to perform an error correction procedure if the inner code detects an error syndrome that can be caused by a small number of errors (e.g., one or two errors). 
     XVII. Concluding Remarks 
     Having described and illustrated the principles of the disclosed technology with reference to the illustrated embodiments, it will be recognized that the illustrated embodiments can be modified in arrangement and detail without departing from such principles.