18#include <tklog/TketLog.hpp>
28typedef Eigen::Matrix<bool, Eigen::Dynamic, Eigen::Dynamic>
MatrixXb;
29typedef Eigen::Matrix<bool, Eigen::Dynamic, 1>
VectorXb;
32typedef Eigen::Matrix<std::complex<double>, 8, 8>
Matrix8cd;
61Eigen::PermutationMatrix<Eigen::Dynamic>
lift_perm(
62 const std::map<unsigned, unsigned> &p);
71 const Eigen::MatrixXcd &m,
const qubit_map_t &perm);
73 const Eigen::VectorXcd &v,
const qubit_map_t &perm);
77 const MatrixXb &a,
unsigned blocksize = 6);
79 const MatrixXb &a,
unsigned blocksize = 6);
98std::tuple<Eigen::Matrix4cd, std::array<double, 3>, Eigen::Matrix4cd>
104 Eigen::Matrix4cd &U);
124 const std::vector<TripletCd> &
triplets,
unsigned rows,
unsigned cols);
127 const std::vector<TripletCd> &
triplets,
unsigned rows);
145 const Eigen::MatrixXcd &matr,
double abs_epsilon =
EPS);
179Eigen::Matrix2cd
nth_root(
const Eigen::Matrix2cd &u,
unsigned long long n);
181template <
class MatrixT>
182static inline MatrixT clamp_to_unitary(
const MatrixT &A) {
187 "Non-unitary product of matrices assumed unitary: "
188 "presuming rounding error and applying correction.");
195 Eigen::JacobiSVD<MatrixT, Eigen::NoQRPreconditioner> svd(
196 A, Eigen::DecompositionOptions::ComputeFullU |
197 Eigen::DecompositionOptions::ComputeFullV);
198 return svd.matrixU() * svd.matrixV().adjoint();
207template <
class MatrixT>
210 return clamp_to_unitary(A);
218template <
class MatrixT>
220 MatrixT A = U *
V * W;
221 return clamp_to_unitary(A);
Generally useful typedefs and constants.
Include this file rather than including the Eigen headers directly.
Functions related to (possibly symbolic) phase values.
std::vector< TripletCd > triplets
Named registers of arrays of (quantum or classical) nodes.
Defines tket::DeviceCharacterisation, used in NoiseAwarePlacement and in commute_SQ_gates_through_SWA...
SparseMatrixXcd get_sparse_matrix(const std::vector< TripletCd > &triplets, unsigned rows, unsigned cols)
Eigen::Matrix< bool, Eigen::Dynamic, 1 > VectorXb
Eigen::Matrix< bool, 2, 1 > Vector2b
Eigen::MatrixXcd apply_qubit_permutation(const Eigen::MatrixXcd &m, const qubit_map_t &perm)
std::map< Qubit, Qubit > qubit_map_t
std::pair< Eigen::Matrix2cd, Eigen::Matrix2cd > kronecker_decomposition(Eigen::Matrix4cd &U)
unsigned get_matrix_size(unsigned number_of_qubits)
Returns 2^n, but throws if n is too large (causes overflow).
Eigen::PermutationMatrix< Eigen::Dynamic > lift_perm(const std::map< unsigned, unsigned > &p)
Lift a permutation of to a permutation of as a matrix.
bool in_weyl_chamber(const std::array< Expr, 3 > &k)
Whether a triplet of TK2 angles are normalised.
bool is_projector(const Eigen::MatrixXcd &P, double tol)
std::vector< TripletCd > get_triplets(const SparseMatrixXcd &matr, double abs_epsilon)
abs_epsilon is used to decide if a near-zero entry should be set to zero exactly.
std::pair< MatrixXb, MatrixXb > binary_LLT_decomposition(const MatrixXb &a)
bool is_unitary(const Eigen::MatrixXcd &U, double tol)
Test matrix for unitarity.
double trace_fidelity(double a, double b, double c)
Similarity measure of TK2(a, b, c) to SU(4) identity.
std::tuple< Eigen::Matrix4cd, std::array< double, 3 >, Eigen::Matrix4cd > get_information_content(const Eigen::Matrix4cd &X)
Performs KAK decomposition.
constexpr double EPS
Default tolerance for floating-point comparisons.
unsigned get_number_of_qubits(unsigned matrix_size)
We have a matrix size, which should be 2^n.
Eigen::Matrix< std::complex< double >, 8, 8 > Matrix8cd
Eigen::SparseMatrix< std::complex< double > > SparseMatrixXcd
SparseMatrixXcd get_sparse_square_matrix(const std::vector< TripletCd > &triplets, unsigned rows)
MatrixT unitary_product3(const MatrixT &U, const MatrixT &V, const MatrixT &W)
Compute the product of three unitary matrices, with error correction.
Eigen::Matrix4cd reverse_indexing(const Eigen::Matrix4cd &m)
std::vector< std::pair< unsigned, unsigned > > gaussian_elimination_col_ops(const MatrixXb &a, unsigned blocksize)
MatrixT unitary_product2(const MatrixT &U, const MatrixT &V)
Compute the product of two unitary matrices, with error correction.
Eigen::Triplet< std::complex< double > > TripletCd
It is sometimes more convenient to deal with Triplets directly, rather than sparse matrices.
Eigen::Matrix2cd nth_root(const Eigen::Matrix2cd &u, unsigned long long n)
Get an nth root of a 2x2 unitary matrix.
std::vector< std::pair< unsigned, unsigned > > gaussian_elimination_row_ops(const MatrixXb &a, unsigned blocksize)
Eigen::Matrix< bool, Eigen::Dynamic, Eigen::Dynamic > MatrixXb