# Noise Models and Open System Simulation **Noise models** simulate realistic hardware imperfections: depolarizing errors, dephasing, amplitude damping. CUDA-Q integrates with [[qutip|QuTiP]] for open system simulation. ```cpp #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( {"h", "rx", "ry", "rz"}, 0.01 ); // 2% depolarizing error on 2-qubit gates noise_model.add_channel( {"cx", "cz"}, 0.02 ); // 1% readout error noise_model.add_channel( 0.01 ); // Set noisy backend cudaq::set_target("density_matrix"); // Use density matrix for mixed states // Execute with noise auto noisy_result = cudaq::sample(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(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.