{'fraction_non_alphanumeric': 0.029526829469175966, 'fraction_numerical': 0.0070007824403903966, 'mean_word_length': 4.731413736134057, '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}}
Some Size and Structure Metrics for Quantum Software

Quantum software plays a critical role in exploiting the full potential of quantum computing systems. As a result, it is drawing increasing attention recently. As research in quantum programming reaches maturity with a number of active research and practical products, software metric researchers need to focus on this new paradigm to evaluate it rigorously and quantitatively. As the first step, this paper proposes some basic metrics for quantum software, which mainly focus on measuring the size and structure of quantum software. These metrics are defined at different abstraction levels to represent various size and structure attributes in quantum software explicitly. The proposed metrics can be used to evaluate quantum software from various viewpoints.


I. INTRODUCTION
Software metrics aim to measure the inherent complexity of software systems to predict the overall project cost and evaluate the quality and effectiveness of the design. Software metrics have many applications in software engineering tasks such as testing [1], maintenance [2], reengineering [3], reuse [4], and project management [5], [6]. Research for software measurement must adapt to the emergence of new software development methods, and metrics for new languages and design paradigms must be defined based on models relevant to these new paradigms [7].
Quantum programming is the process of designing and building executable quantum computer programs to achieve a particular computing result [8], [9]. A number of quantum programming approaches are available, for instance, Scaffold [10], Qiskit [11], Q# [12], ProjectQ [13], and Quipper [14]. A quantum program consists of blocks of code, each of which contains classical and quantum components. Quantum operations can be divided into unitary operations (reversible and preserve the norm of the operands), and non-unitary operations (not reversible and have probabilistic implementations). A quantum program executed on a quantum computer uses a quantum register of qubits to perform quantum operations and a classical register of classic bits to record the measurements of the qubits' states and apply quantum operators conditionally [15].
As research in quantum programming reaches maturity with a number of active research and practical products, software metrics researchers need to focus on this new paradigm to evaluate it in a rigorous and quantitative fashion [16], [17]. However, although a large number of software metrics have been proposed for classical software [5]- [7], [18]- [21], few metrics have been proposed for quantum software. Further, due to quantum software's specific features, existing models and abstractions for classical software cannot be applied to model quantum software straightforwardly.
As the first step towards evaluating quantum software, this paper proposes some basic metrics for quantum software, which mainly focus on measuring the size and structure of quantum software. These metrics are defined at different abstraction levels to represent various size and structure attributes in quantum software explicitly. The proposed metrics can be used to evaluate quantum software from various viewpoints.
The rest of this paper is organized as follows. Section II reviews the fundamental terminology in quantum computing. Section III and Section IV propose some basic size and structure metrics for quantum software, respectively. Related work is discussed in Section V, and concluding remarks are given in Section VI.

II. BACKGROUND
This section briefly introduces some basics of quantum mechanics, which form the basis of quantum computing [22].

A. Quantum Bit
A classical bit is a binary unit of information used in classical computation. It can take two possible values, 0 or 1. A quantum bit (or qubit) is different from the classical bit in that its state is theoretically represented by a linear combination of two bases in the quantum state space (represented by a column vector of length 2). We can define two qubits |0 and |1 , which can be described as Qubits |0 and |1 are the computational basis state of the qubit. In other words, they are a set of the basis of quantum state space. Any qubit |e can be expressed as a linear combination of two basis as |e = α|0 + β|1 , where α and β are complex numbers, and |α| 2 + |β| 2 = 1. This restriction is also called normalization conditions.

B. Quantum Gate and Circuit
Just as a logic gate in a digital circuit that can modify the state of a bit, a quantum gate can change the state of a qubit. A quantum gate can have only one input and one output (transition of a single quantum state), or it can have multiple inputs and multiple outputs (transition of multiple quantum states). The number of inputs and outputs should be equal because the operators need to be reversible, which means no information can be lost in quantum computing.
1) NOT Gate: The NOT gate works on a single qubit. It can exchange the coefficients of two basis vectors: The quantum NOT gate is an extension of the NOT gate in classical digital circuits.
A single input-output quantum gate can be represented by a 2 × 2 matrix. The state of a quantum state after passing through the quantum gate is determined by the value of the quantum state vector left-multiplied by the quantum gate matrix. The quantum gate matrix corresponding to the NOT gate is X = 0 1 1 0 Therefore, the result of a qubit passing a NOT gate can be denoted as 2) Hadamard Gate: The Hadamard gate also works on a single qubit, which can decompose existing quantum states according to its coefficients as follows.
This can be represented by a matrix as: Although Hadamard gate is not directly related to the AND and OR gates in classical digital circuits, it has important applications in many quantum computing algorithms. Interested readers can try to prove that after applying the Hadamard gate twice in a row, the quantum state will return to its original state. This behavior is consistent with the NOT gate.
3) Controlled NOT Gate: Computer programs are full of conditional judgment statements: if so, what to do, otherwise, do something else. In quantum computing, we also expect that the state of one qubit can be changed by another qubit, which requires a quantum gate with multiple inputs and outputs. The following is the controlled-NOT gate (CNOT gate). It has two inputs and two outputs. If the input and output are taken as a whole, this state can be expressed by where |00 , |01 , |10 , |11 are column vectors of length 4, which can be generated by concatenating |0 and |1 . This state also needs to satisfy the normalization conditions, that is |α| 2 + |β| 2 + |γ| 2 + |θ| 2 = 1.
The CNOT gate is two-qubit operation, where the first qubit is usually referred to as the control qubit and the second qubit as the target qubit. When the control qubit is in state |0 , it leaves the target qubit unchanged, and when the control qubit is in state |1 , it leaves the control qubit unchanged and performs a Pauli-X gate on the target qubit. It can be expressed in mathematical formulas as follows: The action of the CNOT gate can be represented by the matrix: Quantum Circuit: Quantum circuits, also known as quantum logic circuits, are the most commonly used generalpurpose quantum computing models, which represent circuits that operate on qubits under an abstract concept. A quantum circuit is a collection of interconnected quantum gates. The actual structure of quantum circuits, the number and the type of gates, and the interconnection scheme, are all determined by the unitary transformation U , performed by the circuit. The result of a quantum circuit can be read out through quantum measurements.

C. Quantum Programming
Quantum programming is the process of designing and building executable quantum computer programs to achieve a particular computing result [8], [9]. A quantum program consists of blocks of code, each of which contains classical and quantum components. Quantum operations can be divided into unitary operations (reversible and preserve the norm of the operands), and non-unitary operations (not reversible and have probabilistic implementations). A quantum program executed on a quantum computer uses a quantum register of qubits to perform quantum operations and a classical register of classic bits to record the measurements of the qubits' states and apply quantum operators conditionally [15]. Therefore, a typical quantum program usually consists of two types of instructions (or statements). One is called classical instructions that operate on the state of classical bits and apply conditional statements. Another is called quantum instructions that operate on the state of qubits and measure the qubit values.

III. BASIC SIZE METRICS FOR QUANTUM SOFTWARE
Software size represents one of the most significant internal attributes of a software product [5]. Many software effort estimation models [23]- [25] use some size metrics as their main effort driver to estimate the software development effort. In this section, we introduce some basic metrics that can be used to measure the size of quantum software from different levels: code, design, and specification.

A. Code Size
Program code is an integral component of the software. Such code includes source code, intermediate code, and even executable code. Here we only focus on the source code of quantum software and discuss how some widely used size metrics for classical software can be extended to measure the size of quantum software.
(1) simulator = Aer.get_backend('qasm_simulator') (2) (2) 1) Lines-of-Code (LOC): As we know, the most commonly used metric of source code program length is the number of lines of code (LOC). The LOC metrics can be used to predict the amount of effort required to develop a program and can also be used to estimate the programming productivity or maintainability after the software product is completed. Similarly, for quantum software, we may also consider some LOC metrics to measure the internal attribute of the software, specifically related to the quantum attributes. Let Q be a quantum program, some basic LOC metrics for Q can be defined as follows: • ϕ 1 : number of LOC in Q As we observed, ϕ 1 is a general metric, which consists of both classical and quantum statements in Q, that can be used to measure the total size of a quantum program. We can also define some metrics to especially measure the size related to the quantum aspects in Q as follows.
• ϕ 2 : number of LOC related to quantum gate operations • ϕ 3 : number of LOC related to quantum measurements Based on the above metrics, we can finally derive a general size metric to quantify the total size of the quantum-related aspects in Q as ϕ 4 = ϕ 3 + ϕ 2 .
Moreover, we can even consider the number of qubits or gates used in Q to obtain the following size metrics.
2) Halstead's Software Science: Halstead [19] introduces some size metrics for classical software. According to Halstead, "a computer program that implements an algorithm is considered to be a collection of tokens that can be divided into operators or operands." Halstead observes that software metrics should reflect how algorithms are implemented in different programming languages and independent of the platform and language used. These metrics should be computable statically from the source code of the program.
Let P be a classical program which is a collection of tokens, classified as either operators or operands, then some basic numbers for these tokens in P can be defined as follows: • µ 1 : number of unique operators • µ 2 : number of unique operands • N 1 : total occurrences of operators • N 2 : total occurrences of operands Based on these numbers, several metrics could be defined further to quantify various aspects of classical software.
• The length of P : N = N 1 + N 2 • The vocabulary of P : µ = µ 1 + µ 2 • The estimated length of P : • The effort required to generate P : E = D × V Let Q be a quantum program that consists of both classical and quantum statements, and we can define some basic numbers in Q as well.
• η 1 : number of unique classical and quantum operators • η 2 : number of unique classical and quantum operands • M 1 : total occurrences of classical and quantum operators • M 2 : total occurrences of classical and quantum operands We can define some metrics for quantum software by extending the classical Halstead's metrics based on these numbers. These metrics can be used to quantify various aspects of quantum software.

B. Design Size
Quantum software design is a process to transform user requirements into a suitable form that helps the programmer in quantum software implementation (coding). As classical software design [75], a quantum software design may also involve two stages: architectural design and detailed design. Like measuring the size of quantum software at the code level, we can measure the size of a quantum software design at the architectural level as well.
1) Architectural Design Size: Architectural design defines a collection of quantum software components, their functions, and their interactions (interfaces) to establish a framework for developing a quantum software system. The software architecture of the system defines its high-level structure, revealing its overall organization as a set of interacting components [26], [27]. A well-defined architecture allows an engineer to reason about system properties at a high level of abstraction. We can measure the size of a quantum architectural design based on formal architectural specifications and architectural patterns.
Architectural description languages (ADLs) [28] are formal languages representing the architecture of a software system. Using ADLs, software architects can specify the system's functionality using components and the interaction between components using connectors.
Like classical ADLs, we can use a quantum architectural description language (qADL), an extension of a classical ADL to formally specify the architectures of a quantum software system, to support the architectural-level design of quantum systems. A qADL can specify a quantum system's architecture with those mechanisms, including specifications of classical components and connectors between classical components, specifications of quantum components and connectors between quantum components, and specifications of connectors between classical and quantum components.
Let S be the formal architectural specification of a quantum software architecture, which consists of a group of components and the connectors between components, and we can define some general architectural-level size metrics for S as follows: • γ 1 : number of lines of architectural specifications • γ 2 : number of components and connectors We can also define some size metrics that specifically quantify the size of the quantum aspects in S from different viewpoints.
• γ 3 : number of quantum components • γ 4 : number of connectors between quantum components • γ 5 : number of connectors between a quantum component and a classical component Based on the above metrics, we can finally derive a general size metric to quantify the total size of the quantum-related aspects in S as γ 6 = γ 3 + γ 4 + γ 5 2) Detailed Design Size: Detailed design refines and expends the architectural design to describe the internals of the quantum software components (the algorithms, processing logic, data structures, and data definitions).
Recently, some researches have been carried out for studying design patterns for quantum systems [29], [30]. We can define some design size metrics for quantum systems based on these quantum patterns.
Let D be a design for a quantum system, and we can define some general size metrics in terms of design patterns in D • δ 1 : number of unique design patterns used in D • δ 2 : number of design pattern realizations for each pattern type Moreover, we can also define some size metrics that are specific to quantify the quantum attributes in terms of quantum design patterns in D as follows: • δ 3 : number of unique quantum design patterns used in D • δ 4 : number of quantum design pattern realizations for each pattern type

C. Specification Size
The Unified Modeling Language (UML) [31] is a generalpurpose, well-known modeling language in the field of classical software engineering. It provides a standard way to visualize the design of the classical software development life cycle. Recently, Pérez-Delgado and Perez-Gonzalez [32] present an extension of UML called Q-UML to model quantum software systems. The extension covers two types of UML diagrams: class diagram and sequence diagram. In this work, they claim that, in addition to the classical elements in a classical UML, the Q-UML should contain those elements related to the quantum aspects, such as quantum classes, quantum elements (quantum variables and quantum operations), quantum supremacy, quantum aggregation, and quantum communications.
Similar to the classical UML, Q-UML can serve as a base for defining some size metrics for a quantum software system at the specification level. An example of some metrics, which can be used to quantify the quantum aspects of the system, can be defined as follows.  [20] and the information flow metric by Henry and Kafura [21]. In this section, we discuss how these classical software metrics can be extended to evaluate quantum software.

A. McCabe's Complexity Metric
A well-known metric for measuring the complexity of a classical program's control structure is the cyclomatic complexity metric by McCabe [20].
For a program P , the cyclomatic complexity metric V (G) of P is defined as the number of linearly independent paths through a control-flow graph (CFG) of P and can be computed as follows: where G is the CFG of P to be measured, N is the number of nodes of G, each representing a statement in P , and E is the number of edges of G, each presenting the flow of control from one statement to another in P .
Similarly, we can measure the complexity of a quantum program's control structure by defining an extended cyclomatic complexity metric for quantum software. The definition of such a metric can be based on the quantum control flow graph (QCFG), which is an extension of the classical CFG to represent a quantum program. Let G Q be the QCFG of a quantum program Q to be measured, the cyclomatic complexity metric V (G Q ) of Q can be defined as follows.
where N Q is the number of nodes of G Q and E Q is the number of edges of G Q .
Similar to classical CFG, each node n ∈ N Q represents either a classical (or quantum related) statement, and each e ∈ E Q represents the flow of control from one statement to another in Q. The QCFG of Q can be constructed based on its AST, which can be derived through the static analysis on Q.
As an example, Figure 2 shows the QCFG of the Qiskit program in Figure 1. Based on the QCFG, we can calculate that the cyclomatic complexity metric of the program is 17 -16 + 2 = 3.

B. Henry and Kafura's information flow Metric
Perhaps the most common design structure metrics are known as information flow metrics, which deal with the complexity of a system by observing the flow of information among system components or modules. Among these metrics, one well-known approach is Henry and Kafura's information flow metric [21], which measures the total level of information flow between individual modules and the rest of a system. This metric considers the complexity of a software module, which could be affected by the following two factors.
• The complexity of the module code itself. • The complexity due to the module's connections to its environment.
The effect of the first factor has been included through the LOC (Lines Of Code) metric. For the quantification of the second factor, Henry and Kafura have defined two terms: fanin and fan-out.
• The fan-in of a module M is the number of local flows into M , plus the number of data structures from which M retrieves information. • The fan-out of a module M is the number of local flows from M , plus the number of data structures which M updates. Based on these concepts, Henry and Kafura define their information flow metric value as the module length multiplied by the square of fan-in multiplied by fan-out.
where length(M ) is the number of programming language statements in M , and F in and F out are the fan-in and fan-out of M , respectively. A quantum software system is usually composed of classical and quantum modules. These modules are not independent, and therefore may have some interactions among them, which may lead to some information flows, from a classical/quantum module to a classical/quantum module. To measure the complexity of a quantum system by observing the flow of information among the system modules, we can extend Henry and Kafura's information flow metric to the domain of quantum systems.
Let M Q be a classical/quantum module of a quantum system, length(M Q ) be the number of quantum programming language statements in M Q , and F in and F out be the fan-in and fan-out of M Q , respectively, we can define a structure metric based on the information flow to measure the complexity as a module of fan-in and fan-out in the system as follows.
V. RELATED WORK Although a large body of research in software metrics has been proposed for classical software [5], [7], [18]- [21], few metrics have been proposed for quantum software. To the best of our knowledge, our work is the first to propose some size and structure metrics for quantum software from various viewpoints.
Several metrics have been proposed to measure the performance of quantum computer systems. One is called the Total Quantum Factor (TQF) by Sete et al. [33]. TQF can provide rough estimates of the quantum circuit's size (circuit width times circuit depth) that can be run before the processor's performance decoheres. Another metric used to measure quantum computing systems' performance is called Quantum Volume [34]. Salm et al. [35] propose a metric to measure the performance of a gate-based quantum computer, which can be used to determine if a quantum circuit is successfully executable on a given gate-based quantum computer. They also discuss how the quantum system, noise, and errors affect the metric and how it can be refined for precise estimation.
Piattini et al. [17] present the Talavera Manifesto for quantum software engineering and programming, which collects some principles and commitments about the field of quantum software engineering and programming. Among these principles and commitments, one is "QSE assures the quality of quantum software," which mentioned that new metrics for quantum software should be developed. However, they do not define any concrete metric regarding quantum software measurement in the manifesto.
Sicilia et al. [36] present a preliminary study on the structure of the source code of quantum software, using initially the same metrics typically used in classical software. Their study focuses on the module structure and use of quantum gates in the libraries of Microsoft's quantum development platform QDK (Quantum Development Kit) that uses a specific language Q#. However, they do not propose any software metric that can be used to quantify the attributes of quantum software.

VI. CONCLUDING REMARKS
This paper has proposed some basic metrics for quantum software, which mainly focus on measuring the size and structure of quantum software. Some of these metrics are the extensions of their classical counterparts, while the others are specifically designed to quantify the quantum features in quantum software. These metrics are defined at different abstraction levels to represent various size and structure attributes in quantum software explicitly. The proposed metrics can be used to evaluate quantum software from various viewpoints.
We are now implementing a metrics collection tool for quantum programming language Qiskit to automatically derive the results of proposed metrics from Qiskit programs. The next step for us is to perform some experiments and collect data for evaluation. We hope a primary evaluation of these metrics will be available soon.