Skip to content

3. Data types, constants and global objects

Vlad Gheorghiu edited this page Jan 24, 2022 · 8 revisions

All header files of Quantum++ are located inside the include directory. All functions, classes and global objects defined by the library belong to the namespace qpp. To avoid additional typing, we will omit the prefix qpp:: in the rest of this document.

Data types

The most important data types are defined in the header file types.hpp. We list them in the table below.

Type Description
idx Index (non-negative integer), alias for std::size_t
bigint Big integer, alias for long long int
cplx Complex number, alias for std::complex<double>
cmat Complex dynamic matrix, alias for Eigen::MatrixXcd
dmat Double dynamic matrix, alias for Eigen::MatrixXd
ket Complex dynamic column vector, alias for Eigen::VectorXcd
bra Complex dynamic row vector, alias for Eigen::RowVectorXcd
dyn_mat<Scalar> Dynamic matrix template alias over the field Scalar, alias for Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>
dyn_col_vect<Scalar> Dynamic column vector template alias over the field Scalar, alias for Eigen::Matrix<Scalar, Eigen::Dynamic, 1>
dyn_row_vect<Scalar> Dynamic row vector template alias over the field Scalar, alias for Eigen::Matrix<Scalar, 1, Eigen::Dynamic>
qram Quantumly-accessible Random Access Memory (qRAM), alias for std::vector<idx>

Constants

The important constants are defined in the header file constants.hpp and are listed in below.

Constant Description
constexpr double pi = 3.1415...; $\pi$
constexpr double ee = 2.7182...; $e$, base of natural logarithms
constexpr double chop = 1e-14; Used in display manipulators to set numbers to zero
constexpr double infty = ...; Used to denote infinity in double precision
constexpr cplx operator""_i (unsigned long long int x) User-defined literal for the imaginary number $i:=\sqrt{-1}$
constexpr cplx operator""_i (unsigned long double int x) User-defined literal for the imaginary number $i:=\sqrt{-1}$
cplx omega(idx D) $D$-th root of unity $e^{2\pi i/D}$

Singleton classes and their global instances

Some useful classes are defined as singletons and their instances are globally available, being initialized at runtime in the header file qpp.h, before main(). They are listed below.

Singleton Description
const Init& init = Init::get_instance(); Library initialization
const Codes& codes = Codes::get_instance(); Quantum error correcting codes
const Gates& gt = Gates::get_instance(); Quantum gates
const States& st = States::get_instance(); Quantum states
RandomDevices& rdevs = RandomDevices::get_thread_local_instance(); Random devices/generators/engines