The Quipper System

Safe Haskell None

QuipperLib.QuipperASCIIParser.CircInfo

Contents

Description

This module uses a state monad to track certain circuit information that is collected during parsing. This information contains the inputs and outputs of a circuit, as well as an entry for each subroutine that is defined within a circuit, and all the gates that make up the circuit.

Synopsis

# Data-types for the State

data Sub Source #

Information collected about the current subroutine

Constructors

 Sub Fieldsname :: String shape :: String controllable :: ControllableFlag inputs :: [(Wire, Wiretype)] outputs :: [(Wire, Wiretype)] circuit :: [Gate]

An initial subroutine, with only a name

A CircInfoState is a record containing a list of input wires, along with their types, and a list of output wires, along with their types. We also keep track of whether we're in a subroutine definition, and all the subroutines that have been defined.

Constructors

 CircInfoState Fieldsused_wires :: Map Wire (Maybe Wiretype) defined_inputs :: [(Wire, Wiretype)] undefined_inputs :: [(Wire, Maybe Wiretype)] defined_outputs :: Maybe [(Wire, Wiretype)] current_subroutine :: [Sub]

An initial, empty CircInfoState

type CircInfo a = State CircInfoState a Source #

The CircInfo Monad is used to track a CircInfoState during parsing.

add_wire_inputs :: [(Wire, Wiretype)] -> CircInfo () Source #

The CircInfo Monad tracks wires that are inputs, these can only be given in a Input line in the parsed ASCII, so we assume that duplicate wires don't occur, and we add input wires to the state without checking.

add_wire_outputs :: [(Wire, Wiretype)] -> CircInfo () Source #

The CircInfo Monad tracks wires that are outputs, these can only be given in a Output line in the parsed ASCII, so we assume that duplicate wires don't occur, and we add output wires to the state without checking.

Given a a wire, check whether it is already in scope.

check_inputs :: [(Wire, Maybe Wiretype)] -> Map Wire (Maybe Wiretype) -> [(Wire, Maybe Wiretype)] Source #

Given a list of wires that are inputs to a gate, check whether they are already in scope. The returned wires are not in scope, when used by a gate, and must be declared as undefined inputs.

add_gate :: Gate -> [(Wire, Wiretype)] -> CircInfo CircInfoOut Source #

The CircInfo Monad keeps track of all the gates that have been parsed and adds them to the relevant part of the state.

The CircInfo Monad tracks whether we are in a subroutine, and collects info about that subroutine. The entrance to the subroutine contains its name.

We can add the shape to the current subroutine

The CircInfo Monad tracks whether we are in a subroutine, and collects info about that subroutine. The subroutine might be controllable.

A datatype to represent the various outputs a CircInfo computation may require.

Constructors

 Empty Lazy Gate SubDef (BoxId, Sub)

This function returns True if the given input defines a Gate

This function returns True if the given inputs defines a SubDef

The CircInfo Monad tracks whether we are in a subroutine, and collects info about that subroutine. At the end of the subroutine, it stores the subroutine for later use.

Take a GatePlus and execute it in the CircInfo monad. Again, the executed computation may depend upon whether we're in a subroutine definition.

Monad version of parse_ascii_line: parse a string and execute the resulting gate directly in the CircInfo monad.

run_ascii_lines :: [String] -> (Maybe [(Wire, Wiretype)], CircInfo [CircInfoOut]) Source #

Parse a stream consisting of many lines of ASCII output and execute the parsed gates in the CircInfo monad, checking to see if the first line defines the inputs to the circuit.

Run function for the CircInfo monad: evaluate the state and produce a list of inputs, outputs, and used wires.