- Compilation/
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 CNOTs | condition | check |
---|---|---|
0 | χ[γ(U)](x)=(x±1)4 | tr(γ(U))=±4 |
1 | χ[γ(U)](x)=(x+i)2(x−i)2 | tr(γ(U))=0 and γ(U)2+I=0 |
2 | χ[γ(U)](x) has real coefficients | tr(γ(U)) is real |
3 | otherwise | - |
Here χ[U](x)=det(xI−U) in the table is the characteristic polynomial with scalar variable x. The polynomial's roots λi (as defined by χ[U](λi)=0) are the eigenvalues of U. γ(U)=U(Y⊗Y)UT(Y⊗Y) is a simpler Makhlin invariant introduced by the authors in [1] and [2].
This invariant has the special property that γ(U)=γ(V) if and only if U and V are equivalent up to local SU(2) unitaries from the right (see Proposition IV.3 in [1]). This means that
where G=SU(2)⊗SU(2) and the multiplication of a matrix with a group is defined as UG={Ug∣g∈G }. For example, for the two-qubit case, there exist matrices u0⊗u1 and v0⊗v1 such that U(u0⊗u1)=V(v0⊗v1).
Another property of this invariant is that χ[γ(U)]=χ[γ(V)] if and only if U and V are equivalent up to local SU(2) unitaries from the left and right, i.e.,
In the algorithm to synthesize the optimal two-qubit unitary we are going to compute E†γ(U)E=(E†UE)(E†UE)T, an equivalent invariant to γ(U) (also shown in Proposition IV.3 in [1]). E is a so-called magic basis that transforms A∈SO(4) such that EAE†∈SU(2)⊗SU(2). In qml.ops.two_qubit_decomposition, we define it as
Note that E above has the nice property that EET=−Y⊗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=(E†UE)(E†UE)T instead of γ(U) due to their equivalence.
Optimal formulae
0 CNOTs
In this case we have U=A⊗B with both A,B∈SU(2) and we find the following simple circuit structure.
-A-
-B-
We can compute the coefficients of the matrices A and B analytically by the following formula. First, we write
in terms of its four 2×2 Ci block matrices. We further define
that fulfills ∣a1∣2+∣a2∣2=1. Using the Kronecker product definition,
we can identify C1C4†=a12 and −C2C3†=a2, which yield a1 and a2 up to a sign that can be further resolved using C1C2†=a1a2∗. Now that we have A, we can compute B using B=C1/a1 or B=C2/a2, depending on whether a1 or a2 are non-zero.
To obtain the final circuit decomposition, we use qml.ops.one_qubit_decomposition on A and B.
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,D such that U=(A⊗B)CNOT01(C⊗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 U such that U=(A⊗B)V(C⊗D) for some known unitary matrix V. This can be mapped back to the original problem by considering V to be a single CNOT gate.
The equation U=(A⊗B)V(C⊗D) is fulfilled if and only if χ[γ(U)]≡χ[γ(V)]. This invariant equation is equivalently satisfied when we substitute γ(U)→E†UE=:u and γ(V)→E†VE=:v. Note that E†γ(U)E=uuT so we have χ[uuT]≡χ[vvT]. Given that their characteristic polynomials are equivalent, their eigenvalues must also be the same. Further, uuT and vvT can be diagonalized with orthogonal eigenvectors; i.e., uuT=aTDλa and vvT=bTDλb. Here, a and b are orthogonal, i.e. a,b∈SO(4), whereas u and v are unitary. Assuming the eigenvalues in the diagonal matrix Dλ are ordered in the same way (which can always be achieved by commuting rows and columns), we obtain,
In the 1 CNOT case, V=CNOT, so the latter diagonalization can be hard-coded.
Solving this equation for u and using the fact that (v†bTau)(v†bTau)T=1⇔vTbTau∗=v†bTau then leads to
where we can identify the desired results
We then use the same process as for the 0 CNOT case above to obtain A,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,D will be similar to the previous case, but now with V=CNOT10(a⊗b)CNOT10 instead of a single CNOT gate. Since X commutes with the target of a CNOT gate, and Z with the control, we can cleverly choose a parameterization a=RX(⋅)RZ(α)RX(⋅) and b=RZ(⋅)RX(β)RZ(⋅). This enables us to move the RX and RZ through the controls and targets. This leaves us with
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 U, up to local gates. In particular, we look for A,B,C,D∈SU(2) such that U=(C⊗D)V(A⊗B). The characteristic polynomial of this circuit is
We can thus compute the eigenvalues of uuT again with u=E†UE, identifying λ1=α+β and λ2=α−β. Here, λi are the two phases of the eigenvalues of uuT, which can be read out from its characteristic polynomial. This then yields
There is a special case where the two unique eigenvalues are 1 and −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(β))CNOT10.
3 CNOT
The case with 3 CNOTs is derived similarly to the 2-CNOT case, but with the following middle part
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
where x,y,z are the phases of the eigenvalues of uuT.