Quantum machine learning simulation method and system based on OpenMP parallel model
By using OpenMP parallel model to simulate and parallel acceleration of the HHL algorithm on classic multi-core computers, the large-scale experimental simulation problem of HHL algorithm in the existing technology is solved, and efficient linear equations of 4×4, 8×8 and 16×16 matrices are solved.
Patent Information
- Application Number
- CN202210927534.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-03
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2042-08-03
AI Technical Summary
The existing technology is difficult to effectively implement large-scale experimental simulation of HHL algorithms on real quantum computers, mainly because the number of qubits provided by existing quantum cloud platforms is insufficient, which limits the expansion of matrix scale.
Using the quantum machine learning simulation method based on OpenMP parallel model, the simulation of the HHL algorithm is realized through a high-level programming language on classic multi-core computers, and the linear equation solution of 4×4, 8×8 and 16×16 matrices is realized, and the algorithm is accelerated in parallel using parallel programming models.
It realizes parallel acceleration of HHL algorithms on classic computers, can effectively solve large-scale matrix linear equation systems, improves calculation efficiency, is highly applicable, and is convenient for practical scenario applications.
Smart Images

Figure CN115409187B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of quantum computing simulation, and in particular relates to a quantum machine learning simulation method and system based on an OpenMP parallel model. Background Art
[0002] Linear systems are at the core of many scientific and engineering fields. Today, many fields rely heavily on solving linear equations. In 2009, someone proposed using quantum algorithms to solve linear system equations. This algorithm is often called the HHL algorithm by researchers. It is often used in machine learning algorithms because problems in machine learning are ultimately related to solving optimization problems, which often involve solving linear equations. Because the HHL algorithm has a good exponential acceleration effect compared to classical algorithms under certain conditions, it has been widely used in data processing, numerical calculations, optimization problems and other fields.
[0003] With the rapid development of quantum technology, quantum computers designed based on the unique superposition and entanglement of quantum have attracted people's attention. Their powerful parallel capabilities have brought powerful computing power far beyond that of classical computers. However, since quantum computing is still in its infancy, based on this background, it is not yet fully possible to study algorithms on real quantum computers, so there are still few effective HHL practical applications and experimental implementations in the literature. Most simulations of the HHL algorithm are performed on quantum cloud platforms provided by companies such as IBM and Benyuan. The number of free and available quantum bits provided by the platform is insufficient to support large-scale experimental simulations. Therefore, the existing HHL algorithm experiments are relatively small in scale, basically concentrated in 2×2 matrices and 4×4 matrices, and the number of quantum bits required does not exceed 10 bits. Summary of the invention
[0004] To this end, the present invention provides a quantum machine learning simulation method and system based on the OpenMP parallel model, which uses a high-level programming language to implement algorithm simulation of HHL on a classical multi-core computer, can solve linear equations of 4×4, 8×8 and 16×16 matrices, can achieve relatively ideal quantum computing efficiency, has strong applicability, and is convenient for application in actual scenarios.
[0005] According to the design scheme provided by the present invention, a quantum machine learning simulation method based on the OpenMP parallel model is provided, which includes the following contents:
[0006] For the linear equation system of the coefficient matrix, a quantum simulator is constructed by mapping the input vector and the output vector into two quantum states and converting the solution of the linear equation system into the solution of the eigenvalue of the coefficient matrix, wherein the quantum expression in the quantum simulator is represented as: A|x>=|b>, wherein A is the coefficient matrix, b is the input vector, and x is the output vector;
[0007] The quantum simulator is deployed on a classical multi-core computer, and based on the OpenMP model and using the quantum machine learning algorithm, the hot spots in the algorithm code are analyzed to find and select the code modules to be parallelized, and the selected code modules to be parallelized are processed in parallel.
[0008] As a quantum machine learning simulation method based on the OpenMP parallel model in the present invention, further, in constructing a quantum simulator, first, the coefficient matrix is converted into a Hermitian matrix, and the spectral decomposition data of the coefficient matrix is constructed; then, the input vector b is expanded on the eigenvector of the coefficient matrix A and the output vector x is obtained.
[0009] As a quantum machine learning simulation method based on the OpenMP parallel model in the present invention, further, the spectral decomposition of the coefficient matrix is expressed as: A = ∑ j λ j |μ j ><μ j |, where |μ j > is the eigenvector of the coefficient matrix A, λ j is the eigenvalue corresponding to the eigenvector.
[0010] As a quantum machine learning simulation method based on the OpenMP parallel model in the present invention, further, the expansion of the input vector b is expressed as: |b>=∑ j β j |μ j >, the output vector x is represented as β j represents the characteristic ground state coefficient.
[0011] As a quantum machine learning simulation method based on the OpenMP parallel model of the present invention, further, in the quantum machine learning simulation solution operation, first, the quantum state of the input vector b is initialized, and the initial bit quantum state is decomposed into a superposition of eigenvector combinations of the coefficient matrix using phase estimation; then, using auxiliary quantum bits, the inverse of the eigenvalues of the eigenvectors is proportionally extracted to the probability of the corresponding ground state through a controlled rotation operation; finally, the inverse quantum phase estimation is used to offset the eigenvalues stored in the characteristic register, and the solution to the linear equation system is obtained by measuring the quantum bits.
[0012] As a quantum machine learning simulation method based on the OpenMP parallel model of the present invention, further, in the phase estimation, the quantum state of the input vector b is initialized, the coefficient matrix is prepared into a unitary operator through Hamiltonian simulation, and the unitary operator is used to act on the quantum state of the input vector b to decompose the quantum state into a linear combination superposition of the eigenvectors of the coefficient matrix.
[0013] As a quantum machine learning simulation method based on the OpenMP parallel model of the present invention, further, the process of using the inverse quantum phase estimation to offset the eigenvalue stored in the eigenregister is expressed as: Among them, |μ j > is the eigenvector of the coefficient matrix A, λ j is the eigenvalue corresponding to the eigenvector, β j represents the characteristic ground state coefficient, c represents the normalization constant, and the normalization process can be expressed as: c / λ j <1.
[0014] As a quantum machine learning simulation method based on the OpenMP parallel model of the present invention, further, for the quantum phase estimation in the quantum machine learning algorithm, first, the thread pool ThreadPool function is used to construct the controlled phase gate operation in the quantum phase estimation, and the tasks of constructing the controlled phase gate are added to the thread pool one by one through a loop, and the constructed phase gate circuit is saved by a locking operation.
[0015] As a quantum machine learning simulation method based on the OpenMP parallel model of the present invention, further, for the quantum machine learning algorithm, first, a loop code module for adding tasks to the thread pool is constructed according to the number of control bits, and the parallel code module is identified; then, multi-threading is used to enable the task execution in the thread pool to construct a controlled phase gate operation; finally, a for loop is used to perform inverse quantum Fourier parallel operations, H gates and phase gates are added to the circuit, and each parallel block in the inner loop code is iteratively allocated to each thread through task scheduling.
[0016] Furthermore, the present invention also provides a quantum machine learning simulation system based on the OpenMP parallel model, comprising: a simulator construction module and a parallel solution module, wherein:
[0017] A simulator building module, for building a quantum simulator for a linear equation system of a coefficient matrix by mapping an input vector and an output vector into two quantum states and by converting the solution of the linear equation system into the solution of the eigenvalue of the coefficient matrix, wherein the quantum expression in the quantum simulator is represented as: A|x>=|b>, wherein A is the coefficient matrix, b is the input vector, and x is the output vector;
[0018] The parallel solution module is used to deploy the quantum simulator on a classical multi-core computer. Based on the OpenMP model and using the quantum machine learning algorithm, it analyzes the hot spots in the algorithm code, finds and selects the code modules to be parallelized, and performs parallel computing on the selected code modules to be parallelized.
[0019] Beneficial effects of the present invention:
[0020] The present invention is based on a classical computer platform, uses the high-level programming language C++ to simulate the HHL algorithm, and uses the OpenMP parallel programming model to accelerate the algorithm in parallel, so as to realize the HHL algorithm simulation to solve the linear equations problem of 4×4, 8×8, and 16×16 matrices; and further uses the time comparison data of normal operation under a classical computer and after parallel acceleration to show that the parallel acceleration effect of the scheme in this case is good, which provides a reference for larger-scale matrix simulation and solution. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 This is a schematic diagram of the quantum machine learning simulation process based on the OpenMP parallel model in the embodiment;
[0022] Figure 2 The schematic diagram of the HHL algorithm in the embodiment;
[0023] Figure 3 This is a schematic diagram of the Fork-join execution model in the embodiment;
[0024] Figure 4 This is a schematic diagram of the task scheduling process in the embodiment;
[0025] Figure 5 Schematic diagram of the speedup ratio of matrices of different sizes under different numbers of cores in the embodiment. DETAILED DESCRIPTION
[0026] In order to make the purpose, technical solutions and advantages of the present invention clearer and more understandable, the present invention is further described in detail below in conjunction with the accompanying drawings and technical solutions.
[0027] Quantum computing has parallel computing capabilities that are difficult to match with classical computing technology due to its natural superposition and entanglement. Based on the powerful parallel capabilities of quantum computing, some known quantum algorithms can process problems faster than classical algorithms. However, at this stage, since the development of quantum computers is still in the development stage, the demand for algorithm experiments on quantum computers cannot be met. Therefore, quantum algorithms can be classically simulated on classical computers. The HHL (Hetero-Homogeneous Learning quantum machine learning) algorithm is often used to solve linear system equations. It is widely used in data processing, numerical calculation, optimization problems and other fields. For an embodiment of the present invention, see Figure 1 As shown, a quantum machine learning simulation method based on the OpenMP parallel model is provided, including:
[0028] S101. For a linear equation system of a coefficient matrix, a quantum simulator is constructed by mapping an input vector and an output vector into two quantum states and converting the solution of the linear equation system into the solution of the eigenvalue of the coefficient matrix, wherein the quantum expression in the quantum simulator is represented as: A|x>=|b>, wherein A is the coefficient matrix, b is the input vector, and x is the output vector;
[0029] S102. Deploy the quantum simulator on a classical multi-core computer, and based on the OpenMP model and using the quantum machine learning algorithm, find and select the code modules to be parallelized by analyzing the hot spots in the algorithm code, and perform parallel computing on the selected code modules to be parallelized.
[0030] On a classical computer, any quantum logic operation can be decomposed into a series of single-qubit logic operations and a combination sequence of double-qubit controlled NOT gates, and these single-qubit gates or double-qubit gates can be represented by matrices using high-level programming languages. Currently, commonly used tools include packaged packages such as libquantum and Qpanda2.0. These tools encapsulate the gates required in quantum computing through code for easy use. In the embodiment of this case, based on a classical computer platform, the HHL algorithm is simulated through the high-level programming language C++, and the OpenMP parallel programming model is used to accelerate the algorithm in parallel. The HHL algorithm can be used to simulate the solution of linear equations for 4×4, 8×8, and 16×16 matrices, which is convenient for application in actual scenarios.
[0031] As a preferred embodiment, further, in constructing a quantum simulator, first, the coefficient matrix is converted into a Hermitian matrix, and the spectral decomposition data of the coefficient matrix is constructed; then, the input vector b is expanded on the eigenvector of the coefficient matrix A and the output vector x is obtained.
[0032] If each row or column of the matrix A has at most s non-zero entries, then the linear system is called an s-sparse linear system. The time complexity required to solve the N-dimensional s-sparse linear system using the classical algorithm (conjugate gradient method) is Here κ represents the condition number of the system, and ∈ represents the accuracy of the approximation. When A is a Hermitian matrix, the time complexity of solving the linear equations using the HHL algorithm is The classic problem of solving linear equations is to input an N×N matrix A and an N-dimensional vector b, and output an N-dimensional vector x. We can assume that b and x are standardized and map them to quantum states |b> and |x>, whose quantum expressions are as follows:
[0033] A|x>=|b>
[0034] The algorithm has certain restrictions: the N×N matrix A must be a Hermitian matrix. If not, A needs to be converted into a Hermitian matrix in some way. Assume |μ j > is the eigenvector of A, λ j is its corresponding eigenvalue. According to the spectral decomposition theorem, each Hermitian matrix has a standard orthogonal basis of eigenvectors, so the spectral decomposition of matrix A can be expressed as A = ∑ j λ j |μ j ><μ j |.
[0035] For the input vector |b>, expanding on the eigenvector of matrix A, we can get |b>=∑ j β j |μ j >. The ideal end state is to obtain From this formula, we can see that the final output vector |x> is the inverse of the eigenvalue of matrix A added as a coefficient before the input vector |b>. Therefore, further formula conversion is required, A|μ j >=λ j |μ j >The expression From this formula and the expression of |b>, we can get:
[0036]
[0037] Therefore, it can be seen that the problem of solving the linear equations is transformed into solving the eigenvalue information of the matrix A. The three sub-processes of the HHL algorithm are: phase estimation, controlled rotation, and inverse phase estimation. The general steps are:
[0038] 1. The first step is to apply phase estimation to the initial bits, which is a general step to decompose quantum states on a specific basis. Initialize the quantum state |b> and prepare the coefficient matrix A into a unitary operator e by Hamiltonian simulation. iAt , applying the controlled operation U=e by the quantum phase estimation algorithm iAt Acting on |b>, |b> is decomposed into the superposition of the linear combination of the eigenvectors of A. After the phase estimation algorithm is applied, the state of |b> is ∑ j β j |μ j >, then the state of the entire system is ∑ j β j |μ j >.
[0039] 2. Perform a controlled rotation operation, the purpose of which is to In order to achieve this effect, an auxiliary qubit can be introduced here, according to |λ j >The value in the eigenvalue register, the state of the entire system after the controlled gate acts on the auxiliary qubit is:
[0040]
[0041] The controlled rotation operation realizes the transfer of effective quantum information from the register to the quantum state amplitude, and by adding quantum bits, the inverse of the eigenvalue is extracted proportionally to the probability radius of the corresponding ground state.
[0042] 3. Use the inverse quantum phase estimation method to offset the characteristic value stored in the register to obtain:
[0043]
[0044] The measurement on the first qubit gives |1>
[0045] If it is |0>, recalculate.
[0046] Since the HHL algorithm calculates the expected value of operators related to the solution, rather than the solution itself, the HHL algorithm has an exponential speedup compared to the classical algorithm. However, the classical algorithm can return an exact solution, while the HHL algorithm can only return an approximate solution. The expression result obtained in this solution is proportional to the solution of the linear equation system. At this time, we only need to measure the result with the additional bit |1>. The circuit diagram is as follows Figure 2 shown.
[0047] As a preferred embodiment, further, for quantum phase estimation in quantum machine learning algorithms, first, the thread pool ThreadPool function is used to construct the controlled phase gate operation in quantum phase estimation, and the tasks of constructing the controlled phase gate are added to the thread pool one by one through a loop, and the constructed phase gate circuit is saved by a locking operation. For quantum machine learning algorithms, first, a loop code module for adding tasks to the thread pool is constructed according to the number of control bits, and the parallel code module is identified; then, multithreading is used to enable the tasks in the thread pool to execute the controlled phase gate operation; finally, a for loop is used to execute the inverse quantum Fourier parallel operation, the H gate and the phase gate are added to the circuit, and each parallel block in the inner loop code is iteratively allocated to each thread through task scheduling.
[0048] Currently popular parallel programming models include OpenMP and MPI. The biggest difference between these two models is that OpenMP is a portable parallel programming model suitable for shared memory multi-processor architectures. It can only work on a single host and can make full use of multi-core CPUs to distribute parallel loads to computing cores through multi-threading to achieve acceleration. MPI is a tool for multi-host networked collaboration for parallel computing. It is suitable for distributed memory systems. It can coordinate parallel computing between multiple hosts and has strong scalability in parallel scale.
[0049] The basic idea of shared memory parallelism is to use multithreading. OpenMP can use the fork-join execution model, which is based on threads and uses compiler guidance statements to explicitly guide parallelization, that is, the main thread derives many child threads in the parallel region, and the main thread continues to execute after the parallel region ends. Its execution model is as follows Figure 3 As shown. After determining the code blocks suitable for parallelization, select the appropriate OpenMP compilation guidance instructions and runtime library functions to create a parallel program. The OPenMP application program interface consists of three parts: compilation guidance, runtime function library, and environment variables. The application programming interface can be used to implement task allocation and data sharing between threads, and the compiler automatically generates parallel programs suitable for parallel architecture by analyzing and discovering the parallelism contained in the serial program. When the compiler chooses to ignore the preprocessing instructions, or the compiler does not support OpenMP, the program degenerates into a serial program, and the code can still operate normally.
[0050] At the beginning of an OpenMP program, the main thread executes serially until it encounters the first parallel domain, which is when it starts to execute in parallel. A parallel domain means that this part of the program is computationally intensive and requires multiple processors to work together to improve efficiency and running speed.
[0051] First, analyze the algorithm code and determine the modules suitable for parallelization. The main source of parallelism in OpenMP is the loop structure. After locating the modules suitable for parallelization, it is necessary to properly manage the private and public data in the algorithm, because multithreading runs asynchronously. When multiple threads operate on the same data, the data will be different under the action of multiple threads, resulting in unknowable results. Therefore, care should be taken to avoid competition between thread data that may lead to calculation errors, and synchronize the data source when enabling multithreading. Finally, if the determined code section is independent and will not cause calculation errors due to thread competition, you can try to select the code block as the parallel processing part for parallel experiments, and compare the parallel effect of this part through experimental results.
[0052] In OpenMP, parallelism is achieved by inserting compilation guidance instructions into serial code. Its general format is the #pragma omp instruction. Common OpenMP instructions are shown in Table 1:
[0053] Table 1 OpenMP parameter description
[0054]
[0055]
[0056] Commonly used library functions of OpenMP are shown in Table 2:
[0057] Table 2 Description of OpenMP library functions
[0058]
[0059] The goal of this case is to simulate the HHL algorithm on a classical multi-core computer and perform multi-threaded parallel processing. Therefore, the QPanda2.0 quantum software development toolkit can be used to simulate the specific implementation of the algorithm through the C++ high-level programming language, and the algorithm can be improved through OpenMP to achieve parallel acceleration, shorten the simulation time of the HHL algorithm, improve simulation efficiency, and determine the feasibility of simulating quantum algorithms on classical computers.
[0060] First, a simulation experiment is conducted on the 4×4 linear equation system. For the 4×4 linear equation system, the coefficient matrix A is selected as:
[0061]
[0062] The b vector is:
[0063] (0.5 0.5 0.5 0.5) T
[0064] It can also be achieved through Indicates that For this linear equation, the exact classical solution can be calculated as:
[0065]
[0066] The Qpanda2.0 quantum programming framework supports most quantum logic gate operations and quantum circuit construction operations in quantum computing. On this basis, the HHL algorithm will be simulated and hot spot analysis will be performed on the algorithm to find code blocks that can be run in parallel and implement parallel operations of the algorithm. The pseudo code design of the HHL algorithm can be shown as follows:
[0067] 1. Input: A, b
[0068] 2.Output: result
[0069] 3.auto machine=initQuantumMachine(CPU);
[0070] 4.auto prog = QProg();
[0071] 5.QCircuit circuit=CreateEmptyCircuit();
[0072] 6.QCircuit< <QPE();
[0073] 7.QCircuit< <build_CR();
[0074] 8.QCircuit< <QPE_Inverse();
[0075] 9.QCircuit hhl_circuit=HHL_circuit(A,b,machine);
[0076] 10.result = x;
[0077] 11.Return result;
[0078] The three modules of the HHL algorithm are constructed through code, namely quantum phase estimation, controlled rotation, and inverse quantum phase estimation. After the HHL algorithm circuit is constructed, the three modules of the algorithm are analyzed and the parts that can be accelerated are determined.
[0079] The phase estimation part is as follows:
[0080] 1.QCircuit QPE(Qubit*control,Qubit*target)
[0081] 2.
[0082] 3.QCircuit qpe_cir;
[0083] 4.qpe_cir< <apply_QGate(control,H)<<
[0084] 5.control_unitary(Qubit*Control)<<
[0085] 6.QFT_Inverse();
[0086] 7.}
[0087] This part mainly consists of three parts: Hadamard transform, controlled phase transform and quantum inverse Fourier transform. After analysis, it is found that the two stages that consume more time are the controlled phase transform and quantum inverse Fourier transform, so we try to improve the codes of these two stages.
[0088] First, we operate on the controlled phase part in quantum phase estimation. The operation of constructing the controlled phase gate in the code uses the thread pool ThreadPool function. The purpose of this operation is to realize multi-threaded concurrency in the future. The thread pool serves a large number of operations through several fixed threads, reducing the time required to create and destroy threads and improving efficiency. The tasks of constructing the phase gate are added to the thread pool one by one through a loop. When each thread task in the thread pool is executed, a locking operation is used when saving the constructed circuit. The constructed phase gate circuit can add the phase gate of each part to the circuit in sequence in subsequent operations. The measured results are as follows:
[0089] (-0.0542 0.3801 0.5974 0.7051) T
[0090] The fidelity calculated from the theoretical value and the measured value is 96.73%. The entire program runs on a classic 8-core computer and takes 928.16ms. This is because the process simulates a 4×4 matrix, which is not large in size and can be constructed using 7 quantum bits in the quantum gimbal, so the time consumption is not too large.
[0091] The code blocks of the algorithm are modified and analyzed, and the part of adding tasks to the thread pool is improved. Because before the execution of the tasks in the thread pool is completed, a locking method is used when saving the line operation to ensure that the constructed phase gate line is saved correctly. This means that even if all tasks are added to the thread pool through multi-threading through parallel operations, the line construction order will not be disrupted.
[0092] According to the number of control bits, a for loop can be constructed to add tasks to the thread pool. The parallel program block can be identified by using pragma ompparallel for. Through multithreading, the tasks in the thread pool can be constructed to perform controlled phase gate operations, and no additional synchronization operations are added to the code. After testing the code, it is found that compared with the serial code execution, the order in which the tasks enter the thread pool has changed, and the execution order has become disordered. However, since each task is passed an index parameter formulated according to the control bit position when entering the thread pool, and the line saving operation is locked, and finally all the saved lines are sorted, these constructions can still be constructed in the correct order. Therefore, the result is still the same as the approximate solution obtained before, and the time is 263.34ms.
[0093] Then, parallel operations are designed for the inverse quantum Fourier. The inverse quantum Fourier consists of two parts: Hadamard transform and phase transform. Through two layers of for loops, the H gate and phase gate are added to the circuit respectively. When the loop is executed, the circuit construction is also completed. When constructing the circuit, first design parallel operations for the two layers of for loops at the same time, and do not add synchronization operations to the parallel process. The result obtained in this case is:
[0094] (2.962 3.492 6.195 8.097) T
[0095] Each time the result is different and there is a big discrepancy with the expected result. After analysis, it is found that the condition value of the inner loop in the code depends on the condition value of the outer loop. Therefore, after parallelization, the inner loop will have errors, which will cause problems in the construction of the controlled phase gate, which will lead to errors in the calculation results. So the code is improved next. Because the amount of tasks executed by the inner loop is large, the inner loop can be operated in parallel. In the inner loop, the task is scheduled through pragma ompparallel for schedule. Its working principle is as follows: Figure 4 As shown in the figure, the iterations are dynamically assigned to each thread, and finally the correct approximate solution is obtained. The time after parallelization is 236.57ms, which proves that the parallel operation is effective and correct.
[0096] Furthermore, based on the above method, an embodiment of the present invention also provides a quantum machine learning simulation system based on the OpenMP parallel model, comprising: a simulator construction module and a parallel solution module, wherein:
[0097] A simulator building module, for building a quantum simulator for a linear equation system of a coefficient matrix by mapping an input vector and an output vector into two quantum states and by converting the solution of the linear equation system into the solution of the eigenvalue of the coefficient matrix, wherein the quantum expression in the quantum simulator is represented as: A|x>=|b>, wherein A is the coefficient matrix, b is the input vector, and x is the output vector;
[0098] The parallel solution module is used to deploy the quantum simulator on a classical multi-core computer. Based on the OpenMP model and using the quantum machine learning algorithm, it analyzes the hot spots in the algorithm code, finds and selects the code modules to be parallelized, and performs parallel computing on the selected code modules to be parallelized.
[0099] In order to verify the effectiveness of this solution, the following is a further explanation based on the test data:
[0100] The first measured serial program running time on 8 cores was 928.16ms, and the accelerated time was 236.57ms. Then the time after parallel operation on 2 cores, 4 cores, and 6 cores was tested respectively. The results are shown in Table 3:
[0101] Table 3 4×4 matrix running time
[0102]
[0103] After many tests, it was found that the execution time of the program built with the OpenMP framework was not much different when it was executed under 6 cores and 8 cores. This is because the program can satisfy the execution of all allocated threads under 6 cores.
[0104] The 4×4 matrix was simulated on a classical computer, and the experimental results of the program implementing multi-threading through OpenMP were measured, achieving correct simulation and parallel acceleration of quantum algorithms on classical computers. Compared with the 4×4 matrix implemented on the quantum cloud platform, the circuit depth of the HHL algorithm built on a classical computer is larger. The circuit based on the 4×4 matrix needs 976 gates to simulate on a classical computer, while the circuit depth of the 4×4 matrix implemented on the quantum cloud platform is 353, which is 1 / 3 of the circuit simulation on classical computing. It can be seen that circuit simulation on a classical computer consumes a lot of memory. Next, experiments with 8×8 matrices and 16×16 matrices were carried out according to the above method. The result of the normal operation of 8×8 is 1781.39ms. The results after parallel operation are shown in Table 4:
[0105] Table 4 8×8 matrix running time
[0106]
[0107] At the same time, the gates required for the decomposition of the 8×8 matrix are recorded as 7250. The simulation result for the 16×16 matrix is 3232.84ms. The results after parallel operation are shown in Table 5:
[0108] Table 5 16×16 matrix running time
[0109]
[0110] After testing, it was found that for a 16×16 matrix, after multithreading was enabled, the acceleration effect was not very obvious as the number of cores increased. After analysis, it was concluded that a single 8-core computer could no longer handle the matrix decomposition task, because for the decomposition of a 16×16 matrix, the number of gates required to decompose the matrix to build the circuit reached 35039, and the task of building a controlled phase gate also reached 12. When the number of threads is greater than the number of computer cores, because the number of threads running at the same time can only be equal to the number of cores, the other threads become concurrent, which wastes more time on thread switching. By comparing the three sets of matrix simulations, the running time obtained is, for example, Figure 4 As shown. It is found that as the scale of matrix simulation increases, its acceleration effect will gradually decrease. This is because when performing quantum computing simulation on a classical computer, the time and space overhead required increases exponentially with the growth of the number of simulated bits. As the scale of the simulated matrix becomes larger and larger, the number of simulated quantum bits also increases, and the amount of tasks to be processed increases. The memory and processor of a single computer will not be able to meet the simulation. Therefore, based on a larger scale of classical simulation of quantum algorithms, it can be processed by computer clusters. For example, MPI and accelerated thread libraries are used to simulate quantum Fourier transforms on supercomputers on a large scale, making full use of the potential of multi-core CPUs and distributed architectures to achieve the simulation and optimization of 46-bit quantum Fourier algorithms; CPU-GPU heterogeneous cluster technology can be used to achieve multi-bit quantum computing simulation, and the effectiveness and scalability of the simulation system are proved by the classical simulation of the QFT algorithm. By further using cluster distributed storage to amortize exponential storage overhead and computing requirements, the memory and time bottleneck problems of quantum computing simulation can be solved. It can be seen that by building a distributed computer system, a larger scale of algorithm simulation can be achieved.
[0111] Unless otherwise specifically stated, the relative steps, numerical expressions and values of the components and steps set forth in these embodiments do not limit the scope of the present invention.
[0112] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the system disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0113] The units and method steps of each example described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. A person of ordinary skill in the art may use different methods to implement the described functions for each specific application, but such implementation is not considered to be beyond the scope of the present invention.
[0114] Those skilled in the art will appreciate that all or part of the steps in the above method can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium, such as a read-only memory, a disk or an optical disk. Optionally, all or part of the steps in the above embodiment can also be implemented using one or more integrated circuits, and accordingly, each module / unit in the above embodiment can be implemented in the form of hardware or in the form of software function modules. The present invention is not limited to any specific form of combination of hardware and software.
[0115] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims
1. A quantum machine learning simulation method based on the OpenMP parallel model, characterized in that: Contains the following: For the linear equation system of the coefficient matrix, a quantum simulator is constructed by mapping the input vector and the output vector into two quantum states and converting the solution of the linear equation system into the solution of the eigenvalue of the coefficient matrix, wherein the quantum expression in the quantum simulator is represented as: A|x>=|b>, wherein A is the coefficient matrix, b is the input vector, and x is the output vector; The quantum simulator is deployed on a classical multi-core computer. Based on the OpenMP model and using the quantum machine learning algorithm, the hot spots in the algorithm code are analyzed to find and select the code modules to be parallelized, and the selected code modules to be parallelized are processed in parallel. For the quantum phase estimation in the quantum machine learning algorithm, first, the thread pool ThreadPool function is used to construct the controlled phase gate operation in the quantum phase estimation, and the tasks of constructing the controlled phase gate are added to the thread pool one by one through a loop, and the constructed phase gate circuit is saved by a locking operation; and in the quantum machine learning algorithm, first, a loop code module for adding tasks to the thread pool is constructed according to the number of control bits, and the code modules to be parallelized are identified; then, multithreading is used to enable the tasks in the thread pool to execute the constructed controlled phase gate operation; finally, the for loop is used to execute the inverse quantum Fourier parallel operation, the H gate and the phase gate are added to the circuit, and the parallel blocks in the inner loop code are iteratively allocated to each thread through task scheduling.
2. The quantum machine learning simulation method based on the OpenMP parallel model according to claim 1, characterized in that: In constructing a quantum simulator, first, the coefficient matrix is converted into a Hermitian matrix, and the spectral decomposition data of the coefficient matrix is constructed; then, the input vector b is expanded on the eigenvector of the coefficient matrix A and the output vector x is obtained.
3. The quantum machine learning simulation method based on the OpenMP parallel model according to claim 2, characterized in that: The spectral decomposition of the coefficient matrix is expressed as: A = ∑ j λ j |μ j ><μ j |, where |μ j > is the eigenvector of the coefficient matrix A, λ j is the eigenvalue corresponding to the eigenvector.
4. The quantum machine learning simulation method based on the OpenMP parallel model according to claim 3 is characterized in that: The expansion of the input vector b is expressed as: |b> = ∑ j β j |μ j >, the output vector x is represented as β j represents the characteristic ground state coefficient.
5. The quantum machine learning simulation method based on the OpenMP parallel model according to claim 1, characterized in that: In the quantum machine learning simulation solution operation, first, the quantum state of the input vector b is initialized, and the phase estimation is used to decompose the initial bit quantum state into a superposition of eigenvector combinations of the coefficient matrix; then, using the auxiliary quantum bit, the inverse of the eigenvalue of the eigenvector is extracted proportionally to the probability of the corresponding ground state through a controlled rotation operation; finally, the inverse quantum phase estimation is used to offset the eigenvalue stored in the feature register, and the solution to the linear equations is obtained by measuring the quantum bit.
6. The quantum machine learning simulation method based on the OpenMP parallel model according to claim 5, characterized in that: In phase estimation, the quantum state of the input vector b is initialized, the coefficient matrix is prepared into a unitary operator through Hamiltonian simulation, and the unitary operator is used to apply quantum phase estimation to the quantum state of the input vector b, decomposing the quantum state into a linear combination superposition of the eigenvectors of the coefficient matrix.
7. The quantum machine learning simulation method based on the OpenMP parallel model according to claim 5, characterized in that: The process of using the inverse quantum phase estimate to cancel the eigenvalue stored in the eigenregister is expressed as: Among them, |μ j > is the eigenvector of the coefficient matrix A, λ j is the eigenvalue corresponding to the eigenvector, β j represents the characteristic ground state coefficient, and c represents the normalization constant.
8. A quantum machine learning simulation system based on the OpenMP parallel model, characterized in that: Contains: simulator building module and parallel solution module, among which, A simulator building module, for building a quantum simulator for a linear equation system of a coefficient matrix by mapping an input vector and an output vector into two quantum states and by converting the solution of the linear equation system into the solution of the eigenvalue of the coefficient matrix, wherein the quantum expression in the quantum simulator is represented as: A|x>=|b>, wherein A is the coefficient matrix, b is the input vector, and x is the output vector; The parallel solution module is used to deploy the quantum simulator on a classical multi-core computer. Based on the OpenMP model and using the quantum machine learning algorithm, the hot spots in the algorithm code are analyzed to find and select the code modules to be parallelized, and the selected code modules to be parallelized are processed in parallel. For the quantum phase estimation in the quantum machine learning algorithm, first, the thread pool ThreadPool function is used to construct the controlled phase gate operation in the quantum phase estimation, and the tasks of constructing the controlled phase gate are added to the thread pool one by one through a loop, and the constructed phase gate circuit is saved by a locking operation; and in the quantum machine learning algorithm, first, a loop code module for adding tasks to the thread pool is constructed according to the number of control bits, and the code modules to be parallelized are identified; then, multithreading is used to enable the tasks in the thread pool to execute the constructed controlled phase gate operation; finally, a for loop is used to execute the inverse quantum Fourier parallel operation, the H gate and the phase gate are added to the circuit, and each parallel block in the inner loop code is iteratively allocated to each thread through task scheduling.
Citation Information
Patent Citations
Quantum computing simulation platform and linear equation set quantum solving simulation method and system
CN112232512A
Radar sparse imaging method based on quantum machine learning
CN113238224A