Template Class DynamicDispatcher¶
Defined in File DynamicDispatcher.hpp
Class Documentation¶
-
template<typename PrecisionT>
class DynamicDispatcher¶ DynamicDispatcher class.
This is a singleton class that can call a gate/generator operation dynamically. Currently, all gate operations (gates/generators/matrices) are registered to this class when the library is loaded. As all functions besides registration functions are already thread-safe, we can use this class in multithreading environment without any problem. In addition, adding mutex is not required unless kernel functions are registered in multiple threads.
Public Types
-
using CFP_t = std::complex<PrecisionT>¶
-
using GateFunc = std::function<void(std::complex<PrecisionT>*, size_t, const std::vector<size_t>&, bool, const std::vector<PrecisionT>&)>¶
-
using GeneratorFunc = Gates::GeneratorFuncPtrT<PrecisionT>¶
-
using MatrixFunc = Gates::MatrixFuncPtrT<PrecisionT>¶
Public Functions
-
DynamicDispatcher(const DynamicDispatcher&) = delete¶
-
DynamicDispatcher(DynamicDispatcher&&) = delete¶
-
DynamicDispatcher &operator=(const DynamicDispatcher&) = delete¶
-
DynamicDispatcher &operator=(DynamicDispatcher&&) = delete¶
-
~DynamicDispatcher() = default¶
-
inline auto registeredKernels() const -> std::vector<Gates::KernelType>¶
Get all registered kernels.
-
inline auto isRegisteredKernel(Gates::KernelType kernel) const¶
Check whether the kernel is registered to a dispatcher.
-
inline void registerKernelName(Gates::KernelType kernel, std::string name)¶
Register kernel name.
- Parameters
kernel – Kernel
name – Name of the kernel
-
inline auto getKernelName(Gates::KernelType kernel) const -> std::string¶
Get registered name of the kernel.
- Parameters
kernel – Kernel
-
inline auto registeredGatesForKernel(Gates::KernelType kernel) const -> std::unordered_set<Gates::GateOperation>¶
Get registered gates for the given kernel.
- Parameters
kernel – Kernel
-
inline auto registeredGeneratorsForKernel(Gates::KernelType kernel) const -> std::unordered_set<Gates::GeneratorOperation>¶
-
inline auto registeredMatricesForKernel(Gates::KernelType kernel) const -> std::unordered_set<Gates::MatrixOperation>¶
-
inline auto strToGateOp(const std::string &gate_name) const -> Gates::GateOperation¶
Gate name to gate operation.
- Parameters
gate_name – Gate name
-
inline auto strToGeneratorOp(const std::string &gntr_name) const -> Gates::GeneratorOperation¶
Generator name to generator operation.
- Parameters
gntr_name – Generator name without “Generator” prefix
-
template<typename FunctionType>
inline void registerGateOperation(Gates::GateOperation gate_op, Gates::KernelType kernel, FunctionType &&func)¶ Register a new gate operation for the operation. Can pass a custom kernel.
-
template<typename FunctionType>
inline void registerGeneratorOperation(Gates::GeneratorOperation gntr_op, Gates::KernelType kernel, FunctionType &&func)¶ Register a new gate generator for the operation. Can pass a custom kernel.
-
inline void registerMatrixOperation(Gates::MatrixOperation mat_op, Gates::KernelType kernel, MatrixFunc func)¶
Register a new matrix operation. Can pass a custom kernel.
-
inline bool isRegistered(Gates::GateOperation gate_op, Gates::KernelType kernel) const¶
Check if a kernel function is registered for the given gate operation and kernel.
- Parameters
gate_op – Gate operation
kernel – Kernel
-
inline bool isRegistered(Gates::GeneratorOperation gntr_op, Gates::KernelType kernel) const¶
Check if a kernel function is registered for the given generator operation and kernel.
- Parameters
gntr_op – Generator operation
kernel – Kernel
-
inline bool isRegistered(Gates::MatrixOperation mat_op, Gates::KernelType kernel) const¶
Check if a kernel function is registered for the given matrix operation and kernel.
- Parameters
mat_op – Matrix operation
kernel – Kernel
-
inline void applyOperation(Gates::KernelType kernel, CFP_t *data, size_t num_qubits, const std::string &op_name, const std::vector<size_t> &wires, bool inverse, const std::vector<PrecisionT> ¶ms = {}) const¶
Apply a single gate to the state-vector using the given kernel.
- Parameters
kernel – Kernel to run the gate operation.
data – Pointer to data.
num_qubits – Number of qubits.
op_name – Gate operation name.
wires – Wires to apply gate to.
inverse – Indicates whether to use inverse of gate.
params – Optional parameter list for parametric gates.
-
inline void applyOperation(Gates::KernelType kernel, CFP_t *data, size_t num_qubits, Gates::GateOperation gate_op, const std::vector<size_t> &wires, bool inverse, const std::vector<PrecisionT> ¶ms = {}) const¶
Apply a single gate to the state-vector using the given kernel.
- Parameters
kernel – Kernel to run the gate operation.
data – Pointer to data.
num_qubits – Number of qubits.
gate_op – Gate operation.
wires – Wires to apply gate to.
inverse – Indicates whether to use inverse of gate.
params – Optional parameter list for parametric gates.
-
inline void applyOperations(Gates::KernelType kernel, CFP_t *data, size_t num_qubits, const std::vector<std::string> &ops, const std::vector<std::vector<size_t>> &wires, const std::vector<bool> &inverse, const std::vector<std::vector<PrecisionT>> ¶ms) const¶
Apply multiple gates to the state-vector using a registered kernel.
- Parameters
data – Pointer to data.
num_qubits – Number of qubits.
ops – List of Gate operation names.
wires – List of wires to apply each gate to.
inverse – List of inverses
params – List of parameters
-
inline void applyOperations(Gates::KernelType kernel, CFP_t *data, size_t num_qubits, const std::vector<std::string> &ops, const std::vector<std::vector<size_t>> &wires, const std::vector<bool> &inverse) const¶
Apply multiple (non-parameterized) gates to the state-vector using a registered kernel.
- Parameters
data – Pointer to data.
num_qubits – Number of qubits.
ops – List of Gate operation names.
wires – List of wires to apply each gate to.
inverse – List of inverses
-
inline void applyMatrix(Gates::KernelType kernel, CFP_t *data, size_t num_qubits, const std::complex<PrecisionT> *matrix, const std::vector<size_t> &wires, bool inverse) const¶
Apply a given matrix directly to the statevector.
- Parameters
kernel – Kernel to use for this operation
data – Pointer to the statevector.
num_qubits – Number of qubits.
matrix – Perfect square matrix in row-major order.
wires – Wires the gate applies to.
inverse – Indicate whether inverse should be taken.
-
inline void applyMatrix(Gates::KernelType kernel, CFP_t *data, size_t num_qubits, const std::vector<std::complex<PrecisionT>> &matrix, const std::vector<size_t> &wires, bool inverse) const¶
Apply a given matrix directly to the statevector.
- Parameters
kernel – Kernel to use for this operation
data – Pointer to the statevector.
num_qubits – Number of qubits.
matrix – Perfect square matrix in row-major order.
wires – Wires the gate applies to.
inverse – Indicate whether inverse should be taken.
-
inline auto applyGenerator(Gates::KernelType kernel, CFP_t *data, size_t num_qubits, Gates::GeneratorOperation gntr_op, const std::vector<size_t> &wires, bool adj) const -> PrecisionT¶
Apply a single generator to the state-vector using the given kernel.
- Parameters
kernel – Kernel to run the gate operation.
data – Pointer to data.
num_qubits – Number of qubits.
gntr_op – Generator operation.
wires – Wires to apply gate to.
adj – Indicates whether to use adjoint of gate.
-
inline auto applyGenerator(Gates::KernelType kernel, CFP_t *data, size_t num_qubits, const std::string &op_name, const std::vector<size_t> &wires, bool adj) const -> PrecisionT¶
Apply a single generator to the state-vector using the given kernel.
- Parameters
kernel – Kernel to run the gate operation.
data – Pointer to data.
num_qubits – Number of qubits.
op_name – Gate operation name.
wires – Wires to apply gate to.
adj – Indicates whether to use adjoint of gate.
Public Static Functions
-
static inline DynamicDispatcher &getInstance()¶
Get the singleton instance.
-
using CFP_t = std::complex<PrecisionT>¶