Quantum program execution method, quantum program compilation method, quantum computer and program
The method allows quantum computers to execute complex programs with control flow by identifying and converting quantum circuits based on measurement results and connectivity, enhancing program execution accuracy and efficiency.
Patent Information
- Application Number
- JP2023538916
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Priority Date
- 2021-12-08
- Filing Date
- 2022-10-21
- Publication Date
- 2024-11-06
- Estimated Expiration
- 2042-10-21
AI Technical Summary
Quantum computers are limited in executing complex quantum programs due to their restricted connectivity between qubits, which prevents the execution of programs with control flow.
A method and device for executing quantum programs by identifying an initial quantum circuit, obtaining measurement results, selecting target circuits based on connection relationships, and executing mapping conversion circuits to follow the control flow, along with a compilation method to convert logical circuits into physical circuits compatible with the quantum computer's connectivity.
Enables the execution of complex quantum programs with control flow on quantum computers, optimizing data processing and ensuring accurate program execution.
Smart Images

Figure 0007577912000018 
Figure 0007577912000019 
Figure 0007577912000020
Abstract
Description
[Technical field]
[0001] This application claims priority to a Chinese patent application filed with the China Patent Office on December 8, 2021, bearing application number 202111492774.7 and entitled "Method for executing quantum programs and method for compiling quantum programs," the entire contents of which are incorporated herein by reference.
[0002] The present application relates to the field of quantum technology, and in particular to a method, an apparatus, a quantum computer, a storage medium, and a computer program for executing a quantum program, as well as a method, an apparatus, a quantum computer, a storage medium, and a computer program for compiling a quantum program. [Background technology]
[0003] A quantum computer is a computer that can execute quantum programs using quantum bits as the basic memory unit. In a quantum computer, the connectivity between quantum bits is limited, so only two quantum bit gate transformations can be performed between specific quantum bit pairs.
[0004] At present, the execution of a quantum program on a quantum computer is achieved by compiling the quantum program into a quantum circuit consisting of basic gates that can be executed on a quantum computer, and then sequentially executing the compiled quantum circuits to realize the execution task of the quantum program on the quantum computer. However, the current processing method for quantum programs can only execute quantum programs with a single processing flow on a quantum computer, but cannot execute complex quantum programs with control flows on a quantum computer. Summary of the Invention [Problem to be solved by the invention]
[0005] An object of the embodiments of the present application is to provide a method, an apparatus, a quantum computer, a computer-readable storage medium, and a computer program for executing a quantum program, which can be executed according to a control flow, as well as a method, an apparatus, a quantum computer, a computer-readable storage medium, and a computer program for compiling a quantum program. The objective is to provide the following. [Means for solving the problem]
[0006] The present application provides a method for executing a quantum program, the method comprising: The initial quantum circuit among the physical quantum circuits included in the target quantum program is set as the current quantum circuit; Execute the current quantum circuit and obtain the quantum measurement result; Select a target quantum circuit that matches the quantum measurement result from among candidate quantum circuits that have a connection relationship with the current quantum circuit, and the connection relationship matches a control flow corresponding to the target quantum program; and The method includes executing a mapping conversion circuit between the current quantum circuit and the target quantum circuit to make the target quantum circuit the current quantum circuit, returning to and continuing the execution of the current quantum circuit to obtain a quantum measurement result (step), and obtaining a program execution result when an execution termination condition is satisfied.
[0007] The present application further provides an apparatus for executing a quantum program, the apparatus comprising: An initial quantum circuit identification (recognition) module for identifying an initial quantum circuit among physical quantum circuits included in the target quantum program as the current quantum circuit; a quantum measurement result acquisition module for executing the current quantum circuit to obtain the quantum measurement result; a quantum circuit selection module for selecting a target quantum circuit that matches the quantum measurement result from among candidate quantum circuits that have a connection relationship with the current quantum circuit, the connection relationship matching a control flow corresponding to the target quantum program; and A target quantum circuit update module is included for making the target quantum circuit a current quantum circuit by executing a mapping conversion circuit between the current quantum circuit and the target quantum circuit, jumping to the quantum measurement result acquisition module for continued execution, and acquiring a program execution result when an execution termination condition is satisfied.
[0008] The present application further provides a method for compiling a quantum program, the method comprising: Determine a plurality of logical quantum circuits included in the initial quantum program and connection relationships between each of the logical quantum circuits according to a control flow of the initial quantum program; Converting each of the logical quantum circuits into a physical quantum circuit according to an execution condition corresponding to a quantum program execution environment; Based on the mapping between the physical quantum circuits of the connection relationships between the logical quantum circuits, converting the quantum bit mapping relationship between the two physical quantum circuits having a connection relationship to obtain a mapping conversion circuit; and A target quantum program including the physical quantum circuit and the mapping transformation circuit is a compilation result of the initial quantum program.
[0009] The present application further provides a quantum program compilation apparatus, the apparatus comprising: a logical quantum circuit determination module for determining a plurality of logical quantum circuits included in an initial quantum program and connection relationships between the logical quantum circuits according to a control flow of the initial quantum program; a quantum circuit conversion module for converting each of the logical quantum circuits into a physical quantum circuit respectively according to an execution condition corresponding to a quantum program execution environment; A mapping relationship conversion module for converting a quantum bit mapping relationship between two physical quantum circuits having a connection relationship based on a mapping between the physical quantum circuits of the connection relationship between the logical quantum circuits to obtain a mapping conversion circuit; and A compilation result determination module is provided for determining a target quantum program including the physical quantum circuit and the mapping transformation circuit as a compilation result of the initial quantum program.
[0010] The present application further provides a quantum computer, the quantum computer including a memory and one or more processors, the memory storing computer-readable instructions, and the one or more processors implementing the steps of each of the method embodiments described above when executing the computer-readable instructions.
[0011] The present application further provides a computer-readable storage medium having computer-readable instructions stored thereon, the computer-readable instructions being capable of implementing the steps of each of the method embodiments described above when executed by one or more processors.
[0012] The present application further provides a computer program, said computer program comprising computer readable instructions which, when executed by one or more processors, implement the steps of each of the method embodiments described above.
[0013] The details of one or more embodiments of the present application are provided in the drawings and description that follow. Other features, objects, and advantages of the present application will become apparent from the description, drawings, and claims. [Brief description of the drawings]
[0014] In order to more clearly describe the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings that need to be used in the description of the embodiments. It is obvious that the drawings in the following description are only some embodiments of the present application, and those skilled in the art can obtain other drawings based on these drawings without creative work. [Figure 1] FIG. 1 is a diagram illustrating an application environment of a quantum program execution method in one embodiment. [Diagram 2] FIG. 1 is a diagram showing a flow of a quantum program execution method in one embodiment. [Diagram 3] FIG. 2 is a diagram illustrating a quantum circuit according to an embodiment. [Figure 4]FIG. 2 is a diagram showing a directed graph corresponding to the control flow of a quantum program in one embodiment. [Diagram 5] FIG. 2 is a configuration diagram showing the connection relationship of physical quantum bits of a quantum computer in one embodiment. [Figure 6] FIG. 1 is a diagram showing a flow of a quantum program compilation method in one embodiment. [Figure 7] FIG. 13 illustrates changing qubit mapping relationships with exchange gates in one embodiment. [Figure 8] FIG. 13 is a diagram showing a quantum circuit conversion result in one embodiment. [Figure 9] FIG. 1 is a diagram showing a flow of a quantum program compilation method in one embodiment. [Figure 10] FIG. 1 is a diagram showing a flow of a quantum program execution method in one embodiment. [Figure 11] FIG. 1 is a diagram showing the relationship between the compilation process and the execution process of a quantum program in one embodiment. [Figure 12] FIG. 1 is a block diagram showing a configuration of a quantum program execution device in one embodiment. [Figure 13] FIG. 1 is a block diagram showing a configuration of a quantum program compilation device in one embodiment. [Figure 14] FIG. 1 is a diagram illustrating an internal configuration of a quantum computer according to an embodiment. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0015] In order to make the purpose, technical solution and advantages of the present application clearer, the present application will be described in more detail below in conjunction with the drawings and examples, in which the specific examples described herein are only used to interpret the present application and are not intended to limit the present application.
[0016] The quantum program execution method provided in the embodiment of the present application can be used in an application environment as shown in FIG. 1. The application environment includes a classical computer 102 and a quantum computer 104. Among them, the quantum computer 104 can communicate with the classical computer 102 via a network, and the quantum computer is a physical device that performs high-speed mathematical and logical operations and stores and processes quantum information according to the laws of quantum mechanics. The classical computer is relative to the quantum computer, and the classical computer may be called an ordinary computer, which is a mature computer at present. The qubits in the quantum computer may not be completely connected, that is, only some of the qubits can be connected. The quantum computer can only perform quantum operations between qubit pairs having a connection relationship or on a single qubit. Usually, when designing a hybrid quantum algorithm, the qubit connection relationship of the quantum computer is not taken into consideration, so that a quantum program composed of a logical quantum circuit may not be directly executed on a quantum computer. Therefore, a conversion is performed on the logical quantum circuit, and the converted quantum circuit (for convenience of explanation, the converted quantum circuit may be referred to as a physical quantum circuit hereinafter) is made to satisfy the qubit connection relationship, so that it can be executed on a quantum computer. In the application scenario shown in FIG. 1, the process of performing transformations on an initial quantum program consisting of a logical quantum circuit can be executed by the classical computer in FIG.
[0017] In one embodiment, the classical computer is communicatively connected to the quantum computer, the initial quantum program is stored in the classical computer, and the classical computer communicates with the quantum computer to transmit the initial quantum program to the quantum computer, which stores its own quantum bit connection relationship. The quantum computer compiles the initial quantum program according to the quantum bit connection relationship of the quantum computer to obtain and execute a target quantum program including a physical quantum circuit and a mapping conversion circuit.
[0018] In another embodiment, the classical computer is communicatively connected to the quantum computer, and the classical computer obtains an initial quantum program and a qubit connection relationship of the quantum computer through interaction with the quantum computer, and the classical computer performs a transformation on the logical quantum circuit according to the qubit connection relationship of the quantum computer to obtain a physical quantum circuit, and then transmits the target quantum program consisting of the physical quantum circuit to the quantum computer for execution.
[0019] Specifically, the classical computer compiles the acquired quantum program according to the quantum bit connection relationship of the quantum computer to obtain a compiled target quantum program, and then sends it to the quantum computer for execution. The process of the quantum computer executing the target quantum program includes the following steps: the quantum computer sets an initial quantum circuit among the physical quantum circuits included in the target quantum program as the current quantum circuit; executes the current quantum circuit to obtain a quantum measurement result; selects a target quantum circuit that matches the quantum measurement result from among the candidate quantum circuits that have a connection relationship with the current quantum circuit, and the connection relationship matches the control flow corresponding to the target quantum program; and executes a mapping conversion circuit between the current quantum circuit and the target quantum circuit to set the target quantum circuit as the current quantum circuit; when the execution termination condition is not satisfied, returns to the step of executing the current quantum circuit and obtaining the quantum measurement result and continues execution; and obtains the program execution result when the execution termination condition is satisfied.
[0020] Among them, the classical computer 102 may be, but is not limited to, various personal computers, notebook computers, smartphones, tablet computers, IoT devices, and portable wearable devices, and the IoT devices may be smart speakers, smart TVs, smart air conditioners, smart car devices, etc. The portable wearable devices may be smart watches, smart bracelets, head-mounted devices, etc. The quantum computer 104 is a physical device that performs high-speed mathematical and logical operations and stores and processes quantum information according to the laws of quantum mechanics.
[0021] In one embodiment, as shown in FIG. 2, a method for executing a quantum program is provided. The method is described below by taking the quantum computer in FIG. 1 as an example, and specifically includes the following steps:
[0022] Step 202: An initial quantum circuit among the physical quantum circuits included in the target quantum program is set as the current quantum circuit.
[0023] Among them, the target quantum program is a quantum program that satisfies the connectivity between quantum bits in a quantum computer and can be executed by a quantum computer. Specifically, the target quantum program may be a quantum program written according to the connectivity between quantum bits in a quantum computer, or may be a quantum program obtained by compiling a pre-written initial quantum program based on the connectivity between quantum bits in a quantum computer. The control execution method of each quantum circuit in the target quantum program is a classical control method, which refers to a control method that determines the execution operation of the next step in real time based on the execution result of the previous step.
[0024] A quantum circuit is a component part of a quantum program, and a quantum program may contain one quantum circuit, or two or more quantum circuits. A quantum circuit includes multiple qubits and a series of quantum gates and quantum measurement operations.
[0025] Among them, a quantum bit is the basic unit by which a quantum computer stores data, and a quantum program performs corresponding operations on the quantum bits to achieve specific functions. A quantum gate can achieve a specific quantum operation by changing the state of the quantum bit it acts on. According to the number of quantum bits it acts on, quantum gates can be divided into one-qubit gates and two-qubit gates. A one-qubit gate acts on only one specific quantum bit and can only change the state of that quantum bit, while a two-qubit gate acts on two quantum bits and can change the states of these two quantum bits. Two-qubit gates specifically include controlled NOT gates, exchange gates, etc. In the quantum circuit shown in Figure 3, the quantum circuit has two quantum bits q 0 , q 1 where each line represents a corresponding qubit, and module A represents qubit q 0 represents a general one-qubit gate acting on the qubit q, and module B represents a one-qubit gate acting on the qubit q 0 , q 1 and module C represents a controlled-NOT gate acting on the qubit q 0 Represents a measurement operation on
[0026] There are two special quantum circuits in the target quantum program including classical control, which are the initial quantum circuit and the final quantum circuit. The initial quantum circuit represents the first quantum circuit that the quantum program needs to execute in the initial state, and the final quantum circuit represents the quantum program that ends after executing the corresponding quantum circuit, that is, the last quantum circuit that the quantum program needs to execute. The quantum computer can determine the initial quantum circuit and the final quantum circuit in the quantum program based on the identification of the mark corresponding to the initial quantum circuit. The mark corresponding to the initial quantum circuit and the mark corresponding to the final quantum circuit can be marked in the process of writing the quantum program.
[0027] Specifically, after the quantum computer obtains a target quantum program that satisfies the connectivity between quantum bits in the quantum computer, it identifies an initial quantum circuit from among the quantum circuits included in the target quantum program, sets the initial quantum circuit as the current quantum circuit, and sequentially performs quantum operations on each quantum bit in the initial quantum circuit in accordance with the arrangement order of the quantum gates in the initial quantum circuit.
[0028] Step 204: Execute the current quantum circuit to obtain a quantum measurement result.
[0029] Among them, the current quantum circuit is the quantum circuit that needs to be currently executed in the execution process of the quantum program, and the current quantum circuit can change along with the execution process. Specifically, after the execution of the current quantum circuit is completed, the next quantum circuit waiting to be executed is expressed as the new current quantum circuit.
[0030] Specifically, the execution process of the current quantum circuit changes the state of the quantum bit by sequentially performing quantum operations corresponding to the quantum gates on the state of the quantum bit according to the arrangement order of the quantum gates in the currently executed quantum circuit. Note that, since every quantum operation of the quantum gate can change the state of the quantum bit that it acts on, there may be differences in the quantum measurement results performed on the same quantum bit each time.
[0031] A quantum measurement result is a result obtained after performing a quantum measurement process on a quantum bit, where quantum measurement is a special quantum operation, and the specific processing process of quantum measurement involves performing a predetermined adjustment and control on one or more specific quantum bits to obtain a measurement result on the quantum bit state, where the value of the measurement result is random, and the probability of obtaining a certain result is related to the state of the measured quantum bit.
[0032] After performing a quantum measurement operation on a quantum bit, the state of the measured quantum bit may also change randomly. Each quantum circuit in the target quantum program has a corresponding quantum measurement operation, and after the execution of one quantum circuit is completed, the quantum measurement result is read based on the quantum measurement operation performed on one or more quantum bits in the quantum circuit, and the quantum circuit that needs to be executed thereafter is determined.
[0033] Specifically, after the quantum computer determines the quantum circuit represented by the current quantum circuit, it launches (starts) an execution process for the quantum circuit, and according to the arrangement order of the quantum gates in the quantum circuit, executes the corresponding quantum operation by the quantum gate to change the state of the quantum bit, and then reads the quantum measurement result corresponding to the quantum circuit from the quantum gate for performing quantum measurement.
[0034] Step 206: A target quantum circuit that matches the quantum measurement result is selected from among the candidate quantum circuits that have a connection relationship with the current quantum circuit, and the connection relationship matches the control flow corresponding to the target quantum program.
[0035] Among them, the candidate quantum circuit is a quantum circuit that has a connection relationship with the current quantum circuit. Specifically, the quantum computer determines the quantum circuit that has a connection relationship with the current quantum circuit based on the control flow corresponding to the target quantum program, and the quantum circuit that has the connection relationship is the candidate quantum circuit. The quantum measurement result can be represented by a string of characters, each character in the string represents the measurement result of the target quantum bit to be measured, the number of digits in the string can be related to the number of the target quantum bits to be measured, and the number of the target quantum bits to be measured can be determined based on the number of candidate quantum circuits that have a connection relationship with the current quantum circuit.
[0036] The control flow corresponding to the target quantum program is used to represent the execution order of the quantum circuits, and the connection relationship between the quantum circuits is determined according to a preset execution order. The connection relationship between the quantum circuits can be obtained by connecting two quantum circuits that need to be executed sequentially according to the preset execution order between the quantum circuits. For example, when writing a quantum program, if it is set that quantum circuit A is executed first and then quantum circuit B is executed, the connection relationship between quantum circuit A and quantum circuit B can be determined by connecting quantum circuit A and quantum circuit B according to the set execution order. Note that the connection relationship is unidirectional (one-way), and the same quantum circuit may connect multiple quantum circuits or may be connected to multiple quantum circuits. For example, quantum circuit 1, quantum circuit 2, and quantum circuit 3 are all connected to quantum circuit 4, and quantum circuit 4 is connected to quantum circuit 5 and quantum circuit 6, respectively. When the quantum computer completes the execution of quantum circuit 4, it determines in real time which of quantum circuit 5 and quantum circuit 6 is the quantum circuit to be executed next based on the current execution result of quantum circuit 4.
[0037] Specifically, the quantum computer determines candidate quantum circuits that have a connection relationship with the current quantum circuit, and selects a target quantum circuit that matches the quantum measurement result from among the candidate quantum circuits based on the quantum measurement result corresponding to the current quantum circuit. In a specific application, the candidate quantum circuits that have a connection relationship with the current quantum circuit can be determined in addition to a directed graph that represents the control flow corresponding to the target quantum program.
[0038] In a specific application, the control flow corresponding to the target quantum program can be represented by a directed graph, in which a node represents a specific quantum circuit, and an outgoing edge of the node corresponds to a quantum measurement result of the quantum circuit. The destination node to which the outgoing edge points represents the quantum circuit that needs to be executed after the measurement result is obtained. In addition, the directed graph needs to further define two special nodes, which are an initial node and an end node. The initial node represents the initial quantum circuit that the quantum program needs to execute in the initial state, and the end node represents the end quantum circuit of the quantum program, and the out-degree of the end node is 0, and the out-degree refers to the number of outgoing edges of the node. Figure 4 is a directed graph representing a classical control flow, and as shown in Figure 4, the node with 0 is the initial node, and the node with 7 is the end node. The 0 node and the 1 node are connected by two directed arrows, and the outgoing edge from the 0 node to the 1 node represents the execution of the quantum circuit included in the 1 node after completing the execution of the quantum circuit included in the 0 node. The outgoing edge from the 1 node to the 0 node represents the execution of the quantum circuit included in the 0 node after completing the execution of the quantum circuit included in the 1 node.
[0039] Step 208: A mapping conversion circuit between the current quantum circuit and the target quantum circuit is executed to make the target quantum circuit the current quantum circuit.
[0040] If the execution end condition is not satisfied, the process returns to step 204 for continued execution, and if the execution end condition is satisfied, the process proceeds to step 210.
[0041] Step 210: The program execution result is obtained.
[0042] Among them, the mapping conversion circuit is an intermediate circuit for connecting two physical quantum circuits, and the mapping conversion circuit can realize the conversion of the final qubit mapping relationship of the source physical quantum circuit and the initial qubit mapping relationship of the target physical quantum circuit. The mapping conversion circuit is executed to realize the switching of the physical quantum circuit, thereby updating the current quantum circuit. The execution end condition refers to the end condition for terminating the processing process of executing the current quantum circuit and returning to obtaining the quantum measurement result. Specifically, the execution end condition may be that there is no candidate quantum circuit having a connection relationship with the current quantum circuit, that is, the current quantum circuit is the end quantum circuit in the quantum program. The execution result obtained when the execution end condition is satisfied is the result obtained after completing the execution of all quantum circuits in the quantum program, that is, completing the execution of the end quantum program.
[0043] Specifically, the quantum computer sets the target quantum circuit as the current quantum circuit, executes the quantum circuit represented by the current quantum circuit to obtain a quantum measurement result corresponding to the quantum circuit, and determines whether a candidate quantum circuit exists that has a connection relationship with the current quantum circuit. If the determination result is that a candidate quantum circuit exists, it selects a target quantum circuit that matches the quantum measurement result from among the candidate quantum circuits that have a connection relationship with the current quantum circuit, continues to set the target quantum circuit as the current quantum circuit, and repeatedly executes the circuit until the determination result is that the circuit does not exist. If the determination result is that the circuit does not exist, it feeds back the execution result at the end of the quantum program execution.
[0044] In the above-mentioned quantum program execution method, the initial quantum circuit among the physical quantum circuits included in the target quantum program is set as the current quantum circuit, thereby determining the execution start point of the quantum program, and executing the current quantum circuit to obtain a quantum measurement result, thereby selecting a target quantum circuit that matches the quantum measurement result from among the candidate quantum circuits that have a connection relationship with the current quantum circuit, and selecting the target quantum circuit based on the quantum measurement result, thereby realizing the execution of the quantum circuit based on the control flow, and executing the mapping conversion circuit between the current quantum circuit and the target quantum circuit to make the target quantum circuit the current quantum circuit, thereby realizing the execution of the connection between different physical quantum circuits, and returning to and continuing to execute the current quantum circuit to obtain the quantum measurement result, thereby obtaining the program execution result when the execution end condition is satisfied, and in this way, the quantum computer executes a complex quantum program having a control flow, and the occupation of data processing resources can be simplified, so that the quantum computer can accurately execute a complex quantum program having a control flow according to the control flow.
[0045] In one embodiment, executing a mapping conversion circuit between the current quantum circuit and the target quantum circuit to make the target quantum circuit the current quantum circuit, returning to and continuing the execution of the step of executing the current quantum circuit to obtain a quantum measurement result, and obtaining a program execution result when an execution termination condition is satisfied includes: when the target quantum circuit is not an end quantum circuit, setting the target quantum circuit as the current quantum circuit, returning to and continuing the execution of the step of executing the current quantum circuit to obtain a quantum measurement result; and, when the target quantum circuit is an end quantum circuit, executing the end quantum circuit and obtaining the execution result of the target quantum program.
[0046] Wherein, the finished quantum circuit refers to the last quantum circuit executed in the target quantum program, and the result after the execution of the finished quantum circuit is the execution result of the target quantum program. The quantum computer can determine whether the target quantum circuit is a finished quantum circuit based on the identification of the mark corresponding to the finished quantum circuit. Wherein, the mark corresponding to the finished quantum circuit can be marked in the process of writing the quantum program.
[0047] Specifically, in the iterative update process of the current quantum circuit, the quantum computer judges whether the target quantum circuit is a finished quantum circuit, and when the target quantum circuit is not a finished quantum circuit, the target quantum circuit is set as the current quantum circuit, and a target quantum circuit that matches the quantum measurement result is selected from among the candidate quantum circuits that have a connection relationship with the current quantum circuit, and then cyclically executes until the judgment result is "the target quantum circuit is a finished quantum circuit", and when the target quantum circuit is a finished quantum circuit, the finished quantum circuit is executed to obtain the execution result of the target quantum program. Among them, whether the target quantum circuit is a finished quantum circuit may be determined based on a label corresponding to the quantum circuit, or may be determined based on whether a candidate quantum circuit with a connection relationship exists.
[0048] In a specific application, the quantum computer determines whether to end the cycle by determining whether the selected target quantum circuit is an end quantum circuit, and when the cycle is ended, the end quantum circuit can be executed to obtain the execution result of the target quantum program, in this way, when the end quantum circuit is executed, there is no need to obtain a quantum measurement result, and the amount of data processing can be reduced. The quantum computer determines whether to end the cycle by determining whether there is a candidate quantum circuit that has a connection relationship with the target quantum circuit to be executed, and when the cycle is ended, the execution result of the target quantum program can be directly obtained, in this way, the determination is made directly based on whether there is a candidate quantum circuit, which simplifies the identification process of the end quantum circuit and is favorable for improving data processing efficiency.
[0049] In this embodiment, the quantum computer determines whether the target quantum circuit is a finished quantum circuit, and when the target quantum circuit is not a finished quantum circuit, the target quantum circuit is set as the current quantum circuit, and the target quantum circuit is re-determined, thereby executing cyclically. By setting a cyclic end condition, it is possible to ensure that each quantum circuit in the target quantum program is executed accurately according to the control flow, and therefore the accuracy of the execution result of the target quantum program can be improved.
[0050] In one embodiment, the method of executing a quantum program further includes performing a quantum measurement operation on a target quantum bit in the current quantum circuit in response to an execution trigger event for the current quantum circuit.
[0051] Additionally, executing the current quantum circuit to obtain a quantum measurement includes obtaining a quantum measurement corresponding to the target qubit when execution of the current quantum circuit finishes.
[0052] Among them, the execution start event refers to a trigger event that starts the execution of the quantum circuit represented by the current quantum circuit. Specifically, when the quantum computer determines the target quantum circuit based on the quantum measurement result, it sets the target quantum circuit as the current quantum circuit and automatically triggers the execution start event for the target quantum circuit. A quantum measurement operation is a special quantum operation in the quantum circuit execution process, and the object of the quantum measurement operation is one or more target quantum bits in the quantum circuit. The target quantum bit may be set during the quantum program design, the quantum measurement operation is an operation on the current state of the target quantum bit, and the process of the quantum measurement operation can also change the state of the target quantum bit that is measured. The value of the quantum measurement result is random, and the probability of obtaining a certain result is related to the state of the measured quantum bit, and after the measurement, the state of the measured quantum bit may also change randomly.
[0053] Specifically, the quantum computer performs a quantum measurement operation on a target quantum bit based on a quantum measurement quantum gate included in the quantum circuit represented by the current quantum circuit in response to a determination of an execution start event for the current quantum circuit triggered by the current quantum circuit. When the execution of the quantum circuit represented by the current quantum circuit is terminated, a quantum measurement result corresponding to the target quantum bit is obtained, and the current quantum circuit to be updated is determined based on the quantum measurement result. In concrete implementation, the quantum computer determines a target quantum gate for performing a measurement operation in the current quantum circuit and a target quantum bit matching the target quantum gate in response to an execution start event for the current quantum circuit, performs a measurement operation on the state data of the matched target quantum bit based on the target quantum gate, and obtains updated state data and a quantum measurement result.
[0054] In this embodiment, the quantum computer performs a quantum measurement operation on a target quantum bit based on the quantum measurement quantum gate included in the quantum circuit represented by the current quantum circuit in response to the determination of an execution activation event for the current quantum circuit triggered by the current quantum circuit, and obtains a quantum measurement result corresponding to the target quantum bit when the execution of the current quantum circuit is terminated, thereby ensuring the accuracy of the quantum measurement result.
[0055] In one embodiment, the number of target quantum bits is multiple, and obtaining a quantum measurement result corresponding to the target quantum bit when execution of the current quantum circuit is terminated includes reading binary bit data representing the quantum measurement result from each of the target quantum gates when execution of the current quantum circuit is terminated, and setting a binary bit string consisting of each binary bit data as the quantum measurement result.
[0056] Among them, binary bit data refers to bit data whose value is 0 or 1, and the quantum measurement result is represented as a binary classical bit string, the number of digits of which is equal to the number of measured quantum bits. For all measurement operations in a quantum program, the connection relationship between logical quantum circuits
[0057]
number
[0058] In this embodiment, by treating the quantum measurement result as a binary bit string consisting of binary bit data, the expression of the measurement result of the target quantum bit to be measured can be simplified and the number of target quantum bits to be measured can be effectively reduced, thereby improving the processing efficiency of the quantum measurement process.
[0059] In one embodiment, the method for executing a quantum program further includes a compilation process of a target quantum program, in which the compilation process of the target quantum program may be realized by a classical computer, and the classical computer sends the compiled target quantum program to a quantum computer for execution; or the compilation process of the target quantum program may be realized by a quantum computer, and the quantum computer directly executes the compiled target quantum program after compilation.
[0060] The quantum program compilation process specifically includes: a classical computer or a quantum computer compiles an initial quantum program according to the control flow of the initial quantum program based on the execution conditions corresponding to the quantum program execution environment to obtain a target quantum program, in which each physical quantum circuit included in the target quantum program corresponds to each node of the control flow, and the mapping conversion circuit between each physical quantum circuit corresponds to the connection relationship between each node.
[0061] Among them, the execution conditions corresponding to the quantum program execution environment are determined by the quantum computer that executes the target quantum program, and the execution conditions corresponding to different quantum computers may be different. The execution conditions may specifically be physical connection restriction conditions between each quantum bit in the quantum computer. The physical connection restriction conditions can be expressed by a configuration diagram of a quantum computer. The configuration diagram of a quantum computer is an undirected connection diagram, in which nodes represent physical quantum bits and edges represent connections of quantum bits, and gate conversion of two quantum bits can only be performed between physical quantum bits directly connected by edges. In the undirected connection diagram shown in FIG. 5, gate conversion of two quantum bits can only be performed between physical bits (v0, v1) and (v1, v2), and the corresponding gate conversion cannot be performed between (v0, v2).
[0062] An initial quantum program refers to a quantum algorithm designed without considering the physical connection constraints of a quantum computer. Compiling refers to the process of converting an initial quantum program designed without considering the physical connection constraints of a quantum computer into a target quantum program that can be executed on a quantum computer. The initial quantum program is composed of a logical quantum circuit, and a classical computer or a quantum computer can convert the initial quantum program composed of a logical quantum circuit so that the converted target quantum circuit satisfies the physical connectivity constraints of a quantum computer, thereby making it possible to be executed on a quantum computer.
[0063] The control flow of the initial quantum program may be realized by a subprogram for deriving a classical control flow, and thus a directed graph for representing the control flow of the initial quantum program can be obtained. The nodes in the directed graph and the directed connection relationships between the nodes can represent the quantum circuits and the connection relationships between the quantum circuits.
[0064] In one specific application, a classical computer or a quantum computer executes a classical control flow derivation subprogram for an input initial quantum program, and the data processing process of the classical control flow derivation subprogram includes the following: for each logical quantum circuit in the initial quantum program, generate a corresponding node; the node corresponding to the initial logical quantum circuit is called an initial node; the node corresponding to the final logical quantum circuit is called an final node; and for every measurement operation in the initial quantum program, generate an edge
[0065]
number
[0066] In this embodiment, a classical computer or a quantum computer compiles an initial quantum program according to the control flow of the initial quantum program based on execution conditions corresponding to the quantum program execution environment to obtain a target quantum program. This compilation method makes it possible to convert a quantum algorithm designed without taking into account the physical connection constraints of a quantum computer into a target quantum program that can be executed on a quantum computer, thereby reducing the constraints when designing a quantum program. For different quantum computers, it is only necessary to compile according to the corresponding physical connection constraints, which reduces the constraints when designing a quantum program and also expands (extends) the range in which quantum programs can be used.
[0067] In one embodiment, a quantum program compiling method is provided, as shown in Fig. 6. The quantum program compiling method can also be a specific implementation process of compiling an initial quantum program including a control flow according to an execution condition corresponding to a quantum program execution environment in the above-mentioned quantum program execution method to obtain a target quantum program. Hereinafter, the method will be described by taking the quantum computer in Fig. 1 as an example, and specifically includes the following steps.
[0068] Step 602: According to the control flow of the initial quantum program, a plurality of logical quantum circuits included in the initial quantum program and the connection relationships between each logical quantum circuit are determined.
[0069] Step 604: Convert each logical quantum circuit into a physical quantum circuit according to the execution conditions corresponding to the quantum program execution environment.
[0070] Step 606: Based on the mapping between the physical quantum circuits of the connection relationships between the logical quantum circuits, a conversion of the quantum bit mapping relationship is performed for the two physical quantum circuits having the connection relationship, to obtain a mapping conversion circuit.
[0071] Step 608: The target quantum program including the physical quantum circuit and the mapping transformation circuit is taken as the compilation result of the initial quantum program.
[0072] Among them, the execution conditions corresponding to the quantum program execution environment include the physical connection restriction conditions of the quantum computer, that is, the qubit connection relationship that matches the quantum computer. In the design of a quantum program, the qubit connection relationship of the quantum computer is usually not taken into consideration, and it is assumed by default that two-qubit gate transformation can be performed between any qubits. A quantum circuit designed based on this assumption is a logical quantum circuit, and the qubits included in the logical quantum circuit are logical qubits. Correspondingly, when all two-qubit gates in a quantum circuit satisfy the qubit connection relationship of a certain quantum computer, the quantum circuit is called a physical quantum circuit, and the qubits included in the physical quantum circuit are physical qubits.
[0073] Based on the qubit connection relationship of the quantum computer, the logical quantum circuit can be converted into a physical quantum circuit by qubit mapping. When the quantum computer executes a quantum program, it needs to map the qubits in the logical quantum circuit to physical qubits, and this process is called qubit mapping. By introducing an exchange gate into the physical circuit, one determined qubit mapping can be changed, and as shown in Figure 7, if the initial state of the qubit mapping is q 0 From v 0 Mapping to q 1 From v 1 Mapping to q 2 From v 2 and the exchange gate SWAP(v 0 ,v 1 ) to change the qubit mapping to q 0 From v 1 Mapping to q 1 From v 0 Mapping to q 2 From v 2 Let the symbol τ denote one qubit mapping, and τ(q) denote the corresponding physical qubit under that mapping for the logical qubit of q.
[0074] The number of logical qubits may be the same as or different from the number of physical qubits. When the numbers are the same, there may be a one-to-one correspondence between the logical qubits and the physical qubits. As shown in FIG. 7, in FIG. 0 is v 0 is mapped to q 1 is v 1 is mapped to q 2 is v 2 The number of physical qubits may be greater than the number of logical qubits, when the numbers are different. In this case, the logical qubits may be mapped to a portion of the physical qubits. For example, if a quantum computer includes 10 physical qubits, three physical qubits may be selected from the 10 physical qubits to have a one-to-one correspondence with the logical qubits.
[0075] The process of converting each logical quantum circuit into a physical quantum circuit is called quantum circuit conversion, which refers to the following: in order to execute a quantum circuit on a specific quantum computer, first determine an initial quantum bit mapping based on the configuration diagram of the physical quantum bits in the quantum computer, and then introduce a redundant exchange gate operation to convert the logical quantum circuit into an executable physical quantum circuit, so that the generated physical quantum circuit is functionally equivalent to the logical quantum circuit, and the two-qubit gate among them satisfies the connectivity constraints of the configuration diagram of the quantum computer.
[0076] A mapping conversion circuit is a quantum circuit for realizing qubit mapping conversion. Qubit mapping conversion refers to the conversion of two qubit mapping relations. Specifically, for two given qubit mapping relations, it is the process of converting one qubit mapping relation into another qubit mapping relation by introducing a series of exchange gate operations.
[0077] Specifically, a classical computer or a quantum computer obtains an initial quantum program, and determines a plurality of logical quantum circuits included in the initial quantum program and the connection relationships between each logical quantum circuit according to the control flow of the initial quantum program, and also constructs a directed graph by treating the logical quantum circuits as nodes and treating the connection relationships between each logical quantum circuit as connection edges between the nodes; after constructing the directed graph by treating the logical quantum circuits as nodes and treating the connection relationships between each logical quantum circuit as connection edges between the nodes, quantum circuit conversion is performed according to execution conditions corresponding to the quantum program execution environment based on each conversion waiting node of the directed graph, thereby converting the logical quantum circuits represented by each conversion waiting node into physical quantum circuits, and converting the first and last quantum bit mapping relationships for the physical quantum circuits connected to each conversion waiting connection edge based on each conversion waiting connection edge of the directed graph. , obtain a mapping conversion circuit, and specifically, for any one unconverted (before conversion) node of the directed graph, i.e., a logical quantum circuit that has not been converted to a physical quantum circuit, the classical computer or quantum computer converts each logical quantum circuit into a physical quantum circuit according to the execution conditions corresponding to the quantum program execution environment until the conversion of all nodes in the directed graph is completed; then, for any one unconverted edge of the directed graph, i.e., two physical quantum circuits for which the conversion of the quantum bit mapping relationship has not been performed and which have a connection relationship, the conversion of the first and last quantum bit mapping relationships is performed until the conversion of all unconverted edges in the directed graph is completed, and then, based on the directed graph of the converted nodes and the connecting edges of the nodes, a quantum program represented by the converted directed graph is obtained, which is the target quantum program after compilation.
[0078] In this embodiment, in the compilation stage, the classical computer or the quantum computer converts the initial quantum program at the logic level, including the classical control flow, into a set of physical quantum circuits that can be executed by the quantum computer through a quantum circuit conversion process and a conversion process of the first and last quantum bit mapping relationship; in the execution stage of the quantum program, the quantum computer calls the corresponding compiled next physical quantum circuit based on the measurement result of the physical quantum circuit. This ensures the execution process of one quantum program including classical control, and only requires compilation according to the corresponding physical connection restriction conditions for different quantum computers, thereby reducing the restrictions when designing a quantum program and expanding the scope of use of the quantum program.
[0079] In one embodiment, converting the quantum bit mapping relationship for two physical quantum circuits having a connection relationship based on the mapping between the physical quantum circuits of the connection relationship between each logical quantum circuit to obtain a mapping conversion circuit includes determining the connection relationship between the physical quantum circuits based on the mapping between the physical quantum circuits of the connection relationship between each logical quantum circuit; obtaining, from the two physical quantum circuits having the connection relationship, a last quantum bit mapping relationship corresponding to the source physical quantum circuit and a first quantum bit mapping relationship corresponding to the target physical quantum circuit; and obtaining a mapping conversion circuit that converts the last quantum bit mapping relationship into the first quantum bit mapping relationship by converting the mapping relationship.
[0080] Among them, the exchange gate is also called a swap gate (SWAP), and the operation object of the SWAP gate is two quantum bits, and the action (function / role) of the SWAP gate is to make two quantum bits exchange quantum bits with each other. Specifically, a classical computer or a quantum computer can determine the connection relationship between physical quantum circuits by realizing the mapping between the physical quantum circuits of the connection relationship based on the connection relationship between each logical quantum circuit, and for two physical quantum circuits having a connection relationship, each physical quantum circuit includes multiple quantum bits and quantum gates arranged in sequence, so that the last quantum bit mapping relationship corresponding to the source physical quantum circuit and the first quantum bit mapping relationship corresponding to the target (target) physical quantum circuit can be obtained from the two physical quantum circuits having a connection relationship based on the quantum bits and the quantum gates arranged in sequence. Corresponding physical quantum bits are determined according to the final quantum bit mapping relationship and the first quantum bit mapping relationship, an exchange gate is introduced between the determined physical quantum bits to obtain a mapping conversion circuit, and then conversion of the mapping relationship between the final quantum bit mapping relationship and the first quantum bit mapping relationship is realized based on the mapping conversion circuit, so that the connections between the physical quantum circuits can also be made to match the quantum bit connection relationships corresponding to the quantum computer, thereby allowing the physical quantum circuits to be executed sequentially.
[0081] In this embodiment, a classical computer or a quantum computer obtains, from two physical quantum circuits having a connection relationship, the last quantum bit mapping relationship corresponding to the source physical quantum circuit and the first quantum bit mapping relationship corresponding to the target physical quantum circuit; and introduces an exchange gate to construct a mapping conversion circuit and converts the quantum bit mapping relationship, thereby realizing the connection in the execution process of the two physical quantum circuits, and thus improving the reliability of the execution process of the quantum program.
[0082] In one embodiment, obtaining a mapping conversion circuit that converts the final quantum bit mapping relationship into the initial quantum bit mapping relationship by mapping relationship conversion includes: determining a first physical quantum bit from a configuration diagram representing an execution condition of a classical or quantum computer, where the first physical quantum bit is a physical quantum bit that does not affect the quantum bit connection relationship in the configuration diagram even if it is deleted from the configuration diagram; determining a logical quantum bit corresponding to the first physical quantum bit based on the final quantum bit mapping relationship, and determining a second physical quantum bit corresponding to the logical quantum bit based on the initial quantum bit mapping relationship; determining a connection path in the configuration diagram between the first quantum bit and the second quantum bit; and introducing an exchange gate according to the connection path, thereby obtaining a mapping conversion circuit that converts the final quantum bit mapping relationship into the initial quantum bit mapping relationship.
[0083] Among them, the configuration diagram is an undirected connection diagram for representing the connectivity of each physical qubit in a quantum computer, and the nodes in the configuration diagram respectively represent each physical qubit in a quantum computer, and the connection edges between the nodes represent the connectivity between the physical qubits represented by the connected nodes. A one-to-one correspondence can be established between the logical qubits and the physical qubits through a mapping relationship. Therefore, a logical qubit corresponding to the first physical qubit can be determined based on the last qubit mapping relationship and the first physical qubit, and a second physical qubit corresponding to the logical qubit can also be determined based on the logical qubit and the first qubit mapping relationship. The first physical qubit and the second physical qubit are two different qubits, and in practical applications, the names of the first physical qubit and the second physical qubit can be interchanged.
[0084] A connection path refers to a set of qubits consisting of an end qubit, an intermediate qubit, and an initial qubit obtained after connecting an end qubit and an initial qubit by increasing an intermediate qubit for an end qubit and an initial qubit that do not match the qubit connection relationship corresponding to a quantum computer. Introducing an exchange gate based on a connection path refers to introducing an exchange gate between adjacent qubits based on each qubit to be connected in sequence, which is represented by the connection path, so that a connection between the end qubit and the initial qubit is realized after being exchanged in sequence.
[0085] Specifically, a classical computer or a quantum computer can connect a physical qubit v according to the qubit connection relationship corresponding to the quantum computer. i and v j Build a path between
[0086]
number
[0087]
number
[0088]
number
[0089] In one specific application, a classical or quantum computer constructs an empty physical quantum circuit PC and simultaneously performs the current qubit mapping τ = τ ini By constructing a quantum computer, one target node is extracted from the configuration diagram that represents the quantum bit connections of the quantum computer, and v jand v j After deleting, it is necessary to satisfy that the configuration diagram is still a connection diagram, and then, from among the converted physical quantum circuits, fin (q)=v j Find one end qubit q that satisfies and also set the initial qubit v i = τ(q) and in the diagram, the physical quantum bit v i and v j and form a path between
[0090]
number
[0091]
number
[0092] In this embodiment, a classical computer or a quantum computer constructs a connection path, introduces an exchange gate between the terminal quantum bit and the starting quantum bit based on the connection path, and performs quantum bit mapping conversion on the terminal quantum bit and the starting quantum bit, thereby realizing a connection between the terminal quantum bit and the starting quantum bit and making it consistent with the original execution logic, thereby improving the reliability of the execution process of the quantum program.
[0093] In one embodiment, converting each logical quantum circuit into a physical quantum circuit according to an execution condition corresponding to the quantum program execution environment includes: determining a quantum bit connection relationship corresponding to the quantum program execution environment based on the quantum program execution environment; for each logical quantum circuit, performing quantum circuit conversion on the logical quantum circuit according to the quantum bit connection relationship to obtain a physical quantum circuit.
[0094] The quantum program execution environment refers to the execution environment provided by the quantum computer for executing the target quantum program after compilation. Since there are different connection relationships between the physical qubits in different quantum computers, it is necessary to obtain the qubit connection relationship corresponding to the quantum computer after determining the quantum computer that executes the target quantum program. Then, quantum circuit conversion is performed based on the qubit connection relationship.
[0095] Quantum circuit conversion is a process of converting a logical quantum circuit into an executable physical quantum circuit based on a configuration diagram showing the connection relationship between physical quantum bits in a specific quantum computer in order to execute the quantum circuit on the specific quantum computer. Specifically, for each logical quantum bit in the logical quantum circuit, one initial quantum bit mapping is determined, and a physical quantum bit that corresponds one-to-one to each logical quantum bit in the logical quantum circuit is determined, and then a redundant exchange gate operation is introduced to convert the logical quantum circuit into an executable physical quantum circuit, so that the generated physical quantum circuit is functionally equivalent to the logical quantum circuit, and the two-qubit gate in the physical quantum circuit satisfies the connectivity constraint of the quantum computer configuration diagram.
[0096] In one specific application, as shown in FIG. 8, a logical quantum circuit is 0 , q 1 , q 2 and the controlled NOT gate CNOT(q 1 ,q 2 ), CNOT(q 0 ,q 2 ), and the physical qubits in a quantum computer are v 0 , v 1 , v 2 Including v 1 is v 2 connected to v 0 is v 1 The process of quantum circuit conversion is to convert the initial qubit mapping to q 0 From v 0 Mapping to q 1 From v 1Mapping to q 2 From v 2 and SWAP(v 0 ,v 1 ) and qubit mapping is q 0 From v 1 Mapping to q 1 From v 0 Mapping to q 2 From v 2 At the same time, change the mapping to CNOT(v 1 ,v 2 ) is introduced, and the gate functions as a CNOT(q 0 ,q 2 ) for physical quantum circuits; 0 ,v 1 ) and qubit mapping is q 0 From v 0 Mapping to q 1 From v 1 Mapping to q 2 From v 2 At the same time, change the mapping to CNOT(v 1 ,v 2 ) is introduced, and the gate functions as a CNOT(q 1 ,q 2 ), which enables the conversion of a logical quantum circuit into a physical quantum circuit with the same functionality.
[0097] In this embodiment, a classical computer or a quantum computer determines a quantum bit connection relationship corresponding to the quantum program execution environment based on the quantum program execution environment; for each logical quantum circuit, a quantum circuit conversion is performed on the logical quantum circuit according to the quantum bit connection relationship, so that the converted physical quantum circuit is functionally the same as the logical quantum circuit and can be executed in a quantum program execution environment corresponding to the quantum computer, thereby improving the reliability of quantum program execution.
[0098] In one embodiment, for each logical quantum circuit, performing quantum circuit conversion on the logical quantum circuit in accordance with the quantum bit connection relationship to obtain a physical quantum circuit includes: sequentially determining, based on the arrangement order of each quantum gate in the logical quantum circuit, target physical quantum bits that have a mapping relationship with the logical quantum bits on which the quantum gates act, in accordance with the quantum bit connection relationship; adding the quantum gate to the target physical quantum bit corresponding to the acting logical quantum bit, and deleting the quantum gate from the logical quantum circuit; and obtaining a physical quantum circuit corresponding to the logical quantum circuit when the number of quantum gates in the logical quantum circuit becomes zero (0).
[0099] Among them, quantum gates are components of quantum circuits. Quantum gates act on qubits in a quantum circuit and change the state of the qubits they act on to realize specific quantum operations. According to the number of qubits they act on, quantum gates can be divided into one-qubit gates and two-qubit gates. A one-qubit gate acts on only one specific qubit and can change the state of only that qubit, a two-qubit gate acts on two qubits and can change the states of the two qubits, and two-qubit gates include controlled-not gates and exchange gates. Each quantum gate in a quantum circuit is arranged in order to represent a quantum operation performed on the qubits in sequence.
[0100] Specifically, a classical computer or a quantum computer sequentially maps the logical qubits on which the quantum gates act to physical qubits that satisfy the qubit connection relationship according to the arrangement order of each quantum gate in the logical quantum circuit, thereby realizing the same quantum operation for the physical qubits as for the logical qubits in the physical quantum circuit, and in order to accurately realize the mapping for the logical qubits on which each quantum gate acts and to realize the same function in the physical quantum circuit after mapping, a quantum gate corresponding to the mapped logical qubit is deleted from the logical quantum circuit and a quantum gate is added to the physical qubit that has a mapping relationship with the logical qubit, thereby expressing the synchronous structure of the quantum gates. The number of quantum gates in the logical quantum circuit gradually decreases with the deletion process, and when the number of quantum gates in the logical quantum circuit becomes zero, a physical quantum circuit including each physical qubit and a quantum gate acting on the physical qubit is obtained.
[0101] In one specific application, a classical computer or a quantum computer generates an initial qubit mapping τ based on the logical quantum circuit LC and the quantum computer configuration diagram. ini and the mapping is q i v i Then, build one empty physical quantum circuit PC and map the current qubit mapping τ = τ ini The quantum gates of the LC are arranged sequentially from left to right according to the order of execution. Each time, a quantum gate is taken from the leftmost side of the logical quantum circuit LC and denoted as G(). For the logical quantum bits on which G() acts, a physical quantum bit that has a one-to-one mapping to the logical quantum bit is determined until there are no more quantum gates available for extraction into LC, i.e., the number of quantum gates in LC becomes 0.
[0102] In this embodiment, by sequentially performing a mapping relationship transformation on the quantum bits on which the quantum gates act, and then adding quantum gates to the physical quantum bits obtained by the mapping, it is possible to make the physical quantum circuit obtained by the transformation functionally identical to a logical quantum circuit, thereby improving the reliability of quantum program execution.
[0103] In one embodiment, mapping a logical quantum bit operated on by a quantum gate to a physical quantum bit satisfying the quantum bit connection relationship includes, when the quantum gate is a 1-bit quantum gate having one logical quantum bit operated on, determining a physical quantum bit to be mapped to the logical quantum bit based on the quantum bit mapping relationship; and, when the quantum gate is a 2-bit quantum gate having two logical quantum bits operated on, determining a physical quantum bit to be mapped to the logical quantum bit by constructing a quantum bit mapping relationship and introducing an exchange gate to update the mapping relationship.
[0104] Among them, a one-qubit gate is a quantum gate that acts on one specific qubit and can change the state of only that qubit, while a two-qubit gate is a quantum gate that acts on two qubits and can change the states of both qubits.
[0105] There is a difference in the mapping method of the corresponding physical qubit between the one-qubit gate and the two-qubit gate. Specifically, since the one-qubit gate acts on one object and does not affect other qubits, the physical qubit corresponding to the logical qubit can be determined directly based on the mapping relationship between the logical qubit and the physical qubit that has been constructed. In contrast, the two-qubit gate acts on two objects and the qubit connection relationship needs to be considered during execution, so that an exchange gate needs to be introduced to update the mapping relationship so that the physical qubit corresponding to the logical qubit after the mapping relationship has been updated can realize the same quantum operation as the logical qubit.
[0106] Specifically, the classical computer or quantum computer determines whether the quantum gate is a 1-qubit gate or a 2-qubit gate based on the number of logical qubits that the quantum gate acts on. When the quantum gate is a 1-bit quantum gate with one logical qubit acting on it, it finds the current corresponding mapping relationship of the logical qubit, and determines the physical qubit to be mapped to the logical qubit based on the found mapping relationship. Specifically, when the mapping relationship of the logical qubit that the 1-bit quantum gate acts on has not yet been updated, the current corresponding mapping relationship of the logical qubit is the constructed initial mapping relationship, and when the mapping relationship has already been updated, the current corresponding mapping relationship of the logical qubit is the updated mapping relationship. When the quantum gate is a 2-bit quantum gate with two logical qubits acting on it, it builds a qubit mapping relationship and introduces an exchange gate to update the mapping relationship, thereby determining the physical qubit to be mapped to the logical qubit.
[0107] In one specific application, a classical computer or a quantum computer generates an initial qubit mapping τ based on the logical quantum circuit LC and the quantum computer configuration diagram. ini and the mapping is q i v i Then, build one empty physical quantum circuit PC and map the current qubit mapping τ = τ ini For a quantum gate G() in a logical quantum circuit LC, if G() is a one-qubit gate G(q) acting on a logical qubit q, add G(τ(q)) to the end of PC, where τ(q) is the physical qubit that is mapped to the logical qubit q, and τ represents the mapping relationship. i ,q j ) acting on a two-qubit gate G(q i ,q j ), then the physical qubit τ(q i ) and τ(q j) and build a path between
[0108]
number
[0109]
number
[0110] In this embodiment, the classical computer or quantum computer determines whether the quantum gate is a one-qubit gate or a two-qubit gate based on the number of logical qubits that the quantum gate acts on, and performs different processing on different qubit gates. Based on the feature that the one-qubit gate acts on only one object and does not affect other qubits, the physical qubit corresponding to the logical qubit is determined directly according to the mapping relationship between the logical qubit and the physical qubit that is constructed. Based on the feature that the two-qubit gate acts on two objects and the qubit connection relationship needs to be considered during execution, an exchange gate is introduced to update the mapping relationship, and the physical qubit corresponding to the logical qubit after the mapping relationship is updated can realize the same quantum operation as the logical qubit, thereby improving the accuracy of the execution of the quantum program.
[0111] In one embodiment, updating the mapping relationship by constructing a quantum bit mapping relationship and introducing an exchange gate includes: constructing an initial quantum bit mapping relationship to map two logical quantum bits acted upon by a two-bit quantum gate to a first physical quantum bit and a second physical quantum bit, respectively; determining a connection path between the first physical quantum bit and the second physical quantum bit according to the quantum bit connection relationship; introducing an exchange gate based on the connection path to update the initial quantum bit mapping relationship, thereby obtaining an updated quantum bit mapping relationship.
[0112] Among them, the first physical quantum bit and the second physical quantum bit are two different quantum bits, and in practical applications, the first physical quantum bit and the second physical quantum bit can be exchanged. The initial quantum bit mapping relationship can be constructed randomly, and only needs to satisfy the one-to-one corresponding relationship between the physical quantum bit and the logical quantum bit. The connection path refers to the result of connecting quantum bits by increasing an intermediate quantum bit for two quantum bits that cannot be directly connected. Introducing an exchange gate based on the connection path refers to introducing an exchange gate between adjacent quantum bits based on each quantum bit that is sequentially connected represented by the connection path, so that the connection of two quantum bits is realized after sequential exchange.
[0113] In one specific application, logical qubits (q i ,q j ) acting on a two-qubit gate G(q i ,q j ), the logical qubit q i and q j The physical qubit τ(q i ) and τ(q j ) and then calculate the physical quantum bit τ(q i ) and τ(q j ) and build a path between
[0114]
number
[0115]
number
[0116]
number
[0117] In this embodiment, a connection path is constructed, intermediate quantum bits are added to connect physical quantum bits, and based on each quantum bit that is sequentially connected as represented by the connection path, an exchange gate is introduced between adjacent quantum bits to update the mapping relationship, thereby realizing the connection of the physical quantum bits after sequential exchange and mapping update, and enabling the operation corresponding to the original logical quantum bit to be realized, thereby ensuring the accuracy of the execution results of the quantum program.
[0118] In one specific embodiment, as shown in Figure 9, a quantum program compilation method is provided, which includes the following quantum program compilation process: The quantum program compilation process can be realized by a classical computer or a quantum computer, in which the classical computer or the quantum computer compiles the quantum program specifically includes the following steps:
[0119] Step 902: According to the control flow of the initial quantum program, a plurality of logical quantum circuits included in the initial quantum program and the connection relationships between each logical quantum circuit are determined.
[0120] Step 904: For each logical quantum circuit, based on the arrangement order of each quantum gate in the logical quantum circuit, sequentially determine target physical quantum bits that have a mapping relationship with the logical quantum bits on which the quantum gate acts, according to the quantum bit connection relationship corresponding to the quantum computer.
[0121] Step 906: When the quantum gate is a 1-bit quantum gate whose number of logical qubits it operates on is 1, determine a physical qubit that is mapped to the logical qubit based on the qubit mapping relationship.
[0122] Step 908: When the quantum gate is a 2-bit quantum gate whose number of logical qubits it operates on is 2, an initial qubit mapping relationship is constructed to map the two logical qubits operated by the 2-bit quantum gate to two physical qubits.
[0123] Step 910: Determine a connection path of two physical qubits according to the qubit connection relationship.
[0124] Step 912: Introduce exchange gates based on the connection paths to update the initial qubit mapping relationship, obtain an updated qubit mapping relationship, and determine the physical qubits that are mapped to the logical qubits based on the updated qubit mapping relationship.
[0125] STEP 914: The quantum gate is added to the target physical qubit that corresponds to the logical qubit that it operates on, and the quantum gate is removed from the logical quantum circuit.
[0126] Step 916: When the number of quantum gates in the logical quantum circuit becomes zero, a physical quantum circuit corresponding to the logical quantum circuit is obtained.
[0127] Step 918: Based on the mapping of the connection relationships between the logical quantum circuits to the physical quantum circuits, the connection relationships between the physical quantum circuits are determined.
[0128] Step 920: From the two physical quantum circuits having a connection relationship, obtain a last qubit mapping relationship corresponding to the source physical quantum circuit and a first qubit mapping relationship corresponding to the target physical quantum circuit.
[0129] Step 922: A first physical quantum bit is determined from the configuration diagram representing the execution conditions, the first physical quantum bit being a physical quantum bit that does not affect the quantum bit connection relationship in the configuration diagram after being deleted from the configuration diagram.
[0130] Step 924: Determine a logical qubit that corresponds to the first physical qubit based on the final qubit mapping relationship, and also determine a second physical qubit that corresponds to the logical qubit based on the initial qubit mapping relationship.
[0131] Step 926: A connection path between the first quantum bit and the second quantum bit in the configuration diagram is determined.
[0132] Step 928: Introducing exchange gates along the connection path to obtain a mapping conversion circuit that converts the final qubit mapping relationship to the initial qubit mapping relationship.
[0133] Step 930: Determine a target quantum program including a physical quantum circuit and a mapping transformation circuit.
[0134] In one specific embodiment, as shown in Figure 10, a quantum program execution method is provided, which includes the following quantum program execution process: The quantum program execution process can be realized by a quantum computer, and specifically includes the following steps:
[0135] Step 1002: The target quantum program after being compiled according to the quantum bit connection relationships is obtained, and an initial quantum circuit among the physical quantum circuits included in the target quantum program is set as the current quantum circuit.
[0136] Step 1004: In response to an execution trigger event for the current quantum circuit, a quantum measurement operation is performed on a target quantum bit in the current quantum circuit.
[0137] Step 1006: When the execution of the current quantum circuit is completed, read binary bit data representing the quantum measurement result from each target quantum gate.
[0138] Step 1008: A binary bit string consisting of each binary bit data is treated as a quantum measurement result.
[0139] Step 1010: A target quantum circuit that matches the quantum measurement result is selected from among the candidate quantum circuits that have a connection relationship with the current quantum circuit, and the connection relationship matches the control flow corresponding to the target quantum program.
[0140] Step 1012: When the target quantum circuit is not a finished quantum circuit, execute a mapping conversion circuit between the current quantum circuit and the target quantum circuit to make the target quantum circuit the current quantum circuit, perform a quantum measurement operation on the target quantum bit in the current quantum circuit, and return to step 1006.
[0141] Step 1014: When the target quantum circuit is a finished quantum circuit, the finished quantum circuit is executed to obtain the execution result of the target quantum program.
[0142] This application further provides an application scenario, in which the above-mentioned quantum program execution method is used. Specifically, the application of the quantum program execution method in the application scenario is as follows:
[0143] The execution process of a quantum program includes two stages, compilation and execution, as components of the quantum computing software to hardware interface. The compilation stage can convert a logic-level quantum algorithm including classical control flow into a set of executable physical quantum circuits, and the execution stage can invoke the corresponding compiled physical quantum circuits according to the measurement results, thereby ensuring the execution process of a quantum program including classical control.
[0144] As shown in FIG. 11, the processing of the quantum program includes a compilation process and an execution process. The input data is an initial quantum program including classical control and a configuration diagram for representing the physical quantum bit connection relationship in the quantum computer corresponding to the quantum computer, thereby realizing the compilation and execution of the input initial quantum program on the target quantum computer. The compilation process is responsible for converting the input initial quantum program including classical control into a series of physical circuits that can be executed by a specific quantum computer. For convenience of explanation, the physical quantum bit in the configuration diagram is denoted as v, and the logical quantum bit in the initial quantum program is denoted as q.
[0145] The specific steps of compilation are as follows:
[0146] S1: Execute a classical control flow derivation subprogram for the input initial quantum program to obtain a directed graph that matches the classical control flow of the initial quantum program.
[0147] Wherein, a node in the directed graph represents a specific logical quantum circuit, an outgoing edge of the node corresponds to a measurement result of the logical quantum circuit, and a destination node corresponding to the outgoing edge represents a logical quantum circuit that needs to be executed after the measurement result is obtained. Two special nodes are further defined in the directed graph, which are an initial node and an end node. The initial node includes a quantum circuit that needs to be executed in the initial state of the quantum program, and the end node has an out-degree of 0 and includes the end logical quantum circuit of the quantum program.
[0148] Specifically, the input of the classical control flow derivation subprogram is the initial quantum program, and its detailed steps are as follows:
[0149] S1-1: For each logical quantum circuit in the initial quantum program, generate one corresponding node; S1-2: A node corresponding to an initial logical quantum circuit is denoted as an initial node, and a node corresponding to an end logical quantum circuit is denoted as an end node; S1-3: For all measurement operations in the initial quantum program, the edge
[0150]
number
[0151] S2: Take any one untransformed node in the directed graph, denote it as i, and define the logical quantum circuit it represents as LC i He wrote; S3:LC i Execute the quantum circuit conversion subprogram on the i and PC i Let the initial and final qubit mappings of τ i ini and τ i fin It is written as follows.
[0152] Among them, the quantum circuit conversion subprogram is its configuration diagram, which first determines an initial quantum bit mapping, and then introduces redundant exchange gate operations to convert the logical quantum circuit into an executable physical quantum circuit, so that the generated physical quantum circuit is functionally equivalent to the logical quantum circuit, and the two-qubit gate in the circuit satisfies the connectivity constraints of the quantum computer configuration diagram, thereby allowing the quantum circuit to be executed on a specific quantum computer.
[0153] Specifically, the input of the quantum circuit conversion subprogram is a logical quantum circuit LC and a quantum computer configuration diagram, a physical quantum circuit PC that satisfies the configuration diagram connectivity constraint, and an initial quantum bit mapping τ ini and one final qubit mapping τ fin The detailed steps are as follows:
[0154] S3-1: The first qubit mapping relation τ ini and the mapping is i The physical qubit v i Map to; S3-2: Build one empty quantum circuit PC and simultaneously perform the current quantum bit mapping τ = τ ini Build; S3-3: Take one quantum gate from the leftmost side of the logical quantum circuit LC and write it as G(); S3-4: If G() is a one-qubit gate G(q) acting on a logical qubit q, add G(τ(q)) to the end of the physical quantum circuit PC, then proceed to S3-6; S3-5: G() is a logical quantum bit (q i ,q j ) acting on a two-qubit gate G(q i ,q j ), then there is one physical qubit τ(q i ) and τ(q j ) and construct a path between them.
[0155]
number
[0156]
number
[0157] S4: If the transformation of all nodes in the configuration diagram is completed, go to S5, otherwise go to S2; S5: Take any one untransformed edge in the directed graph and denote it as (i,j), where i is the source node of the edge and j is the destination node of the edge; S6: The first qubit mapping relation τ i fin Let be the initial mapping relation, and the final qubit mapping relation τ j ini , the qubit mapping conversion subprogram is executed to construct the mapping conversion circuit that needs to be executed to convert the qubits, and the PC i,j It is written as follows.
[0158] Specifically, the input of the qubit mapping conversion subprogram is one initial mapping relation τ ini , the goal mapping relation τ fin and the corresponding configuration diagram of a quantum computer. The output is a constructed mapping conversion physical circuit PC, which is a qubit mapping τ ini τ fin The detailed steps of the quantum bit mapping conversion subprogram are as follows:
[0159] S6-1: Construct one empty physical quantum circuit PC, and at the same time, the current quantum bit mapping relationship τ = τ ini Build; S6-2: Take one physical qubit from the diagram and vj and the physical qubit is v j After being deleted, the configuration diagram must still be a connection diagram; S6-3:τ fin (q)=v j Find a logical qubit q that satisfies v based on the current qubit mapping relation τ. i = τ(q); S6-4: Physical qubit v on the diagram i and v j Build a path between
[0160]
number
[0161]
number
[0162] The execution process can realize the execution process of one compiled quantum program on a specific quantum computer through a specific scheduling method. The execution process comes immediately after the compilation process, and the specific steps are as follows:
[0163] S7: Take the initial node of the compiled target quantum program as the current node and denote it as i; S8: The physical quantum circuit PC represented by node i in the quantum computeri and obtain the measurement result m; S9: If node i is an end node, go to S12, otherwise go to next step; S10: Determine the outgoing edge of its corresponding node i based on the result m, denoted as (i, j), where j is the destination node of the outgoing edge; S11: A mapping conversion circuit PC that needs to be executed for mapping conversion i,j Execute , assign j to i as the current node, and go to S8; S12: Feedback is given that the quantum program execution is completed, and the execution result is obtained.
[0164] The above-mentioned method can realize the compilation and execution of a quantum program including classical control, thus overcoming the problem that the conventional method can only process a single logical quantum circuit that does not include a classical control flow. A classical control flow is derived to represent the execution and scheduling process of a quantum program including classical control, and a set of physical quantum circuits is obtained by calling the quantum circuit conversion algorithm and the qubit mapping conversion algorithm multiple times, and these physical quantum circuits can satisfy the execution conditions of a specific quantum computer, so that the quantum program including classical control can be executed on a specific quantum computer.
[0165] In addition, although each step in the flowcharts according to the above-mentioned embodiments is shown in sequence according to the direction of the arrows, these steps do not necessarily have to be executed in sequence according to the order of the arrows. Unless otherwise specified, there is no strict order restriction for the execution of these steps, and these steps may be executed in other orders. In addition, at least some of the steps in the flowcharts according to the above-mentioned embodiments may include multiple steps or multiple stages, and these steps or stages do not necessarily have to be executed at the same time, but may be executed at different times, and these steps or stages do not necessarily have to be executed sequentially, but may be executed in order or alternately with other steps or at least some of the steps or stages in other steps.
[0166] Based on the same inventive concept, the embodiments of the present application further provide a quantum program execution device for implementing the above-mentioned quantum program execution method, and a quantum program compilation device for implementing the quantum program compilation method. The problem-solving implementation schemes provided by these devices are similar to the implementation schemes described in the above-mentioned methods, so the specific limitations of one or more quantum program execution devices and compilation device embodiments provided below can refer to the limitations of the above-mentioned quantum program execution method and compilation method, and detailed descriptions thereof will be omitted here.
[0167] In one embodiment, as shown in FIG. 12 , a quantum program execution device 1200 is provided, which includes an initial quantum circuit identification module 1202, a quantum measurement result acquisition module 1204, a quantum circuit selection module 1206 and a target quantum circuit update module 1208.
[0168] The initial quantum circuit identification module 1202 is used to set an initial quantum circuit among the physical quantum circuits included in the target quantum program as a current quantum circuit; The quantum measurement result acquisition module 1204 is used to execute the current quantum circuit and obtain the quantum measurement result; The quantum circuit selection module 1206 is used to select a target quantum circuit that matches the quantum measurement result from among candidate quantum circuits that have a connection relationship with the current quantum circuit, and the connection relationship matches a control flow corresponding to the target quantum program; The target quantum circuit update module 1208 is used to make the target quantum circuit the current quantum circuit by executing a mapping conversion circuit between the current quantum circuit and the target quantum circuit, jump to the quantum measurement result acquisition module to continue execution, and obtain the program execution result when the execution termination condition is satisfied.
[0169] In one embodiment, the quantum program execution device further includes a compilation module, which is used to compile the initial quantum program according to a control flow of the initial quantum program based on execution conditions corresponding to a quantum program execution environment to obtain a target quantum program, wherein each physical quantum circuit included in the target quantum program corresponds to each node of the control flow, and a mapping conversion circuit between each of the physical quantum circuits corresponds to the connection relationship between each of the nodes.
[0170] In one embodiment, the compilation module further includes a logical quantum circuit division module, a quantum circuit transformation module, a mapping relationship transformation module, and a synthesis module.
[0171] The logical quantum circuit division module is used to determine a plurality of logical quantum circuits included in an initial quantum program and connection relationships between each of the logical quantum circuits according to a control flow of the initial quantum program; a quantum circuit conversion module for converting each of the logical quantum circuits into a physical quantum circuit according to an execution condition corresponding to a quantum program execution environment; The mapping relationship conversion module is used to convert a quantum bit mapping relationship between two physical quantum circuits having a connection relationship based on the mapping between the physical quantum circuits of the connection relationship between each of the logical quantum circuits, to obtain a mapping conversion circuit; The synthesis module is used to determine a target quantum program that includes the physical quantum circuit and the mapping transformation circuit.
[0172] In one embodiment, the mapping relationship conversion module is further used to: determine a connection relationship between the physical quantum circuits based on mapping of the connection relationship between each of the logical quantum circuits between the physical quantum circuits; obtain a final qubit mapping relationship corresponding to a source physical quantum circuit and a first qubit mapping relationship corresponding to a target physical quantum circuit from two physical quantum circuits having a connection relationship; and obtain a mapping conversion circuit that converts the final qubit mapping relationship into the first qubit mapping relationship through a mapping relationship conversion.
[0173] In one embodiment, the mapping relationship conversion module is further used to: determine a first physical quantum bit from the configuration diagram representing the execution conditions, where the first physical quantum bit is a physical quantum bit that does not affect the quantum bit connection relationship in the configuration diagram after being deleted from the configuration diagram; determine a logical quantum bit corresponding to the first physical quantum bit based on the final quantum bit mapping relationship, and determine a second physical quantum bit corresponding to the logical quantum bit based on the initial quantum bit mapping relationship; determine a connection path between the first quantum bit and the second quantum bit in the configuration diagram; and introduce an exchange gate according to the connection path to obtain a mapping conversion circuit for converting the final quantum bit mapping relationship into the initial quantum bit mapping relationship.
[0174] In one embodiment, the quantum circuit conversion module is further used to: determine, based on a quantum program execution environment, a quantum bit connection relationship corresponding to the quantum program execution environment; and for each of the logical quantum circuits, perform quantum circuit conversion on the logical quantum circuit according to the quantum bit connection relationship to obtain a physical quantum circuit.
[0175] In one embodiment, the quantum circuit conversion module is further used to: sequentially determine, based on the quantum bit connection relationship, a target physical quantum bit that has a mapping relationship with the logical quantum bit acted upon by the quantum gate according to the arrangement order of each quantum gate in the logical quantum circuit; add the quantum gate to the target physical quantum bit corresponding to the acted logical quantum bit, and delete the quantum gate from the logical quantum circuit; and obtain a physical quantum circuit corresponding to the logical quantum circuit when the number of quantum gates in the current logical quantum circuit becomes zero.
[0176] In one embodiment, the quantum circuit conversion module is further used to: when the current quantum gate is a 1-bit quantum gate having a number of logical quantum bits acting on it being 1, determine a physical quantum bit to be mapped to the logical quantum bit based on a quantum bit mapping relationship; and when the current quantum gate is a 2-bit quantum gate having a number of logical quantum bits acting on it being 2, introduce an exchange gate to perform a mapping relationship update on the quantum bit mapping relationship, and determine a physical quantum bit to be mapped to the logical quantum bit based on the updated quantum bit mapping relationship.
[0177] In one embodiment, the quantum circuit conversion module is further used to: construct an initial qubit mapping relationship to map the two logical qubits operated by the 2-bit quantum gate to a first physical qubit and a second physical qubit, respectively; determine a connection path between the first physical qubit and the second physical qubit according to the qubit connection relationship; and introduce an exchange gate based on the connection path to update the initial qubit mapping relationship and obtain an updated qubit mapping relationship.
[0178] In one embodiment, the target quantum circuit update module is further used to do the following: when the current target quantum circuit is not a finished quantum circuit, set the target quantum circuit as the current quantum circuit and jump to the quantum measurement result acquisition module for continued execution; and when the current target quantum circuit is a finished quantum circuit, execute the finished quantum circuit and obtain the execution result of the target quantum program.
[0179] In one embodiment, the apparatus further includes a quantum measurement module that performs a quantum measurement operation on a target quantum bit in the current quantum circuit in response to an execution trigger event for the current quantum circuit; and obtains a quantum measurement result corresponding to the target quantum bit when execution of the current quantum circuit ends.
[0180] In one embodiment, the quantum measurement module is further used to: determine a target quantum gate for performing a measurement operation in the current quantum circuit and a target quantum bit matched to the target quantum gate in response to an execution trigger event for the current quantum circuit; and perform a measurement operation on state data of the target quantum bit matched to the target quantum gate based on the target quantum gate.
[0181] In one embodiment, the number of the target quantum bits is multiple, and the quantum measurement module is further used to: read binary bit data representing a quantum measurement result from each of the target quantum gates when the execution of the current quantum circuit is completed; and, a binary bit string consisting of each of the binary bit data is the quantum measurement result.
[0182] Each module in the quantum program execution device described above can be realized in whole or in part by software, hardware, or a combination thereof. Each module described above can be embedded in one or more processors in the quantum computer in the form of hardware, or can be stored in a memory in the quantum computer in the form of software, so that one or more processors can call each module described above and perform the operation corresponding to each module described above.
[0183] In one embodiment, as shown in FIG. 13, a quantum program compilation device 1300 is further provided, which includes a logical quantum circuit division module 1302, a quantum circuit conversion module 1304, a mapping relationship conversion module 1306 and an integration module 1308.
[0184] The logical quantum circuit division module 1302 is used to determine a plurality of logical quantum circuits included in the initial quantum program and connection relationships between each of the logical quantum circuits according to a control flow of the initial quantum program; The quantum circuit conversion module 1304 is used for converting each of the logical quantum circuits into a physical quantum circuit according to an execution condition corresponding to the quantum program execution environment; The mapping relationship conversion module 1306 is used to convert the quantum bit mapping relationship between two physical quantum circuits having a connection relationship based on the mapping between the physical quantum circuits of the connection relationship between each of the logical quantum circuits, and obtain a mapping conversion circuit; and The synthesis module 1308 is used to compile the initial quantum program into a target quantum program including the physical quantum circuit and the mapping transformation circuit.
[0185] In one embodiment, the quantum circuit conversion module is further used to: construct a directed graph with the logical quantum circuits as nodes and the connection relationships between the logical quantum circuits as connection edges between the nodes; and convert the logical quantum circuits represented by the conversion-waiting nodes into physical quantum circuits by performing quantum circuit conversion according to execution conditions corresponding to a quantum program execution environment based on the conversion-waiting nodes of the directed graph; and The mapping relationship conversion module is further used to: based on each connection edge of the directed graph waiting to be converted, perform first and last quantum bit mapping relationship conversion for the physical quantum circuits connected to each connection edge waiting to be converted to obtain a mapping conversion circuit.
[0186] In one embodiment, the mapping relationship conversion module is further used to: determine a connection relationship between the physical quantum circuits based on mapping of the connection relationship between each of the logical quantum circuits between the physical quantum circuits; obtain a final qubit mapping relationship corresponding to a source physical quantum circuit and a first qubit mapping relationship corresponding to a target physical quantum circuit from two physical quantum circuits having a connection relationship; and obtain a mapping conversion circuit that converts the final qubit mapping relationship into the first qubit mapping relationship through a mapping relationship conversion.
[0187] In one embodiment, the mapping relationship conversion module is further used to: determine a first physical quantum bit from a configuration diagram representing the execution conditions, where the first physical quantum bit is a physical quantum bit that does not affect the quantum bit connection relationship in the configuration diagram after being deleted from the configuration diagram; determine a logical quantum bit corresponding to the first physical quantum bit based on the final quantum bit mapping relationship, and determine a second physical quantum bit corresponding to the logical quantum bit based on the initial quantum bit mapping relationship; determine a connection path between the first quantum bit and the second quantum bit in the configuration diagram; and introduce an exchange gate based on the connection path to obtain a mapping conversion circuit that converts the final quantum bit mapping relationship to the initial quantum bit mapping relationship.
[0188] In one embodiment, the quantum circuit conversion module is further used to: determine, based on a quantum program execution environment, a quantum bit connection relationship corresponding to the quantum program execution environment; and for each of the logical quantum circuits, perform quantum circuit conversion on the logical quantum circuit according to the quantum bit connection relationship to obtain a physical quantum circuit.
[0189] In one embodiment, the quantum circuit conversion module is further used to: sequentially determine, based on the arrangement order of each quantum gate in the logical quantum circuit, a target physical quantum bit that has a mapping relationship with the logical quantum bit acted upon by the quantum gate according to a quantum bit connection relationship; add the quantum gate to the target physical quantum bit corresponding to the acted upon logical quantum bit, and delete the quantum gate from the logical quantum circuit; and obtain a physical quantum circuit corresponding to the logical quantum circuit when the number of quantum gates in the current logical quantum circuit becomes zero.
[0190] In one embodiment, the quantum circuit conversion module is further used to: when the quantum gate is a 1-bit quantum gate having a number of logical quantum bits acting on it being 1, determine a physical quantum bit to be mapped to the logical quantum bit based on a quantum bit mapping relationship; and when the quantum gate is a 2-bit quantum gate having a number of logical quantum bits acting on it being 2, introduce an exchange gate to perform a mapping relationship update on the quantum bit mapping relationship, and determine a physical quantum bit to be mapped to the logical quantum bit based on the updated quantum bit mapping relationship.
[0191] In one embodiment, the quantum circuit conversion module is further used to: establish an initial qubit mapping relationship, and map the two logical qubits acted upon by the 2-bit quantum gate to a first physical qubit and a second physical qubit respectively; determine a connection path between the first physical qubit and the second physical qubit according to the qubit connection relationship; and introduce an exchange gate based on the connection path to update the initial qubit mapping relationship and obtain an updated qubit mapping relationship.
[0192] In one embodiment, a quantum computer is provided, which may be a terminal, and its internal configuration diagram may be as shown in FIG. 14. The quantum computer includes one or more processors, a memory, a communication interface, a display screen, and an input device connected by a system bus. Among them, the one or more processors of the quantum computer are used to provide the functions of calculation and control. The memory of the quantum computer includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system (OS) and computer-readable instructions. The internal memory provides an environment for the execution of the OS and the computer-readable instructions in the non-volatile storage medium. The communication interface of the quantum computer is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be realized by WIFI, mobile cellular network, NFC, or other technologies. The computer-readable instructions can realize the execution method and compilation method of a quantum program when executed by one or more processors. The display screen of the quantum computer may be a liquid crystal display screen or an electronic ink display screen, and the input device of the quantum computer may be a touch layer covered by the display screen, or a button, trackball or touchpad installed on the outer shell of the quantum computer, or even an external keyboard, touchpad, mouse, etc.
[0193] As can be understood by those skilled in the art, the configuration shown in FIG. 14 is only a partial configuration of the technical solution of the present application, and does not limit the quantum computer to which the technical solution of the present application is applied; a specific quantum computer may include more or fewer components than those shown, may be combined with several components, or may have a different component arrangement.
[0194] In one embodiment, a quantum computer is further provided, comprising a memory and one or more processors, the memory storing computer readable instructions, the one or more processors performing the steps of each of the method embodiments described above when executing the computer readable instructions.
[0195] In one embodiment, a computer readable storage medium is further provided, storing computer readable instructions, the computer program being adapted to perform the steps of each of the method embodiments described above when executed by one or more processors.
[0196] In one embodiment, a computer program product or computer program is further provided, the computer program product or computer program comprising computer readable instructions stored in a computer readable storage medium, the computer readable instructions being read by one or more processors of a computing device from the computer readable storage medium, and the one or more processors executing the computer readable instructions, thereby causing the computing device to perform the steps of each of the method embodiments described above.
[0197] It should be noted that all user information (including, but not limited to, user device information, user personal information, etc.) and data (including, but not limited to, data for analysis, data for storage, data for display, etc.) related to this application is information and data that has been approved by the user or fully approved by each party.
[0198] As can be understood by those skilled in the art, the execution of all or part of the steps in the method of the above-mentioned embodiments may be completed by computer-readable instructions instructing related hardware, and the computer-readable instructions may be stored in a non-volatile computer-readable storage medium, and the computer-readable instructions may include the steps of each method embodiment as described above when executed. In particular, any reference to a storage device, database, or other medium in each embodiment provided in this application may include at least one of a non-volatile storage device and a volatile storage device. The non-volatile storage device may include a Read-Only Memory (ROM), a magnetic tape, a floppy disk, a flash memory, an optical disk, a high-density embedded non-volatile memory, a resistive memory (ReRAM), a magnetoresistive random access memory (MRAM), a volatile memory (V ... Random Access Memory), FRAM (Ferroelectric Random Access Memory), PCM (Phase Volatile memory may include Random Access Memory (RAM), external high-speed cache memory, etc. By way of example and not limitation, RAM may be Static Random Access Memory (SRAM). Memory, SRAM, Dynamic Random Access Memory The database according to the embodiments provided herein may be in various forms, such as a memory, a network ...
[0199] Although the preferred embodiment of the present application has been described above, the present application is not limited to this embodiment, and any modification to the present application falls within the technical scope of the present application as long as it does not depart from the spirit of the present application.
Claims
1. A method for executing a quantum program, performed by a quantum computer, comprising: A step of setting an initial quantum circuit among the physical quantum circuits included in the target quantum program as a current quantum circuit; executing the current quantum circuit to obtain a quantum measurement result; A step of selecting a target quantum circuit that matches the quantum measurement result from candidate quantum circuits having a connection relationship with the current quantum circuit, the connection relationship matching a control flow corresponding to the target quantum program; performing a mapping transformation circuit between the current quantum circuit and the target quantum circuit, so that the target quantum circuit becomes the current quantum circuit; and The method includes a step of returning to and continuing the step of executing the current quantum circuit and obtaining a quantum measurement result, and obtaining a program execution result when an execution termination condition is satisfied.
2. 2. The method of claim 1, Further comprising a step of compiling the initial quantum program to obtain a target quantum program according to a control flow of the initial quantum program based on an execution condition corresponding to a quantum program execution environment; A method according to claim 1, wherein each physical quantum circuit included in the target quantum program corresponds to each node of the control flow, and a mapping conversion circuit between each of the physical quantum circuits corresponds to a connection relationship between each of the nodes.
3. 3. The method of claim 2, The step of compiling an initial quantum program including a control flow to obtain a target quantum program according to an execution condition corresponding to the quantum program execution environment includes: determining a plurality of logical quantum circuits included in the initial quantum program and connection relationships between the logical quantum circuits according to a control flow of the initial quantum program; converting each of the logical quantum circuits into a physical quantum circuit according to an execution condition corresponding to a quantum program execution environment; A step of converting a quantum bit mapping relationship between two physical quantum circuits having a connection relationship based on a mapping between the physical quantum circuits of the connection relationship between the logical quantum circuits to obtain a mapping conversion circuit; and determining a target quantum program including the physical quantum circuit and the mapping transformation circuit.
4. 4. The method of claim 3, The step of converting a quantum bit mapping relationship between two physical quantum circuits having a connection relationship based on a mapping between the physical quantum circuits of the connection relationship between the logical quantum circuits to obtain a mapping conversion circuit includes: determining a connection relationship between the physical quantum circuits based on a mapping between the physical quantum circuits of a connection relationship between the logical quantum circuits; Obtaining a final qubit mapping relationship corresponding to the source physical quantum circuit and an initial qubit mapping relationship corresponding to the target physical quantum circuit from two physical quantum circuits having a connection relationship; and obtaining a mapping transformation circuit that transforms the final qubit mapping relationship to the initial qubit mapping relationship via a mapping relationship transformation.
5. 5. The method of claim 4, The step of obtaining a mapping transformation circuit for transforming the final qubit mapping relationship into the initial qubit mapping relationship by the mapping relationship transformation includes: determining a first physical quantum bit from the configuration diagram representing the execution conditions, the first physical quantum bit being a physical quantum bit that does not affect a quantum bit connection relationship in the configuration diagram after being deleted from the configuration diagram; determining a logical qubit corresponding to the first physical qubit based on the final qubit mapping relationship, and determining a second physical qubit corresponding to the logical qubit based on the initial qubit mapping relationship; determining a connection path between the first quantum bit and the second quantum bit in the configuration diagram; and introducing a commutation gate along the connection path to obtain a mapping conversion circuit that converts the final qubit mapping relationship to the initial qubit mapping relationship.
6. 4. The method of claim 3, The step of converting each of the logical quantum circuits into a physical quantum circuit in accordance with an execution condition corresponding to the quantum program execution environment includes: Determining a quantum bit connection relationship corresponding to the quantum program execution environment based on the quantum program execution environment; and For each of the logical quantum circuits, performing a quantum circuit transformation on the logical quantum circuit according to a qubit connection relationship to obtain a physical quantum circuit.
7. 7. The method of claim 6, For each of the logical quantum circuits, a step of performing quantum circuit conversion on the logical quantum circuit according to a quantum bit connection relationship to obtain a physical quantum circuit includes: sequentially determining target physical quantum bits having a mapping relationship with the logical quantum bits on which the quantum gates act, according to quantum bit connection relationships based on the arrangement order of each quantum gate in the logical quantum circuit; adding said quantum gate to a target physical qubit corresponding to its operating logical qubit and deleting said quantum gate from said logical quantum circuit; and 10. The method of claim 9, further comprising: obtaining a physical quantum circuit corresponding to said logical quantum circuit when a number of quantum gates in said logical quantum circuit becomes zero.
8. 8. The method of claim 7, The step of determining a target physical quantum bit having a mapping relationship with a logical quantum bit on which the quantum gate operates includes: When the quantum gate is a one-bit quantum gate having one logical quantum bit, determining a physical quantum bit to be mapped to the logical quantum bit based on a quantum bit mapping relationship; and The method includes, when the quantum gate is a 2-bit quantum gate in which the number of logical quantum bits that it operates on is 2, a step of performing a mapping relationship update on a quantum bit mapping relationship by introducing an exchange gate, and determining a physical quantum bit to be mapped to the logical quantum bit based on the updated quantum bit mapping relationship.
9. 9. The method of claim 8, The step of constructing the quantum bit mapping relationship and updating the mapping relationship by introducing an exchange gate includes: constructing an initial qubit mapping relationship to map two logical qubits on which the two-bit quantum gate operates to two physical qubits; determining a connection path between the two physical qubits according to the qubit connection relationship; and introducing an exchange gate based on the connection path to update the initial qubit mapping relationship to obtain an updated qubit mapping relationship.
10. 10. The method according to any one of claims 1 to 9, comprising: The step of executing a mapping conversion circuit between the current quantum circuit and the target quantum circuit to set the target quantum circuit as the current quantum circuit, returning to the step of executing the current quantum circuit to obtain a quantum measurement result and continuing to execute the current quantum circuit, and obtaining a program execution result when an execution end condition is satisfied, When the target quantum circuit is not a finished quantum circuit, executing a mapping conversion circuit between the current quantum circuit and the target quantum circuit, and setting the target quantum circuit as a current quantum circuit; Return to and continue executing the current quantum circuit to obtain a quantum measurement result; and When the target quantum circuit is a finished quantum circuit, the method includes executing the finished quantum circuit to obtain an execution result of the target quantum program.
11. 10. The method according to any one of claims 1 to 9, comprising: performing a quantum measurement operation on a target quantum bit in the current quantum circuit in response to an execution trigger event for the current quantum circuit; Executing the current quantum circuit to obtain a quantum measurement result includes: When execution of the current quantum circuit is completed, obtaining a quantum measurement corresponding to the target qubit.
12. 12. The method of claim 11, The step of performing a quantum measurement operation on a target quantum bit in the current quantum circuit in response to an execution trigger event for the current quantum circuit includes: determining a target quantum gate and a target qubit that matches the target quantum gate for performing a measurement operation in the current quantum circuit in response to an execution trigger event for the current quantum circuit; and performing a measurement operation on state data of a target quantum bit matched to the target quantum gate based on the target quantum gate.
13. 12. The method of claim 11, the number of target qubits is multiple; When execution of the current quantum circuit is completed, obtaining a quantum measurement corresponding to the target quantum bit includes: When the execution of the current quantum circuit is completed, reading binary bit data representing the quantum measurement result from the target quantum gate for performing the quantum measurement; and The method includes a step of making each of the binary bit data into a binary bit string as a quantum measurement result.
14. 1. A method for compiling a quantum program for execution by a classical or quantum computer, comprising: determining a plurality of logical quantum circuits included in the initial quantum program and connection relationships between the logical quantum circuits according to a control flow of the initial quantum program; converting each of the logical quantum circuits into a physical quantum circuit according to an execution condition corresponding to a quantum program execution environment; A step of converting a quantum bit mapping relationship between two physical quantum circuits having a connection relationship based on a mapping between the physical quantum circuits of the connection relationship between the logical quantum circuits to obtain a mapping conversion circuit; and A method comprising the step of compiling a target quantum program including the physical quantum circuit and the mapping transformation circuit into a result of the initial quantum program.
15. 15. The method of claim 14, The step of converting each of the logical quantum circuits into a physical quantum circuit according to an execution condition corresponding to the quantum program execution environment, and converting a quantum bit mapping relationship between two physical quantum circuits having a connection relationship based on a mapping between the physical quantum circuits of the connection relationship between the logical quantum circuits to obtain a mapping conversion circuit, constructing a directed graph by treating the logical quantum circuits as nodes and treating the connection relationships between the logical quantum circuits as connection edges between the nodes; A step of performing quantum circuit conversion according to an execution condition corresponding to a quantum program execution environment based on each conversion waiting node of the directed graph, and converting a logical quantum circuit represented by each conversion waiting node into a physical quantum circuit; and The method includes a step of performing a first and a last qubit mapping relationship conversion on a physical quantum circuit connected to each of the conversion-awaiting connection edges of the directed graph based on the conversion-awaiting connection edges to obtain a mapping conversion circuit.
16. An apparatus for executing a quantum program, an initial quantum circuit identification module for identifying an initial quantum circuit among the physical quantum circuits included in the target quantum program as a current quantum circuit; a quantum measurement result acquisition module for executing the current quantum circuit to obtain a quantum measurement result; A quantum circuit selection module for selecting a target quantum circuit that matches the quantum measurement result from candidate quantum circuits that have a connection relationship with the current quantum circuit, the connection relationship matching a control flow corresponding to the target quantum program; and a target quantum circuit update module for executing a mapping conversion circuit between the current quantum circuit and the target quantum circuit to make the target quantum circuit a current quantum circuit, jumping to the quantum measurement result acquisition module to continue execution, and obtaining a program execution result when a termination condition is satisfied.
17. An apparatus for compiling a quantum program, comprising: a logical quantum circuit determination module for determining a plurality of logical quantum circuits included in the initial quantum program and connection relationships between the logical quantum circuits according to a control flow of the initial quantum program; a quantum circuit conversion module for converting each of the logical quantum circuits into a physical quantum circuit according to an execution condition corresponding to a quantum program execution environment; A mapping relationship conversion module for converting a quantum bit mapping relationship between two physical quantum circuits having a connection relationship based on the mapping between the physical quantum circuits of the connection relationship between each of the logical quantum circuits to obtain a mapping conversion circuit; and The apparatus includes a compilation result determination module for determining a target quantum program including the physical quantum circuit and the mapping transformation circuit as a compilation result of the initial quantum program.
18. A quantum computer comprising: a storage device; and a processor connected to the storage device, The memory stores computer readable instructions, 10. A quantum computer, wherein the processor is configured to execute the computer readable instructions to implement the method of any one of claims 1 to 9.
19. A program for causing a computer to execute the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Mapping logical qubits on a quantum circuit
US20200218842A1
Computer Architecture for Executing Quantum Programs
US20210064350A1
System and method of optimizing instructions for quantum computers
US20210334081A1
