The Quipper System

Safe HaskellNone

Algorithms.TF.Definitions

Contents

Description

This module provides global definitions for the Triangle Finding Algorithm.

Synopsis

Qram abstraction

data Qram Source

A data structure to hold a Qram implementation. This provides operations for fetching and storing quantum data from a quantum array, addressed by a quantum integer. One implementation is given by algorithms a8_FetchT, a9_StoreT and a10_FetchStoreT.

Constructors

Qram 

Fields

qram_fetch :: QData qa => QDInt -> IntMap qa -> qa -> Circ (QDInt, IntMap qa, qa)
 
qram_store :: QData qa => QDInt -> IntMap qa -> qa -> Circ (QDInt, IntMap qa, qa)
 
qram_swap :: QData qa => QDInt -> IntMap qa -> qa -> Circ (QDInt, IntMap qa, qa)
 

Types for the Triangle Finding Algorithm

type CNode = [Bit]Source

A node of the graph (classical circuit type).

type QNode = [Qubit]Source

A node of the graph (quantum circuit type).

type QWTFP_spec = (Int, Int, QNode -> QNode -> Qubit -> Circ Qubit, Qram)Source

The type of problem specifications for the Triangle Finding Problem. A problem specification consists of:

  • an integer n which determines the number N=2n of nodes of the graph,
  • an integer r which determines the size R=2r of tuples in the Hamming graph,
  • a function edge_oracle which inputs two graph nodes and a qubit and flips the qubit if the nodes are connected by an edge and
  • additional options, for selecting, e.g., which qRAM implementation should be used.

TF integers

Types

We define a QData family of integer datatypes (QIntTF, CIntTF, IntTF). These are similar to (QDInt, CInt, IntM), except that the integers are considered to be mod 2m-1 instead of 2m.

In general, functions on these types should be able to handle both 00…00 and 11…11, and should treat them equally, essentially regarding IntTF, CIntTF, and the computational basis of QIntTF as formal quotients. Some operations are not perfect. One should keep in mind, for example, that specifying a control on a QIntTF of the form q .==. 0 will compare the bitwise representation to 0, and not the logical quotient.

data XIntTF x Source

All three types QIntTF, CIntTF, and IntTF are special cases of a more general type XIntTF x, parameterized by a type x of bits. It is an abstract type, and details of its implementation is not exposed to user-level code.

Constructors

XIntTF (XInt x) 

type QIntTF = XIntTF QubitSource

The type of fixed-length m-qubit quantum integers, regarded modulo 2m-1.

type CIntTF = XIntTF BitSource

The type of fixed-length m-bit classical integers, regarded modulo 2m-1.

type IntTF = XIntTF BoolSource

The type of fixed-length m-bit integer parameters, regarded modulo 2m-1. A value of type IntTF may have indeterminate length, similarly to IntM.

Operations for IntTF

integer_of_inttf :: IntTF -> IntegerSource

Convert an IntTF of length m to an Integer in the range {0, …, 2m-2}. If the IntTF has indeterminate length, return the original Integer.

inttf_of_integer :: Integer -> IntTFSource

Convert an Integer to an IntTF of indeterminate length.

inttf :: Int -> Integer -> IntTFSource

Convert an Integer to an IntTF of length m.

inttf_length :: IntTF -> Maybe IntSource

Return the length of an IntTF, or Nothing if indeterminate.

inttf_set_length :: Int -> IntTF -> String -> IntTFSource

Set the length of an IntTF to m ≥ 0. This operation is only legal if the input (a) has indeterminate length or (b) has determinate length already equal to m. In particular, it cannot be used to change the length from anything other than from indeterminate to determinate.

If both arguments already have determinate lengths, and they do not coincide, throw an error. The String argument is used as an error message in that case.

inttf_promote :: IntTF -> XIntTF x -> String -> IntTFSource

Try to set the length of an IntTF to that of another XIntTF value (which could be a QIntTF, a CIntTF, or another IntTF). This will fail with an error if both numbers already have determinate lengths that don't coincide. In this case, the string argument is used as an error message. The promotion is done modulo 2m-1.

show_inttf :: IntTF -> StringSource

Convert an IntTF to human readable form. We show the bit value, i.e., 0 and 2m-1 are shown as different values.

Operations for QIntTF

qulist_of_qinttf_lh :: QIntTF -> [Qubit]Source

Convert a QIntTF to a list of qubits. The conversion is little-headian, i.e., the head of the list holds the least significant digit.

qinttf_of_qulist_lh :: [Qubit] -> QIntTFSource

Convert a list of qubits to a QIntTF. The conversion is little-headian, i.e., the head of the list holds the least significant digit.

qinttf_shape :: Int -> QIntTFSource

Return a piece of shape data to represent an m-qubit QIntTF. Please note that the data can only be used as shape; it will be undefined at the leaves.

Auxiliary functions

xinttf_of_xint :: XInt x -> XIntTF xSource

The low-level isomorphism from XInt x to XIntTF x. Note that "isomorphism" is between the underlying raw types, and does not respect the arithmetic operations.

xint_of_xinttf :: XIntTF x -> XInt xSource

The low-level isomorphism from XIntTF x to XInt x. Note that "isomorphism" is between the underlying raw types, and does not respect the arithmetic operations.

xint_with_promote :: XIntTF y -> IntTF -> IntMSource

Like xint_of_xinttf, but first try to promote the length of the IntTF to that of the given XIntTF.

Miscellaneous circuit-building functions

phaseFlipIf :: ControlSource ctrl => ctrl -> Circ ()Source

Controlled phase flip of -1.

phaseFlipUnless :: ControlSource ctrl => ctrl -> Circ ()Source

Variant of phaseFlip that performs a phase flip unless all controls are in the given state.

qor :: Qubit -> [(Qubit, Bool)] -> Circ QubitSource

qor q c: Applies "not" to q, if any of the control qubits in c is in specified state.

Arithmetic functions

increment :: QDInt -> Circ QDIntSource

Increment a standard QDInt (i.e. big-endian, mod 2).

decrement :: QDInt -> Circ QDIntSource

Decrement a standard QDInt (i.e. big-endian, mod 2).

increment_big :: [Qubit] -> Circ [Qubit]Source

Increment a bit-string, considered as a big-endian integer mod 2.

decrement_big :: [Qubit] -> Circ [Qubit]Source

Decrement a bit-string, considered as a big-endian integer mod 2.

increment_little :: [Qubit] -> Circ [Qubit]Source

Increment a bit-string, considered as a little-endian integer mod 2.

decrement_little :: [Qubit] -> Circ [Qubit]Source

Decrement a bit-string, considered as a little-endian integer mod 2.

choose :: Integral a => a -> a -> aSource

The standard “combinations” function “n choose k”.

IntMaps as QData

addKeys :: IntMap a -> IntMap (Key, a)Source

Replace an IntMap f with the IntMap mapping each key k to (k,f(k)). An auxiliary function for defining mapWithKeyM, etc.

mapWithKeyM :: Monad m => (Key -> a -> m b) -> IntMap a -> m (IntMap b)Source

Analogous to mapM, but allows the function to use the key. Particularly useful for mapping in parallel over two (or more) IntMaps assumed to have the same domain.

mapWithKeyM_ :: Monad m => (Key -> a -> m b) -> IntMap a -> m ()Source

Analogous to mapM_, but allows the function to use the key.

intMap_replicate :: Int -> a -> IntMap aSource

Analogous to replicate on lists.

(!) :: IntMap a -> Key -> aSource

Convenient syntax for accessing elements of an IntMap. Left associative, and binds very strongly, like '(!!)'.