Professional Documents
Culture Documents
net/publication/334615236
CITATIONS READS
0 2,009
1 author:
Dmytro Fedoriaka
Google Inc.
3 PUBLICATIONS 0 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Dmytro Fedoriaka on 22 July 2019.
Dmytro Fedoriaka
(Dated: June 19, 2019)
Algorithm is proposed to convert arbitrary unitary matrix to a sequence of X gates and fully
controlled Ry , Rz and R1 gates. This algorithm is used to generate Q# implementation for arbitrary
unitary matrix. Some optimizations are considered and complexity of result is analyzed.
If i is index of state, i[j] is j-th bit of this index (i.e. where |ai - basis state of target qubits t0 , . . . tT −1 , |bi -
j-th character in binary string representing i). basis state of control qubits c0 , . . . cC−1 , U ∈ U(2T ). In
2
other words, it applies U on target bits only if all control Let’s demand that tan θ is real and positive. Then:
qubits are set to |1i .
Matrix of a controlled gate has special form. It’s an b
θ = arctan , (10)
identity matrix 2C+T ×2C+T , where lower right submatrix a
2T ×2T is replaced by U . If T = 1, this matrix is two-level
unitary.
b
arg − exp(−i(λ + µ)) = π+arg(b)−arg(a)−λ−µ = 0
We will denote I — unitary matrix; X = ( 01 10 ) — Pauli a
X matrix, also known as X gate or NOT gate. (11)
Expression a ⊕ b means bitwise addition modulo 2 (also From (11) we can express µ:
known as XOR), e.g. 25 ⊕ 13 = 20.
Let’s denote U1 , U2 , . . . UD — all matrices which we other qubits in the register. This gate will act on certain
applied during this algorithm and Uf - final two-level basis state only if all bits in index of this state (except
matrix we got. Then the whole process can be written as maybe i-th) are set to one. For example, if n = 5, FC
gate U acting on bit 1 applies matrix U to states |10111i
and |11111i.
A · U1 · U2 . . . UD = Uf , (17)
By convention, FC gate acting on single qubit is just
from which follows simple one-qubit gate without control qubits.
FC gate applies a two-level unitary matrix. But also
† † any two-level unitary matrix (acting on states differing in
A = Uf · UD · UD−1 . . . U1† . (18) one bit) can be implemented with a fully controlled gate
Equation (18) gives desired decomposition of A into and possibly some single-qubit X gates. Let’s show how.
2-level unitary matrices. This decomposition has d(d−1) Let U be two-level unitary acting matrix on states
matrices. Indeed, each matrix in decomposition (includ-
2 (i, i ⊕ 2r ). Let J0 — set of all indices j, such that j-th
ing Uf ) corresponds to one eliminated element in upper bit of i is zero, J1 — set of all indices j, such that j-th
bit of i is one (both sets don’t include r). Then we need
triangular part of matrix A, and there are d(d−1)2 such to apply this two-level unitary only to pair of such states,
elements. whose indices have zeroes on positions J0 , and ones on
All matrices in decomposition are special unitary, with positions J1 . If J0 = ∅, this is simply fully-controlled gate
two exceptions. First, if we were swapping columns due to on qubit r.
a being zero, we will have two-level X matrices. Second,
But if there is some j ∈ J0 , then we have to just apply
if det(A) 6= 1, matrix Uf will not be special unitary.
X on j-th qubit, then apply U and then apply X on j-th
qubit again.
B. Gray codes This will work because X acting on j-th qubit swaps
state i with state i ⊕ 2j , so if U does something only with
states i where i[j] = 1, then XU X does the same thing
Now all two-level matrices in decomposition act on pair
with states i where i[j] = 0.
of states (i, i + 1). For our purposes we want them to act
on pairs of states differing only in one bit, i.e. (i, i ⊕ 2k ). So, to implement two-level unitary matrix we have to
Luckily, for any positive integer n exists such permuta- apply X gate to all qubits from J0 , then apply fully-
tion of numbers 0, 1, . . . , 2n − 1, that any two neighboring controlled gate on qubit r and then again apply X gate
numbers in it differ only in one bit. Such permutation to all qubits from J0 .
is called binary-reflected Gray code [5], and is given by Let’s consider an example. Let n = 5 and we want
formula to apply two-level unitary matrix with non-trivial 2 × 2
submatrix U acting on states |10100i and |10110i. Then
r = 3, J0 = {1, 4} and J1 = {0, 2}. So, we need to build
πi = i ⊕ bi/2c , (19) the following circuit:
where i = 0, 1, . . . , 2n − 1.
For example, Gray code for n = 3 is (0, 1, 3, 2, 6, 7, 5, 4). •
Let’s consider matrix P ∈ U(2n ), such that Pij = δi,πj . •
This is permutation matrix, i.e. its action on a vector •
is permuting elements of that vector with permutation U
π. Then expression P † A0 P simultaneously permutes rows •
and columns of matrix A0 with permutation π. If A0
was a two-level matrix acting on states (i, i + 1), then
A = P † A0 P will be two-level matrix acting on states
D. Implementing a single gate
(πi , πi+1 ) — exactly what we need.
So, we need to apply two-level decomposition algorithm
to matrix A0 = P AP Q †
and get decomposition A0 = i A0i .
Q
At this point we have sequence of X gates and FC gates
Then A = P † A0 P = i (P † A0i P ). So, we have decomposi- acting on single qubit, but each such gate is represented
tion of A into two-level unitary matrices acting on states by arbitrary U ∈ U(2). We have to decompose U into
differing in one bit. product of matrices, which can be implemented by gates.
Similar technique is used in [6]. In this paper I will consider how to decompose them into
R1 , Ry and Rz gates, which are defined as:
V. DISCUSSION
Table I. Number of gates in decomposition of random matrices
n #(X) #(Ry ) #(Rz ) #(R1 ) G(n) G(n)/4n A. Further decomposition
1 0 1 2 1 4 1.00
2 2 6 12 1 21 1.31 In this paper we consider fully controlled Ry , Rz and
R1 gates as primitives, because they are supported by Q#
3 28 28 56 1 113 1.77 language. However, two-level matrix can be decomposed
4 130 120 240 1 491 1.92 into sequence of simpler gates, namely Ry , Rz and R1
gates acting on single qubit and CNOT (controlled-X)
5 532 496 992 1 2021 1.97
gate (acting on two qubits), and decomposition of a single
6 2118 2016 4032 1 8167 1.99 two-level matrix will contain Θ(n2 ) such gates. How to
7 8392 8128 16256 1 32777 2.00
do that is shown in [3, §4.6].