<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Quantum Software Testing</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Macario Polo Usaola</string-name>
          <email>macario.polo@uclm.es</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Escuela Superior de Informática, Universidad de Castilla-La Mancha</institution>
        </aff>
      </contrib-group>
      <fpage>57</fpage>
      <lpage>63</lpage>
      <abstract>
        <p>This article introduces some ideas and challenges related to the testing of quantum programs. In particular, it approaches functional testing, white box testing (specially mutation) and model-based testing.</p>
      </abstract>
      <kwd-group>
        <kwd>Quantum programming</kwd>
        <kwd>quantum testing</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>Quantum computers operate on cryogenic environments, at temperatures close to
absolute zero. One of the characteristics of calculus made with quantum computers is
the uncertainty of the results, that are not always the same: in fact, the same program
executed two times may produce different outputs with different probabilities. As the
number of executions grows up, the program output that could be considered as the
actual output will be the most repeated one. This uncertainty introduces interesting
challenges in quantum program testing. The situation is different if the quantum
program is executed on a simulator, that produce deterministic results. However, the
complexity of the quantum program may convert testing on a simulator in an
unapproachable task.</p>
      <p>
        In classic software engineering, a test case [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] is a “specification of the inputs,
execution conditions, testing procedure, and expected results that define a single test to
be executed to achieve a particular software testing objective […]”. One of the
desired characteristics of test cases is their “repeatability”: this is, the verdict of a test
must be always the same. The “verdict” is the result of the test execution, usually
“Pass” (if the test has not found any error in the system under test, the SUT) or “Fail”
(if the system has shown a behavior different than the expected one). So, a test case
has three parts: (1) specification of the initial situation, (2) execution of operations on
the SUT and (3) an oracle, which compares the actual and expected outputs, so
determining the verdict.
      </p>
      <p>Thus, executing a test case on a quantum computer actually requires executing the
same test case a number of times and, then, to compare the most repeated output to
the expected output.</p>
      <p>As well as this adaptation is required, quantum software testing requires both the
adaptation of other techniques, as well as the creation of new ones. In this paper we
discuss what can researchers do in this sense.</p>
    </sec>
    <sec id="sec-2">
      <title>Functional testing</title>
      <p>In practice, quantum programs provide quantum functionalities to conventional
programs via some kind of interface. In Figure 1, the Functionaly Q calls the quantum
program, which runs on a quantum computer, to perform some specific calculus.</p>
      <p>In a functional testing, the test suite (i.e., the set of test cases) checks the different
functionalities offered by the SUT. Depending on the test level, the test suite usually
executes on the system the same operations that any of the actors could execute. For
the system of Figure 1, the Test suite could replace the User, as illustrated on the left
side of Figure 2. In the same way, a test suite for testing the quantum program will
substitute the conventional system functionalities’ that require the services offered by
the quantum program (right-hand side of Figure 2).</p>
      <p>Going back to the three-parts structure of a test case, and recalling that the
uncertainty requires that every test case must be executed several times: (1) the initial
situation of a quantum test case will set up the initial status of the qubits, (2) as in
conventional testing, the quantum circuit will be executed, and (3) finally, the test suite will
save the obtained result, in order to calculate, in a further step, which is the most
probable actual result.
3</p>
    </sec>
    <sec id="sec-3">
      <title>White box testing</title>
      <p>
        In white box testing, the tester is interested in knowing which “fragments” of the
program are executed by the test cases. Thus, a program is completely tested if the test
cases have gone through all those “fragments”. Moreover, if the test cases do not
reveal errors, then the probability that the program is right is very high. The problem
here is in the granularity of the “fragment”. To measure it, there exist a number of
coverage criteria [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], such as statements, branches, conditions, decisions, modified
condition-decision…
      </p>
      <p>Thus, if a test suite runs all the statements of the SUT, it is said that its coverage is
100%. Obviously, some coverage criteria are more powerful than others: running all
the methods is a coarse criterion that is subsumed by, for example, statements because
if a test suite runs all the program statements, it runs also all its methods. Modified
condition-decision (MC/DC) is one of the most powerful coverage criteria. It is
fulfilled when every decision (understood as a set of conditions: for example, if A&gt;B or
B&lt;C is a decision with two conditions, A&gt;B and B&lt;C) is executed in its two branches
(true and false) thanks to the individual contribution of each individual condition. For
this example, since the decision is composed by two conditions separated by OR, a
complete test suite should lead the decision to the true branch thanks to A&gt;B and to
B&lt;C (first two rows of Table 1), and to the false branch also thanks to each individual
condition: since the operator is OR, this requires to do false both individual
conditions, as shown in the third row.
A&gt;B B&lt;C A&gt;B or B&lt;C Determinant condition
true false true A&gt;B (B&lt;C has no influence)
false true true B&lt;C (A&gt;B has no influence)
false false false Both conditions influence</p>
      <p>An additional white-box coverage criterion is based on mutation testing. In
mutation testing, the tester creates a set of mutants, which are copies of the SUT. Each
copy contains a syntactic change that, with the adequate test case, may produce an
output different than the SUT’s output. Thus, the mutant can be seen as a faulty
version of the original program. In this way, a mutation-based testing process finishes
when the test suite has found all the faults inserted in the mutants and none in the
original one. Some of the mutants produced are functionally equivalent, what means
that it is impossible to find a test case that finding the inserted fault (in practice, this
means that the change introduced in the mutant is not a fault, bust a code optimization
or de-optimization). The coverage is measured in terms of the mutation score, which
is the percentage of faults discovered (excluding equivalent mutants).</p>
      <p>
        Artificial faults are inserted by means of mutation operators. A mutation operator
introduces some type of fault: some of the most typical mutation operators (see Table
2) are AOR (Arithmetic Operator Replacement), ROR (Relational Operator
Replacement) or UOI (Unary Operator Insertion). As it is seen, the artificial faults reproduce
errors that a competent programmer could commit [
        <xref ref-type="bibr" rid="ref3 ref4">3, 4</xref>
        ].
      </p>
      <p>if (a&gt;b)</p>
      <p>AOR ifr(eat&gt;ubr)n a*b;
if (a&gt;b) return a-b;
return a+b; ROR ifr(eat=u=rbn)a+b;</p>
      <p>UOI ifr(e-tau=r=nb)a+b;</p>
      <p>There are many different types of mutation operators for reproducing many
different types of faults. There are also specific operators for specific programming
languages (operators on the use of pointers in C and C++, for example) and specific
technologies, such as mobile software.</p>
      <p>Depending on the goodness of the mutation operators used, a given mutation score
may subsume other coverage criteria. Mutation testing is quite suitable for quantum
testing.
In quantum programming, the programmer writes her/his programs directly using bits
(actually qubits) and logic gates (actually quantum gates). Thus, the simple operation
of adding two numbers requires to work at so low abstraction level.</p>
      <p>
        Anagolum [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] presents an example for adding two integer numbers using the
IBM’s QISkit simulator. The program code (and its corresponding quantum circuit)
reproduces the process used by a classical computer (carry bits, etc.). The example
needs two qubytes for saving the initial numbers, one additional qubyte for the carry
bits and one classical byte (to save the state of the read qubits).
      </p>
      <p>The program code, translated into OpenQASM, appears in Figure 3: it reserves 5
qubits for the first binary number (qreg a), 6 for the second one (qreg b), 5 for the
carry bits (qreg c) and 6 classical bits (creg d) for saving the results. Initially all
qubits are set to 0. Some of them (0, 2, 4 of a and 1, 3, 4 of b) are set to 1 via de x
gate. Thus, the input numbers are those in Figure 3.</p>
      <p>a
b
c
5
0</p>
      <p>Then, the remaining code in the left column is composed by five blocks of three
statements. Each block performs the following:
1. Via the ccx gate, if a[i]=1 and b[i]=1, then it changes the value of c[i+1].
2. With cx, if a[i]=1, then it changes the value of b[i].
3. The third statement changes c[i+1] if b[i]=1 and c[i]=1.</p>
      <p>In these blocks of statements, the qubits change according to Figure 4.</p>
      <p>
        5 4 3 2 1 0
ccx a[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], b[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], c[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ];
cx a[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], b[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ];
ccx b[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], c[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], c[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ];
ccx a[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], b[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], c[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ];
cx a[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], b[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ];
ccx b[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], c[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], c[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ];
ccx a[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], b[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], b[
        <xref ref-type="bibr" rid="ref5">5</xref>
        ];
cx a[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], b[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ];
ccx b[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], c[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], b[
        <xref ref-type="bibr" rid="ref5">5</xref>
        ];
cx c[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], b[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ];
ccx b[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], c[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], c[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ];
cx a[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], b[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ];
ccx a[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], b[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], c[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ];
cx c[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], b[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ];
cx a[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], b[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ];
ccx b[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], c[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], c[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ];
cx a[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], b[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ];
ccx a[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], b[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], c[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ];
cx c[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], b[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ];
cx a[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], b[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ];
ccx b[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], c[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], c[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ];
cx a[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], b[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ];
ccx a[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], b[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], c[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ];
cx c[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], b[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ];
cx a[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], b[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ];
ccx b[0], c[0], c[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ];
cx a[0], b[0];
ccx a[0], b[0], c[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ];
cx c[0], b[0];
cx a[0], b[0];
measure b[0] -&gt; d[0];
measure b[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] -&gt; d[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ];
measure b[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] -&gt; d[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ];
measure b[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] -&gt; d[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ];
measure b[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] -&gt; d[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ];
measure b[
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] -&gt; d[
        <xref ref-type="bibr" rid="ref5">5</xref>
        ];
      </p>
      <p>Fig. 4. Code for adding two numbers</p>
      <p>The code in the second column (blocks with five statements of gates cx and ccx)
runs in a very similar way. The final statements (measure) read the qubit values and
pass them to the classical register, d.</p>
      <p>As it is seen, working at bit level is hard and fault prone: the programmer may be
specially tempted to copy and paste for changing later the indexes of the qubits (and
forgetting it), she/he may use a wrong gate, write statements in a different order…</p>
      <p>All these possible faults are suitable of being reproduced with mutation operators.
4</p>
    </sec>
    <sec id="sec-4">
      <title>Model-based testing</title>
      <p>In model-based testing (MBT), the test engineer models test cases with models,
typically using UML. The UML specification includes the UML Testing Profile, an
extension whose metamodel defines all the elements involved in tests definition (Figure
5).
researched, but maybe it is possible to tailor the UML testing profile to this new
programming paradigm.</p>
    </sec>
    <sec id="sec-5">
      <title>Acknowledgements</title>
      <p>This paper and its associated research is part of the project TESTIMO
(SBPLY/17/180501/000503) that has been funded by JCCM Consejería de
Educación y Cultura y Deportes, y Fondos FEDER.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1. ISO/IEC/IEEE. ISO/IEC/IEEE International Standard - Systems and software engineering - Vocabulary. IEEE Std.
          <volume>24765</volume>
          , (
          <year>2017</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Glenford</surname>
            <given-names>J.</given-names>
          </string-name>
          <string-name>
            <surname>Myers</surname>
          </string-name>
          .
          <article-title>The Art of Software Testing, 2nd edition</article-title>
          .,
          <year>2004</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>DeMillo</surname>
            ,
            <given-names>R.A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lipton</surname>
            ,
            <given-names>R.J. and Sayward F.G.</given-names>
          </string-name>
          <article-title>Hints on test data selection: Help for the practicing programmer</article-title>
          . IEEE Computer;
          <volume>11</volume>
          (
          <issue>4</issue>
          ),
          <fpage>34</fpage>
          -
          <lpage>41</lpage>
          , (
          <year>1978</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Hayes</surname>
            ,
            <given-names>J.H.</given-names>
          </string-name>
          <article-title>and</article-title>
          <string-name>
            <surname>Offutt</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          <article-title>Recognizing authors: an examination of the consistent programmer hypothesis</article-title>
          .
          <source>Software Testing, Verification and Reliability</source>
          ,
          <volume>20</volume>
          (
          <issue>4</issue>
          ),
          <fpage>329</fpage>
          -
          <lpage>356</lpage>
          , (
          <year>2009</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Barbosa</surname>
            ,
            <given-names>E. F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Maldonado</surname>
            ,
            <given-names>J. C.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Vincenzi</surname>
            ,
            <given-names>Am.R.</given-names>
          </string-name>
          <article-title>Toward the determination of sufficient mutant operators for C, Software Testing</article-title>
          ,
          <source>Verification and Reliability</source>
          ,
          <volume>11</volume>
          (
          <issue>2</issue>
          ),
          <fpage>113</fpage>
          -
          <lpage>136</lpage>
          , (
          <year>2001</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Anagolum</surname>
          </string-name>
          , S. Arithmetic on Quantum Computers: Addition. Available at (
          <year>January 20</year>
          ,
          <year>2020</year>
          ): https://medium.com/@sashwat.anagolum/arithmetic-on
          <article-title>-quantum-computersaddition-7e0d700f53ae</article-title>
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7. OMG, UML Testing Profile, Object Management Group,
          <source>Tech. Rep. formal/05-07-07</source>
          , (
          <year>2013</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <given-names>Pérez</given-names>
            <surname>Lamancha</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            ,
            <surname>Polo</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            ,
            <surname>Caivano</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            ,
            <surname>Piattini</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            and
            <surname>Visaggio</surname>
          </string-name>
          ,
          <string-name>
            <surname>G.</surname>
          </string-name>
          <article-title>Automated generation of test oracles using a model-driven approach</article-title>
          .
          <source>Information and Software Technology</source>
          ,
          <volume>55</volume>
          (
          <issue>2</issue>
          ),
          <fpage>301</fpage>
          -
          <lpage>319</lpage>
          , (
          <year>2013</year>
          ).
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>