{'fraction_non_alphanumeric': 0.025099293909973522, 'fraction_numerical': 0.009763901147396293, 'mean_word_length': 4.684854186265287, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
HHL Analysis and Simulation Verification Based on Origin Quantum Platform

Solving large-scale linear equations is of great significance in many engineering fields, such as weather forecasting and bioengineering. The classical computer solves the linear equations, no matter adopting the elimination method or Kramer’s rule, the time required for solving is in a polynomial relationship with the scale of the equation system. With the advent of the era of big data, the integration of transistors is getting higher and higher. When the size of transistors is close to the order of electron diameter, quantum tunneling will occur, and Moore’s Law will not be followed. Therefore, the traditional computing model will not be able to meet the demand. In this paper, through an in-depth study of the classic HHL algorithm, a small-scale quantum circuit model is proposed to solve a 2×2 linear equations, and the circuit diagram and programming are used to simulate and verify on the Origin Quantum Platform. The fidelity under different parameter values reaches more than 90%. For the case where the matrix to be solved is a sparse matrix, the quantum algorithm has an exponential speed improvement over the best known classical algorithm.


Introduction
The quantum era has arrived. Linear equations, as one of the most important content in linear algebra, play an important role in many fields, so it is very important to solve large-scale linear equations. However, regardless of whether Gaussian elimination or Kramer's rule is used to solve linear equations on a traditional classical computer, the solution time is in a polynomial relationship with the dimension of the equation. With the advent of the era of big data, the growth rate of data has reached an unprecedented level [1], and traditional computers have certain difficulties in processing large-scale data. Therefore, the current situation puts forward higher requirements for us.
In response to this situation, quantum computing bears the brunt, it is currently one of the hottest and best solutions. As we all know, quantum computing is naturally capable of parallel computing due to its superposition, entanglement and reversibility. Compared with the parallel computing capability of classical computers, it has incomparable advantages in multi-machine parallel, multi-thread parallel and instruction level parallel. An N-bit classic register can only store a certain number of bits from 0 to 2 N -1, while in a quantum computer, the number of N-bit quantum registers in the super imposed state is all the numbers from 0 to 2 N -1, which exist at the same time with certain probability [2]. Therefore, one N-bit quantum register can simultaneously store 2 N N-bit binaries. When individuals operate on N qubits, in principle, it means that operate on 2 N states simultaneously [2]. The linear increase in the number of bits in the quantum register causes the storage space to increase exponentially. This is the 2 basic feature of quantum computing memory cells and the premise that quantum computing speed can greatly exceed the classic computing speed [3].
According to the erasure theorem, in an irreversible process, the heat is closely related to the scale of the irreversible operation: The higher the integration, the more heat is generated per unit area [4]. The quantum computer based on the basic principles of quantum mechanics, and the information processing process is unitary transformation, so the reversibility of unitary transformation makes quantum information processing process does not bring heat. Therefore, quantum computing can theoretically solve the problem of high energy consumption, another key technology of modern information processing.
The structure of this paper is as follows: The first part introduces the background and significance of quantum computing. In the second part, the HHL quantum algorithm for solving linear equations is discussed in detail, and its solution idea, main algorithm framework and complexity advantage over classical algorithm are analyzed. In the third part, combining the practical characteristics of the Origin Quantum Platform, the specific case in this HHL algorithm is simulated by means of circuit diagram and programming. The last part is the summary of this paper and the prospect of the follow-up work.

HHL quantum algorithm principle
Aram W. Harrow, Avinatan Hassidim and Seth Lloyd explicitly proposed a quantum algorithm for solving linear equations [5], which solves such a problem: In Ax = b, if an Hermite N×N matrix A and a unit vector b are given, one solve for x satisfying the above equation. Equivalently, one can convert the problem to solve x = A −1 b. Since matrix A is an invertible matrix, this equation must have a unique set of solutions.
First, the N×N matrix A has to be an Hermitian matrix (the conjugate transposed matrix of A is equal to itself). Secondly, the input vector b is a normalized quantum state b . When the matrix A is not an Hermitian matrix, individuals convert the matrix A into an Hermitian matrix by construction as follows: At this time, the constructed matrix  A will be changed from a general matrix to an Hermitian matrix, and subsequent paper will only consider the case where matrix A is an Hermitian matrix.
will be found, and x at this time is the solution of the linear equations. Since the quantum state used to store the linear equation vector information must be normalized, the input information of the quantum linear equations algorithm is not a strict vector b, but a normalized quantum state b proportional to the vector b. Therefore, the vector b of the linear equations should be converted to b , which can be converted through It is worth noted that the HHL quantum algorithm finally solved a quantum state containing x information. That is, the HHL quantum algorithm could not directly solve the size of x, but could only obtain a global characteristic about x. Therefore, the result x differs from the solution of the original problem by a normalized constant. However, for many real-world applications, individuals don't need to get the exact value of x directly, just the overall properties. In addition, the normalized constant can also be obtained by means of amplitude estimation in the case that exact value is required. Therefore, HHL quantum algorithm is worth considered when it is necessary to solve large-scale linear equations without requiring the exact value of output directly. In order to make the problem more clear, the process of HHL quantum algorithm is first analyzed in detail. For the Hermitian matrix A, one express it as the spectral decomposition of the N×N Hermitian matrix:  is the eigenvector of matrix A , and j  is the eigenvalue corresponding to matrix A.
For the input quantum state b , if expand it on the eigenvector j  of the matrix A, one can get: The equation of x can be obtained from the above equations: It can be found that the required output vector x is actually the input vector b with a corresponding reciprocal of the eigenvalue of the matrix A as a coefficient before each of its eigenvectors. Therefore, the purpose of solving linear equations can be transformed into how to obtain the information of these eigenvalues and add them to the corresponding eigenvectors [6]. The specific implementation of the algorithm can be divided into the following three subroutines: Phase Estimation(PE), Controlled Rotation(CR), and Inverse Phase Estimation(PE −1 ) [7]. The quantum circuit of this algorithm is shown in Fig.1, with the first, second and third registers from top to bottom.

Fig. 1 Quantum circuit of HHL algorithm
The quantum algorithm includes three registers: an auxiliary qubit register with the initial state of 0 , a register containing n qubits with the initial state of 0 , and a register with the initial state of b .
The first subroutine, Phase Estimation, is analyzed.
Step 1 is the preparation of the initial state. The first register is the auxiliary register and its initial state is 0 . The second register is a working register, and its initial state is 0 as well, and it contains n qubits. Here, n is the number of unknowns in linear equations. The third register is initialized to b . Then, the coefficient matrix A of linear equations is prepared into unitary matrix by e −iAt0 . At this point, the joint initial state of the entire system is .
Step 2 is the Phase Estimation operation. The purpose of this operation is to extract the eigenvalues of the coefficient matrix A. One express the eigenvector of the coefficient matrix A as j  , then j  represents the eigenvalue corresponding to the matrix A.
Firstly, the eigenvalues of matrix A are extracted into the probability amplitude of the quantum state of the second register by H gate and controlled unitary matrix. And then the phases of the probability amplitude are extracted by the inverse Quantum Fourier Transform (QFT −1 ) and placed into the ground state of the quantum state of the second register. At this time, the state of the second register is based on the characteristic vector j  , and the joint initial state of the whole system is This step is the acceleration of the whole algorithm, because when calculating the eigenvalues of the coefficient matrix A, it is processed for all the eigenvalues simultaneously, that is, parallel computing.
Although the information of the eigenvalues into the second register in the Phase Estimation has been extracted, the eigenvalues here are stored in the quantum state. According to Formula (4), the eigenvalue j  must be stored in the form of coefficient and in the form of reciprocal. The results of the second register do not currently exist in the form individuals expect. Therefore, these can be converted through Controlled Rotation.
Controlled Rotation is mainly implemented in the first register and the second register, which is divided into three steps. First, one change the state of the second register from j  to (including the first register). In short, the function of Controlled Rotation is to extract the reciprocal of the ground state value proportionally to the corresponding probability amplitude of the ground state by an auxiliary qubit.
When the Controlled Rotation is completed, the state of the entire system is close to the final output. The output of the third register is useful. At this time, the second register and the third register are in an entangled state, which will affect the result. Therefore, the operation purpose of the Reverse Phase Estimation is to de-entangle the second register and the third register, and restore the result of the second register to the initial state. Only the entanglement result of the first register and the third register is left. The entire Inverse Phase Estimation is actually the inverse process of the previous Phase Estimation. After execution, the second register untangles and returns to the initial state. Meanwhile, the result of the entire system is The complexity analysis of this algorithm mainly comes from Phase Estimation and Controlled Rotation. We define s as the sparsity of the matrix, that is, there are no more than s non-zero elements in each row. And is the conditional number, that is, the absolute value of the ratio between the  [7]. At present, for solving the problem of linear equations, the fastest classic algorithm is based on the conjugate gradient descent method, and its complexity is O(Nsκ/ε 2 ). It can be seen that in addition to the lack of accuracy, the HHL quantum algorithm has a huge advantage over the classical algorithm in other respects. Under certain conditions, it has an exponential time acceleration.

Simulation implementation
In order to verify the feasibility of HHL quantum algorithm, 2×2 linear equations will be simulated and verified. In this paper, the Origin Quantum Platform is selected as the experimental platform.
Founded on September 11, 2017, the Origin Quantum is the first domestic start-up company whose main business is the development and application of quantum computer. The Origin Quantum Platform provides quantum-virtual machines for users to choose, in which 32-bit quantum-virtual machine is free to use and 64-bit application is required. Virtual machine adopts visual programming learning mode: legend + quantum language. Users can easily drag and place legend for quantum simulation operation, and can convert the designed operation into quantum language mode for in-depth learning. QPanda SDK is a C++ host language toolkit for writing quantum programs and applications, which enables users to easily connect and execute quantum programs. For quantum learners, it greatly reduces the difficulty of learning quantum computation.

Circuit implementation
In order to solve the 2×2 linear equations, four qubits are needed to achieve the system. One qubit as the input b , one as an auxiliary qubit for Controlled Rotation and measurement, and two qubits for Phase Estimation. For 2×2 linear equations, its coefficient matrix A is selected as: Through calculation, individuals can get the eigenvector of matrix A as follows: In this demonstration experiment, for input b of the third register, the paper selects two sets of data as a demonstration: The circuit for solving linear equations is shown in Fig.2. Assuming 1 , the vector b can be encoded into this state: . The eigenvalues of matrix A are λ 1 =1 and λ 2 =2, and the corresponding eigenvectors are 1  and 2  . At this time, λ 1 and λ 2 can be accurately encoded by similarly. In other words, after the SWAP gate, the system state becomes When performing a Controlled Rotation, in general, the mapping from In this case, R Y is used to approximate R. R Y uses a revolving door (Pauli Y ) around the Y axis of the Bloch ball, acting on 0 to obtain At this time, the system status is When the result of measuring the first quantum register 0 q is 1, the ideal 3 q should be 2 2 . Therefore, when is very small, the probability of outputting x will be very low, but high fidelity of output can be guaranteed.  Fig.2, some operations need to be converted. The conversion scheme is shown in Fig.3, which are two unitary matrices and a controlled rotating Y gate in Phase Estimation. The final quantum circuit diagram implemented on the Origin Quantum Platform is shown in Fig.4. The init operation is the initialization of 3 q , that is, the assignment of vector b. For A b , it is equivalent to not execute any operation. For B b is equivalent to NOT gate + H gate. Fig. 4 Quantum circuit diagram on the cloud platform By analyzing the quantum circuit diagram, it is found that 3 q is used for the input vector b and also used to store the output x . Therefore, the required x is the magnitude of the probability amplitude when 3 q is 0 and 1 respectively, if the measurement result of the additional qubit 0 q is 1. Special emphasis is placed on the need to include signs [9] [10]. That is, what ultimately need to extract is the probability amplitude of 0001 and 1001 . The theoretical value of x is calculated through Python's numpy package. For different input b , the corresponding theoretical values of x are:  In the completed quantum circuit, the different input b were measured in turn. Each test iteration is 8192 times (the optional number range is 1-8192 times), and the bar chart of the run results is obtained. Fig. 56 shows the run results. Through the above analysis, it can be clearly known that the useful value is the probability amplitude of 0001 and 1001 . The result marks are respectively By normalizing the theoretical value and the measured value, the inner product of the two value is calculated and the fidelity is approximately 0.959081 and 0.910324, respectively.

Programming implementation
QPanda2 SDK is a fully functional and efficient quantum software development toolkit. It is an open source quantum computing framework developed by the Origin Quantum Platform. It supports mainstream quantum logic gate operations, and can be optimized for quantum programs on different platforms, and can be adapted to a variety of quantum chips. QPanda2 uses C++ as the classic host language and supports quantum languages written in QRunes and QASM. This section provides a quantum programming based on QPanda2 development environment to verify the 2×2 linear equations mentioned in the previous section.
Taking the input A b as an example to show the code, the code is as follows: By calling runWithConfiguration() to get the measurement result of the quantum program, the test iteration is set to 10000 times. For input A b , the times of getting 0001 and 1001 are 9920 and 34 respectively. The times were converted into probability and normalized, and the inner product was carried out with the normalized theoretical value to obtain the fidelity of 0.965542. Similarly, for input B b , the fidelity is about 0.933564.

Conclusion
Regardless of whether it is implemented by the circuit diagram or programming, for different input b , the output of this HHL quantum circuit is maintained above 90% accuracy, basically meeting the requirements of solving linear equations. As far as the error is concerned, the error of this quantum circuit is mainly caused by the inherent error caused by the Phase Estimation and the choice of the rotation angle when the R Y approximates the controlled R operation in the Controlled Rotation. In addition, there is random error caused by repeated measurements. The accuracy has reached the required standard, but the success rate is not high. The overall probability of 0001 and 1001 is low, and further research is needed. However, this paper has carried out a complete study of the HHL algorithm from theory to simulation implementation, and the decomposition of advanced logic gates to basic logic gates, which provides a clear reference for the understanding of the algorithm itself and the realization of quantum computing for the next step. It has laid a good foundation for the application research of the broader Shor algorithm and Grover algorithm [11][12] [13].