The Quipper System

Safe HaskellNone

QuipperLib.ClassicalOptim.Circuit

Contents

Description

This module provides a simplified representation of classical circuits.

Synopsis

Simplified circuits

type Wire = Int Source #

The type of wires. A wire is determined by an integer ID.

data Gate Source #

The type of gates.

Constructors

NoOp

No operation.

Init Bool Wire

Initialization.

Cnot Wire [(Wire, Bool)]

Multi-controlled not.

Instances

Eq Gate # 

Methods

(==) :: Gate -> Gate -> Bool #

(/=) :: Gate -> Gate -> Bool #

Show Gate # 

Methods

showsPrec :: Int -> Gate -> ShowS #

show :: Gate -> String #

showList :: [Gate] -> ShowS #

wireOfGate :: Gate -> Maybe Wire Source #

Get the wire acted upon by a gate, if any.

ctlsOfGate :: Gate -> Maybe [(Wire, Bool)] Source #

Get the list of controls, if any.

evalCirc :: Map Wire Bool -> [Gate] -> Map Wire Bool Source #

Evaluate a circuit on a given initial state, and return the final state. A state is represented as a map from wires to booleans.

Simplified Circ monad

data CircState Source #

A data structure to represent a "circuit under construction". This holds the data needed for circuit generation.

Constructors

CS 

Fields

emptyState :: CircState Source #

The empty state.

data Circ a Source #

A simplified Circ monad.

Constructors

Circ (CircState -> (CircState, a)) 

Instances

Monad Circ # 

Methods

(>>=) :: Circ a -> (a -> Circ b) -> Circ b #

(>>) :: Circ a -> Circ b -> Circ b #

return :: a -> Circ a #

fail :: String -> Circ a #

Functor Circ # 

Methods

fmap :: (a -> b) -> Circ a -> Circ b #

(<$) :: a -> Circ b -> Circ a #

Applicative Circ # 

Methods

pure :: a -> Circ a #

(<*>) :: Circ (a -> b) -> Circ a -> Circ b #

(*>) :: Circ a -> Circ b -> Circ b #

(<*) :: Circ a -> Circ b -> Circ a #

Low-level access functions

getFresh :: Circ Wire Source #

Retrieve the next fresh wire.

incrementFresh :: Circ () Source #

Increment the value of the fresh wire.

addGate :: Gate -> Circ () Source #

Add a new gate to the circuit.

extractCircuit :: Circ a -> [Gate] Source #

Get the circuit out of the monad.

Higher-level access functions

init :: Bool -> Circ Wire Source #

Initialize a new wire.

cnot :: Wire -> [(Wire, Bool)] -> Circ () Source #

Add a multi-controlled not gate.

Pretty-printing

These functions are only used for testing.

printCircuit :: Circ a -> IO () Source #

Pretty-print a circuit as a list of gates.

print_quipperStyle :: Gate -> IO () Source #

Print a gate as Quipper code.