Safe Haskell | None |
---|

This module contains an implementation of a quantum simulator that uses the stabilizer states of the Clifford group (i.e. the Pauli group), to provide efficient simulation of quantum circuits constructed from elements of the Clifford group. The module provides an implementation of the Clifford group operators {x,y,z,h,s,controlled-x} which form a generating set for the Clifford group.

## Synopsis

- type Qubit = Int
- data Tableau = ST Qubit !(Map Qubit Sign) !(Map (Qubit, Qubit) Pauli) !(Map Qubit Sign) !(Map (Qubit, Qubit) Pauli)
- next_qubit :: Tableau -> Qubit
- sign :: Tableau -> Map Qubit Sign
- tableau :: Tableau -> Map (Qubit, Qubit) Pauli
- de_sign :: Tableau -> Map Qubit Sign
- de_tableau :: Tableau -> Map (Qubit, Qubit) Pauli
- lookup :: (Ord k, Show k, Show v) => k -> Map k v -> v
- empty_tableau :: Tableau
- add_qubit :: Bool -> Tableau -> Tableau
- type Unitary = Pauli -> (Sign, Pauli)
- data MinPauli
- type MinUnitary = MinPauli -> (Sign, Pauli)
- from_minimal :: MinUnitary -> Unitary
- from_matrix :: (Floating r, Eq r, Show r) => Matrix1 (Cplx r) -> Unitary
- apply_unitary :: Unitary -> Qubit -> Tableau -> Tableau
- apply_unitary_row :: Unitary -> Qubit -> Tableau -> Qubit -> Tableau
- type Unitary2 = (Pauli, Pauli) -> (Sign, Pauli, Pauli)
- data MinPauli2
- type MinUnitary2 = MinPauli2 -> (Sign, Pauli, Pauli)
- from_minimal2 :: MinUnitary2 -> Unitary2
- from_matrix2 :: (Floating r, Eq r, Show r) => Matrix2 (Cplx r) -> Unitary2
- from_matrix_controlled :: (Floating r, Show r, Eq r) => Matrix1 (Cplx r) -> Unitary2
- apply_unitary2 :: Unitary2 -> (Qubit, Qubit) -> Tableau -> Tableau
- measure :: Qubit -> Tableau -> IO (Bool, Tableau)
- reduce :: Qubit -> Tableau -> Tableau
- multiply :: Qubit -> Qubit -> Tableau -> Tableau
- multiply_de :: Qubit -> Qubit -> Tableau -> Tableau
- x :: Unitary
- x_min :: MinUnitary
- x' :: Unitary
- x'' :: Unitary
- y :: Unitary
- y_min :: MinUnitary
- y' :: Unitary
- y'' :: Unitary
- z :: Unitary
- z_min :: MinUnitary
- z' :: Unitary
- z'' :: Unitary
- h :: Unitary
- h_min :: MinUnitary
- h' :: Unitary
- h'' :: Unitary
- s :: Unitary
- s_min :: MinUnitary
- s' :: Unitary
- s'' :: Unitary
- e :: Unitary
- e_min :: MinUnitary
- e' :: Unitary
- e'' :: Unitary
- cnot :: Unitary2
- cnot_min :: MinUnitary2
- cnot' :: Unitary2
- cnot'' :: Unitary2
- cz :: Unitary2
- cz_min :: MinUnitary2
- cz' :: Unitary2
- cz'' :: Unitary2
- type CliffordCirc a = StateT Tableau IO a
- init_qubit :: Bool -> CliffordCirc Qubit
- init_qubits :: [Bool] -> CliffordCirc [Qubit]
- gate_X :: Qubit -> CliffordCirc ()
- gate_Y :: Qubit -> CliffordCirc ()
- gate_Z :: Qubit -> CliffordCirc ()
- gate_H :: Qubit -> CliffordCirc ()
- gate_S :: Qubit -> CliffordCirc ()
- gate_Unitary :: Unitary -> Qubit -> CliffordCirc ()
- controlled_X :: Qubit -> Qubit -> CliffordCirc ()
- controlled_Z :: Qubit -> Qubit -> CliffordCirc ()
- gate_Unitary2 :: Unitary2 -> Qubit -> Qubit -> CliffordCirc ()
- measure_qubit :: Qubit -> CliffordCirc Bool
- measure_qubits :: [Qubit] -> CliffordCirc [Bool]
- show_tableau :: CliffordCirc ()
- eval :: CliffordCirc a -> IO Tableau
- sim :: CliffordCirc a -> IO a
- swap :: Qubit -> Qubit -> CliffordCirc ()
- controlled_Z' :: Qubit -> Qubit -> CliffordCirc ()
- bell :: (Bool, Bool) -> CliffordCirc (Qubit, Qubit)
- measure_bell00 :: CliffordCirc (Bool, Bool)
- controlled_if :: Bool -> (Qubit -> CliffordCirc ()) -> Qubit -> CliffordCirc ()
- teleport :: Qubit -> CliffordCirc Qubit
- test_teleport :: Bool -> CliffordCirc Bool
- random_bool :: CliffordCirc Bool

# Documentation

The state of the system is a representation of a stabilizer tableau.

next_qubit :: Tableau -> Qubit Source #

Accessor function for the next_qubit field of a Tableau

tableau :: Tableau -> Map (Qubit, Qubit) Pauli Source #

Accessor function for the tableau field of a Tableau

de_tableau :: Tableau -> Map (Qubit, Qubit) Pauli Source #

Accessor function for the de_tableau field of a Tableau

lookup :: (Ord k, Show k, Show v) => k -> Map k v -> v Source #

A local Map lookup function that throws an error if the key doesn't exist.

empty_tableau :: Tableau Source #

An initial (empty) tableau.

add_qubit :: Bool -> Tableau -> Tableau Source #

A new qubit in the state |0〉 or |1〉 can be added to a tableau.

type Unitary = Pauli -> (Sign, Pauli) Source #

A (Clifford) unitary can be defined as a function acting on Pauli operators.

type MinUnitary = MinPauli -> (Sign, Pauli) Source #

The minimal definition of a unitary requires the actions on *X* and *Z*.

from_minimal :: MinUnitary -> Unitary Source #

The definition of a `Unitary`

can be constructed from a `MinUnitary`

.

from_matrix :: (Floating r, Eq r, Show r) => Matrix1 (Cplx r) -> Unitary Source #

It is possible to construct a `Unitary`

from a 2×2-matrix.

apply_unitary :: Unitary -> Qubit -> Tableau -> Tableau Source #

A unitary can be applied to a qubit in a given tableau. By folding through each row

apply_unitary_row :: Unitary -> Qubit -> Tableau -> Qubit -> Tableau Source #

Apply the unitary to the given column, in the given row.

type Unitary2 = (Pauli, Pauli) -> (Sign, Pauli, Pauli) Source #

A two-qubit (Clifford) unitary can be defined as a function acting on a pair of Pauli operators.

The minimal definition of a two-qubit unitary requires the actions on *IX*, *XI*, *IZ*, and *ZI*.

type MinUnitary2 = MinPauli2 -> (Sign, Pauli, Pauli) Source #

The minimal definition of a two-qubit unitary requires the actions on *IX*, *XI*, *IZ*, and *ZI*.

from_minimal2 :: MinUnitary2 -> Unitary2 Source #

The definition of a `Unitary2`

can be constructed from a `MinUnitary2`

.

from_matrix2 :: (Floating r, Eq r, Show r) => Matrix2 (Cplx r) -> Unitary2 Source #

It is possible to construct a `Unitary2`

from a 4×4-matrix.

from_matrix_controlled :: (Floating r, Show r, Eq r) => Matrix1 (Cplx r) -> Unitary2 Source #

It is possible to construct a `Unitary2`

from controlling a 2×2-matrix.

apply_unitary2 :: Unitary2 -> (Qubit, Qubit) -> Tableau -> Tableau Source #

A two-qubit unitary can be applied to a pair of qubits in a given tableau.

measure :: Qubit -> Tableau -> IO (Bool, Tableau) Source #

A measurement, in the computational basis, can be made of a qubit in the Tableau, returning the measurement result, and the resulting Tableau.

reduce :: Qubit -> Tableau -> Tableau Source #

This function reduces a tableau so that it contains either plus
or minus *Z*_{q}. Note that it is only called in the case
where *Z*_{q} is generated by the tableau (i.e., during
measurement).

multiply :: Qubit -> Qubit -> Tableau -> Tableau Source #

Multiply the stabilizers for the two given rows, in the given tableau, and update the first row with the result of the multiplication.

multiply_de :: Qubit -> Qubit -> Tableau -> Tableau Source #

Multiply row1 of the destabilizer by row2 of the stabilizer.

x_min :: MinUnitary Source #

We can (equivalently) define Pauli-*X* as a `MinUnitary`

.

We can (equivalently) construct Pauli-*X* from a `MinUnitary`

.

y_min :: MinUnitary Source #

We can (equivalently) define Pauli-*Y* as a `MinUnitary`

.

We can (equivalently) construct Pauli-*Y* from a `MinUnitary`

.

z_min :: MinUnitary Source #

We can (equivalently) define Pauli-*Z* as a `MinUnitary`

.

We can (equivalently) construct Pauli-*Z* from a `MinUnitary`

.

h_min :: MinUnitary Source #

We can (equivalently) define Hadamard as a `MinUnitary`

.

We can (equivalently) construct Hadamard from a `MinUnitary`

.

We can (equivalently) construct Hadamard from a matrix. Although rounding errors break this!!!

s_min :: MinUnitary Source #

We can (equivalently) define phase gate as a `MinUnitary`

.

We can (equivalently) construct phase gate from a `MinUnitary`

.

e_min :: MinUnitary Source #

We can (equivalently) define phase gate as a `MinUnitary`

.

We can (equivalently) construct phase gate from a `MinUnitary`

.

cnot_min :: MinUnitary2 Source #

We can (equivalently) define CNot as a `MinUnitary2`

.

We can (equivalently) construct CNot from a `MinUnitary2`

.

cz_min :: MinUnitary2 Source #

We can (equivalently) define controlled-*Z* as a `MinUnitary2`

.

We can (equivalently) construct controlled-*Z* from a `MinUnitary2`

.

type CliffordCirc a = StateT Tableau IO a Source #

A Clifford group circuit is implicitly simulated using
a state monad over a `Tableau`

.

init_qubit :: Bool -> CliffordCirc Qubit Source #

Initialize a new qubit.

init_qubits :: [Bool] -> CliffordCirc [Qubit] Source #

Initialize multiple qubits.

gate_X :: Qubit -> CliffordCirc () Source #

Apply a Pauli-*X* gate to the given qubit.

gate_Y :: Qubit -> CliffordCirc () Source #

Apply a Pauli-*Y* gate to the given qubit.

gate_Z :: Qubit -> CliffordCirc () Source #

Apply a Pauli-*Z* gate to the given qubit.

gate_H :: Qubit -> CliffordCirc () Source #

Apply a Hadamard gate to the given qubit.

gate_S :: Qubit -> CliffordCirc () Source #

Apply a phase gate to the given qubit.

gate_Unitary :: Unitary -> Qubit -> CliffordCirc () Source #

Apply a given `Unitary`

to the given qubit.

controlled_X :: Qubit -> Qubit -> CliffordCirc () Source #

Apply a controlled-*X* gate to the given qubits.

controlled_Z :: Qubit -> Qubit -> CliffordCirc () Source #

Apply a controlled-*Z* gate to the given qubits.

gate_Unitary2 :: Unitary2 -> Qubit -> Qubit -> CliffordCirc () Source #

Apply a given `Unitary2`

to the given qubits

measure_qubit :: Qubit -> CliffordCirc Bool Source #

Measure the given qubit in the computational basis.

measure_qubits :: [Qubit] -> CliffordCirc [Bool] Source #

Measure the given list of qubits.

show_tableau :: CliffordCirc () Source #

For testing purposes, we can show the tableau during a simulation.

sim :: CliffordCirc a -> IO a Source #

Return the result of simulating the given circuit.

swap :: Qubit -> Qubit -> CliffordCirc () Source #

A swap gate can be defined in terms of three controlled-not gates.

controlled_Z' :: Qubit -> Qubit -> CliffordCirc () Source #

A controlled-*Z* gate can (equivalently) be defined in terms of
Hadamard and controlled-*X*.

bell :: (Bool, Bool) -> CliffordCirc (Qubit, Qubit) Source #

Each of the four Bell states can be generated, indexed by a pair of boolean values.

measure_bell00 :: CliffordCirc (Bool, Bool) Source #

Create a Bell state, and measure it.

controlled_if :: Bool -> (Qubit -> CliffordCirc ()) -> Qubit -> CliffordCirc () Source #

A single-qubit operation can be controlled by a classical boolean value.

test_teleport :: Bool -> CliffordCirc Bool Source #

A wrapper around the teleportation circuit that initializes a qubit in the given boolean state, and measures the teleported qubit.

random_bool :: CliffordCirc Bool Source #

Measure an equal superposition.