Safe Haskell | None |
---|
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
- data ControlList
- = ControlList (Map Wire Bool)
- | Inconsistent
- clist_empty :: ControlList
- clist_add :: Wire -> Bool -> ControlList -> ControlList
- combine :: ControlList -> ControlList -> ControlList
- combine_controls :: Controls -> ControlList -> ControlList
- add_to_controls :: Controls -> ControlList -> Maybe Controls
- control_gate :: ControlList -> Gate -> Maybe Gate
- control_gate_catch_all :: ControlList -> Gate -> Maybe Gate
- controllable_gate :: Gate -> Bool
- controllable_circuit :: Circuit -> Bool
- class ControlSource a where
- to_control :: a -> ControlList
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.
Instances
Show ControlList # | |
Defined in Quipper.Internal.Control showsPrec :: Int -> ControlList -> ShowS # show :: ControlList -> String # showList :: [ControlList] -> ShowS # | |
ControlSource ControlList # | |
Defined in Quipper.Internal.Control to_control :: ControlList -> ControlList Source # |
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 typeBit
(for a classical execution-time control) andQubit
(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.
to_control :: a -> ControlList Source #
Convert a condition to a control.