Site Tools


cuda-q-noise-models

Noise Models and Open System Simulation

Noise models simulate realistic hardware imperfections: depolarizing errors, dephasing, amplitude damping. CUDA-Q integrates with QuTiP for open system simulation.

#include "cudaq.h"
#include "cudaq/noise_model.h"
 
// Define noise model
struct NoiseKernel {
  void operator()() __qpu__ {
    cudaq::qvector q(2);
    h(q[0]);
    cx(q[0], q[1]);
    mz(q);
  }
};
 
int main() {
  // Create depolarizing noise model
  cudaq::noise_model noise_model;
 
  // 1% depolarizing error on all 1-qubit gates
  noise_model.add_channel<cudaq::channels::depolarizing>(
      {"h", "rx", "ry", "rz"},
      0.01
  );
 
  // 2% depolarizing error on 2-qubit gates
  noise_model.add_channel<cudaq::channels::depolarizing>(
      {"cx", "cz"},
      0.02
  );
 
  // 1% readout error
  noise_model.add_channel<cudaq::channels::readout_error>(
      0.01
  );
 
  // Set noisy backend
  cudaq::set_target("density_matrix");  // Use density matrix for mixed states
 
  // Execute with noise
  auto noisy_result = cudaq::sample<NoiseKernel>(1000);
  printf("Noisy result:\n");
  for (auto& [bits, count] : noisy_result) {
    printf("  %s: %lu\n", bits.c_str(), count);
  }
 
  // Compare with ideal (no noise)
  cudaq::set_target("qpp");  // Ideal simulator
  auto ideal_result = cudaq::sample<NoiseKernel>(1000);
  printf("Ideal result:\n");
  for (auto& [bits, count] : ideal_result) {
    printf("  %s: %lu\n", bits.c_str(), count);
  }
 
  return 0;
}

Noise simulation is critical for designing robust algorithms before deployment to noisy hardware.

cuda-q-noise-models.md · Last modified: by 127.0.0.1