A quantum program automatic repair method based on unitary operation

CN116954969BActive Publication Date: 2026-09-04BEIHANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310817416.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-05
Publication Date
2026-09-04
Estimated Expiration
2043-07-05

AI Technical Summary

Technical Problem

演化过程是量子程序中实现计算功能的关键,如果在演化过程存在缺陷,这虽然不会导致程序运行崩溃,但会输出错误的结果

Benefits of technology

[0019] First, the present invention can treat the program as a black box model, thus making the patch location process less demanding, only requiring introduction at a fixed position before and after evolution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116954969B_ABST
    Figure CN116954969B_ABST
Patent Text Reader

Abstract

The application discloses a quantum program automatic repairing method based on unitary operation, which comprises the following steps: 1) regarding the quantum program as a black box model and modeling the same, establishing reasonable equations among the initial state, the final state and the evolution process, and preliminarily solving the evolution operator; 2) defining two repairing modes of pre-repairing and post-repairing, and establishing reasonable mathematical relations; 3) adopting a test case set of sufficient orthogonal bases to output and expect the K-L divergence of the probability distribution as a judgment criterion as a test prediction; 4) modifying and further estimating the evolution operator according to the test result, and simplifying the equivalent estimation operator; and 5) calculating the candidate patch and performing unitary modification on the non-unitary patch. The application firstly proposes an automatic repairing method for the quantum program, and through the use of the characteristics of the quantum, the low positioning requirement, the multi-defect repairing and the fully automatic process can be realized, so that the quality of the quantum program is improved while the repairing cost of the quantum program is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the interdisciplinary field of software engineering and quantum computing, and specifically relates to an automatic quantum program repair method based on unitary operations. Background Technology

[0002] As an emerging and continuously developing form of computing, quantum computing, leveraging its quantum parallelism, has the potential to solve extremely complex computational problems and perform domain-specific simulation tasks. Quantum computing has broad application prospects; its algorithms can solve key problems in many fields. For example, Shor's algorithm can factor integers in polynomial time, making it possible to break the RSA encryption protocol in cryptography; in machine learning, Grover's algorithm can reduce the time complexity of the search process from O(N) to... Quantum support vector machines can reduce the training time complexity from O(M) of classical algorithms. 2 The value of N is reduced to O(logMN). Currently, several languages ​​are available for writing quantum programs to execute quantum algorithms, such as IBM's Qiskit, Google's Cirq, Microsoft's Q#, and Origin Quantum's Qpanda.

[0003] Similar to classical programs, quantum programs also suffer from defects that can cause them to malfunction. To ensure the quality and reliability of quantum programs, software testing techniques are commonly used in software engineering to evaluate and analyze the behavior of the tested program, followed by program repair techniques to eliminate defects by generating correct patches. However, current research in the field of quantum program testing focuses only on how to test quantum programs and how to classify and summarize defects, while program repair remains unresolved. Unlike classical computing, quantum measurement is the only means of obtaining quantum information in a real quantum system. Such operations cause quantum state collapse, completely altering the original qubit. Therefore, directly applying classical computational program repair techniques to quantum computing seems impractical and ineffective. This is because most previous research focused on program defects at the code and statement level, while the results of each line of code cannot be observed in quantum computing. In fact, the superposition and entanglement of quantum states in quantum computing allow qubits to store more potential information and perform reversible computational operations. To fully utilize the characteristics of quantum computing, a novel and targeted quantum program repair method is needed.

[0004] In quantum mechanics, the process by which a quantum system transforms from one state to another over time is called evolution. In practice, running a quantum program is considered the evolution of a real qubit, and it exhibits strict unitary properties. In other words, the evolution from the initial state to the final state can be represented as a unitary linear mapping. The evolution process is crucial for realizing computational functions in a quantum program. Defects in the evolution process, while not causing the program to crash, will output incorrect results. Theoretically, defects in the evolution process can be understood as violating the expected computational process, resulting in a reversible unitary operation between the defective and expected quantum programs. Therefore, by adding repair operators at appropriate locations as patches, the influence of the unitary operation introduced by the defect can be eliminated, ensuring that the repaired program and the expected program have the same quantum measurement results.

[0005] How to establish a reasonable automatic repair framework for the characteristics of quantum programs, and how to design algorithms to locate, generate, and verify patches, are the key points and difficulties in the design of automatic program repair methods, and are also the problems that this invention aims to solve. Summary of the Invention

[0006] This invention utilizes the physical model of quantum computing to propose a comprehensive theoretical framework for automated quantum program repair. Unlike program repair techniques in classical computing, the method of this invention can eliminate multiple defects and achieve a fully automated program repair process.

[0007] Building upon existing program repair techniques, this invention introduces a repair location method to add patches and employs a generation and verification process to repair quantum programs. Without modifying the original code of the evolution process, this method aims to find suitable repair operators as patches before or after evolution. Specifically, through a thorough testing process, sufficient initial states and measurement results can be obtained. Based on the measurement results, estimates corresponding to the evolution process of the defective program can be calculated, thereby aiding in patch generation. Subsequently, candidate patches are selected sequentially, and each repair version is verified, ultimately yielding at least one version that conforms to the program specification.

[0008] Furthermore, this invention also addresses how to reduce candidate patches with equivalent effects and how to modify non-unitary repair operators into valid unitary operators. On the one hand, irreversible measurement operations lead to non-unique estimates of the final state, resulting in a large number of potentially valid estimation operators, thus making candidate patches redundant. Therefore, reducing the number of estimation operators is valuable for reducing the complexity of patch verification. On the other hand, due to the statistical randomness of the measurement process and the floating-point errors of computer operations, theoretically unitary operators may become non-unitary operators, preventing patches from being successfully added to the quantum program. Therefore, it is necessary to design a general method to transform repair operators into unitary operators that can be accepted by the program without causing crashes.

[0009] The quantum program auto-repair framework involved in this invention is as follows: Figure 1 As shown, it mainly includes a testing section (quantum program testing) and a repair section (repair operator calculation and verification, repair mode selection).

[0010] For the quantum program testing section: This invention treats the initial state as the input test case and the measurement result as the output. Since the internal state of the quantum evolution process cannot be observed, it can be considered a black box model. The location for repair and positioning can be set to the position before and after quantum evolution.

[0011] For the operator calculation and correction section: This section mainly includes operator solving, evolution estimation, and patch correction. These three parts are also the key technical points and difficulties in realizing the framework proposed in this invention. Operator solving mainly involves mathematically modeling the quantum program, abstracting the program operation process into unitary operators, and then solving the program's evolution operators and quantitatively representing the repair operators through input and output. Evolution estimation aims to solve the two problems of how to estimate the evolution process of a defective program based on measurement results, and how to reduce the estimated results. Patch correction proposes a general method to correct the calculated patches into legitimate unitary operators that can be accepted by the program.

[0012] Therefore, this invention proposes an automatic quantum program repair method based on unitary operations, which includes the following steps:

[0013] Step 1) Treat the quantum program as a black box model and model it, establish reasonable equations between the initial state, the final state and the evolution process, and perform preliminary solutions for the evolution operator;

[0014] Step 2) Define two repair modes: pre-repair and post-repair, and establish a reasonable mathematical relationship;

[0015] Step 3) Use a test case set with a sufficiently orthogonal basis, and use the KL divergence of the output and expected probability distributions as the evaluation criterion for test predictions.

[0016] Step 4) Based on the test results, the evolution operator is corrected and further estimated, and the equivalent estimated operator is reduced;

[0017] Step 5) Calculate candidate patches and perform unitization correction on non-unitary patches.

[0018] The advantages and beneficial effects of this invention are as follows:

[0019] First, the present invention can treat the program as a black box model, thus making the patch location process less demanding, only requiring introduction at a fixed position before and after evolution.

[0020] Second, this invention abstracts all computational processes into a single unitary operator, thereby enabling the solution of the problem of repairing quantum programs containing multiple defects;

[0021] Third, by establishing mathematical relationships, this invention can transform the program repair process into a mathematical operation process, thereby enabling a fully automated process of patch location, generation, and verification without the need for developer intervention.

[0022] Therefore, this invention can automatically repair quantum programs, thereby reducing repair costs and improving the quality of quantum programs. Attached Figure Description

[0023] Figure 1 It is a quantum program automatic repair framework.

[0024] Figure 2 It is the patch generation and verification process.

[0025] Figure 3 This is an example of quantum program repair. Detailed Implementation

[0026] The following is combined Figure 1-3 As shown, the automatic quantum program repair method based on unitary operation proposed in this invention is described in detail below:

[0027] Step 1) Treat the quantum program as a black box model and model it, establish reasonable equations between the initial state, the final state, and the evolution process, and perform preliminary solutions for the evolution operator; specifically:

[0028] For a quantum program with n qubits, the states before and after performing qubit operations are called the initial states. The final state |ψ> is defined by vectors, and in quantum computing, any quantum state can be represented by a vector. For a quantum system, the change of a qubit over time is called evolution. Therefore, for a quantum program, the evolution from the initial state to the final state can be abstracted as a unitary linear transformation. U∈U(2n ), where U(2 n ) represents 2 n ×2 n The unitary group of dimension, where each unitary operator has the property In quantum mechanics, symbols This indicates the conjugate transpose of the operator, and the symbols |·> and <·| represent column vectors and row vectors, respectively, and there is a relation between them.

[0029] Assuming that potential defects in a quantum program do not cause program crashes but lead to erroneous outputs, we can assume that these defects exist within the quantum evolution process. For a quantum program implementing a specific function, the expected output under specified inputs can be defined in the test suite, thus abstracting it into an expected program. The purpose of program repair is to fix the defective program so that its output matches the expected result. Let U be the unitary operator corresponding to the evolution processes of the expected program and the defective program. e U d For a quantum program containing n qubits, its quantum state... This means that the program's computational space can be increased by 2. n A series of linearly independent quantum states span the quantum states, allowing for reversible linear operations. If given 2... n An orthogonal initial state The final states corresponding to the two programs are respectively The superscript (i) indicates the i-th (i = 0, 1, ..., 2) n -1) Initial states are used as test cases, and their corresponding final states are used as output results. Then, through the linear relationship between input and output... and It can be solved.

[0030]

[0031]

[0032] Step 2) Define two repair modes: pre-repair and post-repair, and establish a reasonable mathematical relationship; specifically:

[0033] To determine whether the repair result is valid, let U be the evolution operator of the program after repair. r Then the expected repair result must either satisfy U r =U e Or the repair procedure and the expected procedure have the same measurement results. In quantum computing, quantum states... The measurement yielded the result m (m = 0, 1, ..., 2). n The probability of -1 can be expressed as Where Mm For the measurement operator and M m =|m><m|,|m> Let be a natural basis, that is, a unit vector whose (m+1)th element is 1 and all other elements are 0. Therefore, specifically, an effective repair result satisfies:

[0034]

[0035] Based on the unitary properties of the evolutionary process, this invention defines two repair modes: pre-repair and post-repair, and uses unitary operators as patches (U) to repair defective programs. p Pre-repair is achieved by introducing a repair operator U. ep Make U r =U d U ep Post-repair is achieved by introducing the repair operator U. op Make U r =U op U d Under normal circumstances, U d It cannot be calculated directly because the final state |ψ d It cannot be uniquely determined through measurement. However, the evolution of a defective program can be estimated using the measurement results, and then the estimated value can be used. Replace the true value U d Perform the calculation. Based on the above requirements, the two repair operators can be defined as follows:

[0036]

[0037]

[0038] Step 3) Use a test case set with a sufficiently orthogonal basis, and use the KL divergence between the output and expected probability distributions as the evaluation criterion for test predictions; specifically:

[0039] If given test cases The conditional probability distributions of the measurement results of the expected procedure and the repaired procedure are respectively The index D can then be defined based on the KL divergence. maxKL (E||R),

[0040]

[0041] D maxKL The smaller (E||R) is, the closer the repaired program is to the expected program. In particular, if Then D maxKL(E||R) = 0. However, since the calculated probability is replaced by the frequency of a large number of measurement results, statistical randomness means that even a successfully repaired program will not have exactly the same probability distribution as the expected result, and thus D maxKL (E||R) approaches 0 but D maxKL (E||R) ≠ 0. Given a reasonable threshold T KL > 0, if D maxKL (E||R) < T KL it can be concluded that the repair is successful; otherwise, the repair fails. In subsequent processes, multiple patches can still be used for repair. If at least one patch can be repaired successfully, it indicates that the method proposed by the present invention is effective.

[0042] Step 4): correcting and further estimating the evolution operator according to the test results, and reducing the equivalent estimation operators; the specific steps are as follows:

[0043] The process of patch repair and verification is as Figure 2 shown. First, a preliminary estimation of the evolution operator in the defective program is required. To obtain the estimated solution the final state |ψ d > can be estimated based on the measurement results first. Suppose p(m|i) is the test case the conditional probability of obtaining result m when used as input. Then an estimated value in the real vector space can be obtained as

[0044]

[0045] In fact, the estimation operator calculated from and the estimation operator calculated from the above is not necessarily a unitary operator, so it is necessary to correct the preliminary estimation before a reasonable patch can be generated.

[0046] In the process of generating candidate patch U p the present invention considers two processes: correction and reduction. The correction process constructs a symbolic matrix to perform Hadamard product on that is, elements at the same positions in the two matrices are multiplied. If it can be regarded as a unitary operator within a certain error range ε (ε u > 0), then it can be considered that u and ​it can be added to the candidate estimation subset EO. In fact, the estimation values in EO may correspond to equivalent patches, specifically if generates patches respectively as estimation values if the two patched and repaired programs obtain the same measurement result, it is defined that are equivalent. An estimation difference operator is introduced to represent the linear relationship between different estimation operators,

[0047]

[0048] if is a scalar matrix, then are equivalent. Elements in EO can be merged based on equivalence, after all equivalent operators are merged, the reduced estimation subset EO can be obtained S .

[0049] For each the corresponding repair patch U can be calculated p . Subsequently, after decomposing the patch into quantum gates, it can be added to the measured program for repair and verification. Given a reasonable threshold T KL > 0, if D maxKL (E||R) < T KL it indicates that the repair is successful, otherwise the repair fails. If the repair fails, select another and repeat the above process.

[0050] Step 5): Calculate candidate patches, and perform unitarization correction on non-unitary patches, specifically:

[0051] In the actual operation process, due to the randomness of measurement and the floating-point error of numerical operation, the calculated operator U p is not necessarily a unitary operator, so it is expected that the obtained through correction satisfies the following within the error limit ε given by the API:

[0052]

[0053] and it is necessary to ensure that the difference before and after correction is as small as possible. The present invention adopts the numerically stable Householder transformation in QR decomposition to solve this problem, that is:

[0054] U p = QR

[0055]

[0056]

[0057] Where Q∈U(2) n ) is a unitary group. It is a triangular array on the positive axis and a diagonal array S. D It is a sign adjustment matrix to ensure Smaller.

[0058] The following explanation, using specific numerical values, further illustrates the point:

[0059] Regarding the proposed method, the framework of this invention can be... Figure 3 The following explanation uses a quantum program and its corresponding quantum circuit as an example, where the program is based on the Qikit quantum programming language. The target for repair can be abstracted into a desired quantum program by defining the expected output under the test cases specified in the program specification and test suite. A defective quantum program can be understood as an incorrect output program that, compared to the desired program, incorrectly calls the API, resulting in erroneous output. Figure 3 The task is to achieve the superposition of two qubits. Assume the selected test case is C. 4 Four natural bases in space The expected input-output relationship can then be expressed as:

[0060]

[0061]

[0062]

[0063]

[0064] The probability distribution of the corresponding measurement results is as follows:

[0065]

[0066]

[0067] If using When testing a defective program, the resulting output probability distribution is:

[0068]

[0069]

[0070] According to the KL divergence index D maxKL (E||R)=∞>T KL The program is clearly outputting an error. Next, a reasonable preliminary estimate of the final state can be given.

[0071]

[0072]

[0073] In combination with and then solve to obtain:

[0074]

[0075] Since is not a unitary operator, a symbolic matrix can further be constructed through enumeration or designing a heuristic search method,

[0076]

[0077] such that is a unitary operator, and,

[0078]

[0079] In fact, Λ is not unique, but it can be reduced through equivalence merging. For example, for the above Λ, if then is a scalar matrix, and further the values calculated by (-1)Λ and Λ are and are equivalent.

[0080] After equivalence merging, if only the repair operator patch can be solved by definition.

[0081] Pre-repair:

[0082]

[0083] Post-repair:

[0084]

[0085] Combined with the actual repaired quantum program, it can be known that if T is set as KL = 5×10 -3 , for the above situation, the actual program operation result may cause the two measurement results not to be necessarily the same due to measurement randomness and floating-point error, but D must satisfy maxKL (E||R)→0,

[0086] further D maxKL (E||R)<T KL , indicating that the repair is successful.

[0087] Since the measurement randomness and floating-point operation error are not considered in the analysis process, the above derivation process cannot analyze the correction of the operator. Therefore, the present invention analyzes the following matrix correction process in numerical calculation. If Up High precision was lost in the calculation, let's assume

[0088]

[0089] So the revised It has higher accuracy, and

[0090]

[0091]

[0092]

[0093] It is easy to see from the above specific examples that each part of the method proposed in this invention is reasonable and effective.

Claims

1. A quantum program automatic repair method based on unitary operations, characterized in that: The method includes the following steps: Step 1) Treat the quantum program as a black box model and model it, establish reasonable equations between the initial state, the final state and the evolution process, and perform preliminary solutions for the evolution operator; Step 2) Define two repair modes: pre-repair and post-repair, and establish a reasonable mathematical relationship; use unitary operators as patches to repair defective programs. Pre-repair is achieved by introducing a repair operator. Make Post-repair is achieved by introducing a repair operator. Make ; in, It cannot be calculated directly because of the final state. It cannot be uniquely determined by measurement; therefore, an estimated value is used. Replace the true value Perform calculations; the two repair operators are defined as follows: ; Step 3) Use a test case set with a sufficiently orthogonal basis, and use the KL divergence of the output and expected probability distributions as the evaluation criterion for test predictions. Step 4) Based on the test results, the evolution operator is corrected and further estimated, and the equivalent estimated operator is reduced; Step 5) Calculate candidate patches and perform unitization correction on non-unitary patches.

2. The automatic quantum program repair method based on unitary operation according to claim 1, characterized in that: In step 1, for those with A quantum program with 1 qubits, the states before and after performing qubit operations are called the initial states. and final state In quantum computing, any quantum state is represented by a vector.

3. The automatic quantum program repair method based on unitary operation according to claim 1 or 2, characterized in that: In step 1, for a quantum program, the evolution process from the initial state to the final state is abstracted as a unitary linear transformation. , ,in express The unitary group of dimension, where each unitary operator has the property ;symbol This represents the conjugate transpose of the operator, symbol... and Let them represent column vectors and row vectors respectively, and let them have a relationship. .

4. The automatic quantum program repair method based on unitary operation according to claim 3, characterized in that: In step 1, let the unitary operators corresponding to the desired program and the defective program evolution process be respectively... For those containing The quantum program of a qubit, its quantum state Given An orthogonal initial state The final states corresponding to the two programs are respectively , superscript Indicates the first The test cases are initialized with an initial state and their corresponding final states are outputs; then, through the linear relationship between input and output... and Solving for the given information, we can obtain the following results. ; 。 5. The automatic quantum program repair method based on unitary operation according to claim 1 or 4, characterized in that: In step 3, given test cases The conditional probability distributions of the measurement results of the expected procedure and the repaired procedure are respectively , Then, according to the KL divergence definition index , ; The smaller the value, the closer the repaired program is to the expected program; if ,So .

6. The automatic quantum program repair method based on unitary operation according to claim 1, characterized in that: In step 4, a preliminary estimate of the evolution operators in the defective program needs to be performed; the estimated values ​​are then solved. ,set up For test cases As input, the result is The conditional probability is given in the real vector space. The estimated value in , ; By and the estimated operator calculated is not necessarily a unitary operator, and it is necessary to perform preliminary estimation on for correction.

7. The automatic quantum program repair method based on unitary operation according to claim 6, characterized in that: In step 4, the two processes are correction and reduction; the correction process involves constructing a symbol matrix. ,right Perform Hadamard product That is, multiplication is performed on the elements of two matrices that are in the same position; if Within a certain error range If the inner can be considered as the *you* operator, then it is considered... ,and Add it to the candidate estimation subset ; if Patches were generated based on the estimated values. If the program after adding these two patches obtains the same measurement results, then define... They are equivalent; an estimate difference operator is introduced. This represents the linear relationship between different estimating operators. ; if If it is a scalar matrix, then They are equivalent; based on equivalence, Merge the elements in the file. After all equivalent operators are combined, a reduced set of estimated operators is obtained. ; For each The corresponding repair patch is calculated. The patch is then broken down into quantum gates and added to the program under test for repair and verification; a reasonable threshold is given. ,if This indicates the repair was successful; otherwise, the repair failed. If the repair failed, select another option. And repeat the above process.

8. The automatic quantum program repair method based on unitary operation according to claim 1, characterized in that: In step 5, the result obtained through correction Within the error limits given by the API Internal satisfaction: ; And it is necessary to ensure the differences before and after the correction. To minimize the size, the problem was solved using the numerically stable Householder transformation from QR decomposition, namely: ; ; ; in, It is a group of 'West'. It is a triangular array on the main line and a diagonal array. It is a sign adjustment matrix to ensure Smaller.