A Quantum Program Automatic Repair Method Based on Homotopy Method

Through the application of homoeconomic method and Clifford gate collection, the huge patch space and verification difficulties in quantum program automation repair are solved, and fast and accurate quantum program repair is achieved, which improves the repair success rate and universality of the method.

CN119807078BActive Publication Date: 2025-07-11ZHEJIANG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510294538.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-13
Publication Date
2025-07-11
Estimated Expiration
2045-03-13

AI Technical Summary

Technical Problem

The existing quantum program automation repair technology cannot be effectively applied to quantum programs, and there are problems such as huge patch space, difficulty in verification, high cost and low repair success rate.

Method used

The quantum program automation repair method based on homoethic method is adopted, and the quantum computer is repaired through assertion construction, test case generation, error positioning on classical computers and the differentiability of quantum gates is used to fix errors on quantum computers. The Clifford gate set is used to approximate quantum programs, which are converted into MAX-SMT problems and optimize quantum gate parameters.

Benefits of technology

Fast and accurate quantum program repairs at lower times are achieved, improving repair success rate, reducing patch positioning complexity and improving method versatility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119807078B_ABST
    Figure CN119807078B_ABST
Patent Text Reader

Abstract

The present invention discloses a quantum program automatic repair method based on a homotopy method, belonging to the technical field of quantum program repair, including: assertion construction: constructing an assertion for a defective quantum program, and defining the expected behavior of the quantum program from input to output through the assertion; test case generation: for the input space encoded into qubit states and gate parameters, sampling test cases in the input space by using the orthogonal decomposition of quantum states and quantum gates; error localization on a classical computer: constructing a patch on a classical computer, transforming the search for the patch into a MAX-SMT problem to locate multi-position patches, and replacing the set of general quantum gates in the patch with a set of Clifford gates to approximate the quantum program; error repair on a quantum computer: based on the test cases, using the differentiability of quantum gates to repair errors. This method realizes the automatic repair of quantum programs in a relatively short time and can improve the repair success rate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of quantum program repair, and particularly relates to an automated quantum program repair method based on a homotopy method. Background Art

[0002] Quantum programs have shown significant acceleration potential in certain fields (such as financial technology and chemical analysis). However, due to human errors, logical errors inevitably occur in quantum programs, thus requiring program debugging. Unfortunately, compared with classical programs, the information representation and operations of quantum programs have significant differences in semantics and behavior, making many errors difficult to solve. For example, on Stack Overflow (a community of software developers and programmers), only 21% of the errors related to quantum programs have been solved, which is 4.1 times lower than that of classical programs. Therefore, compared with manual repair, automated program repair (APR) has become a natural choice.

[0003] However, the current advanced APR techniques cannot be directly applied to automated quantum program repair (Q-APR). Typical APR techniques generate and verify repair patches heuristically until the program passes the test. A patch refers to a module that can correct the program. However, quantum programs use the quantum circuit model, which results in an extremely large patch space. For example, a 5-bit quantum program may have quantum operation combinations as patches. In addition, existing APR techniques use neural networks or semantic information to assist in repair, but current quantum programming languages lack semantic information (such as type systems and exception handling systems), and there is a lack of sufficient program data to effectively train neural networks.

[0004] Verifying patches in Q-APR further increases the difficulty. Performing state density matrix tomography on quantum hardware requires exponential complexity because quantum measurements cause quantum collapse. On the other hand, verification through simulation on a classical computer also faces exponential complexity. For example, simulating a 53-bit quantum program requires 128 PiB of memory and 20 days of running time (using the Summit supercomputer). To ensure the correctness of the patch, the number of required test inputs will further increase. For example, the Quito tool (a coverage-based quantum program test generator) needs to run different test inputs to verify whether an 11-bit quantum lock program error has been correctly repaired.

[0005] To address these challenges, some Q-APR methods employ large language models and program synthesis to fix errors. For example, ChatGPT is used to repair quantum programs, but the high cost of running quantum programs inevitably limits the training data, resulting in a success rate of less than 20% in fixing quantum errors on Stack Overflow. Another example is to approximate the correct program by appending a large unitary matrix after the problematic program, which relies on synthesizing the unitary matrix into executable quantum gates. However, for quantum programs with more than 8 qubits, even the optimal synthesis algorithm takes more than a year to output a high-quality program, or it can complete the synthesis in a few minutes but generates thousands of redundant gates. Summary of the Invention

[0006] In view of the above, an object of the present invention is to provide a quantum program automatic repair method based on the homotopy method, which can achieve the automatic repair of quantum programs in a relatively short time and improve the repair success rate.

[0007] To achieve the above object of the invention, an embodiment provides a quantum program automatic repair method based on the homotopy method, including the following steps:

[0008] Assertion construction: Construct an assertion for the defective quantum program, and define the expected behavior of the quantum program from input to output through the assertion;

[0009] Test case generation: For the input space encoded into qubit states and gate parameters, sample test cases in the input space using the orthogonal decomposition of quantum states and quantum gates;

[0010] Error localization on a classical computer: Construct a patch on a classical computer, transform the search for the patch into a MAX-SMT problem to locate multi-position patches, and replace the set of general quantum gates in the patch with a set of Clifford gates to approximate the quantum program;

[0011] Error repair on a quantum computer: Based on the test cases, utilize the differentiability of quantum gates to repair errors. The repair process is achieved by minimizing the objective function derived from the assertion. The gradient of the gate parameters is calculated on a simulator or a quantum computer. If the assertion condition is satisfied after repair, the repaired quantum program will be output; if the assertion is not satisfied, the error localization stage will be returned to gradually approach the correct quantum program.

[0012] Preferably, the expected behavior of the quantum program defined by the assertion is represented by the implication relationship between the input and output of the quantum program, where the antecedent of the assertion defines the spatial range of the input, and the consequent gives the expected relationship between the program input and the runtime state, expressed as:

[0013] ;

[0014] Among them, represents test cases in the input space range, represents the measurement probability distribution of the quantum program output, and represent two constraints, and and must comply with the satisfiability modulo theory formula, and is defined as a polynomial objective function, the symbol represents derivation, and the symbol represents definition, represents assertion;

[0015] The meaning of the assertion is: If the input t and output p satisfy the constraint , then the constraint should also be satisfied. The functions of the quantum program are described by defining multiple assertions, and these assertions are aggregated into a single repair process.

[0016] Preferably, during the test case generation process, there are two encoding schemes for the input of the quantum program, namely the state encoding scheme, which encodes the input as a quantum bit state, and the quantum bit state is represented as a vector; the gate encoding scheme, which encodes the input as the gate parameters of a quantum gate, and the gate parameters are represented as a unitary matrix;

[0017] For the input of the state encoding scheme, test cases are sampled from the orthonormal state space;

[0018] For the input of the gate encoding scheme, the quantum gate is replaced by a combination of a measurement operation and a subsequent quantum gate operation. The measurement operation is sampled from the basic set, and the quantum gate is sampled from the gate set;

[0019] Finally, these two encoding schemes orthogonally constitute the input space, which is regarded as the tensor product of the state space and the gate space. Based on this input space, test cases are obtained through orthogonal decomposition sampling.

[0020] Preferably, the variables in the MAX - SMT problem represent the possible positions of the patches and the quantum bit states during the program execution. The constraints of the problem include assertions and the changes in the quantum bit states after applying different gate operations.

[0021] Preferably, the variables in the problem include:

[0022] Variable one, the variable for patch insertion: An auxiliary layer is attached after each layer to place the patch, and a boolean variable is used to represent whether a quantum gate is applied to certain quantum bits in a certain auxiliary layer;

[0023] Variable two, the variable for quantum bit state: For the approximated quantum program, the quantum bit state after each layer is represented by a stabilizer table;

[0024] The constraints of the problem include:

[0025] Constraint 1, the constraint between patches: At each layer, due to the limitations of the quantum circuit model, each qubit can be operated on by at most one gate;

[0026] Constraint 2, the constraint of the gate operation: If a certain quantum gate is applied, the state of the qubits in the next layer is determined by the state of the previous layer through a Boolean operation;

[0027] Constraint 3, the constraint of the assertion: The goal of localization is to find patches that satisfy the assertion, and the assertion is added as two constraints: 1. For to hold, 2. , is a complex value, represents the m th test case, represents the test output after passing through the quantum program corresponding to the quantum program.

[0028] Preferably, replace the set of general quantum gates in the patch with a set of Clifford gates to approximate the quantum program, including:

[0029] For each quantum gate g in the quantum program, calculate the unitary matrix of each quantum gate g through the Hilbert - Schmidt test and the unitary matrix of each gate in the Clifford gate set the distance between:

[0030] ;

[0031] wherein, is the dimension of the unitary matrix, is the trace operation of taking the sum of the diagonal elements of the matrix, represents the conjugate transpose of the matrix,

[0032] Based on the distance , replace the quantum gate g with the gate in the Clifford gate set that is closest to the quantum gate g to obtain an approximate program.

[0033] Preferably, for the differentiability of the quantum gate, let be a parameterized quantum program, where the quantum gate parameter is a real value, and the quantum program is differentiable with respect to the parameter , which means that for the r - th parameter , the partial derivative exists and is continuous;

[0034] Any quantum program containing parameterized quantum gates is regarded as a parameterized program. The Clifford gates in the patch are converted into parameterized quantum gates according to the equivalence. The goal of optimizing based on the parameterized program is to minimize the constraints of the assertion , while satisfying the constraints :

[0035] ;

[0036] Among them, represents the parameterized output for the input , represents the satisfied condition, represents finding the minimum quantum gate parameters.

[0037] Preferably, the repair process is to update the quantum gate parameters within L cycles, specifically:

[0038] In each cycle, a set of test inputs X is generated by randomly calculating the linear combination of test cases. The program runs with these inputs X to obtain the parameterized output ; then, the test inputs are filtered, and only those that satisfy the constraints are retained; the gradient is first initialized to 0. Then, for each parameter , and perturbations are added, and the gradient of the parameterized output is calculated and updated. If the assertion holds in the test case, that is , the repaired quantum program is output.

[0039] Preferably, the parameter translation method is used to calculate the gradient of the quantum gate parameters.

[0040] Compared with the prior art, the beneficial effects of the present invention at least include:

[0041] The repair process of the quantum program proposed by the present invention, based on a method similar to homotopy, can perform program repair quickly and accurately, and at the same time has high generality;

[0042] The present invention introduces a test case generation method, supports multiple quantum input encoding schemes, and combines with the orthogonal basis of the quantum program to achieve higher input coverage;

[0043] The present invention reduces the complexity of Q-APR patch location. By formalizing it as a symbolic reasoning problem and utilizing the differentiability of quantum gates, its complexity is reduced to a polynomial level. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the accompanying drawings required for the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0045] Figure 1 is a schematic flow chart of the homotopy-like method provided by the embodiment for quantum program repair;

[0046] Figure 2 is a flow chart of the quantum program automatic repair method based on the homotopy method provided by the embodiment;

[0047] Figure 3 is a schematic flow chart of generating test cases provided by the embodiment;

[0048] Figure 4 is a schematic diagram of fault location based on SMT provided by the embodiment. Detailed implementation manners

[0049] To make the objectives, technical solutions and advantages of the present invention clearer and more understandable, the following further details the present invention in conjunction with the accompanying drawings and embodiments. It should be understood that the specific implementation manners described herein are only used to explain the present invention and do not limit the protection scope of the present invention.

[0050] The inventive concept of the present invention is: a quantum program automatic repair method based on the homotopy method, which adopts a method similar to homotopy, and uses the iterative switching between a classical computer and a quantum computer to locate and repair errors, as Figure 1 shown in (a) therein. The typical homotopy method solves problems by gradually transforming a complex optimization problem into a simpler problem and evolving back to the original problem. For this purpose, it creates a continuous path, that is, a homotopy. Inspired by this, as Figure 1 shown in (b) therein, the present invention converts the quantum program into a more simplified and affordable form for easy analysis on a classical computer. In this way, the present invention gradually optimizes the simplified program to identify the coarse-grained patch positions, and then refines the quantum program to capture the fine-grained gate parameters. Finally, it can gradually converge to the correct program.

[0051] Specifically, in the implementation process, first, the correct behavior of the quantum program is specified through an implication assertion annotation. A test case is generated using the orthogonal basis of the quantum program to achieve maximum input coverage. To reduce the high computational overhead, the patch localization problem is approximately transformed into a symbolic reasoning problem through Clifford analysis (which is a generalization of complex function theory to higher dimensions, and in the four-dimensional case, i.e., quaternion analysis, mainly studies the kernel function of the Dirac operator). This method not only achieves high precision but also reduces the complexity of patch localization from to approximation. This localization process determines the specific location of the patch and the qubits it acts on. Subsequently, the correct parameters of the patch are searched, and by utilizing the differentiability of quantum gates, the computationally intensive execution tasks in the program are transferred to the quantum hardware for processing.

[0052] As Figure 2 shown, a quantum program automated repair method based on the homotopy method provided by the embodiment includes the following steps:

[0053] S1, Assertion construction: Construct an assertion for the defective quantum program to define the expected behavior of the quantum program through the assertion.

[0054] In the embodiment, a user-defined assertion is used as the optimization target for repair. The expected behavior of the quantum program defined by the assertion is represented by the implication relationship between the input and output of the quantum program. Among them, the antecedent of the assertion defines the spatial range of the input, and the consequent gives the expected relationship between the program input and the runtime state, expressed as:

[0055] ;

[0056] Among them, represents the test case in the spatial range of the input, represents the measurement probability distribution of the output of the quantum program, and represent two constraints, and and must comply with the SMT (Satisfiability Modulo Theories) formula, expressed as polynomial inequalities, and is defined as a polynomial objective function, the symbol represents derivation, the symbol represents definition, represents the assertion.

[0057] The meaning of the assertion is: If the input t and the output p satisfy the constraint , then they should also satisfy the constraint , multiple assertions are defined to describe the functionality of a quantum program, and these assertions are aggregated into a single repair process. In theory, p can be any measurement probability distribution derived from the runtime state. For the sake of simplicity in discussion, p will be regarded as the program output in the following sections.

[0058] Take the Grover algorithm as an example, which is a quantum algorithm widely used in pattern matching and recommendation systems. The Grover algorithm is verified through module testing, which consists of an oracle function and a Grover subroutine. The input bit string t is encoded into the quantum gate parameters to flip the phase of its corresponding ground state ∣t>. In a correct Grover program, this input bit string is expected to have a relatively high measurement probability (e.g., ). For example, when the input is 0110, the phase of the ground state ∣0110> will be flipped in the oracle function. Therefore, the probability of obtaining 0110 in the output is approximately 76%. This assertion is defined as follows:

[0059] ;

[0060] where, represents the probability of the bit string t in the output. When the number of qubits is 4, the range of t is , and (integer).

[0061] S2, test case generation: For the input space encoded into qubit states and gate parameters, use the orthogonal decomposition of quantum states and quantum gates to sample test cases in the input space.

[0062] The test case generation method provided by the present invention can cover as large an input space as possible and can repair and extend to untested inputs. Specifically, the present invention automatically generates a test case set composed of test cases by sampling the input space encoded into qubit states and gate parameters. The key feature of these sampled inputs is that their execution results can be generalized to other untested inputs, thereby enhancing the overfitting tolerance ability of the method of the present invention.

[0063] In the embodiment, the input of the quantum program can be encoded by two encoding methods: (1) State encoding scheme, which encodes the input as qubit states, and the qubit states are represented as vectors; (2) Gate encoding scheme, which encodes the input as the gate parameters of quantum gates, and the gate parameters are represented as unitary matrices. According to the different encoding schemes, the following different sampling strategies are adopted:

[0064] For the input of the state encoding scheme, sampling test cases from the orthonormal state space in Document 1 (Hadamard-free circuits expose the structure of the Clifford group). Sampling test cases from it;

[0065] For the input of the gate encoding scheme, the quantum gate is replaced by a combination of a measurement operation and a subsequent quantum gate operation. The measurement operation is sampled from the basic set and the quantum gate is sampled from the gate set where respectively represent:

[0066] X (Pauli-X, or the NOT gate), ;

[0067] Y (Pauli-Y), ;

[0068] I (the identity matrix), ;

[0069] H (the Hadamard gate), ;

[0070] HS is a combination of H and the S gate. The S gate is a phase gate and its matrix representation is:

[0071] , then .

[0072] Finally, these two encoding schemes orthogonally form the input space, which can be regarded as the tensor product of the state space and the gate space ( ). Based on this input space, test cases are obtained through the above orthogonal decomposition sampling. As far as is known, the existing test case set generation methods can only generate test cases for the state encoding scheme, thus limiting the generality of the existing quantum program automatic repair (Q-APR) methods.

[0073] Figure 3 Shows the process of generating the test case set: The input input1 represents the state encoding scheme, and its sampling space contains 3 basic states; the input input2 represents the gate encoding scheme, and its input space contains 12 combinations of measurement and gate operations. Therefore, the total number of test cases is 36. For example, in the first test case, input1 is set to ∣0>, and the gate operation of input2 measures in the X basis, followed by an I gate operation.

[0074] Based on this, the sampling generality of test cases is as follows: for inputs using the state encoding or gate encoding scheme, define the set of test cases as the input and the corresponding output set , where represents the m th test case, represents the test output corresponding to the quantum program;

[0075] For any input represented by a linear combination of test cases :

[0076]

[0077] where is a complex value, then the output for the input p is:

[0078]

[0079] The generality of the state encoding scheme stems from the isomorphism theory proposed in the literature (MorphQPV: Exploiting Isomorphism in Quantum Programs to Facilitate Confident Verification). The generality of the gate encoding scheme can refer to the circuit partitioning theory of distributed quantum computing. Based on the generality of the input space, assertion verification can ensure that the assertion holds for any linear combination of test cases, thus maximizing the coverage of the input space.

[0080] S3. Locate errors on a classical computer: Build patches on a classical computer, and transform the search for patches into a MAX-SMT (i.e., maximum satisfiability modulo theory) problem to locate multi-position patches, and replace the set of general quantum gates in the patches with a set of Clifford gates to approximate the quantum program.

[0081] In the embodiment, first build patches on a classical computer, and transform the search for patches into a MAX-SMT problem to locate multi-position patches. The variables in the problem represent the possible positions of the patches and the states of the qubits during program execution. The constraints of the problem include assertions and the changes in the qubit states after applying different gate operations. To accelerate the exploration of the space, replace the set of general quantum gates with a set of Clifford gates to approximate the quantum program. Since the operations are reduced to Boolean expressions, this method exhibits polynomial complexity.

[0082] Specifically, simulating quantum behavior on a classical computer usually faces huge computational overheads, making it very time-consuming to verify possible patches. On the other hand, verification on a quantum computer is not flexible enough due to the problem of quantum state collapse. To accelerate verification, the embodiment adopts a homotopy-like method, approximating the quantum program by using Clifford gates to reduce the simulation difficulty. First, define the Clifford gate set:

[0083] The Clifford gate set is a subset of the universal quantum gates, including 24 single-qubit gates and 3 two-qubit gates. During the approximation process, for each quantum gate g in the quantum program, calculate the unitary matrix of each quantum gate g through the Hilbert-Schmidit test and the unitary matrix of each gate in the Clifford gate set the distance between them:

[0084] ;

[0085] where, is the dimension of the unitary matrix, is the trace operation of taking the sum of the diagonal elements of the matrix, represents the conjugate transpose of the matrix. Based on the distance replace the quantum gate g with the gate in the Clifford gate set that is closest to the quantum gate g to obtain an approximate program.

[0086] The reason for choosing the Clifford gate set is that it contains the most commonly used single-qubit and two-qubit gates. In addition, in current quantum algorithms, more than 60% of the quantum gates belong to the Clifford gates. When a quantum program consists only of Clifford gates, its N-qubit quantum state can be represented as a stabilizer table, rather than a dimensional state vector. The stabilizer table is as follows:

[0087]

[0088] Each element in the table is a boolean value. For an N-qubit quantum program, its stabilizer table contains elements. Clifford quantum gates can be calculated through boolean operations instead of matrix-vector multiplication. For example:

[0089] Applying the X gate to qubit i: For each row k, execute .

[0090] Applying the H gate to qubit i: For each row k, swap and , and execute 。

[0091] Apply the CNOT gate to qubits i and j: For each row k, perform the following operations:

[0092] ,

[0093] ,

[0094]

[0095] represents the exclusive-or operation (XOR). The operations of all Clifford gates can be completed within a time complexity of no more than polynomial.

[0096] In the embodiment, a gate-level-based patch is also used to repair the quantum program. The patch is a quantum gate inserted into the quantum program. The patch using the Clifford gate set in the positioning stage will be transformed into a parameterized gate in the error repair stage. Representing the patch positioning as a MAX-SMT problem. As Figure 4 shown, this MAX-SMT problem contains two types of variables and three types of constraints.

[0097] Use layers to represent the execution order of quantum gates. For example, Figure 4 the first layer, the second layer, etc. in , and the gates in the same layer can be executed in parallel. These two types of variables include:

[0098] Variables for patch insertion: That is, an auxiliary layer is appended after each layer. For example, the 1.1 layer, the 1.2 layer, etc. to place the patch. The number of auxiliary layers is specified by the user and depends on the expected search space. Use boolean variables to represent whether a quantum gate is applied to certain qubits in a certain auxiliary layer. For example, the boolean variable represents that a CX gate is applied to qubits and in the 3.1 layer, and the boolean variable represents that a CX gate is applied.

[0099] Variables for qubit states: For an approximated quantum program, the qubit states after each layer can be represented by a stabilizer table, which contains a total of (2N + 1) variables.

[0100] Three types of constraints are used to specify the relationships between variables, specifically including:

[0101] Constraint 1, constraints between patches: That is, in each layer, due to the limitations of the quantum circuit model, each qubit can be operated on by at most one gate;

[0102] Constraint 2, Constraint on gate operation: That is, if a certain quantum gate is applied, the state of the qubits in the next layer is determined by the state of the previous layer through a Boolean operation. For example, the Boolean variable : indicates that for the operation gate , the state of the qubits in the second layer is determined by the state of the qubits in the first layer through the Boolean operation .

[0103] Constraint 3, Constraint on assertion: The goal of localization is to find patches that satisfy the assertion. The assertion is added as two constraints: 1. holds for , 2. . These two constraints ensure that the patch makes the assertion hold under the test case and its linear combination. Since the approximate quantum program can only determine the most likely patch, the second constraint is a soft constraint.

[0104] The MAX - SMT problem will be handed over to the Z3 solver. By finding the truth assignment related to patch insertion, the possible patch positions and the types of quantum gates for repairing the quantum program can be obtained.

[0105] S4, Based on the test case, utilize the differentiability of the quantum gate to repair the error. The repair process is achieved by minimizing the objective function derived from the assertion. The gradient of the gate parameters is calculated on the simulator or quantum computer. If the assertion condition is satisfied after repair, the repaired quantum program will be output; if the assertion is not satisfied, the error localization phase will be returned to gradually approach the correct quantum program.

[0106] Error localization uses an approximate quantum program to identify patches. Subsequently, a homotopy - like method is executed on the exact program containing these patches to further fine - tune the parameters of the quantum gates to approach the correct program. This fine - tuning can be performed on the quantum computer, thus avoiding the computationally intensive simulation process.

[0107] Regarding the differentiability of the quantum gate, let be a parameterized quantum program, where the quantum gate parameter is real - valued. The quantum program is differentiable with respect to the parameter , which means that for the r - th parameter , the partial derivative exists and is continuous. Mathematically, this can be expressed as: , represents the unit vector in the r - th direction.

[0108] Any quantum program containing parametric quantum gates such as RX, RY, and RZ gates can be regarded as a parametric program. Additionally, Clifford gates in the patch can be converted to parametric gates according to equivalence. For example, the X Clifford can be converted to a parametric RX gate with a default parameter of . The goal of optimization is to minimize the constraints of the assertion , while satisfying the constraints :

[0109]

[0110] where, represents the parametric output, represents the satisfied conditions, represents finding the minimum quantum gate parameters.

[0111] The parameter shift method is adopted to calculate the gradient of the quantum gate parameters. This method allows the quantum program to run directly on the quantum computer, eliminating the need for computationally intensive simulations. The specific repair process is as follows: Update the quantum gate parameters within L cycles. In each cycle, a set of test inputs X is generated by randomly calculating linear combinations of test cases. The program runs with these inputs X to obtain the parametric output ; then, the test inputs are filtered to retain only those that satisfy the constraints . The gradient is initially set to 0. Then, for each parameter , add and perturbations, and calculate and update the gradient of the parametric output . If the assertion holds in the test case, that is, , then output the repaired quantum program.

[0112] Experimental results show that compared with existing large language model-based technologies and synthesis-based technologies, the method of the embodiment of the present invention improves the repair success rate by 93.3% (14.9 times) and 62.5% (2.67 times) respectively. Additionally, the method of the present invention can repair a 20-qubit quantum program within 28.2 minutes and only requires 249 additional gates, while existing synthesis-based methods may take more than 6 months and more than additional gates.

[0113] The above-described specific embodiments have detailed the technical solutions and beneficial effects of the present invention. It should be understood that the above is only the most preferred embodiment of the present invention and is not used to limit the present invention. Any modifications, supplements, equivalent replacements, etc. made within the scope of the principles of the present invention shall be included in the protection scope of the present invention.

Claims

1. A quantum program automatic repair method based on the homotopy method, characterized in that The steps include the following: Assertion construction: Construct an assertion for a defective quantum program, and define the expected behavior of the quantum program from input to output through the assertion; Test case generation: For the input space encoded into qubit states and gate parameters, sample test cases in the input space using the orthogonal decomposition of quantum states and quantum gates; Error localization on a classical computer: Construct a patch on a classical computer, transform the search for the patch into a MAX-SMT problem to locate multi-position patches, and replace the set of general quantum gates in the patch with a set of Clifford gates to approximate the quantum program; Error repair on a quantum computer: Based on the test cases, utilize the differentiability of quantum gates to repair the error. The repair process is achieved by minimizing the objective function derived from the assertion. The gradient of the gate parameters is calculated on a simulator or a quantum computer. If the assertion condition is satisfied after repair, the repaired quantum program will be output; If the assertion is not satisfied, return to the error localization stage to gradually approach the correct quantum program.

2. The quantum program automated repair method based on the homotopy method according to claim 1, wherein The expected behavior of the quantum program defined by the assertion is represented by the implication relationship between the input and output of the quantum program. Among them, the antecedent of the assertion defines the spatial range of the input, and the consequent gives the expected relationship between the program input and the runtime state, expressed as: ; Among them, represents test cases in the input spatial range, represents the measurement probability distribution output by the quantum program, and represent two constraints, and and must comply with the satisfiability modulo theory formula, and is defined as a polynomial objective function, the symbol represents derivation, the symbol represents definition, represents assertion; The assertion means that if the input t and the output p satisfy the constraint , then the constraint should also be satisfied. The function of the quantum program is described by defining multiple assertions and aggregating these assertions into a single repair process.

3. The quantum program automatic repair method based on the homotopy method according to claim 1, wherein During the test case generation process, there are two encoding schemes for the input of the quantum program, namely the state encoding scheme, which encodes the input as qubit states, and the qubit states are represented as vectors; the gate encoding scheme, which encodes the input as the gate parameters of quantum gates, and the gate parameters are represented as unitary matrices; For the input of the state encoding scheme, sample test cases from the orthonormal state space; For the input of the gate encoding scheme, the quantum gate is replaced by a combination of a measurement operation and a subsequent quantum gate operation. The measurement operation samples from the basic set, and the quantum gate samples from the gate set; Finally, these two encoding schemes orthogonally constitute the input space, which is regarded as the tensor product of the state space and the gate space. Based on this input space, test cases are sampled through orthogonal decomposition.

4. The quantum program automatic repair method based on the homotopy method according to claim 1, wherein The variables in the MAX-SMT problem represent the possible positions of the patch and the qubit states during the program execution. The constraints of the problem include the assertion and the changes in qubit states after applying different gate operations.

5. The quantum program automatic repair method based on the homotopy method according to claim 4, wherein The variables in the problem include: Variable one, the variable for patch insertion: An auxiliary layer is attached after each layer to place the patch, and boolean variables are used to represent whether a quantum gate is applied to certain qubits in a certain auxiliary layer; Variable two, the variable for qubit states: For the approximated quantum program, the qubit states after each layer are represented by stabilizer tables; The constraints of the problem include: Constraint one, the constraint between patches: In each layer, due to the limitations of the quantum circuit model, each qubit can be operated on by at most one gate; Constraint two, the constraint of gate operations: If a certain quantum gate is applied, the qubit states in the next layer are determined by the states in the previous layer through boolean operations; Constraint 3, Constraint of Assertion: The goal of localization is to find patches that satisfy the assertion, and the assertion is added as two constraints:

1. For to hold, 2. , is a complex value, represents the m th test case, represents the test output corresponding to the quantum program.

6. The quantum program automatic repair method based on the homotopy method according to claim 1, characterized in that Replacing the set of general quantum gates in the patch with a set of Clifford gates to approximate the quantum program includes: For each quantum gate g in the quantum program, calculate the unitary matrix of each quantum gate g through the Hilbert-Schmidt test with the unitary matrix of each gate in the Clifford gate set the distance between : ; Among them, is the dimension of the unitary matrix, is the trace operation that takes the sum of the diagonal elements of the matrix, represents the conjugate transpose of the matrix, Distance-based , replace the quantum gate g with the gate in the Clifford gate set that is closest to the quantum gate g to obtain an approximate program.

7. The quantum program automated repair method based on the homotopy method according to claim 1, characterized in that Regarding the differentiability of quantum gates, let be a parameterized quantum program, where the quantum gate parameter is a real value, and the quantum program is differentiable with respect to the parameter , which means that for the r-th parameter , the partial derivative exists and is continuous; Any quantum program that contains parameterized quantum gates is regarded as a parameterized program. The Clifford gates in the patch are converted into parameterized quantum gates according to the equivalence. The goal of optimizing based on the parameterized program is to minimize the constraints of the assertions , while satisfying the constraints : ; Among them, represents the parameterized output for the input test case , represents the satisfied condition, represents finding the minimum quantum gate parameters.

8. The quantum program automatic repair method based on the homotopy method according to claim 7, wherein The repair process is to update the quantum gate parameters within L cycles, specifically: In each cycle, a set of test inputs X is generated by randomly calculating a linear combination of test cases, and the program runs with these inputs X to obtain parameterized outputs ; Then, the test inputs are filtered to retain only those inputs that satisfy the constraint ; the gradients are first initialized to 0, and then, for each parameter , perturbations of and are added, and the gradients of the parameterized output are calculated and updated. If the assertion holds in the test case, i.e., , then the repaired quantum program is output.

9. The quantum program automatic repair method based on the homotopy method according to claim 8, wherein The parameter translation method is used to calculate the gradient of quantum gate parameters.

Citation Information

Patent Citations

  • Test case generation method based on quantum program language grammar rule

    CN115344476A

  • Quantum program automatic repairing method based on unitary operation

    CN116954969A