src/simulators/tensor_network/tensor_network_state.hpp
//=========================================================================
// Implementation: Kraus Noise
// This function has not been checked yet
//=========================================================================
Kraus Noise
This function has not been checked yet
Kraus Noise This function has not been checked yet
void State::apply_kraus(const reg_t &qubits,
                        const std::vector<cmatrix_t> &kmats,
                        RngEngine &rng) {
  if (kmats.empty())
    return; 
  double r = rng.rand(0., 1.);
  double accum = 0.;
  bool complete = false;
  for (size_t j=0; j < kmats.size() - 1; j++) {
    cvector_t vmat = Utils::vectorize_matrix(kmats[j]);
    double p = qreg_.norm(qubits, vmat);
    accum += p;
    if (accum > r) {
      Utils::scalar_multiply_inplace(vmat, 1 / std::sqrt(p));
      apply_matrix(qubits, vmat);
      complete = true;
      break;
    }
  }
  if (complete == false) {
    complex_t renorm = 1 / std::sqrt(1. - accum);
    apply_matrix(qubits, Utils::vectorize_matrix(renorm * kmats.back()));
  }
}
void State :: apply_kraus ( const reg_t & qubits , const std :: vector < cmatrix_t > & kmats , RngEngine & rng ) { if ( kmats . empty ( ) ) return ; double r = rng . rand ( 0. , 1. ) ; double accum = 0. ; bool complete = false ; for ( size_t j = 0 ; j < kmats . size ( ) - 1 ; j ++ ) { cvector_t vmat = Utils :: vectorize_matrix ( kmats [ j ] ) ; double p = qreg_ . norm ( qubits , vmat ) ; accum += p ; if ( accum > r ) { Utils :: scalar_multiply_inplace ( vmat , 1 / std :: sqrt ( p ) ) ; apply_matrix ( qubits , vmat ) ; complete = true ; break ; } } if ( complete == false ) { complex_t renorm = 1 / std :: sqrt ( 1. - accum ) ; apply_matrix ( qubits , Utils :: vectorize_matrix ( renorm * kmats . back ( ) ) ) ; } }
Implementation: Kraus Noise
This function has not been checked yet
Implementation : Kraus Noise This function has not been checked yet
// Check edge case for empty Kraus set (this shouldn't happen) // end function early // Choose a real in [0, 1) to choose the applied kraus operator once // the accumulated probability is greater than r. // We know that the Kraus noise must be normalized // So we only compute probabilities for the first N-1 kraus operators // and infer the probability of the last one from 1 - sum of the previous // Loop through N-1 kraus operators // Calculate probability // check if we need to apply this operator // rescale vmat so projection is normalized // apply Kraus projection operator // check if we haven't applied a kraus operator yet // Compute probability from accumulated