The Quipper System

Safe HaskellNone

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.

Synopsis

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.

i :: ComplexnumberSource

The imaginary unit.

s :: ComplexnumberSource

The square root of 2.

sqrti :: ComplexnumberSource

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.

mult :: Matrix -> Matrix -> MatrixSource

Multiply two matrices.

adjoint :: Matrix -> MatrixSource

Take the adjoint of a matrix.

trace :: Matrix -> ComplexnumberSource

Take the trace of a matrix.

Specific matrices

identity :: MatrixSource

The identity matrix.

not_gate :: MatrixSource

The Pauli X operator (not-gate).

hadamard :: MatrixSource

The Hadamard gate H.

s_gate :: MatrixSource

The Phase gate S.

t_gate :: MatrixSource

The T-gate.

s_mult :: Matrix -> MatrixSource

Faster version of mult s_gate.

t_mult :: Matrix -> MatrixSource

Faster version of mult t_gate.

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 |AkI|, 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

data Gate Source

A type to represent symbolic basis gates (X, H, S, T).

Constructors

X 
H 
S 
T 

Instances

Representation of normal forms

data Axis Source

An axis: I, H, or SH.

Constructors

R_I 
R_H 
R_SH 

Instances

data Flip Source

A flip: I or X.

Constructors

F_I 
F_X 

Instances

data Turn Source

A turn: I, S, SS, SSS.

Constructors

T_I 
T_S 
T_SS 
T_SSS 

Instances

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.

clifford_id :: CliffordSource

The identity Clifford gate.

data CAxis Source

An axis change: H or SH.

Constructors

N_H 
N_SH 

Instances

data CliffordT Source

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.

Instances

data NormalForm Source

An element of the Clifford + T group in normal form. This consists of a CliffordT, followed by an optional T.

Constructors

NF_T CliffordT 
NF CliffordT 

class Gatelist a whereSource

Class of things that can be converted to a gate list.

Methods

to_gates :: a -> [Gate]Source

nf_len :: NormalForm -> IntSource

Compute the length of a normal form.

ct_len :: CliffordT -> IntSource

Compute the length of a normal form not ending in T.

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.

to_matrix :: Gatelist a => a -> MatrixSource

Convert a circuit representation to a matrix

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

some_gate :: MatrixSource

Some arbitrary unitary matrix for testing.

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.

main :: IO ()Source

The main function.

parse_args :: [String] -> IO MatrixSource

Parse the command line arguments. Possible arguments are:

  • random_gate - approximate a random gate.
  • zrot_gate double - approximate a Z-rotation by angle alpha.
  • phase_gate int - approximate a Z-rotation gate with angle eiπ / 2d.