Gate interface 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_qubits;
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, qubit_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, qubit_id control, qubit_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<qubit_id> const &controls, std::vector<qubit_id> const &targets)

Construct a gate using vectors.

Parameters
  • unitary_op: the operation (must be unitary operation).
  • control: 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.

Iterators

class gate

Public Functions

template <typename Fn>
void foreach_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(qubit_id)
  • bool(qubit_id)

If fn returns a bool, then it can interrupt the iteration by returning false.

template <typename Fn>
void foreach_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(qubit_id)