{'fraction_non_alphanumeric': 0.04189523502205012, 'fraction_numerical': 0.005700763687210928, 'mean_word_length': 4.210142897170075, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Diagnosis of single faults in quantum circuits

Detecting and isolating faults is crucial for synthesis of quantum circuits. Under the single fault assumption that is now routinely accepted in circuit fault analysis, we show that the behaviour of faulty quantum circuits can be fully characterized by the single faulty gate and the corresponding fault model. This allows us to efficiently determine test input states as well as measurement strategy that can be used to detect every single-gate fault using very few test cases and with minimal probability of error; in fact we demonstrate that most commonly used quantum gates can be isolated without any error under the single missing gate fault (SMGF) model. We crucially exploit the quantum nature of circuits to show vast improvement upon the existing works of automatic test pattern generation (ATPG) for quantum circuits.


I. INTRODUCTION
Detection and diagnosis of faults in classical digital circuits have been part of mainstream circuit manufacturing research and industry for several decades. A common approach for this is to analyze outputs when a circuit is given a fixed set of carefully chosen inputs (also known as patterns). ATPG (automated test pattern generation) techniques essentially try to efficiently generate an effective set of such inputs. This is computationally challenging because it belongs to the category of NP-complete problems [1]. However, extremely efficient heuristics have led to successful adoption of ATPG in VLSI.
ATPG is an obvious avenue to explore fault detection in quantum circuits; however, current results on ATPG for quantum circuits are few and do not seem to fully exploit the power of quantum computation in generating an efficient set of test patterns. In this regard, we noted the idea of quantum tomographic testing that has been discussed earlier in [2,3]. Like quantum state tomography, quantum tomographic testing requires multiple measurements on the circuit in question on various inputs; the histogram or the frequency counts of output patterns can be used to approximately determine the output states. The pairs of input and output states are then analyzed to detect and diagnose faults in the circuit.
Theoretically the number of possible faults is endless for any quantum circuit. Practically however, a method of synthesizing a circuit limits the possible set of faults.
Single fault assumption is now routine used in academia and industry in which the cause of a circuit failure is attributed to only one faulty component (gate). Hayes et al. reported that the commonly used "stuck-at" faultmodel and "bridging fault-model are not very apt for quantum circuits [4]. They proposed the missing gate fault (MGF) model in which one or more quantum gates are missing, i.e., these gates behave like an identity operator. ATPG for quantum circuits have since then largely focused around single MGF (SMGF). It is of course clear that if a gate behaves almost like an identity operator, then detecting whether it is present or missing is going to be difficult, if not impossible. However, formal understanding of this statement was not available so far.
In this work we explain what it means for a gate to be hard to diagnose (maybe more computation is required but no faulty gate is impossible to diagnose). We further show how to efficiently obtain a set of input states and measurement operators to cover all faulty gates with much less trials compared to existing results [2,3]. Unlike these works, our detailed explanations pertain to arbitrary single gate fault models, including SMGF; the faults may even be different for each gate. Furthermore, we do not require any internal modification of the circuit (unlike [3]).
The technical contribution is essentially answers to a set of questions raised, but left unaddressed, in [3]. Central to these are three observations, all of which are peculiarities of quantum circuits not present in their classical cousins. Suppose we have two states |u and |v whose output, when measured identically, generate the probability distributions {u m } and {v m }, respectively, on measurement outcomes. The first observation is that the "difference" caused by faulty behaviour of any gate is preserved subsequently. In other words, statistical distance between {u m } and {v m } does not change if an identical quantum circuit is applied on both the states before measuring.
The second observation is that using the same measurement operators on some combination of the input states (α |u + β |v ) generates a probability distribution which is not a linear combination ({|α| 2 u m + |β| 2 v m }) of the earlier probability distributions. Therefore, it makes sense to explicitly consider input states that are in superpositions of standard basis states.
Finally, motivated by the last reason, we ought to take advantage of the generalized measurement operators that quantum systems allow beyond the usual practice of measuring in the standard basis. It is therefore immediate that, unlike earlier approaches ( [2,3]), we ought to be looking for input states that could be super-position of basis states, and measurement operators more general than projective measurements in the standard basis.
We will denote by C the circuit to be diagnosed which acts on n qubits and represent its gates when enumerated in the standard manner, by G 1 , G 2 . . . . G s . To simplify our explanation, we will say G 0 is faulty to mean that C is fault-free. In the fault model we consider, at most one of these s gates is faulty, and when faulty, the corresponding faulty behaviour (operator) is known to us. The operators for the fault-free and faulty ith gate are denoted by G i and G i f , respectively (G i f is set to the identity operator under the SMGF model). Let C 0 denote a circuit in which no gate is faulty, and C i denote a circuit in which (only) the i-th gate is faulty. That is, . .. We want to detect if C is fault-free or faulty, and furthermore, if faulty then diagnose the offending gate; in other words, we want to know C = C j for which j ∈ {0, . . . s}. We illustrate the effectiveness of our strategy by applying it on a benchmark circuit "3qubitcnot".

II. DETECTING IF A SPECIFIC GATE IS FAULTY
This section contains the main tools of this paper. Suppose we are told that all but the i-th gate are fault-free. We want to detect if the i-th gate is fault-free or faulty. For the sake of brevity, we will use the following notation in this section: The high-level idea of our approach is to 1. Find an input state |φ such that |ψ = C |φ and |ψ ′ = C ′ |φ are at the farthest "distance" possible.
2. Find measurement operators which can distinguish between those two faraway states |ψ and |psi ′ with minimal probability of failure.
The fact that these can be done in general is wellknown [5]. We reformulate the known results and describe how to derive optimum input state and measurement operators to solve the problem described above.

A. Optimal input state
The appropriate measure of "distance" for pure quantum states with respect to distinguishability is the trace distance defined by D(|ψ , |ψ ′ ) = 1 − | ψ |ψ ′ | 2 . Trace distance is also equal to the maximum L1 distance of the probability distributions obtained from the two states upon measurement [10]. Given two operators G and G f , we say that a state |φ is a (G, G f )-separator (similarly, (C, C ′ )-separator) if this state, given as input, maximizes the trace distance between G |φ and G f |φ (respectively, C |φ and C ′ |φ ).
Therefore, our immediate goal is to find a (C, C ′ )separator input state |φ which minimizes | ψ |ψ ′ |. Our main observation here is that we can decompose our circuits into common sub-circuits excluding the i-th gate: Without loss of generality, we can consider that G (hence, G ′ and S) acts on all n qubits (possibly by tensoring with an identity operator of suitable dimensions).
Let the the eigenvalues of S be denoted by e −iθ1 . . . e −iθm (including duplicates) and the corresponding eigenvectors by |v 1 , . . . |v m . Letā = {a 1 . . . a m } be a solution to this optimization problem: First observe that minimizing Eqn. 1 is equivalent to We can now choose |φ = C † 1 |φ ′ as our re- optimumā also minimizes | ψ |ψ ′ | and this minimum value is simply | j a j e −iθj |.
The above optimization problem is not a computational hurdle for three reasons. First, the number of variables is exponential only in the dimension of the gate involved, which is usually quite small in practice. Secondly, OPT has the form of an equality-constrained quadratic program for which efficient algorithms exist.
The final reason is the interesting fact that the separator input for a gate in a circuit depends fundamentally on the gate in question and corresponding fault model. It does not depend at all on the portion of the circuit coming after the faulty gate (C 2 ), and its dependence on the portion of the circuit before the faulty gate (C 1 ) is really incidental. Therefore, it is feasible to have a precomputed table of (G, G f )-separators for different gates under common fault models. The required separator input for any circuit can be obtained by running the first portion of the circuit in reverse on a gate-separator input. Quantum circuits are usually built using a small set of gates that operate on a small number of qubits. Therefore, the major computation tasks of eigen-decomposition of S and solving OPT can be done only once and reused as and when needed.
If G acts on n ′ qubits and n ′ ≪ n (say, n ′ = 1 or 2), then it is possible to solve OPT using the larger nqubit operator I n−n ′ ⊗ G i . This may be computationally expensive, so a better alternative is to let S = G † G f as before, and let T = I n−n ′ ⊗ S be the extension of S to n qubits. If {(e −iθj , |v j )} are the eigenpairs of S then it is easy to see that {(e −iθj , |v j ⊗ |0 ⊗n−n ′ )} are the eigenpairs of T . Thus our required input state can be derived as |φ = C † 1 |φ ′ ⊗ |0 where |φ ′ is a (G, G f )-separator input state. For example, if G is a single qubit gate, then we only need to store that |φ ′ is 1 √ 2 (|v 1 + |v 2 ) where |v 1 and |v 2 are the eigenvectors of G † G f , irrespective of the value of n.
If the fault in question belongs to the single missing gate fault model, then we can treat it is a special case of the above where G f = I and therefore S = G † . Table I presents the separator input states for various commonly used gates in the SMGF model.
It should be obvious that our method of decomposing a circuit into portions before and after the gate in question can also be used for multiple missing/defective gate faults as long as the faulty gates can be grouped together and the circuit can be sliced around them. For example, our method is applicable to multiple gate faults if they act on distinct set of qubits, and/or are adjacent to each other; trivial extension is required to the computation of optimal state described earlier.

B. Optimal measurement
Once we have obtained the optimal input state |φ , we can compute the two possible output states |ψ = C |φ and |ψ ′ = C ′ |φ . Quantum states are manifested only by their measurement outputs. It is thus important to

Gate
Separator input states Error prob. design and implement measurement operators that are able to distinguish between these states. and thereby determine if the circuit in question is C or C ′ . However, unlike input states, measurement operators depend on the actual circuit and has to be computed once for every circuit and every fault model. The question of distinguishing between two given quantum states is one of the classical problems of quantum computing [6]. Two states can be differentiated (using measurements) with certainty if and only if they are orthogonal. So, if G f is almost same as G, then obviously no measurement should be able to distinguish between them with high confidence. We show below that we can distinguish with high confidence for gates with low value of | j a j e −iθj | (obtained by solving OPT).
There are two known modes of distinguishing between a pair of states. Helstrom measurement is a two-output (von Neumann) projective measurement which minimizes the error of incorrect labelling [5]. If we prohibit incorrect outcome and instead allow our measurement operators to either label a state with certainty or report "?"(inconclusive), then we would be performing what is known as unambiguous state discrimination (USD). USD is commonly achieved by employing a POVM [7][8][9], a gen- eralized measurement operator. We will use Helstrom projective measurement in the rest of this paper for explaining our technique; however, we can also use USD for doing the same and even combine both of these techniques for different gates and faults.
For Helstrom projective measurement, we want to create an orthonormal basis |ω + and |ω − which spans |ψ and |ψ ′ . This basis will be used for measurement and we will infer the state as |ψ or |ψ ′ upon measurement outcome |ω + or |ω − , respectively. We want to minimize the probability of error (when state is |ψ but outcome is incorrectly |ω − and similarly for the other pair); so the basis states should be maximally away from the output states, i.e., | ω − |ψ | 2 = | ω + |ψ ′ | 2 . We denote the corresponding probability of error by δ.
Therefore, we obtain the three following projectors to distinguish between |ψ and |ψ ′ : {P 0 = |ω + ω + | , P 1 = |ω − ω − | , P ? = I − P 0 − P 1 } with outcomes 0, 1 and ?, respectively. The outcome 0 corresponds to the output state being |ψ and hence implies that the circuit is (probably) fault-free; similarly, outcome 1 implies that the i-th gate is probably faulty. Outcome ? is never observed if circuit is fault-free or if the i-th gate is faulty; therefore, outcome ? immediately signifies that the circuit has fault at some other gate. We capture the measurement output using triplets containing probability of different outcomes (p(0), p(1), p(?)). We call the combination of a (C 0 , C i )-separator input and a measurement operator to distinguish between C 0 and C i as T est(i).
The probability of error after one measurement would be at most δ = | ψ |ω − | 2 = r 2 2 = 1 − √ 1 − k 2 /2 which matches the minimum probability of error in distinguishing |ψ and |ψ ′ by any projective measurement [5]. This shows that T est(i) can optimally distinguish between a faulty and a fault-free i-th gate. Table I shows the probability of error in detecting SMGF faults for some of the commonly used quantum gates. The table demonstrates that for most gates, missing gate faults can be easily detected. If necessary, δ could be further reduced using standard techniques of repeating a T est and reporting the majority of measurement outcomes -O( 1 δ log 1 ǫ ) repetitions are required to reduce error to ǫ. For deciding if C is C 0 or C i , we first compute the two triplets µ f f = (1 − δ, δ, 0) for fault-free and µ F = (δ, 1−δ, 0) for faulty circuit. Then we estimate the distribution of measurement outcomes by running the circuit multiple times using the separator state as input. Standard statistical techniques of classification can be used to determine if the observed distribution is obtained from µ f f or µ F . The optimum number of samples required is inversely proportional to the L1 distance of these distributions, which in our case is equal to (1 − 2δ) [12]. It is clear from Table I that just a single measurement can determine if a particular Hadamard gate is missing.

III. DETECTING IF A CIRCUIT IS FAULTY
Having discussed our solution to the problem of deciding whether a particular gate in a quantum circuit is faulty or not, given that other gates are fault-free, now we discuss the more general case where any one gate in a circuit may be faulty. Our efficient diagnostic strategy uses a pre-processing stage and a circuit evaluation stage.
Pre-processing stage: The pre-processing stage takes as input a description of the circuit, along with each of the fault-free and faulty operators. First, for each gate G i , we construct the input state and measurement  operator for T est(i). Then, we construct a diagnostic table with s rows and (1 + s) columns whose (q, r)-th cell contains the triple π(q, r) = (Pr[0], Pr [1], Pr[?]) when T est(q) is applied to circuit C r -the probabilities can be obtained by using any quantum circuit simulator, such as QuIDDPro [13]. Diagnostic tables for a benchmark circuit 3qubitcnot (illustrated in Figure 2) are given in the Table II.
Circuit evaluation stage: During circuit evaluation stage, we get an input circuit C on which we can apply any T est from {T est(F 1) . . . T est(F s)}. Suppose we apply T est(F i) (for some chosen i) enough number of times to create an output distributionπ. If C = C j , thenπ will be "closest" to the distribution π(i, j). What is required is therefore an efficient way to classify C into the classes {C 0 . . . C s } by multiple applications of suitable Tests. It is clear that T est(j) will be able to identify between C 0 and C j since the L1 distance of π(j, 0) and π(j, j) is at least (1−2δ) (δ is a property of the j-th gate as explained earlier). However, in practice it is possible that a particular T est() is able to distinguish between more than two classes of faults. The diagnostic table for the 3qubitcnot circuit shows that most Tests are able to easily classify all C i , except C 5 & C 0 in some cases. Therefore, Test(1) followed by Test (5), a few applications of each, suffices to diagnose all faults -less that 20 evaluations of C which is a huge improvement compared to earlier works [2,3].

IV. CONCLUSION
In this letter we present a clear outline on how one should diagnose faults in quantum circuits in the framework of ATPG. Our explanation is mostly based on single gate faults, but the techniques can be extended to certain types of multiple faults, though the computational costs would naturally increase in such cases. We show how to isolate every type of fault using very few test patterns compared to existing techniques. Our main contribution here is to demonstrate that while studying faults in quantum circuits, one should consider the properties of quantum circuits for choosing proper quantum input states as well as proper strategy of measurement for efficient testing of circuits.

ACKNOWLEDGMENTS
First author would like to thank the Centre of Excellence in Cryptography, Indian Statistical Institute, Kolkata for hosting him during which major portion of this work was accomplished.