Method for executing quantum program and method for compiling quantum program
By screening and mapping quantum circuits in a quantum computer, the execution of complex quantum programs with control flow was realized, solving the problem that existing technologies can only run a single quantum program, and improving execution efficiency and accuracy.
Patent Information
- Application Number
- CN202111492774.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-08
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2041-12-08
AI Technical Summary
In current technology, quantum computers can only run quantum programs with a single processing flow and cannot execute complex quantum programs with control flow.
By using the physical quantum circuit of the target quantum program as the current quantum circuit, executing the quantum measurement results, and selecting the target quantum circuit that matches the measurement results from the candidate quantum circuits with connection relationships, connecting and executing the circuit through mapping transformation until the termination condition is met, the execution of the quantum program based on control flow is realized.
This enables quantum computers to execute complex quantum programs with control flow, simplifies the use of data processing resources, and improves the accuracy and efficiency of execution.
Smart Images

Figure CN116243974B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of quantum technology, and in particular to a method, apparatus, quantum computer, storage medium, and computer program product for executing a quantum program, as well as a method, apparatus, quantum computer, storage medium, and computer program product for compiling a quantum program. Background Technology
[0002] A quantum computer is a computer that uses qubits as its basic storage unit and can execute quantum programs. Because the connectivity between qubits is restricted in a quantum computer, gate transformations between two qubits can only be performed between specific pairs of qubits.
[0003] Currently, running quantum programs on quantum computers involves compiling the program into quantum circuits composed of basic gates executable on the quantum computer. The compiled quantum circuits are then executed sequentially to run the program. However, current methods of processing quantum programs only allow quantum computers to run programs with simple processing flows; complex quantum programs with control flow cannot be executed. Summary of the Invention
[0004] Therefore, it is necessary to provide a method, apparatus, quantum computer, computer-readable storage medium, and computer program product for executing quantum programs according to control flow, as well as a method, apparatus, quantum computer, computer-readable storage medium, and computer program product for compiling quantum programs, in response to the above-mentioned technical problems.
[0005] Firstly, this application provides a method for executing a quantum program. The method includes:
[0006] The initial quantum circuit in the physical quantum circuit contained in the target quantum program is taken as the current quantum circuit;
[0007] The quantum measurement result is obtained by executing the current quantum circuit;
[0008] From the candidate quantum circuits that have a connection relationship with the current quantum circuit, a target quantum circuit that matches the quantum measurement result is selected, wherein the connection relationship matches the control flow corresponding to the target quantum program;
[0009] By executing the mapping conversion circuit between the current quantum circuit and the target quantum circuit, the target quantum circuit is used as the current quantum circuit. The execution of the current quantum circuit is then returned to obtain the quantum measurement result and continue execution until the execution termination condition is met to obtain the program execution result.
[0010] Secondly, this application also provides a device for executing quantum programs. The device includes:
[0011] The initial quantum circuit in the physical quantum circuit contained in the target quantum program is taken as the current quantum circuit;
[0012] The quantum measurement result is obtained by executing the current quantum circuit;
[0013] From the candidate quantum circuits that have a connection relationship with the current quantum circuit, a target quantum circuit that matches the quantum measurement result is selected, wherein the connection relationship matches the control flow corresponding to the target quantum program;
[0014] By executing the mapping conversion circuit between the current quantum circuit and the target quantum circuit, the target quantum circuit is used as the current quantum circuit. The execution of the current quantum circuit is then returned to obtain the quantum measurement result and continue execution until the execution termination condition is met to obtain the program execution result.
[0015] Thirdly, this application also provides a quantum computer. The quantum computer includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to perform the following steps:
[0016] The initial quantum circuit in the physical quantum circuit contained in the target quantum program is taken as the current quantum circuit;
[0017] The quantum measurement result is obtained by executing the current quantum circuit;
[0018] From the candidate quantum circuits that have a connection relationship with the current quantum circuit, a target quantum circuit that matches the quantum measurement result is selected, wherein the connection relationship matches the control flow corresponding to the target quantum program;
[0019] By executing the mapping conversion circuit between the current quantum circuit and the target quantum circuit, the target quantum circuit is used as the current quantum circuit. The execution of the current quantum circuit is then returned to obtain the quantum measurement result and continue execution until the execution termination condition is met to obtain the program execution result.
[0020] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, performs the following steps:
[0021] The initial quantum circuit in the physical quantum circuit contained in the target quantum program is taken as the current quantum circuit;
[0022] The quantum measurement result is obtained by executing the current quantum circuit;
[0023] From the candidate quantum circuits that have a connection relationship with the current quantum circuit, a target quantum circuit that matches the quantum measurement result is selected, wherein the connection relationship matches the control flow corresponding to the target quantum program;
[0024] By executing the mapping conversion circuit between the current quantum circuit and the target quantum circuit, the target quantum circuit is used as the current quantum circuit. The execution of the current quantum circuit is then returned to obtain the quantum measurement result and continue execution until the execution termination condition is met to obtain the program execution result.
[0025] Fifthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, performs the following steps:
[0026] The initial quantum circuit in the physical quantum circuit contained in the target quantum program is taken as the current quantum circuit;
[0027] The quantum measurement result is obtained by executing the current quantum circuit;
[0028] From the candidate quantum circuits that have a connection relationship with the current quantum circuit, a target quantum circuit that matches the quantum measurement result is selected, wherein the connection relationship matches the control flow corresponding to the target quantum program;
[0029] By executing the mapping conversion circuit between the current quantum circuit and the target quantum circuit, the target quantum circuit is used as the current quantum circuit. The execution of the current quantum circuit is then returned to obtain the quantum measurement result and continue execution until the execution termination condition is met to obtain the program execution result.
[0030] The aforementioned quantum program execution method, apparatus, quantum computer, storage medium, and computer program product determine the starting point of the quantum program execution by using the initial quantum circuit in the physical quantum circuit contained in the target quantum program as the current quantum circuit. Quantum measurement results are obtained by executing the current quantum circuit. From candidate quantum circuits connected to the current quantum circuit, a target quantum circuit matching the quantum measurement results is selected. The selection of the target quantum circuit based on the quantum measurement results is then performed to achieve control-flow-based quantum circuit execution. By executing the mapping transformation circuit between the current quantum circuit and the target quantum circuit, the target quantum circuit is used as the current quantum circuit, enabling connection execution between different physical quantum circuits. Execution continues by returning to the current quantum circuit to obtain quantum measurement results, until the execution termination condition is met, thus obtaining the program execution result. This allows the quantum computer to execute complex quantum programs with control flow.
[0031] Sixthly, this application also provides a method for compiling a quantum program, the method comprising:
[0032] According to the control flow of the initial quantum program, determine the multiple logical quantum circuits contained in the initial quantum program and the connection relationships between the logical quantum circuits.
[0033] According to the execution conditions corresponding to the quantum program execution environment, each of the logical quantum circuits is converted into a physical quantum circuit;
[0034] Based on the mapping of the connection relationship between each logical quantum circuit to the physical quantum circuit, the quantum bit mapping relationship of two physical quantum circuits with connection relationship is transformed to obtain the mapping transformation circuit;
[0035] The target quantum program, which includes the physical quantum circuit and the mapping transformation circuit, is used as the compilation result of the initial quantum program.
[0036] In one embodiment, the mapping of the connection relationships between the logical quantum circuits to the physical quantum circuits, and the conversion of the qubit mapping relationship between two connected physical quantum circuits to obtain a mapping conversion circuit, includes:
[0037] 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.
[0038] From two physical quantum circuits that are connected, obtain the last qubit mapping relationship of the source physical quantum circuit and the initial qubit mapping relationship of the destination physical quantum circuit;
[0039] By transforming the mapping relationship, a mapping transformation circuit is obtained that converts the last qubit mapping relationship into the initial qubit mapping relationship.
[0040] In one embodiment, the step of obtaining a mapping conversion circuit that converts the final qubit mapping relationship into the initial qubit mapping relationship through mapping relationship conversion includes:
[0041] From the structure diagram representing the execution conditions, a first physical qubit is determined. The first physical qubit is a physical qubit whose deletion from the structure diagram does not affect the qubit connectivity in the structure diagram.
[0042] Based on the last qubit mapping relationship, the logical qubit corresponding to the first physical qubit is determined, and based on the initial qubit mapping relationship, the second physical qubit corresponding to the logical qubit is determined;
[0043] Determine the connection path between the first quantum bit and the second quantum bit in the structural diagram;
[0044] By introducing a switching gate according to the connection path, a mapping conversion circuit is obtained that converts the mapping relationship of the last qubit into the mapping relationship of the initial qubit.
[0045] In one embodiment, the step of converting each logical quantum circuit into a physical quantum circuit according to the execution conditions corresponding to the quantum program execution environment includes:
[0046] Based on the quantum program execution environment, determine the quantum bit connectivity relationship corresponding to the quantum program execution environment;
[0047] For each of the aforementioned logical quantum circuits, a quantum circuit conversion is performed on the logical quantum circuit according to the quantum bit connectivity to obtain a physical quantum circuit.
[0048] In one embodiment, the step of performing quantum circuit conversion on each logical quantum circuit according to the quantum bit connectivity to obtain a physical quantum circuit includes:
[0049] Based on the arrangement order of each quantum gate in the logical quantum circuit, and according to the quantum bit connectivity, the target physical quantum bits that have a mapping relationship with the logical quantum bits that act on the quantum gate are determined sequentially.
[0050] The quantum gate is added to the target physical qubit corresponding to the logic qubit it is applied to, and the quantum gate is removed from the logic quantum circuit.
[0051] When the number of quantum gates of the logical quantum circuit is zero, a physical quantum circuit corresponding to the logical quantum circuit is obtained.
[0052] In one embodiment, determining the target physical qubit that has a mapping relationship with the logical qubit acting on the quantum gate includes:
[0053] When the quantum gate is a single-bit quantum gate with a logic qubit quantity of 1, the physical qubit mapped by the logic qubit is determined based on the qubit mapping relationship.
[0054] When the quantum gate is a two-bit quantum gate with two logical qubits, the mapping relationship of the qubits is updated by introducing a swap gate, and the physical qubits mapped by the logical qubits are determined based on the updated qubit mapping relationship.
[0055] In one embodiment, the step of updating the mapping relationship by constructing a qubit mapping relationship and introducing a swap gate includes:
[0056] By constructing an initial quantum bit mapping relationship, the two logical quantum bits operated by the two-bit quantum gate are mapped to two physical quantum bits;
[0057] Determine the connection path between the two physical qubits according to the aforementioned qubit connectivity relationship;
[0058] A switching gate is introduced based on the connection path to update the initial qubit mapping relationship, resulting in an updated qubit mapping relationship.
[0059] Seventhly, this application also provides a quantum program compilation apparatus, the apparatus comprising:
[0060] A logic quantum circuit determination module is used to determine, according to the control flow of the initial quantum program, multiple logic quantum circuits contained in the initial quantum program and the connection relationships between the logic quantum circuits.
[0061] The quantum circuit conversion module is used to convert each of the logical quantum circuits into physical quantum circuits according to the execution conditions corresponding to the quantum program execution environment.
[0062] The mapping relationship conversion module is used to convert the qubit mapping relationship between two physical quantum circuits with a connection relationship based on the mapping of the connection relationship between each logical quantum circuit to the physical quantum circuit, so as to obtain the mapping conversion circuit;
[0063] The compilation result determination module is used to take the target quantum program, which includes the physical quantum circuit and the mapping transformation circuit, as the compilation result of the initial quantum program.
[0064] Eighthly, this application also provides a quantum computer. The quantum computer includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to perform the following steps:
[0065] According to the control flow of the initial quantum program, determine the multiple logical quantum circuits contained in the initial quantum program and the connection relationships between the logical quantum circuits.
[0066] According to the execution conditions corresponding to the quantum program execution environment, each of the logical quantum circuits is converted into a physical quantum circuit;
[0067] Based on the mapping of the connection relationship between each logical quantum circuit to the physical quantum circuit, the quantum bit mapping relationship of two physical quantum circuits with connection relationship is transformed to obtain the mapping transformation circuit;
[0068] The target quantum program, which includes the physical quantum circuit and the mapping transformation circuit, is used as the compilation result of the initial quantum program.
[0069] Ninthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, performs the following steps:
[0070] According to the control flow of the initial quantum program, determine the multiple logical quantum circuits contained in the initial quantum program and the connection relationships between the logical quantum circuits.
[0071] According to the execution conditions corresponding to the quantum program execution environment, each of the logical quantum circuits is converted into a physical quantum circuit;
[0072] Based on the mapping of the connection relationship between each logical quantum circuit to the physical quantum circuit, the quantum bit mapping relationship of two physical quantum circuits with connection relationship is transformed to obtain the mapping transformation circuit;
[0073] The target quantum program, which includes the physical quantum circuit and the mapping transformation circuit, is used as the compilation result of the initial quantum program.
[0074] Tenthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, performs the following steps:
[0075] According to the control flow of the initial quantum program, determine the multiple logical quantum circuits contained in the initial quantum program and the connection relationships between the logical quantum circuits.
[0076] According to the execution conditions corresponding to the quantum program execution environment, each of the logical quantum circuits is converted into a physical quantum circuit;
[0077] Based on the mapping of the connection relationship between each logical quantum circuit to the physical quantum circuit, the quantum bit mapping relationship of two physical quantum circuits with connection relationship is transformed to obtain the mapping transformation circuit;
[0078] The target quantum program, which includes the physical quantum circuit and the mapping transformation circuit, is used as the compilation result of the initial quantum program.
[0079] The aforementioned quantum program compilation method, apparatus, quantum computer, storage medium, and computer program product determine the multiple logical quantum circuits contained in the initial quantum program and the connection relationships between each logical quantum circuit according to the control flow of the initial quantum program. Based on the execution conditions corresponding to the quantum program execution environment, each logical quantum circuit is converted into a physical quantum circuit, enabling each logical quantum circuit to execute in the quantum program execution environment. Based on the mapping of the connection relationships between each logical quantum circuit to the physical quantum circuits, a qubit mapping relationship is converted between two connected physical quantum circuits to obtain a mapping conversion circuit. This allows the connected logical quantum circuits to execute continuously in the quantum program execution environment. The target quantum program, including the physical quantum circuits and the mapping conversion circuit, is used as the compilation result of the initial quantum program, enabling the compiled target quantum program with control flow to execute in the quantum computer. Attached Figure Description
[0080] Figure 1 This is an application environment diagram of a quantum program execution method in one embodiment;
[0081] Figure 2 This is a flowchart illustrating a method for executing a quantum program in one embodiment;
[0082] Figure 3 This is a schematic diagram of a quantum circuit in one embodiment;
[0083] Figure 4 This is a schematic diagram of the directed graph corresponding to the control flow of a quantum program in one embodiment;
[0084] Figure 5 This is a structural diagram illustrating the physical quantum bit connectivity of a quantum computer in one embodiment;
[0085] Figure 6 This is a flowchart illustrating a quantum program compilation method in one embodiment;
[0086] Figure 7 This is a schematic diagram illustrating how the quantum bit mapping relationship is changed through a swap gate in one embodiment;
[0087] Figure 8 This is a schematic diagram of the quantum circuit conversion result in one embodiment;
[0088] Figure 9 This is a flowchart illustrating a quantum program compilation method in one embodiment;
[0089] Figure 10 This is a flowchart illustrating a method for executing a quantum program in one embodiment;
[0090] Figure 11This is a schematic diagram illustrating the relationship between the compilation and execution processes of a quantum program in one embodiment;
[0091] Figure 12 This is a structural block diagram of a quantum program execution device in one embodiment;
[0092] Figure 13 This is a block diagram of a quantum program compilation device in one embodiment;
[0093] Figure 14 This is a diagram of the internal structure of a quantum computer in one embodiment. Detailed Implementation
[0094] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0095] The quantum program execution method provided in this application embodiment can be applied to, for example, Figure 1 The application environment shown includes a classical computer 102 and a quantum computer 104. The quantum computer 104 can communicate with the classical computer 102 via a network. A quantum computer is a physical device that performs high-speed mathematical and logical operations, stores and processes quantum information according to the laws of quantum mechanics. A classical computer, also known as a conventional computer, is a mature computing device. The qubits in a quantum computer may not be fully connected, meaning only some qubits can be connected. A quantum computer can only perform quantum operations on pairs of connected qubits or on individual qubits. Typically, when designing hybrid quantum algorithms, the qubit connectivity of the quantum computer is not considered, which may prevent quantum programs composed of logical quantum circuits from being directly executed in a quantum computer. Therefore, the logical quantum circuits can be transformed so that the transformed quantum circuits (for ease of description, the transformed quantum circuits will be referred to as physical quantum circuits in subsequent embodiments) satisfy the qubit connectivity requirements, thereby enabling execution in a quantum computer. Figure 1 The application scenario shown illustrates that the process of converting an initial quantum program composed of logic quantum circuits can be performed by... Figure 1 Classic computer execution.
[0096] In one embodiment, a classical computer and a quantum computer are communicatively connected. An initial quantum program is stored in the classical computer. The classical computer sends the initial quantum program to the quantum computer through interaction with it. The quantum computer stores its own qubit connectivity relationships. Based on the quantum computer's qubit connectivity relationships, the quantum computer compiles the initial quantum program to obtain a target quantum program containing physical quantum circuits and mapping transformation circuits, and then executes it.
[0097] In another embodiment, a classical computer and a quantum computer are communicatively connected. The classical computer obtains an initial quantum program and the quantum computer's qubit connectivity through interaction with the quantum computer. Based on the quantum computer's qubit connectivity, the classical computer converts the logical quantum circuits into physical quantum circuits and sends the target quantum program, constructed from these physical quantum circuits, to the quantum computer for execution.
[0098] Specifically, a classical computer compiles the acquired quantum program according to the quantum computer's qubit connectivity to obtain the compiled target quantum program, which is then sent to the quantum computer for execution. The execution process of the quantum computer for the target quantum program is as follows: the quantum computer takes the initial quantum circuit in the physical quantum circuit contained in the target quantum program as the current quantum circuit; it executes the current quantum circuit to obtain a quantum measurement result; from the candidate quantum circuits that have a connection relationship with the current quantum circuit, it selects the target quantum circuit that matches the quantum measurement result, and the connection relationship matches the control flow corresponding to the target quantum program; by executing the mapping transformation circuit between the current quantum circuit and the target quantum circuit, it takes the target quantum circuit as the current quantum circuit, returns to the execution of the current quantum circuit to obtain the quantum measurement result, and continues execution until the execution termination condition is met to obtain the program execution result.
[0099] The classical computer 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, and smart in-vehicle systems. Portable wearable devices can include smartwatches, smart bracelets, and head-mounted devices. The quantum computer 104 is a physical device that performs high-speed mathematical and logical operations, stores, and processes quantum information according to the laws of quantum mechanics.
[0100] In one embodiment, such as Figure 2 As shown, a method for executing a quantum program is provided, which can be applied to... Figure 1 Taking a quantum computer as an example, the following steps are included:
[0101] Step 202: Take the initial quantum circuit in the physical quantum circuit contained in the target quantum program as the current quantum circuit.
[0102] The target quantum program is a quantum program that can be executed in a quantum computer and satisfies the connectivity between qubits in the quantum computer. Specifically, the target quantum program can be a quantum program written according to the connectivity between qubits in the quantum computer, or it can be a quantum program obtained by compiling a pre-written initial quantum program based on the connectivity between qubits in the quantum computer. The execution control method of each quantum circuit in the target quantum program is classical control, which refers to a control method that determines the next execution action in real time based on the execution result of the previous step.
[0103] A quantum circuit is a component of a quantum program. A quantum program can include one quantum circuit, or two or more quantum circuits. A quantum circuit consists of qubits and a series of quantum gates and quantum measurement operations.
[0104] In a quantum computer, a qubit is the basic unit for storing data. Quantum programs perform specific functions by manipulating qubits. A quantum gate can change the state of the qubit it operates on, thus enabling specific quantum operations. Based on the number of qubits involved, quantum gates can be divided into single-qubit gates and two-qubit gates. A single-qubit gate operates on only one specific qubit and can only change the state of that qubit; a two-qubit gate operates on two qubits and can change the states of both qubits, such as the controlled NOT gate and the swapping gate. Figure 3 In the quantum circuit shown, the quantum circuit contains two qubits q0 and q1. Each line represents the corresponding qubit. Module A represents a general single-qubit gate acting on qubit q0. Module B represents a controlled NOT gate acting on qubits q0 and q1. Module C represents a measurement operation on qubit q0.
[0105] A target quantum program containing classical control contains two special quantum circuits: the initial quantum circuit and the termination quantum circuit. The initial quantum circuit represents the first quantum circuit to be executed in the initial state of the quantum program, while the termination quantum circuit indicates that the quantum program terminates after executing its corresponding quantum circuit. A quantum computer can determine the initial quantum circuit in a quantum program based on the identification of its corresponding identifier. This identifier can be added during the programming process of the quantum program.
[0106] Specifically, after acquiring the target quantum program that satisfies the connectivity between qubits in the quantum computer, the quantum computer identifies the initial quantum circuit from the quantum circuits contained in the target quantum program, uses the initial quantum circuit as the current quantum circuit, and performs quantum operations on each qubit in the initial quantum circuit in sequence based on the arrangement order of the quantum gates in the initial quantum circuit.
[0107] Step 204: Execute the current quantum circuit to obtain the quantum measurement result.
[0108] The current quantum circuit is the quantum circuit that needs to be executed during the execution of each quantum circuit in the quantum program. The current quantum circuit changes based on the execution process. After the execution of the current quantum circuit is completed, the next quantum circuit to be executed will be used as the new current quantum circuit.
[0109] Specifically, the execution process of the current quantum circuit is as follows: based on the arrangement order of the quantum gates in the currently executed quantum circuit, quantum operations corresponding to the quantum gates are sequentially performed on the state of the qubits to change the state of the qubits. It should be noted that since each quantum operation of a quantum gate changes the state of the qubit it operates on, the results of each quantum measurement performed on the same qubit may differ.
[0110] Quantum measurement results are used to characterize the quantum measurements performed on qubits. Quantum measurement is a special quantum operation that, by controlling one or more specific qubits, yields a measurement result for the state of the qubit. The value of the measurement result is random, and the probability of obtaining a certain result is related to the state of the measured qubit.
[0111] After a quantum measurement operation is performed on a qubit, the state of the measured qubit will also change randomly. Each quantum circuit in the target quantum program corresponds to a quantum measurement operation. After a quantum circuit is executed, the quantum measurement results are read out based on the quantum measurement operations performed on one or more qubits in the quantum circuit to determine the next quantum circuit to be executed.
[0112] Specifically, after determining the quantum circuit represented by the current quantum circuit, the quantum computer initiates an execution process for that quantum circuit. Based on the arrangement order of the quantum gates in the quantum circuit, it performs corresponding quantum operations through the quantum gates to change the state of the qubits, and reads the quantum measurement result corresponding to that quantum circuit from the quantum gate used for quantum measurement.
[0113] Step 206: From the candidate quantum circuits that have a connection relationship with the current quantum circuit, select the target quantum circuit that matches the quantum measurement result, and the connection relationship matches the control flow corresponding to the target quantum program.
[0114] In this context, candidate quantum circuits are those connected to the current quantum circuit. Specifically, the quantum computer, based on the control flow corresponding to the target quantum program, determines the quantum circuits connected to the current quantum circuit and designates these connected quantum circuits as candidate quantum circuits. Quantum measurement results can be represented by strings, where each character represents the measurement result of the target qubit. The number of bits in the string can be related to the number of target qubits being measured, which can be determined based on the number of candidate quantum circuits connected to the current quantum circuit.
[0115] The control flow corresponding to the target quantum program is used to characterize the execution order of quantum circuits. The connection relationship between quantum circuits is determined based on a pre-set execution order. By connecting two quantum circuits that need to be executed sequentially according to the pre-set execution order, the connection relationship between quantum circuits is obtained. For example, when writing a quantum program, if it is set that quantum circuit A is executed first and then quantum circuit B, then based on the set execution order, quantum circuit A is connected to quantum circuit B, thus determining the connection relationship between quantum circuit A and quantum circuit B. It should be noted that the connection relationship is unidirectional. The same quantum circuit can connect to multiple quantum circuits and can be connected by multiple quantum circuits. For example, quantum circuits 1, 2, and 3 are all connected to quantum circuit 4, and quantum circuit 4 is connected to quantum circuits 5 and 6 respectively. When the quantum computer finishes executing quantum circuit 4, it determines in real time whether quantum circuit 5 or 6 will be the next quantum circuit to be executed, based on the current execution result of quantum circuit 4.
[0116] Specifically, a quantum computer identifies candidate quantum circuits that are connected to the current quantum circuit, and then, based on the quantum measurement results corresponding to the current quantum circuit, selects a target quantum circuit from the candidate quantum circuits that matches the quantum measurement results. In practical applications, the candidate quantum circuits connected to the current quantum circuit can be determined by combining a directed graph representing the control flow corresponding to the target quantum program.
[0117] In a specific application, the control flow corresponding to the target quantum program can be represented by a directed graph. Nodes in the directed graph represent specific quantum circuits; the outgoing edges of a node correspond to a quantum measurement result of that quantum circuit. The destination node pointed to by the outgoing edge represents the quantum circuit to be executed subsequently, given that the measurement result is obtained. Furthermore, the directed graph needs to define two special nodes: the initial node and the termination node. The initial node represents the initial quantum circuit to be executed in the initial state of the quantum program, and the termination node represents the final quantum circuit of the quantum program. The outgoing degree of the termination node must be 0. For example... Figure 4 The diagram shows a directed graph representing classical control flow, where node 0 is the initial node and node 7 is the terminating node. Nodes 0 and 1 are connected by two directed arrows. An outgoing edge from node 0 to node 1 indicates that the quantum circuit contained in node 0 is executed first, followed by the quantum circuit contained in node 1. Conversely, an outgoing edge from node 1 to node 0 indicates that the quantum circuit contained in node 1 is executed first, followed by the quantum circuit contained in node 0.
[0118] Step 208: By executing the mapping conversion circuit between the current quantum circuit and the target quantum circuit, the target quantum circuit is used as the current quantum circuit. The execution of the current quantum circuit is then resumed to obtain the quantum measurement result, and execution continues until the execution termination condition is met to obtain the program execution result.
[0119] The mapping and conversion circuit is an intermediate circuit used to connect two physical quantum circuits. It converts the mapping relationship between the last qubit of the source physical quantum circuit and the initial qubit mapping relationship of the destination physical quantum circuit. By executing the mapping and conversion circuit, the physical quantum circuits are switched, thereby updating the current quantum circuit. The execution termination condition refers to the condition that ends the process of returning to the current quantum circuit to obtain the quantum measurement result. Specifically, the execution termination condition can be that there are no candidate quantum circuits with a connection relationship for the current quantum circuit, that is, the current quantum circuit is the termination quantum circuit in the quantum program. The execution result obtained when the termination condition is met is the result obtained after executing all quantum circuits in the quantum program, that is, after executing the termination quantum program.
[0120] Specifically, the quantum computer takes the target quantum circuit as the current quantum circuit, executes the quantum circuit represented by the current quantum circuit, obtains the quantum measurement result corresponding to the quantum circuit, and determines whether there are candidate quantum circuits with a connection relationship with the current quantum circuit. If the determination result is yes, the target quantum circuit that matches the quantum measurement result is selected from the candidate quantum circuits with a connection relationship with the current quantum circuit, and the target quantum circuit is continued to be used as the current quantum circuit. The execution is repeated until the determination result is no. If the determination result is no, the execution result of the quantum program execution is fed back.
[0121] The aforementioned quantum program execution method determines the starting point of the quantum program by using the initial quantum circuit in the physical quantum circuit contained in the target quantum program as the current quantum circuit. It obtains quantum measurement results by executing the current quantum circuit, selects the target quantum circuit that matches the quantum measurement results from candidate quantum circuits connected to the current quantum circuit, and uses the quantum measurement results to filter the target quantum circuit, thus achieving control-flow-based quantum circuit execution. It then executes the mapping transformation circuit between the current quantum circuit and the target quantum circuit, using the target quantum circuit as the current quantum circuit, achieving connection execution between different physical quantum circuits. It continues execution by returning to the execution of the current quantum circuit to obtain quantum measurement results, until the execution termination condition is met, thus obtaining the program execution result. This enables the quantum computer to execute complex quantum programs with control flow, simplifies the use of data processing resources, and allows the quantum computer to accurately execute complex quantum programs with control flow according to the control flow.
[0122] In one embodiment, by executing a mapping conversion circuit between the current quantum circuit and the target quantum circuit, the target quantum circuit is used as the current quantum circuit. The execution of the current quantum circuit is then returned to obtain the quantum measurement result, and execution continues until the execution termination condition is met to obtain the program execution result. This includes: when the target quantum circuit is not a termination quantum circuit, the target quantum circuit is used as the current quantum circuit, the execution of the current quantum circuit is returned to obtain the quantum measurement result, and execution continues until the target quantum circuit is a termination quantum circuit; the termination quantum circuit is executed to obtain the execution result of the target quantum program.
[0123] In this context, the termination quantum circuit refers to the last quantum circuit executed in the target quantum program. The result after executing the termination quantum circuit is the execution result of the target quantum program. A quantum computer can determine whether a target quantum circuit is a termination quantum circuit by recognizing the identifier corresponding to the termination quantum circuit. This identifier can be added during the writing of the quantum program.
[0124] Specifically, during the iterative update of the current quantum circuit, the quantum computer determines whether the target quantum circuit is a termination quantum circuit. When the target quantum circuit is not a termination quantum circuit, it takes the target quantum circuit as the current quantum circuit. From the candidate quantum circuits that have a connection relationship with the current quantum circuit, it selects the target quantum circuit that matches the quantum measurement result and executes it in a loop until the determination result is that the target quantum circuit is a termination quantum circuit. When the target quantum circuit is a termination quantum circuit, it executes the termination quantum circuit and obtains the execution result of the target quantum program.
[0125] In practical applications, quantum computers can determine whether a selected target quantum circuit is a termination quantum circuit to decide whether to end the loop. When the loop terminates, the execution result of the target quantum program is obtained by executing the termination quantum circuit. This eliminates the need to obtain quantum measurement results when executing the termination quantum circuit, reducing the amount of data processing. Alternatively, quantum computers can determine whether to end the loop by checking if the target quantum circuit has candidate quantum circuits with connectivity relationships. When the loop terminates, the execution result of the target quantum program is directly obtained, simplifying the identification process of termination quantum circuits and improving data processing efficiency.
[0126] In this embodiment, the quantum computer determines whether the target quantum circuit is a terminated quantum circuit. If the target quantum circuit is not a terminated quantum circuit, it takes the target quantum circuit as the current quantum circuit, returns to execute the current quantum circuit to obtain the quantum measurement result, and continues execution until the target quantum circuit becomes a terminated quantum circuit. Executing the terminated quantum circuit yields the execution result of the target quantum program. By setting a loop termination condition, it is ensured that each quantum circuit in the target quantum program executes accurately according to the control flow, thereby improving the accuracy of the execution result of the target quantum program.
[0127] In one embodiment, the method further includes: performing a quantum measurement operation on a target qubit in the current quantum circuit in response to an execution initiation event for the current quantum circuit;
[0128] Furthermore, executing the current quantum circuit to obtain quantum measurement results includes: when the execution of the current quantum circuit ends, obtaining the quantum measurement result corresponding to the target qubit.
[0129] The execution initiation event refers to the triggering event that initiates 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 automatically triggers the execution initiation event for the target quantum circuit as the current quantum circuit. A quantum measurement operation is a special quantum operation in the execution process of a quantum circuit. The object of the quantum measurement operation is one or more target qubits in the quantum circuit. The target qubit can be set during quantum programming. The quantum measurement operation is an operation performed on the current state of the target qubit, and the quantum measurement operation itself also changes the state of the target qubit. 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 qubit. After the measurement, the state of the measured qubit also changes randomly.
[0130] Specifically, in response to an execution start event triggered by the determination of the current quantum circuit, the quantum computer performs quantum measurement operations on the target qubit based on the quantum gates for quantum measurements contained in the quantum circuit represented by the current quantum circuit. Upon completion of the execution of the quantum circuit represented by the current quantum circuit, the quantum measurement result corresponding to the target qubit is obtained, and an updated current quantum circuit is determined based on the quantum measurement result. In a specific implementation, in response to an execution start event for the current quantum circuit, the quantum computer determines the target quantum gate used for measurement operations in the current quantum circuit, and the target qubit matching the target quantum gate. Based on the target quantum gate, the state data of the matching target qubit is measured to obtain updated state data and quantum measurement results.
[0131] In this embodiment, in response to determining the execution start event triggered by the current quantum circuit, the quantum computer performs quantum measurement operations on the target qubit based on the quantum gates of quantum measurement contained in the quantum circuit represented by the current quantum circuit. When the execution of the current quantum circuit ends, the quantum measurement result corresponding to the target qubit is obtained to ensure the accuracy of the quantum measurement result.
[0132] In one embodiment, the number of target qubits is multiple; when the current quantum circuit finishes execution, the quantum measurement result corresponding to the target qubit is obtained, including: when the current quantum circuit finishes execution, binary bit data used to characterize the quantum measurement result is read from each target quantum gate, and the binary bit string composed of each binary bit data is taken as the quantum measurement result.
[0133] In this context, binary bit data refers to bit data with a value of 0 or 1. Quantum measurement results are represented using binary classical bit strings, the number of bits equal to the number of qubits being measured. For all measurement operations in a quantum program, the connections between logical quantum circuits are determined. Where i represents the number of the logic quantum circuit in which the measurement operation takes place, j m This represents the number of the logical quantum circuit that needs to be executed after obtaining the measurement result m, and n represents the number of qubits being measured. For example, if the number of logical quantum circuits connected to logical quantum circuit i is 4, then the number of target qubits to be measured can be 2; if the number of logical quantum circuits connected to logical quantum circuit i is 8, then the number of target qubits to be measured can be 3.
[0134] In this embodiment, by using the binary bit string composed of binary bit data as the quantum measurement result, the representation of the measurement result of the target qubit under test can be simplified, the number of target qubits under test can be effectively reduced, and the processing efficiency of quantum measurement can be improved.
[0135] In one embodiment, the method for executing a quantum program further includes a compilation process for a target quantum program. The compilation process for the target quantum program can be implemented in a classical computer, and the classical computer sends the compiled target quantum program to the quantum computer for execution. Alternatively, the compilation process for the target quantum program can be implemented in a quantum computer, and the quantum computer directly executes the compiled target quantum program after compilation.
[0136] The compilation process of a quantum program specifically includes: compiling the 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 the target quantum program. The physical quantum circuits in the target quantum program correspond to the nodes of the control flow, and the mapping and transformation circuits between the physical quantum circuits correspond to the connection relationships between the nodes.
[0137] The execution conditions corresponding to the quantum program execution environment are determined by the quantum computer executing the target quantum program, and different quantum computers may have different execution conditions. Specifically, the execution conditions can be the physical connectivity constraints between the qubits in the quantum computer. These physical connectivity constraints can be represented by a quantum computer architecture graph. The quantum computer architecture graph is an undirected connected graph, where nodes represent physical qubits, edges represent connections between qubits, and gate transformations between two qubits can only be performed between physically connected qubits that are directly connected by an edge. Figure 5 In the undirected connected graph shown, gate transformations between two qubits can only be performed between physical bits (v0,v1) and (v1,v2), while the corresponding gate transformations cannot be performed between (v0,v2).
[0138] An initial quantum program refers to a quantum algorithm designed without considering the physical connectivity constraints of a quantum computer. Compilation refers to the process of converting this initial quantum program, which does not consider the physical connectivity 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 logical quantum circuits. Classical or quantum computers can convert this initial quantum program, which consists of logical quantum circuits, so that the converted target quantum circuits satisfy the physical connectivity constraints of a quantum computer, thereby enabling execution on a quantum computer.
[0139] The control flow of the initial quantum program can be implemented through subroutines used to derive the classical control flow, thereby obtaining a directed graph that characterizes the control flow of the initial quantum program. The quantum circuits and the connections between quantum circuits are characterized by the nodes in the directed graph and the directed connections between nodes.
[0140] In a specific application, a classical computer or a quantum computer executes a classical control flow derived subroutine on the input initial quantum program. The data processing of the classical control flow derived subroutine includes: for each logical quantum circuit in the initial quantum program, generating a corresponding node; marking the node corresponding to the initial logical quantum circuit as the initial node; marking the node corresponding to the terminating logical quantum circuit as the terminating node; and for all measurement operations in the initial quantum program, generating edges. Where i represents the logical quantum circuit node number where the measurement operation is performed, j m Let represent the node number of the logical quantum circuit to be executed after obtaining the measurement result m, and let n represent the number of qubits being measured. Based on the generated nodes and the edges between the nodes, a directed graph is obtained to characterize the control flow of the initial quantum program. A classical or quantum computer converts the logical quantum circuits in the initial quantum program into physical quantum circuits. Based on the connection relationships between the logical quantum circuits represented by the directed graph, the converted physical quantum circuits are connected to obtain the target quantum program.
[0141] In this embodiment, a classical computer or a quantum computer compiles the initial quantum program according to the execution conditions corresponding to the quantum program execution environment and the control flow of the initial quantum program to obtain the target quantum program. Through compilation, a quantum algorithm designed without considering the physical connectivity constraints of the quantum computer can be converted into a target quantum program that can be executed on a quantum computer. This reduces the constraints when designing quantum programs. For different quantum computers, compilation can be performed according to the corresponding physical connectivity constraints, which reduces the constraints when designing quantum programs and expands the scope of use of quantum programs.
[0142] In one embodiment, such as Figure 6 As shown, a method for compiling a quantum program is provided. It should be noted that this quantum program compilation method can also be used as the execution method described above for quantum programs, compiling an initial quantum program containing control flow according to the execution conditions corresponding to the quantum program execution environment to obtain the specific implementation process of the target quantum program. This method is applied to... Figure 1 Taking a quantum computer as an example, the following steps are included:
[0143] Step 602: According to the control flow of the initial quantum program, determine the multiple logical quantum circuits contained in the initial quantum program and the connection relationships between the logical quantum circuits.
[0144] Step 604: Convert each logical quantum circuit into a physical quantum circuit according to the execution conditions corresponding to the quantum program execution environment.
[0145] Step 606: Based on the mapping of the connection relationship between each logical quantum circuit to the physical quantum circuit, the qubit mapping relationship of two physical quantum circuits with connection relationship is transformed to obtain the mapping transformation circuit.
[0146] Step 608: Compile the target quantum program, which includes physical quantum circuits and mapping transformation circuits, as the result of the initial quantum program.
[0147] The execution conditions corresponding to the quantum program execution environment include the physical connectivity constraints of the quantum computer, i.e., the qubit connectivity of the quantum computer. In quantum program design, the qubit connectivity of the quantum computer is usually not considered, and it is assumed that two-qubit gate transformations can be performed between any qubits. Quantum circuits designed based on this assumption are called logical quantum circuits, and the qubits contained in logical quantum circuits are called logical qubits. Correspondingly, if all two-qubit gates in a quantum circuit satisfy the qubit connectivity of a specific quantum computer, then the quantum circuit is called a physical quantum circuit, and the qubits contained in a physical quantum circuit are called physical qubits.
[0148] Based on the connectivity of qubits in a quantum computer, logical quantum circuits can be converted into physical quantum circuits through qubit mapping. When running quantum programs in a quantum computer, the qubits in the logical quantum circuits need to be mapped to physical qubits; this process is called qubit mapping. A given qubit mapping can be changed by introducing a swapping gate into the physical circuit, such as... Figure 7 As shown, the initial state of the qubit mapping is q0 mapped to v0, q1 mapped to v1, and q2 mapped to v2. By introducing the SWAP(v0,v1) gate, the qubit mapping can be transformed into q0 mapped to v1, q1 mapped to v0, and q2 mapped to v2. A qubit mapping can be represented by the symbol τ, where τ(q) represents the physical qubit corresponding to the q logic qubit under this mapping.
[0149] The number of logical qubits can be the same as or different from the number of physical qubits. When both are the same, there can be a one-to-one correspondence between logical and physical qubits. For example... Figure 7 As shown, Figure 7 In this system, q0 is mapped to v0, q1 to v1, and q2 to v2. When the quantities of physical qubits and logical qubits are different, the number of physical qubits can be greater than the number of logical qubits. In this case, logical qubits can be mapped to a subset of physical qubits. For example, assuming a quantum computer includes 10 physical qubits, then 3 physical qubits can be selected to correspond one-to-one with logical qubits.
[0150] The process of converting each logical quantum circuit into a physical quantum circuit is called quantum circuit conversion. Quantum circuit conversion refers to the process of determining an initial quantum bit mapping based on the structure diagram of the physical qubits in the quantum computer in order to execute the quantum circuit. Then, redundant swapping gate operations are 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 gates in it satisfy the connectivity constraints of the quantum computer structure diagram.
[0151] A qubit mapping conversion circuit is a quantum circuit used to implement qubit mapping conversion. Qubit mapping conversion refers to the transformation of the mapping relationship between two qubits. Specifically, it is the process of transforming one qubit mapping relationship into another by introducing a series of swapping gate operations, given two qubit mapping relationships.
[0152] Specifically, classical or quantum computers acquire an initial quantum program, determine the multiple logical quantum circuits contained in the initial quantum program and the connections between these circuits according to the control flow of the initial quantum program, and construct a directed graph using the logical quantum circuits as nodes and the connections between them as edges. Then, for any untransformed node in the directed graph, which is the logical quantum circuit that has been transformed into a microphysical quantum circuit, each logical quantum circuit is transformed into a physical quantum circuit according to the execution conditions corresponding to the quantum program execution environment, until all nodes in the directed graph have been transformed. Then, for any untransformed edge in the directed graph, which is two physical quantum circuits that have not undergone qubit mapping relationship transformation but have a connection relationship, the first and last qubit mapping relationship transformation is performed. This process continues until all untransformed edges in the directed graph have been transformed. Based on the transformed nodes and the directed graph of the node connections, the quantum program represented by the transformed directed graph is the compiled target quantum program.
[0153] In this embodiment, a classical computer or a quantum computer converts the initial quantum program containing classical control flow at the logical level into a set of physical quantum circuits that can be executed in the quantum computer during the compilation stage. This is achieved through quantum circuit conversion processing and first-to-last qubit mapping relationship conversion. During the execution stage, the quantum computer can reliably implement the execution process of a quantum program containing classical control by calling the corresponding compiled next physical quantum circuit based on the measurement results of the physical quantum circuits. For different quantum computers, compilation can be performed according to the corresponding physical connectivity constraints, which reduces the restrictions on quantum program design and expands the scope of use of quantum programs.
[0154] In one embodiment, based on the mapping of the connection relationships between logical quantum circuits to physical quantum circuits, the qubit mapping relationship of two physical quantum circuits with connection relationships is transformed to obtain a mapping transformation circuit, including:
[0155] Based on the mapping of the connection relationships between logical quantum circuits to physical quantum circuits, the connection relationships between physical quantum circuits are determined; from two physical quantum circuits with connection relationships, the last quantum bit mapping relationship corresponding to the source physical quantum circuit and the initial quantum bit mapping relationship corresponding to the target physical quantum circuit are obtained; through mapping relationship transformation, the mapping transformation circuit that converts the last quantum bit mapping relationship into the initial quantum bit mapping relationship is obtained.
[0156] The swap gate, also known as the interchange gate, operates on two qubits, allowing them to exchange qubits. Specifically, classical or quantum computers determine the connections between physical quantum circuits by mapping these connections to the connections between logical quantum circuits. For two connected physical quantum circuits, each circuit consists of multiple qubits and sequentially arranged quantum gates. Based on these qubits and gates, the final qubit mapping of the source quantum circuit and the initial qubit mapping of the destination quantum circuit can be obtained. These mappings determine the corresponding physical qubits. A swap gate is then introduced between these physical qubits to create a mapping conversion circuit. This circuit converts the final and initial qubit mappings, ensuring that the connections between physical quantum circuits conform to the qubit connectivity of the quantum computer, allowing the physical quantum circuits to execute sequentially.
[0157] In this embodiment, a classical computer or a quantum computer obtains the final qubit mapping relationship of the source physical quantum circuit and the initial qubit mapping relationship of the destination physical quantum circuit from two connected physical quantum circuits. By introducing a switching gate to construct a mapping conversion circuit to convert the qubit mapping relationship, the connection between the two physical quantum circuits during execution can be realized, thereby improving the reliability of the quantum program execution process.
[0158] In one embodiment, a mapping conversion circuit is obtained by converting the mapping relationship of the last qubit to the mapping relationship of the initial qubit through mapping relationship conversion, including:
[0159] From the structure diagram representing the execution conditions, the first physical qubit is determined. The first physical qubit is a physical qubit whose removal from the structure diagram does not affect the qubit connectivity in the structure diagram. Based on the last qubit mapping relationship, the logical qubit corresponding to the first physical qubit is determined, and based on the initial qubit mapping relationship, the second physical qubit corresponding to the logical qubit is determined. The connection path between the first qubit and the second qubit in the structure diagram is determined. A switching gate is introduced according to the connection path to obtain a mapping conversion circuit that converts the last qubit mapping relationship into the initial qubit mapping relationship.
[0160] The structure graph is an undirected connected graph used to represent the connectivity of physical qubits in a quantum computer. Nodes in the structure graph represent each physical qubit in the quantum computer, and edges between nodes indicate connectivity between the physical qubits represented by those nodes. Logical qubits and physical qubits are mapped one-to-one. Therefore, the logical qubit corresponding to the first physical qubit can be determined based on the mapping relationship between the last qubit and the first physical qubit, and the second physical qubit corresponding to the logical qubit can be determined based on the mapping relationship between the logical qubit and the initial qubit. The first physical qubit and the second physical qubit are two different qubit entities; however, in practical applications, their names can be interchanged.
[0161] A connection path refers to a set of qubits consisting of an end qubit, an intermediate qubit, and an beginning qubit, obtained by connecting the end qubit and the beginning qubit, which do not conform to the connection relationship corresponding to a quantum computer, by adding an intermediate qubit. Introducing a swap gate based on the connection path means introducing a swap gate between adjacent qubits, based on the sequentially connected qubits represented by the connection path, so that the connection between the end qubit and the beginning qubit is achieved after sequential swapping.
[0162] Specifically, classical or quantum computers construct a physical quantum bit network according to the connectivity of the corresponding qubits in the quantum computer. i and v j The path between them is denoted as in, For intermediate qubits, l represents the path length. Based on the constructed connection path, a swap gate is introduced into the physical quantum circuit for each qubit in the connection path. The number of switching gates introduced is the same as the path length.
[0163] In a specific application, a classical or quantum computer constructs an empty physical quantum circuit PC and simultaneously constructs the current qubit mapping τ = τ ini Take a target node, denoted as v, from the structure diagram representing the connectivity of qubits in a quantum computer. j And it needs to satisfy the deletion of v j The structural graph remains connected. Then, from the transformed physical quantum circuit, we search for a path that satisfies τ. fin (q)=v j The end qubit q, and the beginning qubit v i =τ(q); Construct a physical quantum bit v on the structure diagram. i and v j The path between them is denoted as Where l is the path length; (Introduced into PC) Furthermore, τ is updated according to the introduced swap gate, thereby realizing the qubit mapping conversion between the end qubit and the beginning qubit.
[0164] In this embodiment, classical or quantum computers construct connection paths and introduce switching gates between end qubits and beginning qubits based on these paths. This allows for qubit mapping and conversion between the end and beginning qubits, enabling connectivity between them while maintaining the original execution logic. This improves the reliability of the quantum program execution process.
[0165] In one embodiment, each logical quantum circuit is converted into a physical quantum circuit according to the execution conditions corresponding to the quantum program execution environment, including: determining the quantum bit connectivity relationship corresponding to the quantum program execution environment based on the quantum program execution environment; and performing quantum circuit conversion on each logical quantum circuit according to the quantum bit connectivity relationship to obtain a physical quantum circuit.
[0166] The quantum program execution environment refers to the execution environment provided by the quantum computer used to execute the compiled target quantum program. Different quantum computers have different connectivity relationships between their physical qubits; therefore, after determining the quantum computer to execute the target quantum program, it is necessary to obtain the qubit connectivity relationships corresponding to that quantum computer. Then, quantum circuit conversion is performed based on these qubit connectivity relationships.
[0167] Quantum circuit conversion is the process of converting a logical quantum circuit into an executable physical quantum circuit to execute a quantum circuit in a specific quantum computer. This is based on a structural diagram representing the connectivity between physical qubits in that specific quantum computer. Specifically, for each logical qubit in the logical quantum circuit, an initial qubit mapping is determined, and physical qubits corresponding one-to-one with each logical qubit in the logical quantum circuit are identified. Then, redundant swapping gate operations are introduced to convert the logical quantum circuit into an executable physical quantum circuit, ensuring that the generated physical quantum circuit is functionally equivalent to the logical quantum circuit, and that the two-qubit gates in the physical quantum circuit satisfy the connectivity constraints of the quantum computer's structural diagram.
[0168] In a specific application, such as Figure 8 As shown, assuming the logical quantum circuit includes logical qubits q0, q1, and q2, and control NOT gates CNOT(q1,q2) and CNOT(q0,q2), the physical qubits in the quantum computer include v0, v1, and v2, where v1 and v2 are connected, and v0 and v1 are connected. The quantum circuit conversion process includes: initially selecting qubit mappings as q0 to v0, q1 to v1, and q2 to v2; introducing SWAP(v0,v1) into the physical quantum circuit to change the qubit mappings to q0 to v1, q1 to v0, and q2 to v2; and simultaneously introducing CNOT(v1,v2), which functionally corresponds to CNOT(q0,q2) in the logical quantum circuit; and then introducing SWAP(v0,v1) into the physical quantum circuit to change the qubit mappings to q0 to v0, q1 to v1, and q2 to v2; and simultaneously introducing CNOT(v1,v2), which functionally corresponds to CNOT(q1,q2) in the logical quantum circuit, thereby realizing the conversion of the logical quantum circuit into a functionally identical physical quantum circuit.
[0169] In this embodiment, a classical computer or a quantum computer determines the quantum bit connectivity relationship corresponding to the quantum program execution environment based on the quantum program execution environment. For each logical quantum circuit, according to the quantum bit connectivity relationship, the logical quantum circuit is converted into a quantum circuit so that the converted physical quantum circuit is functionally the same as the logical quantum circuit and can be executed in the quantum program execution environment corresponding to the quantum computer, thereby improving the reliability of quantum program execution.
[0170] In one embodiment, for each logical quantum circuit, a quantum circuit conversion is performed on the logical quantum circuit according to the quantum bit connectivity to obtain a physical quantum circuit, including: based on the arrangement order of each quantum gate in the logical quantum circuit, and according to the quantum bit connectivity, determining the target physical quantum bits that have a mapping relationship with the logical quantum bits that act on the quantum gates; adding the quantum gates to the target physical quantum bits corresponding to the acting logical quantum bits, and removing the quantum gates from the logical quantum circuit; when the number of quantum gates in the logical quantum circuit is zero, the physical quantum circuit corresponding to the logical quantum circuit is obtained.
[0171] Quantum gates are components of quantum circuits. They act on qubits within the circuit, altering the state of the affected qubit to perform specific quantum operations. Based on the number of qubits affected, quantum gates can be categorized into single-qubit gates and two-qubit gates. A single-qubit gate acts on only one specific qubit, changing only its state; a two-qubit gate acts on two qubits, changing the states of both. Two-qubit gates include controlled NOT gates and swapping gates. The quantum gates in a quantum circuit are arranged sequentially to represent the quantum operations performed on the qubits in turn.
[0172] Specifically, classical or quantum computers, based on the arrangement of quantum gates in a logical quantum circuit, sequentially map the logical qubits acted upon by each quantum gate to physical qubits that satisfy the qubit connectivity relationship. This allows the same quantum operations to be performed on physical qubits as on logical qubits within the physical quantum circuit. To accurately map the logical qubits acted upon by each quantum gate and achieve the same function in the mapped physical quantum circuit, the quantum gates corresponding to the mapped logical qubits are removed from the logical quantum circuit, and the quantum gates are added to the physical qubits that have a mapping relationship with the logical qubits. This represents the synchronous construction of the quantum gates. The number of quantum gates in the logical quantum circuit gradually decreases with the removal process. When the number of quantum gates in the logical quantum circuit is zero, a physical quantum circuit is obtained, including each physical qubit and the quantum gates acting on the physical qubits.
[0173] In a specific application, a classical or quantum computer constructs an initial qubit mapping τ based on logic quantum circuits (LC) and a quantum computer architecture diagram. ini This mapping will q i Mapping to v i Then, an empty physical quantum circuit PC is constructed, and the current quantum bit mapping τ = τ is constructed simultaneously. iniThe quantum gates of LC are arranged from left to right in the order of execution. Each time, a quantum gate is taken from the leftmost side of the logical quantum circuit LC, denoted as G(). For the logical qubits acted upon by G(), physical qubits that are mapped one-to-one with the logical qubits are determined until there are no available quantum gates in LC, that is, the number of quantum gates in LC is 0.
[0174] In this embodiment, by sequentially performing mapping relationship transformation on the qubits affected by the quantum gates, and adding quantum gates to the mapped physical qubits, the resulting physical quantum circuits are functionally identical to logical quantum circuits, thereby improving the reliability of quantum program execution.
[0175] In one embodiment, mapping the logical qubits acted upon by a quantum gate to physical qubits that satisfy the qubit connectivity relation includes: when the quantum gate is a single-qubit quantum gate with one logical qubit acting upon it, determining the physical qubits mapped by the logical qubits based on the qubit mapping relation; when the quantum gate is a two-qubit quantum gate with two logical qubits acting upon it, determining the physical qubits mapped by the logical qubits by constructing the qubit mapping relation and introducing a swap gate to update the mapping relation.
[0176] A single-qubit gate is a quantum gate that operates on a specific qubit and can only change the state of that qubit. A two-qubit gate is a quantum gate that operates on two qubits and can change the states of both qubits.
[0177] The mapping methods for physical qubits differ between single-qubit and two-qubit gates. Specifically, because a single-qubit gate operates on a single object and does not affect other qubits, the physical qubit corresponding to the logical qubit can be directly determined based on the constructed mapping relationship between logical and physical qubits. However, a two-qubit gate operates on two objects, and the connectivity of the qubits must be considered during execution. Therefore, a swapping gate is introduced to update the mapping relationship, ensuring that the physical qubit corresponding to the updated logical qubit can perform the same quantum operations as the logical qubit.
[0178] Specifically, classical or quantum computers determine whether a quantum gate is a single-qubit or two-qubit gate by the number of logical qubits it operates on. When the quantum gate is a single-qubit gate with one logical qubit, the mapping relationship corresponding to that logical qubit is found, and the physical qubit mapped to that logical qubit is determined based on the found mapping relationship. Specifically, if the mapping relationship of the logical qubit operated by the single-qubit quantum gate has not been updated, the current mapping relationship corresponding to the logical qubit is the initial mapping relationship constructed; if the mapping relationship has been updated, the current mapping relationship corresponding to the logical qubit is the updated mapping relationship. When the quantum gate is a two-qubit gate with two logical qubits, the mapping relationship is updated by constructing a qubit mapping relationship and introducing a swapping gate, thus determining the physical qubit mapped to the logical qubit.
[0179] In a specific application, a classical or quantum computer constructs an initial qubit mapping τ based on logic quantum circuits (LC) and a quantum computer architecture diagram. ini This mapping will q i Mapping to v i Then, an empty physical quantum circuit PC is constructed, and the current quantum bit mapping τ = τ is constructed simultaneously. ini For a quantum gate G() in a logical quantum circuit (LC), if G() is a single-qubit gate G(q) acting on a logical qubit q, then add G(τ(q)) to the end of the PC, where τ(q) is the physical qubit mapped to the logical qubit q, and τ represents the mapping relationship. If G() is a single-qubit gate G(q) acting on a logical qubit (q)... i ,q j The two-qubit gate G(q) on ) i ,q j Then, construct the physical quantum bit τ(q) i ) and τ(q j The path between ) is denoted as Where l is the path length (L > 2), and is introduced into PC. as well as And update the mapping relationship τ according to the introduced exchange gate.
[0180] In this embodiment, a classical or quantum computer determines whether a quantum gate is a single-qubit or two-qubit gate based on the number of logical qubits it operates on. Different processing is applied to different qubit gates. For single-qubit gates, which operate on a single object and do not affect other qubits, the physical qubit corresponding to the logical qubit is determined directly based on the mapping relationship between the constructed logical qubits and physical qubits. For two-qubit gates, which operate on two objects, the specific connectivity of the qubits needs to be considered during execution. A swapping gate is introduced to update the mapping relationship, ensuring that the physical qubit corresponding to the updated logical qubit can perform the same quantum operations as the logical qubit, thereby improving the accuracy of quantum program execution.
[0181] In one embodiment, updating the qubit mapping relationship by constructing a qubit mapping relationship and introducing a switching gate includes: constructing an initial qubit mapping relationship to map the two logical qubits operated by the two-bit qubit gate to a first physical qubit and a second physical qubit, respectively; determining the connection path between the first physical qubit and the second physical qubit according to the qubit connectivity relationship; and introducing a switching gate based on the connection path to update the initial qubit mapping relationship, thereby obtaining an updated qubit mapping relationship.
[0182] In this context, the first physical qubit and the second physical qubit are two distinct qubit entities, which can be interchanged in practical applications. The initial qubit mapping can be randomly constructed, as long as a one-to-one correspondence between physical and logical qubits is maintained. A connection path refers to the result of connecting two qubits that cannot be directly connected by adding an intermediate qubit. Introducing a swap gate based on the connection path involves introducing swap gates between adjacent qubits, based on the sequentially connected qubits represented by the connection path, to achieve connectivity between the two qubits after sequential swapping.
[0183] In a specific application, this is aimed at the action on logical qubits (q i ,q j The two-qubit gate G(q) on ) i ,q j ), determine the logical quantum bit q i ,q j Mapped physical qubit τ(q) i ) and τ(q j ), constructing physical qubits τ(q) on the structure diagram. i ) and τ(q j The path between ) is denoted as Where l is the path length (L > 2); This is introduced into the constructed empty physical quantum circuit PC. as well as Realizing the physical quantum bit τ(q) i ) and τ(q j The connectivity of ) is established, and the mapping relation τ is updated according to the introduced exchange gate, i.e., the logical qubit q. i The physical qubit of the mapping is composed of τ(q) i Updated to
[0184] In this embodiment, by constructing connection paths and adding intermediate qubits to connect physical qubits, and based on the sequentially connected qubits represented by the connection paths, a swap gate is introduced between adjacent qubits to update the mapping relationship. This allows the physical qubits that have undergone sequential swapping and mapping updates to be connected and to perform the operations corresponding to the original logical qubits, ensuring the accuracy of the quantum program execution results.
[0185] In one specific embodiment, such as Figure 9 As shown, a method for compiling a quantum program is provided, including the following compilation process using a quantum program. The compilation process of a quantum program can be implemented using either a classical computer or a quantum computer. Specifically, the compilation process of a quantum program by a classical computer or a quantum computer includes the following steps:
[0186] Step 902: According to the control flow of the initial quantum program, determine the multiple logical quantum circuits contained in the initial quantum program and the connection relationships between the logical quantum circuits.
[0187] Step 904: For each logical quantum circuit, based on the arrangement order of each quantum gate in the logical quantum circuit, and according to the quantum bit connectivity relationship corresponding to the quantum computer, determine the target physical quantum bits that have a mapping relationship with the logical quantum bits that act on the quantum gates.
[0188] Step 906: When the quantum gate is a single-bit quantum gate with a logic qubit number of 1, determine the physical qubit mapped by the logic qubit based on the qubit mapping relationship.
[0189] Step 908: When the quantum gate is a two-bit quantum gate with two logical qubits, the two logical qubits acted by the two-bit quantum gate are mapped to two physical qubits by constructing an initial qubit mapping relationship.
[0190] Step 910: Determine the connection path between two physical qubits according to the qubit connectivity relationship.
[0191] Step 912: Introduce a switching gate based on the connection path to update the initial qubit mapping relationship, obtain the updated qubit mapping relationship, and determine the physical qubit mapped by the logical qubit based on the updated qubit mapping relationship.
[0192] Step 914: Add the quantum gate to the target physical qubit corresponding to the logic qubit being acted upon, and remove the quantum gate from the logic quantum circuit.
[0193] Step 916: When the number of quantum gates in the logical quantum circuit is zero, the physical quantum circuit corresponding to the logical quantum circuit is obtained.
[0194] Step 918: Based on the mapping of the connection relationships between logical quantum circuits to physical quantum circuits, determine the connection relationships between physical quantum circuits.
[0195] Step 920: From two physical quantum circuits with a connection relationship, obtain the last quantum bit mapping relationship corresponding to the source physical quantum circuit and the initial quantum bit mapping relationship corresponding to the destination physical quantum circuit.
[0196] Step 922: Determine the first physical qubit from the structure diagram representing the execution conditions. The first physical qubit is a physical qubit whose deletion from the structure diagram does not affect the qubit connectivity in the structure diagram.
[0197] Step 924: Based on the final qubit mapping relationship, determine the logical qubit corresponding to the first physical qubit, and based on the initial qubit mapping relationship, determine the second physical qubit corresponding to the logical qubit.
[0198] Step 926: Determine the connection path between the first and second qubits in the structure diagram.
[0199] Step 928: Introduce a switching gate according to the connection path to obtain a mapping conversion circuit that converts the last qubit mapping relationship into the initial qubit mapping relationship.
[0200] Step 930: Determine the target quantum program, which includes physical quantum circuitry and mapping transformation circuitry.
[0201] In one specific embodiment, such as Figure 10 As shown, a method for executing a quantum program is provided, including the following execution process of the quantum program. The execution process of the quantum program can be implemented using a quantum computer, specifically including the following steps:
[0202] Step 1002: Obtain the target quantum program compiled according to the quantum bit connectivity, and take the initial quantum circuit in the physical quantum circuit contained in the target quantum program as the current quantum circuit.
[0203] Step 1004: In response to the execution start event for the current quantum circuit, perform a quantum measurement operation on the target qubit in the current quantum circuit.
[0204] Step 1006: When the current quantum circuit finishes execution, read the binary bit data used to characterize the quantum measurement results from each target quantum gate.
[0205] Step 1008: The binary bit string formed by each binary bit data is taken as the quantum measurement result.
[0206] Step 1010: From the candidate quantum circuits that have a connection relationship with the current quantum circuit, select the target quantum circuit that matches the quantum measurement result, and the connection relationship matches the control flow corresponding to the target quantum program.
[0207] Step 1012: When the target quantum circuit is not a termination quantum circuit, the target quantum circuit is used as the current quantum circuit by executing the mapping conversion circuit between the current quantum circuit and the target quantum circuit. The execution of the current quantum circuit is then resumed to obtain the quantum measurement result and continue execution until the target quantum circuit becomes a termination quantum circuit.
[0208] Step 1014: Execute the termination quantum circuit to obtain the execution result of the target quantum program.
[0209] This application also provides an application scenario in which the above-described quantum program execution method is applied. Specifically, the application of the quantum program execution method in this scenario is as follows:
[0210] The execution of a quantum program consists of two phases: compilation and execution, serving as a component of the quantum computing software-to-hardware interface. During the compilation phase, a quantum algorithm containing classical control flow at the logical level is transformed into a set of executable physical quantum circuits. During the execution phase, the corresponding compiled physical quantum circuits are invoked based on measurement results, reliably realizing the execution of a quantum program containing classical control.
[0211] like Figure 11 As shown, quantum program processing includes compilation and execution. The input data consists of an initial quantum program containing classical control and a structure diagram representing the connectivity of physical qubits in the quantum computer, enabling the compilation and execution of the initial quantum program on the target quantum computer. The compilation process transforms an input initial quantum program containing classical control into a series of physical circuits that can be executed by a specific quantum computer. For ease of representation, the physical qubits in the structure diagram are denoted as v, and the logical qubits in the initial quantum program are denoted as q.
[0212] The specific steps for compilation are as follows:
[0213] S1: Execute the classical control flow derivation subroutine on the input initial quantum program to obtain a directed graph that matches the classical control flow of the initial quantum program.
[0214] In this directed graph, each node represents a specific logical quantum circuit. The outgoing edges of a node correspond to a measurement result of that logical quantum circuit, and the destination node of that outgoing edge represents the logical quantum circuit to be executed after obtaining that measurement result. The directed graph also defines two special nodes: the initial node and the termination node. The initial node contains the quantum circuit to be executed in the initial state of the quantum program; the termination node must have an outgoing degree of 0 and contains the termination logical quantum circuit of the quantum program.
[0215] Specifically, the input to the classical control flow derivation subroutine is the initial quantum program, and its detailed steps are as follows:
[0216] S1-1: For each logical quantum circuit in the initial quantum program, generate a corresponding node;
[0217] S1-2: Mark the node corresponding to the initial logical quantum circuit as the initial node, and mark the node corresponding to the termination logical quantum circuit as the termination node;
[0218] S1-3: For all measurement operations in the initial quantum program, generate edges. Where i represents the logical quantum circuit node number where the measurement operation is performed, j m This represents the logical quantum circuit node number that needs to be executed after obtaining the measurement result m, where n represents the number of qubits being measured.
[0219] S1-4: Returns a directed graph generated based on nodes and edges.
[0220] S2: Take any untransformed node in the directed graph, denoted as i, and denote its represented logical quantum circuit as LC. i ;
[0221] S3: For LC i Execute the quantum circuit conversion subroutine and denote the resulting physical circuit as PC. i PC i The initial and final quantum bit mappings are denoted as and
[0222] The quantum circuit conversion subroutine is its structure diagram. It first needs to determine an initial qubit mapping, and then introduce redundant swapping gate operations to convert the logical quantum circuit into an executable physical quantum circuit. This makes the generated physical quantum circuit functionally equivalent to the logical quantum circuit, and the two qubit gates satisfy the connectivity constraints of the quantum computer structure diagram, enabling the execution of the quantum circuit in a specific quantum computer.
[0223] Specifically, the quantum circuit conversion subroutine takes a logical quantum circuit LC and a structure diagram of a quantum computer as input, and returns a physical quantum circuit PC that satisfies the connectivity constraints of the structure diagram and an initial qubit mapping τ. ini And a final quantum bit mapping τ fin The detailed steps are as follows:
[0224] S3-1: Constructing the initial quantum bit mapping relationship τ ini This mapping will transform the logical qubit q i Mapped to physical qubits v i ;
[0225] S3-2: Construct an empty physical quantum circuit PC, and simultaneously construct the current qubit mapping τ = τ ini ;
[0226] S3-3: Take a quantum gate from the leftmost side of the logic quantum circuit LC, denoted as G();
[0227] S3-4: If G() is a single-qubit gate G(q) acting on logical qubit q, then add G(τ(q)) at the end of the physical quantum circuit PC, and then proceed to S3-6;
[0228] S3-5: If G() is an action on a logical qubit (q) i ,q j The two-qubit gate G(q) on ) i ,q j Then, a physical quantum bit τ(q) is constructed on the structure diagram. i ) and τ(q j The path between ) is denoted as Where l is the path length (L > 2);
[0229] S3-6: Introducing a swapping gate into a physical quantum circuit PC based on the constructed path. as well as Furthermore, the qubit mapping relationship τ is updated based on the introduced swap gate;
[0230] S3-7: Remove the extracted quantum gate from the logic quantum circuit LC. If the number of quantum gates decreases to 0, proceed to the next step; otherwise, proceed to S3-3.
[0231] S3-8: Return the physical quantum circuit PC and the initial qubit mapping relationship τ ini Last quantum bit mapping relationship τ fin Let τ fin =τ, which realizes the update of the quantum bit mapping relationship.
[0232] S4: If all nodes in the structure diagram have been transformed, proceed to S5; otherwise, proceed to S2.
[0233] S5: Take any untransformed edge from 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;
[0234] S6: Based on the initial quantum bit mapping relationship Initial mapping relationship, final quantum bit mapping relationship To determine the target mapping relationship, execute the qubit mapping transformation subroutine, construct the mapping transformation circuit required for the transformation, and denote it as PC. i,j .
[0235] Specifically, the input to the qubit mapping transformation subroutine is an initial mapping relation τ. ini Target mapping relationship τ fin And the corresponding structure diagram of the quantum computer, the output of which is a constructed mapping transformation physical circuit PC, which can map qubits to τ ini Convert to τ fin The detailed steps of the qubit mapping and conversion subroutine are as follows:
[0236] S6-1: Construct an empty physical quantum circuit PC, and simultaneously construct the current quantum bit mapping relationship τ = τ ini ;
[0237] S6-2: Take out a physical qubit from the structure diagram, denoted as v. j Furthermore, the physical qubit needs to satisfy the deletion of v. j Afterwards, the structure graph remains a connected graph;
[0238] S6-3: Finding the condition that satisfies τ fin (q)=v j Let q be the logical qubit, and based on the current qubit mapping relationship τ, let v i =τ(q);
[0239] S6-4: Construct a physical qubit v on the structure diagram i and vj The path between them is denoted as Where l is the path length;
[0240] S6-5: Introducing a switching gate into a physical quantum circuit PC based on the constructed path. Furthermore, the qubit mapping relationship τ is updated based on the introduced swap gate;
[0241] S6-6: Remove the extracted physical qubit v from the structure diagram j ;
[0242] S6-7: If the number of nodes in the structure diagram is 0, proceed to the next step; otherwise, proceed to S6-2.
[0243] S6-8: Return to mapping conversion line PC i,j .
[0244] The execution process can be implemented on a specific quantum computer using a specific scheduling method. The execution process follows immediately after the compilation process, and the specific steps are as follows:
[0245] S7: Take the initial node of the compiled target quantum program as the current node, denoted as i;
[0246] S8: Execute the physical quantum circuit PC represented by node i in a quantum computer. i The measurement result m is obtained;
[0247] S9: If node i is the terminating node, proceed to S12; otherwise, proceed to the next step.
[0248] S10: Determine the outgoing edge of node i based on the result m, denoted as (i,j), where j is the destination node of the outgoing edge;
[0249] S11: The mapping transformation circuit PC required to perform the mapping transformation. i,j Assign j to i as the current node and proceed to S8;
[0250] S12: The feedback quantum program has been executed and the execution result is obtained.
[0251] The above method enables the compilation and execution of quantum programs containing classical control, overcoming the limitation of traditional methods that can only handle single logical quantum circuits without classical control flow. By deriving classical control flow to represent the execution and scheduling process of quantum programs containing classical control, and through multiple calls to quantum circuit conversion algorithms and qubit mapping conversion algorithms, a series of physical quantum circuits are obtained. These physical quantum circuits can satisfy the execution conditions of a specific quantum computer, enabling quantum programs containing classical control to run on that specific quantum computer.
[0252] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0253] Based on the same inventive concept, this application also provides a quantum program execution apparatus for implementing the quantum program execution method and a quantum program compilation apparatus for implementing the quantum program compilation method described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method. Therefore, the specific limitations of one or more quantum program execution apparatus and compilation apparatus embodiments provided below can be found in the limitations of the quantum program execution method and compilation method described above, and will not be repeated here.
[0254] In one embodiment, such as Figure 12 As shown, a quantum program execution device 1200 is provided, including: an initial quantum circuit identification module 1202, a quantum measurement result acquisition module 1204, a quantum circuit screening module 1206, and a target quantum circuit update module 1208, wherein:
[0255] The initial quantum circuit identification module 1202 is used to identify the initial quantum circuit in the physical quantum circuit contained in the target quantum program as the current quantum circuit.
[0256] The quantum measurement result acquisition module 1204 is used to execute the current quantum circuit to obtain the quantum measurement result;
[0257] The quantum circuit screening module 1206 is used to screen out target quantum circuits that match the quantum measurement results from candidate quantum circuits that have a connection relationship with the current quantum circuit, wherein the connection relationship matches the control flow corresponding to the target quantum program;
[0258] The target quantum circuit update module 1208 is used to execute the mapping conversion circuit between the current quantum circuit and the target quantum circuit, take the target quantum circuit as the current quantum circuit, return to the quantum measurement result obtained by executing the current quantum circuit and continue execution until the execution termination condition is met to obtain the program execution result.
[0259] In one embodiment, the quantum program execution device further includes a compilation module, which is used to compile the 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 the target quantum program;
[0260] The target quantum program contains physical quantum circuits that correspond to nodes of the control flow, and the mapping and transformation circuits between the physical quantum circuits correspond to the connection relationships between the nodes.
[0261] In one embodiment, the compilation module includes a logic quantum circuit splitting module, a quantum circuit conversion module, a mapping relationship conversion module, and an integration module; wherein,
[0262] The logic quantum circuit splitting module is used to determine, according to the control flow of the initial quantum program, the multiple logic quantum circuits contained in the initial quantum program and the connection relationships between the logic quantum circuits.
[0263] The quantum circuit conversion module is used to convert each of the logical quantum circuits into physical quantum circuits according to the execution conditions corresponding to the quantum program execution environment.
[0264] The mapping relationship conversion module is used to convert the qubit mapping relationship between two physical quantum circuits with a connection relationship based on the mapping of the connection relationship between each logical quantum circuit to the physical quantum circuit, so as to obtain the mapping conversion circuit;
[0265] An integration module is used to determine the target quantum program, which includes the physical quantum circuit and the mapping transformation circuit.
[0266] In one embodiment, the mapping relationship conversion module is further configured to determine the connection relationship between the physical quantum circuits based on the mapping of the connection relationship between each logical quantum circuit between the physical quantum circuits; obtain the last qubit mapping relationship corresponding to the source physical quantum circuit and the initial qubit mapping relationship corresponding to the destination physical quantum circuit from two physical quantum circuits with connection relationship; and obtain a mapping conversion circuit that converts the last qubit mapping relationship into the initial qubit mapping relationship through mapping relationship conversion.
[0267] In one embodiment, the mapping conversion module is further configured to: determine a first physical qubit from a structure diagram characterizing the execution conditions, wherein the first physical qubit is a physical qubit whose removal from the structure diagram does not affect the qubit connectivity in the structure diagram; determine a logical qubit corresponding to the first physical qubit based on the last qubit mapping relationship, and determine a second physical qubit corresponding to the logical qubit based on the initial qubit mapping relationship; determine the connection path between the first qubit and the second qubit in the structure diagram; and introduce a switching gate according to the connection path to obtain a mapping conversion circuit that converts the last qubit mapping relationship into the initial qubit mapping relationship.
[0268] In one embodiment, the quantum circuit conversion module is further configured to determine the quantum bit connectivity relationship corresponding to the quantum program execution environment based on the quantum program execution environment; and to perform quantum circuit conversion on each logical quantum circuit according to the quantum bit connectivity relationship to obtain a physical quantum circuit.
[0269] In one embodiment, the quantum circuit conversion module is further configured to, based on the arrangement order of each quantum gate in the logical quantum circuit, sequentially determine the target physical qubit that has a mapping relationship with the logical qubit acting on the quantum gate according to the qubit connectivity; add the quantum gate to the target physical qubit corresponding to the acting logical qubit, and remove the quantum gate from the logical quantum circuit; when the number of quantum gates in the logical quantum circuit is zero, a physical quantum circuit corresponding to the logical quantum circuit is obtained.
[0270] In one embodiment, the quantum circuit conversion module is further configured to: when the quantum gate is a single-bit quantum gate with one logical qubit acting on it, determine the physical qubit mapped by the logical qubit based on the qubit mapping relationship; and when the quantum gate is a two-bit quantum gate with two logical qubits acting on it, update the qubit mapping relationship by introducing a swap gate, and determine the physical qubit mapped by the logical qubit based on the updated qubit mapping relationship.
[0271] In one embodiment, the quantum circuit conversion module is further configured to construct an initial quantum bit mapping relationship, map the two logical qubits operated by the two-bit quantum gate to a first physical qubit and a second physical qubit respectively; determine the connection path of the first physical qubit and the second physical qubit according to the quantum bit connectivity relationship; introduce a switching gate based on the connection path to update the initial quantum bit mapping relationship, thereby obtaining an updated quantum bit mapping relationship.
[0272] In one embodiment, the target quantum circuit update module is further configured to, when the target quantum circuit is not a terminated quantum circuit, use the target quantum circuit as the current quantum circuit, return to the execution of the quantum measurement result obtained by the current quantum circuit and continue execution until the target quantum circuit becomes the terminated quantum circuit; execute the terminated quantum circuit to obtain the execution result of the target quantum program.
[0273] In one embodiment, the device further includes a quantum measurement module, configured to perform a quantum measurement operation on a target qubit in the current quantum circuit in response to an execution start event for the current quantum circuit; and to obtain a quantum measurement result corresponding to the target qubit when the execution of the current quantum circuit ends.
[0274] In one embodiment, the number of target qubits is multiple; the quantum measurement module is further configured to read binary bit data characterizing the quantum measurement result from each of the target quantum gates when the current quantum circuit finishes execution; and to use the binary bit string formed by the binary bit data as the quantum measurement result.
[0275] Each module in the aforementioned quantum program execution device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in hardware within or independently of the processor in the quantum computer, or stored in software within the quantum computer's memory, so that the processor can invoke and execute the operations corresponding to each module.
[0276] In one embodiment, such as Figure 13 As shown, a quantum program compilation device 1300 is provided, including: a logic quantum circuit splitting module 1302, a quantum circuit conversion module 1304, a mapping relationship conversion module 1306, and an integration module 1308, wherein:
[0277] The logic quantum circuit splitting module 1302 is used to determine, according to the control flow of the initial quantum program, the multiple logic quantum circuits contained in the initial quantum program and the connection relationships between the logic quantum circuits.
[0278] The quantum circuit conversion module 1304 is used to convert each of the logical quantum circuits into physical quantum circuits according to the execution conditions corresponding to the quantum program execution environment.
[0279] The mapping relationship conversion module 1306 is used to convert the qubit mapping relationship between two physical quantum circuits with a connection relationship based on the mapping of the connection relationship between each logical quantum circuit to the physical quantum circuit, so as to obtain the mapping conversion circuit;
[0280] The integration module 1308 is used to compile the target quantum program, which includes the physical quantum circuit and the mapping transformation circuit, as the compilation result of the initial quantum program.
[0281] In one embodiment, the mapping relationship conversion module is further configured to determine the connection relationship between the physical quantum circuits based on the mapping of the connection relationship between each logical quantum circuit between the physical quantum circuits; obtain the last qubit mapping relationship corresponding to the source physical quantum circuit and the initial qubit mapping relationship corresponding to the destination physical quantum circuit from two physical quantum circuits with connection relationship; and obtain a mapping conversion circuit that converts the last qubit mapping relationship into the initial qubit mapping relationship through mapping relationship conversion.
[0282] In one embodiment, the mapping conversion module is further configured to: determine a first physical qubit from a structure diagram characterizing the execution conditions, wherein the first physical qubit is a physical qubit whose removal from the structure diagram does not affect the qubit connectivity in the structure diagram; determine a logical qubit corresponding to the first physical qubit based on the last qubit mapping relationship, and determine a second physical qubit corresponding to the logical qubit based on the initial qubit mapping relationship; determine the connection path between the first qubit and the second qubit in the structure diagram; and introduce a switching gate according to the connection path to obtain a mapping conversion circuit that converts the last qubit mapping relationship into the initial qubit mapping relationship.
[0283] In one embodiment, the quantum circuit conversion module is further configured to determine the quantum bit connectivity relationship corresponding to the quantum program execution environment based on the quantum program execution environment; and to perform quantum circuit conversion on each logical quantum circuit according to the quantum bit connectivity relationship to obtain a physical quantum circuit.
[0284] In one embodiment, the quantum circuit conversion module is further configured to, based on the arrangement order of each quantum gate in the logical quantum circuit, sequentially determine the target physical qubit that has a mapping relationship with the logical qubit acting on the quantum gate according to the qubit connectivity; add the quantum gate to the target physical qubit corresponding to the acting logical qubit, and remove the quantum gate from the logical quantum circuit; when the number of quantum gates in the logical quantum circuit is zero, a physical quantum circuit corresponding to the logical quantum circuit is obtained.
[0285] In one embodiment, the quantum circuit conversion module is further configured to: when the quantum gate is a single-bit quantum gate with one logical qubit acting on it, determine the physical qubit mapped by the logical qubit based on the qubit mapping relationship; and when the quantum gate is a two-bit quantum gate with two logical qubits acting on it, update the qubit mapping relationship by introducing a swap gate, and determine the physical qubit mapped by the logical qubit based on the updated qubit mapping relationship.
[0286] In one embodiment, the quantum circuit conversion module is further configured to construct an initial quantum bit mapping relationship, map the two logical qubits operated by the two-bit quantum gate to a first physical qubit and a second physical qubit respectively; determine the connection path of the first physical qubit and the second physical qubit according to the quantum bit connectivity relationship; introduce a switching gate based on the connection path to update the initial quantum bit mapping relationship, thereby obtaining an updated quantum bit mapping relationship.
[0287] In one embodiment, a quantum computer is provided, which can be a terminal, and its internal structure diagram can be as follows: Figure 14 As shown, the quantum computer includes a processor, memory, communication interface, display screen, and input device connected via a system bus. The processor provides computational and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage medium. The communication interface allows for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When the computer program is executed by the processor, it implements a quantum program execution and compilation method. The display screen can be an LCD screen or an e-ink screen. The input device can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the quantum computer's casing, or an external keyboard, touchpad, or mouse.
[0288] Those skilled in the art will understand that Figure 14 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the quantum computer on which the present application is applied. A specific quantum computer may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.
[0289] In one embodiment, a quantum computer is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.
[0290] In one embodiment, a computer-readable storage medium is provided storing a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0291] In one embodiment, a computer program product or computer program is provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and executes the computer instructions, causing the computer device to perform the steps in the above method embodiments.
[0292] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0293] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0294] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0295] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A method for executing a quantum program, characterized in that, The method includes: The initial quantum circuit in the physical quantum circuit contained in the target quantum program is taken as the current quantum circuit; The quantum measurement result is obtained by executing the current quantum circuit; From the candidate quantum circuits that have a connection relationship with the current quantum circuit, a target quantum circuit that matches the quantum measurement result is selected, wherein the connection relationship matches the control flow corresponding to the target quantum program; By executing the mapping conversion circuit between the current quantum circuit and the target quantum circuit, the target quantum circuit is used as the current quantum circuit. The execution of the current quantum circuit is then returned to obtain the quantum measurement result and continue execution until the execution termination condition is met to obtain the program execution result.
2. The method according to claim 1, characterized in that, The method further includes: Based on the execution conditions corresponding to the quantum program execution environment, the initial quantum program is compiled according to the control flow of the initial quantum program to obtain the target quantum program; The target quantum program contains physical quantum circuits that correspond to nodes of the control flow, and the mapping and transformation circuits between the physical quantum circuits correspond to the connection relationships between the nodes.
3. The method according to claim 2, characterized in that, The process of compiling an initial quantum program containing control flow according to the execution conditions corresponding to the quantum program execution environment to obtain a target quantum program includes: According to the control flow of the initial quantum program, determine the multiple logical quantum circuits contained in the initial quantum program and the connection relationships between the logical quantum circuits. According to the execution conditions corresponding to the quantum program execution environment, each of the logical quantum circuits is converted into a physical quantum circuit; Based on the mapping of the connection relationship between each logical quantum circuit to the physical quantum circuit, the quantum bit mapping relationship of two physical quantum circuits with connection relationship is transformed to obtain the mapping transformation circuit; Determine the target quantum program, which includes the physical quantum circuit and the mapping transformation circuit.
4. The method according to claim 3, characterized in that, The mapping of the connection relationships between the logical quantum circuits to the physical quantum circuits, based on the connection relationships between the logical quantum circuits, involves converting the qubit mapping relationship between two physical quantum circuits with connection relationships to obtain a mapping conversion circuit, including: 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. From two physical quantum circuits that are connected, obtain the last qubit mapping relationship of the source physical quantum circuit and the initial qubit mapping relationship of the destination physical quantum circuit; By transforming the mapping relationship, a mapping transformation circuit is obtained that converts the last qubit mapping relationship into the initial qubit mapping relationship.
5. The method according to claim 4, characterized in that, The mapping transformation circuit that converts the final qubit mapping relationship into the initial qubit mapping relationship through mapping relationship conversion includes: From the structure diagram representing the execution conditions, a first physical qubit is determined. The first physical qubit is a physical qubit whose deletion from the structure diagram does not affect the qubit connectivity in the structure diagram. Based on the last qubit mapping relationship, the logical qubit corresponding to the first physical qubit is determined, and based on the initial qubit mapping relationship, the second physical qubit corresponding to the logical qubit is determined; Determine the connection path between the first physical qubit and the second physical qubit in the structural diagram; By introducing a switching gate according to the connection path, a mapping conversion circuit is obtained that converts the mapping relationship of the last qubit into the mapping relationship of the initial qubit.
6. The method according to claim 3, characterized in that, The step of converting each logical quantum circuit into a physical quantum circuit according to the execution conditions corresponding to the quantum program execution environment includes: Based on the quantum program execution environment, determine the quantum bit connectivity relationship corresponding to the quantum program execution environment; For each of the aforementioned logical quantum circuits, a quantum circuit conversion is performed on the logical quantum circuit according to the quantum bit connectivity to obtain a physical quantum circuit.
7. The method according to claim 6, characterized in that, The step of performing quantum circuit conversion on each logical quantum circuit according to the quantum bit connectivity to obtain a physical quantum circuit includes: Based on the arrangement order of each quantum gate in the logical quantum circuit, and according to the quantum bit connectivity, the target physical quantum bits that have a mapping relationship with the logical quantum bits that act on the quantum gate are determined sequentially. The quantum gate is added to the target physical qubit corresponding to the logic qubit it is applied to, and the quantum gate is removed from the logic quantum circuit. When the number of quantum gates of the logical quantum circuit is zero, a physical quantum circuit corresponding to the logical quantum circuit is obtained.
8. The method according to claim 7, characterized in that, The determination of the target physical qubit that has a mapping relationship with the logical qubit acting on the quantum gate includes: When the quantum gate is a single-bit quantum gate with a logic qubit quantity of 1, the physical qubit mapped by the logic qubit is determined based on the qubit mapping relationship. When the quantum gate is a two-bit quantum gate with two logical qubits, the mapping relationship of the qubits is updated by introducing a swap gate, and the physical qubits mapped by the logical qubits are determined based on the updated qubit mapping relationship.
9. The method according to claim 8, characterized in that, The method of updating the mapping relationship by constructing a quantum bit mapping relationship and introducing a swap gate includes: By constructing an initial quantum bit mapping relationship, the two logical quantum bits operated by the two-bit quantum gate are mapped to two physical quantum bits; Determine the connection path between the two physical qubits according to the aforementioned qubit connectivity relationship; A switching gate is introduced based on the connection path to update the initial qubit mapping relationship, resulting in an updated qubit mapping relationship.
10. The method according to any one of claims 1 to 9, characterized in that, The process of executing a mapping conversion circuit between the current quantum circuit and the target quantum circuit, using the target quantum circuit as the current quantum circuit, returning to the execution of the current quantum circuit to obtain the quantum measurement result, and continuing execution until the execution termination condition is met to obtain the program execution result includes: When the target quantum circuit is not a termination quantum circuit, the mapping conversion circuit between the current quantum circuit and the target quantum circuit is executed, the target quantum circuit is used as the current quantum circuit, and the execution of the quantum measurement result obtained by executing the current quantum circuit is returned to continue execution until the target quantum circuit becomes the termination quantum circuit; Execute the terminated quantum circuit to obtain the execution result of the target quantum program.
11. The method according to any one of claims 1 to 9, characterized in that, The method further includes: In response to an execution start event for the current quantum circuit, a quantum measurement operation is performed on the target qubit in the current quantum circuit; The process of obtaining a quantum measurement result by executing the current quantum circuit includes: When the current quantum circuit finishes execution, the quantum measurement result corresponding to the target qubit is obtained.
12. The method according to claim 11, characterized in that, The number of target qubits is multiple; When the current quantum circuit finishes execution, obtaining the quantum measurement result corresponding to the target qubit includes: When the current quantum circuit finishes execution, binary bit data characterizing the quantum measurement result is read from the target quantum gate used for quantum measurement; The binary bit string formed by the binary bit data is taken as the result of quantum measurement.
13. A method for compiling a quantum program, characterized in that, The method includes: According to the control flow of the initial quantum program, determine the multiple logical quantum circuits contained in the initial quantum program and the connection relationships between the logical quantum circuits. According to the execution conditions corresponding to the quantum program execution environment, each of the logical quantum circuits is converted into a physical quantum circuit; Based on the mapping of the connection relationship between each logical quantum circuit to the physical quantum circuit, the quantum bit mapping relationship of two physical quantum circuits with connection relationship is transformed to obtain the mapping transformation circuit; The target quantum program, which includes the physical quantum circuit and the mapping transformation circuit, is used as the compilation result of the initial quantum program.
14. A quantum program execution device, characterized in that, The device includes: The initial quantum circuit identification module is used to identify the initial quantum circuit in the physical quantum circuit contained in the target quantum program as the current quantum circuit; The quantum measurement result acquisition module is used to execute the current quantum circuit to obtain the quantum measurement result; A quantum circuit screening module is used to screen out target quantum circuits that match the quantum measurement results from candidate quantum circuits that have a connection relationship with the current quantum circuit, wherein the connection relationship matches the control flow corresponding to the target quantum program; The target quantum circuit update module is used to execute the mapping conversion circuit between the current quantum circuit and the target quantum circuit, take the target quantum circuit as the current quantum circuit, return to the quantum measurement result obtained by executing the current quantum circuit and continue execution until the execution termination condition is met to obtain the program execution result.
15. A quantum program compilation device, characterized in that, The device includes: A logic quantum circuit determination module is used to determine, according to the control flow of the initial quantum program, multiple logic quantum circuits contained in the initial quantum program and the connection relationships between the logic quantum circuits. The quantum circuit conversion module is used to convert each of the logical quantum circuits into physical quantum circuits according to the execution conditions corresponding to the quantum program execution environment. The mapping relationship conversion module is used to convert the qubit mapping relationship between two physical quantum circuits with a connection relationship based on the mapping of the connection relationship between each logical quantum circuit to the physical quantum circuit, so as to obtain the mapping conversion circuit; The compilation result determination module is used to take the target quantum program, which includes the physical quantum circuit and the mapping transformation circuit, as the compilation result of the initial quantum program.
16. A quantum computer, comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 13.
17. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 13.
18. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 13.
Citation Information
Patent Citations
Method and device for realizing quantum circuit replacement, storage medium and electronic device
CN111027702A
Quantum bit topological structure reconstruction method for improving fidelity of quantum calculation
CN113762517A