The Quipper System

Safe HaskellNone

QuipperLib.ClassicalOptim.Circuit

Contents

Description

This module provides a simplified representation of classical circuits.

Synopsis

Simplified circuits

type Wire = IntSource

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 
Show Gate 
NFData Gate 

wireOfGate :: Gate -> Maybe WireSource

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 BoolSource

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

circuit :: [Gate]

The circuit so far.

freshWire :: Wire

The next fresh wire.

Instances

emptyState :: CircStateSource

The empty state.

data Circ a Source

A simplified Circ monad.

Constructors

Circ (CircState -> (CircState, a)) 

Instances

Low-level access functions

getFresh :: Circ WireSource

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 WireSource

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.