Poq: Projection-based Runtime Assertions for Debugging on a Quantum Computer

In this paper, we propose Poq, a runtime assertion scheme for debugging on a quantum computer. The predicates in the assertions are represented by projections (or equivalently, closed subspaces of the state space), following Birkhoff-von Neumann quantum logic. The satisfaction of a projection by a quantum state can be directly checked upon a small number of projective measurements rather than a large number of repeated executions. Several techniques are introduced to rotate the predicates to the computational basis, on which a realistic quantum computer usually supports its measurements, so that a satisfying tested state will not be destroyed when an assertion is checked and multi-assertion per testing execution is enabled. We compare Poq with existing quantum program assertions and demonstrate the effectiveness and efficiency of Poq by its applications to assert two sophisticated quantum algorithms.

READ FULL TEXT VIEW PDF
POST COMMENT

Comments

There are no comments yet.

Authors

page 1

page 2

page 3

page 4

05/29/2020

Classical and Quantum Data Interaction in Programming Languages: A Runtime Architecture

We propose a runtime architecture that can be used in the development of...
08/01/2019

Quantum Temporal Logic: from Birkhoff and von Neumann to Pnueli

In this paper, we introduce a model of quantum concurrent program, which...
08/01/2019

Quantum Temporal Logic

In this paper, we introduce a model of quantum concurrent program, which...
10/05/2020

Quantum Computational Psychoanalysis – Quantum logic approach to Bi-logic

In this paper, we are dealing with the fundamental concepts of Bi-logic ...
11/28/2019

Expected Runtime of Quantum Programs

Building upon recent work on probabilistic programs, we formally define ...
06/05/2020

Eliminating Intermediate Measurements in Space-Bounded Quantum Computation

A foundational result in the theory of quantum computation known as the ...
11/21/2019

Local certification of programmable quantum devices of arbitrary high dimensionality

The onset of the era of fully-programmable error-corrected quantum compu...
This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1. Introduction

Quantum computing is a promising computing paradigm with great potential in cryptography (shor1999polynomial, ), database (grover1996fast, ), linear systems (harrow2009quantum, ), chemistry simulation (peruzzo2014variational, ), etc. Several quantum program languages (Qiskit, ; svore2018q, ; green2013quipper, ; paykin2017qwire, ; abhari2012scaffold, ; RigettiForest, ; GoogleCirq, ) have been published to write quantum programs for quantum computers. One of the key challenges that must be addressed during quantum program development is to guarantee the correctness of the composed program since it is easy for programmers living in the classical world to make mistakes in the counter-intuitive quantum programming. For example, Huang and Martonosi (huang2019qdb, ; huang2019statistical, ) reported a few bugs found in the example programs from the ScaffCC compiler project (javadiabhari2015scaffcc, ). Bugs have also been found in the example programs in IBM’s QpenQASM project (IBMopenqasm, ) and Rigetti’s PyQuil project (Rigettipyquil, )

. These erroneous quantum programs, written and reviewed by professional quantum computing experts, are sometimes even of very small size (with only 3 qubits)

111We checked the issues raised in these projects’ official GitHub repositories for this information.. Such difficulty in writing correct quantum programs hinders practical quantum computing. Thus, effective and efficient quantum program debugging is naturally in urgent demand.

Assertions have demonstrated the ability to capture the bugs in quantum programs. Huang and Martonosi proposed statistical assertions, which employed statistical tests on classical observations (huang2019statistical, ) to debug quantum programs. Motivated by quantum error correction (QEC), Zhou and Byrd proposed a runtime assertion (zhou2019quantum, ), which introduces ancilla qubits to indirectly detect the system state. However, as early attempts towards quantum program debugging, these assertion schemes suffer from the following drawbacks:

1) Very few assertion types The properties of quantum states can be much more complex than those in classical computing. Expressing the quantum program assertion predicates in a classical logic language leads to very few available assertion types. Existing quantum assertions (huang2019statistical, ; zhou2019quantum, ) can only describe three types of states.

2) Limited assertion locations The behaviors of quantum states can be very complicated inside a quantum program and it requires non-trivial effort to evaluate the predicates even within a quantum program logic system (ying2011floyd, ; zhou2019applied, ; unruh2019quantum, ; hung2019quantitative, ; yu2019quantum, ). Existing quantum assertions (huang2019statistical, ; zhou2019quantum, ) can only inject assertions at some special locations where the states are within the three supported types.

3) Repeated executions for one assertion A general quantum state cannot be duplicated (wootters1982single, )

, while measurements usually only probe part of the state information and will destroy the tested state immediately. Thus, an assertion, together with the computation before it, must be repeated for a large number of times to achieve a precise estimation 

(huang2019statistical, ).

4) One assertion per execution Another drawback of the destructive measurement is that the computation after an assertion will become meaningless. Even though multiple assertions can be injected at the same time, only one assertion could be inspected per execution, which will make the assertion testing more prolonged (huang2019statistical, ).

Limited assertion types and locations will increase the difficulty in debugging as assertions may have to be injected far away from a bug. Moreover, programs with complex intermediate states cannot be checked by the limited assertions. The large number of executions will make the testing process very time-consuming, restricting the size of the program and the number of assertions that could be feasibly checked.

We observe that projection can be the key to address these issues due to its potential logical expressive power and unique mapping property. First used as propositions or predicates in quantum logic by Birkhoff and von Neumann back in 1936 (birkhoff1936logic, ), projections can enable reasoning about quantum programs with the power of quantum logic. It has already served as predicates in several existing quantum program logics (brunet2004dynamic, ; ying2010predicate, ; unruh2019quantum, ; zhou2019applied, ; barthe2019coupling, ). Projections correspond to closed subspaces of a Hilbert space, on which logical connectives (e.g., conjunction, disjunction, and negation) can be defined, leading to strong logical expressive power. Moreover, projections naturally match the projective measurement, which may not affect the measured state when the state is in one of its basis states (PhysRevA.89.042338, ). Such a feature could potentially reduce the testing overhead as a state can be tested for multiple predicates (zhou2019applied, ).

However, the systematic employment of projections in quantum program debugging remains unexplored. We fill this gap by proposing the first Projection-Operator based Quantum program assertion scheme, namely Poq, for practical runtime debugging on a quantum computer. In particular, we make the following main contributions:

  1. We define the syntax and semantics of a new primitive for Poq, using projections as predicates. With the help of the expressive power of the logical connectives in Birkhoff-von Neumann quantum logic, this primitive could represent much more complex properties of quantum programs. Poq also employs applied Quantum Hoare Logic (zhou2019applied, ) to derive flexible assertions at arbitrary locations in a program.

  2. We introduce several transformation techniques, including additional unitary transformation, combination of projections, and using auxiliary qubits, to implement the primitive on a measurement-restricted quantum computer. The satisfaction of such primitives can be checked within very few executions with high certainty. Multi-assertion per execution is also allowed since a satisfying tested state will not be destroyed during the assertion checking.

  3. We further investigate the trade-off between efficien-cy and effectiveness of debugging by studying the local projection technique, which can relax the constraints in the predicates for a simplified assertion implementation. We also prove the robustness of our assertions under small errors.

  4. We show that Poq outperforms existing quantum program assertions (huang2019statistical, ; zhou2019quantum, ) in both theoretical analysis and practical application, with much stronger expressive power, more flexible assertion location, fewer testing executions, and low implementation overhead. Case studies are performed on two well-known sophisticated quantum algorithms, namely Shor’s algorithm (shor1999polynomial, ) and HHL algorithm (harrow2009quantum, ).

2. Preliminary

In this section, we cover the necessary preliminary to help understand the proposed assertion scheme.

2.1. Quantum computing

Quantum computing is based on quantum systems which evolve under the law of quantum mechanics. The state space of a quantum system is a Hilbert space (denoted by

), a complete complex vector space with inner product defined. A pure state of a quantum system is described by a unit vector

in its state space. When the exact state is unknown but we know it could be in one of some pure states

, with respective probabilities

, where , a density operator can be defined to represent such a mixed state with . A pure state is a special mixed state. Hence, in this paper, we adopt the more general density operator formulation most of the time since the state in a quantum program can be mixed upon branches and while-loops.

For example, a qubit (the quantum counterpart of a bit in classical computing) has a two-dimensional state space , where and , are two computational basis states. Another commonly used basis is the Pauli-X basis, and . For a quantum system with

qubits, the state space of the composite system is the tensor product of the state spaces of all its qubits:

. This paper only considers finite dimensional quantum systems because realistic quantum computers only have a finite number of qubits.

There are mainly two types of operations performed on a quantum system, unitary transformation and quantum measurement.

Definition 2.0 (Unitary transformation).

A unitary transformation on a quantum system in the finite dimensional Hilbert space is a linear operator satisfying , where is the identity operator on .

After a unitary transformation, a state vector or a density operator is changed to or , respectively. We list the definitions of the unitary transformations used in the rest of this paper in Appendix A.

Definition 2.0 (Quantum measurement).

A quantum measurement on a quantum system in the Hilbert space is a collection of linear operators satisfying .

After a quantum measurement on a pure state , an outcome is returned with probability and then the state is changed to . Note that . For a mixed state , the probability that the outcome occurs is , and then the state will be changed to .

2.2. Quantum programming language

For simplicity of presentation, this paper adopts the quantum while-language  (ying2011floyd, ) to describe the quantum algorithms. This language is purely quantum without classical variables but this selection will not affect the generality since the quantum while-language, which has been proved to be universal (ying2011floyd, ), only keeps basic quantum computation elements that can be easily implemented by other quantum programming languages (Qiskit, ; svore2018q, ; green2013quipper, ; paykin2017qwire, ; abhari2012scaffold, ; RigettiForest, ; GoogleCirq, ). Thus, our debugging scheme based on this language can also be easily extended to other quantum programming languages

Definition 2.0 (Syntax (ying2011floyd, )).

The quantum while-programs are defined by the grammar:

The language grammar is explained as follows. represents a quantum variable while means a quantum register, which consists of one or more variables with its corresponding Hilbert space denoted by . means that quantum variable is initialized to be . denotes that a unitary transformation is applied to . Case statement means a quantum measurement is performed on to determine which subprogram should be executed based on the measurement outcome . The loop means a measurement with two possible outcomes will determine whether the loop will terminate or the program will re-enter the loop body.

2.3. Projection and projective measurement

One type of quantum measurement of particular interest is the projective measurement, which is directly supported on realistic quantum computers. We first introduce projections and then define the projective measurement.

For each closed subspace of , we can define a projection . Note that every ( does not have to be normalized) can be written as with and (the orthocomplement of ).

Definition 2.0 (Projection).

The projection is defined by for every .

Note that is Hermitian () and . If a pure state (or a mixed state ) is in the corresponding subspace of a projection , we have (). There is a one-to-one correspondence between the closed subspaces of a Hilbert space and the projections in it. For simplicity, we do not distinguish a projection with its corresponding subspace. Then the of a projection is defined by the dimension of its corresponding subspace.

Definition 2.0 (Projective measurement).

A projective measurement is a quantum measurement in which all the measurement operators are projections ( is the zero operator on ):

Note that if a state (or ) is in the corresponding subspace of , then a projective measurement with observed outcome will not change the state since:

2.4. Applied Quantum Hoare Logic

To reason about a quantum program with projective measurements, applied Quantum Hoare Logic (aQHL) was introduced in  (zhou2019applied, ) as a variant of the Quantum Hoare Logic (ying2011floyd, ) for convenient applications. In aQHL, both the precondition and the postcondition of a Hoare triple are assumed to be projections. A state is said to satisfy a predicate (written ) corresponding to subspace if where

is the subspace spanned by the eigenvectors of

with non-zero eigenvalues. A projective Hoare triple

is true in the sense of partial correctness in aQHL if for all , , where is the semantic function of program . It was proved that aQHL is (relatively) complete for quantum programs in which all the measurements are projective.

In addition, aQHL can reason about the robustness of quantum programs, i.e., error bounds of the outputs of programs, with robust (projective) Hoare triples. A robust Hoare triple is a formula of the form: where are projections, S is a program, and .

Definition 2.0 (Trace distance of states).

For two states and , the trace distance between and is defined as where .

A state is said to approximately satisfy (projective) predicate with error parameter , written if there exists a with the same trace such that and . A robust Hoare triple is true (written ) if for all , .

2.5. Measurement-restricted quantum computer

Although aHQL has restricted all the measurements in a quantum program to be projective measurements, most realistic quantum computers which run on the well-adopted quantum circuit model (nielsen2010quantum, ) usually only support projective measurement in the computational basis. For qubits, such a measurement is described as , where is the projection onto the -dimensional subspace spanned by the basis state , and ranges over all -bit strings; in particular, for a single qubit, this measurement is simply with and .

3. Assertion Design and Implementation

In this section, we introduce Poq, a projection-based assertion scheme. We first define the syntax and semantics of a new projection-based primitive. Then we introduce several techniques to implement the new primitives on measurement-restricted machines. The proof of all the propositions, lemmas, and theorems in this and the next sections are in Appendix B.

3.1. Syntax and semantics

In classical computing, a runtime assertion is checked during execution. If the program state satisfies the predicate in the assertion, the program will continue with the state unchanged. Otherwise, an exception is raised. Such property can be achieved with projection based quantum predicates.

A quantum state will not be affected by a projection if it is in the subspace of . We can construct a projective measurement . When is in the subspace of , the outcome of this projective measurement is always “true” with probability of and the state is still . Then we can know that satisfies without changing the state. When is not in the subspace of , which means that does not satisfy , the probability of outcome “true” or “false” in the constructed projective measurement is or , respectively. Suppose we perform such procedure times, the probability that we do not observe any “false” outcome is . Since , this probability approaches 0 very quickly and we can conclude if satisfies with high certainty within very few executions.

Thus, quantum runtime assertions can be designed with projections as predicates. We first add a new assertion statement to the quantum while-language grammar.

Definition 3.0 (Syntax of the assertion statement).

A quantum assertion is defined as

where is a collection of quantum variables and is a projection onto a (closed) subspace of the state space .

Semantics of the assertion statement When executing a assertion statement , a constructed projective measurement will be performed on the quantum variables . If the outcome is “true”, the execution continues. Otherwise an error message is reported and the execution will terminate.

With Poq’s runtime assertion defined above, we can inject several assertions in a program since a passed assertion will not affect the state. And with just a few executions, we can conclude whether the predicates are satisfied with high certainty. However, we still need to know what predicate we should use at what place in a program.

Poq cooperates with aQHL to resolve this problem and is able to derive and inject assertions at arbitrary places in a quantum program. Suppose we have a program . We divide the it into segments and hope to inject assertion between consecutive program segments. In Poq, we first derive a series of Hoare triples , , , with aQHL where all s are projections. Then we can define a debugging scheme to check whether is correct in the sense of Hoare triple .

Definition 3.0 ().

A debugging scheme for is a new program with assertions being added between consecutive subprograms and :

where is the collection of quantum variables and is a projection on for all .

The following theorem shows that this debugging scheme is theoretically feasible.

Theorem 3.3 (Feasibility of debugging scheme).

Suppose we execute for times with input satisfying and collect all the error messages.

  1. If an error message occurs in with , we conclude that subprogram is not correct according to Hoare triple ;

  2. If no error message is reported, we claim that program is close to the bug-free standard program; more precisely, , where the minimum is taken over all bug-free standard program that satisfies .

Moreover, any error detection does not significantly affect a later detection; that is, even if is wrong, the error detection will still be efficient for all .

3.2. Transformation techniques for implementation on quantum computers

Although the debugging scheme is theoretically feasible, the constructed projective measurement may not be directly supported on a realistic quantum computer. In aQHL, there is no constraint on the derived projections and the projective measurement in the assertions can be in any basis. However, only projective measurements in the computational basis is supported on a realistic quantum computer, which makes the assertions not directly executable on the measurement-restricted quantum computers. In this section, we introduce several transformation techniques to overcome this obstacle.

3.2.1. Additional unitary transformation

Suppose the assertion we want to implement is over -qubit, that is, , each of is a single qubit variable. The simplest case is for some integer with .

Proposition 3.0 ().

For projection with , there exists unitary transformation such that (here ):

where is either , or for each .

We call the pair an implementation in computati-onal basis (ICB for short) of . Generally, ICB is not unique. According to this proposition, we have the following procedure to implement :

  1. Apply on ;

  2. Check in the following steps: For each , if or , then measure in the computational basis to see whether the outcome is consistent with ; that is, . If all outcomes are consistent, go ahead; otherwise, we terminate the program with an error message;

  3. Apply on .

Example 3.0 ().

Given a two-qubit register , if we want to test whether it is in the Bell state (maximally entangled state) , we can use the assertion . To implement it in the computational basis, noting that

we can first apply gate on and gate on , then measure and in the computational basis. If both outcomes are “0”, we apply on and on again to recover the state; otherwise, we terminate the program and report that the state is not Bell state .

3.2.2. Combining assertions

The method introduced above only applies to the case that with some integer . The following proposition provides us a way for dealing with the more general case : split the assertion into multiple sub-assertions that satisfy the above conditions.

Proposition 3.0 ().

For projection with , there exist projections satisfying for all , such that

Essentially, this way works for our scheme because conjunction can be defined in Birkhoff-von Neumann quantum logic. Theoretically, is sufficient; but in practice a larger allows us to choose simpler for each .

Using the above proposition, to implement , we may sequentially apply , , . Suppose is an ICB of for , we have the following scheme to implement :

  1. Set counter ;

  2. If , apply ; else if , apply and return; otherwise, apply ;

  3. Check ; ; go to step .

Example 3.0 ().

Given register , how to implement where

Observe that where

with following properties:

Therefore, we are able to implement by:

  • Apply ;

  • Measure and check if the outcome is “0”; if not, terminate and report the error message;

  • Apply and then ;

  • Measure and check if the outcome is “0”; if not, terminate and report the error message;

  • Apply .

3.2.3. Auxiliary qubits

A case still remains unsolved: . To handle this case, the auxiliary qubit is necessary. Without the auxiliary qubit, any measurement divides the entire space into multiple subspaces with dimension at most , which leads to the impossibility of implementing . Introducing an auxiliary qubit can solve this difficulty.

Specifically, we introduce an auxiliary qubit which is initialized to basis state , then implement

instead of original . Noting that and the number of qubits is including auxiliary qubit , therefore the methods introduced before is enough to complete the rest steps. Here is a trick to reduce the complexity: we may split with such that . Since the auxiliary qubit is initialized to , automatically holds and thus we only need to sequentially apply , , . In fact, is enough.

Example 3.0 ().

Given register , we aim to implement where

We may have the decomposition , where

and an ICB of is:

Note that automatically holds since the auxiliary qubit is in , we only need to execute:

  • Introduce auxiliary qubit , initialize it to ;

  • Apply ;

  • Measure and check if the outcome is “0”; if not, terminate and report the error message;

  • Apply ; free the auxiliary qubit .

4. Efficiency and Robustness of Debugging

In this section, we discuss efficient assertion designs and the decomposition of the introduced unitary transformation. We also prove the robustness of our debugging scheme. In other words, the accumulated error from the assertions is bounded when the error from each assertion is small.

4.1. Local projection: trade-off between efficiency and effectiveness

For projections over multiple qubits, it is quite common to be highly entangled, which leads to the difficulty of implementing the unitary transformation in ICB. It is possible to slightly relax the constraints in the predicates for simplified assertion implementation. To achieve this trade-off, we employ a commonly used approach in quantum information science, namely the quantum state tomography via local measurements (PhysRevLett.89.207901, ; PhysRevA.86.022339, ; PhysRevLett.118.020401, ).

We first introduce the notion of partial trace to describe the state (operator) of a subsystem. Let and be two disjoint registers with corresponding state Hilbert space and , respectively. The partial trace over is a mapping from operators on to operators in defined by: for all and together with linearity. The partial trace over can be defined dually.

To illustrate this idea, we need the following definition of local projection:

Definition 4.0 (Local projection).

Given , a local projection over is defined as:

Realizing that , the implementation of can partially test whether the state satisfies . Moreover, if the number of qubits of is small, the implementation of can be efficiently achieved. Therefore, we have the following implementation strategy which is essentially a trade-off between checking efficiency and effectiveness:

  • Find a sequence of local projection of ;

  • Instead of implementing the original , we sequentially apply , , , .

Example 4.0 ().

Given register , we want to check if the state is the superposition of following states:

To accomplish this, we may apply the assertion with . However, projection is highly entangled which prevents efficient implementation. Observe the following local projections:

To avoid implementing directly, we may apply , , and instead. Though these assertions do not fully characterize the required property, their implementation requires only relatively low cost, i.e., each of them only acts on two qubits.

4.2. Unitary transformation decomposition

The additional unitary transformation, which is essential in Poq, is usually decomposed into a directly supported gate set when being implemented on a quantum computer. We focus on assertion scheme design while detailed unitary transformation decomposition is out of the scope of this paper. Here we only briefly discuss common target gate sets for decomposition, and the metrics to evaluate a decomposition. It has been proved that arbitrary unitary transformation can be decomposed into a gate set consisting of CNOT gates and single-qubit gates (barenco1995elementary, ). CNOT gate count is a commonly used metric due to the high implementation overhead of a CNOT gate under state-of-the-art technology (linke2017experimental, ).

After considering quantum error correction, the set of the elementary logical gates allowed is dictated by the fault tolerance techniques that limit the efficiency of implementing an arbitrary transformation. Recent studies suggest that the fault-tolerant library should consist of Clifford (single-qubit Pauli, Hadamard, Phase, CNOT gates) and T logical gates, with the understanding that the T gate requires considerably more resources than any of the Clifford gates . It has become widely accepted that the T-gate count/depth serves as a good first-order approximation of the resource count required to physically implement a quantum circuit (Aliferis:2006:QAT:2011665.2011666, ; Ross:2016:OAC:3179330.3179331, ).

4.3. Robust debugging scheme

Similar to the debugging scheme defined in Section 3, we can still use the projections and appeared in a robust Hoare triple  (zhou2019applied, ) to define the robust debugging scheme for approximate quantum programs while ignoring the parameter and . However, it is worthwhile to show this robust debugging scheme is still correct and efficient to detect possible errors of the program when and is small.

We first study a special case of the gentle measurement lemma (Winter99, ) with projections. The result is slightly stronger than the original one in (Winter99, ) under the constraint of projection.

Lemma 4.0 (Gentle measurement with projections).

For projection and density operator , if , then

Suppose a state satisfies with error , then which ensures that, applying the projective measurement , we have the outcome “true” with probability at least . Moreover, if the outcome is “true”, the post-measurement state is , which is actually close to the original state in the sense that their trace distance is at most .

Consider a program with desired robust Hoare triples

which are used to conclude the correctness formula of . The following theorem states that the debugging scheme defined in Definition 3.2 is still efficient for robust debugging.

Theorem 4.4 (Feasibility of robust debugging).

Assume that all are small. Execute for times, and we count for the occurrence of error message for assertion .

  1. If is significantly larger than , we conclude that is not valid for with high confidence.

  2. If all are close to or smaller than for all , we can conclude that is valid with high probability, where which is explained as the accumulated error of applying assertions.

5. Overall Comparison

We evaluate Poq in the Section 5 and 6. In this section, we focus on an overall comparison among Poq and two other quantum program assertions in terms of assertion coverage (i.e., the expressive power of the predicates, the assertion locations in a program) and debugging overhead (i.e., the number of measurements, executions, and auxiliary qubits).

Baseline We use the statistical assertions (Stat) (huang2019statistical, ) and the QEC-inspired assertions (QECA) (zhou2019quantum, ) as the baseline assertion schemes. To the best of our knowledge, they are the only published quantum program assertions till now. Stat employs classical statistical test on the measurement results to check if a state satisfies a predicate. QECA introduces auxiliary qubits to indirectly measure the tested state.

5.1. Coverage analysis

Poq employs projections which are able to represent a wide variety of predicates in the derived assertions. However, both Stat and QECA only support three types of assertions: classical assertion, superposition assertion, and entanglement assertion. All these three types of assertions can be considered as 1-dimensional special cases in Poq. The corresponding projections are

Thus, all the three types of assertions are covered in Poq. The expressive power of the assertions in Poq, which can support many more complicated cases as introduced in Section 3, is much more than that of the baseline schemes.

For the assertion location, Poq can inject assertions at arbitrary place in a program with the help of the proof system proposed in aQHL (zhou2019applied, ). But the baseline schemes can only inject assertions in those places with states that can be checked with the very limited types of assertions. Therefore, the number of potential assertion injection locations of Poq is much larger than that of the baseline schemes.

# of Poq Stat QECA
Measure N/A
Execution N/A
Aux. Qbit or
Table 1. Asymptotic overhead comparison for Poq, Stat (huang2019statistical, ), and QECA (zhou2019quantum, ), assertions, qubits, and

5.2. Debugging overhead analysis

To analyze the debugging overhead of the three assertion schemes, we assume that all the assertions are within the three types of assertions supported in all assertion schemes in order to perform a fair overhead comparison. Suppose there are qubits in the program with assertions injected. For Stat, we suppose that the number of executions for one statistical test is . Usually we have to ensure an accurate estimation for the amplitudes in the state vector.

Table 1 shows the asymptotic overhead comparison for Poq, Stat (huang2019statistical, ), and QECA (zhou2019quantum, ). In particular, we compare the number of measurement operations (here one measurement operation means measuring one qubit), executions, and auxiliary qubits. Among them, Stat is the most time consuming one which requires executions and measurements because each time only one out of the assertions is checked (with measurements) and for each assertion Stat needs to run repeated executions. But for Poq, in each execution all assertions (with measurements for each assertion) can be checked and only executions will reveal unsatisfied assertions with a high probability. The total number of measurements would be . QECA does not provide a complete implementation of debugging with multiple assertions. For the number of auxiliary qubits, Stat does not require any auxiliary qubits while QECA requires at least one additional qubit. For Poq, at most one auxiliary qubit is enough when .

In summary, Poq significantly outperforms both Stat and QECA with much stronger expressive power and flexible assertion location. Also, Poq is much more efficient than the time-consuming Stat. We do not compare with QECA comprehensively but later in the case study of Shor’s algorithm, we will show that the implementation of Poq has much lower overhead than that of QECA.

6. Case Studies: Runtime Assertions for Realistic Quantum Algorithms

In this section, we perform case studies by appling Poq on two famous sophisticated quantum algorithms, the Shor’s algorithm (shor1999polynomial, ) and the HHL algorithm (harrow2009quantum, ). We will demonstrate how to derive assertions with Poq and how the assertions work in these realistic programs.

For Shor’s algorithm, we focus the circuit implementation of the assertions injected in a concrete example of the quantum order finding subroutine. The derived assertions are simple and can be supported by the baselines, which allows us to compare the resource consumption between Poq and the baseline and show that Poq could generate low overhead runtime assertions.

For HHL algorithm, instead of just asserting a concrete circuit implementation, we will show that Poq could derive non-trivial assertions that cannot be supported by the baselines. In these non-trivial assertions, we will illustrate how the proposed techniques, i.e., combining assertions, auxiliary qubits, local projection, can be applied in implementing the projections. Numerical simulation confirms that Poq-derived assertions can work correctly.

6.1. Shor’s algorithm

Shor’s algorithm was proposed to factor a large integer (shor1999polynomial, ). Given an integer , Shor’s algorithm can find its non-trivial factors within time. In this paper, we focus on its quantum order finding subroutine and omit the classical part which is assumed to be correctly implemented.

6.1.1. Shor’s algorithm program

Figure 1 shows the program of the quantum subroutine in Shor’s algorithm with the injected assertions in the quantum while

-language. Briefly, it leverages Quantum Fourier Transform (QFT) to find the period of the function

where is a random number selected by a preceding classical subroutine. The transformation , the measurement , and the result set are defined as follows:

For the measurement, the set consists of the expected values that can be accepted by the follow-up classical subroutine. For a comprehensive introduction, please refer to (nielsen2010quantum, ).