A quantum circuit pattern matching method based on pattern tree
By introducing pattern trees, transformation and organizational transformation rules into the quantum line pattern matching algorithm, the problems of redundant matching and execution time extension in the existing algorithm are solved, and more efficient quantum line pattern matching is achieved.
Patent Information
- Application Number
- CN202410738232.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-07
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2044-06-07
AI Technical Summary
The existing quantum line pattern matching algorithm has a redundant matching process when processing transformation rules, resulting in an increase in execution time and the inability to effectively share matching information.
The quantum line pattern matching method based on the pattern tree is adopted to reduce the redundant matching process by converting the transformation rules in the transformation rule library into composite transformation rules, and selecting the transformation rules to be processed on the pattern tree.
The execution time of the pattern matching algorithm is optimized, the efficiency of pattern matching of quantum lines is improved, and unnecessary matching processes are reduced.
Smart Images

Figure CN118690864B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of quantum information technology, and in particular to a quantum circuit pattern matching method based on a pattern tree. Background Art
[0002] Quantum computing is a new computing model that follows the laws of quantum mechanics to control quantum devices for computing. Compared with classical computing, quantum computing presents different possibilities. For example, the Shor algorithm in quantum algorithms has an exponential acceleration compared to the classical large number decomposition algorithm, and the Grover algorithm provides a quadratic acceleration for the classical unstructured database search algorithm.
[0003] In the past decade, quantum computing has developed rapidly, and emerging application areas include quantum chemistry, telecommunications, machine learning, and finance. We are currently in the era of noisy intermediate-scale quantum (NISQ), which means that the quantum system being operated has 1) hundreds of quantum bits, 2) limited quantum bit connections, and 3) a high error rate in quantum bit execution. When executing large-scale quantum circuits, the characteristics of NISQ devices cause the accuracy of the execution results of quantum circuits to decrease as the execution time increases. In order to solve this problem, many works have begun to consider applying optimization techniques to quantum programs.
[0004] In traditional computer science, pattern matching is the act of checking whether there is a subsequence in a given sequence that matches a specific pattern. Its uses include outputting the position of a pattern in a given sequence and replacing it with some other sequence. Pattern matching and transformation is also a potential method for quantum program optimization. Before real quantum devices are put into use, this part of research work usually focuses on logic circuit synthesis. After quantum devices were developed and the concept of native quantum gates of quantum devices was proposed, new work began to focus on the following two points: 1) Proposing transformation rules based on device native quantum gates; 2) Implementing more efficient quantum circuit matching algorithms.
[0005] However, because the pattern matching problem on quantum circuits is an NP-complete problem, there is no algorithm with polynomial complexity. The execution time of the pattern matching algorithm will increase rapidly with the increase of the scale of quantum circuits and the increase of transformation rules. In this regard, it is noted that the existing pattern matching algorithms have redundant matching processes in the process of processing transformation rules, and this redundancy reduces the execution efficiency of the pattern matching algorithm.
[0006] In the existing pattern matching algorithm, the algorithm needs to process each transformation rule one by one, and its processing flow includes two parts: finding the subcircuit in the quantum circuit that matches the source quantum circuit pattern, and instantiating the target circuit pattern with the matching context and then placing it in the original position of the matching subcircuit. This way of processing each transformation rule one by one means that the processing of the transformation rules is independent of each other, so the matched information cannot be shared, resulting in unnecessary matching processes, which further increases the execution time of the pattern matching algorithm. Summary of the invention
[0007] Based on the technical problems existing in the background technology, the present invention proposes a quantum circuit pattern matching method based on a pattern tree, which reduces the redundant matching process in the matching process and optimizes the execution time of pattern matching.
[0008] The quantum circuit pattern matching method based on pattern tree proposed in the present invention comprises the following steps:
[0009] Step 1: Define quantum circuit patterns, transformation rules, and pattern trees;
[0010] Step 2: Convert the transformation rules in the quantum circuit transformation rule library into multiple composite transformation rules based on the pattern tree. The quantum circuit pattern matching algorithm first selects the transformation rules to be processed on the pattern tree based on the composite transformation rules, searches for subcircuits that match the source quantum circuit pattern in the transformation rule in the input quantum circuit, and replaces the subcircuits with the subcircuits instantiated according to the matching information of the target quantum circuit pattern in the transformation rule. This process continues until the transformation rule can no longer be used, thereby realizing quantum circuit transformation.
[0011] Furthermore, in the step 1 of defining a quantum circuit mode, a quantum circuit mode represents a class of quantum circuits specified by the following parameters:
[0012] Quantum gate list G = g1g2…g n , where n is the total number of quantum gates, g n represents the nth quantum gate;
[0013] Abstract qubit list Q v = {q v1 q v2 …q vm}, where q vi ,i=1,2,…,m represents an abstract quantum bit, which can be instantiated to distinguish it from the quantum bits in the quantum circuit;
[0014] Parameter variable vector Contains all angle variables in the quantum gate list.
[0015] Furthermore, in step one:
[0016] Define transformation rule R: A transformation rule R = (C TS ,C TT ) is represented by a source quantum circuit pattern C describing the replaced subcircuit TS and a target quantum circuit pattern C describing the replaced subcircuit TT composition;
[0017] Define the order relationship between quantum circuit modes: For two quantum circuit modes C TA and C TB , if the quantum circuit mode C TA The sequence representation corresponds to the quantum circuit mode C TB The prefix of the sequence representation is called quantum circuit pattern C TA is the quantum circuit mode C TB prefix;
[0018] Define a pattern tree T = (V, E), where V represents a node set, E represents a set of connecting edges between nodes in the node set, each node v∈V represents a quantum circuit pattern, and each edge e = (u, v, g) represents that the quantum circuit pattern corresponding to the node v is obtained by adding a quantum gate g to the end of the gate list of the quantum circuit pattern corresponding to the node u. The pattern tree is an abstract data structure for describing multiple quantum circuit patterns.
[0019] Furthermore, in the pattern tree T, there are three types of nodes: b1) root node: corresponding to the empty quantum circuit pattern; b2) valid node: the quantum circuit pattern corresponding to the valid node can be optimized, and each transformation rule is placed in the node corresponding to the respective source quantum circuit pattern, and the pattern tree T is used to represent multiple transformation rules; b3) invalid node: the source circuit mode corresponding to the invalid node cannot be optimized, and there is no transformation rule with it as the source quantum circuit pattern.
[0020] Furthermore, in step 2, the mode matching algorithm of the quantum circuit uses a transformation rule base of the quantum circuit when performing mode transformation, and the transformation rule base is obtained by combining various transformation rules.
[0021] In step 2, the pattern tree-based quantum circuit pattern matching algorithm first connects one or more transformation rules in the transformation rule library based on the pattern tree definition to form a composite transformation rule, and uses the composite transformation rule to simultaneously process one or more transformation rules. Based on the composite transformation rule, a path is explored downward from the root node of the pattern tree. If the quantum circuit pattern corresponding to the current node can be successfully matched, it continues to move deeper; if it fails, it falls back and reuses the matching information of the previous node, thereby realizing the pattern matching of the quantum circuit.
[0022] The advantage of the pattern tree-based quantum circuit pattern matching method provided by the present invention is that a group of transformation rules are organized into a pattern tree in a manner of sharing a common prefix according to their source quantum circuit patterns, and a quantum circuit pattern matching algorithm is designed based on the pattern tree representation. The pattern matching algorithm can efficiently search for a sub-quantum circuit set in a given quantum circuit that matches one or some quantum circuit patterns in the pattern tree, while maintaining the optimization effect of pattern matching on the quantum circuit. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 It is a schematic diagram of the process of the present invention;
[0024] Figure 2 is a schematic diagram of an example of a quantum circuit mode;
[0025] Figure 3 For the general Figure 2 Schematic diagram of quantum circuit instantiation of quantum circuit pattern shown;
[0026] Figure 4 is the transformation rule R A and R B Schematic diagram of
[0027] Figure 5 is the transformation rule R C and R D Schematic diagram of
[0028] Figure 6 Based on Figure 4 and Figure 5 The pattern tree constructed by the transformation rules shown. DETAILED DESCRIPTION
[0029] Below, the technical solution of the present invention is described in detail through specific embodiments. Many specific details are set forth in the following description to facilitate a full understanding of the present invention. However, the present invention can be implemented in many other ways different from those described herein, and those skilled in the art can make similar improvements without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific implementation disclosed below.
[0030] like Figures 1 to 6 As shown, the quantum circuit pattern matching method based on pattern tree proposed in the present invention comprises the following steps:
[0031] Step 1: Define quantum circuit patterns, transformation rules, and pattern trees;
[0032] (1) Define the pattern tree T = (V, E). To define the pattern tree, we first need to define the quantum circuit pattern and transformation rules. The so-called pattern tree is an abstract data structure that describes multiple quantum circuit patterns. Each node v∈V on the tree represents a quantum circuit pattern. Each edge e=(u,v,g)∈E represents that the quantum circuit pattern corresponding to node v is obtained by adding a quantum gate g to the end of the gate list of the quantum circuit pattern corresponding to node u.
[0033] (2) Defining quantum circuit patterns
[0034] One line mode represents a class of quantum circuits specified by the following parameters:
[0035] A gate list G = g1g2…g consisting of quantum gates n , where n is the total number of quantum gates, g n
[0036] represents the nth quantum gate;
[0037] An abstract list of qubits Q v = {q v1 q v2 …q vm}, where q vi (i=1,2,…,m) represents an abstract qubit, which can be instantiated to distinguish it from the qubit in the quantum circuit;
[0038] A vector of parameter variables Contains all angle variables in the quantum gate list;
[0039] Since the quantum bits in the quantum circuit pattern are abstract, they cannot be directly replaced with matching subcircuits in the quantum circuit. Instead, the quantum circuit pattern needs to be instantiated first (e.g. Figure 3 for Figure 2 Schematic diagram of the quantum circuit instantiated by the quantum circuit pattern in the figure), that is, replacing the abstract quantum bits with the specific quantum bits in the quantum circuit and assigning values to the angle variables.
[0040] (3) Define transformation rule R: A transformation rule R = (C TS ,C TT ) is represented by a source quantum circuit pattern C describing the replaced subcircuit TS and a target quantum circuit pattern C describing the replaced subcircuit TT composition;
[0041] (4) Define the order relationship between quantum circuit modes: For two quantum circuit modes C TA and C TB , if the quantum circuit mode CTA The sequence representation corresponds to the quantum circuit mode C TB The prefix of the sequence representation is called quantum circuit pattern C TA is the quantum circuit mode C TB prefix;
[0042] (5) Definition of pattern tree: A pattern tree T = (V, E) is an abstract data structure that describes multiple quantum circuit patterns. V represents a node set, and E represents a set of connecting edges between nodes in the node set. Each node v∈V represents a quantum circuit pattern, and each edge e = (u, v, g) represents that the quantum circuit pattern corresponding to node v is obtained by adding a quantum gate g to the end of the quantum circuit pattern corresponding to node u.
[0043] According to the above definition, multiple quantum circuit patterns can now construct a pattern tree T = (V, E) based on their precedence relationship. Using this definition, it is possible to connect edges between nodes represented by different quantum circuit patterns, thereby constructing a pattern tree T.
[0044] Because the transformation rule consists of a source quantum circuit pattern and a target quantum circuit pattern, for multiple transformation rules, their source quantum circuit patterns can be built into a pattern tree to associate nodes with transformation rules. Note that since different transformation rules may have the same source quantum circuit pattern, a node may represent one or more transformation rules. In addition, in order to build the pattern tree, additional nodes may be introduced to connect the nodes represented by the source pattern of the transformation rule. This is because according to the definition of the pattern tree edge, only one quantum gate can be added to each edge. Therefore, if this introduced node cannot be used as the source quantum circuit pattern of any transformation rule, then it does not correspond to any transformation rule.
[0045] In the pattern tree T, according to the above record, and separating the empty quantum circuit mode, these nodes are divided into the following three types of nodes: b1) root node: corresponding to the empty quantum circuit mode; b2) valid node: the quantum circuit mode corresponding to the valid node can be optimized, and the node can express all the transformation rules with it as the source quantum circuit mode, that is, each transformation rule is placed in the node corresponding to the respective source quantum circuit mode, and the pattern tree T is used to represent multiple transformation rules; b3) invalid node: the source circuit mode corresponding to the invalid node cannot be optimized, and there is no transformation rule with it as the source quantum circuit mode.
[0046] It is known that each transformation rule consists of a source quantum circuit pattern and a target circuit pattern, so each node on the pattern tree can represent zero, one or more than one transformation rules, depending on whether the quantum circuit pattern corresponding to the node can serve as the source quantum circuit pattern of the transformation rule.
[0047] In order to more clearly illustrate the pattern tree proposed in this embodiment, a specific example is given below. Figure 4 Shown are two transformation rules R A and R B , note that although the transformation rule R A Source quantum circuit mode and R B Source quantum circuit mode are not each other's prefix patterns, but they have a quantum circuit pattern as a common prefix, which is denoted here as The gate list G = g1g2, g1 = H(q v0 ), g2=X(q v0 ). Abstract qubit list Q v = {q v0}. Parameter variable vector is empty because this quantum circuit mode does not involve any angle parameters.
[0048] Figure 5 Shown are two transformation rules R C and R D , noting that the transformation rule R C Source quantum circuit mode is the transformation rule R D Source quantum circuit mode prefix.
[0049] In view of the above four rules, Figure 6 The pattern tree shown. The blue nodes correspond to the root nodes, the orange nodes correspond to the valid nodes, and the white nodes correspond to the invalid nodes. Node 4 corresponds to quantum circuit pattern C ′ T , node 6 corresponds to Node 9 corresponds to Node 5 corresponds to Node 8 corresponds to The identifier on the edge represents the eg of each edge, that is, the quantum gate added between the nodes. Based on the correspondence between the quantum circuit pattern and the transformation rules in this example, this pattern tree can also express all the above transformation rules.
[0050] Step 2: Convert the transformation rules in the quantum circuit transformation rule library into multiple composite transformation rules based on the pattern tree. The quantum circuit pattern matching algorithm first selects the transformation rules to be processed on the pattern tree based on the composite transformation rules, searches for subcircuits that match the source quantum circuit pattern in the transformation rule in the input quantum circuit, and replaces the subcircuits with the subcircuits instantiated according to the matching information of the target quantum circuit pattern in the transformation rule. Continue this process until the transformation rule can no longer be used, thereby realizing quantum circuit transformation.
[0051] The traditional quantum circuit pattern matching algorithm uses only one transformation rule in the transformation rule base when performing a pattern transformation, and the transformation rule base is obtained by combining various transformation rules.
[0052] The quantum circuit pattern matching algorithm based on the pattern tree uses the pattern tree to represent the transformation rule base during pattern transformation, and connects the transformation rules in the transformation rule base according to the relationship on the pattern tree, thereby obtaining a composite transformation rule in the shape of a pattern tree. Compared with the traditional algorithm, the quantum circuit pattern matching algorithm based on the pattern tree in this embodiment explores a path downward from the root node of the pattern tree when performing a pattern transformation. If the quantum circuit pattern corresponding to the current node can be successfully matched, it will continue to move deeper and match a longer quantum circuit pattern; if it fails, it will fall back.
[0053] In the above pattern matching, the deepest node matched in the process, that is, the longest quantum circuit pattern, is selected as the transformation rule. Because the quantum circuit pattern corresponding to each node on the pattern tree is the prefix of the quantum circuit pattern corresponding to its child node, the quantum circuit pattern matching algorithm can reuse the matching information of the previous node each time it goes back.
[0054] For example, based on Figure 6 When the pattern tree shown in the figure performs the pattern matching process, if the sub-circuit matching of the input circuit to the quantum circuit pattern corresponding to node 6 fails, the execution process will fall back to node 4. After finding that node 4 has other child nodes, continue to execute the transformation rule R A Matching of source quantum circuit modes Instead of discarding all matching information and restarting matching from the root node as in traditional methods.
[0055] The pattern matching algorithm of quantum circuits is to replace the matched sub-circuit in the input circuit with a sub-circuit with a smaller scale but equivalent function according to the given equivalence rule, i.e., the quantum circuit transformation rule, thereby reducing the execution cost of the quantum circuit.
[0056] The pattern matching algorithm of quantum circuits will choose whether to delete the upper nodes of the pattern tree to form multiple composite rules according to the amount of common parts, reducing unnecessary access overhead. During execution, the algorithm will use composite transformation rules to process one or more transformation rules at the same time.
[0057] Optimization principle of quantum circuit pattern matching algorithm based on pattern tree: In the existing pattern matching algorithm, the algorithm processes each transformation rule one by one, and its processing flow includes two parts: finding the subcircuit in the quantum circuit that matches the source quantum circuit pattern, and instantiating the target circuit pattern with the matching context and then placing it in the original position of the matching subcircuit. In this embodiment, the pattern tree representation of the transformation rule library is used. Based on the fact that one or more quantum circuit patterns in the pattern tree have the same prefix, the pattern matching algorithm of the quantum circuit simultaneously performs pattern transformation processing on the one or more quantum circuit patterns; that is, the pattern matching algorithm of the quantum circuit can process multiple patterns at the same time, and in the case of matching failure, it can also reduce the overhead caused by matching failure by means of backtracking.
[0058] In step one, the shared prefix relationship between the source two-word circuit patterns in different quantum circuit transformation rules is observed. By defining the precedence relationship between circuit transformation rules and circuit patterns, a pattern tree is proposed, so that the quantum circuit pattern matching algorithm can process multiple transformation rules at the same time; in step two, by adopting a pattern matching algorithm for quantum circuits based on a pattern tree, the redundant matching process of the algorithm in the matching process is reduced, thereby optimizing the execution time of the pattern matching algorithm.
[0059] Therefore, according to steps 1 and 2, this embodiment organizes a batch of transformation rules into a pattern tree in a manner that the source quantum circuit patterns share a common prefix, and designs a pattern matching algorithm for quantum circuits based on this pattern tree representation. The pattern matching algorithm can efficiently find a set of sub-quantum circuits in a given quantum circuit that matches one or some quantum circuit patterns in the pattern tree, while maintaining the optimization effect of pattern matching on the quantum circuit.
[0060] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can make equivalent replacements or changes according to the technical scheme and inventive concept of the present invention within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.
Claims
1. A quantum circuit pattern matching method based on a pattern tree, characterized in that: The steps include: Step 1: Define quantum circuit patterns and transformation rules; define a pattern tree based on the common prefix structure of different quantum circuit patterns; Step 2: Convert the transformation rules in the quantum circuit transformation rule library into multiple composite transformation rules based on the pattern tree. The quantum circuit pattern matching algorithm first selects the transformation rules to be processed on the pattern tree based on the composite transformation rules, searches for subcircuits that match the source quantum circuit pattern in the transformation rule in the input quantum circuit, and replaces the subcircuits with the subcircuits instantiated according to the matching information of the target quantum circuit pattern in the transformation rule. This process is continued until the transformation rule can no longer be used, so as to replace the matched subcircuits with subcircuits with smaller circuit scale but equivalent functions, thereby realizing quantum circuit transformation.
2. The method for pattern matching of quantum circuits based on pattern trees according to claim 1, characterized in that: In step 1, a quantum circuit pattern is defined. represents a class of quantum circuits specified by the following parameters; List of quantum gates ,in is the total number of quantum gates, Indicates A quantum gate; List of abstract qubits ,in Represents an abstract qubit that can be instantiated to distinguish it from the qubits in a quantum circuit; Parameter variable vector Contains all angle variables in the quantum gate list.
3. The quantum circuit pattern matching method based on pattern tree according to claim 1 is characterized in that: In step one: Defining transformation rules : A transformation rule A source quantum circuit pattern describing the replaced subcircuit and a target quantum circuit pattern describing the replaced subcircuit composition; Define the order relationship between quantum circuit modes: For two quantum circuit modes and , if the quantum circuit mode The sequence representation corresponds to the quantum circuit mode The prefix of the sequence representation is called quantum circuit mode It is a quantum circuit model prefix; Defining the Schema Tree , Represents a collection of nodes. Represents the set of connecting edges between nodes in the node set. Each node Represents a quantum circuit pattern, each edge Represents the node The corresponding quantum circuit pattern is at the node Add a quantum gate to the end of the gate list of the corresponding quantum circuit mode The obtained pattern tree is an abstract data structure for describing multiple quantum circuit patterns.
4. The method for pattern matching of quantum circuits based on pattern trees according to claim 3, characterized in that: In the schema tree In the example, each node corresponds to a quantum circuit mode. According to the characteristics of the corresponding quantum circuit mode and whether it can correspond to the transformation rules, these nodes are divided into the following three types of nodes: b1) root node: corresponding to the empty quantum circuit mode; b2) valid node: the quantum circuit mode corresponding to the valid node can be optimized, and the node can express all the transformation rules with it as the source quantum circuit mode; b3) invalid node: the source circuit mode corresponding to the invalid node cannot be optimized, and there is no transformation rule with it as the source quantum circuit mode.
5. The method for pattern matching of quantum circuits based on pattern trees according to claim 2, characterized in that: In step 2, the pattern matching algorithm of the quantum circuit uses the transformation rule base of the quantum circuit when performing pattern transformation, and the transformation rule base is obtained by combining various transformation rules.
6. The method for pattern matching of quantum circuits based on pattern trees according to claim 5, characterized in that: In step 2, the pattern tree-based quantum circuit pattern matching algorithm first connects one or more transformation rules in the transformation rule library based on the pattern tree definition to form a composite transformation rule, and uses the composite transformation rule to simultaneously process one or more transformation rules. Based on the composite transformation rule, a path is explored downward from the root node of the pattern tree. If the quantum circuit pattern corresponding to the current node can be successfully matched, it continues to move deeper; if it fails, it falls back and reuses the matching information of the previous node, thereby realizing the pattern matching of the quantum circuit.
Citation Information
Patent Citations
Cooperative quantum learning method and system and storage medium
CN114861926A
Quantum circuit simplification method based on NCV quantum gate sequence equivalent transformation
CN115600679A