1. Introduction
Quantum computing, a new computing paradigm that leverages the superposition and entanglement features of quantum mechanics, has the potential to solve many problems faster than classical computers, such as integer factorization [
1] and linear equations [
2]. Currently, quantum computing has entered the era of noisy intermediate-scale quantum (NISQ) devices [
3]. In contrast to the idealized quantum circuit model, physical quantum architectures have a connectivity constraint, limiting the set of allowable two-qubit gates between specific pairs of qubits. To ensure that a quantum circuit is functionally equivalent to the desired computation and satisfies the connectivity constraint, quantum circuit transformations must be applied. However, NISQ devices suffer from crosstalk noise, which results from unexpected interactions or uncorrected control of qubits. This noise compromises the fidelity of the final circuit execution results [
4]. Therefore, minimizing the number of SWAP gates added to the circuit during the transformation process is a critical task for circuit optimization.
The process of transforming a quantum circuit can be divided into two sub-procedures. The first involves finding an initial mapping, which maps logical qubits to physical qubits. The second sub-procedure involves handling quantum gates that violate the interaction constraint in the current mapping by inserting SWAP gates to lead to neighboring qubits. However, determining the minimal number of SWAP gates required for the quantum circuit transformation is an NP complete problem [
5]. To solve this problem, various methods have been proposed [
6,
7,
8,
9,
10,
11,
12,
13,
14,
15]. One type of method formulates the problem mathematically and uses solvers such as integer linear programming [
16], satisfiability module theory [
4], constraint planning [
17], or Boolean solvers [
18] to find solutions. These methods are effective for small quantum circuits. The second type of method uses heuristic algorithms to solve the problem. For example, the backward traversal-based mapping method SABRE [
6], Monte Carlo tree search [
8], A* search algorithm [
7,
19], good initial mapping generation [
9], Bridge gate insertion [
10], reversibility-based comparison of forward and reverse circuit transformation processes [
11], greedy algorithm [
12], simulated annealing [
13], subgraph isomorphism-based mapping [
14], and an algorithm based on dynamic look-ahead heuristic cost functions [
15] have been proposed. These heuristic algorithms use different evaluation functions to determine the best mapping strategy, based on various factors such as the number of two-qubit quantum gates, the depth of the circuit, the distance between the control qubit and the target qubit, or the topology of the quantum circuit. Some methods also consider the dependency of quantum gates in the circuit and prioritize the execution of preceding gates.
In this paper, we follow a similar approach to the literature [
14] by using the number of additional CNOT gates as a metric for measurement, and we utilize subgraph isomorphism as the basic algorithm in the initial mapping. However, in addition to this, we consider the execution order of the quantum gates in the logical quantum circuit during the initial mapping process. Furthermore, we propose a forward-looking heuristic algorithm during the routing process to compare the quantum gate interaction distances, particularly in cases where the interactability rates are equal, to find a better routing path. The proposed method achieves the final transformation of logical quantum circuits to executable physical quantum circuits.
The process of transforming a quantum circuit can be divided into two main steps: (i) initial qubit mapping and (ii) insertion of SWAP gates. In the initial qubit mapping step, we first assign a timing weight to each edge in the circuit’s interaction graph and then use a subgraph isomorphism algorithm based on these timing weights to find an initial mapping between the logical qubits and physical qubits. In the SWAP gates insertion step, there may be several possible sequences of SWAP gates that can be applied. To determine the best sequence, we define an interactivity value and a distance optimization measure for each sequence. We propose a sequence selection optimization algorithm based on maximizing the distance measure optimization function, which selects the SWAP gates sequence with the highest value. The experimental results demonstrate the effectiveness of our algorithm.
The paper is structured as follows. In
Section 2, we provide definitions and notations related to quantum gates and circuits.
Section 3 presents our initial mapping algorithm based on timing weight subgraph isomorphism. In
Section 4, we propose a SWAP gate sequence selection optimization algorithm for quantum circuit transformation. In
Section 5, we evaluate our approach on benchmark quantum circuits and compare it with a state-of-the-art method. We conclude the paper in
Section 6.
3. Initial Qubit Mapping
A physical quantum device can be represented by its coupling graph
, which is an undirected graph
where each qubit in the device is a node in
V, and there is an edge
between two nodes
and
if they can be operated by a two-qubit gate in the device. For instance,
Figure 4 shows the coupling graph of IBM QX20 Tokyo.
Given a quantum circuit and a coupling graph , an initial mapping is an injection from Q to V. To find an effective initial mapping, it is important to consider the following two conditions when designing the algorithm:
Logical qubits that interact frequently should be mapped to physically adjacent qubits.
Qubits with high execution priority, based on the order of quantum gates in the circuit, should be mapped to adjacent physical qubits.
By taking into account these conditions, we can design an initial mapping algorithm that can improve the performance and efficiency of quantum circuit execution on physical devices.
3.1. Timing Weight
To further improve the effectiveness of the initial mapping algorithm, we can introduce another metric called timing weight. The timing weight takes into account the execution order of quantum gates and the interaction relationships between qubits in the quantum circuit. In this subsection, we define the timing weight for quantum gates and edges in the interaction graph and explain how it can be used to design an improved initial mapping algorithm.
Definition 1. Given a quantum circuit , where and , the timing weight, , for each quantum gate iswhere is the execution order of . Definition 2. Let be the interaction graph of . For each edge in , where are qubits in , the timing weight, , of iswhere is the timing weight of . The timing weight measures the importance of a quantum gate in the execution order of a quantum circuit, with lower weights assigned to gates executed later. The timing weight of an edge in the interaction graph represents the total timing weight of the gates that interact through that edge.
Example 2. Figure 5 displays the timing weights of the gates in the circuit of Figure 2 and the timing weights of the edges in its interaction graph. The edge has the largest weight, indicating that the gates associated with these qubits are executed first in the circuit. As and contain the most CNOT gates in the circuit, they should be mapped as nearest neighbors. 3.2. Initial Mapping Based on Timing Weight
To construct an initial mapping for a quantum circuit and a coupling graph , we first compute the interaction graph of with timing weights assigned to each edge. If is isomorphic to a subgraph of , we can construct an initial mapping from the isomorphism without adding any SWAP gates. However, when cannot be directly mapped to , we use a partial subgraph isomorphism based on timing weight. This means that edges with larger timing weights are given higher priority in the mapping process.
The timing weight of each edge in not only indicates the qubits with more CNOT executions but also the execution order of the CNOT gates in the circuit. Thus, it is an important factor in finding an optimal initial mapping that provides a better precondition for subsequent quantum circuit transformations. We propose an initial mapping algorithm based on timing weight subgraph isomorphism, as outlined in Algorithm 1. The algorithm takes and as inputs and constructs an initial mapping by searching every edge from the one with the highest timing weight.
Algorithm 1 outlines the steps for constructing an initial mapping based on timing weight subgraph isomorphism. To begin, we initialize the set of edges
of
. Lines 2–8 compute the interaction graph,
, of
with timing weights for all edges. Line 9 sorts the edges from the largest timing weight to the smallest timing weight. Lines 10–16 construct a graph
starting from the edge with the largest timing weight and add the edge to
if there is a subgraph isomorphism from
to
. If there is no subgraph isomorphism, the edge is skipped. This process is repeated until all the edges in
are traversed. Finally, an initial mapping is constructed from
and saved in
. It is important to note that the initial mapping obtained may not be unique, as it depends on the subgraph isomorphism found from
to
in the algorithm.
Algorithm 1 Initial mapping based on timing weight subgraph isomorphism |
- Input:
A quantum circuit and a coupling graph . - Output:
An initial mapping from Q to V. - 1:
Initialize:; - 2:
for each gate do - 3:
- 4:
if or then - 5:
- 6:
- 7:
end if - 8:
end for - 9:
- 10:
whiledo - 11:
if is isomorphic to a subgraph of then - 12:
- 13:
else - 14:
- 15:
end if - 16:
end while - 17:
- 18:
return
|
Example 3. By applying Algorithm 1 to the quantum circuit shown in Figure 2 and the coupling graph of IBM QX20 shown in Figure 4, we can obtain three initial mappings (colored in red) as shown in Figure 6. It is important to note that the initial mapping obtained may not be unique, as it depends on the subgraph isomorphism found from the algorithm. 4. Quantum Circuit Transformation and Optimization
Given the quantum circuit
, the coupling graph
, and the mapping
from
to
, we need to ensure that every quantum gate in
is mapped to adjacent qubits in
. If a gate violates this interaction condition, we can add SWAP gates to the circuit to make the two qubits operated by the gate adjacent. This process can be repeated for every edge in
. We use
to denote the application of a SWAP gate on the two ends of
e. After performing a swap operation, a new mapping
can be obtained by updating
. For instance, in
Figure 6, the initial mapping
is
. We can apply
and
to obtain the mapping
.
4.1. Swap Sequence Selection
During the quantum circuit transformation process, a sequence of SWAP gates is added to ensure that every gate in the circuit satisfies the interaction condition with respect to the coupling graph. However, this sequence is not unique, and we aim to find the shortest sequence that minimizes the number of gates in the resulting circuit.
Let
be a mapping from the quantum circuit
to the coupling graph
, and let
be a sequence of SWAP gates, where each
is an edge of
. We use
to denote the number of gates in
that are executable after applying the sequence
a from mapping
. To measure the effectiveness of the transformation, we define the interactivity value:
where
is the number of SWAP gates in
a. A larger value of
indicates that the sequence
a is more effective in transforming the circuit. Therefore, we aim to find the sequence
b that maximizes
for a given mapping
.
Now let us consider an example to see how the swap sequence selection algorithm works in practice.
Example 4. Consider the quantum circuit shown in Figure 2 and the initial mapping in Figure 6. The first quantum gate that violates the interactive constraint is . To address this issue, we explore four different swap ways and the number of gates that can be executed for each one, as follows: - 1.
: seven gates can be executed;
- 2.
: seven gates can be executed;
- 3.
: four gates can be executed;
- 4.
: six gates can be executed.
We can then evaluate the validity of each sequence using the metric , and obtain , , , and . Based on these values, we conclude that the candidate sequences are (i) and (ii).
4.2. Sequence Selection Optimization
For large-scale quantum circuits, there are often multiple swap sequences that satisfy the interactivity constraint, as shown in Example 4. In this subsection, we propose a sequence selection optimization algorithm to find a better swap sequence from the candidate sequences.
Given the quantum circuit
, the coupling graph
, and the mapping
from
to
, we use
to denote the length of the shortest path between
and
in
for every gate
in
. Let
a be a sequence of SWAP gates, and let
denote the new mapping obtained by applying
a to
. We define the set
, which contains the gates whose execution order is affected by the sequence
a. We then define the distance optimization measure as follows:
where
is the timing weight of
.
The value of
depends on the timing weight of every gate in
S. A gate
with a large value of
means that
has a high execution order. Therefore,
indicates the priority of the sequence
a; a sequence with a larger
should be selected first. To select the best swap sequence, we compute the
values for each candidate sequence using Equation (
4), and choose the sequence with the largest value. The swap sequence selection optimization algorithm is presented in Algorithm 2. The inputs of the algorithm are a quantum circuit, a coupling graph, and an initial mapping. The output is a transformed quantum circuit that is compliant with the connectivity constraint.
Algorithm 2 Sequence selection optimization algorithm |
- Input:
A quantum circuit , a coupling graph , and an initial mapping . - Output:
A quantum circuit that is compliant with connectivity constraint of . - 1:
Initialize:; ; ; - 2:
for each gate do - 3:
if then - 4:
- 5:
- 6:
else - 7:
- 8:
(compute the for all possible SWAP gates and save the largest ones) - 9:
for each do - 10:
- 11:
(compute the for all sequences in and take one of the largest) - 12:
end for - 13:
- 14:
- 15:
- 16:
- 17:
- 18:
end if - 19:
end for - 20:
return
|
The algorithm starts by initializing the necessary variables. It adds all quantum gates that meet the connectivity constraint in and removes them from according to their execution order in the current mapping, as described in Lines 3–5. If no gate can be added to , indicating that SWAP gates must be inserted, the algorithm computes the for all possible SWAP gate sequences and saves those with the largest value in , as shown in Line 7. Next, Lines 9–12 compute the for all sequences in and selects the one that has the largest value. Finally, Lines 13–17 update , , , and a based on the SWAP gates added.
To illustrate how the sequence selection optimization algorithm works, let us consider the following example.
Example 5. In Example 4, we compare the two SWAP gate sequences and , which have the same value. Using Equation (4), we obtain the following distances and cost values:Since both sequences have the same value, we choose the sequence with the higher values according Algorithm 2. Therefore, we choose sequence as the optimal swap sequence. 5. Evaluation
To assess the effectiveness of the proposed methods, we now turn to evaluate their performance on a variety of quantum circuits. We provide experimental results and comparisons with existing approaches in this section.
The proposed methods were implemented in Python, and the experiments were conducted on a Windows 10 machine with an Intel Core i7 processor and 16 GB of RAM. The quantum circuits used in the experiments were publicly available benchmarks evaluated in [
14]. The experimental comparison baseline is the number of CNOT gates inserted by the quantum circuit transformation. In this paper, we classify quantum circuits with less than 1000 gates as small scale, those with greater than 1000 and less than 10,000 gates as medium scale, and those with more than 10,000 gates as large scale.
Table 1,
Table 2 and
Table 3 show the results of the experiments for small scale, medium scale, and large scale circuits, respectively. The first column in each table lists the benchmark, the second column “QubitNu” shows the number of qubits in the circuit, and the third column “GateNu” shows the number of CNOT gates in the circuit. The fourth and fifth columns, labeled “AuxGt”, show the number of auxiliary CNOT gates added by the transformation algorithm in [
6,
14], respectively, and serve as the main comparative baseline for the experiments. The sixth column shows the number of auxiliary CNOT gates added by the algorithm proposed in this paper. The seventh and eighth columns, labeled “Comp.”, show the optimization rate compared with the literature [
6,
14]. The last row of each table shows the average optimization rate.
In order to evaluate the effectiveness of the proposed quantum circuit transformation optimization algorithm, we compare the experimental results with two previous algorithms, Sabre [
6] and Topgraph [
14]. Sabre is integrated in the IBMQ quantum cloud platform, which represents the current optimal level of IBMQ, and Topgraph is the basis of algorithm improvement in this paper. Therefore, they are selected as the baselines for the experiments in this paper. From the experimental results in the three tables, it is evident that the quantum circuit transformation optimization algorithm in this paper outperforms Sabre, with the highest average optimization rate reaching 70.15%. In comparison with Topgraph, the algorithm proposed in this paper achieves a minimum average optimization rate of 4.30% on small-scale circuits and 21.79% on large-scale circuits. Although two quantum circuits in the medium-scale circuit are not optimized, the average optimization rate still reaches 22.04%. Overall, the proposed algorithm has a significant optimization effect on circuits of any scale, with the larger circuits showing more obvious optimization.