The Quipper System

QuipperLib.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.

Constructors

 WireState Fieldswire_map :: IntMap (Wire, Wiretype) in_sub :: Bool subroutines_in_scope :: Map BoxId Sub

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.

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

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

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

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 a new qubit to the state.

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

Add a new bit to the state.

Remove a wire from the state

A helper function for providing the qubits within a control structure

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.

Take a Gate and execute it in the ASCIICirc monad.

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.