Safe Haskell | None |
---|
Programs.Synthesis.Fowler
Contents
Description
This module implements a variant of Fowler's algorithm for optimally approximating any single-qubit gate by Clifford + T gates with precision δ [Fowler 2010, http://arxiv.org/abs/quant-ph/0411206v2].
This is experimental.
- type Complexnumber = Complex Double
- type Realnumber = Double
- i :: Complexnumber
- s :: Complexnumber
- sqrti :: Complexnumber
- type Matrix = (Complexnumber, Complexnumber, Complexnumber, Complexnumber)
- mult :: Matrix -> Matrix -> Matrix
- adjoint :: Matrix -> Matrix
- trace :: Matrix -> Complexnumber
- identity :: Matrix
- not_gate :: Matrix
- hadamard :: Matrix
- s_gate :: Matrix
- t_gate :: Matrix
- s_mult :: Matrix -> Matrix
- t_mult :: Matrix -> Matrix
- magnitude_squared :: Complexnumber -> Realnumber
- fowler_norm :: Matrix -> Realnumber
- fowler_metric :: Matrix -> Realnumber
- fowler_norm_of_metric :: Realnumber -> Realnumber
- euclid_norm :: Matrix -> Realnumber
- dist_of_norm :: (Matrix -> Realnumber) -> Matrix -> Matrix -> Realnumber
- fowler_dist :: Matrix -> Matrix -> Realnumber
- euclid_dist :: Matrix -> Matrix -> Realnumber
- data Gate
- data Axis
- data Flip
- data Turn
- type Clifford = (Axis, Flip, Turn)
- clifford_id :: Clifford
- data CAxis
- data CliffordT
- data NormalForm
- class Gatelist a where
- nf_len :: NormalForm -> Int
- ct_len :: CliffordT -> Int
- matrix_of_gate :: Gate -> Matrix
- matrix_of_gatelist :: [Gate] -> Matrix
- to_matrix :: Gatelist a => a -> Matrix
- nf_matrix_gen :: Matrix -> [(NormalForm, Matrix, Int)]
- nf_length :: Matrix -> Int -> [(NormalForm, Matrix, Int)] -> [(NormalForm, Matrix, Int)]
- approximate :: (Matrix -> Realnumber) -> Matrix -> [(Matrix, NormalForm, Int, Int, Realnumber)]
- some_gate :: Matrix
- random_gate :: IO Matrix
- zrot_gate :: Realnumber -> Matrix
- phase_gate :: Int -> Matrix
- print_list :: (a -> String) -> [a] -> IO ()
- main :: IO ()
- parse_args :: [String] -> IO Matrix
Overview
We use an exhaustive enumeration of all shortest circuits of a certain length. We use the result by [Matsumoto and Amano 2008, http://arxiv.org/abs/0806.3834v1] (rather than the older Fowler method) to avoid duplicate enumeration. By Matsumoto and Amano's result, each operator can be uniquely written in the form
BTATATA...TATC,
where:
- A is H or SH,
- B is I or H or SH,
- C is any Clifford gate, or more precisely: C = BDEF,
- D is I or X,
- E is I or S or S2 or S3, and
- F is a global phase in {1, z, z2, z3, z4, z5, z6, z7}, where z = eiπ/4.
Since a global phase doesn't matter, we only need to consider the 24 Clifford gates of the form BDE, and this way each operator has a unique representation up to global phase.
Scalars
type Complexnumber = Complex DoubleSource
A type to represent complex numbers.
type Realnumber = DoubleSource
A type to represent real numbers.
The imaginary unit.
The square root of 2.
The square root of i.
Basic matrix operations
type Matrix = (Complexnumber, Complexnumber, Complexnumber, Complexnumber)Source
The type of 2×2-matrices of complex numbers. The elements are listed by rows.
trace :: Matrix -> ComplexnumberSource
Take the trace of a matrix.
Specific matrices
Norms and distance
magnitude_squared :: Complexnumber -> RealnumberSource
Calculate the square of the magnitude of a complex number.
fowler_norm :: Matrix -> RealnumberSource
Calculate the Fowler-norm of a unitary matrix A, defined as
norm(A) = sqrt(1 - |tr A| / n),
where n is the dimension. Note: this norm is with respect to the group structure, i.e., it satisfies norm(I) = 0, and the triangle inequality norm(AB) ≤ norm(A) + norm(B), and norm(A⁻¹) = norm(A). It is invariant under global phase, i.e., norm(A)=norm(kA) if k is a complex unit. It is also invariant under basis change.
In case n=2, the Fowler norm is actually the same as the operator norm (up to a factor of √2), although this is not mentioned in Fowler's paper. More precisely, recall that the operator norm of a diagonalizable matrix A is given by the magnitude of the largest eigenvalue. For a matrix A and phase k, consider the operator norm of kA-I, and minimize this over all possible k. The result, for diagonalizable A, is:
min {operator-norm(kA-I) | |k|=1} = sqrt(2 - |tr A|),
which is exactly the same as the Fowler norm multiplied by √2. This is important because presumably the "relevant" notion of distance in quantum computing is distance in the operator norm up to a global phase.
fowler_metric :: Matrix -> RealnumberSource
Note that minimizing the Fowler-norm is the same as minimizing −|tr A|2; the latter requires two fewer square roots to be computed. Therefore, we provide this function for efficiency reasons.
fowler_norm_of_metric :: Realnumber -> RealnumberSource
Convert the Fowler metric to the Fowler norm.
euclid_norm :: Matrix -> RealnumberSource
Calculate the Euclidean norm of a 2×2 unitary matrix A, modulo global phase, defined to be the minimum of |A−kI|, where k is a unit scalar. It can be defined by:
norm(A) = sqrt(2 + tr AA+ - 2 |tr A|)
Note: this norm is with respect to the group structure, i.e., it satisfies norm(I) = 0, and the triangle inequality norm(AB) ≤ norm(A) + norm(B), and norm(A⁻¹) = norm(A). It is invariant under global phase, i.e., norm(A)=norm(kA) if k is a complex unit. It is also invariant under basis change.
dist_of_norm :: (Matrix -> Realnumber) -> Matrix -> Matrix -> RealnumberSource
Turn a norm into a distance function, defined by
dist(A,B) = norm(A B+)
fowler_dist :: Matrix -> Matrix -> RealnumberSource
Calculate the Fowler distance.
euclid_dist :: Matrix -> Matrix -> RealnumberSource
Calculate the Euclidean distance.
Representation of {X, H, S, T} circuits
A type to represent symbolic basis gates (X, H, S, T).
Representation of normal forms
type Clifford = (Axis, Flip, Turn)Source
Each of the 24 Clifford gates (modulo global phase) can be uniquely specified as a turn followed by a flip and an axis.
The identity Clifford gate.
An element of the Clifford + T group whose normal form does not end in T. It consists of a clifford circuit, followed by 0 or more gates of the form HT or SHT.
data NormalForm Source
An element of the Clifford + T group in normal form. This
consists of a CliffordT
, followed by an optional T.
Instances
Class of things that can be converted to a gate list.
nf_len :: NormalForm -> IntSource
Compute the length of a normal form.
Mapping circuits to unitary matrices
matrix_of_gate :: Gate -> MatrixSource
Assign a unitary matrix to a gate.
matrix_of_gatelist :: [Gate] -> MatrixSource
Assign a unitary matrix to a gate list.
More memory-efficient enumeration
nf_matrix_gen :: Matrix -> [(NormalForm, Matrix, Int)]Source
Uniquely enumerate all normal forms. Return an infinite list of triples (nf, m, n), where nf is a normal form, m is the product of the normal form's matrix and m0, and n is the size of the normal form. The list is ordered by increasing n. We use an iterated depth-first enumeration with logarithmic memory usage.
nf_length :: Matrix -> Int -> [(NormalForm, Matrix, Int)] -> [(NormalForm, Matrix, Int)]Source
Enumerate all normal forms of size len, followed by tail. This function is productive, i.e., the resulting list is lazy with no storage.
Finding best approximations
approximate :: (Matrix -> Realnumber) -> Matrix -> [(Matrix, NormalForm, Int, Int, Realnumber)]Source
Given a norm and a matrix, find the successively best approximation for each length. Return an infinite list of quadruples (m, nf, len, n, δ). Here nf is the normal form, m is its matrix, len is the actual length of the normal form, n is the length for which the normal form is optimal, and δ is the distance.
Some gates to approximate
random_gate :: IO MatrixSource
Return a random unitary matrix (Haar measure).
zrot_gate :: Realnumber -> MatrixSource
Return a Z-rotation by angle alpha.
phase_gate :: Int -> MatrixSource
Return a phase rotation gate with phase eiπ / 2d.
User interface
print_list :: (a -> String) -> [a] -> IO ()Source
A convenience function for printing a list, one element per line.