Quantum circuit simulation method and device suitable for multi-GPU system
By building communication channels and dynamic segmentation qubit planning in a multi-GPU environment, quantum circuit simulation is realized, and the problems of insufficient single GPU resources and adaptability of multi-GPU environments are solved, and the simulation efficiency and performance are improved.
Patent Information
- Application Number
- CN202411164533.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-23
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2044-08-23
AI Technical Summary
The existing quantum circuit simulation technology has limited computing resources in a single GPU environment and cannot adapt to multi-GPU environments. It lacks data transmission and switching mechanisms between GPUs, making it difficult to simulate large-scale quantum circuits.
By building a communication channel between GPUs, dynamic segmentation qubit planning is used to segment the initial state vector of the quantum system and initialize it to each GPU, implementing parallel execution of quantum circuit simulation operations, and efficient data exchange through the NCCL library to build multi-GPUs Supported quantum gate operation sequences to obtain the final state vector.
In a multi-GPU environment, the quantum circuit simulation efficiency is significantly improved, the single-machine GPU storage limitations are overcome, the cross-GPU data exchange needs are reduced, information transmission is accelerated, and analog performance is enhanced.
Smart Images

Figure CN119005352A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of quantum computing technology, specifically to the field of quantum circuit simulation, and more specifically to a quantum circuit simulation method and device suitable for a multi-GPU system. Background Art
[0002] Quantum computing, a revolutionary technology based on the principles of quantum mechanics, is rapidly emerging in the global scientific research field. It encodes and processes information through quantum bits, and uses unique phenomena such as quantum superposition and quantum entanglement to achieve efficient parallel operations on information. Quantum algorithms, such as Shor's factorization algorithm and Grover's search algorithm, have proven that quantum computing has a significant speed improvement over traditional computing methods when dealing with certain types of problems. With the continuous advancement of technology, quantum computing has shown its potential huge application value in many fields such as materials science, cryptography, and combinatorial optimization.
[0003] At present, quantum computing is still in the so-called "noisy intermediate-scale quantum (NISQ) era". In this stage, quantum circuit simulation has become an important tool for researchers to verify the correctness and effectiveness of quantum algorithms and quantum systems. Quantum circuit simulation involves representing the state of a quantum system in the form of a complex vector, the length of which grows exponentially with the number of quantum bits. During the simulation process, by continuously multiplying the state vector with the unitary matrix corresponding to each quantum gate in the quantum circuit, the evolution of the state of the quantum system can be gradually derived until the final quantum state is obtained. Despite the many challenges, the development prospects of quantum computing are exciting, and it is expected to open a new chapter in the field of computing for us.
[0004] As the number of quantum bits increases, the amount of computation required for quantum circuit simulation will grow exponentially. In a single-machine environment, the existing quantum circuit simulation technology can no longer meet the simulation time and resource requirements for large-scale quantum circuits. Existing quantum circuit simulation technology usually uses state vectors to simulate quantum circuits, and only considers the functional implementation of quantum system state vectors and quantum gate matrix operations. As the scale of quantum circuits increases, a single CPU or GPU is difficult to meet the computational requirements of large-scale quantum circuit simulation, and existing quantum circuit simulation technology usually does not consider how to perform quantum circuit simulation calculations on multiple GPUs. On the one hand, in a multi-GPU environment, due to the difficulty of storing the state vector of the quantum system in the same memory space, the quantum states that each GPU can access are incomplete, and existing quantum computing simulation methods cannot perform simulation calculations. On the other hand, how the quantum state vector is transmitted and exchanged between GPUs is also not considered by existing quantum computing simulation technology. With the development of quantum computing, the number of quantum bits in quantum computers is also increasing. The scale of existing quantum computers has reached more than one hundred quantum bits, and quantum circuit simulation technology also needs to face increasing challenges.
[0005] In summary, existing quantum circuit simulation methods have the following problems: 1) Computing resources are limited in a single GPU environment: the dimension of the state vector of a quantum system grows exponentially with the number of quantum bits, resulting in the inability of the memory and computing power of a single GPU environment to meet the needs of simulating large-scale quantum circuits. 2) Quantum circuit simulation in a multi-GPU environment cannot be used: in a multi-GPU environment, the state vector of the quantum system is difficult to store in the same memory space, and the state vectors contacted on each GPU are incomplete, resulting in the inability of existing simulation methods to adapt to a multi-GPU environment. 3) Lack of data transmission and exchange mechanism between GPUs: Existing quantum circuit simulation methods do not consider the data exchange mechanism in a multi-GPU environment. Therefore, there is an urgent need for a method for simulating large-scale quantum circuits suitable for multi-GPU systems.
[0006] It should be noted that this background technology is only used to introduce the relevant information of the present invention to help understand the technical solution of the present invention, but it does not mean that the relevant information is necessarily the prior art. If there is no evidence that the relevant information has been disclosed before the application date of the present invention, the relevant information shall not be regarded as the prior art. Summary of the invention
[0007] Therefore, the purpose of the present invention is to overcome the above-mentioned defects of the prior art and provide a quantum circuit simulation method and device suitable for a multi-GPU system.
[0008] The objective of the present invention is achieved through the following technical solutions:
[0009] According to a first aspect of the present invention, the present invention proposes a quantum circuit simulation method suitable for a multi-GPU system, which is used to simulate the operation process of a quantum circuit on a specified quantum system to obtain a final state vector of the quantum system. The method comprises: step S1, obtaining the number of GPUs and building a communication channel between GPUs, obtaining all quantum bits of the quantum circuit to be simulated, the order of the quantum bits, a quantum gate operation sequence, and an initial state vector of the specified quantum system, wherein the quantum gate operation sequence comprises a plurality of quantum gate operation layers arranged in an orderly manner, each quantum gate operation layer comprises a plurality of quantum gate operations that can be executed in parallel, and each quantum gate operation acts on one or more quantum bits; step S2, selecting a plurality of split quantum bits for splitting the initial state vector of the quantum system for each quantum gate operation layer from all the quantum bits of the quantum circuit by a preset method, so as to construct a dynamic split quantum bit planning; step S3, based on the dynamic split quantum bit planning, for each quantum bit acting on the split quantum bit quantum gate operation, adding GPU data exchange operation between every two consecutive quantum gate operation layers with different split quantum bits, and converting all quantum gate operations into quantum gate operations supported by multiple GPUs, and constructing a quantum circuit simulation operation sequence with all GPU data exchange operations and all quantum gate operations supported by multiple GPUs; step S4, based on the split quantum bits of the first quantum gate operation layer in the quantum circuit, evenly splitting the initial state vector of the specified quantum system to each GPU to initialize the state vector in each GPU, and executing all operations in the quantum circuit simulation operation sequence in parallel in each GPU to update the state vector thereon, wherein each GPU uses a preset data exchange method to perform data exchange operations between the current GPU and other GPUs when executing the quantum gate operation acting on the split quantum bits; step S5, collecting the updated state vectors in all GPUs, and rearranging them according to the order of the quantum bits in the quantum circuit to obtain the final state vector of the quantum system.
[0010] Preferably, the communication channel between the GPUs is constructed based on the NCCL library.
[0011] Preferably, in step S2, the preset method is to select a split quantum bit for each quantum gate operation layer from all the quantum bits of the quantum circuit through the following steps: step S21, configuring the split cost of each quantum gate operation according to the amount of data exchange and the amount of calculation required for different types of quantum gate operations to act on the split quantum bit, wherein the greater the amount of data exchange and the amount of calculation, the greater the split cost; step S22, based on the split costs configured for different quantum gate operations in step S21, obtaining the split cost of each quantum bit in the quantum circuit to be simulated when it is selected as a split quantum bit in each quantum gate operation layer, wherein the split cost of a quantum bit in a quantum gate operation layer is the split cost of all quantum gate operations acting on the quantum bit in the quantum gate operation layer. The sum of the split costs; step S23, dividing all quantum gate operation layers into multiple quantum gate operation layer intervals, wherein each quantum gate operation layer interval contains multiple consecutive quantum gate operation layers, and the split quantum bits of each quantum gate operation layer are the same; step S24, for every two consecutive quantum gate operation layer intervals, calculating the sum of the split cost of the second quantum gate operation interval and the first preset threshold, and the split cost when the split quantum bits of the second quantum gate operation interval are the same as the split quantum bits of the first quantum gate operation interval, and comparing the two values. If the former is less than or equal to the latter, then updating the split quantum bits of all quantum gate operation layers in the second quantum gate operation layer interval to the same split quantum bits as the quantum gate operation layers in the first quantum gate operation layer interval.
[0012] Preferably, the step S23 comprises: step S231, based on all the quantum bits in the quantum circuit, dividing into a plurality of quantum bit groups containing different quantum bits, wherein each quantum bit group contains different quantum bits, is the number of GPUs; step S232, for each quantum bit group, use the quantum bits in the quantum bit group as the split quantum bits of all quantum gate operation layers, calculate the split cost of each quantum gate operation layer, and accumulate the split cost of each quantum gate operation layer layer by layer according to the order of the quantum gate operation layers. Under the condition that the accumulated value is less than a preset threshold, find the interval containing the most quantum gate operation layers, and obtain the number of quantum gate operation layers in the interval and the quantum gate operation layers contained in the interval, wherein the split cost of each quantum gate operation layer is the sum of the split costs of all split quantum bits of the quantum gate operation layer; step S233, divide the interval corresponding to the quantum bit group with the largest number of quantum gate layers into a quantum gate operation interval, and use the quantum bits in the quantum bit group as the split quantum bits of all quantum gate operation layers in the quantum gate operation interval; step S234, based on the remaining quantum gate operation layers in the quantum gate operation sequence, repeat steps S231 to S233 until all quantum gate operation layers are divided.
[0013] Preferably, the GPU data exchange operation includes: a full data exchange operation, which is an operation of exchanging all state vectors in the current GPU with all state vectors in other GPUs; a half data exchange operation, which is an operation of exchanging the first half of the state vector of the current GPU with the second half of the state vector of other GPUs, or exchanging the second half of the state vector of the current GPU with the first half of the state vector of other GPUs; a quarter data exchange operation, which is an operation of dividing the state vector of the current GPU into four equal parts, selecting three of them to exchange data with the state vectors of three GPUs in other GPUs respectively; a data exchange operation according to quantum bits, which is an operation of selecting the state vectors to be exchanged and performing data exchange according to the quantum bit information of the current GPU and other GPUs to be exchanged.
[0014] Preferably, the state vector of each GPU is initialized in the following manner: Based on the split quantum bits of the first quantum gate operation layer, the split quantum bit states mapped on each GPU are initialized in the following manner:
[0015]
[0016]
[0017] in, Indicates the GPU serial number, Indicates the serial number is The split qubit states mapped on the GPU, The value of is the number of split quantum bits minus 1, Represents a binary string formed by splicing the state of each split quantum bit, wherein the serial number of the GPU is equal to the decimal value corresponding to the binary string formed by splicing the state of the split quantum bits mapped on the GPU, and the state of each split quantum bit is 1 or 0; for each GPU, obtain the partial state vectors of the initial state vector of the specified quantum system that are the same as the state of the split quantum bits mapped on the GPU and extract the state vectors of other quantum bits except the split quantum bits as the state vector of the GPU, so as to initialize the state vector of each GPU.
[0018] Preferably, the preset data exchange method is configured as follows: obtaining a portion of the state vector of the current GPU that requires data exchange and a target GPU for data exchange, and obtaining the portion of the state vector that transmits it to the target GPU; transmitting the portion of the state vector of the target GPU that requires data exchange to the current GPU, and storing the state vector transmitted from the current GPU; performing a quantum gate operation on the current GPU to update the quantum state vector, extracting a portion of the state vector transmitted from the target GPU from the updated quantum state vector and returning it to the target GPU, and returning the state vector of the current GPU stored in the target GPU to the current GPU.
[0019] According to a second aspect of the present invention, the present invention proposes a quantum circuit simulation device for implementing any method as described in any one of the first aspects of the present invention, for simulating the operation process of a quantum circuit on a specified quantum system to obtain a final state vector of the quantum system, the device comprising: a communication module for performing data exchange operations between GPUs through a communication channel constructed based on an NCCL library; a quantum system state vector segmentation module for selecting from all quantum bits of the quantum circuit to be simulated for the quantum gate operation layer A split quantum bit with the smallest splitting cost for splitting the initial state vector of the quantum system is used to build a dynamic split quantum bit plan; a quantum circuit simulation module is used to build a quantum circuit simulation operation sequence including all GPU data exchange operations and all quantum gate operations supported by multiple GPUs, as well as to initialize the state vector on the GPU, and execute the quantum circuit simulation operation sequence in parallel on all GPUs to update the state vector on each GPU; a state vector integration module collects the updated state vectors in all GPUs and sorts them based on the order of the quantum bits in the quantum circuit to be simulated to obtain the final state vector of the quantum device.
[0020] According to a third aspect of the present invention, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program can be executed by a processor to implement the steps of the method described in any one of the first aspect or the second aspect of the present invention.
[0021] According to a fourth aspect of the present invention, the present invention proposes an electronic device, comprising: one or more processors; and a memory, wherein the memory is used to store executable instructions; the one or more processors are configured to implement the steps of the method described in any one of the first aspect or the second aspect of the present invention by executing the executable instructions.
[0022] Compared with the prior art, the advantages of the present invention are:
[0023] The solution of the present invention realizes the execution of quantum circuit simulation tasks in a multi-GPU environment, overcomes the limitations of a single GPU in storing large-scale quantum circuit state vectors, and significantly improves the simulation efficiency. In this method, a specific algorithm is used to split the dynamic quantum bit plan with the minimum cost, and the state vector is reasonably distributed to each GPU, reducing the need for cross-GPU data exchange. In addition, the efficient communication channel constructed by the NCCL library further accelerates the information transmission between GPUs, thereby enhancing the simulation performance of quantum circuits. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The embodiments of the present invention are further described below with reference to the accompanying drawings, in which:
[0025] Figure 1 This is a flow chart of a quantum circuit simulation method applicable to a multi-GPU system according to an embodiment of the present invention;
[0026] Figure 2 is a program flow chart of a quantum circuit simulation method applicable to a multi-GPU system according to an embodiment of the present invention;
[0027] Figure 3 A structure diagram of a quantum circuit simulation device suitable for a multi-GPU system according to an embodiment of the present invention;
[0028] Figure 4 FIG. 4 is a structural diagram of another quantum circuit simulation device suitable for a multi-GPU system according to an embodiment of the present invention. DETAILED DESCRIPTION
[0029] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail by specific embodiments below. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0030] As mentioned in the background technology section, existing quantum circuit simulation methods have the following problems: 1) Computing resources are limited in a single GPU environment: the dimension of the state vector of a quantum system grows exponentially with the number of quantum bits, resulting in the inability of a single GPU environment to simulate large-scale quantum circuits in terms of memory and computing power. 2) Quantum circuit simulation in a multi-GPU environment is not possible: in a multi-GPU environment, the state vector of a quantum system is difficult to store in the same memory space, and the state vectors contacted on each GPU are incomplete, resulting in the inability of existing simulation methods to adapt to a multi-GPU environment. 3) Lack of data transmission and exchange mechanisms between GPUs: Existing quantum circuit simulation methods do not consider data exchange mechanisms in a multi-GPU environment.
[0031] To solve these problems, the present invention proposes a quantum circuit simulation scheme suitable for a multi-GPU system. In this scheme, the initial state vector of the quantum system is divided into each GPU, and the operation sequence of the quantum circuit is executed in parallel in the GPU to update the state vector on each GPU. Finally, the state vector of each GPU is collected and reordered to obtain the final state vector of the quantum system, thereby simulating a large-scale quantum circuit on a multi-GPU system. In addition, in view of the problem that the data exchange operations between a large number of GPUs in the multi-GPU system simulation affect the efficiency of quantum circuit simulation, the scheme of the present invention constructs a dynamic quantum split bit plan with a small amount of data exchange and a small amount of calculation, and thereby constructs a quantum gate operation sequence for quantum circuit simulation, thereby reducing the data exchange operations between GPUs, wherein, when the initial state vector of the quantum system is split, a dynamic split quantum bit plan with the minimum splitting cost is constructed and thereby the state vector of the quantum system is split to each GPU; further, in view of the lack of an efficient data transmission mechanism between GPUs in the existing quantum circuit simulation method, the present invention constructs a communication channel between GPUs based on NCCL, and proposes a data exchange operation based on the communication channel to realize a variety of efficient communication methods between GPUs.
[0032] Before specifically introducing the embodiments of the present invention, some of the terms used therein are explained as follows:
[0033] NCCL (NVIDIA Collective Communications Library): NVIDIA Collective Communications Library. NCCL is a high-performance communication library designed for parallel computing applications using NVIDIA GPUs to achieve efficient data transmission and communication. It supports multiple communication methods, such as point-to-point (send / receive), broadcast, reduce, and reduce-scatter.
[0034] The present invention is described in detail below with reference to the accompanying drawings and embodiments.
[0035] In summary, the present invention proposes a quantum circuit simulation method suitable for a multi-GPU system, which is used to simulate the operation process of a quantum circuit on a specified quantum system to obtain the final state vector of the quantum system. The flow chart of the method is as follows: Figure 1As shown, it includes: step S1, obtaining the number of GPUs and building a communication channel between GPUs, obtaining all quantum bits of the quantum circuit to be simulated, the order of the quantum bits, the quantum gate operation sequence and the initial state vector of the specified quantum system, wherein the quantum gate operation sequence includes a plurality of quantum gate operation layers arranged in order, each quantum gate operation layer includes a plurality of quantum gate operations that can be executed in parallel, and each quantum gate operation acts on one or more quantum bits; step S2, selecting a plurality of split quantum bits for splitting the initial state vector of the quantum system for each quantum gate operation layer from all the quantum bits of the quantum circuit by a preset method, so as to build a dynamic split quantum bit plan; step S3, based on the dynamic split quantum bit plan, adding GPU data exchange for each quantum gate operation acting on the split quantum bit and between each two consecutive quantum gate operation layers with different split quantum bits The method further comprises the steps of: performing a quantum circuit simulation operation on each GPU based on the quantum gate operation of the first quantum gate operation layer in the quantum circuit, performing a quantum gate operation on each GPU, performing a quantum gate operation on each GPU, performing a quantum gate operation on each GPU, performing a quantum gate operation on each GPU, performing a quantum gate operation on each GPU, performing a quantum gate operation on each GPU, performing a quantum gate operation on each GPU, performing a quantum gate operation on each GPU, performing a quantum gate operation on each GPU, performing a quantum gate operation on each GPU, performing a quantum gate operation on each GPU using a preset data exchange method, and performing a quantum gate operation on each GPU. The method further comprises the steps of: collecting the updated state vectors in all GPUs, and rearranging them in the order of the quantum bits in the quantum circuit, so as to obtain the final state vector of the quantum system.
[0036] In order to better understand the present invention, each step is described in detail below in conjunction with specific embodiments.
[0037] According to one embodiment of the present invention, in the step S1, a communication channel between GPUs is constructed in the following manner: a data transmission channel between N GPUs in a multi-GPU system is constructed based on the NCCL library, wherein the communication channel between GPUs allows efficient data exchange between multiple GPUs, which is used to provide method support for quantum state data exchange between multiple GPUs during quantum circuit simulation. The present invention provides 8 data communication modes: point-to-point (send / receive), broadcast, reduce, reduce scatter, global reduce, scatter, gather, and global gather. It should be understood that the data communication modes listed here are exemplary and not exhaustive, and the data communication modes are not limited to the above 8 types, and other data communication modes that can realize quantum state data exchange operations are all possible.
[0038] According to one embodiment of the present invention, step S2 includes: step S21, configuring the splitting cost of each quantum gate operation according to the amount of data exchange and the amount of calculation required for different types of quantum gate operations to act on the split quantum bit, wherein the greater the amount of data exchange and the amount of calculation, the greater the splitting cost; step S22, based on the splitting costs configured for different quantum gate operations in step S21, obtaining the splitting cost of each quantum bit in the quantum circuit to be simulated when it is selected as a split quantum bit in each quantum gate operation layer, wherein the splitting cost of a quantum bit in a quantum gate operation layer is the sum of the splitting costs of all quantum gate operations acting on the quantum bit in the quantum gate operation layer; step S23, adding all quantum gates to the splitting cost of each quantum bit in the quantum circuit to be simulated. The operation layer is divided into a plurality of quantum gate operation layer intervals, wherein each quantum gate operation layer interval contains a plurality of continuous quantum gate operation layers, and the split quantum bits of each quantum gate operation layer are the same; step S24, for each two continuous quantum gate operation layer intervals, the sum of the split cost of the second quantum gate operation interval and the first preset threshold value, and the split cost when the split quantum bits of the second quantum gate operation interval are the same as the split quantum bits of the first quantum gate operation interval are calculated, and the numerical values of the two are compared. If the former is less than or equal to the latter, the split quantum bits of all quantum gate operation layers in the second quantum gate operation layer interval are updated to the same split quantum bits as the quantum gate operation layers in the first quantum gate operation layer interval. By executing the above steps S21-S24, dynamic quantum bit planning can be constructed.
[0039] According to an implementation of the present invention, in step S21, when configuring the splitting cost of each quantum gate operation according to the amount of data exchange and the amount of calculation required for the quantum gate operation to act on the split quantum bit, the configuration can be performed in the following manner:
[0040] 1) For a general quantum gate matrix, when it acts on a split quantum bit, it is necessary to exchange data of half of the quantum state vector between GPUs that have state vectors corresponding to the states 0 and 1 of the quantum bits it acts on, and the splitting cost is configured as 2;
[0041] 2) For the diagonal quantum gate matrix, when it acts on the split quantum bits, no additional data exchange operation is required, and the split cost is configured as 0;
[0042] 3) For the inverse diagonal quantum gate matrix, when it acts on the split quantum bit, the GPUs with the state vectors of the quantum bit state 0 and state 1 need to exchange data of all state vectors. This quantum gate operation avoids data exchange between GPUs by adjusting the GPU sequence number, and its splitting cost is configured as 0.5;
[0043] 4) For the measurement quantum gate and reset quantum gate operations, when they act on split quantum bits, it is necessary to add measurement data exchange and merging operations to calculate the final measurement result of the quantum state. Its split generation configuration is 1;
[0044] 5) For other quantum gate matrices, when they act on splitting quantum bits, it is necessary to add state vector exchange operations between GPUs based on quantum bits, and the splitting cost is configured as 3.
[0045] It should be understood that the splitting cost of each type of quantum gate operation configuration described above is only one of the specific embodiments, and those skilled in the art can modify the splitting cost of each type of quantum gate to obtain other embodiments.
[0046] According to one implementation of the present invention, in step S22, the splitting cost of each quantum bit in the quantum circuit to be simulated when it is selected as a split quantum bit is obtained in the following manner: based on the splitting costs of different types of quantum gates, the splitting costs of all quantum bits in the quantum circuit to be simulated in the splitting quantum bits are calculated, wherein the splitting cost corresponding to each quantum bit at each quantum gate operation layer is the sum of the splitting costs of all quantum gate operations acting on the quantum bit in the quantum gate operation layer. The splitting cost of each quantum bit when it is selected as a split quantum bit at each quantum gate operation layer can be obtained in the above manner, and based on all the obtained splitting costs, a splitting cost table D can be constructed, wherein the number of columns is the number of quantum bits contained in the quantum circuit and the number of rows is the number of quantum gate operation layers of the quantum circuit, wherein each element D in the table ij (i represents row, j represents column) represents the splitting cost when the j-th quantum bit is selected as the quantum splitting bit on the i-th quantum gate operation layer.
[0047] According to one embodiment of the present invention, step S23 includes: step S231, based on all the quantum bits in the quantum circuit, dividing into a plurality of quantum bit groups containing different quantum bits, wherein each quantum bit group contains different quantum bits, is the number of GPUs; step S232, for each quantum bit group, the quantum bits in the quantum bit group are used as the split quantum bits of all quantum gate operation layers, the split cost of each quantum gate operation layer is calculated, and the split cost of each quantum gate operation layer is accumulated layer by layer according to the order of the quantum gate operation layers. Under the condition that the accumulated value is less than a preset threshold, the interval containing the most quantum gate operation layers is found, and the number of quantum gate operation layers in the interval and the quantum gate operation layers contained in the interval are obtained, wherein the split cost of each quantum gate operation layer is the sum of the split costs of all split quantum bits of the quantum gate operation layer, and the split cost of each quantum bit in each quantum gate operation layer is obtained by querying the constructed split cost table; step S233, the interval corresponding to the quantum bit group with the largest number of quantum gate layers is divided into a quantum gate operation interval, and the quantum bits in the quantum bit group are used as the split quantum bits of all quantum gate operation layers in the quantum gate operation interval; step S234, based on the remaining quantum gate operation layers in the quantum gate operation sequence, steps S231 to S233 are repeated until all quantum gate operation layers are divided. The above steps S231 to S234 are performed to divide all quantum gate operation layers into a plurality of quantum gate operation layer intervals.
[0048] According to one embodiment of the present invention, in step S231, the number of quantum bit groups divided is , that is, selecting without replacement from all the qubits contained in the quantum circuit There are many ways to select qubits, among which, represents the number of quantum bits contained in the quantum circuit, The calculation formula is as follows:
[0049]
[0050] According to one embodiment of the present invention, in step S3, constructing a quantum circuit simulation operation sequence includes: 1) converting all quantum gate operations into quantum gate operations supported by multiple GPUs. 2) adding GPU data exchange operations for each quantum gate operation acting on a split quantum bit and between each two consecutive quantum gate operation layers with different split quantum bits. The GPU data exchange operation in the quantum circuit simulation operation sequence is used to process the data exchange operation between GPUs when the quantum gate operation acts on the split quantum bit or the split quantum bit changes to realize the simulation of quantum circuits on a multi-GPU system. It should be understood that converting quantum gate operations into quantum gate operations supported by multiple GPUs is a well-known technology for those skilled in the art and will not be elaborated on in detail here.
[0051] According to one embodiment of the present invention, in step S3, the data exchange operation between the GPUs includes a full data exchange operation, a half data exchange operation, a quarter data exchange operation, a bit-based data exchange operation and a measurement data exchange merging operation, wherein the full data exchange operation is an operation of exchanging all state vectors in the current GPU with all state vectors in other GPUs; the half data exchange operation is an operation of exchanging the first half of the state vector of the current GPU with the second half of the state vector of other GPUs, or exchanging the second half of the state vector of the current GPU with the first half of the state vector of other GPUs; the quarter data exchange operation is an operation of dividing the state vector of the current GPU into four equal parts, selecting three of them to exchange data with the state vectors of three GPUs in other GPUs respectively; the data exchange operation based on quantum bits is an operation of selecting the state vectors to be exchanged and performing data exchange according to the quantum bit information of the current GPU and other GPUs to be exchanged; the measurement data exchange merging operation is a data merging operation using global reduction to merge the quantum state measurement results in all GPUs into the data exchange operation in the current GPU. The present invention provides a variety of data exchange modes for dynamic selection according to the required data volume when simulating quantum circuits, effectively controlling the amount of data transmission each time, reducing the time consumption of data transmission and improving the efficiency of quantum circuit simulation.
[0052] According to one embodiment of the present invention, in step S4, the state vector of each GPU is initialized as follows: the split quantum bit state mapped on each GPU is initialized based on the split quantum bits of the first quantum gate operation layer, wherein the split quantum bit state mapped on each GPU is expressed as:
[0053]
[0054]
[0055] in, Indicates the GPU serial number, Indicates the serial number is The split qubit states mapped on the GPU, The value of is the number of split quantum bits minus 1, Represents a binary string formed by splicing the state of each split quantum bit, wherein the serial number of the GPU is equal to the decimal value corresponding to the binary string formed by splicing the state of the split quantum bits mapped on the GPU, and the state of each split quantum bit is 1 or 0; for each GPU, obtain the partial state vectors of the initial state vector of the specified quantum system that are the same as the state of the split quantum bits mapped on the GPU and extract the state vectors of the other quantum bits except the split quantum bits as the state vector of the GPU, so as to initialize the state vector of each GPU.
[0056] To more clearly understand the process of initializing the state vector on each GPU, an example is provided below.
[0057] Assume that the quantum circuit has 10 qubits (Q0…Q9), the multi-GPU system has 4 GPUs (GPU0, GPU1, GPU2, GPU3), the split qubits of the first quantum gate operation layer of the quantum circuit are Q0 and Q1, and the state vector initialized on each GPU is GPU0 =
[00] [00000000,…,111111111], GPU1 =
[01] [00000000,…,111111111], GPU2 =
[10] [00000000,…,111111111], GPU3 =
[11] [00000000,…,111111111], where the serial number of each GPU is equal to the decimal value corresponding to the binary state of the split quantum bit, that is, the state of the split quantum bit corresponding to GPU0 is
[00] . The initial quantum state vector on each GPU is the state vector of the remaining quantum bits in the initial state vector of the quantum system whose state of the split quantum bit is equal to its GPU serial number. For example, the state vector corresponding to GPU0 is the decimal value corresponding to the binary state of the split quantum bits Q0 and Q1, which is equal to 0. The state vectors of all the remaining quantum bits (Q2~Q9) in the initial state vector of the quantum system, that is, the initial state vector on GPU0 is, when the split quantum bit Q0Q1=00, all the state vectors corresponding to (Q2…Q9)∈(00000000~11111111).
[0058] According to one embodiment of the present invention, in step S4, after initializing the state vector on each GPU, all operations in the quantum circuit simulation operation sequence are executed in parallel in each GPU to update the state vector thereon. Wherein, when performing quantum gate operations in the quantum circuit simulation operation sequence, a quantum gate matrix multiplication algorithm is selected according to the properties of the quantum gate operation to perform each quantum gate operation, wherein the quantum gate matrix multiplication algorithm includes: general quantum gate matrix multiplication, diagonal quantum gate matrix multiplication, inverse diagonal quantum gate matrix multiplication, single-bit control quantum gate matrix multiplication, quantum gate matrix multiplication containing control bits, and special double-bit quantum gate matrix multiplication. It should be understood that the quantum gate matrix multiplication algorithms listed here are exemplary and not exhaustive, and other quantum gate matrix multiplication algorithms that can be used to perform quantum gate operations are all acceptable.
[0059] According to one embodiment of the present invention, in step S4, when all operations in the quantum circuit simulation operation sequence are executed in parallel in each GPU, the data exchange operation between GPUs in the quantum circuit simulation operation sequence is performed in the following manner: a partial state vector of the state vector of the current GPU that needs to be exchanged with data and a target GPU for data exchange are obtained, and the partial state vector is obtained and transmitted to the target GPU; the portion of the state vector of the target GPU that needs to be exchanged with data is transmitted to the current GPU, and the state vector transmitted from the current GPU is stored; a quantum gate operation is performed on the current GPU to update the quantum state vector, a partial state vector transmitted from the target GPU is extracted from the updated quantum state vector and returned to the target GPU, and the state vector of the current GPU stored in the target GPU is returned to the current GPU.
[0060] According to one embodiment of the present invention, in step S4, after all operations in the quantum circuit simulation operation sequence are executed in parallel in each GPU, the updated state vectors in all GPUs are collected and rearranged according to the order of the quantum bits in the quantum circuit to obtain the final state vector of the quantum system.
[0061] According to one embodiment of the present invention, the program flow corresponding to the quantum circuit simulation method applicable to a multi-GPU system proposed by the present invention is as follows: Figure 2 As shown, the program flow shown in the figure includes:
[0062] 1) Initialize the communication channel between multiple GPUs;
[0063] 2) Input quantum circuit and the number of GPUs required;
[0064] 3) According to the input quantum circuit and the number of GPUs, the optimal split quantum bits are selected and a series of quantum circuit simulation operations are generated, including quantum gate matrix multiplication operations and quantum state data exchange operations;
[0065] 4) Launch multi-GPU quantum circuit simulators in parallel with multiple processes, each process corresponding to a graphics processing unit (GPU);
[0066] 5) According to the split quantum bits, the corresponding partial quantum state vector is constructed in each GPU;
[0067] 6) Traverse the quantum circuit simulation operation series, obtain and execute quantum circuit simulation operations, where for data exchange operations, obtain the corresponding quantum state vector and target GPU information, send the quantum state data to be exchanged to the target GPU, and wait for the data to be returned to update the state vector on the GPU, and perform matrix multiplication operations with the quantum gate matrix representing the quantum gate operation and the state vector on the GPU to update the state vector;
[0068] 7) Wait for all processes to complete the operation and summarize the state vectors in all GPUs;
[0069] 8) Reorder the summarized quantum state vector according to the order of the quantum bits in the quantum circuit;
[0070] 9) Output the final quantum system state vector. According to one embodiment of the present invention, the present invention proposes a quantum circuit simulation device for implementing the quantum circuit simulation method applicable to a multi-GPU system, the structure of which is as follows: Figure 3 As shown, it includes: a communication module, which is used to build a communication channel based on the NCCL library and perform data exchange operations between GPUs; a quantum system state vector segmentation module, which is used to select from all the quantum bits of the quantum circuit to be simulated for the quantum gate operation layer A split quantum bit with the smallest splitting cost for splitting the initial state vector of the quantum system is used to build a dynamic split quantum bit plan; a quantum circuit simulation module is used to build a quantum circuit simulation operation sequence including all GPU data exchange operations and all quantum gate operations supported by multiple GPUs, as well as to initialize the state vector on the GPU, and execute the quantum circuit simulation operation sequence in parallel on all GPUs to update the state vector on each GPU; a state vector integration module collects the updated state vectors in all GPUs and sorts them based on the order of the quantum bits in the quantum circuit to be simulated to obtain the final state vector of the quantum device.
[0071] According to another embodiment of the present invention, the present invention provides a quantum circuit simulation device for implementing the quantum circuit simulation method applicable to a multi-GPU system. The structure of the device is as follows: Figure 4As shown, it includes: a communication module, which is used to build a communication channel based on the NCCL library and perform data exchange operations between GPUs; a quantum circuit construction module: used to generate quantum circuits, which can be customized to generate quantum circuits containing any number of quantum bits and any type of quantum gates; a quantum system state vector segmentation module, which is used to select quantum gate operation layers from all quantum bits of the quantum circuit to be simulated. A split quantum bit with the smallest splitting cost for splitting the initial state vector of the quantum system is used to build a dynamic split quantum bit plan; a quantum circuit simulation module is used to build a quantum circuit simulation operation sequence including all GPU data exchange operations and all quantum gate operations supported by multiple GPUs, as well as to initialize the state vector on the GPU, and execute the quantum circuit simulation operation sequence in parallel on all GPUs to update the state vector on each GPU; a state vector integration module collects the updated state vectors in all GPUs and sorts them based on the order of the quantum bits in the quantum circuit to be simulated to obtain the final state vector of the quantum device.
[0072] In order to make the beneficial effects of the present invention clearer, the inventors designed a comparative experiment to evaluate the performance of the quantum circuit simulation method proposed in the present invention. The comparative experiment configuration is: using a single GPU quantum circuit simulation method in a single GPU environment and using the quantum circuit simulation method for a multi-GPU system proposed in the present invention to simulate the same quantum circuit in a dual GPU environment, and counting the time required for the quantum circuit simulation method to simulate the same quantum circuit. The experimental results are shown in Table 1. The data in the table show that as the number of quantum bits increases, the quantum circuit simulation method for a multi-GPU system proposed in the present invention is significantly shorter in required time than the traditional single GPU quantum circuit simulation method, which confirms that the present invention has significant advantages in large-scale quantum circuit simulation efficiency.
[0073] Table 1 Experimental results
[0074] The number of qubits contained in the quantum circuit Single GPU environment simulation time (s) Environment simulation time of two GPUs (s) 25 0.163 0.198 28 1.42 1.12 30 6.12 4.43
[0075] It should be noted that although the above describes the various steps in a specific order, it does not mean that the various steps must be executed in the above specific order. In fact, some of these steps can be executed concurrently or even in a different order as long as the required functions can be achieved.
[0076] The present invention may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present invention.
[0077] A computer-readable storage medium may be a tangible device that holds and stores instructions used by an instruction execution device. Computer-readable storage media may include, for example, but are not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination thereof. More specific examples (non-exhaustive list) of computer-readable storage media include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a protruding structure in a groove on which instructions are stored, and any suitable combination thereof.
[0078] The embodiments of the present invention have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A quantum circuit simulation method suitable for a multi-GPU system, used to simulate the operation process of a quantum circuit on a specified quantum system to obtain the final state vector of the quantum system, characterized in that: The method comprises: Step S1, obtaining the number of GPUs and building communication channels between GPUs, obtaining all quantum bits of the quantum circuit to be simulated, the order of the quantum bits, the quantum gate operation sequence, and the initial state vector of the specified quantum system, wherein the quantum gate operation sequence includes a plurality of quantum gate operation layers arranged in order, each quantum gate operation layer includes a plurality of quantum gate operations that can be executed in parallel, and each quantum gate operation acts on one or more quantum bits; Step S2, selecting a plurality of split quantum bits for splitting the initial state vector of the quantum system from all the quantum bits of the quantum circuit for each quantum gate operation layer using a preset method, so as to construct a dynamic split quantum bit plan; Step S3: Based on the dynamic split quantum bit planning, a GPU data exchange operation is added for each quantum gate operation acting on the split quantum bit and between each two consecutive quantum gate operation layers with different split quantum bits, and all quantum gate operations are converted into quantum gate operations supported by multiple GPUs, and a quantum circuit simulation operation sequence is constructed with all GPU data exchange operations and all quantum gate operations supported by multiple GPUs; Step S4, based on the split quantum bits of the first quantum gate operation layer in the quantum circuit, the initial state vector of the specified quantum system is evenly split to each GPU to initialize the state vector in each GPU, and all operations in the quantum circuit simulation operation sequence are executed in parallel in each GPU to update the state vector thereon, wherein each GPU uses a preset data exchange method to perform data exchange operations between the current GPU and other GPUs when executing the quantum gate operation acting on the split quantum bits; Step S5: collect the updated state vectors in all GPUs and rearrange them according to the order of the quantum bits in the quantum circuit to obtain the final state vector of the quantum system.
2. The method according to claim 1, characterized in that The communication channel between the GPUs is built based on the NCCL library.
3. The method according to claim 1, characterized in that: In step S2, the preset method is to select split quantum bits for each quantum gate operation layer from all quantum bits of the quantum circuit through the following steps: Step S21, configuring the splitting cost of each quantum gate operation according to the amount of data exchange and the amount of calculation required for different types of quantum gate operations to split the quantum bits, wherein the greater the amount of data exchange and the amount of calculation, the greater the splitting cost; Step S22, based on the splitting costs configured for different quantum gate operations in step S21, obtaining the splitting cost of each quantum bit in the quantum circuit to be simulated when it is selected as a splitting quantum bit in each quantum gate operation layer, wherein the splitting cost of a quantum bit in a quantum gate operation layer is the sum of the splitting costs of all quantum gate operations acting on the quantum bit in the quantum gate operation layer; Step S23, dividing all quantum gate operation layers into a plurality of quantum gate operation layer intervals, wherein each quantum gate operation layer interval includes a plurality of continuous quantum gate operation layers, and the divided quantum bits of each quantum gate operation layer are the same; Step S24: for every two consecutive quantum gate operation layer intervals, calculate the sum of the segmentation cost of the second quantum gate operation interval and the first preset threshold, and the segmentation cost when the segmentation quantum bits of the second quantum gate operation interval are the same as the segmentation quantum bits of the first quantum gate operation interval, and compare the two values. If the former is less than or equal to the latter, update the segmentation quantum bits of all quantum gate operation layers in the second quantum gate operation layer interval to the same segmentation quantum bits as those of the quantum gate operation layers in the first quantum gate operation layer interval.
4. The method according to claim 3, characterized in that The step S23 comprises: Step S231: Based on all the quantum bits in the quantum circuit, a plurality of quantum bit groups containing different quantum bits are divided, wherein each quantum bit group contains Different quantum bits, is the number of GPUs; Step S232: for each quantum bit group, the quantum bits in the quantum bit group are used as the split quantum bits of all quantum gate operation layers, the split cost of each quantum gate operation layer is calculated, and the split cost of each quantum gate operation layer is accumulated layer by layer according to the order of the quantum gate operation layers. Under the condition that the accumulated value is less than a preset threshold, the interval containing the most quantum gate operation layers is found, and the number of quantum gate operation layers in the interval and the quantum gate operation layers contained therein are obtained, wherein the split cost of each quantum gate operation layer is the sum of the split costs of all split quantum bits of the quantum gate operation layer; Step S233, dividing the interval corresponding to the quantum bit group with the largest number of quantum gate layers into a quantum gate operation interval, and using the quantum bits in the quantum bit group as the split quantum bits of all quantum gate operation layers in the quantum gate operation interval; Step S234: based on the remaining quantum gate operation layers in the quantum gate operation sequence, repeat steps S231 to S233 until all quantum gate operation layers are divided.
5. The method according to claim 1, characterized in that The GPU data exchange operation includes: A full data exchange operation is an operation of exchanging all state vectors in the current GPU with all state vectors in other GPUs; A half data exchange operation is an operation of exchanging the first half of the state vector of the current GPU with the second half of the state vector of another GPU, or exchanging the second half of the state vector of the current GPU with the first half of the state vector of another GPU; A quarter data exchange operation is an operation of dividing the state vector of the current GPU into four equal parts, selecting three of the four parts to exchange data with the state vectors of three GPUs in other GPUs respectively; According to the data exchange operation of quantum bits, it is an operation of selecting the state vectors to be exchanged and performing data exchange according to the quantum bit information of the current GPU and other GPUs to be exchanged.
6. The method according to claim 1, wherein in step S3, the state vector of each GPU is initialized in the following manner: Based on the split qubits of the first quantum gate operation layer, the split qubit states mapped on each GPU are initialized as follows: in, Indicates the GPU serial number, Indicates the serial number is The split qubit states mapped on the GPU, The value of is the number of split quantum bits minus 1, Represents a binary string formed by splicing the states of each split quantum bit, where the serial number of the GPU is equal to the decimal value corresponding to the binary string formed by splicing the states of the split quantum bits mapped on the GPU, and the state of each split quantum bit is 1 or 0; For each GPU, a partial state vector of the initial state vector of the specified quantum system that is identical to the split quantum bit state mapped on the GPU is obtained, and the state vectors of other quantum bits except the split quantum bits are extracted therefrom as the state vector of the GPU, so as to initialize the state vector of each GPU.
7. The method according to claim 1, characterized in that The preset data exchange method is configured as follows: Obtaining a portion of the state vector of the current GPU that needs to be exchanged with data and a target GPU for data exchange, and obtaining a portion of the state vector to transmit it to the target GPU; The part of the state vector of the target GPU that needs to be exchanged is transferred to the current GPU, and the state vector transferred from the current GPU is stored; A quantum gate operation is performed on the current GPU to update the quantum state vector, a partial state vector transmitted from the target GPU is extracted from the updated quantum state vector and returned to the target GPU, and the state vector of the current GPU stored in the target GPU is returned to the current GPU.
8. A quantum circuit simulation device for implementing the method according to any one of claims 1 to 7, for simulating the operation process of a quantum circuit on a specified quantum system to obtain the final state vector of the quantum system, characterized in that: The device comprises: The communication module is used to build a communication channel based on the NCCL library and perform data exchange operations between GPUs; The quantum system state vector segmentation module is used to select the quantum gate operation layer from all the quantum bits of the quantum circuit to be simulated. A split qubit with the minimum splitting cost for splitting the initial state vector of the quantum system to construct a dynamic split qubit plan; A quantum circuit simulation module, used to construct a quantum circuit simulation operation sequence including all GPU data exchange operations and all quantum gate operations supported by multiple GPUs, initialize the state vector on the GPU, and execute the quantum circuit simulation operation sequence in parallel on all GPUs to update the state vector on each GPU; The state vector integration module collects the updated state vectors in all GPUs and sorts them based on the order of quantum bits in the quantum circuit to be simulated to obtain the final state vector of the quantum device.
9. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and the computer program can be executed by a processor to implement the steps of the method according to any one of claims 1 to 7.
10. An electronic device, characterized in that: include: one or more processors; as well as A memory, wherein the memory is used to store executable instructions; The one or more processors are configured to implement the steps of the method of any one of claims 1 to 7 by executing the executable instructions.
Citation Information
Patent Citations
Information processing method and device based on quantum system
CN115577792A
Super-computing-oriented quantum search simulation method and system
CN116227615A
A quantum computing simulation method providing software development kit by using quantum library and a server performing thereof
KR102696749B1
Systems and methods for optimizing quantum circuit simulation using graphics processing units
WO2023177846A1
