Maestro 0.3.11
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
GenericGateValidation.h
Go to the documentation of this file.
1#pragma once
3#include <algorithm>
4#include <cmath>
5#include <initializer_list>
6
7namespace Simulators
8{
9// Shared validation for public language and C bindings. Generic operators need
10// not be unitary; the simulator decides whether it supports the operation.
11template <class Matrix> void ValidateGenericGate(const ISimulator &simulator, std::initializer_list<Types::qubit_t> targets, const Matrix &matrix)
12{
13 for (auto it = targets.begin(); it != targets.end(); ++it)
14 {
15 if (*it >= simulator.GetNumberOfQubits())
16 throw std::invalid_argument("Generic gate target is out of range");
17 if (std::find(targets.begin(), it, *it) != it)
18 throw std::invalid_argument("Generic gate targets must be distinct");
19 }
20 const auto dimension = Eigen::Index{1} << targets.size();
21 if (matrix.rows() != dimension || matrix.cols() != dimension)
22 throw std::invalid_argument("Generic gate matrix has the wrong dimensions");
23 if (!matrix.allFinite())
24 throw std::invalid_argument("Generic gate matrix must contain finite values");
25}
26} // namespace Simulators
Interface class for a quantum computing simulator.
Definition Simulator.h:41
virtual size_t GetNumberOfQubits() const =0
Returns the number of qubits.
Bounded online routing based on current physical bond dimensions.
void ValidateGenericGate(const ISimulator &simulator, std::initializer_list< Types::qubit_t > targets, const Matrix &matrix)