Paper The following article is Open access

Variational quantum compiling with double Q-learning

, , , and

Published 5 March 2021 © 2021 The Author(s). Published by IOP Publishing Ltd on behalf of the Institute of Physics and Deutsche Physikalische Gesellschaft
, , Citation Zhimin He et al 2021 New J. Phys. 23 033002 DOI 10.1088/1367-2630/abe0ae

Download Article PDF
DownloadArticle ePub

You need an eReader or compatible software to experience the benefits of the ePub3 file format.

1367-2630/23/3/033002

Abstract

Quantum compiling aims to construct a quantum circuit V by quantum gates drawn from a native gate alphabet, which is functionally equivalent to the target unitary U. It is a crucial stage for the running of quantum algorithms on noisy intermediate-scale quantum (NISQ) devices. However, the space for structure exploration of quantum circuit is enormous, resulting in the requirement of human expertise, hundreds of experimentations or modifications from existing quantum circuits. In this paper, we propose a variational quantum compiling (VQC) algorithm based on reinforcement learning, in order to automatically design the structure of quantum circuit for VQC with no human intervention. An agent is trained to sequentially select quantum gates from the native gate alphabet and the qubits they act on by double Q-learning with epsilon-greedy exploration strategy and experience replay. At first, the agent randomly explores a number of quantum circuits with different structures, and then iteratively discovers structures with higher performance on the learning task. Simulation results show that the proposed method can make exact compilations with less quantum gates compared to previous VQC algorithms. It can reduce the errors of quantum algorithms due to decoherence process and gate noise in NISQ devices, and enable quantum algorithms especially for complex algorithms to be executed within coherence time.

Export citation and abstract BibTeX RIS

Original content from this work may be used under the terms of the Creative Commons Attribution 4.0 licence. Any further distribution of this work must maintain attribution to the author(s) and the title of the work, journal citation and DOI.

1. Introduction

Current available quantum devices are not large-scale and fault-tolerant, but noisy intermediate-scale quantum (NISQ) devices [1]. IBM's and Rgetti's quantum devices fall into this category. Many quantum algorithms have been implemented by parameterized quantum circuits (PQCs) on NISQ devices. Hybrid quantum–classical algorithms based on PQCs are successfully applied to attacking scaled-down problems in chemistry and combinatorial optimization [24]. Besides, they have been applied to many machine learning tasks, e.g., classification [5, 6], clustering [7] and generative model [8, 9]. These algorithms are not restricted to theory and simulation. They have been tested on real quantum devices such as IBM's and Rigetti's quantum devices.

Although NISQ device is a milestone in the field, there are several constraints, which separate them from fully utilizing their capabilities for a quantum advantage. The connectivities between qubits are limited, i.e., multi-qubit gates cannot apply to arbitrary qubits. Besides, the native gate alphabet is restricted. Different quantum devices have their own topologies, i.e., the arrangement of physical qubits, the interactions supported between them, and the native gate alphabet of available quantum gates. For example, IBM and Rigetti's quantum devices have different topologies. Even different quantum devices developed by IBM (e.g., 5-qubit, 16-qubit and 20-qubit devices) have different topologies. Thus, a quantum circuit cannot directly execute on NISQ devices.

Similar as software must be complied to machine code in classical computers, quantum algorithms must be compiled before running on NISQ devices by taking into account the specific constraints. Quantum compiling is a crucial step in the execution of quantum algorithms on NISQ devices, which receives increasing attention in industry and academia [1012]. Quantum compiling aims to construct a quantum circuit by quantum gates drawn from NISQ device's native gate alphabet, which is functionally equivalent to the target unitary. Many techniques have been proposed to successfully compile one-qubit gates [1316]. However, compiling multi-qubit unitaries is more difficult as the exponentially increasing complexity of the problem. Hybrid quantum–classical algorithm has been applied to quantum compiling [1720], which is referred to variational quantum compiling (VQC). In VQC, a parameterized quantum circuit is trained to be functionally equivalent to the target unitary. Heya et al proposed a gate optimization algorithm to construct a target multi-qubit gate by parameterized single-qubit gates and multi-qubit gates [17]. A circuit template with fixed gate types and sequence is used to compile a 7-qubit unitary with 186 gates based on energy dissipation [18]. Circuit design is a key problem of quantum compiling, which requires human expertise and hundreds of experimentations or modifications from existing quantum circuits. Khatri et al proposed to perform circuit design based on simulated annealing for single-qubit and two-qubit quantum unitaries [19]. However, the structure of the trainable unitary is set to the same structure as the target unitary for the target unitaries with more than two qubits. Most of current quantum compiling algorithms for large-scale gate sequences use a specific template as the searching space of the optimization over circuit structure increases exponentially with the number of quantum gates [1822]. However, the quantum circuits designed by this strategy might not be optimal and require more quantum gates. The performance of the quantum algorithm decreases with runtime because of the noise and limited coherence time in current NISQ devices. The increasing number of quantum gates will lead to more gate noises and increase the running time, resulting in the performance degradation. Variable structure ansatzes have been considered in [23] to discover quantum algorithms for computing the overlap between two states, which have shorter depths than the swap test.

In this paper, we proposed to automate the process of circuit design for quantum compiling based on reinforcement learning. An agent is trained to sequentially choose quantum gates and the qubits they act on by double Q-learning with epsilon-greedy exploration strategy [24] and experience replay [25]. In epsilon-greedy exploration strategy, the agent firstly performs a number of explorations by randomly generating quantum circuits, and then slowly transforms smoothly from exploration to exploitation to generate higher performing quantum circuits according to its findings. As the proposed VQC based on double Q-learning does not rely on human experience, it may have more potential to discover novel structures of circuits compared to VQC based on specific templates, which might inspire designers of quantum algorithms. Similar work can be found in reference [26], which proposed to compile single-qubit gates with elementary gates from a finite universal set based on deep reinforcement learning. However, their work is related to topological compiling and is a special case of quantum compiling by considering the action of target unitary on a fixed input state. In addition, reinforcement learning has also been applied for quantum approximate optimization algorithm problems [27].

The rest of the paper is organized as follows. Some related work is introduced in section 2. In section 3, we present the proposed circuit design in VQC based on double Q-learning. We report the performance of the proposed algorithm compared to current VQC by numerical simulation in section 4. Finally, we summarize the results of this paper and discuss the future work in section 5.

2. Related work

VQC aims to compile a target unitary U to a trainable quantum gate sequence V which has approximately the same action as U on all input states [17, 19, 20]. Another kind of VQC only considers a specific input state, e.g., |ψ0⟩ = |0⟩n [18]. In this paper, we focus on the former case as it has more application scenarios.

In VQC, the trainable gate sequence V can be expressed in terms of the native gate alphabet of NISQ devices being used. The native gate alphabet $\mathcal{A}={\left\{{G}_{k}\left(\theta \right)\right\}}_{k}$ consists of gates Gk (θ) that are native to the NISQ device. k is a discrete parameter used to identify the type of quantum gate and the qubit it acts on. θ is the parameter of the quantum gate. If the quantum gate has no parameter, e.g., Hadamard gate, then θ = []. The goal of VQC is to search a gate sequence ${V}_{ \overrightarrow {k}}\left( \overrightarrow {\theta }\right)={G}_{{k}_{L}}\left({\theta }_{L}\right){G}_{{k}_{L-1}}\left({\theta }_{L-1}\right)\dots {G}_{{k}_{1}}\left({\theta }_{1}\right)$ with L gates to minimize the difference between the target unitary U and ${V}_{ \overrightarrow {k}}\left( \overrightarrow {\theta }\right)$, i.e.,

Equation (1)

where $ \overrightarrow {k}=\left\{{k}_{L},{k}_{L-1},\dots ,{k}_{1}\right\}$ is a vector of indices describing which gates are used and which qubits they act on. $ \overrightarrow {\theta }=\left\{{\theta }_{L},{\theta }_{L-1},\dots ,{\theta }_{1}\right\}$ is a vector of continuous parameters associated with the quantum gates in $ \overrightarrow {k}$. Thus, it needs to make numerous choices to construct a quantum circuit, i.e., the number of quantum gates of each type, the qubits they act on, the ordering of quantum gates, and the parameters of quantum gates, which makes the space of quantum circuit structures extremely large and infeasible for an exhaustive manual search. $C\left(\right. U,{V}_{ \overrightarrow {k}}\left( \overrightarrow {\theta }\right)$ quantifies how close the trained unitary ${V}_{ \overrightarrow {k}}\left( \overrightarrow {\theta }\right)$ is to the target unitary U. It can be calculated by the Hilbert–Schmidt inner product between unitaries U and V [19], i.e.,

Equation (2)

where d = 2n is the Hilbert-space dimension where n is the number of qubits in U. C(U, V) = 0 if and only if unitary U and unitary V differ by a global phase factor. C(U, V) can be calculated by the quantum circuit in figure 1 [19]. At the beginning of the circuit, a maximally-entangled state between n-qubit systems A and B is prepared with n Hadamard gates and n CNOT gates. Then the unitaries U and V* act on system A and B, respectively, where V* is the complex conjugate of unitary V. The undoing unitary is implemented with n Hadamard gates and n CNOT gates. At last, C(U, V) is calculated by the probability of the all-zeros outcome for the Bell-basis measurement. For large problem sizes, the global Hilbert–Schimdt test exhibits barren plateau phenomena [28, 29]. In this paper, local Hilbert–Schmidt test [19] is used for the large problem sizes to address this problem:

Equation (3)

where ${C}_{\text{local}}^{\left(i\right)}\left(U,V\right)$ is the same as the global Hilbert–Schmidt test C(U, V) except that only qubits i and i + n are measured, i.e., the probability of the all-zeros outcome on qubits i and i + n for the Bell-basis measurement. Clocal(U, V) is efficient to compute on a quantum computer and scales well with the size of the problem [19].

Figure 1.

Figure 1. Quantum circuit to estimate the difference between the unitaries U and V.

Standard image High-resolution image

The optimization over the continuous parameters $ \overrightarrow {\theta }$ can be performed by a gradient descent algorithm [19]. The gradient with respect to θl of $C\left(U,{V}_{ \overrightarrow {k}}\left( \overrightarrow {\theta }\right)\right)$ is

Equation (4)

where ${ \overrightarrow {\theta }}_{l}^{{\pm}}= \overrightarrow {\theta }{\pm}\frac{\pi }{2}{ \overrightarrow {e}}^{\enspace l}$, and ${ \overrightarrow {e}}^{\enspace l}$ is the lth unit vector in the parameter space corresponding to θl , i.e., ${\theta }_{l}{\leftarrow}{\theta }_{l}{\pm}\frac{\pi }{2}$, with other angles $ \overrightarrow {\theta }-\left\{{\theta }_{l}\right\}$ unchanged. The derivation of equation (4) adopts the parameter shift rule [30], which does not need any additional quantum gates and has been widely used in many hybrid quantum–classical algorithms [9, 19, 20]. Note that for the parameter shift rule to be valid, the generator of the parameterized gate needs to have two unique eigenvalues.

The calculation of $ \overrightarrow {k}$ in equation (1) is an optimization over gate structures. Many current quantum compiling algorithms use a specific template [1821]. Simulated annealing is also used for the optimization over gate structure [20, 31]. However, the searching space of gate structures increases exponentially with the number of gates, i.e., the total number of quantum gates in the circuit, where simulated annealing is less efficient. In this paper, we focus on the optimization over gate structure and propose to find an optimal gate structure by reinforcement learning.

3. Design of quantum circuits with double Q-learning

Reinforcement learning aims to make optimal decision using experiences. Q-learning is a model-free reinforcement learning algorithm incorporating epsilon-greedy strategy and experience replay, which has been proved powerful in large state space [3235]. The first AI program to beat a professional human Go player, i.e., AlphaGO, is fundamentally Q-learning. In this paper, we adopt Q-learning to automatically design a quantum circuit on the large space of quantum circuit structures. Q-learning maps (state, action) pair to Q-value, which is an estimation of how good it takes the action at the state. The fundamental thing of Q-learning is to iteratively update the Q-values of (state, action) pairs based on the immediate reward and the future reward after taking the action.

In this paper, we train a learning agent to sequentially choose quantum gates from the native gate alphabet until a termination state as described in figure 2(a). Each state is defined as a tuple of all relevant parameters, i.e., (gate, qubit, number of gates), which denote the type of the selected quantum gate, the qubit the gate acts on and the number of gates in current gate sequence. In order to make sure the state-action graph is directed and acyclic, the parameter number of gates is added to the state space. Another advantage of equipping the state with number of gates is that it can limit the number of quantum gates in the compiled quantum circuit. Any state with the maximum number of gates can only transition to a termination state. The selection of a quantum gate and the qubit it acts on can be regarded as an action in Q-learning. The number of actions in the current state depends on the native gate alphabet and the number of qubits. For example, without considering the connectivity constraint, the number of actions is np + qn(n − 1) for compiling an n-qubit unitary with the native gate alphabet including p one-qubit gates and q two-qubit gates. Some restrictions should be considered to make the learning processing tractable. At first, the state with j gates is only permitted to transition to a state with j + 1 gates, which ensures that the state-action graph is directed and acyclic. Figure 2(a) shows feasible states, action space and the state transition from sk to sk+1 by taking action ak , where k is the number of gates in current state.

Figure 2.

Figure 2. Illustration of quantum circuit construction with Q-learning. (a) Shows the feasible states, action space of an n-qubit quantum circuit with L quantum gates and the state transitions by different actions. The tuple of each state is (gate, qubit, number of gates). For example, (Rx , n, 3) denotes that the quantum circuit consists of three gates and the last gate of the quantum circuit is Rx acting on the nth qubit. T state denotes a termination state. The red solid line shows a path the agent may choose, resulting on the quantum circuit in (b). The flowchart of Q-learning is shown in (c).

Standard image High-resolution image

The quantum circuit in figure 2(b) is generated by the red solid line in (a). The gate selection process is a Markov decision process. The design of a quantum circuit can be regarded as an action selection trajectory τi . The reward r of the transition from state s to s' by action a may be stochastic according to a distribution pr|s,a,s'. The agent aims to maximize the expected reward over all possible trajectories τ, i.e., ${\mathrm{max}}_{{\tau }_{i}\in \tau }\enspace {R}_{{\tau }_{i}}$. The total expected reward for a trajectory τi is

Equation (5)

Given a state st S and subsequent action aA(st ) where S is all possible states and A(st ) is all possible actions in state st , the maximum total expected reward is denoted by Q(st , a), i.e., Q-value of the state-action pair (st , a). Based on Bellman's equation, we can get

Equation (6)

It can be formulated as an iterative update

Equation (7)

where ${a}^{\star }=\mathrm{arg}\enspace {\mathrm{max}}_{{a}^{\prime }\in A\left({s}_{t+1}\right)}\;Q\left({s}_{t+1},{a}^{\prime }\right)$. α ∈ [0, 1] is the learning rate, which determines the importance of the newly acquired information compared to old information. α = 0 means that the agent learns nothing from the newly acquired information, while α = 1 indicates the agent only considers the most recent information ignoring prior knowledge. γ is the discount factor, which makes a balance between the immediate reward and the future reward. γ = 0 means that the agent only considers immediate reward. The future reward is more important when γ is larger. rt is the intermediate reward when moving from state st to st+1. When a state goes from st to a termination state sT by an action aT , equation (7) can be simplified as

Equation (8)

where rT is the termination reward. It can be calculated by

Equation (9)

where C(U, V) is measured by Hilbert–Schmidt test of current quantum circuit and the target unitary U using the circuit in figure 1. The intermediate reward rt can be estimated by reward shaping [36], which can speed up the training process, i.e., rt = rT /L, where L is the number of gates in the quantum circuit.

The detail process of double Q-learning for circuit design in VQC is shown in algorithm 1. At first, Q-values are initialized by the average of the termination reward rT over a number of randomly generated quantum circuits, i.e., the quantum circuits generated when epsilon = 1. For each ${{\epsilon}}_{j}\in \overrightarrow {{\epsilon}}$, Ej circuits are generated based on epsilon-greedy strategy. The parameters $ \overrightarrow {\theta }$ of these quantum circuits are optimized based on the gradient descent approach in algorithm 4 of reference [19]. Then the reward can be calculated by Hilbert–Schmidt test with the quantum circuit in figure 1, and is stored in a replay memory as well as its corresponding circuit structure. The Q-values are periodically updated by a batch samples randomly drawn from the replay memory. The flowchart of Q-learning is shown in figure 2(c). The performance of Q-learning is not satisfying in stochastic Markov decision processes due to the overestimation of the action values resulted from using the maximum action value as an approximation for the maximum expected action value. In this paper, we use double Q-learning [37], which uses two Q-value functions Q1 and Q2 to determine the value of the next state. In epsilon-greedy strategy, a quantum gate is selected randomly with probability epsilon and based on Q-value with probability 1 − epsilon. At first, with a high epsilon, the agent can explore different structures of quantum circuits by randomly choosing actions. As the agent explores the environment, epsilon decreases and the agent starts to exploit the environment.

Algorithm 1. Double Q-learning for circuit design in VQC.

Input: $ \overrightarrow {{\epsilon}}=\left\{{{\epsilon}}_{1},{{\epsilon}}_{2},\dots ,{{\epsilon}}_{m}\right\}$: parameters of epsilon-greedy strategy; Ej : the number of generated quantum circuits for epsilonj ; K: the size
 of minibatch for Q-value update; L: the maximum gate number of the quantum circuit; γ: the discount factor; α: the learning
 rate; $\mathcal{A}$: the native gate alphabet.
Output: V: the compiled quantum circuit.
1: set the replay memory M = [] and set r = 0
2: set Q1(s, a) = q0, Q2(s, a) = q0, ∀ sS, ∀ aA(s), where q0 is the average of the termination reward rT
 over a number of randomly generated quantum circuits and the action space depends on the native gate alphabet $\mathcal{A}$
3: for each epsilonj in $ \overrightarrow {{\epsilon}}$ do
4:  for i= 1 to Ej do
5:   remark: generate the ith quantum circuit with epsilon-greedy strategy
6:   set gate sequence Vi = [] and current state s = 'Start'
7:   for l= 1 to L do
8:       with probability epsilonj select a random action a' from A(s)
9:       otherwise select action a' = arg maxaA(s)(Q1(s, a) + Q2(s, a))
10:     perform a transition(s = s') from current state to s' after taking action a'
11:     append (s, a') to Vi
12:    generate a quantum circuit based on Vi
13:    optimize the gate parameters $ \overrightarrow {\theta }$ based on the gradient descent approach in [19]
14:    calculate the reward ${r}_{T}^{i}$ according to equation (9)
15:    put $\left\{{V}_{i},{r}_{T}^{i}\right\}$ into the replay memory M
16:    if ${r}^{\star }{< }{r}_{T}^{i}$ then
17:     ${r}^{\star }={r}_{T}^{i}$ and V = Vi
18:    remark: update Q-values by a batch samples drawn from the replay memory
19:    for k = 1 to K do
20:     randomly select $\left\{{V}_{k},{r}_{T}^{k}\right\}$ from the replay memory
21:     generate a random number y between 0 and 1
22:     for each (st , at ) in Vk do
23:     if y < 0.5 then
24:      Q1(st , at ) = (1 − α)Q1(st , at ) + α(rt + γQ2(st+1, a)),
25:      where ${a}^{\star }=\mathrm{arg}\enspace {\mathrm{max}}_{a\in A\left({s}_{t+1}\right)}{Q}_{1}\left({s}_{t+1},a\right)$
26:     else
27:      Q2(st , at ) = (1 − α)Q2(st , at ) + α(rt + γQ1(st+1, a)),
28:      where ${a}^{\star }=\mathrm{arg}\enspace {\mathrm{max}}_{a\in A\left({s}_{t+1}\right)}{Q}_{2}\left({s}_{t+1},a\right)$

As two-qubit gates have much lower fidelities than single-qubit gates in current NISQ devices, it is of great significance to minimize the number of two-qubit gates in the compiled circuit [38, 39]. It can be done by modifying the reward function in equation (9) as

Equation (10)

where Cp = nCNOT/L is a penalty term which motivates the agent to use fewer CNOT gates in the designed circuit. λ is a weighted parameter which balances C(U, V) and the number of CNOT gates in the circuit. nCNOT and L are the number of CNOT gates and quantum gates in the circuit.

The searching space of the optimization over circuit structure increases exponentially with the number of quantum gates L. In many applications, L grows polynomially with the number of qubits. This issue is crucial for large problem sizes. To address this problem, we can add some common blocks to the candidate gate alphabet, which largely decreases the computation complexity of the proposed algorithm for large problem sizes. This strategy can be regarded as a crossover of variable structure ansatze and fixed-template compiling, which not only makes the algorithm scale well with the size of the problem, but also decreases the number of quantum gates in the compiled circuit.

4. Numerical simulation

In this section, we verify the performance of the proposed VQC based on double Q-learning on 2 to 8-qubit unitaries.

4.1. VQC on two-qubit unitaries

In this section, we compile five two-qubit unitaries including controlled-phase (CS), controlled-Hadamard (CH), controlled-Z (CZ), Mølmer–Sørensen XX gate with θ = 3π/2 (XX(3π/2)) and two-qubit quantum Fourier transform (QFT2) in a simulator. Similar to the previous work [19], we consider the native gate alphabet

Equation (11)

where Rx (π/2) and Rz (θ) are one-qubit gates while CNOT is a two-qubit gate. θ is a continuous parameter of Rz gate which denotes the angle to rotate around the z-axis on the Bloch sphere. In this simulation, we do not consider the connectivity constraint of NISQ devices. Thus, the number of actions (|A(s)|) for each state s is 6. We can simply implement quantum compiling for NISQ devices with connectivity constraint by modifying the action space A(s), i.e., removing the actions which are not permitted due to the connectivity constraint.

A replay memory is used to store the circuit structures and their corresponding costs C(U, V) after each iteration in the experience replay. The parameter K indicates the agent samples K quantum circuits with their corresponding costs from the replay memory to update the Q-values. The learning rate α, the discount factor γ and the batch size K are empirical parameters. According to previous works [35, 40] and the results of serval values, we set α, γ and K to be 0.02, 0.9 and 128.

In epsilon-greedy strategy, the agent either selects a quantum gate based on Q-values with probability 1 − epsilon or randomly selects a quantum gate with probability epsilon. In our experiment, epsilon decreases from 1.0 to 0.1, which makes the agent transform smoothly from exploration to exploitation. The number of quantum circuits generated for each epsilon is shown in table 1. A large number of randomly generated quantum circuits are trained at epsilon = 1.0 in order to let the agent see more quantum circuit structures.

Table 1. Number of quantum circuits generated at each epsilon for two-qubit unitaries.

epsilon 1.00.90.80.70.60.50.40.30.20.1
Number of circuits1500100100100150150150150150150

Figure 3 shows the minimum cost achieved by VQC based on double Q-learning as the increasing of the number of gates in the quantum circuit. The cost C(U, V) decreases with the increasing number of quantum gates in V and finally converges to 0, i.e., U = V. For CS, CZ and XX(3π/2) gates, a quantum circuit with 5 quantum gates from the native gate alphabet can achieve zero cost. To compile CH gate, it needs at least 6 quantum gates. QFT2 is the most difficult unitary to compile which needs 10 quantum gates. The numbers of CNOT gates in the compiled circuits for CH, CS, CZ, XX(3π/2) and QFT2 are 1, 2, 2, 2 and 3, respectively. We remark that the theoretical lower bound of CNOT gates required for the implementation of an arbitrary two-qubit unitary is 3 [41, 42].

Figure 3.

Figure 3. The minimum cost achieved by VQC based on double Q-learning for the two-qubit unitares, i.e., CS, CH, CZ, Mølmer–Sørensen XX gate with 3π/2 (XX(3π/2)) and QFT2.

Standard image High-resolution image

We also compare the number of quantum gates in the VQC based on double Q-learning to the one based on simulated annealing [19] in table 2 and find that we achieve an exact compilation with the same number of quantum gates. Figure 4 shows the structures of the compiled circuits by VQC based on double Q-learning for the two-qubit unitares. The rotation angles of the quantum gates in these circuits are illustrated in table A1 in appendix A.

Table 2. The number of quantum gates in the quantum circuits compiled by the VQC in reference [19] (QAQC) and the proposed VQC for the two-qubit target unitaries. a

 CSCHCZ XX(3π/2)QFT2
QAQC/65/10
Proposed VQC565510

a'/' means that reference [19] did not consider this quantum gate.

Figure 4.

Figure 4. The compiled circuits by VQC based on double Q-learning for the two-qubit unitares.

Standard image High-resolution image

4.2. VQC on three-qubit unitaries

We firstly perform a simulation of the proposed method on fully-connected qubits in section 4.2.1. Then the limited connectivity of qubits on IBM's 5-qubit quantum device ('Ibmq_ourense') is considered in section 4.2.2. In section 4.2.3, a penalty term is considered in the reward function to motivate the agent to generate quantum circuits with fewer CNOT gates.

4.2.1. Simulation on fully-connected qubits

Similar to the previous work [20], we consider the following three-qubit unitaries: three-qubit W-state preparation (WSP3), Toffoli gate (CCNOT) and three-qubit quantum Fourier transform (QFT3). We use the same native gate alphabet as the previous work [20], i.e.,

Equation (12)

where Rx (θ) and Ry (θ) are one-qubit rotation gates around x-axis and y-axis.

Similar to the previous section, the learning rate α, the discount factor γ and the batch size K are set to 0.02, 0.9 and 128, respectively. Compared to two-qubit unitaries, it is much more difficult to compile three-qubit unitaries as it needs more quantum gates and the searching space of the optimization over gate structures increases exponentially with the number of gates. Thus, we enlarge the number of quantum circuits in each epsilon as shown in table 3. Figure 5 shows the result of proposed VQC with different numbers of quantum gates in V for different target unitaries, i.e., WSP3, CCNOT and QFT3. The cost C(U, V) decreases with the increasing number of quantum gates in the circuit V and converges to 0 for all the target unitaries. WSP3 is the easiest to compile among the three target unitaries, which needs 7 quantum gates to make an exact compilation. QFT3 and CCNOT are more difficult to compile which need 22 and 25 quantum gates, respectively. The numbers of CNOT gates in the compiled circuits for WSP3, CCNOT and QFT3 are 2, 10 and 7, respectively. We remark that the theoretical lower bound of CNOT gates required for the implementation of an arbitrary three-qubit unitary is 14 [41, 42].

Table 3. The number of quantum circuits generated at each epsilon for three-qubit unitaries.

epsilon 1.00.90.80.70.60.50.40.30.20.1
Number of circuits3000200200200300300300300300300
Figure 5.

Figure 5. The minimum cost achieved by VQC based on double Q-learning for the three-qubit unitaries, i.e., WSP3, Toffoli gate (CCNOT), and QFT3.

Standard image High-resolution image

We also compare the performance of the circuit structure designed by the proposed method and the found structures in reference [20], i.e., alternating-pair ansatz with two layers and the target-inspired ansatz. In each layer of alternating-pair ansatz, dressed CNOT gates (see figure 6(a)) act on alternating pairs of neighboring qubits as described in figure 6(b). Target-inspired ansatz is constructed by removing all one-qubit gates and replacing each remaining gate with a dressed CNOT in the gate sequence transformed by IBM's simulator. Due to the limitation of space, we just illustrate an example of the target-inspired ansatz for WSP3 in figure 6(c). The structures of target-inspired ansatz for CCNOT and QFT3 can be generated in the same manage.

Figure 6.

Figure 6. The structures of quantum circuits in alternating-pair ansatz with two layers and the target-inspired ansatz. (a) Dressed CNOT; (b) alternating-pair ansatz with two layers; (c) target-inspired ansatz for WSP3.

Standard image High-resolution image

Table 4 shows the cost achieved by alternating-pair ansatz with two layers and the target-inspired ansatz. For WSP3, both alternating-pair ansatz and target-inspired ansatzs can achieve a cost close to 0. However, they use 52 quantum gates while the proposed VQC only needs 7 quantum gates. 25 quantum gates are used to make an exact compilation for CCNOT in the proposed method. Although alternating-pair ansatz uses twice as many quantum gates, i.e., 52 gates, it cannot make an exact compilation. Target-inspired ansatz can achieve a low cost close to zero. However, it uses three times as many gates as the proposed method. Besides, it needs to have knowledge of the gate sequences of the target unitaries transformed by IBM's simulator. For QFT3, 22 quantum gates are used by our method to make an exact compilation, which is much fewer than the other two methods. Alternating-pair ansatz cannot make an exact compilation although it uses 52 quantum gates. The cost achieved by target-inspired ansatz is higher than the proposed method although it uses more than three times as many quantum gates as the proposed method. The simulation results show the importance of the optimization over gate sequence in quantum compiling. The proposed VQC based on reinforcement learning can make an exact compilation with fewer quantum gates, which reduces the errors of quantum algorithm due to decoherence process and gate noise in NISQ devices, and enables quantum algorithms especially for complex algorithms to be executed within coherence time.

Table 4. The cost C(U, V) achieved by the proposed VQC and the structures in [20], i.e., alternating-pair ansatz with two layers and the target-inspired ansatz.

 StructureNumber of gates C(U, V)
WSP3Alternating-pair ansatz521.86 × 10−3
 Target-inspired ansatz528.96 × 10−4
 Proposed VQC70
CCNOTAlternating-pair ansatz521.47 × 10−1
 Target-inspired ansatz782.59 × 10−3
 Proposed VQC252.98 × 10−4
QFT3Alternating-pair ansatz523.88 × 10−2
 Target-inspired ansatz783.03 × 10−3
 Proposed VQC226.30 × 10−4

Figure 7 shows the structures of the quantum circuits generated by our method for the three-qubit unitaries. The depth of the complied circuits for WSP3, QFT3 and CCNOT are 4, 17 and 19, although the numbers of quantum gates in the circuit are 7, 22 and 25. The rotation angles of the quantum gates in these circuits are illustrated in table A2 in appendix A.

Figure 7.

Figure 7. The compiled circuit by VQC based on double Q-learning for the three-qubit unitares, i.e., WSP3, Toffoli gate (CCNOT) and QFT3.

Standard image High-resolution image

4.2.2. Simulation considering the connectivity of qubits

As current available quantum devices do not have completely connected qubits, we also evaluate the performance of the proposed method on the topology of IBM's 5-qubit quantum device, i.e., 'Ibmq_ourense', as shown in figure 8. As WSP3, QFT3 and CCNOT are three-qubit unitaries, we use the first three qubits of 'Ibmq_ourense'. The proposed algorithm can be applied to quantum devices without completely connected qubits by simply removing CNOTi,j gate from the native gate alphabet $\mathcal{A}$ in algorithm 1 if there is no connection between qubit i and qubit j. For 'Ibmq_ourense', the native gate alphabet can be denoted by

Equation (13)

Equation (14)

where ${R}_{z}^{i}$ and ${R}_{y}^{i}$ denote the Rz and Ry gates act on qubit i. CNOTij indicates the CNOT gate acts on qubits i and j where i and j are the control and target qubits, respectively.

Figure 8.

Figure 8. The connectivity of IBM's 5-qubit quantum device, i.e., 'Ibmq_ourense'.

Standard image High-resolution image

Figure 9 shows the result of quantum compiling considering the connectivity of IBM's 5-qubit quantum device. Similar to the completely connected case, the cost C(U, V) decreases with the increasing number of quantum gates in the compiled circuit V and converges to 0 for all the target unitaries. However, more quantum gates are needed in CCNOT and QFT3 as CNOT02 and CNOT20 are not available. For WSP3, the number of quantum gates is the same as the one in the completely connected case as it does not need CNOT02 and CNOT20 (see figure 7).

Figure 9.

Figure 9. The minimum cost achieved by VQC based on double Q-learning for the three-qubit unitaries, considering the connectivity of the IBM's 5-qubit quantum device.

Standard image High-resolution image

4.2.3. Simulation considering the number of CNOT gates

In this section, we decrease the number of CNOT gates by adding a penalty term to the reward function as described in equation (10). The weighted parameter λ is set to be 0.1. We consider the connectivity of qubits on IBM's 5-qubit quantum device. The simulation result in table 5 shows that the penalty term in the reward function can reduce the number of CNOT gates in the circuit. However, more gates are needed to get zero cost.

Table 5. The cost C(U, V), number of CNOT gates and quantum gates of the compiled circuits by the proposed VQC with and without the penalty term on the CNOT gate in the reward function. The simulation considers the connectivity of qubits on IBM's 5-qubit quantum device.

 Reward function C(U, V)Number of CNOT gatesNumber of gates
WSP3Without Cp 2.69 × 10−4 27
 With Cp 6.27 × 10−5 28
CCNOTWithout Cp 9.03 × 10−4 1434
 With Cp 3.52 × 10−5 1235
QFT3Without Cp 8.40 × 10−4 932
 With Cp 6.45 × 10−4 835

4.3. VQC on larger unitaries

In this section, we consider larger unitaries, i.e., 4, 5, 6, 7 and 8 qubits. For larger unitaries, local Hilbert–Schimdt test is used to measure the difference between the target unitary and the designed unitary. We consider the same target unitary as reference [19], i.e.,

Equation (15)

where ${U}_{1}\left( \overrightarrow {\theta }\right)={\bigotimes}_{i=0}^{n-1}{R}_{z}\left({\theta }_{i}\right)$, U2 = ... CNOT23CNOT01, U3 = ... CNOT34CNOT12 and ${U}_{4}\left({ \overrightarrow {\theta }}^{\prime }\right)={\bigotimes}_{i=0}^{n-1}{R}_{z}\left({\theta }_{i}^{\prime }\right)$. CNOTij denotes the CNOT gate where i and j are the control and target qubits, respectively. For large problem sizes, we can add common blocks to the gate alphabet to decrease the computation complexity. This strategy can be regarded as a crossover of variable structure ansatze and fixed-template compiling. It can construct the quantum circuits with some common blocks instead of selecting quantum gate one by one. In this paper, we consider the following blocks:

Equation (16)

We illustrate these blocks on a five-qubit system in figure 10.

Figure 10.

Figure 10. Illustrations of common blocks in five-qubit system.

Standard image High-resolution image

The learning rate α, the discount factor γ and the batch size K are set to 0.2, 1 and 128, respectively. The number of quantum circuits generated at each epsilon is the same as the simulation of three-qubit unitaries. For larger unitaries, local Hilbert–Schimdt test is used to quantify how close the trained unitary is to the target unitary instead of global Hilbert–Schimdt test due to the barren plateau phenomena. Table 6 shows the local cost achieved by the proposed method for 4, 5, 6, 7 and 8-qubit unitaries. By adding common blocks to the candidate gate alphabet, the local cost can converge to 0 for all the target unitaries with 4 to 8 qubits. We also evaluate the global cost C(U, V) with the quantum circuits generated by Clocal(U, V) (i.e., the same circuit with the same gate parameters). The global costs also converge to 0 for all qubits, which indicates exact compilations of the target unitaries.

Table 6. The minimum cost achieved by VQC based on double Q-learning for 4, 5, 6, 7 and 8-qubit unitaries. Clocal(U, V) denotes the local cost between the compiled circuit and the target unitary. C(U, V) is the global cost between the target unitary and the compiled circuit generated by Clocal(U, V) (i.e., the same structure and the same gate parameters).

Number of qubitsNumber of gates Clocal(U, V) C(U, V)
4116.58 × 10−4 9.97 × 10−4
5141.99 × 10−4 9.01 × 10−4
6175.21 × 10−5 1.85 × 10−4
7201.02 × 10−4 2.64 × 10−4
8232.08 × 10−4 5.68 × 10−4

5. Conclusion

Circuit design aims to find a proper structure of quantum circuit, which includes selecting which quantum gates, which qubits they act on and the order of these gates. It largely affects the performance and is crucial in VQC. In this paper, we model the circuit design process as a Markov decision process and design a proper structure of quantum circuit to achieve an exact compilation with double Q-learning. The proposed VQC can automatically generate a high-performance quantum circuit by double Q-learning with epsilon-greedy exploration strategy and experience replay without any human expertise and labor. Another advantage is that the proposed method can minimize the number of quantum gates to achieve an exact compilation, which is especially important for NISQ devices as the algorithm performance degrades with runtime due to decoherence process and gate noise.

Simulation results on two-qubit unitaries (i.e., CZ, CH, CS, XX(3π/2) and QFT2) and three-qubit unitaries (i.e., WSP3, CCNOT and QFT3) show the satisfying performance of the proposed method. Compared to two typical structures in VQC, i.e., alternating-pair ansatz and alternating-pair ansatz, the proposed method can achieve lower cost with much less quantum gates. The proposed method can be easily applied to quantum devices with limited connectivity of qubits. The simulation considering the connectivity of qubits on IBM's quantum device shows that the proposed VQC can make exact compilations of WSP3, CCNOT and QFT3. Considering the low fidelity of two-qubit gates, we motivate the agent to use fewer CNOT gates in the compiled circuit by a penalty term in the reward function. Simulation result shows that it can make an exact compilation with fewer CNOT gates at the cost of more one-qubit gates. Reference [20] provided rigorous theorems stating that the optimal variational parameters in quantum compiling are resilient to various noises such as measurement noise, gate noise and Pauli channel noise. Hence, the proposed method can be practically useful for NISQ devices.

Acknowledgments

This work is supported by Guangdong Basic and Applied Basic Research Foundation (Nos. 2019A1515011166, 2020A1515011204, 2020B1515020050) and the National Natural Science Foundation of China (Nos. 61802061, 61972091, 61772565).

Appendix A.: The values of gate parameters in the compiled quantum circuit

See tables A1 and A2.

Table A1. Rotation angles of the quantum gates with parameters in the compiled quantum circuit for the two-qubit unitares.

 CS θ CH θ CZ θ $XX\left(\frac{3\pi }{2}\right)$ θ QFT2 θ
1 ${R}_{z}^{\left(1\right)}$ 3.9267 ${R}_{z}^{\left(1\right)}$ −3.1420 ${R}_{z}^{\left(1\right)}$ 4.7124 ${R}_{z}^{\left(1\right)}$ −3.1412 ${R}_{z}^{\left(1\right)}$ −2.3562
2 ${R}_{z}^{\left(2\right)}$ 2.3567 ${R}_{z}^{\left(2\right)}$ −3.9270 ${R}_{z}^{\left(2\right)}$ −4.7122 ${R}_{z}^{\left(2\right)}$ 3.1415 ${R}_{z}^{\left(2\right)}$ −4.7124
3 ${R}_{z}^{\left(3\right)}$ 3.9265 ${R}_{z}^{\left(3\right)}$ −5.4981 ${R}_{z}^{\left(3\right)}$ 1.5710   ${R}_{z}^{\left(3\right)}$ 3.9269
4         ${R}_{z}^{\left(4\right)}$ −2.3562
5         ${R}_{z}^{\left(5\right)}$ 1.5708

Table A2. Rotation angles of the quantum gates with parameters in the compiled quantum circuit for the three-qubit unitares.

 WSP3 θ CCNOT θ QFT3 θ
1 ${R}_{z}^{\left(1\right)}$ 0.7854 ${R}_{z}^{\left(1\right)}$ 5.7317 ${R}_{y}^{\left(1\right)}$ 4.6934
2 ${R}_{z}^{\left(2\right)}$ −1.2309 ${R}_{y}^{\left(2\right)}$ 6.1157 ${R}_{y}^{\left(2\right)}$ −0.0376
3 ${R}_{z}^{\left(3\right)}$ 3.1416 ${R}_{z}^{\left(3\right)}$ 6.0494 ${R}_{z}^{\left(3\right)}$ 2.7728
4 ${R}_{z}^{\left(4\right)}$ −0.7854 ${R}_{z}^{\left(4\right)}$ 3.1418 ${R}_{z}^{\left(4\right)}$ 5.8863
5 ${R}_{y}^{\left(5\right)}$ 3.1416 ${R}_{z}^{\left(5\right)}$ −3.6965 ${R}_{z}^{\left(5\right)}$ −3.8488
6   ${R}_{y}^{\left(6\right)}$ 3.1416 ${R}_{z}^{\left(6\right)}$ 0.7768
7   ${R}_{z}^{\left(7\right)}$ −1.8014 ${R}_{y}^{\left(7\right)}$ −1.6191
8   ${R}_{y}^{\left(8\right)}$ −4.8526 ${R}_{z}^{\left(8\right)}$ 1.5786
9   ${R}_{z}^{\left(9\right)}$ −3.9271 ${R}_{z}^{\left(9\right)}$ −1.2562
10   ${R}_{y}^{\left(10\right)}$ −3.1416 ${R}_{y}^{\left(10\right)}$ −2.3667
11   ${R}_{z}^{\left(11\right)}$ 2.3561 ${R}_{y}^{\left(11\right)}$ −4.7129
12   ${R}_{z}^{\left(12\right)}$ 3.9271 ${R}_{z}^{\left(12\right)}$ 5.4917
13   ${R}_{z}^{\left(13\right)}$ −5.4977 ${R}_{y}^{\left(13\right)}$ 6.2535
14   ${R}_{z}^{\left(14\right)}$ 5.4975 ${R}_{y}^{\left(14\right)}$ 5.5126
15   ${R}_{y}^{\left(15\right)}$ 1.6096 ${R}_{z}^{\left(15\right)}$ −4.7659
Please wait… references are loading.