Quantum simulator implementation method, device, related equipment and quantum simulation method

By constructing and deploying qubit gate operators on the Ascend AI processor, the problem of the inability of the quantum simulator to run is solved, efficient quantum computing is achieved, and the computing power of the Ascend processor is fully utilized.

CN113887730BActive Publication Date: 2024-08-27PENG CHENG LAB
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111040089.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-06
Publication Date
2024-08-27
Estimated Expiration
2041-09-06

AI Technical Summary

Technical Problem

Existing quantum simulators cannot run on the Ascend AI processor, which results in the inability to fully utilize the computing power of the Ascend processor and affects the efficiency of quantum computing.

Method used

Construct a qubit gate operator, integrate it into the quantum simulator, deploy it on the Ascend AI processor, and realize quantum circuit simulation through multi-core processing and data handling optimization.

Benefits of technology

The quantum simulator is implemented on the Ascend AI processor, which improves computing efficiency, fully utilizes the computing power of the Ascend processor, and reduces simulation time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113887730B
    Figure CN113887730B
Patent Text Reader

Abstract

The present invention discloses a quantum simulator implementation method, device, related equipment and quantum simulation method, wherein the quantum simulator implementation method includes: constructing a quantum bit gate operator, wherein the quantum bit gate operator is used to move data in a target device and update a state vector based on the operation bit of a quantum gate; constructing a quantum simulator, wherein the quantum simulator includes the quantum bit gate operator, and the quantum simulator is a software package for implementing quantum circuit simulation; deploying the quantum simulator to the target device, and the target device is an Ascend AI processor. Compared with the prior art, the solution of the present invention obtains a quantum bit gate operator that can move data in an Ascend AI processor and update a state vector, and obtains a quantum simulator that can be deployed to the Ascend AI processor for operation based on the quantum bit gate operator, thereby making full use of the computing power of the Ascend AI processor to realize quantum simulation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of quantum computing simulation technology, and in particular to a quantum simulator implementation method, device, related equipment and quantum simulation method. Background Art

[0002] Quantum computing theory has shown its great potential in solving some important problems that are beyond the computing power of classical computers, such as cryptography, financial modeling, and machine learning. Some quantum computers have been launched in recent years, but they are not yet widely used.

[0003] In the prior art, quantum simulation is usually achieved through quantum circuit simulation. Quantum computing circuit simulation is essentially using software to simulate the computing process of a real quantum computer. Software packages that implement quantum circuit simulation are generally called quantum simulators. The problem with the prior art is that existing quantum simulators can only run on CPUs or GPUs, and there are currently no quantum simulators that can run on Ascend AI processors. Users can only use CPU resources to run traditional quantum simulators on training servers equipped with Ascend AI processors, which is not conducive to fully utilizing the computing power of Ascend processors.

[0004] Therefore, the existing technology still needs to be improved and developed. Summary of the invention

[0005] The main purpose of the present invention is to provide a quantum simulator implementation method, apparatus, related equipment and quantum simulation method, aiming to solve the problem that quantum simulators in the prior art cannot run on Ascend AI processors, which is not conducive to fully utilizing the computing power of Ascend AI processors.

[0006] In order to achieve the above object, the first aspect of the present invention provides a method for implementing a quantum simulator, wherein the method comprises:

[0007] Constructing a quantum bit gate operator, wherein the quantum bit gate operator is used to move data in a target device and update a state vector based on an operation bit of quantum simulation;

[0008] Constructing a quantum simulator, wherein the quantum simulator includes the quantum bit gate operator, and the quantum simulator is a software package for realizing quantum circuit simulation;

[0009] The above-mentioned quantum simulator is deployed to the above-mentioned target device, and the above-mentioned target device is the Ascend AI processor.

[0010] Optionally, the above-mentioned quantum bit gate operator is used to perform single quantum bit gate operations on quantum bits.

[0011] Optionally, the above qubit gate operator performs quantum simulation based on the following steps:

[0012] Obtain the type of data to be calculated and the number of cores and buffer size of the Ascend AI processor.

[0013] Starting multi-core processing based on the above number of cores and dividing the state vectors corresponding to the above data to be calculated;

[0014] The divided state vector is moved from the global memory to the output buffer, and then the matrix-vector multiplication operation corresponding to the quantum bit gate operation is performed to obtain the calculated data;

[0015] The calculated data is transferred from the output buffer to the global memory.

[0016] Optionally, the above-mentioned quantum bit gate operator includes a distributed single quantum bit gate operator, a low-order single quantum bit gate operator and a high-order single quantum bit gate operator corresponding to different operation bits respectively.

[0017] Optionally, the above-mentioned construction of the quantum bit gate operator includes:

[0018] Based on the quantum circuit and the target device, a distributed high operation bit range, a low operation bit range, and a non-distributed high operation bit range are obtained, wherein the operation bits in the distributed high operation bit range are operation bits that require distributed communication, the address distance corresponding to the operation bits in the low operation bit range is less than the minimum data transfer scale of the Ascend AI processor, and the address distance corresponding to the operation bits in the non-distributed high operation bit range is not less than the minimum data transfer scale of the Ascend AI processor and there is no distributed communication;

[0019] A distributed single-qubit gate operator corresponding to the above-mentioned distributed high operation bit range, a low-order single-qubit gate operator corresponding to the above-mentioned low operation bit range, and a high-order single-qubit gate operator corresponding to the above-mentioned non-distributed high operation bit range are constructed respectively.

[0020] Optionally, the above-mentioned distributed single-qubit gate operator performs data transfer based on the following steps:

[0021] Obtaining data to be calculated, wherein the data to be calculated includes a local state vector and a paired state vector, the paired state vector is a state vector paired with the local state vector obtained through distributed communication, and the local state vector and the paired state vector are located in different Ascend AI processors;

[0022] Based on the length of the local state vector and the preset fragment length, the local state vector and the paired state vector are moved in a loop. In each loop, the data fragments with the same position and the same length in the local state vector and the paired state vector are moved from the global memory to the output buffer for calculation. After the calculation is completed, the calculated data is moved from the output buffer to the global memory.

[0023] Optionally, the above-mentioned high-order single-qubit gate operator performs data transfer based on the following steps:

[0024] Obtaining data to be calculated, wherein the data to be calculated is a local state vector, and the local state vector includes two paired state vectors located in the same Ascend AI processor and having a distance no less than a minimum data transfer scale of the Ascend AI processor;

[0025] Obtaining the length of continuously transmitted data segments and the interval between adjacent continuous data segments;

[0026] Based on the above-mentioned continuous transmission data segment length and the above-mentioned adjacent continuous data segment interval, data is loaded from different positions of the above-mentioned local state vector in the global memory to the above-mentioned output buffer for calculation. After the calculation is completed, the above-mentioned calculated data is moved from the above-mentioned output buffer to the above-mentioned global memory.

[0027] Optionally, the above low-order single-qubit gate operator performs data transfer based on the following steps:

[0028] Obtaining data to be calculated, wherein the data to be calculated is a local state vector, and the local state vector includes two paired state vectors located in the same Ascend AI processor and having a distance less than a minimum data transfer scale of the Ascend AI processor;

[0029] Loading data from the 0th element of the local state vector in the global memory into the output buffer to obtain a zeroth array;

[0030] Loading data from the first element of the local state vector in the global memory into the output buffer to obtain a first array;

[0031] Loading data from the -1th element of the local state vector in the global memory into the output buffer to obtain a second array;

[0032] After calculating the upper half of the unitary matrix based on the zeroth array and the first data to obtain the third array, and calculating the lower half of the unitary matrix based on the second array and the zeroth array to obtain the fourth array, bit selection is performed on the third array and the fourth array to obtain the fifth array, and the data in the fifth array is moved from the output buffer to the global memory.

[0033] Optionally, the quantum simulator is constructed, wherein the quantum simulator includes the quantum bit gate operator, and the quantum simulator is a software package for implementing quantum circuit simulation, including:

[0034] Based on the above-mentioned quantum bit gate operator packaging, a software package is generated that can be deployed, compiled and executed on the above-mentioned Ascend AI processor as the above-mentioned quantum simulator.

[0035] A second aspect of the present invention provides a quantum simulator implementation device, wherein the device comprises:

[0036] An operator construction module, used to construct a qubit gate operator, wherein the qubit gate operator is used to move data in a target device and update a state vector based on an operation bit of quantum gate calculation;

[0037] A quantum simulator building module, used to build a quantum simulator, wherein the quantum simulator includes the quantum bit gate operator, and the quantum simulator is a software package for realizing quantum circuit simulation;

[0038] A deployment module is used to deploy the quantum simulator to the target device, which is the Ascend AI processor.

[0039] A third aspect of the present invention provides a quantum simulation method and a quantum simulator implementation method, wherein the method comprises:

[0040] Get the data to be calculated;

[0041] The above-mentioned quantum bit gate operator is called to move the above-mentioned data to be calculated and update the state vector.

[0042] A fourth aspect of the present invention provides an intelligent terminal, which includes a memory, a processor, and a quantum simulator implementation program stored in the memory and executable on the processor, wherein the quantum simulator implementation program implements any one of the steps of the quantum simulator implementation method when executed by the processor.

[0043] A fifth aspect of the present invention provides a computer-readable storage medium, on which a quantum simulator implementation program is stored. When the quantum simulator implementation program is executed by a processor, the quantum simulator implementation program implements any step of the above-mentioned quantum simulator implementation method.

[0044] As can be seen from the above, in the scheme of the present invention, a qubit gate operator is constructed, wherein the qubit gate operator is used to move data in the target device and update the state vector based on the operation bit of the quantum gate; a quantum simulator is constructed, wherein the quantum simulator includes the qubit gate operator, and the quantum simulator is a software package for realizing quantum circuit simulation; and the quantum simulator is deployed to the target device, and the target device is an Ascend AI processor. Compared with the prior art, the scheme of the present invention obtains a qubit gate operator that can move data in the Ascend AI processor and update the state vector, and obtains a quantum simulator that can be deployed to the Ascend AI processor for operation based on the qubit gate operator, which is conducive to making full use of the computing power of the Ascend AI processor to realize quantum simulation. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0046] Figure 1 It is a schematic diagram of the Huawei Da Vinci AI Core architecture provided by an embodiment of the present invention;

[0047] Figure 2 It is a flowchart of a method for implementing a quantum simulator provided by an embodiment of the present invention;

[0048] Figure 3 It is a schematic diagram of a calculation flow of a quantum bit gate operator provided by an embodiment of the present invention;

[0049] Figure 4 Embodiment of the present invention Figure 1 Specific flow diagram of step S100;

[0050] Figure 5 is a schematic diagram of an operator calculation process provided by an embodiment of the present invention;

[0051] Figure 6 This is a schematic diagram of data pairing in a CusOneGateMulStatesDist operator provided by an embodiment of the present invention;

[0052] Figure 7 This is a schematic diagram of data pairing in a CusOneGateMulStatesHigh operator provided in an embodiment of the present invention;

[0053] Figure 8This is a schematic diagram of data pairing in a CusOneGateMulStatesLow operator provided in an embodiment of the present invention;

[0054] Fig. 9 It is a specific flow chart of a method for reusing data in blocks in an output buffer provided by an embodiment of the present invention;

[0055] Fig.10 is a schematic structural diagram of a quantum simulator implementation device provided by an embodiment of the present invention;

[0056] Fig.11 is a schematic flow chart of a quantum simulation method provided by an embodiment of the present invention;

[0057] Fig.12 It is a block diagram of the internal structure principle of an intelligent terminal provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0058] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present invention. However, it should be clear to those skilled in the art that the present invention may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present invention.

[0059] It should also be understood that the terms used in the present specification are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the present specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0060] As used in this specification and the appended claims, the term "if" may be interpreted as "when" or "upon" or "in response to determining" or "in response to detecting," depending on the context. Similarly, the phrases "if it is determined" or "if [described condition or event] is detected" may be interpreted as meaning "upon determination" or "in response to determining" or "upon detection of [described condition or event]" or "in response to detecting [described condition or event]," depending on the context.

[0061] The following is a clear and complete description of the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0062] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.

[0063] Quantum computing theory has shown its strong potential in solving some important problems that exceed the computing power of classical computers, such as cryptography, financial modeling, and machine learning. Some quantum computers have been launched in recent years, such as Google's 54-qubit computer Sycamore and 72-qubit computer Bristlecone, and the 76-qubit computer Jiuzhang of the University of Science and Technology of China. However, quantum computers are still a precious resource and cannot be used widely and conveniently. Current quantum computers also have very large error rates and cannot be used to verify complex quantum algorithms. In addition, quantum states collapse after measurement, so not all intermediate data can be collected on real quantum systems. Therefore, quantum circuit simulation is necessary to advance quantum computing theory. Quantum computing circuit simulation is essentially the use of software to simulate the computing process of a real quantum computer. Software packages that implement quantum circuit simulation are generally called quantum simulators.

[0064] The Ascend AI processor is an AI processor launched to meet the demand for chip computing power of today's rapidly developing neural networks. It can provide powerful and efficient multiplication and addition computing power for integers or floating-point numbers. Unlike existing CPUs and GPUs, the Ascend AI processor uses the Da Vinci structure. The Da Vinci architecture is a new computing architecture developed by Huawei for AI computing features. Unlike traditional CPUs and GPUs that support general computing, and unlike dedicated chips ASICs dedicated to a specific algorithm, the Da Vinci architecture is essentially designed to adapt to common applications and algorithms in a specific field, usually referred to as "Domain Specific Architecture (DSA)". The computing core of the Ascend AI processor is mainly composed of the AI ​​Core (AICore). The AI ​​Core adopts the Da Vinci architecture. Figure 1This is a schematic diagram of the Huawei Da Vinci AI Core architecture provided by an embodiment of the present invention. In order to improve the completeness of AI computing and the computing efficiency of different scenarios, the Da Vinci architecture also integrates matrix computing units (Cube Unit), vector computing units (Vector Unit) and scalar computing units (Scalar Unit). It supports multiple precision calculations at the same time, supports the data accuracy requirements of both training and reasoning scenarios, and achieves full scenario demand coverage. The AI ​​Core contains computing units, storage units, and control units. The computing units in the AI ​​Core mainly include matrix computing units (Cube), vector computing units (Vector) and scalar computing units (Scalar), which complete different types of data calculations in the AI ​​Core. There is internal storage in the AI ​​Core, and the AI ​​Core needs to load the data in the external storage into the internal storage to complete the corresponding calculations. The internal storage of AI Core includes L1 Buffer, L0 Buffer, Unified Buffer, General-Purpose Register (GPR), Special-Purpose Register (SPR) and Scalar Buffer. In order to cooperate with the data transmission and handling in AI Core, AI Core also includes Bus Interface Unit (BIU), Memory Transfer Engine (MTE), etc. BIU is the interface for AI Core to interact with the bus; MTE is the data handling unit, which completes the data handling between different buffers. The control unit in AICore mainly includes System Control Module (System Control), Instr.Dispatch Module (Instr.Dispatch), Cube Queue (Cube Queue), Vector Queue (Vector Queue), and MTE Queue (MTE Queue). The System Control Module is responsible for commanding and coordinating the overall operation mode of AI Core, configuring parameters and realizing power consumption control. When instructions are sent out in sequence through the instruction sending module, they will be sent to the Matrix Queue, Vector Queue and Memory Transfer Queue respectively according to the different types of instructions.

[0065] CANN (Compute Architecture for Neural Networks) is a heterogeneous computing architecture launched by Huawei for AI scenarios. It is a chip operator library and a highly automated operator development tool. The core of CANN is the highly automated operator development tool Tensor Engine. Through a unified DSL interface, combined with a collection of tools such as high-level template encapsulation and automatic performance tuning, users can easily develop custom operators on Ascend chips. At the same time, CANN already supports all major AI frameworks. AscendCL (Ascend Computing Language) provides C language API libraries such as Device management, Context management, Stream management, memory management, model loading and execution, operator loading and execution, and media data processing for users to develop deep neural network applications for target recognition, image classification and other functions. Users can call the AscendCL interface through a third-party framework to use the computing power of the Ascend AI processor; users can also use AscendCL to encapsulate and implement third-party lib libraries to provide the operation management and resource management capabilities of the Ascend AI processor.

[0066] In the prior art, quantum computing theory is usually implemented through quantum circuit simulation. Quantum computing circuit simulation is essentially the use of software to simulate the computing process of a real quantum computer. Software packages that implement quantum circuit simulation are generally called quantum simulators. The problem with the prior art is that existing quantum simulators can only run on CPUs or GPUs, and there are currently no quantum simulators that can run on Ascend AI processors. Users can only use CPU resources to run traditional quantum simulators on training servers equipped with Ascend AI processors, which is not conducive to fully utilizing the computing power of Ascend processors and is not conducive to reducing simulation time.

[0067] The most common approach to building a quantum circuit simulation system is to represent quantum states as vectors and to view the quantum gates that operate on the quantum circuit as small matrix-vector multiplications. For example, a system consisting of n qubits has a total of 2 n There are 30 possible states. In the quantum simulator, it is necessary to store the complex number (or amplitude) of the corresponding ground state contained in each possible state. If two single-precision floating points are used in the quantum simulator to represent the complex number, then 8GB of memory is required to simulate a 30qubit quantum system. For an n-qubit system, when performing a single-qubit gate operation on the mth qubit, 2 n The multiplication of these small matrices and vectors has no data dependency and can be parallelized as shown in the following formula (1):

[0068]

[0069] Among them, the quantum bit gate can be represented as a unitary matrix of size 2*2, and each element of the unitary matrix is ​​a complex number, that is, A 00 , A 01 , A 10 and A 11 The system consisting of n quantum bits has a total of 2 n possible states, called state vectors, are represented by a length of 2 n The complex array representation of is, the elements of the array are α i and α j Represent the i-th and j-th elements in the array respectively. In formula (1), the matrix on the left side of the equation is the qubit gate unitary matrix, the vector on the left side of the equation is the state vector element before applying a qubit gate, and the vector on the right side of the equation is the updated state vector element after applying the qubit gate. i and j satisfy the following formula (2):

[0070]

[0071] Formula (2) gives the conditions that i and j in formula (1) need to satisfy during calculation. m represents the mth qubit currently being operated, and the subscripts of the two paired state elements will differ by 2. m , the first line of formula (2) gives the restriction condition of i, i does not exceed the upper and lower limits of the array and in the binary representation of i, the remainder obtained after the number obtained by right shifting m bits and divided by 2 is 0. For example, in a 4-qubit system, if m = 2, then when i = 0 (binary representation is 0000), j = 4 (binary representation is 0100); when i = 1 (binary representation is 0001), j = 5 (binary representation is 0101).

[0072] In order to solve the problems of the prior art, the present invention provides a quantum simulator implementation method. In the embodiment of the present invention, a set of systematic and feasible quantum simulator implementation and optimization solutions based on the Ascend AI processor are proposed in view of the characteristics of the Da Vinci architecture and programming characteristics of the Ascend AI processor, combined with the characteristics of the quantum simulation program, so as to achieve full utilization of AI Core computing resources. And this method provides a general implementation and optimization method for developers who develop, transplant or optimize quantum simulator programs for Ascend AI processors, which has certain guiding significance for the efficient application of quantum simulator programs in other high-performance AI computing platforms.

[0073] like Figure 2 As shown, an embodiment of the present invention provides a method for implementing a quantum simulator. Specifically, the method includes the following steps:

[0074] Step S100, constructing a quantum bit gate operator, wherein the quantum bit gate operator is used to move data in a target device and update a state vector based on an operation bit of a quantum gate.

[0075] In this embodiment, the above-mentioned qubit gate operator is a function that can be compiled and run in the target device. The above-mentioned qubit gate operator is used to perform a single quantum gate bit gate operation on the qubit.

[0076] Step S200, constructing a quantum simulator, wherein the quantum simulator includes the quantum bit gate operator, and the quantum simulator is a software package for realizing quantum circuit simulation.

[0077] Specifically, based on the quantum bit gate operator packaging, a software package that can be deployed and compiled and executed in the target device is generated as the quantum simulator. The quantum simulator includes the quantum bit operator and other functions, instructions and other data used to support the normal use of the quantum bit gate operator in the target device. The specific data can be set and adjusted according to actual needs and is not specifically limited here.

[0078] Step S300: deploy the quantum simulator to the target device, which is the Ascend AI processor.

[0079] Specifically, the quantum simulator is compiled and run in the target device so that the target device can call the qubit gate operator to move data and update the state vector, thereby realizing the simulation of the quantum circuit. In this embodiment, the target device is an Ascend AI processor. In actual use, the target device can also be other processors or devices, which are not specifically limited here.

[0080] As can be seen from the above, in the quantum simulator implementation method provided by the embodiment of the present invention, a quantum bit gate operator is constructed, wherein the quantum bit gate operator is used to move data in the target device and update the state vector based on the operation bit of the quantum gate; a quantum simulator is constructed, wherein the quantum simulator includes the quantum bit gate operator, and the quantum simulator is a software package for realizing quantum circuit simulation; and the quantum simulator is deployed to the target device, and the target device is an Ascend AI processor. Compared with the prior art, the solution of the present invention obtains a quantum bit gate operator that can move data in the Ascend AI processor and update the state vector, and obtains a quantum simulator that can be deployed to the Ascend AI processor for operation based on the quantum bit gate operator, which is conducive to making full use of the computing power of the Ascend AI processor to realize quantum simulation.

[0081] Specifically, in this embodiment, Figure 3 As shown, the above qubit gate operator performs quantum simulation based on the following steps:

[0082] Step A100, obtaining the type of data to be calculated and the number of cores and buffer size of the Ascend AI processor.

[0083] Step A200, starting multi-core processing based on the above number of cores and dividing the state vectors corresponding to the above data to be calculated.

[0084] Step A300, after the divided state vector is moved from the global memory to the output buffer, a matrix-vector multiplication operation corresponding to the quantum bit gate operation is performed to obtain the calculated data.

[0085] Step A400, moving the calculated data from the output buffer to the global memory.

[0086] The data to be calculated is the data that needs to be quantum simulated, and the type of the data to be calculated can be a high-precision floating point number, a single-precision floating point number, etc. On the Ascend AI processor, since the storage output buffer (Unitfied Buffer) inside the AI ​​Core is separated from the storage global memory (Global Memory) outside the AI ​​Core, the data needs to be moved from the Global Memory to the Unitfied Buffer before it is calculated in the AI ​​Core, and then the calculation result is moved back to the Global Memory.

[0087] Specifically, in this embodiment, the above-mentioned qubit gate operator includes a distributed single qubit gate operator, a low-order single qubit gate operator, and a high-order single qubit gate operator corresponding to different operation bits. Figure 4 As shown, the above step S100 specifically includes:

[0088] Step S101, obtaining a distributed high operation bit range, a low operation bit range and a non-distributed high operation bit range based on the quantum circuit and the target device.

[0089] Among them, the operation bits within the above-mentioned distributed high operation bit range are operation bits that require distributed communication, the address distance corresponding to the operation bits within the above-mentioned low operation bit range is less than the minimum data transfer scale of the above-mentioned Ascend AI processor, and the address distance corresponding to the operation bits within the above-mentioned non-distributed high operation bit range is not less than the minimum data transfer scale of the above-mentioned Ascend AI processor and there is no distributed communication.

[0090] Step S102, respectively constructing a distributed single-qubit gate operator corresponding to the above-mentioned distributed high operation bit range, a low-order single-qubit gate operator corresponding to the above-mentioned low operation bit range, and a high-order single-qubit gate operator corresponding to the above-mentioned non-distributed high operation bit range.

[0091] According to the level of quantum gate operation bit, the above quantum bit gate operator requires the above three operators to perform specific calculations.

[0092] Specifically, if a high-order quantum bit that needs to communicate is operated during distributed computing, two state vector fragments (i.e., the local state vector and the paired state vector) are obtained after communication. The above-mentioned distributed single-qubit gate operator is called to complete a single-gate operation. The above-mentioned distributed single-qubit gate operator can be named CusOneGateMulStatesDist. The CusOneGateMulStatesDist operator has four inputs and one output. The first input tensor is the local state vector (input_x), with a length of 2*2 n , the real and imaginary parts of the complex number are stored separately (both the real and imaginary parts are stored in the global memory of the Ascend AI processor. Separate storage means two arrays, the first array contains the real parts of all local elements, and the second array contains the imaginary parts of all local elements). The second input tensor is the state vector fragment (input_y) obtained by communication and paired with the local state vector. The third input tensor is the quantum gate matrix data (input_m). The fourth tensor is the criterion for whether the local state vector in formula (1) is located at the 0th element or the 1st element of the vector when multiplied by the gate matrix. One output tensor is the calculation result (output). The data types and data sizes of input_x, input_y and output should be consistent. The above communication refers to the communication between different Ascend AI processors. For example, the first Ascend AI processor obtains the data of the third Ascend AI processor through communication. The communication method is HCCL, i.e. Huawei Collective Communication Library. The above quantum gate matrix data (input_m) is a quantum gate represented by a matrix, which depends on what quantum gate calculation is to be performed on the data. For example, the matrix data corresponding to the Pauli-X gate is

[0093] The above vector refers to the vector on the left side of equation (1). In one application scenario, the data of the first Ascend AI processor and the data of the third Ascend AI processor are paired in sequence. The data subscript of the first Ascend AI processor is smaller than the data subscript of the third Ascend AI processor, that is, j=i+2 in equation 2. m When calculating, the data of the first Ascend AI processor is placed in the α i The data of the third Ascend AI processor is placed in αj The above-mentioned judgement symbol can be of Boolean type or integer type. The calculation result (output) is obtained by calculating the above-mentioned data as shown in formula (1), and the state vector is paired and then multiplied with the quantum gate matrix to update the state vector.

[0094] The specific number of bits corresponding to the above high bits (i.e., the range of distributed high operation bits) can be determined or set according to actual needs. For example, assuming a circuit with 20 quantum bits, the length of the state vector is 2 20 If eight Ascend AI processors are used for computing, each Ascend AI processor needs to store 2 17 The first Ascend AI processor needs to store 0, 1, 2, ..., 2 17 - Element 1; the second Ascend AI processor needs to store 2 17 , 2 17 +1,2 17 +2, ..., 2 18 -1 element, and so on.

[0095] If we want to operate on quantum bit No. 18 (counting from 0), that is, m=18 in formula (2), then the relationship between i and j in formula (2) is j=i+2 18 . i=0 element needs and j=2 18 Element 0 is in the first Ascend AI processor, 2 18 The element number is in the third Ascend AI processor, so the first Ascend AI processor and the third Ascend AI processor need to exchange data before calculation (i.e., distributed communication). At this time, the quantum bit number m is called an operation bit that needs to be communicated, and the distributed single-qubit gate operator CusOneGateMulStatesDist is called. That is, the condition for calling the distributed single-qubit gate operator is that the quantum bit to be operated is an operation bit that needs to be communicated. The two state vector fragments obtained after the communication are the input data that need to be prepared before calling the operator. In an application scenario, after the communication, the first Ascend AI processor has its own stored 0, 1, 2, ..., 2 17 -1 element, and also stores 2 obtained from the third Ascend AI processor 18 , 2 18 +1,2 18 +2, ..., 2 18 +2 17 -1 element. Because the real and imaginary parts of complex numbers are stored separately, from the program it can be seen that there are four elements of length 2 17 The first array is 0, 1, 2, ..., 2 17 -The real part of the complex number of element 1, the second array is 0, 1, 2, ..., 217 -The imaginary part of the complex number of element 1, the third array is 2 18 , 2 18 +1,2 18 +2, ..., 2 18 +2 17 -The real part of the complex number of element 1, the fourth array is 2 18 , 2 18 +1,2 18 +2, ..., 2 18 +2 17 -The imaginary part of the complex number of element 1. When calculating, the elements with the same subscript in each array are paired.

[0096] The minimum data transfer scale of the Ascend AI processor is 32 bytes, corresponding to 16 half-precision floating-point numbers. If the operation bit is equal to 0, 1, 2, or 3, and the distance between any two elements to be paired is less than 32 bytes, the low-order single-qubit gate operator is called. Other operation bits call the high-order single-qubit gate operator.

[0097] For the local vector (input_x) above, "local" is a concept in distributed computing, which means that if a piece of data is stored on X (such as the first Ascend AI processor), then this piece of data is local to X. In the above example, 0, 1, 2, ..., 2 17 Element -1 is the local data of the first Ascend AI processor, but this data is not local to the third Ascend AI processor.

[0098] If the address distance of the states to be paired is greater than or equal to 32 bytes and there is no distributed communication, call the above high-order single-qubit gate operator to complete a single-gate operation. The above high-order single-qubit gate operator can be named CusOneGateMulStatesHigh. The CusOneGateMulStatesHigh operator has three inputs and one output. The first input tensor is the state vector (input_x), the second input tensor is the quantum gate matrix data (input_m), the third tensor is the offset of the paired state, and one output tensor is the calculation result (output). For the mth operation bit, the offset is equal to 2 m , see formula (2). The data type and data size of input_x and output should be consistent.

[0099] Among them, the state vector is an array, and the state is the element in the state vector, which is a number. For example, when the operation bit is 2, 0 and 4 are matched, 1 and 5 are matched, 2 and 6 are matched, 3 and 7 are matched, 8 and 12 are matched, and the number here is the element subscript. "Address" is a concept on the computer storage unit. The address can be represented by a hexadecimal number, which indicates the location of this data on the memory.

[0100] The mth operation bit is the mth quantum bit in the quantum circuit, 2 n The binary subscripts of the states are 00...00, 00...01, 00...10, 00...11, ..., 11...11, and the states with subscripts xx...xx0xx...xx and xx...xx1xx...xx are paired, that is, the states with different numbers in the m operation bit but the same numbers in other operation bits are paired. Offset 2 m Equal to the difference between xx…xx1xx…xx and xx…xx0xx…xx.

[0101] If the address distance of the states to be paired is less than or equal to 32 bytes, the above low-order single-qubit gate operator (named CusOneGateMulStatesLow) can be called to complete a single-gate operation. The CusOneGateMulStatesLow operator has three inputs and one output. The first input tensor is the state vector (input_x), the second input tensor is the quantum gate matrix data (input_m), the third tensor is the offset of the paired state, and the sel symbol required for assembling and distributing data, and one output tensor is the calculation result (output). For the mth operation bit, the offset is equal to 2 m , see formula (2). The data type and data size of input_x and output should be consistent. The parameters of the same representation in the above operators have the same meaning and will not be repeated here.

[0102] The above three operators have similar operation steps (such as the above steps A100 to A400), and only the data handling and assembly methods are different. Figure 5 This is a schematic diagram of an operator calculation process provided by an embodiment of the present invention, and the specific process is as follows:

[0103] The first step is to obtain the type of input data. A half-precision floating point number occupies 2 bytes, and a single-precision floating point number occupies 4 bytes. The data transport data_move instruction, vector multiplication vec_mul instruction and vector addition vec_add instruction used in the present invention need to set different parameters according to the data type.

[0104] The second step is to obtain the number of cores and buffer size. In the prototype definition of for_range (a function interface of TIK), users can set the parameter block_num to achieve core parallelism. Users can obtain the number of AI Cores through the get_soc_spec interface. Taking the Ascend 910 processor as an example, the chip contains 32 AI Cores. The buffer Unified Buffer is the target storage space corresponding to the input and output of vector and scalar calculations. Users can obtain its size through the get_unified_buffer_size function.

[0105] The third step is to start the multi-core and divide input_x according to the number of cores obtained. Different models of Ascend AI processors have different numbers of AI Cores. For the Ascend 910 processor, one NPU has 32 AI Cores. Specifically, the data stored in the buffer is divided and evenly distributed to each core, and each core only processes the data assigned to it.

[0106] The fourth step, on the Ascend AI processor, since the internal storage Unitfied Buffer of the AI ​​Core is separated from the external storage Global Memory of the AI ​​Core, the data needs to be moved from the Global Memory to the Unitfied Buffer before it can be calculated in the AI ​​Core, and then calculated in the AI ​​Core, and finally the calculation results need to be moved back to the Global Memory. For the Ascend 910 processor, the available size of the Unitfied Buffer does not exceed 256KB, so the state vector array in the Global Memory needs to be copied into the Unitfied Buffer in segments. According to the obtained buffer size, the amount of data copied each time is calculated, and the data_move instruction is used to move the data from the Global Memory to the Unitfied Buffer. The Unitfied Buffer requires the offset address to be aligned to 32Byte. The space occupied by a float16 and float32 in the memory is 2Byte and 4Byte respectively. The shortest length of the continuous transmission data segment of data_move is 16 float16 or 8 float32. In one application scenario, there are a total of 2 n Floating point numbers are stored in the global memory. When n=30, the data volume is 4GB. The unified buffer is only 248kb and cannot store all the data. So each time a part of the data is moved in, it is calculated and moved out before the next part of the data is moved. Therefore, the amount of data copied each time is less than the buffer size.

[0107] In the fifth step, the vector computing unit Vector of the Da Vinci architecture is responsible for performing vector operations. All source data and target data of Vector calculations are required to be stored in the output buffer (Unitfied Buffer) and are required to be 32-byte aligned. The vec_muls, vec_add, and vec_sub instructions are used as shown in formula (1) to perform matrix-vector multiplication operations of gate operations on the data moved to the Unitfied Buffer in the fourth step.

[0108] Step 6: Use the data_move instruction to move the calculation result of step 5 from the Unite Buffer to GlobalMemory. If the calculation of all data is completed, the operation of the operator ends; otherwise, return to step 4 and operate on the next data segment.

[0109] The main difference between the above-mentioned distributed single-qubit gate operator, low-bit single-qubit gate operator, and high-bit single-qubit gate operator is that the data handling and assembly methods are different. As shown in formula (1), the height of different qubit gate operation bits determines the distance between two paired states in memory.

[0110] In this embodiment, the distributed single-qubit gate operator performs data transfer based on the following steps: obtaining data to be calculated, wherein the data to be calculated includes a local state vector and a paired state vector, the paired state vector is a state vector paired with the local state vector obtained through distributed communication, and the local state vector and the paired state vector are located in different Ascend AI processors; based on the length of the local state vector and a preset fragment length, the local state vector and the paired state vector are transferred in a loop, and in each loop, the data fragments of the same position and the same length in the local state vector and the paired state vector are transferred from the global memory to the output buffer for calculation, and after the calculation is completed, the calculated data is transferred from the output buffer to the global memory.

[0111] The preset segment length can be set and adjusted according to actual needs. Specifically, during distributed computing, if the operation is at the highest position, the paired states will be on two different Ascend AI processors, and the two Ascend AI processors need to exchange data before computing. For example, for a 30-qubit quantum system, the 30 quantum bits are numbered from 0 to 29, and the state vector can be represented as a total length of 2 30 , using four (just as an example) Ascend AI processors to simulate quantum circuits, each processor storing 2 28complex number. If the operation bit of the quantum gate is 29, then processors 0 and 2, and processors 1 and 3 need to exchange data, record the local state vector as input_x, record the state vector obtained by communication as input_y, and then call the CusOneGateMulStatesDist operator. Figure 6 This is a data pairing diagram in a CusOneGateMulStatesDist operator provided by an embodiment of the present invention. The nth element of input_x is paired with the nth element of input_y. In each loop, the data fragments of the same position and length of input_x and input_y are copied from the Global Memory to the Unitfied Buffer, and two UnitfiedBuffer arrays ub0 and ub1 are obtained respectively, corresponding to α in formula (1). i and α j , after the calculation is completed, the output is copied from the Unitfied Buffer to the original address of the Global Memory. The original address is the original address of input_x. In an application scenario, the output can also be copied to another preset address of the archived result, but it will take up more memory space. Therefore, in this embodiment, it is copied back to the original address to reduce space occupation.

[0112] The above-mentioned high-order single-qubit gate operator performs data transfer based on the following steps: obtaining data to be calculated, wherein the above-mentioned data to be calculated is a local state vector, and the above-mentioned local state vector includes two paired state vectors located in the same Ascend AI processor and the distance between them is not less than the minimum data transfer scale of the above-mentioned Ascend AI processor; obtaining the length of the continuously transmitted data segment and the interval between adjacent continuous data segments; based on the above-mentioned continuously transmitted data segment length and the above-mentioned adjacent continuous data segment interval, loading data from different positions of the above-mentioned local state vector in the global memory into the above-mentioned output buffer for calculation, and after the calculation is completed, transferring the above-mentioned calculated data from the above-mentioned output buffer to the above-mentioned global memory.

[0113] Figure 7This is a schematic diagram of data pairing in a CusOneGateMulStatesHigh operator provided by an embodiment of the present invention. If the simulator uses single-precision floating point and the gate operation bit is greater than or equal to 3, then the distance between the two paired states in the memory is greater than or equal to 32 bytes, which is the minimum size of the data_move operation (for half-precision floating point, the gate operation bit is greater than or equal to 4). Set the length of the continuously transmitted data segment and the interval between adjacent continuous data segments, call data_move to load data from different positions of the local state vector array into the Unitfied Buffer, and after the calculation is completed, copy the output from the Unitfied Buffer to the original address of the Global Memory. The length of the continuously transmitted data segment is the length of the continuous data, and the interval between adjacent continuous data segments is the number of bytes between two continuously transmitted data.

[0114] The above-mentioned low-order single-qubit gate operator performs data transfer based on the following steps: obtaining data to be calculated, wherein the above-mentioned data to be calculated is a local state vector, and the above-mentioned local state vector includes two paired state vectors located in the same Ascend AI processor and the distance between them is less than the minimum data transfer scale of the above-mentioned Ascend AI processor; loading data from the 0th element of the above-mentioned local state vector in the above-mentioned global memory into the above-mentioned output buffer area to obtain the zeroth array; loading data from the 1st element of the above-mentioned local state vector in the above-mentioned global memory into the above-mentioned output buffer area to obtain the first array; loading data from the -1st element of the above-mentioned local state vector in the above-mentioned global memory into the above-mentioned output buffer area to obtain the second array; after calculating the upper half of the unitary matrix based on the above-mentioned zeroth array and the above-mentioned first data to obtain the third array, and calculating the lower half of the unitary matrix based on the above-mentioned second array and the above-mentioned zeroth array to obtain the fourth array, the above-mentioned third array and the fourth array are bit-selected to obtain a fifth array, and the data in the above-mentioned fifth array is transferred from the above-mentioned output buffer area to the above-mentioned global memory.

[0115] If the operation bits are in the lowest positions (such as 0, 1, 2, 3 of half-precision floating points; 0, 1, 2 of single-precision floating points), then the distance between the paired states in memory will be less than 32 bytes, which is the minimum size of the data_move operation. Taking the operation of qubit No. 0 as an example, the offset of the paired state is 1. If single precision is used, the distance between the paired states in memory is 4 bytes. Element No. 0 of the local state vector is paired with element No. 1, element No. 2 is paired with element No. 3, element No. 4 is paired with element No. 5, and the following elements are paired in sequence. The calculation uses the vector calculation unit, and elements No. 0, No. 2, No. 4... need to be moved to the ub0 array, and elements No. 1, No. 3, No. 5... need to be moved to the ub1 array. Since data_move does not support selective data movement, moving data one by one is very inefficient, such as Figure 8 As shown, the present invention proposes the following method for data transfer for the CusOneGateMulStatesLow operator:

[0116] 1) Load data into the Unified Buffer starting from element 0 of the state vector. The data obtained by ub0 (i.e., the zeroth array) includes elements 0, 1, 2, 3, 4, 5, etc.;

[0117] 2) Load data into the Unitfied Buffer starting from element 1 of the state vector. The data obtained by ub1 (i.e., the first array) includes elements 1, 2, 3, 4, 5, 6, etc.;

[0118] 3) Load data into the Unified Buffer starting from the -1 element of the state vector. The data obtained by ub2 (i.e., the second array) includes: xx, 0, 1, 2, 3, 4, ... elements (xx represents useless data). Because Global Memory does not support negative address memory access, it is necessary to add several blank data in front of the array when creating the Global Memory state vector;

[0119] 4) Substitute the three ub arrays into formula (1) to participate in the calculation. ub0 and ub1 participate in the calculation of the upper half of the matrix to obtain ub3 (i.e., the third array). The data in ub3 are the calculated elements 0, xx, 2, xx, 4, and xx. ub2 and ub0 participate in the calculation of the lower half of the matrix to obtain ub4 (i.e., the fourth array). The data in ub4 are the calculated elements xx, 1, xx, 3, xx, and 5.

[0120] 5) Call the vec_sel function to perform bitwise selection on ub3 and ub4 using the sel symbol (for example, when the bit of sel is 1, select from ub3, and when the bit is 0, select from ub4) to obtain ub5 (i.e., the fifth array), and the data contained in ub5 are the calculated elements numbered 0, 1, 2, 3, 4, 5...

[0121] 6) Copy the data in ub5 back to the original address in Global Memory.

[0122] It should be noted that the data of the gate matrix in formula (1) are not necessarily all non-zero elements. For a matrix containing zero elements, the calculation processes of these three operators can be simplified, omitting the data transfer and floating-point calculation operations related to zero elements. For a single-gate quantum random circuit, according to the high and low of all quantum gate operation bits, call the three operators in sequence to achieve quantum circuit simulation.

[0123] Building a high-performance quantum circuit simulator on the Ascend AI platform is challenging. A large number of small matrix multiplications for simulating various quantum gates result in poor data locality, further leading to low utilization of computing resources. To improve data locality, the present invention proposes an output buffer data block reuse method (UB Blocking method), which repeatedly uses the efficient UnifiedBuffer storage unit to reduce the number of data transfers in Global Memory with lower bandwidth.

[0124] Unified Buffer (referred to as UB for short) is a place used to save the input and output of vector and scalar calculation units. For the Ascend 910 processor, the available size of the Unitfied Buffer does not exceed 256KB, and the number of single-precision floating points that can be stored does not exceed 2 16 During actual calculation, the UB not only needs to store the state vector segments of the input and output, but also needs to store temporary intermediate variables. Therefore, the length of the state vector carried each time is 2 12 single-precision complex numbers.

[0125] Fig. 9 is a schematic diagram of the specific process of an output buffer data block reuse method provided by an embodiment of the present invention. Specifically, consider a quantum circuit composed of n qubits and a gate group containing multiple gates. Within this gate group, all gates only operate on no more than k (0 < k <= n) qubits. A set of complex numbers with a length of 2 k can be extracted from the state vector. When performing the gate operations within the gate group, the calculation results are only related to the data within this set of complex numbers. The entire state vector can be divided into 2 (n-k) such independent sets of complex numbers. During calculation, this set of complex numbers with a length of 2 kThe complex set is moved into the United Buffer, and then all gates in the gate group are applied at once. After the calculation is completed, it is moved back to the Global Memory. Compared with the conventional calculation process, the UB Blocking method reduces the number of data transfers between the Global Memory and the United Buffer. For example, based on the conventional method, each gate needs to be transferred 2 n A complex number, a gate group containing m gates, the total amount of data carried is m*2 n Using this method, the total amount of data moved is 2 n The complex number is reduced to 1 / m of the original, which can reduce the calculation time.

[0126] Furthermore, due to the size limit of the Unite Buffer, for single-precision floating points, a gate group has a maximum of 12 quantum operation bits; since the minimum operation size of the data_move data transfer instruction is 32 bytes, the gate group must contain quantum operation bits 0 to 3, and the other 8 quantum operation bits can be arbitrary. A quantum circuit can be converted into several gate groups, and in some cases the order of the gates can be swapped, which helps to reduce the number of gate groups.

[0127] It should be noted that the ideas of data handling and calculation methods of the above-mentioned quantum bit gate operators are still applicable to the realization of controlled single-qubit gate and double-qubit gate calculations.

[0128] The present invention proposes a general implementation and optimization method for a single-gate operator of a quantum simulator for the Ascend AI processor. Through the underlying TIK development method and combined with multi-core, United Buffer and other optimization methods, the architecture and performance advantages of the Ascend AI processor are better utilized. The following table is a performance comparison between the Ascend quantum simulator and similar open source GPU simulators. Except for the qulacs simulator, all other simulators in the table use single-precision floating-point numbers for calculation simulation. The second column represents the operator running time of the Ascend quantum simulator and the gate operation kernel function time of similar GPU simulators. The simulator runs a 29-qubit, U1 single-gate quantum random circuit. The Ascend quantum simulator uses the Ascend 910 machine, QuEST and qcgpu use NVIDIA Tesla V100GPU, and each simulator uses a single card for testing and comparison. The test performance data results are as follows:

[0129]

[0130] It can be seen that the performance of the Ascend quantum simulator is several times better than that of similar GPU simulators. The present invention aims at the characteristics of the Da Vinci architecture and programming characteristics of the Ascend AI processor, combined with the characteristics of the quantum simulation program, provides the data handling and operation details of the quantum simulator that can be run on the Ascend AI processor, and further proposes the UB Blocking method, which utilizes the multi-core optimization of the Ascend AI processor to achieve full utilization of AICore computing resources; it provides a general implementation and optimization method for developers who develop, transplant or optimize quantum simulator programs for the Ascend AI processor. This method is not only applicable to the implementation of the single quantum gate described in the present invention, but also to the implementation of controlled single quantum bit gates and double quantum bit gates. The quantum simulator for the Ascend AI processor of the present invention has been fully tested and used. Using the Ascend 910 processor, the operator proposed by the present invention is encapsulated by adding custom operators through Mindspore and AscendCL application development. The quantum simulator has completed the implementation and testing of single quantum bit gates, and compared the efficiency with other similar GPU quantum simulators. According to the above table, it can be seen that the invention is feasible and effective.

[0131] It should be noted that the Ascend AI chip has three basic computing resources: matrix computing unit (Cube Unit), vector computing unit (Vector Unit) and scalar computing unit (Scalar Unit). The present invention uses the vector computing unit of the Ascend AI chip to simulate quantum circuits. The matrix computing unit can perform matrix multiplication of two half-precision floating points of size 16*16. If a gate group operates no more than 4 quantum bits, then this gate group can be fused into a 4-qubit gate, represented by a 16*16 matrix. The matrix and the corresponding 16 states are multiplied to obtain the updated vector. This matrix-vector multiplication operation has multiple groups and no data dependency. 16 groups of vectors can form a 16*16 matrix, and then the matrix computing unit can also be used to complete the simulation of quantum circuits. The operation ideas are as follows:

[0132] 1) Analyze the quantum circuit, rearrange the order of quantum gates and divide them into several gate groups. Each gate group contains multiple quantum gates, and a gate group operates no more than 4 quantum bits. Each gate group can be represented by a 16*16 matrix.

[0133] 2) Assuming that the operation bits of a gate group are i, j, k, and l, the 15 states paired with element 0 in the state vector are: 2 i , 2 j , 2 i +2 j , 2 k , 2 k +2 i, 2 k +2 j , 2 k +2 i +2 j ...The above 16 states form a vector, which needs to be multiplied by a 16*16 gate matrix.

[0134] 3) The matrix calculation unit only supports the multiplication of two 16*16 matrices, and cannot perform the matrix-vector multiplication represented in 2). Packing 16 groups of paired states at a time can form a 16*16 state matrix, which can be multiplied with the gate matrix. If the quantum bits operated by this gate group are all greater than or equal to 4, a data transfer method similar to the CusOneGateMulStatesHigh operator can be used. Elements 0, 1, 2...15 are placed in the first row of the state matrix, 2 i , 2 i +1, 2 i +2……2 i Element +15 is placed in the second row of the state matrix...If the number of quantum bits operated by this gate group is less than 4, a data transfer method similar to the CusOneGateMulStatesLow operator can be used, using data transfer instructions with offsets, and finally using selection instructions to extract results.

[0135] like Fig.10 As shown, corresponding to the above-mentioned quantum simulator implementation method, an embodiment of the present invention further provides a quantum simulator implementation device, and the above-mentioned quantum simulator implementation device includes:

[0136] The operator construction module 410 is used to construct a quantum bit gate operator, wherein the quantum bit gate operator is used to move data in the target device and update the state vector based on the operation bit of the quantum gate.

[0137] In this embodiment, the above-mentioned qubit gate operator is a function that can be compiled and run in the target device. The above-mentioned qubit gate operator is used to perform a single quantum gate bit gate operation on the qubit.

[0138] The quantum simulator construction module 420 is used to construct a quantum simulator, wherein the quantum simulator includes the quantum bit gate operator, and the quantum simulator is a software package for realizing quantum circuit simulation.

[0139] Specifically, based on the quantum bit gate operator packaging, a software package that can be deployed and compiled and executed in the target device is generated as the quantum simulator. The quantum simulator includes the quantum bit operator and other functions, instructions and other data used to support the normal use of the quantum bit gate operator in the target device. The specific data can be set and adjusted according to actual needs and is not specifically limited here.

[0140] The deployment module 430 is used to deploy the quantum simulator to the target device, which is the Ascend AI processor.

[0141] Specifically, the quantum simulator is compiled and run in the target device so that the target device can call the qubit gate operator to move data and update the state vector, thereby realizing the simulation of the quantum circuit. In this embodiment, the target device is an Ascend AI processor. In actual use, the target device can also be other processors or devices, which are not specifically limited here.

[0142] It should be noted that the specific functions corresponding to the above-mentioned quantum simulator implementation device and its specific modules can be set and adjusted with reference to the above-mentioned quantum simulator implementation method, which will not be repeated here.

[0143] like Fig.11 As shown, corresponding to the above-mentioned quantum simulator implementation method, an embodiment of the present invention further provides a quantum simulation method, the above-mentioned method includes:

[0144] Step B100, obtaining data to be calculated.

[0145] Step B200, calling the above-mentioned quantum bit gate operator to move the above-mentioned data to be calculated and update the state vector.

[0146] It should be noted that the specific quantum simulation process can refer to the specific calculation process in the above-mentioned quantum simulator implementation method, which will not be repeated here.

[0147] Based on the above embodiments, the present invention further provides an intelligent terminal, whose principle block diagram can be shown as follows: Fig.12 As shown. The above-mentioned intelligent terminal includes a processor, a memory, a network interface and a display screen connected through a system bus. Among them, the processor of the intelligent terminal is used to provide computing and control capabilities. The memory of the intelligent terminal includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a quantum simulator implementation program. The internal memory provides an environment for the operation of the operating system and the quantum simulator implementation program in the non-volatile storage medium. The network interface of the intelligent terminal is used to communicate with an external terminal through a network connection. When the quantum simulator implementation program is executed by the processor, the steps of any of the above-mentioned quantum simulator implementation methods are implemented. The display screen of the intelligent terminal can be a liquid crystal display screen or an electronic ink display screen.

[0148] Those skilled in the art will understand that Fig.12The principle block diagram shown in the figure is only a block diagram of a partial structure related to the scheme of the present invention, and does not constitute a limitation on the smart terminal to which the scheme of the present invention is applied. The specific smart terminal may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0149] In one embodiment, a smart terminal is provided. The smart terminal includes a memory, a processor, and a quantum simulator implementation program stored in the memory and executable on the processor. When the quantum simulator implementation program is executed by the processor, the following operation instructions are performed:

[0150] Constructing a quantum bit gate operator, wherein the quantum bit gate operator is used to move data in a target device and update a state vector based on an operation bit of the quantum gate;

[0151] Constructing a quantum simulator, wherein the quantum simulator includes the quantum bit gate operator, and the quantum simulator is a software package for realizing quantum circuit simulation;

[0152] The above-mentioned quantum simulator is deployed to the above-mentioned target device, and the above-mentioned target device is the Ascend AI processor.

[0153] An embodiment of the present invention further provides a computer-readable storage medium, on which a quantum simulator implementation program is stored. When the quantum simulator implementation program is executed by a processor, the steps of any quantum simulator implementation method provided in the embodiment of the present invention are implemented.

[0154] Optionally, the above-mentioned intelligent terminal and computer-readable storage medium may also store a quantum simulator implementation program to implement the steps of the above-mentioned quantum simulator implementation method.

[0155] It should be understood that the serial numbers of the steps in the above embodiments do not imply a sequence of execution, and the execution sequence of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0156] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the above-mentioned device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0157] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0158] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0159] In the embodiments provided by the present invention, it should be understood that the disclosed apparatus / terminal equipment and method can be implemented in other ways. For example, the apparatus / terminal equipment embodiments described above are only illustrative, for example, the division of the above modules or units is only a logical function division, and in actual implementation, other division methods can be used, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.

[0160] If the above-mentioned integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The above-mentioned computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the above-mentioned computer program includes computer program code, and the above-mentioned computer program code can be in source code form, object code form, executable file or some intermediate form. The above-mentioned computer-readable medium may include: any entity or device capable of carrying the above-mentioned computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the above-mentioned computer-readable storage medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction.

[0161] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, it should be understood by those skilled in the art that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features therein may be replaced by equivalents. However, these modifications or replacements do not 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.

Claims

1. A method for implementing a quantum simulator, characterized in that: The method comprises: Constructing a quantum bit gate operator, wherein the quantum bit gate operator is used to move data in a target device and update a state vector based on an operation bit of a quantum gate; Constructing a quantum simulator, wherein the quantum simulator includes the quantum bit gate operator, and the quantum simulator is a software package for realizing quantum circuit simulation; Deploy the quantum simulator to the target device, where the target device is an Ascend AI processor; The qubit gate operator is used to perform a single qubit gate operation on a qubit, and the qubit gate operator performs quantum simulation based on the following steps: Obtain the type of data to be calculated and the number of cores and buffer size of the Ascend AI processor; Starting multi-core processing based on the number of cores and dividing the state vectors corresponding to the data to be calculated; The divided state vector is moved from the global memory to the output buffer, and then the matrix-vector multiplication operation corresponding to the quantum bit gate operation is performed to obtain the calculated data; The calculated data is moved from the output buffer to the global memory.

2. The method for implementing a quantum simulator according to claim 1, characterized in that: The quantum bit gate operator includes a distributed single quantum bit gate operator, a low-order single quantum bit gate operator and a high-order single quantum bit gate operator corresponding to different operation bits respectively.

3. The method for implementing a quantum simulator according to claim 2, characterized in that: The constructing of the quantum bit gate operator comprises: Based on the quantum circuit and the target device, a distributed high operation bit range, a low operation bit range, and a non-distributed high operation bit range are obtained, wherein the operation bits in the distributed high operation bit range are operation bits that require distributed communication, the address distance corresponding to the operation bits in the low operation bit range is less than the minimum data handling scale of the Ascend AI processor, and the address distance corresponding to the operation bits in the non-distributed high operation bit range is not less than the minimum data handling scale of the Ascend AI processor and there is no distributed communication; A distributed single-qubit gate operator corresponding to the distributed high operation bit range, a low-order single-qubit gate operator corresponding to the low operation bit range, and a high-order single-qubit gate operator corresponding to the non-distributed high operation bit range are constructed respectively.

4. The method for implementing a quantum simulator according to claim 3, characterized in that: The distributed single-qubit gate operator performs data transfer based on the following steps: Acquire data to be calculated, wherein the data to be calculated includes a local state vector and a paired state vector, the paired state vector is a state vector paired with the local state vector obtained through distributed communication, and the local state vector and the paired state vector are located in different Ascend AI processors; Based on the length of the local state vector and a preset fragment length, the local state vector and the paired state vector are moved in a loop. In each loop, data fragments at the same position and the same length in the local state vector and the paired state vector are moved from the global memory to the output buffer for calculation. After the calculation is completed, the calculated data is moved from the output buffer to the global memory.

5. The method for implementing a quantum simulator according to claim 3, characterized in that: The high-order single-qubit gate operator performs data transfer based on the following steps: Acquire data to be calculated, wherein the data to be calculated is a local state vector, and the local state vector includes two paired state vectors located in the same Ascend AI processor and having a distance no less than a minimum data transfer scale of the Ascend AI processor; Obtaining the length of continuously transmitted data segments and the interval between adjacent continuous data segments; Based on the length of the continuously transmitted data segments and the interval between adjacent continuous data segments, data is loaded from different positions of the local state vector in the global memory into the output buffer for calculation, and after the calculation is completed, the calculated data is moved from the output buffer to the global memory.

6. The method for implementing a quantum simulator according to claim 3, characterized in that: The low-order single-qubit gate operator performs data transfer based on the following steps: Acquire data to be calculated, wherein the data to be calculated is a local state vector, and the local state vector includes two paired state vectors located in the same Ascend AI processor and having a distance less than a minimum data transfer scale of the Ascend AI processor; Loading data from the 0th element of the local state vector in the global memory into the output buffer to obtain a 0th array; Loading data from element No. 1 of the local state vector in the global memory into the output buffer to obtain a first array; Loading data from the -1th element of the local state vector in the global memory into the output buffer to obtain a second array; After calculating the upper half of the unitary matrix based on the zeroth array and the first array to obtain a third array, and calculating the lower half of the unitary matrix based on the second array and the zeroth array to obtain a fourth array, bit-by-bit selection is performed on the third array and the fourth array to obtain a fifth array, and the data in the fifth array is moved from the output buffer to the global memory.

7. The method for implementing a quantum simulator according to claim 1, characterized in that: The quantum simulator is constructed, wherein the quantum simulator includes the quantum bit gate operator, and the quantum simulator is a software package for implementing quantum circuit simulation, including: Based on the quantum bit gate operator packaging, a software package that can be deployed, compiled and executed on the Ascend AI processor is generated as the quantum simulator.

8. A quantum simulator implementation device, characterized in that: The device comprises: An operator construction module, used to construct a quantum bit gate operator, wherein the quantum bit gate operator is used to move data in a target device and update a state vector based on an operation bit of a quantum gate; A quantum simulator building module, used to build a quantum simulator, wherein the quantum simulator includes the quantum bit gate operator, and the quantum simulator is a software package for realizing quantum circuit simulation; A deployment module, used to deploy the quantum simulator to the target device, wherein the target device is an Ascend AI processor; The qubit gate operator is used to perform a single qubit gate operation on a qubit, and the qubit gate operator performs quantum simulation based on the following steps: Obtain the type of data to be calculated and the number of cores and buffer size of the Ascend AI processor; Starting multi-core processing based on the number of cores and dividing the state vectors corresponding to the data to be calculated; The divided state vector is moved from the global memory to the output buffer, and then the matrix-vector multiplication operation corresponding to the quantum bit gate operation is performed to obtain the calculated data; The calculated data is moved from the output buffer to the global memory.

9. A quantum simulation method, characterized in that: The quantum simulation method is applied to an Ascend AI processor deployed with a quantum simulator as described in any one of claims 1 to 7, and the method includes: Get the data to be calculated; The quantum bit gate operator is called to move the data to be calculated and update the state vector.

10. An intelligent terminal, characterized in that: The intelligent terminal includes a memory, a processor, and a quantum simulator implementation program stored in the memory and executable on the processor. When the quantum simulator implementation program is executed by the processor, the steps of the quantum simulator implementation method according to any one of claims 1 to 7 are implemented.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a quantum simulator implementation program, and when the quantum simulator implementation program is executed by the processor, the steps of the quantum simulator implementation method according to any one of claims 1 to 7 are implemented.