A method and apparatus for optimizing a quantum neural network model
By constructing and optimizing a quantum neural network model, and utilizing orthogonal bases and loss functions, the problems of large quantum circuit depth and qubit number were solved, and quantum computing simulation of high-dimensional complex physical systems was realized.
Patent Information
- Application Number
- CN202211068147.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-31
- Publication Date
- 2026-02-17
- Estimated Expiration
- 2042-08-31
AI Technical Summary
Existing quantum neural network models, when simulating high-dimensional complex physical systems, have deep quantum circuits and a large number of qubits, which cannot effectively solve the current dilemma.
By constructing a quantum neural network model, initializing parameters, selecting an orthonormal basis, obtaining the final quantum state, introducing weights to construct a loss function, and updating parameters until the optimization termination condition is met, the depth of quantum circuits and the number of qubits are reduced.
This expands the application scope of quantum neural network models, reduces the depth of quantum circuits and the number of qubits, and is beneficial for quantum computing simulation of high-dimensional complex physical systems.
Smart Images

Figure CN117709415B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of quantum computing, and particularly relates to a quantum neural network model optimization method and device. BACKGROUND
[0002] With the advent of the big data era and the physical limit of Moore's law, quantum neural network methods are born, and a quantum neural network (QNN) model is a neural network model based on quantum mechanics principles, which can have greater information capacity and efficient parallel computing capacity, and can better solve the current bottleneck problems.
[0003] Quantum computing simulation is a simulation calculation that simulates quantum mechanics rules by means of numerical calculation and computer science. As a simulation program, it uses the high-speed computing capacity of a computer to depict the space-time evolution of a quantum state according to the basic laws of quantum bits of quantum mechanics. By using quantum computing simulation, the minimum eigenvalue of a matrix and the corresponding eigenvector can be obtained, and the ground state energy of a closed physical Hamiltonian and the corresponding quantum state can also be obtained.
[0004] Due to the advantages of quantum neural networks in computing performance, the current research on using quantum neural networks to realize quantum computing simulation has become a technical hotspot. However, the quantum circuit depth used for simulation based on the quantum neural network model is deep, the number of quantum bits required is large, and high-dimensional complex physical systems cannot be simulated. How to find a more optimized quantum neural network model to solve the current difficulties has become a problem to be solved. SUMMARY
[0005] The purpose of the application is to provide a quantum neural network model optimization method and device to solve the problems in the prior art. It obtains the final quantum state corresponding to the standard orthogonal basis, introduces weights to construct a loss function, widens the application range of the quantum neural network model, reduces the depth of the quantum circuit and the number of quantum bits, and is conducive to the realization of quantum computing simulation of high-dimensional complex physical systems using the quantum neural network model.
[0006] One embodiment of the application provides a quantum neural network model optimization method, which comprises:
[0007] A quantum neural network model is constructed, and the parameters of the quantum neural network model are initialized;
[0008] A group of standard orthogonal bases is selected, and the quantum neural network model is applied to the standard orthogonal bases respectively to obtain the final quantum state corresponding to the standard orthogonal bases, wherein the number of final quantum states is the same as the number of basis vectors contained in the standard orthogonal bases;
[0009] determine a loss function according to the final quantum state and a preset weight;
[0010] determine whether an optimization termination condition of the quantum neural network model is met based on the loss function, wherein the optimization termination condition is that a value of the loss function converges to a fixed value;
[0011] If not, update parameters of the quantum neural network model until the optimization termination condition is met, and obtain an optimized quantum neural network model.
[0012] Optionally, the constructing the quantum neural network model comprises:
[0013] constructing the quantum neural network model according to a system to be simulated and a preset ansatz.
[0014] Optionally, the constructing the quantum neural network model according to the system to be simulated and the preset ansatz comprises:
[0015] determining a target number of quantum bits for constructing the quantum neural network model according to a number of Pauli terms of a Hamiltonian corresponding to the system to be simulated;
[0016] constructing the quantum neural network model containing the target number of quantum bits according to the preset ansatz.
[0017] Optionally, the preset ansatz comprises:
[0018] a first ansatz module and a second ansatz module, wherein the first ansatz module is composed of an RX gate, an RZ gate and a CNOT gate acting on the last two quantum bits in sequence, and the second ansatz module is composed of an RX gate, an RZ gate acting on each quantum bit in sequence, and a CNOT gate acting on adjacent quantum bits.
[0019] Optionally, the initializing the parameters of the quantum neural network model comprises:
[0020] determining initial values of the parameters of the quantum neural network model according to a preset probability density function.
[0021] Optionally, the determining the loss function according to the final quantum state and the preset weight comprises:
[0022] determining the loss function by the following formula:
[0023]
[0024] wherein, the loss function is is a number of basis vectors contained in the standard orthogonal basis, and ω n is a number of basis vectors contained in the standard orthogonal basis, and ω kis a weight corresponding to the kth basis vector in the standard orthogonal basis, and the ψ k is a final quantum state corresponding to the kth basis vector in the standard orthogonal basis, and the H is a Hamiltonian corresponding to a system to be simulated.
[0025] Optionally, the updating the parameters of the quantum neural network model comprises:
[0026] replacing the parameters in the current quantum neural network model with the newly generated parameters; or
[0027] constructing a quantum circuit with the same structure as the preset circuit structure using the newly generated parameters, and inserting the quantum circuit into the current quantum neural network model.
[0028] Another embodiment of the present application provides a quantum neural network model optimization device, the device comprising:
[0029] a construction module configured to construct a quantum neural network model and initialize parameters of the quantum neural network model;
[0030] an obtaining module configured to select a set of standard orthogonal bases and apply the quantum neural network model to the standard orthogonal bases respectively to obtain final quantum states corresponding to the standard orthogonal bases, wherein the number of the final quantum states is the same as the number of basis vectors in the standard orthogonal bases;
[0031] a determination module configured to determine a loss function according to the final quantum states and preset weights;
[0032] a judgment module configured to judge whether an optimization termination condition of the quantum neural network model is met based on the loss function, wherein the optimization termination condition is that the value of the loss function converges to a fixed value;
[0033] an updating module configured to update the parameters of the quantum neural network model if the optimization termination condition is not met until the optimization termination condition is met, and obtain an optimized quantum neural network model.
[0034] Optionally, the construction module comprises:
[0035] a construction unit configured to construct a quantum neural network model according to a system to be simulated and a preset circuit structure.
[0036] Optionally, the construction unit comprises:
[0037] a determination subunit configured to determine a target number of quantum bits for constructing a quantum neural network model according to the number of Pauli terms of a Hamiltonian corresponding to a system to be simulated;
[0038] a construction subunit configured to construct a quantum neural network model containing the target number of quantum bits according to a preset circuit structure.
[0039] Optionally, the construction module comprises:
[0040] The first determination unit is configured to determine the initial value of the quantum neural network model parameter according to a preset probability density function.
[0041] Optionally, the determination module comprises:
[0042] The second determination unit is configured to determine the loss function by the following formula:
[0043]
[0044] The loss function is determined by the following formula: n The number of basis vectors contained in the standard orthogonal basis is ω, the weight corresponding to the kth basis vector in the standard orthogonal basis is ω k, the final quantum state corresponding to the kth basis vector in the standard orthogonal basis is ψ k, and the Hamiltonian corresponding to the system to be simulated is H. k k The number of basis vectors contained in the standard orthogonal basis is ω, the weight corresponding to the kth basis vector in the standard orthogonal basis is ω k, the final quantum state corresponding to the kth basis vector in the standard orthogonal basis is ψ k, and the Hamiltonian corresponding to the system to be simulated is H.
[0045] Optionally, the update module comprises:
[0046] The replacement unit is configured to replace the parameters in the current quantum neural network model with the newly generated parameters; or
[0047] The construction unit is configured to construct a quantum circuit with the same structure as the preset quantum circuit structure by using the newly generated parameters, and insert the quantum circuit into the current quantum neural network model.
[0048] Another embodiment of the present application provides a storage medium having a computer program stored therein, wherein the computer program is configured to execute the method described in any one of the above embodiments when running.
[0049] Another embodiment of the present application provides an electronic device comprising a memory and a processor, wherein the memory has a computer program stored therein, and the processor is configured to execute the computer program to execute the method described in any one of the above embodiments.
[0050] Compared with existing technologies, this invention first constructs a quantum neural network model and initializes its parameters. It then selects a set of orthonormal bases and applies the quantum neural network model to each base to obtain the final quantum state corresponding to the base. Based on the final quantum state and preset weights, a loss function is determined. Based on the loss function, it is determined whether the optimization termination condition of the quantum neural network model is met. If not, the parameters of the quantum neural network model are updated until the optimization termination condition is met, resulting in an optimized quantum neural network model. By obtaining the final quantum state corresponding to the orthonormal base and introducing weights to construct the loss function, this invention broadens the application scope of the quantum neural network model and reduces the depth of quantum circuits and the number of qubits, which is beneficial for realizing quantum computing simulations of high-dimensional complex physical systems using the quantum neural network model. Attached Figure Description
[0051] Figure 1 This is a hardware structure block diagram of a computer terminal for an optimization method of a quantum neural network model provided in an embodiment of the present invention;
[0052] Figure 2 This is a flowchart illustrating an optimization method for a quantum neural network model provided in an embodiment of the present invention;
[0053] Figure 3 This is a schematic diagram of a pre-designed circuit provided in an embodiment of the present invention;
[0054] Figure 4 This is a schematic diagram of the structure of an optimization device for a quantum neural network model provided in an embodiment of the present invention. Detailed Implementation
[0055] 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.
[0056] This invention first provides an optimization method for a quantum neural network model, which can be applied to electronic devices, such as computer terminals, specifically ordinary computers, quantum computers, etc.
[0057] The following detailed explanation uses a computer terminal as an example. Figure 1 This is a hardware structure block diagram of a computer terminal for an optimization method of a quantum neural network model provided in an embodiment of the present invention. (See diagram below.) Figure 1 As shown, a computer terminal may include one or more ( Figure 1The computer terminal shown in FIG. 1 includes only one processor 102 (the processor 102 can include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA), and a memory 104 for storing data. Optionally, the computer terminal can further include a transmission device 106 for communication functions, and an input / output device 108. Those skilled in the art can understand that Figure 1 The structure shown in FIG. 1 is only illustrative and does not limit the structure of the computer terminal. For example, the computer terminal can include more or fewer components than those shown in FIG. 1, or have a different configuration than that shown in FIG. 1. Figure 1 Figure 1 The structure shown in FIG. 1 is only illustrative and does not limit the structure of the computer terminal. For example, the computer terminal can include more or fewer components than those shown in FIG. 1, or have a different configuration than that shown in FIG. 1.
[0058] The memory 104 can be used to store software programs and modules of application software, such as program instructions / modules corresponding to the optimization method of the quantum neural network model in the embodiments of the present application. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, i.e., implements the method described above. The memory 104 can include a high-speed random access memory, and can further include a non-volatile memory such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some examples, the memory 104 can further include a memory remotely disposed relative to the processor 102, which can be connected to the computer terminal through a network. Examples of the network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0059] The transmission device 106 is used to receive or send data via a network. Specific examples of the network can include a wireless network provided by a communication provider of the computer terminal. In one example, the transmission device 106 includes a network adapter (NIC) which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module which is used to communicate with the Internet in a wireless manner.
[0060] It should be noted that a real quantum computer is a hybrid structure, which includes two parts: one part is a classical computer responsible for performing classical computation and control; the other part is a quantum device responsible for running a quantum program to implement quantum computation. The quantum program is a sequence of instructions written in a quantum language such as QRunes language that can run on a quantum computer, which supports quantum logic gate operations and ultimately realizes quantum computation. Specifically, the quantum program is a sequence of instructions for operating quantum logic gates in a certain time sequence.
[0061] In practical applications, due to the limitation of the development of quantum device hardware, quantum computation simulation is usually needed to verify quantum algorithms, quantum applications, and the like. Quantum computation simulation is a process of simulating the running of a quantum program corresponding to a specific problem by means of a virtual architecture (i.e., a quantum virtual machine) of an ordinary computer. Generally, a quantum program corresponding to a specific problem needs to be constructed. The quantum program referred to in the embodiments of the present application is a program written in a classical language representing quantum bits and their evolution, wherein quantum bits, quantum logic gates, and the like related to quantum computation are represented by corresponding classical codes.
[0062] As an embodiment of a quantum program, a quantum circuit, also referred to as a quantum logic circuit, is the most commonly used general quantum computation model, representing a circuit for operating on quantum bits in an abstract concept, the composition of which includes quantum bits, a circuit (a time line), and various quantum logic gates, and finally the result needs to be read out by a quantum measurement operation.
[0063] Unlike a traditional circuit connected by metal wires to transmit voltage signals or current signals, in a quantum circuit, the circuit can be regarded as being connected by time, that is, the state of a quantum bit naturally evolves with time, and in this process, the quantum bit is operated according to the instruction of a Hamiltonian operator until it encounters a logic gate.
[0064] A quantum program as a whole corresponds to a total quantum circuit, and the quantum program described in the present application refers to the total quantum circuit, wherein the total number of quantum bits in the total quantum circuit is the same as the total number of quantum bits of the quantum program. It can be understood that: a quantum program can be composed of a quantum circuit, a measurement operation for quantum bits in the quantum circuit, a register for storing measurement results, and a control flow node (jump instruction), and a quantum circuit can include tens, hundreds, or even thousands or ten thousands of quantum logic gate operations. The execution process of a quantum program is a process of executing all quantum logic gates according to a certain timing sequence. It needs to be noted that the timing sequence is the time sequence in which a single quantum logic gate is executed.
[0065] It should be noted that in classical computing, the most basic unit is a bit, and the most basic control mode is a logic gate, which can be combined to achieve the purpose of controlling the circuit. Similarly, the way to handle quantum bits is quantum logic gates. Using quantum logic gates, quantum states can evolve, and quantum logic gates are the basis of quantum circuits, including single-bit quantum logic gates such as Hadamard gate (H gate), Pauli-X gate (X gate), Pauli-Y gate (Y gate), Pauli-Z gate (Z gate), RX gate, RY gate, RZ gate, and the like; multi-bit quantum logic gates such as CNOT gate, CR gate, iSWAP gate, Toffoli gate, and the like. Quantum logic gates are generally represented by unitary matrices, which are not only matrix forms but also operations and transformations. The action of a general quantum logic gate on a quantum state is calculated by left multiplying the quantum state by the matrix corresponding to the right vector.
[0066] Those skilled in the art can understand that in a classical computer, the basic unit of information is a bit, which has two states of 0 and 1, and the most common physical implementation is to represent the two states by the high and low levels. In quantum computing, the basic unit of information is a quantum bit, which also has two states of 0 and 1, denoted as |0> and |1>, but it can be in a superposition state of the two states, which can be represented as where a and b are complex numbers representing the amplitudes (probability amplitudes) of |0> and |1> states, which are not possessed by classical bits. After measurement, the state of the quantum bit will collapse to a certain state (eigenstate, here |0> or |1>), where the probability of collapsing to |0> is |a| 2 , and the probability of collapsing to |1> is |b| 2 , |a| 2 + |b| 2 = 1, and |> is the Dirac symbol.
[0067] A quantum state, i.e., the state of a quantum bit, generally needs to be described using a set of orthogonal and complete basis vectors, and the commonly used computational basis is represented in binary in quantum algorithms (or quantum programs). For example, a set of quantum bits q0, q1, q2 represents the 0th, 1st, and 2nd quantum bits, and the order from high to low is q2q1q0. The quantum state of this set of quantum bits is a superposition state of 2 3 computational bases, i.e., |000>, |001>, |010>, |011>, |100>, |101>, |110>, and |111>, each computational basis corresponds to a quantum bit, e.g., |000> corresponds to q2q1q0 from high to low. In short, a quantum state is a superposition state of basis vectors, and when the probability amplitude of other bases is 0, it is in a certain basis vector.
[0068] In quantum mechanics, all measurable mechanical quantities can be described by a Hermite matrix, the definition of which is that the transpose conjugate of the matrix is the matrix itself, that is, there is: Such a matrix is usually called a measurement operator, and a non-zero operator will have at least one non-zero eigenvalue λ and the corresponding eigenstate |ψ>, which satisfies H|ψ>=λ|ψ>. If the eigenvalue of the operator H corresponds to the energy level distribution of a system, such an operator can also be called a Hamiltonian.
[0069] According to the time-dependent Schrödinger equation, the evolution from one state |ψ(t=0)> to another state |ψ(t=T)> is completed by using a unitary operator, that is, U(0,T)|ψ(t=0)>=|ψ(t=T)>, where the relationship between the Hamiltonian and the unitary operator is that if a quantum state evolves naturally under a certain system, the energy of the system, that is, the Hamiltonian, then the unitary operator can be written as:
[0070] When the system starts from time 0 and the Hamiltonian does not change with time, the unitary operator is U=exp(-iHt). In quantum computing of a closed system, all quantum operations except measurement can be described by a unitary matrix, and the definition of the unitary matrix is that the transpose conjugate of the matrix is the inverse of the matrix, that is, there is: Generally, the unitary operator is also called a quantum logic gate in quantum computing.
[0071] See Figure 2 , Figure 2 The flowchart of the optimization method of the quantum neural network model provided by the embodiment of the application can include the following steps:
[0072] S201: Construct a quantum neural network model and initialize the parameters of the quantum neural network model.
[0073] Specifically, constructing a quantum neural network model can include: constructing a quantum neural network model according to a system to be simulated and a preset preparation circuit.
[0074] The system to be simulated is a system that needs to be simulated by quantum neural network for quantum computing, and the system to be simulated can be an equation, a molecule, or other systems. Preparation is a method of evolving a prepared initial state to a quantum circuit, and different preparation methods can result in different structures of quantum neural networks. The structure of the quantum neural network can be different with different systems to be simulated and preparation methods.
[0075] In some possible embodiments of the present application, constructing a quantum neural network model according to a system to be simulated and a preset ansatz can include:
[0076] 1. Determining a target number of quantum bits for constructing a quantum neural network model according to a number of Pauli terms of a Hamiltonian corresponding to a system to be simulated;
[0077] 2. Constructing a quantum neural network model containing the target number of quantum bits according to a preset ansatz.
[0078] The Hamiltonian is the sum of the kinetic energy of all particles plus the potential energy of the particles related to the system. For different cases or quantities of particles, the Hamiltonian is different, because it includes the sum of the kinetic energy of the particles and the potential energy function corresponding to this case, generally denoted as H. In quantum mechanics, physical quantities of classical mechanics become corresponding operators, and the Hamiltonian corresponds to the Hamiltonian operator. Generally, in order to be able to process quantum computing simulation problems on quantum devices, the Hamiltonian will be expressed in the form of a weighted sum of Pauli operators {X, Y, Z, I}, where the number of Pauli terms is the target number of quantum bits:
[0079]
[0080] where c k is a weight coefficient, σ is a Pauli operator, M is the number of target quantum bits.
[0081] After determining the ansatz, the corresponding quantum logic gate is applied on the quantum bits, and the initial state is evolved into a quantum neural network. Specifically, the number of quantum bits in the quantum neural network can be the target number of quantum bits. The ansatz can be selected according to different cases. For example, the selected ansatz can be a unitary coupled cluster operator (UCC), and the corresponding ansatz formula is:
[0082]
[0083] where the matrix operator corresponding to the quantum circuit is , which is the ansatz, P i is a generator.
[0084] The simulation method can also be ADAPT (adaptive derivative-assembled pseudo-Trotter), which can be seen as an improvement based on UCC. Of course, other simulation methods include HE (Hardware Efficient), SP (Symmetry Preserved), etc. In this embodiment of the invention, the number of layers (the depth of the simulation method) in the untrained quantum neural network is related to the number of target qubits; specifically, the initial number of layers can be the number of target qubits. More specifically, the neural network constructed according to the simulation method can contain entangled quantum circuits, so the depth of the simulation method can be the number of isomorphically entangled quantum circuits.
[0085] In one alternative implementation, see [link to implementation details]. Figure 3 , Figure 3 This is a schematic diagram of a preset proposed circuit provided in an embodiment of the present invention. The preset proposed circuit may include: a first proposed circuit module and a second proposed circuit module. The first proposed circuit module is composed of an RX gate, an RZ gate and a CNOT gate acting sequentially on the last two qubits. The second proposed circuit module is composed of an RX gate, an RZ gate acting sequentially on each qubit and a CNOT gate acting on the adjacent qubit.
[0086] The initialization of the parameters of the quantum neural network model may include: determining the initial values of the parameters of the quantum neural network model according to a preset probability density function.
[0087] Specifically, in this embodiment of the invention, parameter values can be set based on experience, or numerical values can be selected as the initial values of the parameters based on the algorithm.
[0088] In some possible embodiments of the present invention, initializing the parameters of the quantum neural network may include: initializing the parameters according to a preset probability density function.
[0089] It should be noted that the probability density function can be selected based on the actual situation, or determined according to the mapping relationship between the probability density function and the preset setting. There can be more than one parameter; when there is more than one parameter, they can be initialized separately or simultaneously, without limitation. The initial parameter values can be randomly selected from the function values of the probability density function, or values selected according to certain rules. For example, the probability density function can be a uniform probability density function. According to the properties of a uniform probability density function, the initial value of the parameter is 1 / (ba). For example, b is 2π, a is 0, and the initial parameter value is 1 / 2π.
[0090] S202: select a set of standard orthogonal bases, and apply the quantum neural network model to the standard orthogonal bases respectively to obtain final quantum states corresponding to the standard orthogonal bases, wherein the number of final quantum states is the same as the number of basis vectors contained in the standard orthogonal bases.
[0091] Specifically, by acting quantum neural network on a set of orthogonal initial states (which can be standard orthogonal bases |0><0|, |0><1|, |1><0|, |1><1|), final quantum states |ψ1(θ)>, |ψ2(θ)>, |ψ3(θ)>, |ψ4(θ)> corresponding to the standard orthogonal bases are obtained.
[0092] S203: determine a loss function according to the final quantum states and a preset weight.
[0093] Specifically, the loss function in the quantum neural network model is generally given by the weighted sum of the energy expectation value of each output quantum state |ψ k (θ) with respect to the Hamiltonian H. The weight vector ω can be defaulted as [1, 1, 1, 1].
[0094] wherein the loss function is determined by the following formula:
[0095]
[0096] wherein the loss function is determined by the following formula: n n is the number of basis vectors contained in the standard orthogonal bases, and ωk is the weight corresponding to the kth basis vector in the standard orthogonal bases. k ψk is the final quantum state corresponding to the kth basis vector in the standard orthogonal bases, and H is the Hamiltonian corresponding to the system to be simulated. k
[0097] S204: determine whether the optimization termination condition of the quantum neural network model is met based on the loss function, wherein the optimization termination condition is that the value of the loss function converges to a fixed value.
[0098] Specifically, based on the loss function, it is determined whether the optimization termination condition of the quantum neural network model is met. In fact, it is determined whether the quantum neural network has been trained well. When the value of the loss function converges to a fixed value, for example, the value of the loss function converges to zero or other numerical value, a trained quantum neural network model is obtained, that is, a VQE (Variational Quantum Eigensolver) model based on the quantum neural network.
[0099] In an alternative embodiment, it can also be determined whether the difference between the current loss function value and the previous loss function value meets a preset accuracy. As the quantum neural network model is optimized, the loss function value becomes smaller and smaller, i.e., the difference between the current loss function value and the previous loss function value also becomes smaller and smaller, and the optimization goal is to make the loss function value converge to a fixed value. If the difference between the current loss function value and the previous loss function value is within a preset range, it indicates that the loss function value has approximately equal to the ground state energy of the system to be simulated, and the subsequent research based on the ground state energy has little difference. In order to reduce the waste of computing resources, the optimization is terminated, and the quantum neural network model is optimized at this time. The preset accuracy mentioned here can be determined by the accuracy that the optimization wants to achieve, such as an accuracy of 10 -5 , and the preset range can be (0, 10 -5 ).
[0100] S205: If not, update the parameters of the quantum neural network model until the optimization termination condition is met, and obtain an optimized quantum neural network model.
[0101] Specifically, when the loss function value does not converge to a fixed value, it indicates that the quantum neural network model has not been optimized at this time and needs to be further optimized, and the parameters need to be updated at this time to enter a new round of optimization.
[0102] There are many methods for updating the parameters of the quantum neural network model, as long as the loss function value converges, for example, a fixed value can be set, and the difference or sum of the current parameter value and the fixed value can be used as the new parameter value; or the weight of the parameter value reduction can be determined based on the current loss function value and the previous loss function value, and the parameter value is updated based on the weight of the reduction.
[0103] In an alternative embodiment, a new parameter value is obtained using the loss function and the selected optimizer, and the parameter is updated based on the new parameter value.
[0104] Specifically, the optimizer guides the parameters of the loss function to update in the correct direction and appropriate size during the deep learning backpropagation process, so that the updated parameters make the loss function value continuously approach the global minimum.
[0105] The gradient of the parameter reduction is calculated using the loss function and the selected optimizer, and the specific calculation method is related to the type of the optimizer. Then, after obtaining the gradient, a new parameter value is obtained using the parameter update formula corresponding to the optimizer. For example, the parameter update formula can be: θ i+1 = θ i - αg t , where θ i is the current parameter, and θ i+1for the new parameter value, alpha is the learning rate, g t is the gradient of the current parameter, alpha can be set when configuring the quantum neural network.
[0106] In another optional implementation, updating the parameters of the quantum neural network model can include:
[0107] replacing the parameters in the current quantum neural network model with the newly generated parameters; or
[0108] constructing a quantum circuit with the same structure as the preset circuit structure using the newly generated parameters and inserting it into the current quantum neural network model.
[0109] Specifically, there are two ways to update the parameters: one is direct updating, and the other is that the parameters in the existing quantum neural network remain unchanged, and the quantum circuit with the same structure as the preset method is added to the current quantum neural network, that is, the number of layers of the quantum neural network is increased, and the newly generated quantum circuit is added after the current preset method structure, and the new parameter value is the parameter in the constructed quantum circuit.
[0110] It can be seen that the application first constructs a quantum neural network model, initializes the parameters of the quantum neural network model, selects a set of standard orthogonal bases, and applies the quantum neural network model to the standard orthogonal bases respectively to obtain the final quantum state corresponding to the standard orthogonal bases, determines the loss function according to the final quantum state and the preset weight, judges whether the optimization termination condition of the quantum neural network model is met based on the loss function, updates the parameters of the quantum neural network model if not, until the optimization termination condition is met, and an optimized quantum neural network model is obtained. It obtains the final quantum state corresponding to the standard orthogonal bases, and introduces the weight to construct the loss function, which widens the application range of the quantum neural network model, reduces the depth of the quantum circuit and the number of quantum bits, and is conducive to the realization of quantum computing simulation of high-dimensional complex physical systems by using the quantum neural network model.
[0111] Referring to Figure 4 , Figure 4 The structure diagram of the optimization device of the quantum neural network model provided by the embodiment of the application corresponds to the flow shown in Figure 2 may include:
[0112] The construction module 401 is configured to construct a quantum neural network model and initialize the parameters of the quantum neural network model.
[0113] The obtaining module 402 is configured to select a set of standard orthogonal bases and apply the quantum neural network model to the standard orthogonal bases respectively to obtain the final quantum state corresponding to the standard orthogonal bases, wherein the number of final quantum states is the same as the number of basis vectors contained in the standard orthogonal bases.
[0114] The determining module 403 is configured to determine a loss function according to the final quantum state and a preset weight.
[0115] The judging module 404 is configured to judge whether an optimization termination condition of the quantum neural network model is met based on the loss function, where the optimization termination condition is that a value of the loss function converges to a fixed value.
[0116] The updating module 405 is configured to update parameters of the quantum neural network model if the optimization termination condition is not met until the optimization termination condition is met, and obtain an optimized quantum neural network model.
[0117] Specifically, the constructing module comprises:
[0118] The constructing unit is configured to construct a quantum neural network model according to a system to be simulated and a preset assumed line.
[0119] Specifically, the constructing unit comprises:
[0120] The determining subunit is configured to determine a target number of quantum bits of the quantum neural network model to be constructed according to a number of Pauli terms of a Hamiltonian corresponding to the system to be simulated.
[0121] The constructing subunit is configured to construct a quantum neural network model containing the target number of quantum bits according to the preset assumed line.
[0122] Specifically, the constructing module comprises:
[0123] The first determining unit is configured to determine an initial value of the quantum neural network model parameter according to a preset probability density function.
[0124] Specifically, the determining module comprises:
[0125] The second determining unit is configured to determine a loss function through the following formula:
[0126]
[0127] The loss function is determined by the second determining unit. is a loss function, and 2 n is a number of basis vectors contained in a standard orthogonal basis, ω k is a weight corresponding to a kth basis vector in the standard orthogonal basis, ψ k is a final quantum state corresponding to the kth basis vector in the standard orthogonal basis, and H is a Hamiltonian corresponding to the system to be simulated.
[0128] Specifically, the updating module comprises:
[0129] a replacing unit configured to replace parameters in the current quantum neural network model with newly generated parameters; or
[0130] a constructing unit configured to construct a quantum circuit identical to the preset circuit structure using the newly generated parameters and insert the quantum circuit into the current quantum neural network model.
[0131] Compared with the prior art, the application firstly constructs a quantum neural network model, initializes parameters of the quantum neural network model, selects a set of standard orthogonal bases, and applies the quantum neural network model to the standard orthogonal bases to obtain final quantum states corresponding to the standard orthogonal bases, determines a loss function according to the final quantum states and preset weights, judges whether an optimization termination condition of the quantum neural network model is met based on the loss function, updates the parameters of the quantum neural network model if the optimization termination condition is not met, and obtains an optimized quantum neural network model until the optimization termination condition is met, which widens the application range of the quantum neural network model by obtaining the final quantum states corresponding to the standard orthogonal bases and introducing the weights to construct the loss function, reduces the depth of the quantum circuit and the number of quantum bits, and is conducive to the implementation of quantum computing simulation of high-dimensional complex physical systems by using the quantum neural network model.
[0132] The application also provides a storage medium having a computer program stored therein, wherein the computer program is configured to execute the steps in the method embodiments of any of the above when running.
[0133] Specifically, in the embodiment, the storage medium can be configured to store a computer program for executing the following steps:
[0134] S201: constructing a quantum neural network model and initializing parameters of the quantum neural network model;
[0135] S202: selecting a set of standard orthogonal bases and applying the quantum neural network model to the standard orthogonal bases to obtain final quantum states corresponding to the standard orthogonal bases, wherein the number of the final quantum states is the same as the number of basis vectors contained in the standard orthogonal bases;
[0136] S203: determining a loss function according to the final quantum states and preset weights;
[0137] S204: judging whether an optimization termination condition of the quantum neural network model is met based on the loss function, wherein the optimization termination condition is that the value of the loss function converges to a fixed value;
[0138] S205: updating the parameters of the quantum neural network model if the optimization termination condition is not met, and obtaining an optimized quantum neural network model until the optimization termination condition is met.
[0139] Specifically, in the embodiment, the storage medium can include but is not limited to a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various storage media that can store computer programs.
[0140] The embodiment of the present application also provides an electronic device including a memory and a processor, the memory storing a computer program, and the processor being arranged to run the computer program to execute the steps in the method embodiment of any one of the above.
[0141] Specifically, the electronic device can further include a transmission device connected with the processor and an input and output device connected with the processor.
[0142] Specifically, in the embodiment, the processor can be arranged to execute the following steps through the computer program:
[0143] S201: Constructing a quantum neural network model and initializing parameters of the quantum neural network model;
[0144] S202: Selecting a set of standard orthogonal bases and respectively applying the quantum neural network model to the standard orthogonal bases to obtain final quantum states corresponding to the standard orthogonal bases, wherein the number of the final quantum states is the same as the number of basis vectors contained in the standard orthogonal bases;
[0145] S203: Determining a loss function according to the final quantum states and a preset weight;
[0146] S204: Judging whether an optimization termination condition of the quantum neural network model is met based on the loss function, wherein the optimization termination condition is that a value of the loss function converges to a fixed value;
[0147] S205: If not, updating the parameters of the quantum neural network model until the optimization termination condition is met, and obtaining an optimized quantum neural network model.
[0148] The above embodiment according to the drawings details the structure, features and effects of the present application, and the above description is only the preferred embodiment of the present application, but the present application is not limited to the drawings shown, any change or modification made according to the idea of the present application, or the equivalent embodiment of equivalent change, as long as it is within the scope of the present application.
Claims
1. A method for optimizing a quantum neural network model, the method comprising: The method comprises: According to the system to be simulated and the preset ansatz, a quantum neural network model is constructed, and parameters of the quantum neural network model are initialized, wherein the preset ansatz comprises a first ansatz module and a second ansatz module, the first ansatz module is composed of an RX gate, an RZ gate and a CNOT gate acting on the last two qubits in sequence, and the second ansatz module is composed of an RX gate, an RZ gate acting on each qubit in sequence, and a CNOT gate acting on adjacent qubits; A set of standard orthogonal bases is selected, and the quantum neural network model is applied to the standard orthogonal bases respectively to obtain final quantum states corresponding to the standard orthogonal bases, wherein the number of the final quantum states is the same as the number of basis vectors contained in the standard orthogonal bases; According to the final quantum state and a preset weight, a loss function is determined, including: determining the loss function through the following formula: , wherein the loss function is , the number of basis vectors contained in the standard orthogonal basis is , the weight corresponding to the th basis vector in the standard orthogonal basis is , the final quantum state corresponding to the th basis vector in the standard orthogonal basis is , and the Hamiltonian corresponding to the system to be simulated is . Based on the loss function, it is judged whether the optimization termination condition of the quantum neural network model is met, wherein the optimization termination condition is that the value of the loss function converges to a fixed value; If not, the parameters of the quantum neural network model are updated until the optimization termination condition is met, and an optimized quantum neural network model is obtained.
2. The method of claim 1, wherein, The quantum neural network model is constructed according to the system to be simulated and the preset ansatz, comprising: According to the number of tensor product terms of the Hamiltonian corresponding to the system to be simulated, the number of target qubits for constructing the quantum neural network model is determined; According to the preset ansatz, a quantum neural network model containing the number of target qubits is constructed.
3. The method of claim 1, wherein, The parameters of the quantum neural network model are initialized, comprising: According to the preset probability density function, the initial value of the quantum neural network model parameter is determined.
4. The method of claim 1, wherein, The parameters of the quantum neural network model are updated, comprising: The current parameters in the quantum neural network model are replaced by the newly generated parameters; or A quantum circuit with the same structure as the preset ansatz is constructed using the newly generated parameters and is inserted into the current quantum neural network model.
5. An apparatus for optimizing a quantum neural network model, the apparatus comprising: a quantum neural network model; and a quantum processor configured to perform a quantum optimization of the quantum neural network model. The device comprises: A construction module is configured to construct a quantum neural network model according to a system to be simulated and a preset ansatz, and to initialize parameters of the quantum neural network model, wherein the preset ansatz comprises a first ansatz module and a second ansatz module, the first ansatz module is composed of an RX gate, an RZ gate and a CNOT gate acting on the last two qubits in sequence, and the second ansatz module is composed of an RX gate, an RZ gate acting on each qubit in sequence, and a CNOT gate acting on adjacent qubits; An obtaining module is configured to select a set of standard orthogonal bases, and apply the quantum neural network model to the standard orthogonal bases respectively to obtain final quantum states corresponding to the standard orthogonal bases, wherein the number of the final quantum states is the same as the number of basis vectors contained in the standard orthogonal bases; The determining module is configured to determine a loss function according to the final quantum state and a preset weight, including: determining the loss function by the following formula: , wherein the loss function is , the number of basis vectors contained in the standard orthogonal basis is , the weight corresponding to the th basis vector in the standard orthogonal basis is , the final quantum state corresponding to the th basis vector in the standard orthogonal basis is , and the Hamiltonian corresponding to the system to be simulated is . A judging module is configured to judge whether the optimization termination condition of the quantum neural network model is met based on the loss function, wherein the optimization termination condition is that the value of the loss function converges to a fixed value; An updating module is configured to update the parameters of the quantum neural network model until the optimization termination condition is met, and obtain an optimized quantum neural network model.
6. A storage medium, characterized by The storage medium stores a computer program, and the computer program is configured to execute the method in any one of claims 1 to 4 when running. 7.An electronic device comprising a memory and a processor, the electronic device characterized by, The memory stores a computer program, and the processor is configured to execute the computer program to execute the method in any one of claims 1 to 4.
Citation Information
Patent Citations
Quantum data storage method and device, quantum data reading method and device and computing equipment
CN111563186A
Method and system for estimating expected value under quantum system
CN114202072A