quipper-core-0.8.0.1: An embedded, scalable functional programming language for quantum computing.

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

 Source # MethodsshowList :: [ControlList] -> ShowS # Source # 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.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.

Minimal complete definition

to_control

Methods

to_control :: a -> ControlList Source #

Convert a condition to a control.

Instances

 Source # Methods Source # Methodsto_control :: () -> ControlList Source # Source # Methods Source # Methods Source # Methods Source # Methods ControlSource a => ControlSource [a] Source # Methodsto_control :: [a] -> ControlList Source # Source # Methods Source # Methods Source # Methods (ControlSource a, ControlSource b) => ControlSource (a, b) Source # Methodsto_control :: (a, b) -> ControlList Source # (ControlSource a, ControlSource b, ControlSource c) => ControlSource (a, b, c) Source # Methodsto_control :: (a, b, c) -> ControlList Source # (ControlSource a, ControlSource b, ControlSource c, ControlSource d) => ControlSource (a, b, c, d) Source # Methodsto_control :: (a, b, c, d) -> ControlList Source # (ControlSource a, ControlSource b, ControlSource c, ControlSource d, ControlSource e) => ControlSource (a, b, c, d, e) Source # 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) Source # 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) Source # Methodsto_control :: (a, b, c, d, e, f, g) -> ControlList Source #