28 : qbit_num_(qbit_num), error_rate_(error_rate) {
29 if (error_rate < 0.0 || error_rate > 1.0) {
30 throw std::invalid_argument(
31 "DepolarizingChannel: error_rate must be in [0,1]");
39 throw std::runtime_error(
40 "DepolarizingChannel::apply: qubit number mismatch");
45 double trace_val = tr.
real;
49 double identity_factor = depol_prob * trace_val;
51 for (
int i = 0; i < dim; i++) {
52 for (
int j = 0; j < dim; j++) {
73 : target_qbit_(target_qbit), gamma_(gamma) {
74 if (gamma < 0.0 || gamma > 1.0) {
75 throw std::invalid_argument(
76 "AmplitudeDampingChannel: gamma must be in [0,1]");
84 if (target_qbit_ < 0 || target_qbit_ >= qbit_num) {
85 throw std::runtime_error(
86 "AmplitudeDampingChannel::apply: target_qbit out of range");
100 for (
int i = 0; i < dim; i++) {
101 for (
int j = 0; j < dim; j++) {
104 bool i_target = (i & target_step) != 0;
105 bool j_target = (j & target_step) != 0;
108 if (i_target == j_target) {
109 double factor = i_target ? (1.0 -
gamma_) : 1.0;
110 rho_new(i, j).real += factor * rho(i, j).real;
111 rho_new(i, j).imag += factor * rho(i, j).imag;
115 if (!i_target && !j_target) {
116 int i_flip = i | target_step;
117 int j_flip = j | target_step;
118 rho_new(i, j).real +=
gamma_ * rho(i_flip, j_flip).real;
119 rho_new(i, j).imag +=
gamma_ * rho(i_flip, j_flip).imag;
134 if (lambda < 0.0 || lambda > 1.0) {
135 throw std::invalid_argument(
"PhaseDampingChannel: lambda must be in [0,1]");
143 if (target_qbit_ < 0 || target_qbit_ >= qbit_num) {
144 throw std::runtime_error(
145 "PhaseDampingChannel::apply: target_qbit out of range");
155 for (
int i = 0; i < dim; i++) {
156 for (
int j = 0; j < dim; j++) {
157 bool i_target = (i & target_step) != 0;
158 bool j_target = (j & target_step) != 0;
161 if (i_target != j_target) {
162 rho(i, j).real *= std::sqrt(1.0 -
lambda_);
163 rho(i, j).imag *= std::sqrt(1.0 -
lambda_);
void apply(DensityMatrix &rho) override
Apply noise channel to density matrix.
PhaseDampingChannel(int target_qbit, double lambda)
Constructor.
void apply(DensityMatrix &rho) override
Apply noise channel to density matrix.
scalar * data
pointer to the stored data
DepolarizingChannel(int qbit_num, double error_rate)
Constructor.
double lambda_
λ = 1 - exp(-t/T2)
AmplitudeDampingChannel(int target_qbit, double gamma)
Constructor.
Quantum density matrix Ï for mixed-state representation.
QGD_Complex16 trace() const
Calculate trace: Tr(Ï)
Structure type representing complex numbers in the SQUANDER package.
double gamma_
γ = 1 - exp(-t/T1)
int get_qbit_num() const
Get number of qubits.
void apply(DensityMatrix &rho) override
Apply noise channel to density matrix.
int get_dim() const
Get matrix dimension (2^qbit_num)
double real
the real part of a complex number
double imag
the imaginary part of a complex number