Gate API¶
A Gate
is an gate_base
that is applied to a collection of qubits. Those qubits are identified
by a qid
given by a network
.
This page describes the interface of a quantum gate data structure in tweedledum.
Warning
This part of the documentation makes use of a class called gate
. This class has been
created solely for the purpose of creating this documentation and is not meant to be used in
code.
Mandatory types and constants¶
A gate must expose the following compile-time constants:
static constexpr uint32_t max_num_io;
static constexpr uint32_t network_max_num_qubits;
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");
};
Methods¶
Constructors¶
-
class
gate
Public Functions
-
gate
(gate_base const &op, io_id target) Construct a single qubit gate.
- Parameters
op
: the operation (must be a single qubit operation).target
: qubit identifier of the target.
-
gate
(gate_base const &controlled_op, io_id control, io_id target) Construct a controlled gate.
- Parameters
controlled_op
: the operation (must be a two qubit controlled operation).control
: qubit identifier of the control.target
: qubit identifier of the target.
-
gate
(gate_base const &unitary_op, std::vector<io_id> const &controls, std::vector<io_id> const &targets) Construct a gate using vectors.
- Parameters
unitary_op
: the operation (must be unitary operation).controls
: qubit(s) identifier of the control(s).targets
: qubit identifier of the target.
-
Properties¶
-
class
gate
Public Functions
-
uint32_t
num_controls
() const Return the number of controls.
-
uint32_t
num_targets
() const Returns the number of targets.
-
uint32_t
Iterators¶
-
class
gate
Public Functions
-
template<typename
Fn
>
voidforeach_control
(Fn &&fn) const Calls
fn
on every target qubit of the gate.The paramater
fn
is any callable that must have one of the following two signatures.void(io_id)
bool(io_id)
If
fn
returns abool
, then it can interrupt the iteration by returningfalse
.
-
template<typename
Fn
>
voidforeach_target
(Fn &&fn) const Calls
fn
on every target qubit of the gate.The paramater
fn
is any callable that must have one of the following signature.void(io_id)
-
template<typename