quipper-libraries-0.9.0.0: The standard libraries for Quipper.

Safe HaskellNone
LanguageHaskell98

Quipper.Libraries.QuipperASCIIParser.ASCIICirc

Contents

Description

This module uses a state transformer monad to rebuild a circuit from the CircInfoState representation. This can only be as lazy as the Quipper ASCII output allows, as subroutine definitions need to be known before a subroutine can be called.

Synopsis

Documentation

data WireState Source #

In the Quipper ASCII output, wires are identified by integers. We have to map these to Quipper's native wires and types.

empty_wirestate :: Map BoxId Sub -> WireState Source #

An initial, empty WireState, with the given subroutines_in_scope

type ASCIICirc a = StateT WireState Circ a Source #

The ASCIICirc monad is like the Circ monad, except that it also keeps track of an additional WireState. The lift function must be used to lift any command for the Circ monad to the ASCIICirc monad.

set_in_sub :: ASCIICirc () Source #

The in_sub flag can be set to True, as slightly different behavior is required when evaluating a subroutine.

provide_qubit :: Int -> ASCIICirc Qubit Source #

Look up the qubit corresponding to a ASCII integer representation of a qubit. If it doesn't already exist then initialize a new qubit.

provide_bit :: Int -> ASCIICirc Bit Source #

Look up the bit corresponding to a ASCII integer representation of a bit. If it doesn't already exist then initialize a new bit.

provide_wire :: Int -> ASCIICirc Wire Source #

Look up the wire corresponding to a ASCII integer representation of a bit or qubit. If it doesn't already exist then initialize a new qubit.

add_qubit :: Int -> Qubit -> ASCIICirc () Source #

Add a new qubit to the state.

add_bit :: Int -> Bit -> ASCIICirc () Source #

Add a new bit to the state.

remove_wire :: Int -> ASCIICirc () Source #

Remove a wire from the state

provide_control :: Signed Int -> ASCIICirc (Signed Wire) Source #

A helper function for providing the qubits within a control structure

provide_controls :: [Signed Int] -> ASCIICirc [Signed Wire] Source #

provides quantum wires for the controls in a control list

lift_ncf :: Bool -> Circ a -> ASCIICirc a Source #

Lift a Quipper circuit, preventing the addition of controls depending on the given boolean.

do_gate :: Gate -> ASCIICirc () Source #

Take a Gate and execute it in the ASCIICirc monad.

allocate_input :: (Endpoint, Endpoint) -> ASCIICirc () Source #

Allocate an input endpoint, to an endpoint in the ASCIICirc, by adding it to the map of wires in scope.

Unpacking ASCIICirc

run_gates :: [Gate] -> Maybe [(Wire, Wiretype)] -> [Endpoint] -> [Endpoint] -> ASCIICirc [Endpoint] Source #

Execute a parsed circuit, i.e. a CircInfoState, in the ASCIICirc monad

run_asciicirc :: Map BoxId Sub -> (a -> ASCIICirc b) -> a -> Circ b Source #

Run function for the ASCIICirc monad: execute the actions and produce a circuit.

run :: Maybe [(Wire, Wiretype)] -> [Gate] -> Map BoxId Sub -> CircInfoState -> ([Endpoint], [Endpoint] -> Circ [Endpoint]) Source #

A CircInfoState can be turned into a Circ producing function, and the required input "shape".

set_qubit :: (Wire, Maybe Wiretype) -> (Wire, Wiretype) Source #

If the type of an undefined_input wire is unknown, then set it to be a qubit.