Network API¶
This page describes the interface of a quantum network data structure in tweedledum.
Warning
This part of the documentation makes use of a class called network. This class has been
created solely for the purpose of creating this documentation and is not meant to be used in
code. Custom network implementation do not have to derive from this class, but only need to
ensure that, if they implement a function of the interface, it is implemented using the same
signature.
Mandatory types and constants¶
The interaction with a network data structure is performed using four types for which no application details are assumed. The following four types must be defined within the network data structure. They can be implemented as nested type, but may also be exposed as type alias.
-
template<typename
GateType>
classnetwork Public Types
-
template<>
usingbase_type= network Type referring to itself.
The
base_typeis the network type itself. It is required, because views may extend networks, and this type provides a way to determine the underlying network type.
-
template<>
usinggate_type= GateType Type representing a gate.
A
Gateis an operation that can be applied to a collection of qubits. It could be a meta operation, such as, primary input and a primary output, or a unitary operation gate.
-
struct
node_type Type representing a node.
A
nodeis a node in the network. Each node must contains a gate.
-
struct
storage_type Type representing the storage.
A
storageis some container that can contain all data necessary to store the network. It can constructed outside of the network and passed as a reference to the constructor. It may be shared among several networks. Astd::shared_ptr<T>is a convenient data structure to hold a storage.
-
template<>
Further, a network must expose the following compile-time constants:
static constexpr uint32_t min_fanin_size;
static constexpr uint32_t max_fanin_size;
The struct is_network_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 network type:
template<typename Network>
void algorithm(Network const& ntk) {
static_assert(is_network_type_v<Network>, "Network is not a network type");
}
Methods¶
Constructors¶
-
template<typename
GateType>
classnetwork
Qubits and Ancillae¶
-
template<typename
GateType>
classnetwork Public Functions
-
io_id
add_qubit(std::string const &qlabel) Creates a labeled qubit in the network and returns its
io_id
-
io_id
add_qubit() Creates a unlabeled qubit in the network and returns its
io_idSince all I/Os in a network must be labeled, this function will create a generic label with the form: qN, where N is the
io_id.
-
io_id
Structural properties¶
-
template<typename
GateType>
classnetwork Public Functions
-
uint32_t
size() const Returns the number of nodes.
-
uint32_t
num_qubits() const Returns the number of qubits.
-
uint32_t
num_gates() const Returns the number of gates, i.e., nodes that hold unitary operations.
-
uint32_t
Node iterators¶
-
template<typename
GateType>
classnetwork Public Functions
-
template<typename
Fn>
voidforeach_qubit(Fn &&fn) const Calls
fnon every qubit in the network.The paramater
fnis any callable that must have one of the following three signatures.void(uint32_t qid)void(string const& qlabel)void(uint32_t qid, string const& qlabel)
-
template<typename
Fn>
voidforeach_input(Fn &&fn) const Calls
fnon every input node in the network.The paramater
fnis any callable that must have one of the following two signatures.void(node_type const& node)void(node_type const& node, uint32_t node_index)
-
template<typename
Fn>
voidforeach_output(Fn &&fn) Calls
fnon every output node in the network.The paramater
fnis any callable that must have one of the following two signatures.void(node_type const& node)void(node_type const& node, uint32_t node_index)
-
template<typename
Fn>
voidforeach_gate(Fn &&fn, uint32_t start = 0u) const Calls
fnon every unitrary gate node in the network.The paramater
fnis any callable that must have one of the following four signatures.void(node_type const& node)void(node_type const& node, uint32_t node_index)bool(node_type const& node)bool(node_type const& node, uint32_t node_index)
The paramater
startis a index to a starting point.If
fnreturns abool, then it can interrupt the iteration by returningfalse.
-
template<typename
Fn>
voidforeach_node(Fn &&fn) const Calls
fnon every node in the network.The paramater
fnis any callable that must have one of the following four signatures.void(node_type const& node)void(node_type const& node, uint32_t node_index)bool(node_type const& node)bool(node_type const& node, uint32_t node_index)
If
fnreturns abool, then it can interrupt the iteration by returningfalse.
-
template<typename