Quantum machine learning model training method and device based on block coding

The block-coded quantum machine learning model training method utilizes non-unitary matrices to operate on quantum circuits, solving the problems of insufficient function fitting and excessive number of runs in existing technologies, and improving the training efficiency of quantum machine learning models.

CN121920563APending Publication Date: 2026-04-24ORIGIN QUANTUM COMPUTING TECH (HEFEI) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
ORIGIN QUANTUM COMPUTING TECH (HEFEI) CO LTD
Filing Date
2024-10-16
Publication Date
2026-04-24

AI Technical Summary

Technical Problem

Existing quantum machine learning model training methods cannot perform non-unitary matrix operations, resulting in fewer classical neural network functions that can be fitted and simulated, and a greater number of quantum circuit runs, which reduces training efficiency.

Method used

The input data and target gradient are encoded into the quantum circuit using a block encoding method. The parameters are updated using a non-unitary matrix until the loss function reaches the training cutoff condition. The parameters are then optimized using a gradient optimization algorithm.

Benefits of technology

It enables more functional classical neural network fitting and simulation, reduces the number of times quantum circuits are run, and improves training efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121920563A_ABST
    Figure CN121920563A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of quantum machine learning, in particular to a quantum machine learning model training method and device based on block coding, and the method comprises the steps: obtaining input data and a loss function of a target layer in a to-be-trained quantum machine learning model; coding a transpose matrix of the input data and a target first gradient block to the quantum circuit to obtain a first quantum circuit; the target first gradient is a gradient of an output data relative loss function obtained by the input data passing through a target layer; operating the first quantum circuit to obtain a second gradient of the parameter of the parameter-containing non-unitary matrix relative to the loss function; and updating the parameter of the parameter-containing non-unitary matrix according to the second gradient so as to update the value of the loss function and the target first gradient until the loss function reaches a training cut-off condition. According to the method, more functions of the classic neural network can be fitted and simulated, the loss function of the classic neural network can be optimized more easily by combining the parallel computing advantage of quantum computing, the parameter gradient in a quantum machine learning model can be calculated conveniently, and the number of quantum line operation times is greatly reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of quantum machine learning technology, and in particular to a method and apparatus for training quantum machine learning models based on block coding. Background Technology

[0002] One of the most cutting-edge and promising research directions in quantum computing today is quantum artificial intelligence (AI) research, which integrates with artificial intelligence. Large-scale quantum AI models, due to their computing power far exceeding that of traditional computing, hold the promise of breaking through the current bottlenecks of weak AI and achieving true strong AI. The main platform upon which AI research relies is the framework of AI algorithms. Building and training corresponding algorithms through these frameworks to complete research work is a crucial foundational tool for AI development. Therefore, the research and development of quantum AI requires a supporting large-scale quantum AI algorithm framework to enable rapid deployment, training, and other research methods, thereby promoting the development of related research and technological progress.

[0003] With the development of quantum computing, more and more machine learning models incorporating quantum computing layers are emerging. Current mainstream quantum machine learning training methods generally use variable quantum circuits to encode parameters into quantum circuits and use the parameter drift method to calculate gradients for backpropagation training. This quantum machine learning model training method can only perform unitary matrix transformations and cannot perform non-unitary matrix operations, resulting in a limited number of functions that can be fitted and simulated in classical neural networks. At the same time, when using variable quantum circuits for quantum machine learning training, the quantum circuits are run many times, which reduces the training efficiency of quantum machine learning models. Summary of the Invention

[0004] This invention provides a block-coding-based quantum machine learning model training method and apparatus to solve the problems of limited functions and excessive number of quantum circuit runs in classical neural networks used for training quantum machine learning models with variable quantum circuit fitting and simulation in the prior art.

[0005] This specification provides an embodiment of a block-coded quantum machine learning model training method, including:

[0006] Obtain the input data and loss function of the target layer in the quantum machine learning model to be trained; wherein the target layer is represented by a quantum circuit constructed using a parametric non-unitary matrix;

[0007] The transpose matrix of the input data and the first gradient of the target are respectively block-encoded into the quantum circuit to obtain the first quantum circuit; the first gradient of the target is the gradient of the output data obtained by passing the input data through the target layer relative to the loss function;

[0008] Running the first quantum circuit yields the second gradient of the parameters of the parametric non-unitary matrix relative to the loss function;

[0009] The parameters of the parametric non-unitary matrix are updated according to the second gradient to update the value of the loss function and the target first gradient, until the loss function reaches the training cutoff condition; wherein, the training cutoff condition includes the value of the loss function reaching convergence.

[0010] Optionally, before encoding the transpose matrix of the input data and the target first gradient into the quantum circuit, the method further includes:

[0011] The input data block is encoded into the quantum circuit to obtain the second quantum circuit;

[0012] Run the second quantum circuit to obtain the quantum state data of the output data;

[0013] The quantum state data is measured to obtain the output data;

[0014] The first gradient of the target is determined based on the output data and the loss function.

[0015] Optionally, determining the first gradient of the target based on the output data and the loss function includes:

[0016] The value of the loss function is calculated based on the label values ​​corresponding to the output data and the input data.

[0017] The first gradient of the target is calculated based on the output data and the value of the loss function.

[0018] Optionally, the step of running the first quantum circuit to obtain the second gradient of the parameters of the parametric non-unitary matrix with respect to the loss function includes:

[0019] Running the first quantum circuit yields quantum state data of the second gradient of the parameters of the parametric non-unitary matrix relative to the loss function;

[0020] The quantum state data is measured to obtain the second gradient.

[0021] Optionally, updating the parameters of the parametric non-unitary matrix according to the second gradient to update the value of the loss function and the target first gradient includes:

[0022] The parameters of the parametric non-unitary matrix are updated according to the second gradient and the gradient optimization algorithm to update the values ​​of the target first gradient and the loss function; wherein, the gradient optimization algorithm includes stochastic gradient descent and adaptive moment estimation.

[0023] Optionally, updating the value of the loss function and the target first gradient includes:

[0024] The input data block is encoded into a parameter-updated quantum circuit containing a non-unitary matrix to obtain a third quantum circuit;

[0025] Running the third quantum circuit yields quantum state data for the new output data.

[0026] The quantum state data is measured to obtain new output data;

[0027] The value of the loss function is updated based on the new output data and the label values ​​corresponding to the input data.

[0028] The target first gradient is updated based on the new output data and the updated value of the loss function.

[0029] Optionally, the quantum machine learning model consists of several target layers, and the method further includes:

[0030] The parameters of the parametric non-unitary matrix and the target first gradient are respectively block-encoded into the quantum circuit to obtain the fourth quantum circuit;

[0031] Running the fourth quantum circuit yields the quantum state data of the third gradient of the input data relative to the loss function;

[0032] The quantum state data is measured to obtain the third gradient; wherein the third gradient serves as the backpropagation input data of the layer preceding the current target layer.

[0033] This specification also provides an embodiment of a block-coded quantum machine learning model training device, comprising:

[0034] An information acquisition module is used to acquire the input data and loss function of the target layer in the quantum machine learning model to be trained; wherein the target layer is represented by a quantum circuit constructed using a parametric non-unitary matrix.

[0035] The first encoding module is used to encode the transpose matrix of the input data and the target first gradient into the quantum circuit respectively to obtain the first quantum circuit; the target first gradient is the gradient of the output data obtained by passing the input data through the target layer relative to the loss function;

[0036] The first quantum circuit operation module is used to run the first quantum circuit and obtain the second gradient of the parameters of the parametric non-unitary matrix with respect to the loss function;

[0037] The parameter update module is used to update the parameters of the parametric non-unitary matrix according to the second gradient to update the value of the loss function and the target first gradient, until the loss function reaches the training cutoff condition; wherein, the training cutoff condition includes the value of the loss function reaching convergence.

[0038] An electronic device includes a memory and a processor, the memory storing computer instructions, and the processor being configured to execute the computer instructions to perform the method described above.

[0039] A storage medium, characterized in that the storage medium stores computer instructions, the computer instructions being configured to execute the method described above at runtime.

[0040] Its beneficial effects are as follows: This application realizes the operation of non-unitary matrices on quantum circuits through block encoding, which can fit and simulate more functions of classical neural networks and makes it easier to combine the parallel computing advantages of quantum computing to optimize the loss function of classical neural networks. Compared with using variable quantum circuits for quantum machine learning training, it is not necessary to construct a gradient calculation quantum circuit proportional to the number of variable quantum parameters. It only needs to construct a block-encoded quantum circuit once through the gradient calculation function of classical non-unitary matrices, which facilitates the calculation of parameter gradients in quantum machine learning models and greatly reduces the number of quantum circuit runs. Attached Figure Description

[0041] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:

[0042] Figure 1 A block-coded quantum circuit is provided as an embodiment of this specification;

[0043] Figure 2 A flowchart illustrating a block-coding-based quantum machine learning model training method provided in this specification.

[0044] Figure 3 A schematic diagram of forward propagation during the training of a block-coded quantum machine learning model, provided as an embodiment of this specification;

[0045] Figure 4 A schematic diagram of backpropagation during the training of a block-coded quantum machine learning model, provided as an embodiment of this specification;

[0046] Figure 5 A schematic diagram of a block-coding-based quantum machine learning model training device provided in the embodiments of this specification;

[0047] Figure 6This is a schematic diagram of the structure of an electronic device provided in an embodiment of this specification;

[0048] Figure 7 This is a schematic diagram of a computer-readable medium provided for embodiments of this specification. Detailed Implementation

[0049] The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.

[0050] The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.

[0051] It should be noted that, unless otherwise specifically stated, the relative arrangement, numerical expressions, and values ​​of the components and steps described in these embodiments do not limit the scope of the invention.

[0052] The following description of at least one exemplary embodiment is merely illustrative and is in no way intended to limit the invention or its application or use.

[0053] Techniques, methods, and equipment known to those skilled in the art may not be discussed in detail, but where appropriate, such techniques, methods, and equipment should be considered part of the specification.

[0054] In all the examples shown and discussed herein, any specific values ​​should be interpreted as merely exemplary and not as limitations. Therefore, other examples of exemplary embodiments may have different values.

[0055] It should be noted that similar labels and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be discussed further in subsequent figures.

[0056] For machine learning tasks, the general goal is to train a function model y = f(x) that minimizes the loss function. In classical machine learning, f(x) typically consists of linear algebraic calculations such as matrix multiplication and addition. The elements of the matrices used in these calculations are generally distributed across the entire real number space, resulting in non-unitary matrices. In quantum machine learning, if common variable quantum circuits are used to encode parameters onto quantum logic gates, since the matrix form of quantum logic gates is unitary, the inverse matrix U of a unitary matrix... -1 It is equal to its conjugate transpose matrix U HThe range of function transformations that it can represent is naturally smaller than that of non-unitary matrices used in classical neural networks, and the range of problems it can solve is often less than that of classical machine learning models. In the last two years, quantum algorithms based on block-encoding have developed rapidly, which can directly encode non-unitary matrices into quantum states. The basic definition of block encoding is as follows: The main function of block encoding is to embed a non-unitary matrix A into a unitary matrix U. A This allows the role of A to be implemented and simulated on a quantum computer. Since quantum computers can only perform unitary operations, block coding is a key technology for performing non-unitary operations. The specific definition of block coding is as follows:

[0057] Given a matrix A, its (α,m) block encoding U A It is a unitary matrix that satisfies the following conditions:

[0058]

[0059] in, It is a specific m-qub it state (usually) It is any n-qubit state, A ~ =αA is the scaled A, α is the scaling factor, |G ⊥ Yes In an orthogonal state, I is an m*n matrix, where m = n.

[0060] A general block encoding can be defined as follows, which requires finding U A and U B and construct such Figure 1 The quantum circuit shown, in which The operation is a Hadamard transformation over n qubits. A The operation is a unitary matrix composed of multiple quantum logic gates, which transforms the matrix element A i,j The amplitude, U, is encoded as an auxiliary quantum bit. B The operation ensures that for every combination of (i,j), A i,j This represents the matrix element in the i-th row and j-th column of matrix A.

[0061] A major category of quantum machine learning models uses variational quantum circuits to construct quantum neural network models to solve optimization problems in machine learning. Classical machine learning optimization typically uses gradient descent. Therefore, we need to calculate the gradients of both classical and quantum computation functions simultaneously. For the derivatives of the quantum variational circuit's encoding into the logic gate parameters, we use parameter shifting rules to calculate the gradient of the quantum variational circuit.

[0062]

[0063] in, f(x; θ) represents the gradient of the quantum circuit with respect to θ, where θ represents the parameter in a logic gate of the quantum circuit, f(x; θ) represents the quantum circuit, and x represents the input data of the quantum circuit.

[0064] Then, this only calculates the gradient of the parameters in the quantum circuit with respect to the circuit output. To calculate the gradient of the parameters in the variational circuit with respect to the loss function, the chain rule is required. According to the model building process, the error of the neural network layer input with respect to the loss function is calculated in reverse order from the output to the front. The gradient of the quantum variational circuit is calculated by the first-order partial derivative matrix of the function and the aforementioned parameter shift rule, thereby iteratively updating the parameters in the variational quantum circuit.

[0065] For a variable quantum circuit with n parameters to be trained, each input data requires an additional 2n circuit calculations to obtain the parameters. as well as

[0066] Compared to the above methods, the block-coding-based quantum machine learning training framework largely retains the forward and backward computation processes, but differs in the quantum circuit construction and gradient computation methods.

[0067] Reference Figure 2 A schematic diagram illustrating the principle of a block-coding-based quantum machine learning model training method provided in this specification includes:

[0068] S101: Obtain the input data and loss function of the target layer in the quantum machine learning model to be trained; wherein, the target layer is represented by a quantum circuit constructed using a parametric non-unitary matrix; S102: Encode the transpose matrix of the input data and the first gradient of the target into the quantum circuit respectively to obtain a first quantum circuit; the first gradient of the target is the gradient of the output data obtained by the input data through the target layer relative to the loss function; S103: Run the first quantum circuit to obtain the second gradient of the parameters of the parametric non-unitary matrix relative to the loss function; S104: Update the parameters of the parametric non-unitary matrix according to the second gradient to update the value of the loss function and the first gradient of the target, until the loss function reaches the training cutoff condition; wherein, the training cutoff condition includes the value of the loss function reaching convergence.

[0069] In one optional embodiment, the input data X and loss function L of the target layer in the quantum machine learning model to be trained are first obtained; wherein, the target layer is represented by a quantum circuit constructed by a parametric non-unitary matrix W, the parametric non-unitary matrix W representing the correspondence between classical input data X and output data Y; then, the input data X is encoded into the quantum circuit to obtain a second quantum circuit; the second quantum circuit is run to obtain the quantum state data of the output data Y; then, the quantum state data is measured to obtain the output data Y, completing the forward computation of the target layer; finally, the label values ​​corresponding to the output data Y and the input data X are calculated. Calculate the value of the loss function L; calculate the first gradient of the target based on the output data Y and the value of the loss function L. To optimize the parameters in the parametric non-unitary matrix W1, it is necessary to find the gradient of the parameters of the parametric non-unitary matrix W with respect to the loss function L. Since the first gradient of the target... It is the gradient of the output data Y obtained from the input data X through the target layer relative to the loss function L. Using the matrix differentiation rule, it is easy to obtain:

[0070]

[0071] Combining the above formulas, we can obtain the second gradient of the parameters of the parametric non-unitary matrix W1 with respect to the loss function L. The expression is:

[0072]

[0073] This formula shows that, in order to calculate the second gradient of the parameters of the parametric non-unitary matrix W with respect to the loss function L... The transpose matrix X of the input data needs to be... T Target first gradient The blocks are encoded into the quantum circuit to obtain the first quantum circuit; then, the first quantum circuit is run to obtain the second gradient of the parameters of the parametric non-unitary matrix W with respect to the loss function. Finally, based on the second gradient The parameters of the parametric non-unitary matrix W are updated using a gradient optimization algorithm, and the value of the loss function L and the target first gradient are updated based on the updated parameters of the parametric non-unitary matrix W using a quantum circuit constructed from the updated parameters of the matrix W. The training continues until the loss function reaches the training cutoff condition; wherein, the training cutoff condition includes the convergence of the loss function L, and the gradient optimization algorithm includes stochastic gradient descent and adaptive moment estimation. This application implements the operation of non-unitary matrices on quantum circuits through the above-described block encoding method, which can fit and simulate more functions of classical neural networks and more easily combine the parallel computing advantages of quantum computing to optimize the loss function of classical neural networks. Compared with using variable quantum circuits for quantum machine learning training, it does not require constructing a gradient calculation quantum circuit proportional to the number of variable quantum parameters; it only requires constructing a block-encoded quantum circuit once using the gradient calculation function of classical non-unitary matrices, facilitating the calculation of parameter gradients in the quantum machine learning model and greatly reducing the number of quantum circuit runs.

[0074] Optionally, running the first quantum circuit to obtain the second gradient of the parameters of the parametric non-unitary matrix with respect to the loss function includes: running the first quantum circuit to obtain quantum state data of the second gradient of the parameters of the parametric non-unitary matrix with respect to the loss function; and measuring the quantum state data to obtain the second gradient.

[0075] In one alternative embodiment, the transpose matrix X of the input data is run. T Target first gradient The first quantum circuit, after being block-encoded into the quantum circuit, yields the second gradient of the parameters of the parametric non-unitary matrix W with respect to the loss function L. The quantum state data; the quantum state data is measured to obtain the second gradient. The classical data of the second gradient are obtained by quantum state measurement, which provides data support for the subsequent update of the parameters of the parametric non-unitary matrix W.

[0076] In one alternative embodiment, the value of the loss function L and the target first gradient are updated. The specific process is as follows: First, the input data X block is encoded into a parameter-updated quantum circuit containing a non-unitary matrix W, resulting in a third quantum circuit; then, the third quantum circuit is run to obtain new output data. The quantum state data; the quantum state data is measured to obtain new output data. According to the new output data The label value corresponding to the input data X Update the value of the loss function L; based on the new output data The updated loss function L updates the first gradient of the target. Update the first gradient of the target in a loop. This method provides data support for updating the parameters of the subsequent parametric non-unitary matrix W, thereby enabling the training of the quantum neural model.

[0077] In one optional embodiment, the quantum machine learning model consists of several objective layers. When the quantum machine learning model has two or more objective layers, it is necessary to calculate the third gradient of the input data X with respect to the loss function L. Third gradient The calculation formula is as follows:

[0078]

[0079] Therefore, it is necessary to include the parameters of the parametric non-unitary matrix W and the target first gradient. The blocks are encoded into the quantum circuit to obtain a fourth quantum circuit; the fourth quantum circuit is run to obtain the quantum state data of the third gradient of the input data X with respect to the loss function L; the quantum state data is measured to obtain the third gradient. The third gradient serves as the backpropagation input data for the layer preceding the current target layer. By performing backpropagation training of the quantum neural network model in this manner, the parameters of the parametric non-unitary matrix W of the quantum neural network model are updated, thereby completing the training of the quantum neural network model.

[0080] In one optional embodiment, taking a quantum machine learning model where the target layer includes a first target layer and a second target layer as an example, as follows: Figure 3 As shown, during normal propagation, the quantum machine learning model first encodes the input data X1 of the first target layer into a quantum circuit constructed using a parametric non-unitary matrix W1 within the first target layer. Then, it runs this quantum circuit and performs quantum state measurements to obtain the output data Y1 of the first target layer. At this point, the output data Y1 is also the input data X2 of the second target layer. Next, the output data Y1 is encoded into a quantum circuit constructed using a parametric non-unitary matrix W2 within the second target layer. This quantum circuit is then run, and quantum state measurements are performed to obtain the output data Y2 of the second target layer, thus completing the normal propagation process of the quantum machine learning model. The parameters of the parametric non-unitary matrix W1 are compiled into the first initial quantum circuit using block encoding.

[0081] After the normal propagation of the quantum machine learning model is complete, in order to achieve the desired model training effect, it is necessary to calculate the gradient of the parametric non-unitary matrix W2 with respect to the loss function L through backpropagation. The gradient of the parametric non-unitary matrix W1 with respect to the loss function L Specifically, such as Figure 4 As shown, the gradient of the output data Y2 with respect to the loss function L is first calculated. The gradient of the output data Y2 with respect to the loss function L The transpose of the input data X2 of the second target layer The block is encoded into the quantum circuit constructed using the parametric non-unitary matrix W2 in the second target layer. This quantum circuit is then run, and quantum state measurements are performed to obtain the gradient of the parametric non-unitary matrix W2 with respect to the loss function L. Then, the gradient of the output data Y2 with respect to the loss function L is calculated. The block is encoded into a quantum circuit constructed using a parametric non-unitary matrix W2 in the second target layer. This quantum circuit is then run, and quantum state measurements are performed to obtain the gradient of the input data X2 with respect to the loss function L. Next, the gradient of the input data X2 with respect to the loss function L is calculated. The transpose of the input data X1 from the first target layer is encoded into a block of quantum circuits constructed in the first target layer using a parametric non-unitary matrix W1. This quantum circuit is then run, and quantum state measurements are performed to obtain the gradient of the parametric non-unitary matrix W1 with respect to the loss function L. Finally, based on the gradient of the parametric non-unitary matrix W2 with respect to the loss function L... The parameters of the parametric non-unitary matrix W2 in the second objective layer are updated using a gradient optimization algorithm, and the gradient of the parametric non-unitary matrix W1 with respect to the loss function L is also considered. The parameters of the parametric non-unitary matrix W1 in the first target layer are updated using a gradient optimization algorithm. This process is repeated until the loss function L reaches its minimum or the preset number of training iterations is reached, at which point training stops, resulting in a well-trained quantum machine learning model. By implementing non-unitary matrix operations on quantum circuits using the block encoding method described above, a wider range of functions from classical neural networks can be fitted and simulated. This makes it easier to leverage the parallel computing advantages of quantum computing to optimize the loss function of classical neural networks. Compared to using variable quantum circuits for quantum machine learning training, it eliminates the need to construct a gradient calculation quantum circuit proportional to the number of variable quantum parameters. Only a single block-encoded quantum circuit needs to be constructed using the gradient calculation function of the classical non-unitary matrix, facilitating the calculation of parameter gradients in the quantum machine learning model and significantly reducing the number of quantum circuit runs.

[0082] This application first obtains the input data and loss function of the target layer in the quantum machine learning model to be trained; wherein the target layer is represented by a quantum circuit constructed using a parametric non-unitary matrix; then, the transpose matrix of the input data and the first gradient of the target are respectively block-encoded into the quantum circuit to obtain a first quantum circuit; the first gradient of the target is the gradient of the output data obtained by the input data passing through the target layer relative to the loss function; then, the first quantum circuit is run to obtain the second gradient of the parameters of the parametric non-unitary matrix relative to the loss function; finally, the parameters of the parametric non-unitary matrix are updated according to the second gradient to update the value of the loss function and the first gradient of the target, until the loss function reaches the training cutoff condition; wherein, the training cutoff condition includes the value of the loss function reaching convergence. This application implements the operation of non-unitary matrices on quantum circuits through the aforementioned block encoding method. It can fit and simulate more functions of classical neural networks and is easier to combine the parallel computing advantages of quantum computing to optimize the loss function of classical neural networks. Compared with using variable quantum circuits for quantum machine learning training, it does not require the construction of gradient calculation quantum circuits proportional to the number of variable quantum parameters. It only needs to construct a block-encoded quantum circuit once through the gradient calculation function of classical non-unitary matrices, which facilitates the calculation of parameter gradients in quantum machine learning models and greatly reduces the number of quantum circuit runs.

[0083] Reference Figure 5 This specification also provides an embodiment of a block-coding-based quantum machine learning model training device, comprising:

[0084] The information acquisition module 201 is used to acquire the input data and loss function of the target layer in the quantum machine learning model to be trained; wherein the target layer is represented by a quantum circuit constructed by a parametric non-unitary matrix.

[0085] The first encoding module 202 is used to encode the transpose matrix of the input data and the target first gradient into the quantum circuit respectively to obtain the first quantum circuit; the target first gradient is the gradient of the output data obtained by passing the input data through the target layer relative to the loss function;

[0086] The first quantum circuit operation module 203 is used to run the first quantum circuit and obtain the second gradient of the parameters of the parametric non-unitary matrix with respect to the loss function.

[0087] The parameter update module 204 is used to update the parameters of the parametric non-unitary matrix according to the second gradient to update the value of the loss function and the target first gradient, until the loss function reaches the training cutoff condition; wherein, the training cutoff condition includes the value of the loss function reaching convergence.

[0088] Optionally, the device further includes:

[0089] The second encoding module is used to encode the input data block into the quantum circuit to obtain the second quantum circuit;

[0090] The second quantum circuit operation module is used to run the second quantum circuit and obtain the quantum state data of the output data;

[0091] The first quantum state measurement module is used to measure the quantum state data to obtain the output data;

[0092] The target first gradient determination module is used to determine the target first gradient based on the output data and the loss function.

[0093] Optionally, the target first gradient determination module includes:

[0094] The loss function calculation unit is used to calculate the value of the loss function based on the label values ​​corresponding to the output data and the input data.

[0095] The target first gradient calculation unit is used to calculate the target first gradient based on the output data and the value of the loss function.

[0096] Optionally, the first quantum circuit operation module 203 includes:

[0097] The first quantum circuit operation unit is used to run the first quantum circuit and obtain quantum state data of the second gradient of the parameters of the parameter non-unitary matrix with respect to the loss function;

[0098] The second quantum state measurement unit is used to measure the quantum state data to obtain the second gradient.

[0099] Optionally, the parameter update module 204 includes:

[0100] The parameter update unit is used to update the parameters of the parametric non-unitary matrix according to the second gradient and the gradient optimization algorithm to update the values ​​of the target first gradient and the loss function; wherein, the gradient optimization algorithm includes stochastic gradient descent and adaptive moment estimation.

[0101] Optionally, the parameter update module 204 further includes:

[0102] The third encoding module is used to encode the input data block into a parameter-updated quantum circuit containing a non-unitary matrix, thereby obtaining the third quantum circuit.

[0103] The third quantum circuit operation module is used to run the third quantum circuit and obtain quantum state data of the new output data.

[0104] The second quantum state measurement module is used to measure the quantum state data to obtain new output data;

[0105] The loss function update module is used to update the value of the loss function based on the new output data and the label value corresponding to the input data.

[0106] The target first gradient update module is used to update the target first gradient based on the new output data and the updated value of the loss function.

[0107] Optionally, the quantum machine learning model consists of several target layers, and the device further includes:

[0108] The fourth encoding module is used to encode the parameters of the parametric non-unitary matrix and the target first gradient into the quantum circuit respectively, to obtain the fourth quantum circuit;

[0109] The fourth quantum circuit operation module is used to run the fourth quantum circuit to obtain the quantum state data of the third gradient of the input data relative to the loss function;

[0110] The third quantum state measurement unit is used to measure the quantum state data to obtain the third gradient; wherein the third gradient serves as the backpropagation input data of the layer preceding the current target layer.

[0111] Regarding the apparatus in the above embodiments, the process of performing each step has been described in detail in the embodiments of the method, and will not be elaborated here.

[0112] Based on the same inventive concept, embodiments of this specification also provide an electronic device.

[0113] The following describes embodiments of the electronic device of the present invention, which can be considered as specific implementations of the methods and apparatus embodiments of the present invention described above. Details described in the embodiments of the electronic device of the present invention should be considered as supplements to the methods or apparatus embodiments described above; details not disclosed in the embodiments of the electronic device of the present invention can be implemented with reference to the methods or apparatus embodiments described above.

[0114] Reference Figure 6 This is a schematic diagram of an electronic device provided as an embodiment of this specification. Refer to the following... Figure 6 The electronic device 300 according to this embodiment of the present invention will be described. Figure 6 The electronic device 300 shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.

[0115] like Figure 6As shown, the electronic device 300 is presented in the form of a general-purpose computing device. The components of the electronic device 300 may include, but are not limited to: at least one processing unit 310, at least one storage unit 320, a bus 330 connecting different device components (including storage unit 320 and processing unit 310), a display unit 340, etc.

[0116] The storage unit stores program code that can be executed by the processing unit 310, causing the processing unit 310 to perform the steps described in the processing method section of this specification according to various exemplary embodiments of the present invention. For example, the processing unit 310 can perform, for example... Figure 2 The steps are shown.

[0117] The storage unit 320 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 3201 and / or a cache storage unit 3202, and may further include a read-only memory unit (ROM) 3203.

[0118] The storage unit 320 may also include a program / utility 3204 having a set (at least one) of program modules 3205, such program modules 3205 including but not limited to: operating devices, one or more application programs, other program modules and program data, each or some combination of these examples may include an implementation of a network environment.

[0119] Bus 330 can represent one or more of several types of bus structures, including a memory cell bus or memory cell controller, a peripheral bus, a graphics acceleration port, a processing unit, or a local bus using any of the various bus structures.

[0120] Electronic device 300 can also communicate with one or more external devices 400 (e.g., keyboard, pointing device, Bluetooth device, etc.), and with one or more devices that enable a user to interact with the electronic device 300, and / or with any device that enables the electronic device 300 to communicate with one or more other computing devices (e.g., router, modem, etc.). This communication can be performed via input / output (I / O) interface 350. Furthermore, electronic device 300 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 360. Network adapter 360 can communicate with other modules of electronic device 300 via bus 330. It should be understood that, although... Figure 6As not shown, other hardware and / or software modules may be used in conjunction with electronic device 300, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID devices, tape drives, and data backup storage devices.

[0121] Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described in this invention can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this invention can be embodied in the form of a software product, which can be stored in a computer-readable storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, or network device, etc.) to execute the method described above according to this invention. When the computer instructions are executed by a data processing device, the computer-readable medium is able to implement the method described above, i.e., as follows: Figure 2 The method shown.

[0122] Reference Figure 7 This is a schematic diagram of a computer-readable medium provided for embodiments of this specification.

[0123] accomplish Figure 2 The computer instructions of the method shown can be stored on one or more computer-readable media. A computer-readable medium can be a readable signal medium or a readable storage medium. A readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor device, or any combination thereof. More specific examples (a non-exhaustive list) of readable storage media include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0124] The computer-readable storage medium may include data signals propagated in baseband or as part of a carrier wave, carrying readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The readable storage medium may also be any readable medium other than a readable storage medium, capable of transmitting, propagating, or transmitting a program for use by or in connection with an instruction execution device, apparatus, or apparatus. The program code contained on the readable storage medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof.

[0125] Program code for performing the operations of this invention can be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java and C++, and conventional procedural programming languages ​​such as C or similar languages. The program code can execute entirely on the user's computing device, partially on the user's device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).

[0126] In summary, this invention can be implemented in hardware, or as software modules running on one or more processors, or a combination thereof. Those skilled in the art will understand that in practice, general-purpose data processing devices such as microprocessors or digital signal processors (DSPs) can be used to implement some or all of the functions of some or all of the components according to the embodiments of the invention. The invention can also be implemented as a device or apparatus program (e.g., a computer program and computer program product) for performing part or all of the methods described herein. Such programs implementing the invention can be stored on a computer-readable medium or can take the form of one or more signals. Such signals can be downloaded from an Internet website, provided on a carrier signal, or provided in any other form.

[0127] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the present invention is not inherently related to any specific computer, virtual device, or electronic device, and various general-purpose devices can also implement the present invention. The above descriptions are merely specific embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

[0128] The various embodiments in this specification are described in a progressive manner. The same or similar parts between the various embodiments can be referred to each other. Each embodiment focuses on describing the differences from other embodiments.

[0129] The above description is merely an embodiment of this application and is not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.

Claims

1. A method for training quantum machine learning models based on block coding, characterized in that, include: Obtain the input data and loss function of the target layer in the quantum machine learning model to be trained; wherein the target layer is represented by a quantum circuit constructed using a parametric non-unitary matrix; The transpose matrix of the input data and the first gradient of the target are respectively block-encoded into the quantum circuit to obtain the first quantum circuit; the first gradient of the target is the gradient of the output data obtained by passing the input data through the target layer relative to the loss function; Running the first quantum circuit yields the second gradient of the parameters of the parametric non-unitary matrix relative to the loss function; The parameters of the parametric non-unitary matrix are updated according to the second gradient to update the value of the loss function and the target first gradient, until the loss function reaches the training cutoff condition; wherein, the training cutoff condition includes the value of the loss function reaching convergence.

2. The method as described in claim 1, characterized in that, Before encoding the transpose matrix of the input data and the target first gradient into the quantum circuit in blocks, the method further includes: The input data block is encoded into the quantum circuit to obtain the second quantum circuit; Run the second quantum circuit to obtain the quantum state data of the output data; The quantum state data is measured to obtain the output data; The first gradient of the target is determined based on the output data and the loss function.

3. The method as described in claim 2, characterized in that, Determining the first gradient of the target based on the output data and the loss function includes: The value of the loss function is calculated based on the label values ​​corresponding to the output data and the input data. The first gradient of the target is calculated based on the output data and the value of the loss function.

4. The method as described in claim 1, characterized in that, The process of running the first quantum circuit to obtain the second gradient of the parameters of the parametric non-unitary matrix with respect to the loss function includes: Running the first quantum circuit yields quantum state data of the second gradient of the parameters of the parametric non-unitary matrix relative to the loss function; The quantum state data is measured to obtain the second gradient.

5. The method as described in claim 1, characterized in that, The step of updating the parameters of the parametric non-unitary matrix according to the second gradient to update the value of the loss function and the target first gradient includes: The parameters of the parametric non-unitary matrix are updated according to the second gradient and the gradient optimization algorithm to update the values ​​of the target first gradient and the loss function; wherein, the gradient optimization algorithm includes stochastic gradient descent and adaptive moment estimation.

6. The method as described in claim 1, characterized in that, Updating the value of the loss function and the target first gradient includes: The input data block is encoded into a parameter-updated quantum circuit containing a non-unitary matrix to obtain a third quantum circuit; Running the third quantum circuit yields quantum state data for the new output data. The quantum state data is measured to obtain new output data; The value of the loss function is updated based on the new output data and the label values ​​corresponding to the input data. The target first gradient is updated based on the new output data and the updated value of the loss function.

7. The method as described in claim 1, characterized in that, The quantum machine learning model consists of several target layers, and the method further includes: The parameters of the parametric non-unitary matrix and the target first gradient are respectively block-encoded into the quantum circuit to obtain the fourth quantum circuit; Running the fourth quantum circuit yields the quantum state data of the third gradient of the input data relative to the loss function; The quantum state data is measured to obtain the third gradient; wherein the third gradient serves as the backpropagation input data of the layer preceding the current target layer.

8. A quantum machine learning model training device based on block coding, characterized in that... ,include: An information acquisition module is used to acquire the input data and loss function of the target layer in the quantum machine learning model to be trained; wherein the target layer is represented by a quantum circuit constructed using a parametric non-unitary matrix. The first encoding module is used to encode the transpose matrix of the input data and the target first gradient into the quantum circuit respectively to obtain the first quantum circuit; the target first gradient is the gradient of the output data obtained by passing the input data through the target layer relative to the loss function; The first quantum circuit operation module is used to run the first quantum circuit and obtain the second gradient of the parameters of the parametric non-unitary matrix with respect to the loss function; The parameter update module is used to update the parameters of the parametric non-unitary matrix according to the second gradient to update the value of the loss function and the target first gradient, until the loss function reaches the training cutoff condition; wherein, the training cutoff condition includes the value of the loss function reaching convergence.

9. An electronic device, characterized in that, The method includes a memory and a processor, wherein the memory stores computer instructions and the processor is configured to execute the computer instructions to perform the method according to any one of claims 1 to 7.

10. A storage medium, characterized in that, The storage medium stores computer instructions that are configured to execute the method described in any one of claims 1 to 7 when run.