The Quipper System

Quipper.Internal.Control

Description

Some gates can be controlled by a condition involving one of more "control" qubits and/or classical bits at circuit execution time. Such gates can also be controlled by boolean conditions that are known at circuit generation time (in which case the gate will not be generated when the control condition is false). This Quipper.Internal.Control module provides some convenient functions for creating and updating such controls.

Synopsis

# The type of controls

In the most general case, a "control" could be an arbitrary boolean formula built up from assertions of the form q = |0〉 or q = |1〉, where q is either a qubit or a classical bit in a circuit. However, we are here interested in tracking a simpler kind of control.

A control list is a conjunction (i.e., an "and") of assertions of the form q = |0〉 or q = |1〉. A special case arises when the conjunction involves two mutually exclusive conditions, such as q = |0〉 and q = |1〉. In this case, the control in inconsistent: it can never be active. We use a special representation for the inconsistent control for efficiency reasons.

Implementation note: a ControlList is either Inconsistent, or else a map from a finite set of wires to booleans. Here, the boolean True represents a positive control, i.e., one that is active when the state is |1〉 (a filled dot in circuit diagrams). The boolean False represents a negative control, i.e., on that is active when the state is |0〉 (an empty dot in circuit diagrams).

A ControlList is Quipper's internal representation of the type of conjunctive controls, i.e., controls that can be constructed using the .==., ./=., and .&&. operators.

Constructors

 ControlList (Map Wire Bool) Inconsistent
Instances
 # Instance detailsDefined in Quipper.Internal.Control MethodsshowList :: [ControlList] -> ShowS # # Instance detailsDefined in Quipper.Internal.Control Methods

# Functions for combining control lists

We provide some convenient functions for building control lists from simpler control lists.

The empty control list, corresponding to a condition that is always true.

Add a single signed control to a control list.

combine list1 list2: Take the conjunction of two control lists. This is more efficient if list1 is small and list2 is large.

Like combine, but the first argument is of type Controls from the Quipper.Internal.Circuit module.

Like combine_controls, but also return a value of type Controls, or Nothing if the controls are inconsistent. This function is for convenience.

# Controlling low-level gates

Modify the given gate by applying the specified controls. If the total set of controls (i.e., those specified in the gate itself and those specified in the control list) is inconsistent, return Nothing. If it is consistent, return the appropriately controlled version of the gate. Throw an error if the gate is of a kind that cannot be controlled.

The "catch all" clause for control_gate. This handles all gates that are not controllable. If the control condition is known at circuit generation time to be clist_empty, then we can just append the gate unconditionally. All other cases are errors.

Define whether a gate can be controlled.

Define whether an entire low-level circuit can be controlled

# Specifying control lists

class ControlSource a where Source #

A "control source" is anything that can be used as a control on a gate. The most common way to construct a control source is by using the .==., ./=., and .&&. operators. In addition, we provide the following instances:

• Bool. A boolean condition that is known at circuit generation time can be used as a control, which is then either trivial (the gate is generated) or inconsistent (the gate is not generated).
• Wire. This includes the type Bit (for a classical execution-time control) and Qubit (for a quantum control). A wire can be used as a shorthand notation for a positive control on that wire.
• ControlList. A control list is Quipper's internal representation of a control condition, and is trivially a control source.
• A list of control sources can be used as a control source.

Methods

to_control :: a -> ControlList Source #

Convert a condition to a control.

Instances
 # Instance detailsDefined in Quipper.Internal.Control Methods # Instance detailsDefined in Quipper.Internal.Control Methodsto_control :: () -> ControlList Source # # Instance detailsDefined in Quipper.Internal.Control Methods # Instance detailsDefined in Quipper.Internal.Control Methods # Instance detailsDefined in Quipper.Internal.Monad Methods # Instance detailsDefined in Quipper.Internal.Monad Methods ControlSource a => ControlSource [a] # Instance detailsDefined in Quipper.Internal.Control Methodsto_control :: [a] -> ControlList Source # # Instance detailsDefined in Quipper.Internal.Control Methods (ControlSource (Signed a), ControlSource (Signed b)) => ControlSource (Signed (B_Endpoint a b)) # Instance detailsDefined in Quipper.Internal.Monad Methods # Instance detailsDefined in Quipper.Internal.Monad Methods # Instance detailsDefined in Quipper.Internal.Monad Methods (ControlSource a, ControlSource b) => ControlSource (a, b) # Instance detailsDefined in Quipper.Internal.Control Methodsto_control :: (a, b) -> ControlList Source # (ControlSource a, ControlSource b) => ControlSource (B_Endpoint a b) # Instance detailsDefined in Quipper.Internal.Monad Methods (ControlSource a, ControlSource b, ControlSource c) => ControlSource (a, b, c) # Instance detailsDefined in Quipper.Internal.Control Methodsto_control :: (a, b, c) -> ControlList Source # (ControlSource a, ControlSource b, ControlSource c, ControlSource d) => ControlSource (a, b, c, d) # Instance detailsDefined in Quipper.Internal.Control Methodsto_control :: (a, b, c, d) -> ControlList Source # (ControlSource a, ControlSource b, ControlSource c, ControlSource d, ControlSource e) => ControlSource (a, b, c, d, e) # Instance detailsDefined in Quipper.Internal.Control Methodsto_control :: (a, b, c, d, e) -> ControlList Source # (ControlSource a, ControlSource b, ControlSource c, ControlSource d, ControlSource e, ControlSource f) => ControlSource (a, b, c, d, e, f) # Instance detailsDefined in Quipper.Internal.Control Methodsto_control :: (a, b, c, d, e, f) -> ControlList Source # (ControlSource a, ControlSource b, ControlSource c, ControlSource d, ControlSource e, ControlSource f, ControlSource g) => ControlSource (a, b, c, d, e, f, g) # Instance detailsDefined in Quipper.Internal.Control Methodsto_control :: (a, b, c, d, e, f, g) -> ControlList Source #