The Quipper System

Safe HaskellNone

Quipper.Internal.Control

Contents

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

data ControlList Source #

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

Functions for combining control lists

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

clist_empty :: ControlList Source #

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

clist_add :: Wire -> Bool -> ControlList -> ControlList Source #

Add a single signed control to a control list.

combine :: ControlList -> ControlList -> ControlList Source #

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

combine_controls :: Controls -> ControlList -> ControlList Source #

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

add_to_controls :: Controls -> ControlList -> Maybe Controls Source #

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

control_gate :: ControlList -> Gate -> Maybe Gate Source #

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.

control_gate_catch_all :: ControlList -> Gate -> Maybe Gate Source #

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.

controllable_gate :: Gate -> Bool Source #

Define whether a gate can be controlled.

controllable_circuit :: Circuit -> Bool Source #

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
ControlSource Bool # 
Instance details

Defined in Quipper.Internal.Control

ControlSource () # 
Instance details

Defined in Quipper.Internal.Control

Methods

to_control :: () -> ControlList Source #

ControlSource Wire # 
Instance details

Defined in Quipper.Internal.Control

ControlSource ControlList # 
Instance details

Defined in Quipper.Internal.Control

ControlSource Bit # 
Instance details

Defined in Quipper.Internal.Monad

ControlSource Qubit # 
Instance details

Defined in Quipper.Internal.Monad

ControlSource a => ControlSource [a] # 
Instance details

Defined in Quipper.Internal.Control

Methods

to_control :: [a] -> ControlList Source #

ControlSource (Signed Wire) # 
Instance details

Defined in Quipper.Internal.Control

(ControlSource (Signed a), ControlSource (Signed b)) => ControlSource (Signed (B_Endpoint a b)) # 
Instance details

Defined in Quipper.Internal.Monad

ControlSource (Signed Bit) # 
Instance details

Defined in Quipper.Internal.Monad

ControlSource (Signed Qubit) # 
Instance details

Defined in Quipper.Internal.Monad

(ControlSource a, ControlSource b) => ControlSource (a, b) # 
Instance details

Defined in Quipper.Internal.Control

Methods

to_control :: (a, b) -> ControlList Source #

(ControlSource a, ControlSource b) => ControlSource (B_Endpoint a b) # 
Instance details

Defined in Quipper.Internal.Monad

(ControlSource a, ControlSource b, ControlSource c) => ControlSource (a, b, c) # 
Instance details

Defined in Quipper.Internal.Control

Methods

to_control :: (a, b, c) -> ControlList Source #

(ControlSource a, ControlSource b, ControlSource c, ControlSource d) => ControlSource (a, b, c, d) # 
Instance details

Defined in Quipper.Internal.Control

Methods

to_control :: (a, b, c, d) -> ControlList Source #

(ControlSource a, ControlSource b, ControlSource c, ControlSource d, ControlSource e) => ControlSource (a, b, c, d, e) # 
Instance details

Defined in Quipper.Internal.Control

Methods

to_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 details

Defined in Quipper.Internal.Control

Methods

to_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 details

Defined in Quipper.Internal.Control

Methods

to_control :: (a, b, c, d, e, f, g) -> ControlList Source #