1. Compilation/
  2. Two-qubit Synthesis

Two-qubit Synthesis

Determine the required number of CNOT

A full recipe for determining the number of necessary CNOT gates in a two-qubit gate decomposition is presented in [2]. The results are summarized in the following table. The column "condition" refers to the mathematical condition for the case, whereas "check" refers to what is checked in practice.

# of CNOTsconditioncheck
0χ[γ(U)](x)=(x±1)4\chi[\gamma(U)](x) = (x \pm 1)^4tr(γ(U))=±4\text{tr}(\gamma(U)) = \pm 4
1χ[γ(U)](x)=(x+i)2(xi)2\chi[\gamma(U)](x) = (x+i)^2 (x-i)^2tr(γ(U))=0\text{tr}(\gamma(U)) = 0 and γ(U)2+I=0\gamma(U)^2 + \mathbb{I} = 0
χ[γ(U)](x)\chi[\gamma(U)](x) has real coefficientstr(γ(U))\text{tr}(\gamma(U)) is real
3otherwise-

Here χ[U](x)=det(xIU)\chi[U](x) = \det\left(x \mathbb{I} - U \right) in the table is the characteristic polynomial with scalar variable xx. The polynomial's roots λi\lambda_i (as defined by χ[U](λi)=0\chi[U](\lambda_i) = 0) are the eigenvalues of UU. γ(U)=U(YY)UT(YY)\gamma(U) = U (Y\otimes Y) U^T (Y\otimes Y) is a simpler Makhlin invariant introduced by the authors in [1] and [2].

This invariant has the special property that γ(U)=γ(V)\gamma(U) = \gamma(V) if and only if UU and VV are equivalent up to local SU(2)\text{SU}(2) unitaries from the right (see Proposition IV.3 in [1]). This means that

γ(U)=γ(V)UG=VG,\gamma(U) = \gamma(V) \Leftrightarrow U G = V G,

where G=SU(2)SU(2)G = \text{SU}(2) \otimes \text{SU}(2) and the multiplication of a matrix with a group is defined as UG={UggG }U G = \{ U g | g \in G \}. For example, for the two-qubit case, there exist matrices u0u1u_0 \otimes u_1 and v0v1v_0 \otimes v_1 such that U(u0u1)=V(v0v1)U (u_0 \otimes u_1) = V (v_0 \otimes v_1).

Another property of this invariant is that χ[γ(U)]=χ[γ(V)]\chi[\gamma(U)] = \chi[\gamma(V)] if and only if UU and VV are equivalent up to local SU(2)\text{SU}(2) unitaries from the left and right, i.e.,

χ[γ(U)]=χ[γ(V)]GUG=GVG.\chi[\gamma(U)] = \chi[\gamma(V)] \Leftrightarrow G U G = G V G.

In the algorithm to synthesize the optimal two-qubit unitary we are going to compute Eγ(U)E=(EUE)(EUE)T,E^\dagger \gamma(U) E = (E^\dagger U E) (E^\dagger U E)^T, an equivalent invariant to γ(U)\gamma(U) (also shown in Proposition IV.3 in [1]). EE is a so-called magic basis that transforms ASO(4)A \in \text{SO}(4) such that EAESU(2)SU(2)E A E^{\dagger} \in \text{SU}(2) \otimes \text{SU}(2). In qml.ops.two_qubit_decomposition, we define it as

E=12(1i0000i100i11i00).E = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & i & 0 & 0 \\ 0 & 0 & i & 1 \\ 0 & 0 & i & -1 \\ 1 & -i & 0 & 0 \end{pmatrix}.

Note that EE above has the nice property that EET=YY,E E^T = - Y \otimes Y, which reinforces the connection to the Makhlin invariant defined earlier.

To save some computation, we can perform the checks in the table above with Eγ(U)E=(EUE)(EUE)TE^\dagger \gamma(U) E = (E^\dagger U E) (E^\dagger U E)^T instead of γ(U)\gamma(U) due to their equivalence.

Optimal formulae

0 CNOTs

In this case we have U=ABU = A \otimes B with both A,BSU(2)A, B \in \text{SU}(2) and we find the following simple circuit structure.

-A- -B-

We can compute the coefficients of the matrices AA and BB analytically by the following formula. First, we write

U=(C1C2C3C4)U = \begin{pmatrix} C_1 & C_2 \\ C_3 & C_4 \end{pmatrix}

in terms of its four 2×22 \times 2 CiC_i block matrices. We further define

A=(a1a2a2a1)A = \begin{pmatrix} a_1 & a_2 \\ -a^*_2 & a^*_1 \end{pmatrix}

that fulfills a12+a22=1|a_1|^2 + |a_2|^2 = 1. Using the Kronecker product definition,

AB=(a1Ba2Ba2Ba1B)=(C1C2C3C4),A \otimes B = \begin{pmatrix} a_1 B & a_2 B \\ -a^*_2 B & a^*_1 B \end{pmatrix} = \begin{pmatrix} C_1 & C_2 \\ C_3 & C_4 \end{pmatrix},

we can identify C1C4=a12C_1 C_4^\dagger = a_1^2 and C2C3=a2-C_2 C_3^\dagger = a_2, which yield a1a_1 and a2a_2 up to a sign that can be further resolved using C1C2=a1a2C_1 C_2^\dagger = a_1 a_2^*. Now that we have AA, we can compute BB using B=C1/a1B = C_1 / a_1 or B=C2/a2B = C_2/a_2, depending on whether a1a_1 or a2a_2 are non-zero.

To obtain the final circuit decomposition, we use qml.ops.one_qubit_decomposition on AA and BB.

1 CNOT

A general circuit ansatz requiring one CNOT is given by the following.

-C--╭●--A- -D--╰X--B-

In other words, we need to find A,B,C,DA, B, C, D such that U=(AB)CNOT01(CD)U = (A \otimes B) \text{CNOT}_{0 1} (C \otimes D). The following subroutine will be reused for the cases of 1 and 2 CNOTs below, but exchanging the singular CNOT operator for other ansätze. Let us first consider a more general case of finding UU such that U=(AB)V(CD)U = (A \otimes B) V (C \otimes D) for some known unitary matrix VV. This can be mapped back to the original problem by considering VV to be a single CNOT gate.

The equation U=(AB)V(CD)U = (A \otimes B) V (C \otimes D) is fulfilled if and only if χ[γ(U)]χ[γ(V)]\chi[\gamma(U)] \equiv \chi[\gamma(V)]. This invariant equation is equivalently satisfied when we substitute γ(U)EUE=:u\gamma(U) \rightarrow E^\dagger U E =: u and γ(V)EVE=:v.\gamma(V) \rightarrow E^\dagger V E =: v. Note that Eγ(U)E=uuTE^\dagger \gamma(U) E = u u^T so we have χ[uuT]χ[vvT]\chi[u u^T] \equiv \chi[v v^T]. Given that their characteristic polynomials are equivalent, their eigenvalues must also be the same. Further, uuTu u^T and vvTv v^T can be diagonalized with orthogonal eigenvectors; i.e., uuT=aTDλau u^T = a^T D_\lambda a and vvT=bTDλbv v^T = b^T D_\lambda b. Here, aa and bb are orthogonal, i.e. a,bSO(4)a, b \in \text{SO}(4), whereas uu and vv are unitary. Assuming the eigenvalues in the diagonal matrix DλD_\lambda are ordered in the same way (which can always be achieved by commuting rows and columns), we obtain,

auuTaT=bvvTbT.a u u^T a^T = b v v^T b^T.

In the 1 CNOT case, V=CNOT,V = \text{CNOT}, so the latter diagonalization can be hard-coded.

Solving this equation for uu and using the fact that (vbTau)(vbTau)T=1vTbTau=vbTau(v^\dagger b^T a u) (v^\dagger b^T a u)^T = 1 \Leftrightarrow v^T b^T a u^* = v^\dagger b^T a u then leads to

u=(aTb)v(vTbTau)=(aTb)v(vbTau),u = \left(a^T b \right) v \left(v^T b^T a u^* \right) = \left(a^T b \right) v \left(v^\dagger b^T a u \right),

where we can identify the desired results

AB=(aTb) ;  CD=(vbTau).A \otimes B = \left(a^T b \right) \text{ ; } \ C \otimes D = \left(v^\dagger b^T a u \right).

We then use the same process as for the 0 CNOT case above to obtain A,B,C,DA, B, C, D.

2 CNOT

A general circuit ansatz requiring two CNOTs is given by the following.

-A--╭X--RZ(d)--╭X--C- -B--╰●--RX(p)--╰●--D-

The procedure for determining A,B,C,DA, B, C, D will be similar to the previous case, but now with V=CNOT10(ab)CNOT10V = \text{CNOT}_{10} (a \otimes b) \text{CNOT}_{10} instead of a single CNOT gate. Since XX commutes with the target of a CNOT gate, and ZZ with the control, we can cleverly choose a parameterization a=RX()RZ(α)RX()a = R_X(\cdot) R_Z(\alpha) R_X(\cdot) and b=RZ()RX(β)RZ()b = R_Z(\cdot) R_X(\beta) R_Z(\cdot). This enables us to move the RXR_X and RZR_Z through the controls and targets. This leaves us with

V=CNOT10(RZ(α)RX(β))CNOT10.V = \text{CNOT}_{10} (R_Z(\alpha) \otimes R_X(\beta)) \text{CNOT}_{10}.

We now find ourselves in a similar situation as in the 1-CNOT case, wherein we need this circuit to be equivalent to the target unitary UU, up to local gates. In particular, we look for A,B,C,DSU(2)A, B, C, D \in SU(2) such that U=(CD)V(AB)U = (C \otimes D) V (A \otimes B). The characteristic polynomial of this circuit is

χ[γ(V)](x)=(xei(α+β))(xei(α+β))(xei(αβ))(xei(αβ)).\chi\left[\gamma\left(V\right)\right](x) = (x - e^{i (\alpha + \beta)}) (x - e^{-i (\alpha + \beta)}) (x - e^{i (\alpha - \beta)}) (x - e^{-i (\alpha - \beta)}).

We can thus compute the eigenvalues of uuTu u^T again with u=EUE,u = E^\dagger U E, identifying λ1=α+β\lambda_1 = \alpha + \beta and λ2=αβ.\lambda_2 = \alpha - \beta. Here, λi\lambda_i are the two phases of the eigenvalues of uuTu u^T, which can be read out from its characteristic polynomial. This then yields

α=(λ1+λ2)/2 and β=(λ1λ2)/2.\alpha = (\lambda_1 + \lambda_2)/2 \text{ and } \beta = (\lambda_1 - \lambda_2)/2.

There is a special case where the two unique eigenvalues are 11 and 1-1. In such case, we get the following.

-╭U- = -A--╭X--SZ--╭X--C- = -A--╭●--╭X--C- -╰U- = -B--╰●--SX--╰●--D- = -B--╰X--╰●--D-

The final procedure is now the same as in the case with 1 CNOT, but with the new V=CNOT10(RZ(α)RX(β))CNOT10V = \text{CNOT}_{10} (R_Z(\alpha) \otimes R_X(\beta)) \text{CNOT}_{10}.

3 CNOT

The case with 3 CNOTs is derived similarly to the 2-CNOT case, but with the following middle part

V=CNOT10(IRY(α))CNOT01(RZ(δ)RY(β))CNOT10.V = \text{CNOT}_{10} (\mathbb{I} \otimes R_Y(\alpha)) \text{CNOT}_{01} (R_Z(\delta) \otimes R_Y(\beta)) \text{CNOT}_{10}.

The circuit is the following:

-╭U- = -C--╭X--RZ(d)--╭●---------╭X--A- -╰U- = -D--╰●--RY(b)--╰X--RY(a)--╰●--B-

Similar to the 2 CNOT case, the angles are given by

α=x+y2; β=x+z2; δ=z+y2,\alpha = \frac{x + y}{2} ; \ \beta = \frac{x + z}{2} ; \ \delta = \frac{z + y}{2},

where x,y,zx, y, z are the phases of the eigenvalues of uuTu u^T.