The Quipper System

Safe HaskellNone

Quipper.Libraries.Qureg

Contents

Description

This module provides a data type of quantum registers, as well as associated types of classical and boolean registers.

Synopsis

Quantum registers

type Qureg = Register Qubit Source #

The type of quantum registers. A quantum register is an array of qubits, indexed by natural numbers in the range from 0 to n-1, where n is the length of the register. The syntax a .!(i) is used to access the ith element of the register a.

The main advantage of a register over a list is constant-time access. The main disadvantage is that registers don't allow easy appending, pattern matching, or recursion.

qureg_of_qulist_te :: Qulist -> Qureg Source #

Convert a Qulist to a Qureg. The conversion is tail-endian, i.e., r.!(0) holds the tail of the list.

qulist_of_qureg_te :: Qureg -> Qulist Source #

Convert a Qureg to a Qulist. The conversion is tail-endian, i.e., r.!(0) holds the tail of the list.

qureg_length :: Qureg -> Int Source #

Return the length of a Qureg.

qinit_register :: [Bool] -> Circ Qureg Source #

Creates a new quantum register, initialized from a list of booleans. The conversion is tail-endian, i.e., r.!(0) holds the tail of the list.

qterm_register :: [Bool] -> Qureg -> Circ () Source #

Terminates a quantum register, and assert that its state is as specified by the list of booleans. The conversion is tail-endian, i.e., r.!(0) holds the tail of the list.

qmeasure_register :: Qureg -> Circ [Bit] Source #

Measure a quantum register, yielding a list of Bits.

with_ancilla_reg :: Int -> (Qureg -> Circ a) -> Circ a Source #

Temporarily create a quantum register of size n for use as an ancilla. This can be used to introduce an ancilla with a local scope, like this:

with_ancilla_reg n $ \r -> do {
  <<<code block using ancilla register r>>>
}

with_ancilla_reg_init :: Boollist -> (Qureg -> Circ a) -> Circ a Source #

Like with_ancilla_reg, except also initialize the register as specified by a bit vector. In this case, the argument n is not required, because it equals the length of the bit vector. When the ancilla is terminated at the end of its scope, it is asserted to be in the same state it was prepared in.

qureg_shape :: Int -> Qureg Source #

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

Bit registers

type Bitreg = Register Bit Source #

The type of Bit registers. The syntax a .!(i) is used to access the ith element of the register a.

bitreg_of_bitlist_te :: Bitlist -> Bitreg Source #

Turn a bit vector into a bit register. The conversion is tail-endian, i.e., r.!(0) holds the tail of the list.

bitlist_of_bitreg_te :: Bitreg -> Bitlist Source #

Turn a bit register into a bit vector. The conversion is tail-endian, i.e., r.!(0) holds the tail of the list.

bitreg_length :: Bitreg -> Int Source #

Return the length of a Bitreg.

Boolean registers

type Boolreg = Register Bool Source #

The type of boolean registers.

boolreg_of_boollist_te :: Boollist -> Boolreg Source #

Turn a bool vector into a bool register. The conversion is tail-endian, i.e., r.!(0) holds the tail of the list.

boollist_of_boolreg_te :: Boolreg -> Boollist Source #

Turn a bool register into a bool vector. The conversion is tail-endian, i.e., r.!(0) holds the tail of the list.

boolreg_length :: Boolreg -> Int Source #

Return the length of a Boolreg.

boolreg_of_int_le :: Integral a => Int -> a -> Boolreg Source #

boolreg_of_int m x: Initialize a bool register directly from an integer x, regarded as a binary string of length m. The conversion is little-endian, i.e., the register holds the least significant digit at index 0.

int_of_boolreg_unsigned_le :: Integral a => Boolreg -> a Source #

int_of_boolreg_unsigned_le m r: Turn a bool register into an integer, regarded as a binary string. The conversion is little-endian, i.e., the register holds the least significant digit at index 0. The integer is unsigned.

General registers

data Register x Source #

A register is an array of elements of some type x, indexed by natural numbers in the range from 0 to n-1, where n is the length of the register.

Instances
QCData Bitreg # 
Instance details

Defined in Quipper.Libraries.Qureg

Methods

qcdata_mapM :: Monad m => Bitreg -> (q -> m q') -> (c -> m c') -> QCType q c Bitreg -> m (QCType q' c' Bitreg) Source #

qcdata_zip :: Bitreg -> q -> c -> q' -> c' -> QCType q c Bitreg -> QCType q' c' Bitreg -> ErrMsg -> QCType (q, q') (c, c') Bitreg Source #

qcdata_promote :: BType Bitreg -> Bitreg -> ErrMsg -> BType Bitreg Source #

QCData Qureg # 
Instance details

Defined in Quipper.Libraries.Qureg

Methods

qcdata_mapM :: Monad m => Qureg -> (q -> m q') -> (c -> m c') -> QCType q c Qureg -> m (QCType q' c' Qureg) Source #

qcdata_zip :: Qureg -> q -> c -> q' -> c' -> QCType q c Qureg -> QCType q' c' Qureg -> ErrMsg -> QCType (q, q') (c, c') Qureg Source #

qcdata_promote :: BType Qureg -> Qureg -> ErrMsg -> BType Qureg Source #

Labelable Bitreg String # 
Instance details

Defined in Quipper.Libraries.Qureg

Labelable Qureg String # 
Instance details

Defined in Quipper.Libraries.Qureg

Show x => Show (Register x) # 
Instance details

Defined in Quipper.Libraries.Qureg

Methods

showsPrec :: Int -> Register x -> ShowS #

show :: Register x -> String #

showList :: [Register x] -> ShowS #

type QTypeB Boolreg # 
Instance details

Defined in Quipper.Libraries.Qureg

type QCType x y Qureg # 
Instance details

Defined in Quipper.Libraries.Qureg

type QCType x y Qureg = Register x
type QCType x y Bitreg # 
Instance details

Defined in Quipper.Libraries.Qureg

type QCType x y Bitreg = Register y

(.!) :: Register x -> Int -> x infixl 9 Source #

r !.(i): Return the ith element of a register r.