Quantum state amplitude encoding method, device, equipment and medium based on Gray code
Through the quantum state amplitude coding method based on Gray code, a simplified quantum circuit is constructed, which solves the problem of quantum circuit complexity in the Top-down amplitude coding method, improves the encoding efficiency and simulation speed, and reduces noise interference.
Patent Information
- Application Number
- CN202510018990.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-07
- Publication Date
- 2025-05-13
- Estimated Expiration
- 2045-01-07
AI Technical Summary
The Top-down amplitude encoding method has many quantum gates in quantum machine learning tasks, resulting in complex quantum circuits, slowing down simulation speeds, and may cause noise interference on real hardware.
Using a quantum state amplitude encoding method based on the Gray code, a Gray code queue is generated by normalizing the real vector to be encoded, and a target quantum circuit is constructed, including an alternately arranged X gate and Ry gate. The application position of each X gate and Ry gate is determined according to the Gray code queue.
The total number of quantum gates in quantum circuits is reduced, the encoding efficiency is improved, the encoded quantum circuits are simplified, the simulation speed on the simulator is accelerated, and the noise interference on the real hardware is reduced.
Smart Images

Figure CN119416907B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of quantum computing technology, and in particular to a quantum state amplitude encoding method, device, equipment and medium based on Gray code. Background Art
[0002] Quantum state coding is the process of converting classical information into quantum states, and is an important preprocessing step in quantum computing. Top-down amplitude coding is one of the commonly used quantum state coding techniques in quantum machine learning tasks. The basic idea is to convert classical data into the amplitude of quantum states, so as to make full use of quantum superposition characteristics for efficient information processing. The advantages of top-down amplitude coding include no need to introduce auxiliary bits, small width of quantum circuits, and the ability to achieve precise coding, etc. However, its main disadvantage is that the circuit contains more quantum gates, and except for the first quantum gate, the rest are controlled gates with different control bits. In the actual execution circuit, one or more X gates need to be added before all controlled gates, which further increases the total number of quantum gates and complicates the quantum circuit, resulting in slower simulation speed on the simulator, and may bring greater noise interference on real hardware. Summary of the invention
[0003] The purpose of the present invention is to provide a quantum state amplitude encoding method, device, equipment and medium based on Gray code.
[0004] The embodiment of the present invention provides a quantum state amplitude encoding method based on Gray code, comprising: normalizing a real vector to be encoded; generating a Gray code queue according to the normalized real vector to be encoded; calculating any two adjacent Gray codes according to the generation order of each Gray code in the Gray code queue to obtain a corresponding target XOR value; encoding the normalized real vector to be encoded by adopting a quantum state encoding algorithm to obtain a parameter of an Ry gate; constructing a target quantum circuit according to the Gray code queue; wherein the target quantum circuit comprises a plurality of X gates and Ry gates, each X gate and each Ry gate are alternately arranged; the application position of each X gate is determined according to the target XOR value; the application position of each Ry gate containing a parameter is determined according to each Gray code in the Gray code queue; obtaining a target quantum state through the evolution of the target quantum circuit; wherein the normalized real vector to be encoded is mapped to the amplitude of the target quantum state.
[0005] Furthermore, constructing a target quantum circuit according to a Gray code queue includes:
[0006] According to the generation order of each Gray code in the Gray code queue, the corresponding controlled Ry gates are arranged in the target quantum circuit so that the Hamming distances between the effective control bits of adjacent controlled Ry gates are all 1.
[0007] Furthermore, generating a Gray code queue according to the normalized real vector to be encoded includes:
[0008] Set the dimension of the normalized real vector to be encoded to ; Where n is a positive integer;
[0009] If n is greater than 1, the initial Gray code is recorded as 0;
[0010] like , invert the leftmost bit of the previous Gray code to generate the first current Gray code; where m is the number of Gray code bits in this round; h is the number of Gray codes generated in this round; or,
[0011] like , invert the right bit of the first 0 bit from the left of the previous Gray code to generate a second current Gray code; wherein the generation of the first current Gray code and the generation of the second current Gray code are performed alternately;
[0012] like ,and , increase the number of Gray codes in the previous cycle by one to get the number of Gray codes in this cycle; re-count the number of Gray codes generated in this cycle, and let , adding a 0 bit at the end of the previous Gray code to generate the third current Gray code.
[0013] Furthermore, the Gray code queue includes Gray code; among them,
[0014] In each round of generated Gray codes, the last bit of the first Gray code is 0, and the other bits are all 1;
[0015] All bits of the last Gray code in each round of generated Gray codes are 1;
[0016] All Gray codes in each round of generated Gray codes are different.
[0017] Furthermore, the method of constructing a target quantum circuit according to a Gray code queue further includes:
[0018] Initialize a quantum circuit; the initialized quantum circuit contains n quantum bits, and the initial state of the initialized quantum circuit is , n quantum bits are denoted from high to low ;
[0019] In the quantum bit Apply a Door.
[0020] Furthermore, the method of constructing a target quantum circuit according to a Gray code queue further includes:
[0021] like , the i-th bit in the target XOR value is 1, then in the quantum bit Apply an X gate on it;
[0022] Determine the corresponding target Gray code in the Gray code queue according to the target XOR value;
[0023] In the quantum bit Apply a controlled gate; where length represents the number of bits of the target Gray code, decimal represents the decimal number corresponding to the target Gray code, and quantum bit Is the control bit; controlled The gate has length control bits;
[0024] Traverse all target XOR values to determine the application position of each X gate;
[0025] Traverse all the target Gray codes to determine each controlled The location where the door is applied.
[0026] Furthermore, the target quantum state includes n quantum bits. The target quantum state has a linear combination of Amplitude, The amplitudes correspond to the real vector to be encoded. elements.
[0027] The embodiment of the present invention provides a high-efficiency amplitude coding device based on Gray code, comprising:
[0028] A normalization module, which is used to normalize the real vector to be encoded;
[0029] A generating module, which is used to generate a Gray code queue according to the normalized real vector to be encoded;
[0030] An XOR value module is used to calculate any two adjacent Gray codes according to the generation order of each Gray code in the Gray code queue to obtain a corresponding target XOR value;
[0031] A computing module is used to encode the normalized real vector to be encoded by adopting a quantum state encoding algorithm to obtain Parameters of the door;
[0032] A construction module is used to construct a target quantum circuit according to a Gray code queue; wherein the target quantum circuit includes a plurality of X gates and Ry gates, each X gate and each Ry gate are alternately arranged; the application position of each X gate is determined according to the target XOR value; each containing parameters The gate application position is determined according to each Gray code in the Gray code array;
[0033] An evolution module is used to obtain a target quantum state through evolution of a target quantum circuit; wherein the normalized real vector to be encoded is mapped to the amplitude of the target quantum state.
[0034] An embodiment of the present invention provides an electronic device, which includes a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, the steps of the method described above are implemented.
[0035] An embodiment of the present invention provides a computer-readable storage medium, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the steps of the method described above are implemented.
[0036] The above technical solution of the present invention has the following beneficial technical effects:
[0037] 1. In the embodiment of the present invention, a Gray code generation algorithm is designed, the generated Gray code is used as the effective control bit of the controlled gate, and the corresponding controlled gates are arranged according to the order of the generated Gray code, so that the Hamming distance between the effective control bits of adjacent controlled gates (i.e., adjacent Gray codes) is 1, and then the XOR value of any two adjacent Gray codes is calculated in sequence according to the order of the generated Gray code to determine the application position of the X gate between the adjacent controlled gates, and at the same time, each effective control bit of all the controlled gates is updated to , and finally obtain the actual running encoded quantum circuit. In this target quantum circuit, only one X gate needs to be added before all controlled gates, which reduces the total number of quantum gates in the quantum circuit, improves the coding efficiency, and simplifies the encoded quantum circuit, which can speed up the simulation speed implemented on the simulator and reduce the noise interference brought on the real hardware.
[0038] 2. In the embodiment of the present invention, the characteristics and advantages of Gray code are utilized to cleverly design the generation algorithm of the amplitude coding circuit, thereby reducing the number of X gates in the target quantum circuit actually executed. Compared with the existing Top-down amplitude coding method in quantum machine learning tasks, the coding method provided by the embodiment of the present invention achieves an exponential optimization effect on the number of X gates.
[0039] 3. In the embodiments of the present invention, since there is no need to introduce auxiliary bits, the number of quantum bits required is lower and it is easier to physically implement.
[0040] 4. The encoding method provided in the embodiment of the present invention can achieve 100% fidelity and can realize lossless encoding from classical data to quantum state amplitude. It is an accurate amplitude encoding method. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the technical solution of the embodiment of the present invention, the drawings in the embodiment of the present invention are briefly introduced below.
[0042] Figure 1 This is a schematic diagram of an existing coding circuit structure.
[0043] Figure 2 It is a flowchart of a quantum state amplitude encoding method based on Gray code according to an embodiment of the present invention.
[0044] Figure 3 It is a schematic diagram of the processing process of a quantum state amplitude encoding method based on Gray code according to an embodiment of the present invention.
[0045] Figure 4 It is a schematic diagram of a target quantum circuit structure according to an embodiment of the present invention.
[0046] Figure 5 It is a schematic diagram of another target quantum circuit structure according to an embodiment of the present invention.
[0047] Figure 6 It is a structural block diagram of a quantum state preparation device based on Gray code according to an embodiment of the present invention.
[0048] Figure 7 It is a schematic diagram of an electronic device for implementing a quantum state amplitude encoding method based on Gray code according to an embodiment of the present invention. DETAILED DESCRIPTION
[0049] The principles and spirit of the present invention will be described below with reference to several exemplary embodiments. It should be understood that the purpose of providing these embodiments is to make the principles and spirit of the present invention clearer and more thorough, so that those skilled in the art can better understand and implement the principles and spirit of the present invention. The exemplary embodiments provided herein are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments herein, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0050] Those skilled in the art will appreciate that the embodiments of the present invention may be implemented as a quantum state amplitude encoding method, device, electronic device, and computer-readable storage medium based on Gray code for encoding classical data into a quantum state. Therefore, the present disclosure may be specifically implemented in at least one of the following forms: complete hardware, complete software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.
[0051] In this document, terms such as first, second, etc. are only used to distinguish one entity (or operation) from another entity (or operation), and do not require or imply any order or association between these entities (or operations). In this document, the elements (such as parts, components, processes, steps) defined by the sentence "including..." do not exclude the existence of other elements in addition to the listed elements, that is, other elements that are not explicitly listed may also be included. In this document, any elements and their quantities in the drawings are used for illustration rather than limitation, and any names in the drawings are only used for distinction and do not have any limiting meaning.
[0052] The principle and spirit of the present invention are explained in detail below with reference to several exemplary or representative embodiments of the present invention.
[0053] The advantages of top-down amplitude coding include no need to introduce auxiliary bits, small width of quantum circuit, and accurate coding. However, its main disadvantage is that the circuit contains more quantum gates, and except for the first quantum gate, the rest are controlled gates with different control bits. In the actual circuit, one or more X gates need to be added before all controlled gates, which further increases the total number of quantum gates. Specifically, the number of X gates added depends on the Hamming distance between the effective control bit of the controlled gate and the previous controlled gate, that is, the number of difference bits between the two effective control bits.
[0054] If we use the existing Top-down amplitude coding method to encode a set of dimensions To encode the real vector x to be encoded, we can get Figure 1 The coding circuit shown in the figure contains 37 quantum gates in total. The inclusion of one or more X gates between gates complicates the quantum circuit, slows down the simulation speed on the simulator, and may cause greater noise interference on real hardware.
[0055] Based on this, the present invention proposes a quantum state amplitude coding method based on Gray code to achieve a more efficient amplitude coding method using fewer quantum gates.
[0056] Figure 2 A schematic flow chart of a quantum state amplitude encoding method based on Gray code according to an embodiment of the present invention is shown, and the method comprises the following steps:
[0057] S110: Normalize the real vector to be encoded.
[0058] Specifically, the obtained real vector to be encoded is normalized to achieve the purpose of encoding the input classical data into the amplitude of the quantum state, and it is determined whether the number of elements of the real vector to be encoded is , if the number of elements does not match , it needs to be padded with zeros so that the number of elements reaches , to meet the coding conditions of amplitude coding; where n is a positive integer.
[0059] S120: Generate a Gray code queue according to the normalized real vector to be encoded.
[0060] Specifically, in the encoding of a set of binary numbers, if there is only one bit difference between any two adjacent binary numbers, and there is only one bit difference between the first and the last binary numbers, then this encoding is called Gray code. Obviously, in a set of Gray codes, the Hamming distance between any two cyclically adjacent binary numbers is 1. Considering the characteristic that the Hamming distance between any two binary numbers in a set of Gray codes is always 1, the embodiment of the present invention introduces Gray code into the implementation process of amplitude coding, and designs a special Gray code generation algorithm, which can generate a set of Gray code queues A, which have Therefore, by introducing Gray code for amplitude coding, a simplified coded quantum circuit can be realized.
[0061] S130: According to the generation order of each Gray code in the Gray code queue, any two adjacent Gray codes are calculated to obtain a corresponding target XOR value.
[0062] Specifically, the calculated corresponding target XOR values may be saved in sequence to the XOR value queue B.
[0063] S140: Encode the normalized real vector to be encoded by adopting a quantum state encoding algorithm to obtain Parameters of the door;
[0064] Specifically, for example, the angle tree algorithm in the Top-down amplitude coding method can be used to calculate the real vector x to obtain parameters, such as The rotation angle parameters of the door, for example: .
[0065] S150: constructing a target quantum circuit according to the Gray code queue; wherein the target quantum circuit includes a plurality of X gates and Ry gates, each X gate and each Ry gate are alternately arranged; the application position of each X gate is determined according to the target XOR value; and the application position of each Ry gate containing a parameter is determined according to each Gray code in the Gray code queue.
[0066] S160: Obtain a target quantum state through the evolution of a target quantum circuit; wherein the normalized real vector to be encoded is mapped to the amplitude of the target quantum state.
[0067] Specifically, execute the target quantum circuit and evolve the resulting quantum final state It can be expressed as n qubits Linear combinations of computational basis states:
[0068]
[0069] Among them, the symbol The k in can be written in binary form to calculate the ground state The corresponding amplitude is , final state Total Amplitude , can be fixed according to the ascending order of k The order of calculating the ground state is , then the corresponding Amplitude That is, corresponding to the real vector x to be encoded elements.
[0070] In the embodiment of the present invention, a Gray code generation algorithm is designed, the generated Gray code is used as the effective control bit of the controlled gate, and the corresponding controlled gates are arranged according to the order of the generated Gray code, so that the Hamming distance between the effective control bits of adjacent controlled gates (i.e., adjacent Gray codes) is 1, and then the XOR value of any two adjacent Gray codes is calculated in sequence according to the order of the generated Gray code to determine the application position of the X gate between the adjacent controlled gates, and at the same time, each effective control bit of all the controlled gates is updated to , and finally obtain the actual running encoded quantum circuit. In this target quantum circuit, only one X gate needs to be added before all controlled gates, which reduces the total number of quantum gates in the quantum circuit, improves the coding efficiency, and simplifies the encoded quantum circuit, which can speed up the simulation speed implemented on the simulator and reduce the noise interference brought on the real hardware.
[0071] In some embodiments, constructing the target quantum circuit according to the Gray code queue includes: arranging corresponding controlled Ry gates in the target quantum circuit according to the generation order of each Gray code in the Gray code queue, so that the Hamming distance between the effective control bits of adjacent controlled Ry gates is 1.
[0072] In some embodiments, step S120: generating a Gray code queue according to the normalized real vector to be encoded comprises the following specific steps:
[0073] S121: Set the dimension of the normalized real vector to be encoded to ; Where n is a positive integer;
[0074] S122: If n is greater than 1, the initial Gray code is recorded as zero;
[0075] S123: If , invert the leftmost bit of the previous Gray code to generate the first current Gray code; where m is the number of Gray code bits in this round; h is the number of Gray codes generated in this round; or,
[0076] S124: If , invert the right bit of the first 0 bit from the left of the previous Gray code to generate a second current Gray code; wherein the generation of the first current Gray code and the generation of the second current Gray code are performed alternately;
[0077] S125: If ,and , increase the number of Gray codes in the previous cycle by one to get the number of Gray codes in this cycle; re-count the number of Gray codes generated in this cycle, and let , adding a 0 bit at the end of the previous Gray code to generate the third current Gray code.
[0078] In some embodiments, the Gray code queue includes Gray code; among them,
[0079] In each round of generated Gray codes, the last bit of the first Gray code is 0, and the other bits are all 1;
[0080] All bits of the last Gray code in each round of generated Gray codes are 1;
[0081] All Gray codes in each round of generated Gray codes are different.
[0082] Specifically, each round is defined by the number of Gray code bits. For example, when the number of Gray code bits is 1, the first Gray code generated in this round is 0, and the last Gray code is 1; when the number of Gray code bits is 2, the Gray codes generated in this round are as follows in the order of generation: ; And so on; and, each Gray code in the Gray code queue is generated in sequence according to the above steps S122-125 and saved to the Gray code queue A; in this way, all Gray codes in the Gray code queue A are different, and the Hamming distance between any two adjacent Gray codes in the Gray code queue A is 1.
[0083] In some embodiments, step S150: constructing a target quantum circuit according to a Gray code queue further includes the following specific steps:
[0084] S151: Initialize a quantum circuit; wherein the initialized quantum circuit contains n quantum bits, and the initial state of the initialized quantum circuit is , n quantum bits are denoted from high to low ;
[0085] S152: In quantum bits Apply a Door.
[0086] In some embodiments, step S150: constructing a target quantum circuit according to a Gray code queue further includes the following specific steps:
[0087] S153: If , the i-th bit from left to right in the target XOR value is 1, then in the quantum bit Apply an X gate on it;
[0088] S154: determining a corresponding target Gray code in the Gray code queue according to the target XOR value;
[0089] S155: In quantum bits Apply a controlled gate; where length represents the number of bits of the target Gray code, decimal represents the decimal number corresponding to the target Gray code, and quantum bit Is the control bit; controlled The gate has length control bits;
[0090] S156: traverse all target XOR values to determine the application position of each X gate;
[0091] S157: Traverse all target Gray codes to determine each controlled The location where the door is applied.
[0092] Specifically, according to a set of generated Gray code queues, an X gate and a controlled Ry gate are alternately applied in the quantum circuit, wherein the application position of the X gate is determined by the XOR value of each two adjacent Gray codes, and the parameters of the controlled Ry gate are determined by the number of bits of the Gray code and the corresponding decimal value, thereby generating the target quantum circuit that is actually executed. The main structure of the target quantum circuit is as follows: Figure 4 As shown, in the target quantum circuit, only one X gate needs to be added before all controlled gates, which reduces the total number of quantum gates in the quantum circuit, improves the coding efficiency, and simplifies the encoded quantum circuit, which can speed up the simulation speed implemented on the simulator and reduce the noise interference on the real hardware.
[0093] In some embodiments, the target quantum state includes n quantum bits. The target quantum state has a linear combination of Amplitude, The amplitudes correspond to the real vector to be encoded. elements.
[0094] Quantum state refers to the state of a quantum bit, and its eigenstate is represented by binary in a quantum algorithm (or quantum program). For example, a group of quantum bits is , indicating the 0th, 1st, and 2nd quantum bits, sorted from high to low: , the quantum state that can be evolved based on this group of quantum bits can be expressed as a linear combination of 8 computational basis states on 3 quantum bits: , , the quantum state has amplitudes, corresponding to the real vector x to be encoded. elements, each computational basis state corresponds to a quantum bit, such as state, 000 corresponds from high to low , that is, quantum bit Both are in state; state, 001 corresponds from high to low , that is, quantum bit Both are in state, quantum bit In state.
[0095] The implementation methods and advantages of the embodiments of the present invention are described above through multiple embodiments. The specific processing process of the embodiments of the present invention is described in detail below with reference to specific examples.
[0096] like Figure 3 As shown, the quantum state amplitude encoding method based on Gray code provided in the embodiment of the present invention is applied to encode the real vector x to be encoded, and the specific steps can be described as follows:
[0097] Step S1: Get the dimension (n is a positive integer), determine whether n is a positive integer greater than 1. If , then jump to step S8, otherwise continue to step S2;
[0098] For example, if the dimension is The real vector x to be encoded 0.205, 0.226, 0.440, 0.090,0.356, 0.025, 0.151, 0.195, 0.059, 0.367, 0.358, 0.055, 0.281, 0.302, 0.111,0.256 , where the real vector x to be encoded is already a normalized vector, that is, the dimension of x is .
[0099] Step S2: Generate a set of Gray code queues in a loop, record the number of Gray code bits in this loop as m, the number of Gray codes generated in this loop as h, the current Gray code generated most recently as gray, initialize an empty queue A to store all the generated Gray codes, set the initial state of the loop, and let , add gray to the end of queue A;
[0100] Step S3: If , invert the leftmost bit of the previous gray to get a new gray, and add the new gray to the end of queue A, and continue with step S4, otherwise, jump to step S5;
[0101] Step S4: If , invert the right bit of the first 0 bit from the left of the previous gray, and keep the other bits unchanged to get a new gray, and add the new gray to the end of queue A; jump to step S3, that is, step S3 and step S4 are performed alternately; otherwise, continue to step S5;
[0102] Step S5: If ,and , increase the number of Gray code bits by one, and re-count the number of Gray codes generated in the new cycle, so that the number of Gray codes generated in the new cycle is , add a 0 bit to the end of the previous gray to obtain a new gray, and add the new gray to the end of A; then jump to step S3, and then continue to step S4, step S3 and step S4 are performed alternately until the generation of this round of Gray code is completed; otherwise, continue to step S6;
[0103] Wherein, steps S3 to S5 are repeated, and in the whole cycle, the changes of m, h, gray, and A are shown in Table 1:
[0104] Table 1 Gray code queue generated by loop
[0105]
[0106] Step S6: Initialize queue B to store all adjacent The application of X gates between gates, the initial value contains only one element 1;
[0107] Step S7: Calculate the XOR value of any two adjacent Gray codes in queue A and add it to the end of queue B;
[0108] Take two adjacent Gray codes in queue A as a group of Gray codes, and record the two Gray codes in each group of Gray codes as a and b in order. If the number of bits of a and b is the same, add the XOR value of the two to the end of queue B; if the number of bits of a and b is different, add a 1 bit to the end of a, and then add the XOR value of the two to the end of queue B; repeat this step until the traversal of queue A is completed; in the whole traversal process, the changes of a, b, XOR value, and B are shown in Table 2:
[0109] Table 2 XOR value queue
[0110]
[0111] Step S8: Using the angle tree algorithm in the top-down amplitude coding method, the real vector x is calculated to obtain The parameters are as follows:
[0112] ;
[0113] in, Indicates uncontrolled The parameters of the door, Indicates that there are s control bits, and the effective control bit status is controlled Parameters of the door;
[0114] For example, for the dimension in the above step The real vector x to be encoded can be calculated to obtain 15 parameters, and the specific parameter values are as follows:
[0115]
[0116] Step S9: Initialize a circuit containing n qubits, the initial state is , n quantum bits are denoted from high to low ;
[0117] Step S10: In the quantum bit Apply a Door;
[0118] Step S11: Determine the X gate and the controlled The location of the door application;
[0119] If n ≥ 2, then traverse queues A and B synchronously, record the element in queue A traversed in this round as gray, and the element in queue B as xor, traverse all bits of xor, calculate the bits from left to right, and if the i-th bit is 1, then in the quantum bit Apply an X gate on it, and after traversing xor, the quantum bit Apply a length control bit to the controlled gate; where length represents the number of gray digits, decimal represents the decimal number corresponding to gray, and quantum bit is the control bit, repeat this step until queues A and B are traversed at the same time; during the entire traversal process, the changes of xor and gray and the corresponding X gates and controlled The application of the door is shown in Table 3:
[0120] Table 3 Application of quantum gates
[0121]
[0122] According to the data in Table 3, the coding circuit can be generated as follows Figure 5 If the same vector x is encoded using the existing Top-down amplitude coding method, the actual quantum circuit is as follows: Figure 1 As shown, Figure 1 The quantum circuit contains 37 quantum gates in total, and there are one or more X gates between adjacent controlled gates. Figure 5 The quantum circuit of the invention contains only 29 quantum gates, and there is only one X gate between adjacent controlled gates. Compared with the existing Top-down amplitude coding, the embodiment of the present invention reduces As the dimension of the classical data to be encoded increases, the number of X gates that can be reduced by the method proposed in the present invention will also increase exponentially, and the optimization effect on the number of X gates is .
[0123] Step S12: Execute the coding circuit generated in the above steps, and the evolved quantum state can be represented as The linear combination of the calculated basis states has a total of amplitudes, corresponding to the vector x elements.
[0124] For example, executing the encoding circuit generated by the above steps, the evolved quantum state can be expressed as a linear combination of 16 computational basis states on 4 quantum bits:
[0125]
[0126] It can be seen that the quantum state has a total of 16 amplitudes, corresponding to the real vector x to be encoded. 0.205, 0.226, 0.440, 0.090, 0.356, 0.025, 0.151, 0.195, 0.059, 0.367, 0.358, 0.055, 0.281, 0.302, 0.111, 0.256 Therefore, the above method steps provided by the embodiment of the present invention can successfully encode classical data accurately into the quantum state amplitude.
[0127] In the embodiment of the present invention, for example If a classical data is encoded into n quantum bits, the corresponding quantum circuit will consist of 1 Door, controlled Door and X gates, including Under the same circumstances, the existing Top-down amplitude coding circuit will be replaced by 1 Door, controlled Door and X gates, including In contrast, the quantum state amplitude encoding method provided by the embodiment of the present invention can effectively reduce This allows for faster simulations on simulators or higher fidelity on real hardware by avoiding greater noise interference.
[0128] Corresponding to the method embodiment of the present invention, the present invention also provides a quantum state preparation device based on Gray code, such as Figure 6 As shown, specifically, it may include:
[0129] A normalization module 510, which is used to perform normalization processing on the real vector to be encoded;
[0130] A generating module 520, which is used to generate a Gray code queue according to the normalized real vector to be encoded;
[0131] An XOR value module 530, which is used to calculate any two adjacent Gray codes according to the generation order of each Gray code in the Gray code queue to obtain a corresponding target XOR value;
[0132] A calculation module 540, which is used to encode the normalized real vector to be encoded by adopting a quantum state encoding algorithm to obtain the parameters of the Ry gate;
[0133] A construction module 550 is used to construct a target quantum circuit according to a Gray code queue; wherein the target quantum circuit includes a plurality of X gates and Ry gates, each X gate and each Ry gate are alternately arranged; the application position of each X gate is determined according to the target XOR value; the application position of each Ry gate containing a parameter is determined according to each Gray code in the Gray code queue;
[0134] The evolution module 560 is used to obtain a target quantum state through the evolution of the target quantum circuit; wherein the normalized real vector to be encoded is mapped to the amplitude of the target quantum state.
[0135] In another aspect, the present invention further provides an electronic device, see Figure 7 , Figure 7 1 is a block diagram of the structure principle of an electronic device according to an embodiment of the present invention. Figure 7 As shown, the electronic device includes a processor 601 and a memory 602 storing computer program instructions; when the processor 601 executes the computer program instructions, the quantum state amplitude encoding method in the above-mentioned embodiment is implemented.
[0136] Specifically, the processor 601 may include a central processing unit (CPU) or a graphics processing unit (GPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of an embodiment of the present invention. The memory 602 may include a memory for data or instructions. For example, the memory 602 may be at least one of the following: a hard disk drive (HDD), a read-only memory (ROM), a random access memory (RAM), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a tape, a universal serial bus (USB) drive, or other physical / tangible memory storage device. For another example, the memory 602 includes a removable or non-removable (or fixed) medium. For another example, the memory 602 may be inside or outside the integrated gateway disaster recovery device. The memory 602 may be a non-volatile solid-state memory. In other words, typically the memory 602 includes a tangible (non-transitory) computer-readable storage medium (such as a memory device) encoded with executable instructions, wherein when the stored executable instructions are executed by the processor 601 (such as executed by one or more processors), the quantum state amplitude encoding method in the embodiment of the present invention can be implemented.
[0137] In one example, Figure 7The electronic device shown may also include a communication interface 603 and a bus 610. The processor 601, the memory 602, and the communication interface 603 are connected and communicate with each other via the bus 610. The communication interface 603 is mainly used to implement communication between modules, devices, units, and / or devices in the electronic device.
[0138] The bus 610 includes hardware, software or both, and can couple the components of the online data traffic billing device to each other. For example, the bus may include at least one of the following: an accelerated graphics port (AGP) or other graphics bus, an enhanced industrial standard architecture (EISA) bus, a front-side bus (FSB), a hypertransport (HT) interconnect, an industrial standard architecture (ISA) bus, an infinite bandwidth interconnect, a low pin count (LPC) bus, a memory bus, a microchannel architecture (MCA) bus, a peripheral component interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a serial advanced technology attachment (SATA) bus, a video electronics standard association local (VLB) bus or other suitable bus. The bus 610 may include one or more buses. Although the embodiments of the present invention describe or show a specific bus, the embodiments of the present invention may consider any suitable bus or interconnection method.
[0139] On the other hand, an embodiment of the present invention further provides a computer-readable storage medium, on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the aforementioned quantum state amplitude encoding method is implemented.
[0140] The flowchart and / or block diagram of the method and system of the embodiment of the present invention are described above by way of example, and various aspects of the related aspects are described. It should be understood that each box or combination thereof in the flowchart and / or block diagram can be implemented by computer program instructions, or by dedicated hardware that performs specified functions or actions, or by a combination of dedicated hardware and computer instructions. For example, these computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device to form a machine that enables these instructions executed by such a processor to enable the implementation of the functions / actions specified in each box or combination thereof in the flowchart and / or block diagram. Such a processor can be a general-purpose processor, a special-purpose processor, a special application processor, or a field programmable logic circuit.
[0141] The functional blocks shown in the structural block diagram of the embodiment of the present invention can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application-specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc.; when implemented in software, it is a program or code segment used to perform the required task. The program or code segment can be stored in a memory, or transmitted on a transmission medium or a communication link via a data signal carried in a carrier. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0142] It should be noted that the present invention is not limited to the specific configurations and processes described above or shown in the figures. The above is only a specific implementation mode of the present invention. Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working process of the described system, device, module or unit can refer to the corresponding process in the method embodiment without further description. It should be understood that the protection scope of the present invention is not limited to this. Any technician familiar with the technical field can think of various equivalent modifications or substitutions within the technical scope disclosed by the present invention, and these modifications or substitutions should be covered within the protection scope of the present invention.
Claims
1. A quantum state amplitude encoding method based on Gray code, characterized in that: include: The real vector to be encoded is normalized, where the dimension of the real vector to be encoded after normalization is 2 n ,n is the number of quantum bits of the target quantum circuit; Generate a Gray code queue according to the normalized real vector to be encoded; wherein the Gray code queue includes 2 n -1 Gray code; the last bit of the first Gray code in each round of generated Gray codes is 0, and the other bits are all 1; all bits of the last Gray code in each round of generated Gray codes are 1; all Gray codes in each round of generated Gray codes are different; According to the generation order of each Gray code in the Gray code queue, any two adjacent Gray codes are calculated to obtain the corresponding target XOR value; By using the quantum state coding algorithm to encode the normalized real vector to be encoded, R y Parameters of the door; The target quantum circuit is constructed according to the Gray code queue; wherein the target quantum circuit includes multiple X gates and R y gate, each X gate and each R y The gates are set alternately; the application position of each X gate is determined according to the target XOR value; each containing parameters R y The gate application position is determined according to each Gray code in the Gray code array; A target quantum state is obtained by evolving a target quantum circuit; wherein the normalized real vector to be encoded is mapped to the amplitude of the target quantum state.
2. The method according to claim 1, characterized in that The step of constructing a target quantum circuit according to a Gray code queue includes: According to the generation order of each Gray code in the Gray code queue, the corresponding controlled R y door, so that the adjacent controlled R y The Hamming distance between the effective control bits of the gates is 1.
3. The method according to claim 1, characterized in that The step of generating a Gray code queue according to the normalized real vector to be encoded includes: If n is greater than 1, the initial Gray code is recorded as 0; If h<2 m , invert the leftmost bit of the previous Gray code to generate the first current Gray code; where m is the number of Gray code bits in this round; h is the number of Gray codes generated in this round; or, If h<2 m , invert the right bit of the first 0 bit from the left of the previous Gray code to generate a second current Gray code; wherein the generation of the first current Gray code and the generation of the second current Gray code are performed alternately; If h=2 m , and m<n-1, increase the number of Gray code bits in the previous cycle by one to obtain the number of Gray code bits in this cycle; re-count the number of Gray codes generated in this cycle, let h=1, add a 0 bit to the end of the previous Gray code to generate the third current Gray code.
4. The method according to claim 1, characterized in that: The step of constructing a target quantum circuit according to the Gray code queue further includes: Initialize a quantum circuit; the initialized quantum circuit contains n quantum bits, and the initial state of the initialized quantum circuit is , n quantum bits are denoted from high to low ; In the quantum bit Apply a Door.
5. The method according to claim 1, characterized in that The step of constructing a target quantum circuit according to the Gray code queue further includes: If n ≥ 2, and the i-th bit from left to right in the target XOR value is 1, then in the quantum bit Apply an X gate on it; Determine the corresponding target Gray code in the Gray code queue according to the target XOR value; In the quantum bit Apply a controlled gate; where length represents the number of bits of the target Gray code, decimal represents the decimal number corresponding to the target Gray code, and quantum bit Is the control bit; controlled The gate has length control bits; Traverse all target XOR values to determine the application position of each X gate; Traverse all the target Gray codes to determine each controlled The location where the door is applied.
6. The method according to claim 5, characterized in that The target quantum state includes 2 n The target quantum state has a linear combination of 2 n Amplitude, 2 n The amplitudes correspond to the 2 of the real vector to be encoded. n elements.
7. A quantum state amplitude encoding device based on Gray code, characterized in that: include: A normalization module is used to normalize the real vector to be encoded, wherein the dimension of the real vector to be encoded after normalization is 2 n ,n is the number of quantum bits of the target quantum circuit; A generating module, which is used to generate a Gray code queue according to the normalized real vector to be encoded; wherein the Gray code queue includes 2 n -1 Gray code; the last bit of the first Gray code in each round of generated Gray codes is 0, and the other bits are all 1; all bits of the last Gray code in each round of generated Gray codes are 1; all Gray codes in each round of generated Gray codes are different; An XOR value module is used to calculate any two adjacent Gray codes according to the generation order of each Gray code in the Gray code queue to obtain a corresponding target XOR value; A computing module is used to encode the normalized real vector to be encoded by adopting a quantum state encoding algorithm to obtain R y Parameters of the door; A construction module is used to construct a target quantum circuit according to a Gray code queue; wherein the target quantum circuit includes a plurality of X gates and R y gate, each X gate and each R y The gates are set alternately; the application position of each X gate is determined according to the target XOR value; each containing parameters R y The gate application position is determined according to each Gray code in the Gray code array; An evolution module is used to obtain a target quantum state through evolution of a target quantum circuit; wherein the normalized real vector to be encoded is mapped to the amplitude of the target quantum state.
8. An electronic device, characterized in that: The electronic device comprises: a processor and a memory storing computer program instructions; when the electronic device executes the computer program instructions, the method according to any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Quantum state transformation method and device
CN113222150A
Quantum information preparation method and device, computer equipment and storage medium
CN117077796A