Quantum program automatic repairing method based on homotopy method

Through the automated repair method of quantum program based on homoeconomic method, the problem of quantum program repair is solved by using technical means such as assertion construction, test case generation and error positioning, the problem of quantum program repair is achieved, and the repair success rate is improved.

CN119807078AActive Publication Date: 2025-04-11ZHEJIANG UNIV
View PDF 7 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

The prior art is difficult to effectively automate the repair of logical errors in quantum programs, especially because there are significant differences in the information representation and operation of quantum programs from classical programs, which makes the error difficult to resolve.

Method used

The automated repair method of quantum programs based on homoethic methods is adopted, and the automatic repair of quantum programs is achieved through assertion construction, test case generation, error location and repair processes, and the combination of classical computers and quantum computers is used.

Benefits of technology

It realizes rapid and precise quantum program repair at a lower time, improves repair success rate, reduces the complexity of patch positioning, and reduces its complexity to polynomial level.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119807078A_ABST
    Figure CN119807078A_ABST
Patent Text Reader

Abstract

The invention discloses an automatic quantum program repairing method based on a homotopy method, which belongs to the technical field of quantum program repairing, and comprises the following steps: assertion construction: constructing assertions for defective quantum programs, and defining expected behaviors of the quantum programs based on input to output through the assertions; test case generation: for an input space encoded into a quantum bit state and a gate parameter, sampling the test case in the input space by utilizing orthogonal decomposition of a quantum state and a quantum gate; performing error positioning on a classical computer: constructing a patch on the classical computer, converting search of the patch into an MAX-SMT problem to position the multi-position patch, and replacing a general quantum gate set in the patch with a Clifford gate set to approximate a quantum program; and error repair is carried out on the quantum computer: based on the test case, errors are repaired by utilizing the differentiability of the quantum gate. According to the method, automatic repair of the quantum program is achieved within a short time, and the repair success rate can be increased.
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 in particular relates to a quantum program automatic repair method based on a homotopy method. Background Art

[0002] Quantum programs have demonstrated significant acceleration potential in certain areas, such as financial technology and chemical analysis. However, due to human error, quantum programs will inevitably have logical errors, which require program debugging. Unfortunately, compared with classical programs, the information representation and operations of quantum programs differ significantly in semantics and behavior, making many errors difficult to resolve. For example, on Stack Overflow, a community of software developers and programmers, only 21% of errors related to quantum programs are resolved, which is 4.1 times lower than that of classical programs. Therefore, Automated Program Repair (APR) becomes a natural choice compared to manual repair.

[0003] However, current advanced APR techniques cannot be directly applied to automated quantum program repair (Quantum-APR, Q-APR). Typical APR techniques generate and verify repair patches heuristically until the program passes the test. A patch is a module that can correct a program. However, quantum programs use quantum circuit models, which results in an extremely large patch space. For example, a 5-bit quantum program may have a combination of quantum operations as a patch. 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 lack sufficient program data to effectively train neural networks.

[0004] Verifying patches in Q-APRs further increases the difficulty. Density matrix tomography of states on quantum hardware requires exponential complexity because quantum measurements lead to quantum collapse. On the other hand, verification through simulation on a classical computer also faces exponential complexity. For example, simulating a 53-qubit quantum program requires 128 PiB of memory and 20 days of running time (using the Summit supercomputer). To ensure that the patch is correct, the number of test inputs required increases further. For example, the Quito tool (a coverage-based quantum program test generator) needs to run different test inputs to verify that an error in an 11-qubit quantum lock program has been correctly fixed.

[0005] To address these challenges, some Q-APR methods use large language models and program synthesis to fix errors. For example, ChatGPT is used to fix quantum programs, but the high cost of running quantum programs inevitably limits the training data, resulting in a success rate of less than 20% for fixing quantum errors on Stack Overflow. For another example, the correct program is approximated by appending a large unitary matrix to the problematic program. This method relies on synthesizing the unitary matrix into executable quantum gates. However, for quantum programs larger than 8 bits, even the optimal synthesis algorithm takes more than a year to output high-quality programs, or completes 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 method for automatic repair of quantum programs based on the homology method, which can realize automatic repair of quantum programs in a relatively short time and improve the success rate of repair.

[0007] To achieve the above-mentioned purpose of the invention, an embodiment provides a quantum program automatic repair method based on the homotopy method, comprising the following steps: Assertion construction: Build assertions for flawed quantum programs, defining the expected behavior of quantum programs based on inputs to outputs through assertions; Test case generation: For the input space encoded into qubit states and gate parameters, we 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 and transform the search for the patch into a MAX-SMT problem to locate a multi-position patch, and replace the set of universal quantum gates in the patch with a set of Clifford gates to approximate the quantum program; Error repair on a quantum computer: Based on test cases, the differentiability of quantum gates is used to repair errors. The repair process is implemented 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 conditions are met after the repair, the repaired quantum program will be output; if the assertion is not met, it will return to the error localization stage and gradually approach the correct quantum program.

[0008] Preferably, the expected behavior of the quantum program defined by the assertion is expressed using 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: ; in, Represents the test cases in the input space, represents the measurement probability distribution of the quantum program output, and represents two constraints, and and The satisfiability modulo theoretic formula must be followed, and Defined as a polynomial objective function, the symbol Derivation, symbol Indicates the definition, To express an assertion; The meaning of the assertion is: if the input t and output p satisfy the constraints , then the constraint should also be satisfied , by defining multiple assertions to describe the functionality of a quantum program and aggregating these assertions into a single repair process.

[0009] Preferably, in the test case generation process, there are two encoding schemes for the input of the quantum program, namely, a state encoding scheme, which encodes the input as a quantum bit state, and the quantum bit state is represented as a vector; a gate encoding scheme, which encodes the input as a gate parameter of a quantum gate, and the gate parameter is represented as a unitary matrix; Sampling test cases from an orthogonal canonical state space for the input of the state encoding scheme; 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. Ultimately, these two encoding schemes orthogonally constitute the input space and are viewed as the tensor product of the state space and the gate space. Test cases are obtained based on this input space by orthogonal decomposition sampling.

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

[0011] Preferably, the variables in the question include: Variable 1, patch-inserted variable: an auxiliary layer is attached after each layer to place the patch, and a Boolean variable is used to indicate whether a quantum gate is applied to certain qubits in a certain auxiliary layer; Variable 2, the variable of the quantum bit state: For the quantum program that has been approximated, the quantum bit state after each layer is represented by a stable subtable; The constraints of the problem include: Constraint 1, constraints between patches: At each layer, due to the limitations of the quantum circuit model, each quantum bit can only be operated by one gate at most; Constraint 2: Constraints on gate operations: If a quantum gate is applied, the state of the quantum bits in the next layer is determined by the state of the previous layer through Boolean operations; Constraint 3, Assertions: The goal of positioning is to find patches that satisfy assertions. Assertions are added as two constraints: 1. for Established, 2. , is a complex value, Indicates m Test cases, express Test output corresponding to the quantum program.

[0012] Preferably, the universal quantum gate set in the patch is replaced with a Clifford gate set to approximate the quantum program, including: For each quantum gate g in the quantum program, the unitary matrix of each quantum gate g is calculated by the Hilbert-Schmidt test and the unitary matrix of each gate in the Clifford gate set The distance between : ; in, is the dimension of the unitary matrix, is the trace operation of summing the diagonal elements of a matrix, represents the conjugate transpose of a matrix, Based on distance , replace quantum gate g with the gate closest to quantum gate g in the Clifford gate set to obtain an approximate program.

[0013] Preferably, for the differentiability of quantum gates, is a parameterized quantum program, where the quantum gate parameters is a real-valued, quantum program Parameters is differentiable, which means that for the rth parameter , partial derivative exists and is continuous; Any quantum program containing parameterized quantum gates is considered a parameterized program. The Clifford gates in the patch are converted to parameterized quantum gates according to equivalence. The goal of optimization based on the parameterized program is to minimize the asserted constraints. , while satisfying the constraints : ; in, Indicates that for input The parameterized output of Indicates the conditions that are met, It means to find the minimum quantum gate parameter.

[0014] Preferably, 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 computing linear combinations of test cases, and the program is run with these inputs X to obtain parameterized outputs ; Then, the test inputs are filtered to keep only those that satisfy the constraints The gradient is first initialized to 0, then, for each parameter ,Add to and perturbations and calculate the parameterized output The gradient of is updated if the assertion holds in the test case, i.e. , then the repaired quantum program is output.

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

[0016] Compared with the prior art, the present invention has the following beneficial effects: The quantum program repair process proposed in the present invention is based on a similar homotopy method, which can quickly and accurately repair the program and is highly versatile. The present invention introduces a test case generation method that supports multiple quantum input encoding schemes and combines the orthogonal basis of quantum programs to achieve higher input coverage; The present invention reduces the complexity of Q-APR patch positioning by formalizing it into a symbolic reasoning problem and utilizing the differentiability of quantum gates to reduce its complexity to a polynomial level. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0018] Figure 1 It is a flow chart of using the homotopy method provided in the embodiment for quantum program repair; Figure 2 is a flow chart of a method for automatically repairing a quantum program based on a homotopy method provided in an embodiment; Figure 3 It is a schematic diagram of a flow chart of generating a test case provided by an embodiment; Figure 4 This is a schematic diagram of fault location based on SMT provided in an embodiment. DETAILED DESCRIPTION

[0019] To make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific implementation methods described herein are only used to explain the present invention and do not limit the scope of protection of the present invention.

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

[0021] Specifically, in the implementation process, we first standardize the correct behavior of the quantum program through an implication assertion annotation. A test case is generated using the orthogonal basis of the quantum program to achieve maximum input coverage. In order to reduce the high computational overhead, the patch positioning problem is approximately transformed into a symbolic reasoning problem through Clifford analysis (which is the generalization of complex function theory to high dimensions. In the four-dimensional case, quaternion analysis, the kernel function of the Dirac operator is mainly studied). This method not only achieves high accuracy, but also reduces the complexity of patch positioning from approximation to approximation. The positioning process determines the specific location of the patch and the quantum bits it acts on. Then, 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 quantum hardware for processing.

[0022] like Figure 2 As shown, an embodiment provides a quantum program automatic repair method based on the homotopy method, comprising the following steps: S1, Assertion Construction: Build assertions for defective quantum programs, and define the expected behavior of quantum programs through assertions.

[0023] In the embodiment, a user-defined assertion is used as an optimization target for repair. The expected behavior of the quantum program defined by the assertion is expressed by the implication relationship between the input and output of the quantum program, wherein 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, which is expressed as: ; in, Represents the test cases in the input space, represents the measurement probability distribution of the quantum program output, and represents two constraints, and and must obey the SMT (satisfiability modulo theory) formula, expressed as a polynomial inequality, and Defined as a polynomial objective function, the symbol Derivation, symbol Indicates the definition, Indicates an assertion.

[0024] The meaning of the assertion is: if the input t and output p satisfy the constraints , then the constraint should also be satisfied , by defining multiple assertions to describe the functionality of a quantum program and aggregating these assertions into a single repair procedure. In theory, p can be any measurement probability distribution derived from the runtime state. To simplify the discussion, in the following sections, p is considered to be the program output.

[0025] 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 by modular testing, which consists of an oracle 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, the input bit string is expected to have a high measurement probability (for example, ). For example, when the input is 0110, the phase of the ground state |0110> is flipped in the oracle function. Therefore, the probability of getting 0110 in the output is about 76%. The assertion is defined as follows: ; in, represents the probability of bit string t in the output. When the number of quantum bits is 4, the range of t is ,and (integer).

[0026] S2, test case generation: For the input space encoded into qubit states and gate parameters, test cases are sampled in the input space using the orthogonal decomposition of quantum states and quantum gates.

[0027] 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 consisting of test cases by sampling the input space encoded in the quantum bit state and gate parameters. The key feature of these sampled inputs is that their execution results can be generalized to other untested inputs, thereby improving the tolerance of the method of the present invention to overfitting.

[0028] In the embodiment, the input of the quantum program can be encoded by two encoding methods: (1) a state encoding scheme, which encodes the input as a quantum bit state, and the quantum bit state is represented as a vector; (2) a gate encoding scheme, which encodes the input as a gate parameter of a quantum gate, and the gate parameter is represented as a unitary matrix. Depending on the encoding scheme, the following different sampling strategies are adopted: For the input of the state encoding scheme, the orthogonal canonical state space is obtained from the literature 1 (Hadamard-free circuits expose the structure of the Clifford group) Medium sampling test cases; For 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 from the basic set The quantum gate is sampled from the gate set Sampling in the middle, where Respectively represent: X (Pauli-X, or NOT gate), ; Y (Pauli-Y, ), ; I (the identity matrix), ; H (Hadamard Gate), ; HS is a combination of H and S gates. The S gate is a phase gate, and its matrix representation is: ,but .

[0029] Ultimately, these two encoding schemes orthogonally form the input space, which can be viewed 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 we know, the existing test case set generation methods can only generate test cases for state encoding schemes, thus limiting the versatility of existing Q-APR methods.

[0030] Figure 3 The test case generation process is shown: input input1 represents the state encoding scheme, and its sampling space contains 3 basic states; input input2 represents the gate encoding scheme, and its input space contains 12 combinations of measurement and gate operations, so 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 is measured on the X basis, followed by an I gate operation.

[0031] Based on this, the sampling generality of the test case is: for input using state encoding or gate encoding scheme, define the set of test cases as input and the corresponding output set ,in, Indicates m Test cases, express After the test output corresponding to the quantum program; For any input represented by a linear combination of test cases :

[0032] in, If is a complex value, then enter The output of p for:

[0033] The universality of the state encoding scheme is derived from the isomorphism theory proposed in the literature (MorphQPV: Exploiting Isomorphism in Quantum Programs to Facilitate Confident Verification), and the universality of the gate encoding scheme can refer to the circuit partition theory of distributed quantum computing. Based on the universality of the input space, assertion verification can ensure that the assertion is valid for any linear combination of test cases, thereby maximizing the coverage of the input space.

[0034] S3, error localization on a classical computer: construct a patch on a classical computer and transform the search for the patch into a MAX-SMT (maximum satisfiability modulo theory) problem to locate multi-position patches, and replace the set of universal quantum gates in the patch with a set of Clifford gates to approximate the quantum program.

[0035] In the embodiment, a patch is first constructed on a classical computer, and the search for the patch is converted into a MAX-SMT problem to locate a multi-position patch. The variables in the problem represent the possible locations of the patch and the quantum bit states during program execution. The constraints of the problem include assertions and changes in the quantum bit states after applying different gate operations. In order to accelerate space exploration, the set of universal quantum gates is replaced with a set of Clifford gates to approximate the quantum program. Since the operations are simplified to Boolean expressions, this method exhibits polynomial complexity.

[0036] Specifically, simulating quantum behavior on a classical computer usually faces huge computational overhead, 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. In order to speed up verification, the embodiment adopts a homotopy method to reduce the difficulty of simulation by approximating the quantum program using Clifford gates. First, define the Clifford gate set:

[0037] The Clifford gate set is a subset of universal quantum gates, including 24 single-bit gates and 3 two-bit gates. In the approximation process, for each quantum gate g in the quantum program, the unitary matrix of each quantum gate g is calculated through the Hilbert-Schmidt test and the unitary matrix of each gate in the Clifford gate set The distance between : ; in, is the dimension of the unitary matrix, is the trace operation of summing the diagonal elements of a matrix, Represents the conjugate transpose of a matrix, based on distance Replace quantum gate g with the gate in the Clifford gate set that is closest to quantum gate g to obtain an approximate program.

[0038] The reason for choosing the Clifford gate set is that it contains the most commonly used single-bit and two-bit gates. In addition, in current quantum algorithms, more than 60% of quantum gates are Clifford gates. When a quantum program consists only of Clifford gates, its N-bit quantum state can be represented as a The stable subtable of The state vector of dimension. The stable subtable is as follows:

[0039] Each element in the table is a Boolean value. For an N-bit quantum program, its stable subtable contains elements. Clifford quantum gates can be computed using Boolean operations instead of matrix-vector multiplications. For example: Apply gate X to bit i: For each row k, perform .

[0040] Apply the H gate to bit i: for each row k, swap and , and execute .

[0041] Apply CNOT gates to bits i and j: For each row k, do the following: , ,

[0042] Represents the exclusive OR operation (XOR). All Clifford gate operations can be completed in time no more than polynomial complexity.

[0043] In the embodiment, a gate-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 phase will be converted into a parameterized gate in the error repair phase. The patch positioning is expressed as a MAX-SMT problem. Figure 4 As shown, the MAX-SMT problem contains two types of variables and three types of constraints.

[0044] Use layers to represent the execution order of quantum gates, for example, Figure 4 Layer 1, layer 2, and so on, gates in the same layer can be executed in parallel. These two types of variables include: Variables for patch insertion: Additional auxiliary layers are added after each layer, e.g., layer 1.1, layer 1.2, to place patches. The number of auxiliary layers is specified by the user and depends on the expected search space. Boolean variables are used to indicate whether quantum gates are applied to certain qubits in a certain auxiliary layer. For example, the Boolean variable Indicates that at level 3.1, the quantum bit and A CX gate is applied, the Boolean variable Indicates that the CX gate is applied.

[0045] Variables of qubit states: For a quantum program that has been approximated, the qubit states after each layer can be represented by a stable subtable, which contains (2N+1) variables.

[0046] Three types of constraints are used to specify the relationship between variables, including: Constraint 1, constraints between patches: that is, at each layer, due to the limitations of the quantum circuit model, each quantum bit can only be operated by one gate at most; Constraint 2: Gate operation constraint: If a quantum gate is applied, the state of the quantum bits in the next layer is determined by the state of the previous layer through Boolean operations, such as the Boolean variable : , indicating that for the operation door , the quantum bit state of the second layer The quantum bit state of the first layer is Through Boolean operations decided.

[0047] Constraint 3, Assertions: The goal of positioning is to find patches that satisfy assertions. Assertions are added as two constraints: 1. for Established, 2. These two constraints ensure that the patch makes the assertion true 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.

[0048] The MAX-SMT problem is then handed over to the Z3 solver. By finding the truth value assignments associated with patch insertion, we can obtain possible patch locations and the types of quantum gates that can repair the quantum program.

[0049] S4, based on test cases, uses the differentiability of quantum gates to repair errors. The repair process is implemented by minimizing the objective function derived from the assertion. The gradient of the gate parameters is calculated on a simulator or quantum computer. If the assertion conditions are met after the repair, the repaired quantum program will be output; if the assertion is not met, it will return to the error location stage and gradually approach the correct quantum program.

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

[0051] For the differentiability of quantum gates, let is a parameterized quantum program, where the quantum gate parameters is real-valued. Quantum program Parameters is differentiable, which means that for the rth parameter , partial derivative exists and is continuous. Mathematically, this can be expressed as: , Represented as a unit vector in the rth direction.

[0052] Any quantum program containing parameterized quantum gates such as RX, RY, and RZ gates can be considered a parameterized program. In addition, the Clifford gates in the patch can be converted to parameterized gates according to equivalence. For example, X Clifford can be converted to a parameterized RX gate with the default parameters The optimization goal is to minimize the assertion constraints. , while satisfying the constraints :

[0053] in, Indicates parameterized output, Indicates the conditions that are met, It means to find the minimum quantum gate parameter.

[0054] The parameter shift method is used to calculate the gradient of quantum gate parameters. This method allows quantum programs to run directly on quantum computers, eliminating the need for computationally intensive simulations. The specific repair process is: update the quantum gate parameters in L cycles, and in each cycle, generate a set of test inputs X by randomly calculating linear combinations of test cases. The program is run with these inputs X to obtain parameterized outputs ; Then, the test inputs are filtered to keep only those that satisfy the constraints The gradient is first initialized to 0, and then, for each parameter ,Add to and perturbations and calculate the parameterized output The gradient of is updated if the assertion holds in the test case, i.e. , then the repaired quantum program is output.

[0055] 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. In addition, the method of the present invention can repair a 20-bit quantum program in 28.2 minutes and requires only 249 additional gates, while the existing synthesis-based method may take more than 6 months and more than 10 minutes. An extra door.

[0056] The specific implementation methods described above provide a detailed description of 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 intended to limit the present invention. Any modifications, supplements and equivalent substitutions made within the scope of the principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A quantum program automatic repair method based on homology method, characterized in that: The following steps are involved: Assertion construction: Build assertions for flawed quantum programs, defining the expected behavior of quantum programs based on inputs to outputs through assertions; Test case generation: For the input space encoded into qubit states and gate parameters, we 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 and transform the search for the patch into a MAX-SMT problem to locate a multi-position patch, and replace the set of universal quantum gates in the patch with a set of Clifford gates to approximate the quantum program; Error repair on quantum computers: Based on test cases, the differentiability of quantum gates is used to repair errors. The repair process is implemented 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 conditions are met after the repair, the repaired quantum program will be output. If the assertion is not satisfied, it will return to the error localization stage and gradually approach the correct quantum program.

2. The method for automatic quantum program repair based on homotopy method according to claim 1, characterized in that: The expected behavior of the quantum program defined by the assertion is expressed using 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: ; in, Represents the test cases in the input space, represents the measurement probability distribution of the quantum program output, and represents two constraints, and and The satisfiability modulo theoretic formula must be followed, and Defined as a polynomial objective function, the symbol Derivation, symbol Indicates the definition, To express an assertion; The meaning of the assertion is: if the input t and output p satisfy the constraints , then the constraint should also be satisfied , by defining multiple assertions to describe the functionality of a quantum program and aggregating these assertions into a single repair process.

3. The method for automatic quantum program repair based on homotopy method according to claim 1, characterized in that: In 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 the 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 the quantum gate, and the gate parameters are represented as a unitary matrix; Sampling test cases from an orthogonal canonical state space for the input of the state encoding scheme; 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. Ultimately, these two encoding schemes orthogonally constitute the input space and are viewed as the tensor product of the state space and the gate space. Test cases are obtained based on this input space by orthogonal decomposition sampling.

4. The method for automatic quantum program repair based on homotopy method according to claim 1, characterized in that: The variables in the MAX-SMT problem represent the possible locations of patches and the states of qubits during program execution, and the constraints of the problem include assertions and changes in the states of qubits after applying different gate operations.

5. The method for automatic quantum program repair based on homotopy method according to claim 4, characterized in that: The variables in the question include: Variable 1, patch-inserted variable: an auxiliary layer is attached after each layer to place the patch, and a Boolean variable is used to indicate whether a quantum gate is applied to certain qubits in a certain auxiliary layer; Variable 2, the variable of the quantum bit state: For the quantum program that has been approximated, the quantum bit state after each layer is represented by a stable subtable; The constraints of the problem include: Constraint 1, constraints between patches: At each layer, due to the limitations of the quantum circuit model, each quantum bit can only be operated by one gate at most; Constraint 2: Constraints on gate operations: If a quantum gate is applied, the state of the quantum bits in the next layer is determined by the state of the previous layer through Boolean operations; Constraint 3, Assertions: The goal of positioning is to find patches that satisfy assertions. Assertions are added as two constraints:

1. for Established, 2. , is a complex value, Indicates m Test cases, express Test output corresponding to the quantum program.

6. The method for automatic quantum program repair based on homotopy method according to claim 1, characterized in that: The universal quantum gate set in the patch is replaced with the Clifford gate set to approximate the quantum program, including: For each quantum gate g in the quantum program, the unitary matrix of each quantum gate g is calculated by the Hilbert-Schmidt test and the unitary matrix of each gate in the Clifford gate set The distance between : ; in, is the dimension of the unitary matrix, is the trace operation of summing the diagonal elements of a matrix, represents the conjugate transpose of a matrix, Based on distance , replace quantum gate g with the gate closest to quantum gate g in the Clifford gate set to obtain an approximate program.

7. The method for automatic quantum program repair based on homotopy method according to claim 1, characterized in that: For the differentiability of quantum gates, let is a parameterized quantum program, where the quantum gate parameters is a real-valued, quantum program Parameters is differentiable, which means that for the rth parameter , partial derivative exists and is continuous; Any quantum program containing parameterized quantum gates is considered a parameterized program. The Clifford gates in the patch are converted to parameterized quantum gates according to equivalence. The goal of optimization based on the parameterized program is to minimize the asserted constraints. , while satisfying the constraints : ; in, Indicates that for input The parameterized output of Indicates the conditions that are met, It means to find the minimum quantum gate parameter.

8. The method for automatic quantum program repair based on homotopy method according to claim 7, characterized in that: 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 computing linear combinations of test cases, and the program is run with these inputs X to obtain parameterized outputs ; The test inputs are then filtered to keep only those that satisfy the constraints The gradient is first initialized to 0, then, for each parameter ,Add to and perturbations and calculate the parameterized output The gradient of is updated if the assertion holds in the test case, i.e. , then the repaired quantum program is output.

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

Citation Information

Patent Citations

  • Quantum software automatic test system and method based on combination test

    CN115048286A

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

    CN115344476A

  • Quantum program automatic repairing method based on unitary operation

    CN116954969A

  • Method and system for promoting confidential verification by utilizing isomorphism in quantum program

    CN118333181A

  • Quantum program testing method based on distance and incremental learning model

    CN118535452A