Operation API¶
An operation
is an gate
that is applied to a collection of wires. The wires are
identified by a wire_id
s given by a network
.
This page describes the interface of a operation data structure in tweedledum.
Warning
This part of the documentation makes use of a class called operation
. This class has been
created solely for the purpose of creating this documentation and is not meant to be used in
code.
Important
An peration
implementation must derive from the gate
class.
Gate¶
-
class
gate
¶ Simple class to hold information about the gate.
Subclassed by tweedledum::w2_op, tweedledum::w3_op, tweedledum::wn32_op
Properties¶
-
class
gate
Simple class to hold information about the gate.
Subclassed by tweedledum::w2_op, tweedledum::w3_op, tweedledum::wn32_op
Parameters¶
-
class
gate
Simple class to hold information about the gate.
Subclassed by tweedledum::w2_op, tweedledum::w3_op, tweedledum::wn32_op
Operation¶
Types and constants¶
An operation must expose the following compile-time constants:
static constexpr uint32_t max_num_wires;
static constexpr uint32_t network_max_num_wires;
The struct is_gate_type
can be used to check at compile time whether a given type contains all
required types and constants to implement a network type. It should be used in the beginning of
an algorithm that expects a gate type:
template<typename Gate>
class network {
static_assert(is_gate_type_v<Gate>, "Gate is not a gate type");
};
Constructors¶
-
class
operation
Public Functions
-
operation
(gate const &g, wire::id t) Construct an one-wire operation.
- Parameters
g
: A gate fromgate_lib
.t
: Wire identifier of the target.
-
operation
(gate const &g, wire::id w0, wire::id w1) Construct a two wire operation.
- Parameters
g
: A gate fromgate_lib
.w0
: Wire identifier.w1
: Wire identifier.
-
Properties¶
-
class
operation
Public Functions
-
uint32_t
num_wires
() const Returns the number of controls.
-
uint32_t
num_controls
() const Returns the number of controls.
-
uint32_t
num_targets
() const Returns the number of targets.
-
wire::id
control
(uint32_t const i = 0u) const Returns the i-th control wire identifier.
- Parameters
i
: must be less thannum_controls()
(default = 0).
-
wire::id
target
(uint32_t const i = 0u) const Returns the i-th target wire identifier.
- Parameters
i
: must be less thannum_targets()
(default = 0).
-
uint32_t
position
(wire::id wire) const Returns the position in which a wire is stored in the operation.
The poistion of a qubit is unique within the operation and
wire::id
is a unique wire identifier within the circuit.
-
wire::id
wire
(uint32_t const i) const Returns the wire identifier stored in the i-th position in the operation.
- Parameters
i
: must be less thannum_wires()
.
-
bool
is_adjoint
(operation const &other) const Check whether the this operation is adjoint of
other
operation.The conecept of operation adjointness requires that operation operations to be adjoint, and that both operations act on the same qubits in the same way, i.e., same controls and/or same targets.
-
bool
is_dependent
(operation const &other) const Check whether the this operation depends on
other
operation.If two operations acting on the same qubits are not dependent on each other, it means they can commute. For example:
┌───┐ ┌───┐ |0>──┤ T ├──●──── |0>────●──┤ T ├── A T operation can comute with a CNOT └───┘ │ ── │ └───┘ operation when the T operation it is ┌─┴─┐ ── ┌─┴─┐ acting on the control qubit of the CNOT. |0>───────┤ X ├── |0>──┤ X ├─────── └───┘ └───┘
-
uint32_t
Iterators¶
-
class
operation
Public Functions
-
template<typename
Fn
>
voidforeach_control
(Fn &&fn) const Calls
fn
on every target qubit of the operation.The paramater
fn
is any callable that must have the following signatures:void(wire::id)
-
template<typename
Fn
>
voidforeach_target
(Fn &&fn) const Calls
fn
on every target qubit of the operation.The paramater
fn
is any callable that must have the following signature:void(wire::id)
-
template<typename