43 inline double rand(
double a = 0,
double b = 1)
45 std::uniform_real_distribution<> ud(a, b);
47 #ifndef _NO_THREAD_LOCAL
51 #endif // _NO_THREAD_LOCAL
63 bigint b = std::numeric_limits<bigint>::max())
65 std::uniform_int_distribution<bigint> uid(a, b);
67 #ifndef _NO_THREAD_LOCAL
71 #endif // _NO_THREAD_LOCAL
83 ubigint b = std::numeric_limits<ubigint>::max())
85 std::uniform_int_distribution<ubigint> uid(a, b);
87 #ifndef _NO_THREAD_LOCAL
91 #endif // _NO_THREAD_LOCAL
103 idx b = std::numeric_limits<idx>::max())
105 std::uniform_int_distribution<idx> uid(a, b);
107 #ifndef _NO_THREAD_LOCAL
111 #endif // _NO_THREAD_LOCAL
125 template<
typename Derived>
160 if (rows == 0 || cols == 0)
163 return dmat::Zero(rows, cols).unaryExpr(
194 if (rows == 0 || cols == 0)
197 return rand<dmat>(rows, cols, a, b).cast<cplx>() +
198 1_i * rand<dmat>(rows, cols, a, b).cast<cplx>();
212 template<
typename Derived>
247 double mean,
double sigma)
249 if (rows == 0 || cols == 0)
252 std::normal_distribution<> nd(mean, sigma);
254 return dmat::Zero(rows, cols).unaryExpr(
257 #ifndef _NO_THREAD_LOCAL
261 #endif // _NO_THREAD_LOCAL
288 double mean,
double sigma)
290 if (rows == 0 || cols == 0)
293 return randn<dmat>(rows, cols, mean,
sigma).cast<cplx>() +
294 1_i * randn<dmat>(rows, cols, mean,
sigma).cast<cplx>();
307 std::normal_distribution<> nd(mean,
sigma);
309 #ifndef _NO_THREAD_LOCAL
313 #endif // _NO_THREAD_LOCAL
331 X = 1 / std::sqrt(2.) * randn < cmat > (D, D);
332 Eigen::HouseholderQR<cmat> qr(X);
334 cmat Q = qr.householderQ();
338 Eigen::VectorXcd phases = (rand<dmat>(D, 1)).cast<
cplx>();
339 for (
idx i = 0; i < static_cast<idx>(phases.rows()); ++i)
340 phases(i) = std::exp(2 *
pi * 1_i * phases(i));
342 Q = Q * phases.asDiagonal();
356 if (Din == 0 || Dout == 0 || Din > Dout)
359 return randU(Dout).block(0, 0, Dout, Din);
379 std::vector <cmat> result(N);
380 for (
idx i = 0; i < N; ++i)
381 result[i] = cmat::Zero(D, D);
386 #pragma omp parallel for collapse(3)
387 for (
idx k = 0; k < N; ++k)
388 for (
idx a = 0; a < D; ++a)
389 for (
idx b = 0; b < D; ++b)
390 result[k](a, b) = U(a * N + k, b * N);
406 cmat H = 2 * rand<cmat>(D, D) - (1. + 1_i) * cmat::Ones(D, D);
429 ket kt = randn < cmat > (D, 1);
431 return kt /
norm(kt);
446 result = result *
adjoint(result);
448 return result /
trace(result);
465 std::vector <idx> result(n);
468 std::iota(std::begin(result), std::end(result), 0);
470 #ifndef _NO_THREAD_LOCAL
471 std::shuffle(std::begin(result), std::end(result),
474 std::shuffle(std::begin(result), std::end(result),
476 #endif // _NO_THREAD_LOCAL
static thread_local RandomDevices & get_thread_local_instance() noexcept(std::is_nothrow_constructible< RandomDevices >::value)
Definition: singleton.h:102
idx randidx(idx a=std::numeric_limits< idx >::min(), idx b=std::numeric_limits< idx >::max())
Generates a random index (idx) uniformly distributed in the interval [a, b].
Definition: random.h:102
Eigen::MatrixXd dmat
Real (double precision) dynamic Eigen matrix.
Definition: types.h:71
unsigned long long int ubigint
Non-negative big integer.
Definition: types.h:46
std::vector< cmat > randkraus(idx N, idx D)
Generates a set of random Kraus operators.
Definition: random.h:372
ket randket(idx D)
Generates a random normalized ket (pure state vector)
Definition: random.h:417
Eigen::VectorXcd ket
Complex (double precision) dynamic Eigen column vector.
Definition: types.h:56
Quantum++ main namespace.
Definition: codes.h:30
double norm(const Eigen::MatrixBase< Derived > &A)
Frobenius norm.
Definition: functions.h:231
std::vector< idx > randperm(idx n)
Generates a random uniformly distributed permutation.
Definition: random.h:460
dyn_mat< typename Derived::Scalar > adjoint(const Eigen::MatrixBase< Derived > &A)
Adjoint.
Definition: functions.h:84
double sigma(const std::vector< double > &prob, const Container &X)
Standard deviation.
Definition: statistics.h:181
std::complex< double > cplx
Complex number in double precision.
Definition: types.h:51
Generates custom exceptions, used when validating function parameters.
Definition: exception.h:39
Derived randn(idx rows, idx cols, double mean=0, double sigma=1)
Generates a random matrix with entries normally distributed in N(mean, sigma)
Definition: random.h:213
cmat randU(idx D)
Generates a random unitary matrix.
Definition: random.h:322
Derived::Scalar trace(const Eigen::MatrixBase< Derived > &A)
Trace.
Definition: functions.h:121
constexpr double pi
Definition: constants.h:85
cmat randH(idx D)
Generates a random Hermitian matrix.
Definition: random.h:401
double rand(double a=0, double b=1)
Generates a random real number uniformly distributed in the interval [a, b)
Definition: random.h:43
static RandomDevices & get_instance() noexcept(std::is_nothrow_constructible< RandomDevices >::value)
Definition: singleton.h:90
long long int bigint
Big integer.
Definition: types.h:41
Eigen::MatrixXcd cmat
Complex (double precision) dynamic Eigen matrix.
Definition: types.h:66
cmat randrho(idx D)
Generates a random density matrix.
Definition: random.h:440
std::size_t idx
Non-negative integer index.
Definition: types.h:36
cmat randV(idx Din, idx Dout)
Generates a random isometry matrix.
Definition: random.h:354