32 #ifndef CLASSES_NOISE_H_ 33 #define CLASSES_NOISE_H_ 62 std::is_same<NoiseType::StateDependent, noise_type>::value ||
63 std::is_same<NoiseType::StateIndependent, noise_type>::value,
67 const std::vector<cmat>
Ks_;
83 const std::vector<idx>& target)
const {
84 if (!std::is_same<NoiseType::StateDependent, noise_type>::value)
96 for (
idx i = 0; i <
Ks_.size(); ++i) {
110 const std::vector<idx>& target)
const {
112 idx D =
static_cast<idx>(state.rows());
125 "qpp::NoiseBase::compute_state_()");
128 std::discrete_distribution<idx> dd{std::begin(
probs_),
131 #ifdef NO_THREAD_LOCAL_ 153 template <
typename U = noise_type>
155 const std::vector<cmat>& Ks,
156 typename std::enable_if<
157 std::is_same<NoiseType::StateDependent, U>::value>::type* =
nullptr)
167 for (
auto&& elem : Ks)
168 if (elem.rows() != Ks[0].rows() || elem.cols() != Ks[0].rows())
184 template <
typename U = noise_type>
186 const std::vector<cmat>& Ks,
const std::vector<double>& probs,
188 U>::value>::type* =
nullptr)
194 if (Ks.size() != probs.size())
200 for (
auto&& elem : Ks)
201 if (elem.rows() != Ks[0].rows() || elem.cols() != Ks[0].rows())
203 for (
auto&& elem : probs)
204 if (elem < 0 || elem > 1)
239 std::is_same<NoiseType::StateIndependent, noise_type>::value) {
243 "qpp::NoiseBase::get_probs()",
244 "NoiseBase::operator() was not yet invoked");
257 "qpp::NoiseBase::get_last_idx()",
258 "NoiseBase::operator() was not yet invoked");
271 "qpp::NoiseBase::get_last_p()",
272 "NoiseBase::operator() was not yet invoked");
285 "qpp::NoiseBase::get_last_K()",
286 "NoiseBase::operator() was not yet invoked");
304 std::cerr <<
"In qpp::NoiseBase::operator()\n";
326 std::cerr <<
"In qpp::NoiseBase::operator()\n";
343 const std::vector<idx>& target)
const {
349 std::cerr <<
"In qpp::NoiseBase::operator()\n";
373 {1 - p, p / 3, p / 3, p / 3}) {
377 throw exception::OutOfRange(
378 "qpp::QubitDepolarizingNoise::QubitDepolarizingNoise()");
400 throw exception::OutOfRange(
401 "qpp::QubitPhaseFlipNoise::QubitPhaseFlipNoise()");
423 throw exception::OutOfRange(
424 "qpp::QubitBitFlipNoise::QubitBitFlipNoise()");
446 throw exception::OutOfRange(
447 "qpp::QubitBitPhaseFlipNoise::QubitBitPhaseFlipNoise()");
465 ((
cmat(2, 2)) << 1, 0, 0, std::sqrt(gamma)).finished(),
466 ((
cmat(2, 2)) << 0, std::sqrt(1 - gamma), 0, 0).finished()}) {
469 if (gamma < 0 || gamma > 1)
471 "QubitAmplitudeDampingNoise()");
489 ((
cmat(2, 2)) << 1, 0, 0, std::sqrt(1 - lambda)).finished(),
490 ((
cmat(2, 2)) << 0, 0, 0, std::sqrt(lambda)).finished()}) {
493 if (lambda < 0 || lambda > 1)
495 "QubitPhaseDampingNoise()");
514 std::vector<cmat> Ks(d * d);
516 for (
idx i = 0; i < d; ++i)
517 for (
idx j = 0; j < d; ++j)
532 std::vector<double> probs(d * d);
534 for (
idx i = 1; i < d * d; ++i)
535 probs[i] = p / (d - 1) * (d - 1);
551 if (d < 2 || p < 0 || p > 1)
553 "qpp::QuditDepolarizingNoise::QuditDepolarizingNoise()");
bool check_nonzero_size(const T &x) noexcept
Definition: util.h:123
Dimensions not equal exception.
Definition: exception.h:284
Qudit depolarizing noise.
Definition: noise.h:506
bool check_cvector(const Eigen::MatrixBase< Derived > &A)
Definition: util.h:117
double get_last_p() const
Probability of the last occurring noise element.
Definition: noise.h:266
QubitDepolarizingNoise(double p)
Qubit depolarizing noise constructor.
Definition: noise.h:370
Custom exception.
Definition: exception.h:600
QubitBitFlipNoise(double p)
Qubit bit flip noise constructor.
Definition: noise.h:417
std::mt19937 & get_prng()
Returns a reference to the internal PRNG object.
Definition: random_devices.h:61
std::vector< double > fill_probs_(double p, idx d) const
Fills the probability vector.
Definition: noise.h:531
QubitBitPhaseFlipNoise(double p)
Qubit bit-phase flip noise constructor.
Definition: noise.h:440
std::vector< cmat > fill_Ks_(idx d) const
Fills the Kraus operator vector.
Definition: noise.h:513
Quantum++ main namespace.
Definition: circuits.h:35
Qubit bit flip noise.
Definition: noise.h:410
Matrix is not square nor column vector exception.
Definition: exception.h:209
idx get_d() const noexcept
Qudit dimension.
Definition: noise.h:223
idx get_num_subsys(idx D, idx d)
Definition: util.h:370
virtual cmat operator()(const cmat &state) const
Function invocation operator, applies the underlying noise model on the state vector or density matri...
Definition: noise.h:297
Qubit depolarizing noise.
Definition: noise.h:363
NoiseBase(const std::vector< cmat > &Ks, typename std::enable_if< std::is_same< NoiseType::StateDependent, U >::value >::type *=nullptr)
Constructs a noise instance for StateDependent noise type.
Definition: noise.h:154
dyn_mat< typename Derived::Scalar > ptrace(const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &target, const std::vector< idx > &dims)
Partial trace.
Definition: operations.h:1187
dyn_mat< typename Derived1::Scalar > apply(const Eigen::MatrixBase< Derived1 > &state, const Eigen::MatrixBase< Derived2 > &A, const std::vector< idx > &target, const std::vector< idx > &dims)
Applies the gate A to the part target of the multi-partite state vector or density matrix state...
Definition: operations.h:444
bool generated_
invoked, or if the noise is state-independent
Definition: noise.h:72
virtual ~NoiseBase()=default
Default virtual destructor.
dyn_mat< typename Derived::Scalar > adjoint(const Eigen::MatrixBase< Derived > &A)
Adjoint.
Definition: functions.h:89
QuditDepolarizingNoise(double p, idx d)
Qudit depolarizing noise constructor.
Definition: noise.h:547
static RandomDevices & get_thread_local_instance() noexcept(std::is_nothrow_constructible< RandomDevices >::value)
Definition: singleton.h:103
std::vector< double > probs_
probabilities
Definition: noise.h:68
cmat Id2
Identity gate.
Definition: gates.h:46
cmat get_last_K() const
Last occurring noise element.
Definition: noise.h:280
Qubit bit-phase flip (dephasing) noise.
Definition: noise.h:433
std::vector< double > get_probs() const
Vector of probabilities corresponding to each noise operator.
Definition: noise.h:237
std::vector< cmat > get_Ks() const
Vector of noise operators.
Definition: noise.h:230
cmat X
Pauli Sigma-X gate.
Definition: gates.h:48
virtual cmat operator()(const cmat &state, const std::vector< idx > &target) const
Function invocation operator, applies the underlying correlated noise model on qudits specified by ta...
Definition: noise.h:342
Template tag, used whenever the noise is state-independent.
Definition: noise.h:45
Contains template tags used to specify the noise type.
Definition: noise.h:40
virtual cmat operator()(const cmat &state, idx target) const
Function invocation operator, applies the underlying noise model on qudit target of the multi-partite...
Definition: noise.h:320
Qubit phase flip (dephasing) noise.
Definition: noise.h:387
dyn_mat< typename Derived::Scalar > powm(const Eigen::MatrixBase< Derived > &A, idx n)
Fast matrix power based on the SQUARE-AND-MULTIPLY algorithm.
Definition: functions.h:800
Template tag, used whenever the noise is state-dependent.
bool check_square_mat(const Eigen::MatrixBase< Derived > &A)
Definition: util.h:99
Derived::Scalar trace(const Eigen::MatrixBase< Derived > &A)
Trace.
Definition: functions.h:130
idx d_
qudit dimension
Definition: noise.h:69
Base class for all noise models, derive your particular noise model.
Definition: noise.h:58
void compute_probs_(const cmat &state, const std::vector< idx > &target) const
Compute probability outcomes for StateDependent noise type, otherwise returns without performing any ...
Definition: noise.h:82
Argument out of range exception.
Definition: exception.h:515
QubitPhaseDampingNoise(double lambda)
Qubit phase damping noise constructor.
Definition: noise.h:487
idx get_last_idx() const
Index of the last occurring noise element.
Definition: noise.h:252
static RandomDevices & get_instance() noexcept(std::is_nothrow_constructible< RandomDevices >::value)
Definition: singleton.h:92
Eigen::MatrixXcd cmat
Complex (double precision) dynamic Eigen matrix.
Definition: types.h:64
Qubit phase damping noise, as described in Nielsen and Chuang.
Definition: noise.h:480
Qubit amplitude damping noise, as described in Nielsen and Chuang.
Definition: noise.h:456
cmat compute_state_(const cmat &state, const std::vector< idx > &target) const
Compute the resulting state after the noise was applied.
Definition: noise.h:109
QubitAmplitudeDampingNoise(double gamma)
Qubit amplitude damping noise constructor.
Definition: noise.h:463
Size mismatch exception.
Definition: exception.h:543
std::size_t idx
Non-negative integer index, make sure you use an unsigned type.
Definition: types.h:39
cmat Z
Pauli Sigma-Z gate.
Definition: gates.h:50
Matrix is not square exception.
Definition: exception.h:149
std::vector< idx > complement(std::vector< idx > subsys, idx n)
Constructs the complement of a subsystem vector.
Definition: functions.h:1780
cmat Y
Pauli Sigma-Y gate.
Definition: gates.h:49
QubitPhaseFlipNoise(double p)
Qubit phase flip (dephasing) noise constructor.
Definition: noise.h:394
dyn_mat< typename Derived::Scalar > normalize(const Eigen::MatrixBase< Derived > &A)
Normalizes state vector (column or row vector) or density matrix.
Definition: functions.h:270
NoiseBase(const std::vector< cmat > &Ks, const std::vector< double > &probs, typename std::enable_if< std::is_same< NoiseType::StateIndependent, U >::value >::type *=nullptr)
Constructs a noise instance for StateIndependent noise type.
Definition: noise.h:185
idx i_
index of the last occurring noise element
Definition: noise.h:71
const std::vector< cmat > Ks_
Kraus operators.
Definition: noise.h:64
Base class for generating Quantum++ custom exceptions.
Definition: exception.h:71
Object has zero size exception.
Definition: exception.h:134