Quantum circuit processing method, device and electronic equipment
By optimizing the compilation of quantum circuits, static quantum circuits are equivalently compiled into dynamic quantum circuits, which solves the problem of the limitation on the number of qubits, realizes the simulation and operation of large-scale quantum circuits, and improves the verification capability of quantum algorithms.
Patent Information
- Application Number
- CN202310577717.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-22
- Publication Date
- 2024-11-19
- Estimated Expiration
- 2043-05-22
AI Technical Summary
Existing quantum circuit simulations and real-machine operations are limited by the number of qubits, making it difficult to support the simulation and operation of large-scale quantum algorithms.
By optimizing the compilation of quantum circuits, static quantum circuits are equivalently compiled into dynamic quantum circuits, reducing the number of qubits. The quantum state is reset to zero using the reset operation, and the structure of the quantum circuit is optimized to adapt to hardware with fewer qubits.
It enables classical simulation and real-machine operation of quantum circuits with large-scale qubits, improves the verification capability of quantum algorithms, and reduces the requirements for the insufficient scalability of quantum chips.
Smart Images

Figure CN117391206B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of quantum computing technology, in particular to the field of quantum circuit technology, and specifically to a quantum circuit processing method, device and electronic device. Background Art
[0002] Quantum computing uses the unique operating rules of the quantum world to provide a new and very promising way of information processing. In many specific problems, quantum algorithms can bring advantages over classical algorithms. For example, using Shor's algorithm, large integers can be efficiently decomposed, and using Grover's algorithm, data searches can be performed faster. With the development of quantum theory, new quantum algorithms are constantly being proposed. How to efficiently simulate these algorithms or run them on real quantum hardware has always been an important issue.
[0003] At present, the classical simulation or real machine operation of quantum algorithms is mainly limited by the number of quantum bits. In classical simulation, the length of the column vector describing the quantum state grows exponentially with the number of corresponding bits (for example, the length of the column vector of an n-bit quantum state is 2 n ), it is difficult for classical computers to simulate large-scale quantum algorithms. Limited by computer memory and processor capabilities, existing quantum circuit simulation methods can only support the simulation of algorithms with dozens of quantum bits at most. Summary of the invention
[0004] The present disclosure provides a quantum circuit processing method, device and electronic device.
[0005] According to a first aspect of the present disclosure, a quantum circuit processing method is provided, comprising:
[0006] Acquire a first instruction list, wherein the first instruction list includes operation instructions of a first quantum circuit, wherein the operation instructions are used to indicate quantum operations of the first quantum circuit, and the quantum operations include quantum measurement operations;
[0007] Based on the first instruction list, obtaining a dependency relationship of an execution order of operation instructions of the first quantum circuit;
[0008] Based on the dependency, reorder the operation instructions of the first quantum circuit in ascending order of the quantum bit numbers involved in the operation instructions to obtain a second instruction list of the first quantum circuit;
[0009] Based on the second instruction list, determining classification information, the classification information comprising: first information for indicating the quantum measurement operation at the first quantum circuit position;
[0010] In a case where the first information indicates that the quantum measurement operation is at an end position of the first quantum circuit, the first quantum circuit is equivalently compiled based on the classification information and the second instruction list to obtain a third instruction list of a second quantum circuit equivalent to the first quantum circuit, the third instruction list comprising: an operation instruction for a reset operation, the operation instruction for the reset operation being located after the operation instruction for the quantum measurement operation, the reset operation being used to reset the quantum state of the quantum bit to a zero state, the number of quantum bits of the second quantum circuit being less than the number of quantum bits of the first quantum circuit, and the end position indicating that the quantum measurement operation is the last quantum measurement operation in the quantum measurement operations along the direction of time evolution of the quantum state.
[0011] According to a second aspect of the present disclosure, there is provided a quantum circuit processing device, comprising:
[0012] A first acquisition module is used to acquire a first instruction list, where the first instruction list includes operation instructions of a first quantum circuit, where the operation instructions are used to indicate quantum operations of the first quantum circuit, where the quantum operations include quantum measurement operations;
[0013] A second acquisition module, configured to acquire a dependency relationship of an execution order of operation instructions of the first quantum circuit based on the first instruction list;
[0014] a reordering module, configured to reorder the operation instructions of the first quantum circuit in ascending order of the quantum bit numbers involved in the operation instructions based on the dependency relationship, to obtain a second instruction list of the first quantum circuit;
[0015] A determination module, configured to determine classification information based on the second instruction list, the classification information comprising: first information for indicating the quantum measurement operation at the first quantum circuit position;
[0016] An equivalent compilation module is used to perform equivalent compilation on the first quantum circuit based on the classification information and the second instruction list when the first information indicates that the quantum measurement operation is at the end position of the first quantum circuit, so as to obtain a third instruction list of a second quantum circuit equivalent to the first quantum circuit, wherein the third instruction list includes: an operation instruction of a reset operation, the operation instruction of the reset operation is located after the operation instruction of the quantum measurement operation, the reset operation is used to reset the quantum state of the quantum bit to a zero state, the number of quantum bits of the second quantum circuit is less than the number of quantum bits of the first quantum circuit, and the end position indicates that the quantum measurement operation is the last quantum measurement operation in the quantum measurement operations along the time evolution direction of the quantum state.
[0017] According to a third aspect of the present disclosure, there is provided an electronic device, including:
[0018] at least one processor; and
[0019] a memory communicatively connected to at least one processor; wherein,
[0020] The memory stores instructions that can be executed by at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform any method in the first aspect.
[0021] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause a computer to execute any one of the methods in the first aspect.
[0022] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising a computer program, which implements any one of the methods in the first aspect when executed by a processor.
[0023] The technology disclosed in the present invention solves the problem that classical simulation and real machine operation of quantum circuits in related technologies are relatively difficult, making it possible to perform classical simulation and real machine operation on quantum circuits of large-scale quantum bits.
[0024] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0026] Figure 1 is a flowchart of a quantum circuit processing method according to the first embodiment of the present disclosure;
[0027] Figure 2 This is a schematic diagram of the structure of an example static quantum circuit;
[0028] Figure 3 is a schematic diagram of the structure of an example dynamic quantum circuit;
[0029] Figure 4 It is a schematic diagram of the structure of the dynamic quantum circuit after the static quantum circuit is optimized and compiled;
[0030] Figure 5 It is a schematic diagram of the structure of the dynamic quantum circuit after the dynamic quantum circuit is optimized and compiled;
[0031] Figure 6is a schematic diagram of a structure of an exemplary quantum circuit including classically controlled quantum operations;
[0032] Figure 7 This is a schematic diagram of the structure of a static quantum circuit obtained after processing based on the delayed measurement principle;
[0033] Figure 8 It is a schematic diagram of the structure of the quantum circuit obtained by decomposing the multi-qubit gate;
[0034] Fig. 9 It is a classification scenario diagram of quantum measurement operations;
[0035] Fig.10 It is a schematic diagram of the structure of the static quantum circuit after each quantum operation is numbered;
[0036] Fig.11 It is a schematic diagram of the structure of the input quantum circuit in the optimization compilation example;
[0037] Fig.12 It is a schematic diagram of the structure of the output quantum circuit in the optimized compilation example;
[0038] Fig.13 is a schematic structural diagram of a quantum circuit processing device according to a second embodiment of the present disclosure;
[0039] Fig.14 is a schematic block diagram of an example electronic device for implementing an embodiment of the present disclosure. DETAILED DESCRIPTION
[0040] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0041] First embodiment
[0042] like Figure 1 As shown, the present disclosure provides a quantum circuit processing method, comprising the following steps:
[0043] Step S101: Acquire a first instruction list, where the first instruction list includes operation instructions of a first quantum circuit, where the operation instructions are used to indicate quantum operations of the first quantum circuit, where the quantum operations include quantum measurement operations.
[0044] In this embodiment, the quantum circuit processing method relates to the field of quantum computing technology, and in particular to the field of quantum circuit technology, which can be widely used in classical simulation and real machine operation scenarios of quantum circuits. The quantum circuit processing method of the disclosed embodiment can be executed by the quantum circuit processing device of the disclosed embodiment. The quantum circuit processing device of the disclosed embodiment can be configured in any electronic device to execute the quantum circuit processing method of the disclosed embodiment.
[0045] Limited by computer memory and processor capabilities, existing quantum circuit simulation methods can only support algorithms that simulate dozens of qubits at most. For example, a laptop can simulate about 20-30 qubits, and a large supercomputer and cluster can simulate up to 30-40 qubits. In real machine operation, the scalability problem of current quantum chips has not yet been solved, resulting in a very limited number of qubits that a quantum computer can provide. Therefore, quantum circuit optimization is a fundamental issue in the field of quantum computing.
[0046] Quantum circuit optimization is a process that uses certain technical means to simplify a given quantum circuit to reduce the requirements for classical simulation and real-machine operation, thereby accelerating the research of quantum algorithms and the implementation of quantum computing in practical scenarios.
[0047] The quantum circuit processing of this embodiment can be a quantum circuit optimization process, and its purpose is to optimize and compile the quantum circuit so that the compiled quantum circuit can greatly simplify the original quantum circuit in terms of the number of quantum bits. On the one hand, it can further improve the scale of classical simulation of quantum algorithms and enhance the verification ability of classical computers on quantum algorithms. On the other hand, it can also reduce the bit number requirements of quantum algorithms on real machines, making up for the shortcomings of the current quantum chip scalability problem.
[0048] The quantum circuit model is introduced in detail below.
[0049] At present, quantum computing can be implemented based on the quantum circuit model, that is, the evolution of the quantum state is completed by applying a series of quantum gates on the quantum bits, and quantum measurements are performed at the end of the circuit to obtain the calculation results.
[0050] At present, the most commonly used quantum circuits are static quantum circuits, that is, quantum circuits that only contain quantum measurement operations at the end of the circuit. With the recent rapid development of hardware, mainly the significant improvement of quantum bit coherence time and the realization of high-fidelity intermediate state measurement and reset operations, dynamic quantum circuits containing circuit intermediate measurement and reset operations are increasingly valued by the industry.
[0051] Due to the introduction of intermediate measurements of the circuit, dynamic quantum circuits can effectively combine quantum computing and real-time classical computing and communication within the coherence time of the quantum bit. This feature greatly increases the diversity of computing tasks that can be achieved through quantum circuit models. For example, by using the intermediate measurements of dynamic quantum circuits, it is possible to implement forward feedback operations during circuit operation, that is, to decide which quantum gate to act on next based on the results obtained from the intermediate measurements, or to discard the current calculation results and restart the calculation task. Such functions are very important in realizing quantum error correction. Therefore, it is foreseeable that dynamic quantum circuits will become an important part of various quantum algorithms and quantum applications in the future.
[0052] In addition, since the qubits in a dynamic quantum circuit can be reset and continue to be used in subsequent calculations, compared with a static quantum circuit, when running the same quantum algorithm, a dynamic quantum circuit can effectively reduce the number of qubits required for a computing task, and in theory, computing power is not affected in any way. For example, the Berstein-Vazirani algorithm, which requires n qubits in a static quantum circuit, can be implemented with only 2 qubits in a dynamic quantum circuit.
[0053] It can be seen that dynamic quantum circuits have many advantages and are increasingly valued by the industry. Dynamic quantum circuits can be introduced through quantum circuit optimization, that is, given a quantum circuit, a dynamic quantum circuit equivalent to it can be obtained through quantum circuit optimization. This embodiment can compile a given quantum circuit into a dynamic quantum circuit, and at the same time can greatly reduce the number of quantum bits used for the entire computing task, thereby helping to achieve many advantages of dynamic quantum circuits. Among them, the given quantum circuit can be a static quantum circuit or a dynamic quantum circuit, which is not specifically limited here.
[0054] The quantum circuit diagram can represent the entire process of quantum circuit model calculation.
[0055] Figure 2 This is a schematic diagram of the structure of an example static quantum circuit. Figure 2 As shown, a quantum bit system can be represented by a horizontal line, and the quantum bits of the quantum bits are numbered from top to bottom, where the quantum bit numbers often start from zero.
[0056] The direction of time evolution in the quantum circuit diagram is from left to right. The leftmost end is the initial quantum state, where each quantum bit is usually initialized to the zero state, and then different quantum gate operations are applied to the initial state in sequence to complete the evolution of the quantum state. At the same time, quantum measurements can be performed on certain quantum bits to obtain measurement results.
[0057] If a quantum circuit does not contain operations such as reset and intermediate quantum measurement, and all measurement operations are located at the end of the quantum circuit, then such a quantum circuit is called a static quantum circuit. An example of a static quantum circuit is Figure 2 shown.
[0058] The rest of the quantum circuit diagram except the initial quantum state can usually be represented by an ordered instruction list according to the order of action of the quantum gate. Each element in the instruction list represents an operation instruction, which can be a quantum gate operation instruction or a quantum measurement operation instruction.
[0059] Each single-qubit gate (such as H, X, Y, Z, S, T, Rx, Ry, Rz, etc.) is represented by an operation instruction containing four elements [name, which_qubit, parameters, condition], where name is the name of the quantum gate, which_qubit is the quantum bit acted on by the quantum gate, parameters are the parameters of the quantum gate (if there is no parameter, the default is None), and condition indicates which quantum bit measurement result controls the quantum gate operation (the default parameter in the standard quantum circuit is None). For example, [Rx, 2, pi, None] means to apply an Rx rotation gate to the quantum bit on quantum bit 2, with a rotation angle of pi.
[0060] Each multi-qubit gate (such as controlled NOT gate CNOT, SWAP gate, controlled-controlled NOT gate Toffoli gate) is represented by an instruction containing four elements [name, which_qubit, parameters, condition]. Among them, name is the name of the quantum gate, which_qubit is a list of qubits that the multi-qubit gate acts on, parameters are the parameters of the quantum gate (if there is no parameter, the default is None), and condition indicates which qubit measurement result controls the quantum gate operation (if there is no parameter, the default is None). For example, [SWAP, [1,2], None, None] means to act on SWAP gate between qubits 1 and 2; and [TOFFOLI, [1,2,3], None, None] means to act on Toffoli gate on qubits 1, 2 and 3, where 1 and 2 are control bits and 3 is the controlled bit.
[0061] Each single-bit measurement is represented by an instruction containing four elements [measure, which_qubit, basis, mid], where basis represents the basis of the measurement, which is determined by four parameters, including the measurement angle angle, measurement plane plane, domain set s, and domain set t, and mid is the ID that identifies the current measurement. For example, [measure, 2, [0, 'YZ', [1], [2]], 'a'] means measuring qubit 2, with a measurement angle of 0, a measurement plane of 'YZ' plane, a domain set of 1, a domain set of 2, and an ID of the current measurement instruction of 'a'.
[0062] According to the above instruction expression rules, Figure 2 The static quantum circuit in can be represented as the following ordered instruction list:
[0063] static_circuit=[[H,0,None,None],[H,1,None,None],[H,2,None,None],[H,3,None,None],[H,4,None,None],[ CNOT,[0,1],None,None],[CNOT,[2,3],None,None],[SWAP,[1,2],None,None],[Rx,1,α,None],[Ry,3,β,None],[R z,4,γ,None],[Toffoli,[1,3,4],None,None],[measure,0,[0,'YZ',[],[]],'a'],[measure,1,[0,'YZ',[],[]],' b'],[measure,2,[0,'YZ',[],[]],'c'],[measure,3,[0,'YZ',[],[]],'d'],[measure,4,[0,'YZ',[],[]],'e']].
[0064] More generally, the operation of a quantum circuit may also involve quantum measurements of some qubits in the middle of the circuit, and the evolution of the remaining qubits is regulated based on the measurement results. This type of operation is called a classically controlled quantum operation, which is a quantum gate operation controlled by classical information obtained from quantum measurement operations. The classical information includes 0 and 1. At the same time, after obtaining the measurement results in the middle of the circuit, these measured qubits can be reset to the |0> state for subsequent calculations. This type of quantum circuit that includes measurements and reset operations in the middle of the circuit is called a dynamic quantum circuit. An example of a dynamic quantum circuit is Figure 3 shown.
[0065] Dynamic quantum circuit operation instructions: In addition to the operations in the static quantum circuit described above, the dynamic quantum circuit also includes classical control quantum operations and reset operations.
[0066] Each classical control quantum operation is represented by an instruction containing four elements [name, which_qubit, parameters, condition], where name is the name of the quantum gate, which_qubit is the quantum bit acted on by the quantum gate, parameters are the parameters of the quantum gate (if there are no parameters, the default is None), and condition indicates which measurement result controls the quantum gate operation.
[0067] For example, Figure 3 The classical controlled quantum Z gate in the classical controlled quantum gate can be expressed as [Z, 3, None, 'a'], that is, the Pauli Z gate acting on quantum bit 3. The controlled condition is the measurement result on quantum bit 1 (assuming that the mid of the measurement is 'a'). If the measurement result is 0, the quantum gate is not acted on, and if the measurement result is 1, the quantum gate is acted on.
[0068] Each reset operation instruction can be represented as an instruction containing four elements [reset, which_qubit, matrix, None], where which_qubit is the qubit to be reset, and matrix is the quantum state matrix of the qubit to be reset. The bits after the reset operation can be used for subsequent calculations. For example, Figure 3 The reset operation instruction can be expressed as [reset,1,matrix,None].
[0069] According to the above instruction expression rules, Figure 3 The dynamic quantum circuit in can be represented as an ordered list of instructions as follows:
[0070] dynamic_circuit=[[H,0,None,None],[H,1,None,None],[H,2,None,None],[H,3,None,None],[Toffoli, [0,2,1],None,None],[measure,1,[0,'YZ',[],[]],'a'],[Z,3,None,'a'],[reset,1,matrix,None],[H, 1,None,None],[Toffoli,[1,2,3],None,None],[measure,3,[0,'YZ',[],[]],'b'],[X,2,None,'b'],[me asure,0,[0,'YZ',[],[]],'c'],[measure,1,[0,'YZ',[],[]],'d'],[measure,2,[0,'YZ',[],[]],'e']].
[0071] If a quantum circuit can be equivalently compiled into a dynamic quantum circuit using fewer quantum bits, the quantum circuit can be called a compilable quantum circuit, otherwise it is called a non-compilable quantum circuit. The first quantum circuit can be a compilable quantum circuit.
[0072] It should be noted that the above definition of compilable quantum circuits is not limited to static quantum circuits. For a dynamic quantum circuit, if the number of quantum bits used can be reduced through optimized compilation, then such a dynamic quantum circuit is also compilable. Figure 2 The static quantum circuit shown is similar to Figure 3 The dynamic quantum circuits shown are all compilable quantum circuits. Figure 2 The static quantum circuit of the quantum circuit is optimized and compiled into a dynamic quantum circuit such as Figure 4 , Figure 3 The dynamic quantum circuit of the quantum circuit is compiled after quantum circuit optimization. Figure 5 shown.
[0073] In some quantum circuit optimization scenarios, it is possible to allow the input circuit to perform classical control quantum operations after the measurement at the end of the quantum circuit, such as Figure 6 As shown in the figure, the quantum circuit is measured at the end and then the classical control quantum operation is performed. It can be converted into a standard static quantum circuit by postponing the measurement principle, and then compiled into a dynamic quantum circuit. The principle of postponing measurement is that any measurement in the middle stage of the quantum circuit can always be moved to the end of the circuit; if the measurement result is used in a certain stage of the circuit, the classical control quantum operation can be replaced by the quantum control operation.
[0074] Figure 6 The quantum circuit shown in the figure, after the delayed measurement process, is as follows Figure 7 As shown, it is obvious that such a processing method is not applicable to a dynamic quantum circuit whose input quantum circuit is a classical control quantum operation including intermediate measurements and the intermediate circuit. In this embodiment, the first quantum circuit can be a dynamic quantum circuit including intermediate measurements and the intermediate circuit classical control quantum operation.
[0075] In addition, although it can be mathematically proved that any n-qubit gate can be decomposed into a combination of single-qubit gates and double-qubit CNOT gates, for a quantum circuit containing n (n>2) qubit gates, all n-qubit gates can be decomposed into a form containing only single-qubit and double-qubit gates before subsequent processing. However, such a decomposition will significantly increase the total number of operations in the quantum circuit, thus significantly increasing the complexity of the subsequent compilation process. For example, Figure 8 The quantum circuit diagram shown is a 3-qubit Toffoli gate decomposed into single and double qubit gates. In this embodiment, the input circuit including a multi-qubit gate can be directly processed, that is, the first quantum circuit can include a multi-qubit gate.
[0076] In step S101, the first instruction list may be an ordered instruction list of the first quantum circuit, and a pre-stored first instruction list of the first quantum circuit may be obtained, or a first instruction list of the first quantum circuit input by a user may be obtained, which is not specifically limited here.
[0077] It should be noted that there is a quantum measurement operation at the very end of each quantum bit in the first quantum circuit, and the quantum measurement operation may appear before the very end classical control quantum operation.
[0078] Step S102: Based on the first instruction list, obtain the dependency of the execution order of the operation instructions of the first quantum circuit.
[0079] In this step, for an operation instruction, its dependency may refer to an operation instruction that must be executed before executing the current operation instruction.
[0080] The dependency of the execution order of each operation instruction can be determined based on the qubits acted on by the operation instructions in the first instruction list. If there is an intersection in the qubits acted on by different operation instructions, then these operation instructions have a dependency in the execution order. For example, the first operation instruction is arranged before the second operation instruction in the first instruction list, and the qubits acted on by the two have an intersection. For example, if both act on qubit 0, then the first operation instruction must be executed before the second operation instruction is executed, and there is a dependency between the two operation instructions.
[0081] In an optional implementation, for each operation instruction, the first instruction list may be traversed in reverse (i.e., traversed from back to front) to obtain other operation instructions that have an intersection with the qubits acted upon by the operation instruction, and the dependency of the operation instruction may include other operation instructions that are sorted before the operation instruction and whose qubits have an intersection with the operation instruction.
[0082] In another optional implementation, the quantum bits acted upon by the operation instructions in the first instruction list may be obtained; the operation instructions may be numbered based on the order in which the quantum bits acted upon by the operation instructions appear in the quantum operation of the first quantum circuit to obtain numbering information of the operation instructions of the first quantum circuit; based on the numbering information of the operation instructions, other operation instructions associated with the operation instructions in the first quantum circuit may be searched to obtain a dependency relationship.
[0083] It should be noted that for the operation instructions of classically controlled quantum operations, their dependencies also need to consider the operation instructions of quantum operations on the controlled bits of the classically controlled quantum operations, that is, before their execution, the quantum operations on the controlled bits need to be completed first.
[0084] Step S103: Based on the dependency relationship, the operation instructions of the first quantum circuit are reordered in ascending order of the quantum bit numbers involved in the operation instructions to obtain a second instruction list of the first quantum circuit.
[0085] In this step, after the dependency of the execution order of the operation instructions of the first quantum circuit is obtained, the order of the operation instructions of the first quantum circuit can be optimized, that is, reordered.
[0086] According to the dependency relationship, the operation instructions in the first instruction list may be reordered according to a preset priority principle to achieve the reordering of the operation instructions of the first quantum circuit, wherein the preset priority principle may be a row order priority principle, and the row order priority principle indicates that the operation instructions are sorted in the order of the qubit numbers involved in the operation instructions from small to large, that is, the operation instructions acting on qubit 0 are sorted first, and then the operation instructions acting on qubit 1 are sorted, and so on. The qubits involved in the operation instructions may include the qubits directly acted on by the operation instructions, and for the operation instructions of classically controlled quantum operations, the qubits involved in the operation instructions may also include the qubits where the controlled conditions acted on by the operation instructions are located.
[0087] That is to say, while taking into account the dependency of the execution order of the operation instructions of the first quantum circuit, the quantum operations are executed in the order of rows as much as possible, so as to complete all operations on a certain quantum bit as quickly as possible and perform quantum measurement on the quantum bit.
[0088] In an optional implementation, the operation instructions in the first instruction list may be reordered according to the row order priority principle, and then based on the reordering, the dependency relationship between the operation instructions may be considered, that is, based on the dependency relationship between the operation instructions, the operation instructions may be reordered to obtain the second instruction list of the first quantum circuit. That is, the operation instructions of the first quantum circuit may be sorted in the corresponding order through two reorderings.
[0089] In another optional implementation, during a reordering process, the operation instructions in the first instruction list may be reordered according to a row-order priority principle while considering dependencies between the operation instructions to obtain a second instruction list.
[0090] By reordering the operation instructions, the operation instructions in the reordered second instruction list are made to perform the quantum operations in the order indicated by the row priority principle as much as possible while taking into account the dependencies between the operation instructions. In this way, on the one hand, the equivalence with the original quantum circuit will not be destroyed, and on the other hand, it can also preprocess the subsequent equivalent compilation (i.e., the equivalent compilation from the first quantum circuit to the second quantum circuit) to ensure that the number of bits required for the compiled dynamic quantum circuit is as small as possible.
[0091] Step S104: Based on the second instruction list, determining classification information, the classification information comprising: first information for indicating the position of the quantum measurement operation at the first quantum circuit.
[0092] In this step, the classification information may include two cases. First, if the first quantum circuit does not include a classical control quantum operation, the classification information is only classified for the quantum measurement operation, and the quantum measurement operation may be classified according to different positions. For example, the quantum measurement operation is located in the middle position of the quantum circuit, and the quantum measurement operation is located at the end position of the quantum circuit.
[0093] Among them, the end position indicates that the quantum measurement operation is the last quantum measurement operation along the direction of the time evolution of the quantum state, and the middle position is different from the end position, indicating that the quantum measurement operation is not the last quantum measurement operation along the direction of the time evolution of the quantum state.
[0094] Second, if the first quantum circuit includes classical control quantum operations, the classification information can be classified separately for quantum measurement operations and classical control quantum operations to identify the location of the quantum measurement operation in the first quantum circuit, and to identify and distinguish the classical control quantum operations in the first quantum circuit.
[0095] In an optional implementation, the second instruction list may be traversed in forward order, and the number of quantum measurement operations on each qubit may be recorded, and when the forward order traversal is completed, the position of each quantum measurement operation in the first quantum circuit may be determined. The forward order traversal refers to traversing from the first operation instruction in the second instruction list to the last operation instruction.
[0096] In another optional implementation, the second instruction list may be traversed in reverse order, and when a quantum measurement operation is traversed, the position of the quantum measurement operation in the first quantum circuit is determined based on the first target list updated during the reverse traversal process. The first target list is used to record whether the quantum measurement operation of each quantum bit in the first quantum circuit located at the end of the first quantum circuit is traversed.
[0097] In practical applications, the classification information can be added to the operation instructions as parameters of the operation instructions in the second instruction list, that is, the second instruction list can be preprocessed before compilation to obtain an instruction list with classification information parameters added for equivalent compilation of quantum circuits.
[0098] Step S105: in a case where the first information indicates that the quantum measurement operation is at the end position of the first quantum circuit, based on the classification information and the second instruction list, the first quantum circuit is equivalently compiled to obtain a third instruction list of a second quantum circuit equivalent to the first quantum circuit, the third instruction list comprising: an operation instruction for a reset operation, the operation instruction for the reset operation is located after the operation instruction for the quantum measurement operation, the reset operation is used to reset the quantum state of the quantum bit to a zero state, the number of quantum bits of the second quantum circuit is less than the number of quantum bits of the first quantum circuit, and the end position indicates that the quantum measurement operation is the last quantum measurement operation in the quantum measurement operations along the time evolution direction of the quantum state.
[0099] When a dynamic quantum circuit is used as input, the quantum measurement operation in the quantum circuit may be an intermediate measurement. The quantum measurement operation may also include classical control quantum operations. The practice of resetting and recycling the quantum bits after the quantum measurement operation is not applicable.
[0100] In this step, on the basis of preprocessing the second instruction list, the position of the quantum measurement operation in the first quantum circuit can be determined based on the first information. When traversing to the quantum measurement operation located in the middle position, the reset operation may not be added. When the first information indicates that the quantum measurement operation is at the end position of the first quantum circuit, after the operation instructions of the quantum measurement operation are equivalently compiled, a reset operation may be added after the quantum measurement operation. After the reset, the quantum bit is recovered for continued use. In this way, the number of quantum bits of the second quantum circuit obtained by the equivalent compilation can be reduced accordingly.
[0101] For each operation instruction in the second instruction list, the operation instruction may be equivalently compiled to compile the operation instruction into an operation instruction in a second quantum circuit equivalent to the operation instruction. The second quantum circuit may be a dynamic quantum circuit.
[0102] When performing equivalent compilation, the qubit acted upon by the operation instruction in the second instruction list can be obtained, and a register unit can be allocated to the qubit, which can correspond to the qubit in the second quantum circuit. That is, the operation instruction can be mapped to a dynamic quantum circuit, and specifically, the operation on each qubit in the first quantum circuit (i.e., the qubit acted upon by the operation instruction in the second instruction list) can be dynamically loaded into the register unit of the second quantum circuit.
[0103] After the operation instruction of the quantum measurement operation is equivalently compiled, if the classification information indicates that the quantum measurement operation is located at the end position of the first quantum circuit, the register unit corresponding to the operation instruction of the quantum measurement operation can be recycled, and the operation instruction of the reset operation can be added after the operation instruction of the quantum measurement operation. Through the reset operation instruction, the register unit allocated to the quantum bit can be recycled for subsequent calculation. In this way, the width of the dynamic quantum circuit equivalently compiled can be ensured to be as small as possible.
[0104] In this embodiment, by obtaining the dependency between the operation instructions of the input quantum circuit, while taking into account the dependency between the operation instructions of the quantum circuit, the quantum operation is performed in the order of rows as much as possible, so that all operations on a certain quantum bit are performed as quickly as possible, and the quantum bit is quantum measured, so that the reordering of the operation instructions can be preprocessed. In addition, before equivalent compilation, the reordered operation instructions are preprocessed to obtain classification information indicating the location of the quantum measurement operation, and the equivalent compilation of the quantum circuit is performed based on the classification information, so that the input quantum circuit can be expanded to include intermediate measurements, classical control quantum operations, and multi-qubit gates. The application scenario of optimized compilation is more extensive.
[0105] Furthermore, by adding a reset operation instruction after the quantum measurement operation instruction at the end position during equivalent compilation, so as to provide for subsequent quantum bit calculations of quantum bits, the number of bits required for the dynamic quantum circuit obtained after compiling the quantum circuit can be made as small as possible, so that classical simulation and real machine operation of quantum circuits with large-scale quantum bits can be realized, which can be well applied to the classical simulation of large-scale quantum algorithms.
[0106] Moreover, quantum computers based on different architecture designs can provide different numbers of quantum bits and the ability to implement various operations. Through equivalent compilation, the operation scheme of quantum circuits on real quantum computers can be made more flexible, and dynamic quantum circuits and static quantum circuits can be flexibly selected according to actual hardware conditions. For example, for superconducting quantum computers with short coherence time but easy to expand the number of quantum bits, it is more suitable to run static quantum circuits with larger width and smaller depth; while for quantum computers based on ion trap architecture with longer coherence time but relatively poor scalability, it is more suitable to run dynamic quantum circuits with smaller width and larger depth.
[0107] Optionally, the step S104 specifically includes:
[0108] Traversing the second instruction list in reverse order, and when a quantum measurement operation is found, obtaining a first qubit acted upon by the quantum measurement operation;
[0109] Determine the position of the quantum measurement operation in the first quantum circuit based on the first quantum bit and a first target list updated during the reverse traversal to obtain the first information, wherein the first target list is used to record whether the quantum measurement operation of each quantum bit located at an end position of the first quantum circuit in the first quantum circuit has been traversed;
[0110] Wherein, in case of a quantum measurement operation of a quantum bit located at an end position of the first quantum circuit in the first quantum circuit being traversed in reverse order, the first target list is updated.
[0111] In this embodiment, the position of each quantum measurement operation in the first quantum circuit is determined by traversing the second instruction list in reverse order and recording whether the quantum measurement operation at the end position has been traversed during the traversal process through the first target list, so that the determination of classification information can be simply achieved through algorithm design.
[0112] Optionally, determining the position of the quantum measurement operation in the first quantum circuit based on the first quantum bit and the first target list updated during the reverse traversal to obtain the first information includes:
[0113] In a case where the first target list indicates that the quantum measurement operation of the first quantum bit located at the end position of the first quantum circuit has been traversed, determining that the quantum measurement operation is located at the middle position of the first quantum circuit, and obtaining the first information;
[0114] When the first target list indicates that the quantum measurement operation of the first quantum bit located at the end position of the first quantum circuit has not been traversed, it is determined that the quantum measurement operation is located at the end position of the first quantum circuit to obtain the first information.
[0115] In an optional implementation, when the quantum measurement operation is located in the middle position of the first quantum circuit, the first information may be False, and when it is located at the end position, the first information may be True.
[0116] In this way, the position of each quantum measurement operation in the first quantum circuit can be determined to achieve scenario classification of quantum measurement operations in the equivalent compilation process.
[0117] Optionally, the quantum operation further includes a target operation, the target operation is a quantum gate operation controlled by classical information, the classification information further includes second information, the second information includes: an attribute value for distinguishing each operation instruction of the target operation in the second instruction list, and determining the classification information based on the second instruction list includes:
[0118] In the process of traversing the second instruction list based on the traversal control index, the attribute value of the operation instruction of the target operation is determined based on the index value of the traversal control index of the operation instruction of the target operation traversed; and when the traversal of the second instruction list is completed, the second information is obtained.
[0119] In this implementation, the target operation may be a classical control quantum operation, and the classification information may include first information and second information. The classification information may classify the quantum measurement operation into four cases, such as Fig. 9 shown.
[0120] The first case, such as Fig. 9 As shown in (a), it is the circuit middle measurement + reset operation; the second case, as Fig. 9 As shown in (b), it is the circuit intermediate measurement + classical control quantum operation + reset operation; the third case, such as Fig. 9 (c) in the figure shows the measurement at the end of the circuit. The fourth case is as follows: Fig. 9 As shown in (d), it is the circuit end measurement + classical control quantum operation.
[0121] Among them, for Fig. 9For the first and second cases (i.e., the measurement operation in the middle of the circuit), after traversing to this type of quantum measurement operation, there is no need to add a reset operation to the instruction list, nor is there any need to recycle the quantum bit for continued use after the reset; Fig. 9 In the third case, after traversing to this type of quantum measurement operation, a reset operation can be added after the measurement operation in the instruction list, and the quantum bit can be recycled and continued to be used after the reset; Fig. 9 In the fourth case, after traversing this type of quantum measurement operation, it is necessary to wait until all subsequent classical control quantum operations are completed before the measured quantum bits can be reset and recovered.
[0122] Therefore, after obtaining the circuit instruction list with optimized execution order, the quantum measurement operations in the quantum circuit can be classified according to the above four types, and based on the classification information, the quantum circuit can be optimized and compiled through dynamic management of the quantum register unit.
[0123] The attribute value of the operation instruction of the target operation can be determined by the index value of the traversal control index during the traversal process. During the traversal process of the instruction list, if the operation instruction of the classical control quantum operation is traversed, the attribute value can be added to the operation instruction.
[0124] In an optional implementation, during the forward traversal, the index value of the traversal control index can be determined as the attribute value. In another optional implementation, when the second instruction list is traversed in reverse order, the attribute value of the operation instruction of the target operation is determined to be length-1-i, i is the index value of the traversal control index of the operation instruction of the target operation traversed, and length is the length of the second instruction list.
[0125] The specific process of determining classification information is as follows:
[0126] Input: quantum circuit width width, second instruction list circuit_list, second instruction list length length;
[0127] Output: circuit_list, the circuit instruction list after preprocessing, conditional_operations, the operation instruction list of all classical control quantum operations in circuit_list, and last_measurement, the operation instruction list of all quantum measurement operations at the end positions on all quantum bits in circuit_list.
[0128] Step 1: Create two empty lists conditional_operations and last_measurement, and initialize a list last_measurement_found (i.e., the first target list) of length width, in which the initial value of each element is False. This list is used to record whether the operation instruction of the last quantum measurement operation on each quantum bit has been searched;
[0129] Step 2: Traverse the input instruction list circuit_list in reverse order through a loop. Assume that the current traversed operation instruction is operation, and the current operation instruction is the i-th operation instruction traversed, and i is the traversal control index (which can start from 0);
[0130] Step 2.1: If operation is a quantum measurement operation, obtain the quantum bit which_qubit it acts on; if the value of which_qubit indexed in the last_measurement_found list is False, then perform operation a); if the value of which_qubit indexed in the last_measurement_found list is True, then perform operation b);
[0131] Operation a): Add the last parameter to operation with a value of True; add operation to the last_measurement list; modify the value of which_qubit indexed in the last_measurement_found list to True;
[0132] Operation b): Add the last parameter to operation with a value of False, and then continue to traverse the next operation instruction;
[0133] Step 2.2: If operation is a classical controlled quantum operation, that is, the condition of operation is not equal to None, add the c_gate_id attribute to operation, and the attribute value is (length-1-i); add operation to the conditional_operations list, and continue to traverse the next operation instruction;
[0134] Step 3: After completing the reverse traversal of the entire circuit_list, return the preprocessed circuit_list list, last_measurement list, and conditional_operations list.
[0135] It should be noted that in the process of traversing the circuit_list list in reverse order, the value of the loop variable i is not the actual index value of the operation in the circuit_list. Step 2.2 calculates the actual index value of the operation and adds the c_gate_id attribute to the classical control quantum operation, which is used to distinguish and identify each classical control quantum operation.
[0136] In addition, all quantum measurement operations in the circuit_list list can be divided into circuit intermediate measurements (operation instructions with the last parameter of the operation instruction being False) and circuit end measurements (operation instructions with the last parameter of the operation instruction being True), and all circuit end measurements are stored in the last_measurement list, which is convenient for subsequent optimization compilation. Fig. 9 The classification in is processed.
[0137] Optionally, the step S105 specifically includes:
[0138] For each operation instruction in the second instruction list, perform the following operations:
[0139] Obtaining a second quantum bit acted upon by the operation instruction;
[0140] Determining a first target identifier of a register unit of a second quantum circuit assigned to the second qubit based on the second qubit and a register unit dictionary, wherein the register unit dictionary includes a correspondence between register units and qubits;
[0141] Based on the first target identifier and the classification information, the operation instruction is equivalently compiled to obtain an operation instruction in a second quantum circuit equivalent to the operation instruction, and the third instruction list includes the operation instruction in the second quantum circuit obtained by the equivalent compilation.
[0142] In this implementation, equivalent compilation may be performed for each operation instruction in the second instruction list.
[0143] The operation instructions in the second instruction list may include instruction types and the quantum bits acted on.
[0144] In the equivalent compilation process, a quantum register may be introduced, and the second instruction list may be further compiled into a dynamic quantum circuit instruction list dynamic_circuit by dynamically increasing and decreasing its register units.
[0145] Specifically, when traversing the instruction list of the input quantum circuit, each quantum bit therein can be dynamically mapped to a register unit of the quantum register, and the unit address of the register unit is the quantum bit in the compiled dynamic quantum circuit.
[0146] Based on the second qubit acted upon by the operation instruction and the constructed register unit dictionary, a first target identifier of a register unit of the second quantum circuit assigned to the second qubit, i.e., the address of the register unit, can be determined. The register unit dictionary can be used to record the occupation status of the register unit, i.e., the key of the data in the register unit dictionary can be the address of the register unit, and the corresponding value can be which qubit in the instruction list of the input quantum circuit the register unit is assigned to.
[0147] For example, the register unit dictionary can be: {'0':0,'1':None,'2':3}, which means that the register unit with address 0 is assigned to qubit 0, the register unit with address 1 is free (ie, not assigned), and the register unit with address 2 is assigned to qubit 3.
[0148] In an optional implementation, before performing equivalent compilation of the second instruction list, an empty register unit dictionary may be constructed. Accordingly, when performing equivalent compilation of the instructions in the second instruction list, a register unit may be allocated to the second qubit acted upon by the operation instruction based on the register unit dictionary (if the register unit dictionary is empty, a new register unit may be created to record the address of the register unit), and the register unit dictionary may be updated based on the correspondence between the qubit and the register unit address to record the occupation status of the register unit. Afterwards, the equivalent compilation of the operation instruction in the second instruction list may be continued based on the second qubit acted upon by the operation instruction in the second instruction list and the updated register unit dictionary.
[0149] When the first target identifier is obtained, the operation instruction in the second instruction list can be equivalently compiled based on the first target identifier and the classification information, wherein the first target identifier can indicate the quantum bit of the quantum bit acted on by the operation instruction in the second quantum circuit equivalent to the operation instruction. The process of equivalent compilation will be described in detail in the following implementation mode.
[0150] In this way, equivalent compilation of the operation instructions of the first quantum circuit can be achieved to obtain the operation instructions in the second quantum circuit equivalent to the first quantum circuit.
[0151] Optionally, the equivalently compiling the operation instruction based on the first target identifier and the classification information to obtain an operation instruction in a second quantum circuit equivalent to the operation instruction includes:
[0152] In a case where the operation instruction is an operation instruction for a quantum measurement operation or an operation instruction for a target operation, determining a type of quantum operation corresponding to the operation instruction based on the classification information, and the target operation is a quantum gate operation controlled by classical information; based on the type of quantum operation corresponding to the operation instruction and the first target identifier, performing equivalent compilation on the operation instruction to obtain an operation instruction in a second quantum circuit equivalent to the operation instruction;
[0153] When the operation instruction is an operation instruction for a reset operation, based on the first target identifier, the operation instruction is equivalently compiled into an operation instruction for a reset operation in the second quantum circuit;
[0154] When the operation instruction is an operation instruction of a single quantum bit gate, based on the first target identifier, the operation instruction is equivalently compiled into an operation instruction of the single quantum bit gate in the second quantum circuit;
[0155] When the number of the second quantum bits is greater than 1, based on the first target identifier, the operation instruction is equivalently compiled into an operation instruction of a quantum gate operation corresponding to the operation instruction in the second quantum circuit.
[0156] In this embodiment, when the instruction type indicates that the operation instruction is an operation instruction for a reset operation, or an operation instruction for a multi-qubit gate operation (i.e., the number of second qubits is greater than 1), the operation instruction can be equivalently compiled into an operation instruction equivalent to the operation instruction in the second quantum circuit based on the first target identifier.
[0157] When the instruction type indicates that the operation instruction is an operation instruction of a quantum measurement operation or a classical control quantum operation, the type of quantum operation corresponding to the operation instruction can be determined based on the classification information, wherein the type of quantum operation corresponding to the operation instruction is the position type of the quantum operation.
[0158] For example, whether the quantum measurement operation is located at the end position, at the middle position, and whether there is a classical control quantum operation with the same controlled conditions after the quantum measurement operation. Another example is whether the classical control quantum operation is located after the quantum measurement operation at the end position, or at the middle position, and whether there are other classical control quantum operations with the same controlled conditions after the classical control quantum operation. All of the above can be indicated by the type of quantum operation.
[0159] Accordingly, the operation instruction can be equivalently compiled based on the type and the first target identifier, and the operation instruction obtained by the equivalent compilation includes at least an operation instruction in the second quantum circuit equivalent to the operation instruction. In some cases, such as when the quantum measurement operation is a quantum measurement operation at the end position and there is no subsequent classical control quantum operation whose controlled conditions match it, or when the classical control quantum operation is the last classical control quantum operation of the quantum measurement operation located at the end position, a reset operation will be generated subsequently to reset and recycle the measured quantum bit.
[0160] In this way, equivalent compilation of each operation instruction can be achieved, such as quantum measurement operation instructions located at different locations, operation instructions for classical control quantum operations, operation instructions for multi-qubit gates, reset operations, etc.
[0161] Optionally, when the operation instruction is an operation instruction for a quantum measurement operation, determining the type of quantum operation corresponding to the operation instruction based on the classification information includes:
[0162] When the classification information indicates that the quantum measurement operation is at an end position of the first quantum circuit, and the operation instructions after the quantum measurement operation in the second instruction list include a first operation instruction, determining that the type of the quantum measurement operation is a first type, and the first operation instruction is an operation instruction of a quantum gate operation controlled by classical information obtained by running the operation instruction;
[0163] When the classification information indicates that the quantum measurement operation is at an end position of the first quantum circuit, and the operation instructions after the quantum measurement operation in the second instruction list do not include the first operation instruction, determining that the type of the quantum measurement operation is the second type;
[0164] When the classification information indicates that the quantum measurement operation is in the middle of the first quantum circuit, the type of the quantum measurement operation is determined to be a third type.
[0165] The first type is Fig. 9 The fourth type is shown in (d) in the figure, and the second type is as follows Fig. 9 The third type is as shown in (c) of Fig. 9 (a) and Fig. 9 The type shown in (b) in FIG.
[0166] The position of the quantum measurement operation in the first quantum circuit can be determined based on the first information, such as when the first information is True, the indication is at the end position, and when the first information is False, the indication is at the middle position. Based on the second information or by traversing the operation instructions following the operation instructions of the quantum measurement operation in the second instruction list, it can be determined whether there is a matching classical control quantum operation following the operation instruction of the quantum measurement operation, thereby further determining whether the operation instructions following the quantum measurement operation in the second instruction list include the first operation instruction. In this way, the type of quantum measurement operation can be determined.
[0167] Optionally, the equivalently compiling the operation instruction based on the type of quantum operation corresponding to the operation instruction and the first target identifier to obtain an operation instruction in a second quantum circuit equivalent to the operation instruction includes:
[0168] Based on the first target identifier, compiling the operation instruction into an operation instruction of a quantum measurement operation in the second quantum circuit;
[0169] When the type of the quantum measurement operation is the second type, generating an operation instruction for a reset operation in the second quantum circuit based on the first target identifier;
[0170] The storage unit dictionary is updated, and the updated storage unit dictionary indicates that the storage unit corresponding to the first target identifier is a storage unit that is not allocated to a qubit.
[0171] In this embodiment, after the operation instruction is equivalently compiled into the operation instruction of the quantum measurement operation in the second quantum circuit based on the first target identifier, it is also necessary to generate the operation instruction of the reset operation based on the first target identifier for the second type of quantum measurement operation, and update the register unit dictionary to recycle the measured quantum bit. In this way, the equivalent compilation of the operation instruction of the quantum measurement operation can be achieved.
[0172] Optionally, when the operation instruction is an operation instruction of a target operation, determining the type of quantum operation corresponding to the operation instruction based on the classification information includes:
[0173] Determining that a second operation instruction is included after the operation instruction in the second instruction list based on the attribute value of the operation instruction in the second information, determining that the type of the target operation is a fourth type, the classification information further includes the second information, the second information including: an attribute value for distinguishing each operation instruction of the target operation in the operation instructions of the first quantum circuit, the second operation instruction being an operation instruction in the second instruction list that has the same controlled condition as the operation instruction and is located after the operation instruction;
[0174] In a case where it is determined based on the attribute value of the operation instruction in the second information that the second operation instruction is not included in the second instruction list after the operation instruction, and it is determined based on the first information that a third operation instruction matching the controlled condition of the operation instruction is located in the middle of the first quantum circuit, determining that the type of the target operation is the fifth type;
[0175] When it is determined based on the attribute value of the operation instruction in the second information that the second operation instruction is not included in the second instruction list after the operation instruction, and when it is determined based on the first information that a third operation instruction matching the controlled condition of the operation instruction is located at the end of the first quantum circuit, the type of the target operation is determined to be the sixth type, and the third operation instruction is an operation instruction for a quantum measurement operation.
[0176] In this embodiment, the fourth type is as follows Fig. 9 (b) and Fig. 9 The first type of classical control quantum operation is shown in (d), and the fifth type is as follows Fig. 9 The second classical control quantum operation position type is shown in (b), and the sixth type is as follows Fig. 9 (d) shows the second type of classically controlled quantum operation.
[0177] Based on the attribute value of the operation instruction, it can be determined whether the second instruction list also includes a second operation instruction after the operation instruction. For example, it can be determined whether, in addition to the operation instruction corresponding to the attribute value, the second instruction list contains other operation instructions with the same controlled conditions as the operation instruction. That is, after finding the operation instruction corresponding to the attribute value and excluding it, other operation instructions with the same controlled conditions as the operation instruction can also be found in the instruction list. At this time, it is determined that the second instruction list also includes the second operation instruction after the operation instruction. Otherwise, it is determined that the second instruction list does not include the second operation instruction after the operation instruction.
[0178] Based on the controlled conditions of the operation instruction, an operation instruction of a quantum measurement operation matching the operation instruction can be found, and the position of the operation instruction of the quantum measurement operation in the first quantum circuit can be determined based on the first information. In combination with the search situation of the second operation instruction and the position situation of the third operation instruction, the type of the operation instruction of the classical control quantum operation can be determined.
[0179] Optionally, the equivalently compiling the operation instruction based on the type of quantum operation corresponding to the operation instruction and the first target identifier to obtain an operation instruction in a second quantum circuit equivalent to the operation instruction includes:
[0180] Based on the first target identifier, compiling the operation instruction into an operation instruction of a quantum control operation equivalent to the target operation in the second quantum circuit;
[0181] When the type of the target operation is the sixth type, based on the third qubit acted upon by the third operation instruction and the register unit dictionary, determining a second target identifier of a register unit of the second quantum circuit assigned to the third qubit;
[0182] Based on the second target identifier, generating an operation instruction for a reset operation in the second quantum circuit;
[0183] The register unit dictionary is updated, wherein the updated register unit dictionary indicates that the register unit corresponding to the second target identifier is a register unit that is not allocated to a qubit.
[0184] In this embodiment, after the operation instruction is equivalently compiled into the operation instruction of the quantum control operation in the second quantum circuit based on the first target identifier, it is also necessary to search the second instruction list for the operation instruction of the quantum measurement operation that matches its controlled condition and is located at the end position for the sixth type of classical control quantum operation, generate the operation instruction of the reset operation based on the third quantum bit acted on by the operation instruction of the quantum measurement operation, and update the register unit dictionary to recycle the measured quantum bit. In this way, the equivalent compilation of the operation instruction of the classical control quantum operation can be achieved.
[0185] The specific process of optimizing and compiling the quantum circuit instruction list is as follows:
[0186] Input: preprocessed quantum circuit instruction list circuit_list; list conditional_operations containing all classical control quantum operation instructions in circuit_list; list last_measurement containing the last measurement operation instructions on all quantum bits in circuit_list;
[0187] Output: dynamic_circuit_list, a dynamic quantum circuit instruction list equivalent to the input quantum circuit.
[0188] Step 1: Create an empty dictionary qreg to record the dynamic allocation status of each register unit; and initialize an empty list dynamic_circuit_list to record the compiled dynamic quantum circuit instructions;
[0189] Step 2: Input the quantum circuit instruction list circuit_list by looping, and assume that the current operation instruction traversed is operation, and record the name parameter of the operation instruction as op_name;
[0190] Step 2.1: If the length of the which_qubit parameter of the current operation instruction operation is equal to 1, then use the values of qreg and which_qubit as input, obtain the updated qreg and the output register unit address address, and perform the following sub-operations according to the current operation:
[0191] Sub-operation a1: If the current operation is a measurement operation, obtain the basis parameter and mid parameter of operation, and record them as op_basis and op_mid respectively; generate the quantum bit measurement operation instruction [measure,address,op_basis,op_mid], and add it to the dynamic_circuit_list list; obtain the last parameter of the operation operation instruction. If the parameter value is False, it means that the measurement is not the end measurement of the circuit, and no operation is performed;
[0192] Continue to loop through the next operation instruction in the circuit_list list; if the value of this parameter is True, it means that the measurement is the circuit end measurement, then search the conditional_operations list by looping through it. If there is an operation instruction in the conditional_operations list with the condition parameter equal to op_mid, it means that there is a classical control quantum operation after the measurement operation, and no operation is performed;
[0193] Continue to loop through the next operation instruction in the circuit_list list; if the number of conditions of all operation instructions in the conditional_operations list is not equal to op_mid, it means that there is no classical control quantum operation after the measurement operation, then generate a quantum circuit reset operation instruction [reset, address, matrix, None] and add it to the dynamic_circuit_list list; change the register value corresponding to the address key in qreg to None;
[0194] Sub-operation a2: If the current operation is a classical control quantum operation, that is, the condition parameter of operation is not None, then record the parameter as op_cond; at the same time, obtain the c_gate_id parameter and parameters parameter of operation, and record them as c_id and op_para respectively; generate the classical control quantum operation instruction [op_name, address, op_para, op_cond], and add it to the dynamic_circuit_list list;
[0195] By looping through the conditional_operations list, assuming that the currently traversed element is conditional_operation: if the c_gate_id parameter of conditional_operation is not equal to c_id, no operation is performed and the next element is traversed; if the c_gate_id parameter of conditional_operation is equal to c_id, the currently traversed operation instruction is deleted from the conditional_operations list, and then the current loop is jumped out;
[0196] The conditional_operations list is traversed again by looping. If there is an operation instruction with the condition parameter equal to op_cond in the conditional_operations list, it means that there is a subsequent classical control quantum operation with op_cond as the condition, then no operation is performed, and the next operation instruction in the circuit_list list is traversed by looping. If the condition parameters of all operation instructions in the conditional_operations list are not equal to op_cond, it means that there is no subsequent classical control quantum operation with op_cond as the condition, and then the last_measurement list is traversed by looping.
[0197] If the mid parameter of all measurement operation instructions in the last_measurement list is not equal to op_cond, it means that the action condition of the current classical control quantum operation is the result of the measurement in the middle of the circuit, then no operation is performed, and the next operation instruction in the circuit_list list is traversed in a loop; if there is a measurement operation instruction in the last_measurement list whose mid parameter is equal to op_cond, it means that the action condition of the current classical control quantum operation is the result of the measurement at the end of the circuit;
[0198] Get the quantum bit which_qubit that the measurement operation instruction with mid parameter equal to op_cond acts on, take qreg and which_qubit as input, and get the corresponding register unit address address of the updated qreg and which_qubit; generate the reset operation instruction [reset,address,matrix,None] and add it to the dynamic_circuit_list list; set the value corresponding to the address key in qreg to None;
[0199] Sub-operation a3: If the current operation is a reset operation, obtain the matrix parameter of operation and record it as op_matrix; generate a reset operation instruction [reset, address, op_matrix, None] and add it to the dynamic_circuit_list list;
[0200] Sub-operation a4: If the current operation is a single-qubit gate operation, obtain the parameter of the current operation instruction and record it as op_para; generate a single-qubit gate operation instruction [op_name, address, op_para, None] and add it to the dynamic_circuit_list list;
[0201] Step 2.2: If the length of the which_qubit parameter of the current operation instruction operation is greater than 1, create a list qubits and assign the which_qubit parameter of operation to the qubits list; loop through the qubits list, assuming that the currently traversed element qubit is the i-th element in the list; use the values of qreg and qubit as input to obtain the updated qreg and the output register address address; modify the value of the i-th element of the qubits list to address; when the traversal and update of the qubits list is completed, obtain the parameters of the current operation instruction operation and record it as op_para; generate a multi-qubit gate operation instruction [op_name, qubits, op_para, None] and add it to the dynamic_circuit_list list;
[0202] Step 3: After looping through the circuit_list list, return to the optimized compiled circuit instruction list dynamic_circuit_list.
[0203] The key point of the above optimization compilation algorithm is that after all operations on a certain quantum bit are compiled, the corresponding register unit of the quantum bit needs to be recycled for subsequent calculations. This ensures that the width of the final compiled quantum circuit is as small as possible, which is more conducive to the execution of the final algorithm on hardware.
[0204] When traversing the circuit_list list, if the currently traversed operation is a measurement operation, you first need to compile the operation instruction, and then obtain the last parameter of the measurement operation to determine whether the measurement is the end measurement on the current quantum bit. If not, no subsequent operation is required; if so, you need to search the conditional_operations list to see if there is a classical control quantum operation with this measurement as the action condition that has not been compiled. If so, no subsequent operation is required; if not, you can reset the quantum bit in this measurement and recycle the corresponding storage unit in the quantum register.
[0205] When traversing the circuit_list list, if the currently traversed operation is a classical control quantum operation, the operation instruction must first be compiled, and the instruction is identified by c_gate_id, and deleted from the conditional_operations list, indicating that the operation instruction has been compiled. Then traverse the conditional_operations list to search whether there is a subsequent classical control quantum operation with the same action condition as the current operation. If so, no subsequent operation is required; if not, traverse the last_measurement list in a loop to search whether the measurement corresponding to the action condition of the current operation is the terminal measurement on a certain quantum bit. If not, no subsequent operation is required; if so, the quantum bit corresponding to its condition can be reset after the current classical control quantum operation, and the corresponding register unit in the quantum register can be recycled.
[0206] Optionally, determining the first target identifier of the register unit of the second quantum circuit assigned to the second qubit based on the second qubit and the register unit dictionary includes:
[0207] In the case where the corresponding relationship of the second qubit is found in the storage unit dictionary, the identifier of the storage unit corresponding to the second qubit is determined as the first target identifier;
[0208] In the case where it is found that the corresponding relationship of the second quantum bit is not included in the storage unit dictionary, a storage unit is allocated to the second quantum bit based on the storage unit dictionary, the identifier of the storage unit allocated to the second quantum bit is determined as the first target identifier, and the storage unit dictionary is updated based on the identifier of the storage unit allocated to the second quantum bit.
[0209] In this embodiment, if a qubit in the instruction list of the input quantum circuit already has a corresponding register unit, all quantum operations on the qubit in the instruction list of the input quantum circuit are transferred to the qubit of the dynamic quantum circuit corresponding to the register unit address for execution.
[0210] If a qubit does not have a corresponding register unit, a register unit needs to be allocated for it. This can be done by searching whether there are free register units available for allocation in the created register units. Optionally, when it is found that the register unit dictionary does not include the corresponding relationship of the second qubit, the register unit is allocated to the second qubit based on the register unit dictionary, including at least one of the following:
[0211] In the case that the registration unit dictionary contains an identifier of a first registration unit, assigning the first registration unit to the second qubit, the first registration unit being a registration unit that is not assigned to a node;
[0212] In the case that it is found that the registration unit dictionary does not include the identifier of the first registration unit, the number of registration units represented by the registration unit dictionary is obtained, the identifier of the created second registration unit is determined based on the number, and the second registration unit is allocated to the second qubit.
[0213] If there are multiple free register units, in one embodiment, the first register unit is the register unit with the smallest identifier among the register units not allocated to the node, that is, the register unit with the smallest address is selected for allocation, which can ensure that the register unit allocation is accurate and orderly.
[0214] If all the register cells in the currently created register cells are occupied, a new register cell is created and allocated to the second qubit.
[0215] In this way, register units are dynamically added as needed. If there are free units (such as 1:None, indicating that register unit 1 is a free register unit), the free units are allocated first. Otherwise, a new register unit is created, and based on the number of register units represented by the register unit dictionary (such as the register unit dictionary {'0':0, '1':2}, representing the number of register units is 2), the identifier of the created second register unit is determined, and the second register unit is allocated to the second quantum bit acted upon by the current equivalent compiled operation instruction.
[0216] At the same time, the register dictionary is updated based on the identifier of the register assigned to the second qubit, that is, the correspondence between the second qubit and the first target identifier is added to the register dictionary. When the entire instruction list is traversed, the total number of registers created is the number of qubits required for the dynamic quantum circuit corresponding to the compiled instruction list, which can ensure that the width of the compiled dynamic quantum circuit is as small as possible, which can greatly reduce the number of qubits required when executing the model.
[0217] The specific process of dynamically allocating registers for qubits is as follows:
[0218] Input: register unit dictionary qreg, the qubit to which register unit needs to be assigned which_qubit;
[0219] Output: the updated register unit dictionary qreg; the register unit address address assigned to the quantum bit which_qubit.
[0220] Step 1: Traverse all values of the register unit dictionary qreg and make judgments;
[0221] Step 2.1: If it contains which_qubit, indicating that the qubit has been assigned a register unit, then the register unit address corresponding to the which_qubit value is recorded as address, and the qreg dictionary is not operated;
[0222] Step 2.2: If which_qubit is not assigned a register, search for all register addresses whose value is None in the register dictionary qreg, and store them in the available_units list, and then make a judgment based on the available_units list; if the available_units list is empty, there is no free register in the current register, calculate the number of registers L in qreg, and record it as the register address address assigned to which_qubit, and then create a new register in the qreg dictionary, whose key is the unit address address, and whose value is the corresponding quantum bit which_qubit; if the available_units list is not empty, there is a free register in the current register, take the smallest unit address in the available_units list, and record it as the register address address assigned to which_qubit, and then modify the value corresponding to the address in qreg to which_qubit;
[0223] Step 3: Return and output the register unit dictionary qreg after the unit state is updated and the register unit address address assigned to which_qubit.
[0224] Optionally, the step S102 specifically includes:
[0225] Obtaining the qubits involved in the operation instruction in the first instruction list, where, when the operation instruction is an operation instruction for a quantum gate operation controlled by classical information, the qubits involved in the operation instruction include the qubits where the controlled conditions acted upon by the operation instruction are located;
[0226] Numbering the operation instructions based on the order in which each qubit involved in the operation instructions appears in the quantum operation of the first quantum circuit to obtain numbering information of the operation instructions of the first quantum circuit;
[0227] Based on the number information of the operation instruction, other operation instructions associated with the operation instruction in the first quantum circuit are searched to obtain the dependency relationship, where the quantum bits involved in the other operation instructions include the quantum bits involved in the operation instruction, and the execution order of the other operation instructions is before the operation instruction.
[0228] Each quantum operation in the input quantum circuit can be numbered, and the dependency between the execution order of each quantum operation can be found based on the number.
[0229] In this implementation, the first instruction list input into the quantum circuit can be traversed in a loop to obtain the quantum bits involved in the operation instructions, and each operation instruction therein can be numbered for each quantum bit to obtain numbering information.
[0230] The number information of the operation instruction can be represented by the number parameter (cmd_index parameter), and the cmd_index parameter can be added to the operation instruction. The specific format of this parameter can be a list, and the stored elements are binary arrays, that is, cmd_index = [[which_qubit, gate_index], ...]. Among them, which_qubit represents the quantum bit involved in the operation instruction, and gate_index represents the order in which the operation instruction acts on the which_qubit quantum bit. After adding this parameter, each operation instruction in the instruction list of the quantum circuit becomes a list containing five elements, that is, operation = [name, which_qubit, parameters / basis / matrix, condition / mid / None, cmd_index].
[0231] For each single-qubit gate, the elements in the cmd_index list contain a two-element array. For example Figure 3 The first H gate acting on qubit 2 in the middle, after adding the cmd_index parameter, its operation instruction becomes: [H,2,None,None,[2,1]]. For each n-qubit gate, the elements in the cmd_index list contain n binary arrays, marking the qubits acted on by the n-qubit gate and the order in which they appear on the acted qubits. For example Figure 3 For the Toffoli gate acting on qubits 1, 2, and 3, the operation instructions become [Toffoli, [1, 2, 3], None, None, [[1, 7], [2, 3], [3, 3]]] after adding the cmd_index parameter. For each classical control quantum operation, the elements in the cmd_index list contain two binary arrays, corresponding to the qubit and conditional qubit it acts on, as well as the order of the operation on the two qubits. For example Figure 3 The classical control Paili Z gate on quantum bit 3, after adding the cmd_index parameter, its operation instruction becomes: [Z,3,None,'a',[[1,4],[3,2]]]. Correspondingly, Figure 3 The results of the numbering of each quantum operation in the compilable circuit shown are as follows Fig.10 shown.
[0232] Regarding the numbering of the qubits involved in the quantum operation, in an optional implementation, the qubits involved in the quantum operation can be numbered by a reverse order traversal method. In another optional implementation, the qubits involved in the quantum operation can also be numbered by a forward order traversal method, which is not specifically limited here.
[0233] Afterwards, other operation instructions associated with the operation instruction in the first quantum circuit can be searched based on the number information of the operation instruction, and the dependency relationship of the operation instruction includes other operation instructions associated with the operation instruction. The dependency relationship of the operation instruction may include all other operation instructions that are ordered before the operation instruction and involve the same qubit as the operation instruction, or may only include the nearest neighbor operation instruction that must be executed before executing the current operation instruction, which is not specifically limited here.
[0234] In this embodiment, by numbering each quantum operation in the input quantum circuit based on the quantum bits involved in the operation instructions, and finding the dependency between the execution order of each quantum operation according to the number, the dependency of the execution order of the operation instructions of the first quantum circuit can be simply determined.
[0235] Optionally, before numbering the operation instructions based on the order in which each qubit involved in the operation instructions appears in the quantum operation of the first quantum circuit to obtain the numbering information of the operation instructions of the first quantum circuit, the method further includes:
[0236] Determine, based on a second target list updated during the forward traversal of the first instruction list, the order in which each qubit involved in the operation instruction appears in the quantum operation of the first quantum circuit, wherein the second target list is used to record the order in which each qubit in the first quantum circuit appears during the forward traversal;
[0237] Among them, when the operation instruction of the forward-order traversal involves the fourth quantum bit, the order in which the fourth quantum bit in the second target list appears during the forward-order traversal is increased by 1, and the fourth quantum bit is any quantum bit in the first quantum circuit.
[0238] In this implementation, the qubits involved in the quantum operation can be numbered by forward order traversal, and the specific process is as follows:
[0239] Input: quantum circuit list circuit_list, quantum circuit width width;
[0240] Output: circuit_list list with cmd_index parameter added for each operation instruction.
[0241] Step 1: Initialize a list operation_counter (i.e., the second target list) with a length of width, where the initial value of each element is 0;
[0242] Step 2: Loop through the circuit_list list, and create an empty list qubits for each element traversed to record the qubits involved in the current operation; add the cmd_index parameter to the current element, with an initial value of an empty list; then make a judgment based on the operation of the currently traversed element:
[0243] Step 2.1: If the current element operation is a classical control quantum operation, that is, the condition parameter of the current element operation is not None; record the quantum bit which_qubit that the operation acts on into the qubits list; then loop through the circuit_list list, search for the measurement operation corresponding to the condition of the current operation operation, record the quantum bit which_qubit that the measurement operation acts on into the qubits list, and then jump out of the current loop;
[0244] Step 2.2: If the current element operation is a quantum gate operation (including single- and multi-qubit gates), a measurement operation or a reset operation, that is, the condition parameter of the current element operation is None; record all elements in the qubit which_qubit that the operation acts on into the qubits list;
[0245] Step 2.3: After completing step 2.1 or step 2.2, add the qubits list as the qubits parameter of the current operation operation; then loop through the qubits list, assuming that the element currently traversed is a qubit; add 1 to the value indexed as qubit in the operator_counter list; add [qubit, operator_counter[qubit]] to the cmd_index parameter list of the currently traversed operation operation;
[0246] Step 3: After traversing the entire circuit_list list, return to the circuit_list list after adding the cmd_index parameter for each operation.
[0247] For classical control quantum operations, the quantum bits involved include the quantum bit which_qubit it acts on and the quantum bit where its condition condition is located, and the condition value is the mid of a certain measurement. Therefore, if you want to find the corresponding quantum bit through condition, you need to re-traverse the circuit_list list, find the measurement operation with mid equal to condition, and then obtain its quantum bit. For convenience, you can add a qubits parameter to each operation instruction to indicate the quantum bits involved in the operation. Therefore, in the output circuit_list list, each operation instruction actually contains six elements, namely operation = [name, which_qubit, parameters / basis / matrix, condition / mid / None, cmd_index, qubits].
[0248] For example Fig.10 The classically controlled Pauli Z gate on qubit 3 has an operation instruction of [Z,3,None,'a',cmd_index=[[1,4],[3,2]],qubits=[1,3]] in the output circuit_list list.
[0249] If the qubits involved in the quantum operation are numbered by reverse traversal, after each operation instruction operation, record the qubit which_qubit it acts on, and then traverse the circuit_list list in reverse order from the previous element of the operation instruction to search for the number of operations on which_qubit before the operation. When the reverse traversal is completed, add the cmd_index parameter to operation. Assuming that the circuit_list list contains N operation instructions, after traversing to the i-th element, the number of elements traversed in reverse order is i-1, and the total number of loop traversals is Therefore, the algorithm complexity is O(N 2 ). The qubits involved in the quantum operation are numbered by forward-order traversal. In the forward-order traversal circuit_list list, only one layer of loop on the qubits list is nested. Assuming that the maximum number of qubits involved in the operation instructions in the circuit is n, the maximum algorithm complexity is O(N×n). Generally speaking, the value of n is less than N. Therefore, numbering the qubits involved in the quantum operation by forward-order traversal has certain advantages in algorithm complexity.
[0250] Optionally, searching, based on the serial number information of the operation instruction, other operation instructions associated with the operation instruction in the first quantum circuit to obtain the dependency relationship includes:
[0251] Based on the numbering information of the operation instruction, obtaining target numbering information, the qubit number in the target numbering information is the same as the qubit number in the numbering information of the operation instruction, and the order in which the qubits in the target numbering information appear in the quantum operation of the first quantum circuit is less than the order in which the qubits in the numbering information of the operation instruction appear in the quantum operation of the first quantum circuit;
[0252] The other operation instructions corresponding to the target number information are obtained to obtain the dependency relationship, where the other operation instructions are operation instructions that are executed before the operation instruction in the first quantum circuit and are adjacent to the operation instruction.
[0253] In this implementation, the order of quantum operations involving intersecting qubits in the quantum circuit is not interchangeable, that is, the operations in the quantum circuit need to be executed in a certain order to ensure that the required computing tasks are completed. Fig.10 In the quantum circuit shown, the Toffoli gates for qubits 0, 1, and 2 can only be executed after the three H gates with cmd_index [0, 1], [1, 1], and [2, 1] are executed.
[0254] In order to obtain the execution dependencies of each operation in a given circuit, we can loop through the quantum circuit instruction list circuit_list to which the cmd_index parameter has been added for each operation, and add a domain parameter to each operation instruction in the list to indicate the execution dependency of the operation.
[0255] Specifically, the domain parameter of an operation instruction is a list, in which each element is the cmd_index value of the operation that must be completed before the current operation is performed, that is, domain = [cmd_index_1, cmd_index_2, ...,]. Only the nearest neighbor operations that must be completed before the current operation are considered.
[0256] After adding this parameter, each operation instruction in the list becomes a list containing seven elements, that is, operation = [name, which_qubit, parameters / basis / matrix, condition / mid / None, cmd_index, qubits, domain].
[0257] For an n (n>=1) qubit operation, its domain parameter list contains n elements, which are the cmd_index values of the previous operation on the n qubits it acts on. The operation may be a single qubit operation, a multi-qubit gate, or a classical control quantum operation. For example Fig.10 Before the Toffoli gates [[0,2],[1,2],[2,2]] on qubits 0,1,2 are executed, the three H gates [0,1],[1,1],[2,1] on qubits 0,1,2 need to be executed respectively. Therefore, after adding the domain parameter, the operation instruction becomes: [Toffoli,[0,2,1],None,None,[[0,2],[1,2],[2,2]],[0,1,2],domain=[[0,1],[1,1],[1,2]]]. For example, before the reset operation [1,5] on qubit 1 is executed, the classical controlled Pauli Z gate [[1,4],[3,2]] on qubit 3 needs to be executed. Therefore, after adding the domain parameter, the operation instruction becomes: [reset,[1],None,None,[[1,5]],[1],domain=[[[1,4],[3,2]]]].
[0258] For a classical control quantum operation, its domain parameter list contains two elements, which are the previous operation on the quantum bit which_qubit it acts on and the cmd_index value of the measurement operation corresponding to its condition condition. Fig.10 The classical controlled Pauli X gate [[2,4],[3,5]] acting on qubit 2 requires the measurement operation [3,4] on qubit 3 and the Toffoli gate [[1,7],[2,3],[3,3]] on qubits 1,2,3 before executing this operation. Therefore, after adding the domain parameter, the operation instruction becomes: [X,2,None,'b',[[2,4],[3,5]],[2,3]domain=[[3,4],[[1,7],[2,3],[3,3]]]].
[0259] If no other operations need to be performed before performing an operation, the domain parameter of the operation is an empty list. Fig.10 The H gate [1,1] acting on quantum bit 1 in the middle, after adding the domain parameter, its operation instruction becomes: [H,1,None,None,[1,1],[1],domain=[]].
[0260] The specific process of adding the domain parameter is as follows:
[0261] Input: Quantum circuit instruction list circuit_list with cmd_index and qubits parameters added;
[0262] Output: circuit_list list with domain parameter added for each operation instruction.
[0263] Step 1: Loop through the circuit_list list, set the current operation instruction to be operation; add the domain parameter to the current operation instruction operation, with the initial value being an empty list; get the length of the qubits parameter list of the current operation instruction operation, and initialize a list qubits_done with a length of length, with each element initially having a value of False;
[0264] Starting from the operation instruction before the current operation instruction operation, traverse the circuit_list list in reverse order, assuming that the element currently traversed is pre_operation; traverse the qubits parameter list of the operation instruction by looping, assuming that the element qubit currently traversed is the i-th element in the qubits list;
[0265] If the value of the qubit is included in the qubit parameter list of the pre_operation instruction, and the value of the i-th element in qubits_done is False; add the cmd_index parameter of pre_operation to the domain parameter list of the operation instruction, and change the value of the i-th element in qubits_done to True;
[0266] If the qubit value is not included in the qubit parameter list of the pre_operation instruction, or the value of the i-th element in qubits_done is True, no operation is performed and the circuit_list list is traversed in reverse order;
[0267] If the values of all elements in the qubits_done list are True, then jump out of the reverse loop of the circuit_list list;
[0268] Step 2: After looping through the circuit_list list, return to the circuit_list list after adding the domain parameter for each operation instruction.
[0269] For each quantum bit involved in an operation instruction, it is only necessary to obtain the cmd_index value of the previous nearest neighbor operation on the quantum bit. Therefore, every time an operation instruction is traversed, a list qubits_done with the same length as its parameter qubits list is initialized, and then the circuit_list list is looped in reverse order to search for the nearest neighbor operations on all quantum bits. The elements in the qubits_done list correspond one-to-one to the elements in the qubits list, and are used to record whether the cmd_index of the nearest neighbor operation instruction on each quantum bit in the qubits list has been added to the domain parameter of the current operation instruction. False means it has not been added, and True means it has been added. When the cmd_index of the nearest neighbor operation instructions on all quantum bits in the qubits list are added to the domain parameter of the current operation instruction, the reverse loop can be jumped out to continue adding the domain parameter for the next operation instruction.
[0270] In this implementation, by searching for the nearest neighbor operation instruction that must be executed before executing the current operation instruction, the dependency relationship of the execution order of the operation instructions of the first quantum circuit can be easily determined.
[0271] Optionally, the step S103 specifically includes:
[0272] The operation instructions of the first quantum circuit are first reordered in the ascending order of the qubit numbers involved in the operation instructions to obtain a fourth instruction list of the first quantum circuit, in which the target qubit numbers in the operation instructions arranged earlier are smaller than the target qubit numbers in the operation instructions arranged later, and the operation instructions acting on the same qubit numbers are arranged in the relative order of the operation instructions in the first quantum circuit, and the target qubit is the qubit with the smaller number among the qubits involved in the operation instructions;
[0273] Based on the dependency relationship, the fourth instruction list is reordered in a second manner to obtain the second instruction list.
[0274] In this implementation, the operation instructions in the first instruction list may be reordered according to the row order priority principle, and then based on the reordering, the dependency relationship between the operation instructions may be considered, that is, based on the dependency relationship between the operation instructions, the operation instructions may be reordered to obtain the second instruction list. That is, the operation instructions may be sorted in the corresponding order through two reorderings.
[0275] During the first reordering process, the target qubits involved in each operation instruction in the instruction list of the quantum circuit can be compared, and the operation instruction with a smaller target qubit number is placed in front; for instructions with the same target qubit number, they are arranged according to their relative order in the instruction list of the original quantum circuit, and the instruction list under the default order, i.e., the fourth instruction list, can be obtained accordingly. Among them, for single-qubit quantum operations, the target qubit takes the value of the qubit it acts on, which_qubit; for multi-qubit gates and classical control quantum operations, the target qubit number takes the value of the smallest qubit in the qubits list involved.
[0276] Note that the default sorting does not take into account the dependency between the operation nodes, and is only an ideal sorting method. Based on the default sorting, a second re-sorting can be performed according to the dependency between the operation instructions to obtain a second instruction list.
[0277] In an optional implementation, the operation instructions in the fourth instruction list can be subjected to a second reordering by swapping between different operation instructions, so that for each operation instruction, other operation instructions with which it has a dependency relationship are sorted before the operation instruction, and the order of the operation instructions after the second reordering is the default order.
[0278] In another optional implementation, for an operation instruction, a second reordering of the operation instructions in the fourth instruction list may be achieved by obtaining a list of operation instructions that are sorted after the operation instruction and have a dependency relationship with the operation instruction, and sorting different lists.
[0279] Among them, different lists may include a list of operation instructions sorted before the operation instruction, a list of operation instructions sorted after the operation instruction and having a dependency relationship with it, a list composed of the operation instruction, and a list of operation instructions sorted after the operation instruction and having no dependency relationship with it.
[0280] In this embodiment, the operation instructions in the first instruction list are first reordered according to the row order priority principle, and then based on the reordering, the dependency relationship between the operation instructions is considered, that is, based on the dependency relationship between the operation instructions, the operation instructions are reordered to obtain the second instruction list. That is, the operation instructions can be sorted in the corresponding order through two reorderings. In this way, the process of reordering the operation instructions can be simplified.
[0281] Optionally, performing a second reordering on the fourth instruction list based on the dependency relationship to obtain the second instruction list includes:
[0282] The fourth instruction list is traversed for operation instructions, and the fourth instruction list is split for the currently traversed operation instruction to obtain a first list, a second list, and a third list, wherein the first list is a list consisting of the operation instruction ranked first in the fourth instruction list to the previous operation instruction adjacent to the currently traversed operation instruction, the second list is a list consisting of the currently traversed operation instructions, and the third list is a list consisting of the operation instructions ranked after the currently traversed operation instruction in the fourth instruction list;
[0283] Rearranging the operation instructions of the fourth instruction list based on the target dependency relationship between the currently traversed operation instruction and the operation instruction of the first quantum circuit in the dependency relationship, the first list, the second list, and the third list;
[0284] When the traversal of the fourth instruction list is completed, the second instruction list is determined based on the rearranged fourth instruction list.
[0285] In this implementation, for an operation instruction, a second reordering of the operation instructions in the fourth instruction list can be achieved by obtaining a list of operation instructions that are sorted after the operation instruction and have a dependency relationship with the operation instruction, and by sorting different lists.
[0286] Specifically, the fourth instruction list can be traversed for the operation instructions, and the fourth instruction list can be split for the currently traversed operation instructions to obtain the first list, the second list, and the third list. For example, if the currently traversed operation instruction is the jth instruction, the first list is a list consisting of the operation instructions ranked from 1 to j-1 in the fourth instruction list, the second list is a list consisting of the operation instructions ranked from j+1 to m in the fourth instruction list. Among them, m is the length of the fourth instruction list, that is, the number of operation instructions.
[0287] Accordingly, based on the target dependency relationship between the currently traversed operation instruction and the operation instructions of the first quantum circuit and the first list, a list of operation instructions that are sorted after the operation instruction and have a target dependency relationship with the operation instruction can be screened out from the third list.
[0288] List splicing can be performed based on the first list, this list (i.e., the list of operation instructions sorted after the currently traversed operation instruction and having a target dependency relationship with it), the second list, and the arrangement order of the list of operation instructions sorted after the operation instruction and having no target dependency relationship with it determined based on the third list and this list, so as to achieve a second reordering of the operation instructions in the fourth instruction list and obtain a second instruction list.
[0289] In this way, the order of the operation instructions in the default order can be adjusted based on the dependency relationship between the operation instructions, and the order adjustment process is relatively simple.
[0290] Optionally, the reordering of the operation instructions of the fourth instruction list based on the target dependency relationship between the currently traversed operation instruction in the dependency relationship and the operation instructions of the first quantum circuit, the first list, the second list, and the third list includes:
[0291] Based on the target dependency relationship and the first list, obtaining a third target list, the third target list indicating the operation instructions in the first list that have the target dependency relationship with the currently traversed operation instruction;
[0292] Based on the third target list and the fourth target list, determining a fifth target list, the fourth target list indicating the operation instructions in the fourth instruction list that have the target dependency relationship with the currently traversed operation instruction, and the fifth target list being a list obtained by deleting the third target list from the fourth target list;
[0293] When the fifth target list is not an empty set, deleting the operation instructions indicated by the fifth target list from the third list to obtain a fourth list;
[0294] The first list, the operation instructions indicated by the fifth target list, the second list and the fourth list are concatenated in order from front to back to obtain the rearranged fourth instruction list.
[0295] In this implementation, based on the target dependency relationship between the currently traversed operation instruction and the operation instruction of the first quantum circuit, the operation instructions having the target dependency relationship with the currently traversed operation instruction can be obtained from the first list, and these operation instructions can constitute the third target list. For example, the operation instruction including the domain parameter in the currently traversed operation instruction can be obtained from the first list to obtain the third target list.
[0296] A fourth target list is obtained, and the fourth target list may include operation instructions in the fourth instruction list that have a target dependency relationship with the currently traversed operation instruction. A list obtained by deleting the third target list from the fourth target list is the fifth target list, which is a list of operation instructions that are sorted after the currently traversed operation instruction and have a target dependency relationship with it. The operation instructions in the fifth target list are sorted according to the row order priority principle, that is, the default sorting.
[0297] If the fifth target list is empty, it means that there is no operation instruction in the third list that has a target dependency relationship with the currently traversed operation instruction.
[0298] If the fifth target list is not empty, it means that there are operation instructions in the third list that have a target dependency relationship with the currently traversed operation instruction. Accordingly, the operation instructions in the fifth target list in the third list can be deleted to obtain a fourth list, which is a list of operation instructions that are sorted after the currently traversed measurement instruction and have no target dependency relationship with it.
[0299] By concatenating the lists in the order of the first list, the fifth target list, the second list, and the fourth list from front to back, the rearranged fourth instruction list can be obtained, and then the second instruction list can be determined based on the rearranged fourth instruction list. In this way, the determination of the second instruction list can be achieved.
[0300] Based on the default sorting (i.e., the sorting indicated by the row order priority principle), the process of sorting and adjusting according to the dependency relationship between operation instructions is as follows:
[0301] Input: Quantum circuit instruction list circuit_list with cmd_index, qubits and domain parameters added;
[0302] Output: quantum circuit instruction list circuit_list after the operation execution order is optimized.
[0303] Step 1: Sort the input instruction list circuit_list by default, and record the list length as c; traverse the circuit_list list by looping;
[0304] Step 1.1: Let the currently traversed operation instruction operation be the i-th operation instruction in the list (where i∈{1,2,…,c}); set the parameter optimal=False. When optimal=False, perform the following operations:
[0305] Record the list consisting of the 1st to i-1th elements in the list circuit_list as C1, store the currently traversed operation instruction operation in the list C2, and record the list consisting of the i+1th to cth elements in the list circuit_list as C3; record the set consisting of the cmd_index parameters of all operations in the list C1 in the list executed_indices, and record the set consisting of the domain parameters of the operations operation in the list C2 in the list domains;
[0306] Perform a set operation P_index = domains\executed_indices, that is, find the elements in the domains list that are not included in the executed_indices list and store them in the P_index list;
[0307] If the P_index list is not empty, traverse the C3 list, find the operations corresponding to all elements in P_index in the C3 list, store them in the P list, and perform default sorting on all operation instructions in the P list. Then delete all operations in the P list from the C3 list, and update the order of the circuit_list list to [C1, P, C2, C3];
[0308] If the P_index list is empty, rewrite the optimal parameter to True and return to step 1.1 to continue looping through the i+1th operation instruction in the circuit_list list;
[0309] Step 2: After looping through all elements of the circuit_list list, the updated circuit_list list is the quantum circuit instruction list after the execution order is optimized.
[0310] In order to measure a quantum bit in a quantum circuit as quickly as possible so as to facilitate its resetting for subsequent calculations, after completing the second reordering, the execution order of each quantum measurement operation in the reordered fourth instruction list can be moved forward as much as possible.
[0311] Optionally, after performing a second reordering on the fourth instruction list based on the dependency relationship, the method further includes:
[0312] Move the operation instructions of the quantum measurement operation in the rearranged fourth instruction list to the target position to obtain the second instruction list;
[0313] Among them, the target position is a position located after the target operation instruction in the rearranged fourth instruction list and adjacent to the target operation instruction, the quantum bit acted upon by the target operation instruction includes the quantum bit acted upon by the operation instruction of the quantum measurement operation, and the operation instructions sorted after the target position in the second instruction list do not include the quantum bit acted upon by the operation instruction of the quantum measurement operation.
[0314] The specific process is as follows:
[0315] Input: the instruction list circuit_list after the execution order of each quantum operation is optimized and sorted, i.e. the fourth instruction list;
[0316] Output: A list of instructions that optimizes the execution order of all quantum measurement operations.
[0317] Step 1: Traverse the instruction list circuit_list through a loop;
[0318] Step 2.1: If the currently traversed operation instruction is the operation instruction of the measurement operation, measurement = [measure, which_qubit, None, None, cmd_index, domain], then the measured qubit is recorded as measured_qubit = which_qubit, and starting from the previous operation of the measurement operation, the circuit_list list is traversed in reverse order, and the currently traversed element is set to gate = [name, which_qubit, parameters, condition, cmd_index, domain]; if measured_qubit is included in the qubit which_qubit list acted on by the currently traversed element gate, then the operation instruction of the currently traversed measurement operation measurement is inserted after the gate operation, and then the reverse traversal is jumped out;
[0319] Step 2.2: If measured_qubit is not included in the which_qubit list of the qubits acted on by the currently traversed element gate, continue to traverse the next operation instruction;
[0320] Step 3: After completing the traversal of the entire circuit_list, return the instruction list after the execution order of the measurement operation is optimized, that is, the second instruction list.
[0321] In this way, all operations on a quantum bit can be performed as quickly as possible and the quantum bit can be measured.
[0322] In order to demonstrate the compilation effect of quantum circuit optimization compilation in this embodiment, a dynamic circuit compilation example including multi-qubit gates, classical control quantum operations and reset operations is given, where the input quantum circuit diagram is as follows: Fig.11 After optimization and compilation, the output dynamic quantum circuit is as follows Fig.12 As shown. It can be seen that after optimized compilation, the number of quantum bits required for the quantum circuit can be effectively reduced.
[0323] Second embodiment
[0324] like Fig.13 As shown, the present disclosure provides a quantum circuit processing device 1300, comprising:
[0325] A first acquisition module 1301 is used to acquire a first instruction list, where the first instruction list includes operation instructions of a first quantum circuit, where the operation instructions are used to indicate quantum operations of the first quantum circuit, where the quantum operations include quantum measurement operations;
[0326] A second acquisition module 1302 is used to acquire a dependency relationship of an execution order of operation instructions of the first quantum circuit based on the first instruction list;
[0327] A reordering module 1303 is used to reorder the operation instructions of the first quantum circuit according to the order of the quantum bit numbers involved in the operation instructions from small to large based on the dependency relationship to obtain a second instruction list of the first quantum circuit;
[0328] A determination module 1304 is used to determine classification information based on the second instruction list, where the classification information includes: first information indicating the position of the quantum measurement operation at the first quantum circuit;
[0329] An equivalent compilation module 1305 is used to perform equivalent compilation on the first quantum circuit based on the classification information and the second instruction list when the first information indicates that the quantum measurement operation is at the end position of the first quantum circuit, so as to obtain a third instruction list of a second quantum circuit equivalent to the first quantum circuit, wherein the third instruction list includes: an operation instruction of a reset operation, the operation instruction of the reset operation is located after the operation instruction of the quantum measurement operation, the reset operation is used to reset the quantum state of the quantum bit to a zero state, the number of quantum bits of the second quantum circuit is less than the number of quantum bits of the first quantum circuit, and the end position indicates that the quantum measurement operation is the last quantum measurement operation in the quantum measurement operations along the time evolution direction of the quantum state.
[0330] Optionally, the determining module 1304 includes:
[0331] A first acquisition submodule is used to traverse the second instruction list in reverse order, and when a quantum measurement operation is traversed, obtain a first qubit acted upon by the quantum measurement operation;
[0332] A first determination submodule is configured to determine the position of the quantum measurement operation in the first quantum circuit based on the first quantum bit and a first target list updated during the reverse traversal process to obtain the first information, wherein the first target list is used to record whether the quantum measurement operation of each quantum bit located at an end position of the first quantum circuit in the first quantum circuit has been traversed;
[0333] Wherein, in case of a quantum measurement operation of a quantum bit located at an end position of the first quantum circuit in the first quantum circuit being traversed in reverse order, the first target list is updated.
[0334] Optionally, the first determining submodule is specifically used to:
[0335] In a case where the first target list indicates that the quantum measurement operation of the first quantum bit located at the end position of the first quantum circuit has been traversed, determining that the quantum measurement operation is located at the middle position of the first quantum circuit, and obtaining the first information;
[0336] When the first target list indicates that the quantum measurement operation of the first quantum bit located at the end position of the first quantum circuit has not been traversed, it is determined that the quantum measurement operation is located at the end position of the first quantum circuit to obtain the first information.
[0337] Optionally, the quantum operation further includes a target operation, the target operation is a quantum gate operation controlled by classical information, the classification information further includes second information, the second information includes: an attribute value for distinguishing each operation instruction of the target operation in the second instruction list, and the determination module includes:
[0338] The second determination submodule is used to determine the attribute value of the operation instruction of the target operation based on the index value of the traversal control index of the operation instruction of the target operation traversed during the process of traversing the second instruction list based on the traversal control index; and obtain the second information when the traversal of the second instruction list is completed.
[0339] Optionally, when the second instruction list is traversed in reverse order, the attribute value of the operation instruction of the target operation is determined to be length-1-i, where i is the index value of the traversal control index of the operation instruction of the target operation traversed, and length is the length of the second instruction list.
[0340] Optionally, the equivalent compilation module 1305 includes:
[0341] A second acquisition submodule, configured to acquire, for each operation instruction in the second instruction list, a second qubit acted upon by the operation instruction;
[0342] a third determination submodule, configured to determine a first target identifier of a register unit of a second quantum circuit allocated to the second qubit based on the second qubit and a register unit dictionary, wherein the register unit dictionary includes a correspondence between register units and qubits;
[0343] an equivalent compilation submodule, configured to perform equivalent compilation on the operation instruction based on the first target identifier and the classification information to obtain an operation instruction in a second quantum circuit equivalent to the operation instruction, wherein the third instruction list includes the operation instruction in the second quantum circuit obtained by equivalent compilation.
[0344] Optionally, the equivalent compilation submodule includes:
[0345] A first equivalent compilation unit is used to determine, when the operation instruction is an operation instruction of a quantum measurement operation or an operation instruction of a target operation, based on the classification information, the type of quantum operation corresponding to the operation instruction, and the target operation is a quantum gate operation controlled by classical information; based on the type of quantum operation corresponding to the operation instruction and the first target identifier, perform equivalent compilation on the operation instruction to obtain an operation instruction in a second quantum circuit equivalent to the operation instruction;
[0346] A second equivalent compiling unit is configured to, when the operation instruction is an operation instruction of a reset operation, compile the operation instruction into an operation instruction of a reset operation in the second quantum circuit based on the first target identifier;
[0347] a third equivalent compilation unit, configured to, when the operation instruction is an operation instruction of a single quantum bit gate, equivalently compile the operation instruction into an operation instruction of the single quantum bit gate in the second quantum circuit based on the first target identifier;
[0348] and a fourth equivalent compilation unit, configured to, when the number of the second quantum bits is greater than 1, equivalently compile the operation instruction into an operation instruction of a quantum gate operation corresponding to the operation instruction in the second quantum circuit based on the first target identifier.
[0349] Optionally, when the operation instruction is an operation instruction of a quantum measurement operation, the first equivalent compilation unit is specifically used to:
[0350] When the classification information indicates that the quantum measurement operation is at an end position of the first quantum circuit, and the operation instructions after the quantum measurement operation in the second instruction list include a first operation instruction, determining that the type of the quantum measurement operation is a first type, and the first operation instruction is an operation instruction of a quantum gate operation controlled by classical information obtained by running the operation instruction;
[0351] When the classification information indicates that the quantum measurement operation is at an end position of the first quantum circuit, and the operation instructions after the quantum measurement operation in the second instruction list do not include the first operation instruction, determining that the type of the quantum measurement operation is the second type;
[0352] When the classification information indicates that the quantum measurement operation is in the middle of the first quantum circuit, the type of the quantum measurement operation is determined to be a third type.
[0353] Optionally, the first equivalent compilation unit is further used to:
[0354] Based on the first target identifier, compiling the operation instruction into an operation instruction of a quantum measurement operation in the second quantum circuit;
[0355] When the type of the quantum measurement operation is the second type, generating an operation instruction for a reset operation in the second quantum circuit based on the first target identifier;
[0356] The storage unit dictionary is updated, and the updated storage unit dictionary indicates that the storage unit corresponding to the first target identifier is a storage unit that is not allocated to a qubit.
[0357] Optionally, when the operation instruction is an operation instruction of a target operation, the first equivalent compilation unit is specifically used to:
[0358] Determining that a second operation instruction is included after the operation instruction in the second instruction list based on the attribute value of the operation instruction in the second information, determining that the type of the target operation is a fourth type, the classification information further includes the second information, the second information including: an attribute value for distinguishing each operation instruction of the target operation in the operation instructions of the first quantum circuit, the second operation instruction being an operation instruction in the second instruction list that has the same controlled condition as the operation instruction and is located after the operation instruction;
[0359] In a case where it is determined based on the attribute value of the operation instruction in the second information that the second operation instruction is not included in the second instruction list after the operation instruction, and it is determined based on the first information that a third operation instruction matching the controlled condition of the operation instruction is located in the middle of the first quantum circuit, determining that the type of the target operation is the fifth type;
[0360] When it is determined based on the attribute value of the operation instruction in the second information that the second operation instruction is not included in the second instruction list after the operation instruction, and when it is determined based on the first information that a third operation instruction matching the controlled condition of the operation instruction is located at the end of the first quantum circuit, the type of the target operation is determined to be the sixth type, and the third operation instruction is an operation instruction for a quantum measurement operation.
[0361] Optionally, the first equivalent compilation unit is further used to:
[0362] Based on the first target identifier, compiling the operation instruction into an operation instruction of a quantum control operation equivalent to the target operation in the second quantum circuit;
[0363] When the type of the target operation is the sixth type, based on the third qubit acted upon by the third operation instruction and the register unit dictionary, determining a second target identifier of a register unit of the second quantum circuit assigned to the third qubit;
[0364] Based on the second target identifier, generating an operation instruction for a reset operation in the second quantum circuit;
[0365] The register unit dictionary is updated, wherein the updated register unit dictionary indicates that the register unit corresponding to the second target identifier is a register unit that is not allocated to a qubit.
[0366] Optionally, the third determining submodule includes:
[0367] A first determining unit is configured to determine, when a corresponding relationship of the second qubit is found in the storage unit dictionary, an identifier of the storage unit corresponding to the second qubit as the first target identifier;
[0368] a second determining unit, configured to allocate a storage unit to the second qubit based on the storage unit dictionary, if it is found that the corresponding relationship of the second qubit is not included in the storage unit dictionary, determine the identifier of the storage unit allocated to the second qubit as the first target identifier, and update the storage unit dictionary based on the identifier of the storage unit allocated to the second qubit.
[0369] Optionally, the second determining unit is specifically configured to:
[0370] In the case that the registration unit dictionary contains an identifier of a first registration unit, assigning the first registration unit to the second qubit, the first registration unit being a registration unit that is not assigned to a node;
[0371] In the case that it is found that the registration unit dictionary does not include the identifier of the first registration unit, the number of registration units represented by the registration unit dictionary is obtained, the identifier of the created second registration unit is determined based on the number, and the second registration unit is allocated to the second qubit.
[0372] Optionally, the second obtaining module 1302 includes:
[0373] A third acquisition submodule is used to acquire the qubit involved in the operation instruction in the first instruction list, where, when the operation instruction is an operation instruction of a quantum gate operation controlled by classical information, the qubit involved in the operation instruction includes the qubit where the controlled condition of the operation instruction is located;
[0374] A numbering submodule, used to number the operation instructions based on the order in which each qubit involved in the operation instructions appears in the quantum operation of the first quantum circuit, so as to obtain numbering information of the operation instructions of the first quantum circuit;
[0375] A search submodule is used to search other operation instructions associated with the operation instruction in the first quantum circuit based on the number information of the operation instruction to obtain the dependency relationship, wherein the quantum bits involved in the other operation instructions include the quantum bits involved in the operation instruction, and the execution order of the other operation instructions is before the operation instruction.
[0376] Optionally, the second obtaining module 1302 further includes:
[0377] a fourth determination submodule, configured to determine the order in which each qubit involved in the operation instruction appears in the quantum operation of the first quantum circuit based on a second target list updated during the forward traversal of the first instruction list, wherein the second target list is used to record the order in which each qubit in the first quantum circuit appears during the forward traversal;
[0378] Among them, when the operation instruction of the forward-order traversal involves the fourth quantum bit, the order in which the fourth quantum bit in the second target list appears during the forward-order traversal is increased by 1, and the fourth quantum bit is any quantum bit in the first quantum circuit.
[0379] Optionally, the search submodule is specifically used for:
[0380] Based on the numbering information of the operation instruction, obtaining target numbering information, the qubit number in the target numbering information is the same as the qubit number in the numbering information of the operation instruction, and the order in which the qubits in the target numbering information appear in the quantum operation of the first quantum circuit is less than the order in which the qubits in the numbering information of the operation instruction appear in the quantum operation of the first quantum circuit;
[0381] The other operation instructions corresponding to the target number information are obtained to obtain the dependency relationship, where the other operation instructions are operation instructions that are executed before the operation instruction in the first quantum circuit and are adjacent to the operation instruction.
[0382] Optionally, the reordering module 1303 includes:
[0383] A first reordering submodule is used to perform a first reordering on the operation instructions of the first quantum circuit in the order of the qubit numbers involved in the operation instructions from small to large, to obtain a fourth instruction list of the first quantum circuit, in which the target qubit numbers in the operation instructions that are sorted first are smaller than the target qubit numbers in the operation instructions that are sorted later, and the operation instructions that act on the same qubit numbers are arranged in the relative order of the operation instructions in the first quantum circuit, and the target qubit is the qubit with the smaller number among the qubits involved in the operation instructions;
[0384] The second reordering submodule is used to perform a second reordering on the fourth instruction list based on the dependency relationship to obtain the second instruction list.
[0385] Optionally, the second reordering submodule includes:
[0386] a splitting unit, configured to traverse the fourth instruction list for operation instructions, and split the fourth instruction list for the currently traversed operation instruction to obtain a first list, a second list, and a third list, wherein the first list is a list consisting of the operation instruction ranked first in the fourth instruction list to the previous operation instruction adjacent to the currently traversed operation instruction, the second list is a list consisting of the currently traversed operation instructions, and the third list is a list consisting of the operation instructions ranked after the currently traversed operation instruction in the fourth instruction list;
[0387] a reordering unit, configured to reorder the operation instructions of the fourth instruction list based on the target dependency relationship between the currently traversed operation instruction in the dependency relationship and the operation instructions of the first quantum circuit, the first list, the second list, and the third list;
[0388] The third determining unit is configured to determine the second instruction list based on the rearranged fourth instruction list when the traversal of the fourth instruction list is completed.
[0389] Optionally, the rearrangement unit is specifically used for:
[0390] Based on the target dependency relationship and the first list, obtaining a third target list, the third target list indicating the operation instructions in the first list that have the target dependency relationship with the currently traversed operation instruction;
[0391] Based on the third target list and the fourth target list, determining a fifth target list, the fourth target list indicating the operation instructions in the fourth instruction list that have the target dependency relationship with the currently traversed operation instruction, and the fifth target list being a list obtained by deleting the third target list from the fourth target list;
[0392] When the fifth target list is not an empty set, deleting the operation instructions indicated by the fifth target list from the third list to obtain a fourth list;
[0393] The first list, the operation instructions indicated by the fifth target list, the second list and the fourth list are concatenated in order from front to back to obtain the rearranged fourth instruction list.
[0394] Optionally, the second reordering submodule further includes:
[0395] A moving unit, used for moving the operation instructions of the quantum measurement operation in the rearranged fourth instruction list to a target position to obtain the second instruction list;
[0396] Among them, the target position is a position located after the target operation instruction in the rearranged fourth instruction list and adjacent to the target operation instruction, the quantum bit acted upon by the target operation instruction includes the quantum bit acted upon by the operation instruction of the quantum measurement operation, and the operation instructions sorted after the target position in the second instruction list do not include the quantum bit acted upon by the operation instruction of the quantum measurement operation.
[0397] The quantum circuit processing device 1300 provided in the present disclosure can implement each process implemented in the quantum circuit processing method embodiment and can achieve the same beneficial effects. To avoid repetition, it will not be described here.
[0398] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0399] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0400] Fig.14 A schematic block diagram of an example electronic device that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0401] like Fig.14 As shown, the device 1400 includes a computing unit 1401, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 1402 or a computer program loaded from a storage unit 1408 into a random access memory (RAM) 1403. In the RAM 1403, various programs and data required for the operation of the device 1400 can also be stored. The computing unit 1401, the ROM 1402, and the RAM 1403 are connected to each other via a bus 1404. An input / output (I / O) interface 1405 is also connected to the bus 1404.
[0402] A number of components in the device 1400 are connected to the I / O interface 1405, including: an input unit 1406, such as a keyboard, a mouse, etc.; an output unit 1407, such as various types of displays, speakers, etc.; a storage unit 1408, such as a disk, an optical disk, etc.; and a communication unit 1409, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 1409 allows the device 1400 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0403] The computing unit 1401 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 1401 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 1401 performs the various methods and processes described above, such as the quantum circuit processing method. For example, in some embodiments, the quantum circuit processing method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 1408. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 1400 via the ROM 1402 and / or the communication unit 1409. When the computer program is loaded into the RAM 1403 and executed by the computing unit 1401, one or more steps of the quantum circuit processing method described above may be performed. Alternatively, in other embodiments, the computing unit 1401 may be configured to execute the quantum circuit processing method in any other appropriate manner (for example, by means of firmware).
[0404] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0405] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0406] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0407] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0408] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0409] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0410] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0411] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A quantum circuit processing method, comprising: Acquire a first instruction list, wherein the first instruction list includes operation instructions of a first quantum circuit, wherein the operation instructions are used to indicate quantum operations of the first quantum circuit, and the quantum operations include quantum measurement operations; Based on the first instruction list, obtaining a dependency relationship of an execution order of operation instructions of the first quantum circuit; Based on the dependency, reorder the operation instructions of the first quantum circuit in ascending order of the quantum bit numbers involved in the operation instructions to obtain a second instruction list of the first quantum circuit; Based on the second instruction list, determining classification information, the classification information comprising: first information for indicating the quantum measurement operation at the first quantum circuit position; In the case where the first information indicates that the quantum measurement operation is at the end position of the first quantum circuit, based on the classification information and the second instruction list, the first quantum circuit is equivalently compiled to obtain a third instruction list of a second quantum circuit equivalent to the first quantum circuit, the third instruction list comprising: an operation instruction of a reset operation, the operation instruction of the reset operation is located after the operation instruction of the quantum measurement operation, the reset operation is used to reset the quantum state of the quantum bit to a zero state, the number of quantum bits of the second quantum circuit is less than the number of quantum bits of the first quantum circuit, the end position indicates that the quantum measurement operation is the last quantum measurement operation in the quantum measurement operation along the time evolution direction of the quantum state; in the third instruction list, the operation instruction of the reset operation is not added after the quantum measurement operation at the middle position indicated by the first information; When performing equivalent compilation, the qubit acted upon by the operation instruction in the second instruction list is obtained, a register unit is allocated to the qubit, the register unit corresponds to the qubit in the second quantum circuit, and the register unit allocated to the qubit is recovered through the operation instruction of the reset operation.
2. The method according to claim 1, wherein: The determining classification information based on the second instruction list includes: Traversing the second instruction list in reverse order, and when a quantum measurement operation is found, obtaining a first quantum bit acted upon by the quantum measurement operation; Determine the position of the quantum measurement operation in the first quantum circuit based on the first quantum bit and a first target list updated during the reverse traversal to obtain the first information, wherein the first target list is used to record whether the quantum measurement operation of each quantum bit located at an end position of the first quantum circuit in the first quantum circuit has been traversed; Wherein, in case of a quantum measurement operation of a quantum bit located at an end position of the first quantum circuit in the first quantum circuit being traversed in reverse order, the first target list is updated.
3. The method according to claim 2, wherein: The step of determining the position of the quantum measurement operation in the first quantum circuit based on the first quantum bit and the first target list updated during the reverse traversal to obtain the first information includes: In a case where the first target list indicates that the quantum measurement operation of the first quantum bit located at the end position of the first quantum circuit has been traversed, determining that the quantum measurement operation is located at the middle position of the first quantum circuit, and obtaining the first information; When the first target list indicates that the quantum measurement operation of the first quantum bit located at the end position of the first quantum circuit has not been traversed, it is determined that the quantum measurement operation is located at the end position of the first quantum circuit to obtain the first information.
4. The method according to claim 1, wherein: The quantum operation further includes a target operation, which is a quantum gate operation controlled by classical information. The classification information further includes second information, which includes: an attribute value for distinguishing each operation instruction of the target operation in the second instruction list. The determining of the classification information based on the second instruction list includes: In the process of traversing the second instruction list based on the traversal control index, the attribute value of the operation instruction of the target operation is determined based on the index value of the traversal control index of the operation instruction of the target operation traversed; and when the traversal of the second instruction list is completed, the second information is obtained.
5. The method according to claim 4, wherein: When the second instruction list is traversed in reverse order, the attribute value of the operation instruction of the target operation is determined to be length-1-i, where i is the index value of the traversal control index of the traversed operation instruction of the target operation, and length is the length of the second instruction list.
6. The method according to claim 1, wherein: The first quantum circuit is equivalently compiled based on the classification information and the second instruction list to obtain a third instruction list of a second quantum circuit equivalent to the first quantum circuit, including: For each operation instruction in the second instruction list, perform the following operations: Obtaining a second quantum bit acted upon by the operation instruction; Determining a first target identifier of a register unit of a second quantum circuit assigned to the second qubit based on the second qubit and a register unit dictionary, wherein the register unit dictionary includes a correspondence between register units and qubits; Based on the first target identifier and the classification information, the operation instruction is equivalently compiled to obtain an operation instruction in a second quantum circuit equivalent to the operation instruction, and the third instruction list includes the operation instruction in the second quantum circuit obtained by the equivalent compilation.
7. The method according to claim 6, wherein: The equivalent compilation of the operation instruction based on the first target identifier and the classification information to obtain the operation instruction in the second quantum circuit equivalent to the operation instruction includes: In a case where the operation instruction is an operation instruction for a quantum measurement operation or an operation instruction for a target operation, determining a type of quantum operation corresponding to the operation instruction based on the classification information, and the target operation is a quantum gate operation controlled by classical information; based on the type of quantum operation corresponding to the operation instruction and the first target identifier, performing equivalent compilation on the operation instruction to obtain an operation instruction in a second quantum circuit equivalent to the operation instruction; When the operation instruction is an operation instruction for a reset operation, based on the first target identifier, the operation instruction is equivalently compiled into an operation instruction for a reset operation in the second quantum circuit; When the operation instruction is an operation instruction of a single quantum bit gate, based on the first target identifier, the operation instruction is equivalently compiled into an operation instruction of the single quantum bit gate in the second quantum circuit; When the number of the second quantum bits is greater than 1, the operation instruction is equivalently compiled into an operation instruction of a quantum gate operation corresponding to the operation instruction in the second quantum circuit based on the first target identifier.
8. The method according to claim 7, wherein: In a case where the operation instruction is an operation instruction for a quantum measurement operation, determining the type of quantum operation corresponding to the operation instruction based on the classification information includes: When the classification information indicates that the quantum measurement operation is at an end position of the first quantum circuit, and the operation instructions after the quantum measurement operation in the second instruction list include a first operation instruction, determining that the type of the quantum measurement operation is a first type, and the first operation instruction is an operation instruction of a quantum gate operation controlled by classical information obtained by running the operation instruction; When the classification information indicates that the quantum measurement operation is at an end position of the first quantum circuit, and the operation instructions after the quantum measurement operation in the second instruction list do not include the first operation instruction, determining that the type of the quantum measurement operation is the second type; When the classification information indicates that the quantum measurement operation is in the middle of the first quantum circuit, the type of the quantum measurement operation is determined to be a third type.
9. The method according to claim 8, wherein: The equivalent compilation of the operation instruction based on the type of quantum operation corresponding to the operation instruction and the first target identifier to obtain an operation instruction in a second quantum circuit equivalent to the operation instruction includes: Based on the first target identifier, compiling the operation instruction into an operation instruction of a quantum measurement operation in the second quantum circuit; When the type of the quantum measurement operation is the second type, generating an operation instruction for a reset operation in the second quantum circuit based on the first target identifier; The storage unit dictionary is updated, and the updated storage unit dictionary indicates that the storage unit corresponding to the first target identifier is a storage unit that is not allocated to a qubit.
10. The method according to claim 7, wherein: In a case where the operation instruction is an operation instruction of a target operation, determining the type of quantum operation corresponding to the operation instruction based on the classification information includes: Determining that a second operation instruction is included after the operation instruction in the second instruction list based on the attribute value of the operation instruction in the second information, determining that the type of the target operation is a fourth type, the classification information further includes the second information, the second information including: an attribute value for distinguishing each operation instruction of the target operation in the operation instructions of the first quantum circuit, the second operation instruction being an operation instruction in the second instruction list that has the same controlled condition as the operation instruction and is located after the operation instruction; In a case where it is determined based on the attribute value of the operation instruction in the second information that the second operation instruction is not included in the second instruction list after the operation instruction, and it is determined based on the first information that a third operation instruction matching the controlled condition of the operation instruction is located in the middle of the first quantum circuit, determining that the type of the target operation is the fifth type; When it is determined based on the attribute value of the operation instruction in the second information that the second operation instruction is not included in the second instruction list after the operation instruction, and when it is determined based on the first information that a third operation instruction matching the controlled condition of the operation instruction is located at the end of the first quantum circuit, the type of the target operation is determined to be the sixth type, and the third operation instruction is an operation instruction for a quantum measurement operation.
11. The method according to claim 10, wherein: The equivalent compilation of the operation instruction based on the type of quantum operation corresponding to the operation instruction and the first target identifier to obtain an operation instruction in a second quantum circuit equivalent to the operation instruction includes: Based on the first target identifier, compiling the operation instruction into an operation instruction of a quantum control operation equivalent to the target operation in the second quantum circuit; When the type of the target operation is the sixth type, based on the third qubit acted upon by the third operation instruction and the register unit dictionary, determining a second target identifier of a register unit of the second quantum circuit assigned to the third qubit; Based on the second target identifier, generating an operation instruction for a reset operation in the second quantum circuit; The register unit dictionary is updated, wherein the updated register unit dictionary indicates that the register unit corresponding to the second target identifier is a register unit that is not allocated to a qubit.
12. The method according to claim 6, wherein: The determining, based on the second qubit and the register unit dictionary, a first target identifier of a register unit of a second quantum circuit assigned to the second qubit comprises: In the case where the corresponding relationship of the second qubit is found in the storage unit dictionary, the identifier of the storage unit corresponding to the second qubit is determined as the first target identifier; In the case where it is found that the corresponding relationship of the second quantum bit is not included in the storage unit dictionary, a storage unit is allocated to the second quantum bit based on the storage unit dictionary, the identifier of the storage unit allocated to the second quantum bit is determined as the first target identifier, and the storage unit dictionary is updated based on the identifier of the storage unit allocated to the second quantum bit.
13. The method according to claim 12, wherein: In the case that the corresponding relationship of the second qubit is not included in the query of the storage unit dictionary, the allocating a storage unit for the second qubit based on the storage unit dictionary includes at least one of the following: In the case that the registration unit dictionary contains an identifier of a first registration unit, assigning the first registration unit to the second qubit, the first registration unit being a registration unit that is not assigned to a qubit; In the case that it is found that the registration unit dictionary does not include the identifier of the first registration unit, the number of registration units represented by the registration unit dictionary is obtained, the identifier of the created second registration unit is determined based on the number, and the second registration unit is allocated to the second qubit.
14. The method according to claim 1, wherein: The step of obtaining the dependency of the execution order of the operation instructions of the first quantum circuit based on the first instruction list includes: Obtaining the qubits involved in the operation instruction in the first instruction list, where, when the operation instruction is an operation instruction for a quantum gate operation controlled by classical information, the qubits involved in the operation instruction include the qubits where the controlled conditions acted upon by the operation instruction are located; Numbering the operation instructions based on the order in which each qubit involved in the operation instructions appears in the quantum operation of the first quantum circuit to obtain numbering information of the operation instructions of the first quantum circuit; Based on the number information of the operation instruction, other operation instructions associated with the operation instruction in the first quantum circuit are searched to obtain the dependency relationship, where the quantum bits involved in the other operation instructions include the quantum bits involved in the operation instruction, and the execution order of the other operation instructions is before the operation instruction.
15. The method according to claim 14, before numbering the operation instructions based on the order in which each qubit involved in the operation instructions appears in the quantum operation of the first quantum circuit, and obtaining the numbering information of the operation instructions of the first quantum circuit, further comprises: Determine, based on a second target list updated during the forward traversal of the first instruction list, the order in which each qubit involved in the operation instruction appears in the quantum operation of the first quantum circuit, wherein the second target list is used to record the order in which each qubit in the first quantum circuit appears during the forward traversal; Among them, when the operation instruction of the forward-order traversal involves the fourth quantum bit, the order in which the fourth quantum bit in the second target list appears during the forward-order traversal is increased by 1, and the fourth quantum bit is any quantum bit in the first quantum circuit.
16. The method according to claim 14, wherein: The step of searching, based on the serial number information of the operation instruction, other operation instructions associated with the operation instruction in the first quantum circuit to obtain the dependency relationship includes: Based on the numbering information of the operation instruction, obtaining target numbering information, the qubit number in the target numbering information is the same as the qubit number in the numbering information of the operation instruction, and the order in which the qubits in the target numbering information appear in the quantum operation of the first quantum circuit is less than the order in which the qubits in the numbering information of the operation instruction appear in the quantum operation of the first quantum circuit; The other operation instructions corresponding to the target number information are obtained to obtain the dependency relationship, where the other operation instructions are operation instructions that are executed before the operation instruction in the first quantum circuit and are adjacent to the operation instruction.
17. The method according to claim 1, wherein: The step of reordering the operation instructions of the first quantum circuit in ascending order of the quantum bit numbers involved in the operation instructions based on the dependency relationship to obtain a second instruction list of the first quantum circuit includes: The operation instructions of the first quantum circuit are first reordered in the ascending order of the qubit numbers involved in the operation instructions to obtain a fourth instruction list of the first quantum circuit, in which the target qubit numbers in the operation instructions arranged earlier are smaller than the target qubit numbers in the operation instructions arranged later, and the operation instructions acting on the same qubit numbers are arranged in the relative order of the operation instructions in the first quantum circuit, and the target qubit is the qubit with the smaller number among the qubits involved in the operation instructions; Based on the dependency relationship, the fourth instruction list is reordered in a second manner to obtain the second instruction list.
18. The method according to claim 17, wherein: The step of performing a second reordering on the fourth instruction list based on the dependency relationship to obtain the second instruction list includes: The fourth instruction list is traversed for operation instructions, and the fourth instruction list is split for the currently traversed operation instruction to obtain a first list, a second list, and a third list, wherein the first list is a list consisting of the operation instruction ranked first in the fourth instruction list to the previous operation instruction adjacent to the currently traversed operation instruction, the second list is a list consisting of the currently traversed operation instructions, and the third list is a list consisting of the operation instructions ranked after the currently traversed operation instruction in the fourth instruction list; Rearranging the operation instructions of the fourth instruction list based on the target dependency relationship between the currently traversed operation instruction in the dependency relationship and the operation instructions of the first quantum circuit, the first list, the second list, and the third list; When the traversal of the fourth instruction list is completed, the second instruction list is determined based on the rearranged fourth instruction list.
19. The method according to claim 18, wherein: The reordering of the operation instructions of the fourth instruction list based on the target dependency relationship between the currently traversed operation instruction in the dependency relationship and the operation instruction of the first quantum circuit, the first list, the second list, and the third list comprises: Based on the target dependency relationship and the first list, obtaining a third target list, the third target list indicating the operation instructions in the first list that have the target dependency relationship with the currently traversed operation instruction; Based on the third target list and the fourth target list, determining a fifth target list, the fourth target list indicating the operation instructions in the fourth instruction list that have the target dependency relationship with the currently traversed operation instruction, and the fifth target list being a list obtained by deleting the third target list from the fourth target list; When the fifth target list is not an empty set, deleting the operation instructions indicated by the fifth target list from the third list to obtain a fourth list; The first list, the operation instructions indicated by the fifth target list, the second list and the fourth list are concatenated in order from front to back to obtain the rearranged fourth instruction list.
20. The method according to claim 17, wherein: After performing a second reordering on the fourth instruction list based on the dependency relationship, the method further includes: Move the operation instructions of the quantum measurement operation in the rearranged fourth instruction list to the target position to obtain the second instruction list; Among them, the target position is a position located after the target operation instruction in the rearranged fourth instruction list and adjacent to the target operation instruction, the quantum bit acted upon by the target operation instruction includes the quantum bit acted upon by the operation instruction of the quantum measurement operation, and the operation instructions sorted after the target position in the second instruction list do not include the quantum bit acted upon by the operation instruction of the quantum measurement operation.
21. A quantum circuit processing device, comprising: A first acquisition module is used to acquire a first instruction list, where the first instruction list includes operation instructions of a first quantum circuit, where the operation instructions are used to indicate quantum operations of the first quantum circuit, where the quantum operations include quantum measurement operations; A second acquisition module, configured to acquire a dependency relationship of an execution order of operation instructions of the first quantum circuit based on the first instruction list; a reordering module, configured to reorder the operation instructions of the first quantum circuit in ascending order of the quantum bit numbers involved in the operation instructions based on the dependency relationship, to obtain a second instruction list of the first quantum circuit; A determination module, configured to determine classification information based on the second instruction list, the classification information comprising: first information for indicating the quantum measurement operation at the first quantum circuit position; An equivalent compilation module is used for, when the first information indicates that the quantum measurement operation is at the end position of the first quantum circuit, performing equivalent compilation on the first quantum circuit based on the classification information and the second instruction list, and obtaining a third instruction list of a second quantum circuit equivalent to the first quantum circuit, wherein the third instruction list includes: an operation instruction for a reset operation, the operation instruction for the reset operation is located after the operation instruction for the quantum measurement operation, the reset operation is used to reset the quantum state of the quantum bit to a zero state, the number of quantum bits in the second quantum circuit is less than the number of quantum bits in the first quantum circuit, and the end position indicates that the quantum measurement operation is the last quantum measurement operation in the quantum measurement operation along the time evolution direction of the quantum state; in the third instruction list, the operation instruction for the reset operation is not added after the quantum measurement operation at the middle position indicated by the first information; when performing equivalent compilation, obtaining the quantum bit acted upon by the operation instruction in the second instruction list, allocating a register unit to the quantum bit, the register unit corresponding to the quantum bit in the second quantum circuit, and recovering the register unit allocated to the quantum bit through the operation instruction for the reset operation.
22. The device according to claim 21, wherein The determination module comprises: A first acquisition submodule is used to traverse the second instruction list in reverse order, and when a quantum measurement operation is traversed, obtain a first qubit acted upon by the quantum measurement operation; A first determination submodule is configured to determine the position of the quantum measurement operation in the first quantum circuit based on the first quantum bit and a first target list updated during the reverse traversal process to obtain the first information, wherein the first target list is used to record whether the quantum measurement operation of each quantum bit located at an end position of the first quantum circuit in the first quantum circuit has been traversed; Wherein, in case of a quantum measurement operation of a quantum bit located at an end position of the first quantum circuit in the first quantum circuit being traversed in reverse order, the first target list is updated.
23. The device according to claim 22, wherein: The first determining submodule is specifically used for: In a case where the first target list indicates that the quantum measurement operation of the first quantum bit located at the end position of the first quantum circuit has been traversed, determining that the quantum measurement operation is located at the middle position of the first quantum circuit, and obtaining the first information; When the first target list indicates that the quantum measurement operation of the first quantum bit located at the end position of the first quantum circuit has not been traversed, it is determined that the quantum measurement operation is located at the end position of the first quantum circuit to obtain the first information.
24. The device according to claim 21, wherein The quantum operation further includes a target operation, which is a quantum gate operation controlled by classical information. The classification information further includes second information, which includes: an attribute value for distinguishing each operation instruction of the target operation in the second instruction list. The determination module includes: The second determination submodule is used to determine the attribute value of the operation instruction of the target operation based on the index value of the traversal control index of the operation instruction of the target operation traversed during the process of traversing the second instruction list based on the traversal control index; and obtain the second information when the traversal of the second instruction list is completed.
25. The device according to claim 24, wherein: When the second instruction list is traversed in reverse order, the attribute value of the operation instruction of the target operation is determined to be length-1-i, where i is the index value of the traversal control index of the traversed operation instruction of the target operation, and length is the length of the second instruction list.
26. The device according to claim 21, wherein The equivalent compilation module includes: A second acquisition submodule, configured to acquire, for each operation instruction in the second instruction list, a second qubit acted upon by the operation instruction; a third determination submodule, configured to determine a first target identifier of a register unit of a second quantum circuit allocated to the second qubit based on the second qubit and a register unit dictionary, wherein the register unit dictionary includes a correspondence between register units and qubits; an equivalent compilation submodule, configured to perform equivalent compilation on the operation instruction based on the first target identifier and the classification information to obtain an operation instruction in a second quantum circuit equivalent to the operation instruction, wherein the third instruction list includes the operation instruction in the second quantum circuit obtained by equivalent compilation.
27. The device according to claim 26, wherein: The equivalent compilation submodule includes: A first equivalent compilation unit is used to determine, when the operation instruction is an operation instruction of a quantum measurement operation or an operation instruction of a target operation, based on the classification information, the type of quantum operation corresponding to the operation instruction, and the target operation is a quantum gate operation controlled by classical information; based on the type of quantum operation corresponding to the operation instruction and the first target identifier, perform equivalent compilation on the operation instruction to obtain an operation instruction in a second quantum circuit equivalent to the operation instruction; A second equivalent compiling unit is configured to, when the operation instruction is an operation instruction of a reset operation, equivalently compile the operation instruction into an operation instruction of a reset operation in the second quantum circuit based on the first target identifier; a third equivalent compilation unit, configured to, when the operation instruction is an operation instruction of a single quantum bit gate, equivalently compile the operation instruction into an operation instruction of the single quantum bit gate in the second quantum circuit based on the first target identifier; and a fourth equivalent compilation unit, configured to, when the number of the second quantum bits is greater than 1, equivalently compile the operation instruction into an operation instruction of a quantum gate operation corresponding to the operation instruction in the second quantum circuit based on the first target identifier.
28. The device according to claim 27, wherein In the case where the operation instruction is an operation instruction of a quantum measurement operation, the first equivalent compilation unit is specifically configured to: When the classification information indicates that the quantum measurement operation is at an end position of the first quantum circuit, and the operation instructions after the quantum measurement operation in the second instruction list include a first operation instruction, determining that the type of the quantum measurement operation is a first type, and the first operation instruction is an operation instruction of a quantum gate operation controlled by classical information obtained by running the operation instruction; When the classification information indicates that the quantum measurement operation is at an end position of the first quantum circuit, and the operation instructions after the quantum measurement operation in the second instruction list do not include the first operation instruction, determining that the type of the quantum measurement operation is the second type; When the classification information indicates that the quantum measurement operation is in the middle of the first quantum circuit, the type of the quantum measurement operation is determined to be a third type.
29. The device according to claim 28, wherein The first equivalent compilation unit is further used for: Based on the first target identifier, compiling the operation instruction into an operation instruction of a quantum measurement operation in the second quantum circuit; When the type of the quantum measurement operation is the second type, generating an operation instruction for a reset operation in the second quantum circuit based on the first target identifier; The storage unit dictionary is updated, and the updated storage unit dictionary indicates that the storage unit corresponding to the first target identifier is a storage unit that is not allocated to a qubit.
30. The device according to claim 27, wherein: In the case where the operation instruction is an operation instruction of a target operation, the first equivalent compilation unit is specifically used to: Determining that a second operation instruction is included after the operation instruction in the second instruction list based on the attribute value of the operation instruction in the second information, determining that the type of the target operation is a fourth type, the classification information further includes the second information, the second information including: an attribute value for distinguishing each operation instruction of the target operation in the operation instructions of the first quantum circuit, the second operation instruction being an operation instruction in the second instruction list that has the same controlled condition as the operation instruction and is located after the operation instruction; In a case where it is determined based on the attribute value of the operation instruction in the second information that the second operation instruction is not included in the second instruction list after the operation instruction, and it is determined based on the first information that a third operation instruction matching the controlled condition of the operation instruction is located in the middle of the first quantum circuit, determining that the type of the target operation is the fifth type; When it is determined based on the attribute value of the operation instruction in the second information that the second operation instruction is not included in the second instruction list after the operation instruction, and when it is determined based on the first information that a third operation instruction matching the controlled condition of the operation instruction is located at the end of the first quantum circuit, the type of the target operation is determined to be the sixth type, and the third operation instruction is an operation instruction for a quantum measurement operation.
31. The device according to claim 30, wherein The first equivalent compilation unit is further used for: Based on the first target identifier, compiling the operation instruction into an operation instruction of a quantum control operation equivalent to the target operation in the second quantum circuit; When the type of the target operation is the sixth type, based on the third qubit acted upon by the third operation instruction and the register unit dictionary, determining a second target identifier of a register unit of the second quantum circuit assigned to the third qubit; Based on the second target identifier, generating an operation instruction for a reset operation in the second quantum circuit; The register unit dictionary is updated, wherein the updated register unit dictionary indicates that the register unit corresponding to the second target identifier is a register unit that is not allocated to a qubit.
32. The apparatus of claim 26, wherein: The third determining submodule comprises: A first determining unit is configured to determine, when a corresponding relationship of the second qubit is found in the storage unit dictionary, an identifier of the storage unit corresponding to the second qubit as the first target identifier; a second determining unit, configured to allocate a storage unit to the second qubit based on the storage unit dictionary, if it is found that the corresponding relationship of the second qubit is not included in the storage unit dictionary, determine the identifier of the storage unit allocated to the second qubit as the first target identifier, and update the storage unit dictionary based on the identifier of the storage unit allocated to the second qubit.
33. The device according to claim 32, wherein: The second determining unit is specifically configured to: In the case that the registration unit dictionary contains an identifier of a first registration unit, assigning the first registration unit to the second qubit, the first registration unit being a registration unit that is not assigned to a qubit; In the case that it is found that the registration unit dictionary does not include the identifier of the first registration unit, the number of registration units represented by the registration unit dictionary is obtained, the identifier of the created second registration unit is determined based on the number, and the second registration unit is allocated to the second qubit.
34. The apparatus of claim 21, wherein: The second acquisition module includes: A third acquisition submodule is used to acquire the qubit involved in the operation instruction in the first instruction list, where, when the operation instruction is an operation instruction of a quantum gate operation controlled by classical information, the qubit involved in the operation instruction includes the qubit where the controlled condition of the operation instruction is located; A numbering submodule, used to number the operation instructions based on the order in which each qubit involved in the operation instructions appears in the quantum operation of the first quantum circuit, so as to obtain numbering information of the operation instructions of the first quantum circuit; A search submodule is used to search other operation instructions associated with the operation instruction in the first quantum circuit based on the number information of the operation instruction to obtain the dependency relationship, wherein the quantum bits involved in the other operation instructions include the quantum bits involved in the operation instruction, and the execution order of the other operation instructions is before the operation instruction.
35. The device according to claim 34, wherein The second acquisition module also includes: a fourth determination submodule, configured to determine the order in which each qubit involved in the operation instruction appears in the quantum operation of the first quantum circuit based on a second target list updated during the forward traversal of the first instruction list, wherein the second target list is used to record the order in which each qubit in the first quantum circuit appears during the forward traversal; Among them, when the operation instruction of the forward-order traversal involves the fourth quantum bit, the order in which the fourth quantum bit in the second target list appears during the forward-order traversal is increased by 1, and the fourth quantum bit is any quantum bit in the first quantum circuit.
36. The device according to claim 34, wherein The search submodule is specifically used for: Based on the numbering information of the operation instruction, obtaining target numbering information, the qubit number in the target numbering information is the same as the qubit number in the numbering information of the operation instruction, and the order in which the qubits in the target numbering information appear in the quantum operation of the first quantum circuit is less than the order in which the qubits in the numbering information of the operation instruction appear in the quantum operation of the first quantum circuit; The other operation instructions corresponding to the target number information are obtained to obtain the dependency relationship, where the other operation instructions are operation instructions that are executed before the operation instruction in the first quantum circuit and are adjacent to the operation instruction.
37. The apparatus of claim 21, wherein: The reordering module comprises: A first reordering submodule is used to perform a first reordering on the operation instructions of the first quantum circuit in the order of the qubit numbers involved in the operation instructions from small to large, to obtain a fourth instruction list of the first quantum circuit, in which the target qubit numbers in the operation instructions that are sorted first are smaller than the target qubit numbers in the operation instructions that are sorted later, and the operation instructions that act on the same qubit numbers are arranged in the relative order of the operation instructions in the first quantum circuit, and the target qubit is the qubit with the smaller number among the qubits involved in the operation instructions; The second reordering submodule is used to perform a second reordering on the fourth instruction list based on the dependency relationship to obtain the second instruction list.
38. The device according to claim 37, wherein The second reordering submodule comprises: a splitting unit, configured to traverse the fourth instruction list for operation instructions, and split the fourth instruction list for the currently traversed operation instruction to obtain a first list, a second list, and a third list, wherein the first list is a list consisting of the operation instruction ranked first in the fourth instruction list to the previous operation instruction adjacent to the currently traversed operation instruction, the second list is a list consisting of the currently traversed operation instructions, and the third list is a list consisting of the operation instructions ranked after the currently traversed operation instruction in the fourth instruction list; a reordering unit, configured to reorder the operation instructions of the fourth instruction list based on the target dependency relationship between the currently traversed operation instruction in the dependency relationship and the operation instructions of the first quantum circuit, the first list, the second list, and the third list; The third determining unit is configured to determine the second instruction list based on the rearranged fourth instruction list when the traversal of the fourth instruction list is completed.
39. The device according to claim 38, wherein The rearrangement unit is specifically used for: Based on the target dependency relationship and the first list, obtaining a third target list, the third target list indicating the operation instructions in the first list that have the target dependency relationship with the currently traversed operation instruction; Based on the third target list and the fourth target list, determining a fifth target list, the fourth target list indicating the operation instructions in the fourth instruction list that have the target dependency relationship with the currently traversed operation instruction, and the fifth target list being a list obtained by deleting the third target list from the fourth target list; When the fifth target list is not an empty set, deleting the operation instructions indicated by the fifth target list from the third list to obtain a fourth list; The first list, the operation instructions indicated by the fifth target list, the second list and the fourth list are concatenated in order from front to back to obtain the rearranged fourth instruction list.
40. The apparatus of claim 37, wherein: The second reordering submodule also includes: A moving unit, used for moving the operation instructions of the quantum measurement operation in the rearranged fourth instruction list to a target position to obtain the second instruction list; Among them, the target position is a position located after the target operation instruction in the rearranged fourth instruction list and adjacent to the target operation instruction, the quantum bit acted upon by the target operation instruction includes the quantum bit acted upon by the operation instruction of the quantum measurement operation, and the operation instructions sorted after the target position in the second instruction list do not include the quantum bit acted upon by the operation instruction of the quantum measurement operation.
41. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 20.
42. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-20.
43. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1 to 20.
