diff --git a/docs/sphinx/api/languages/cpp_api.rst b/docs/sphinx/api/languages/cpp_api.rst index 99e0b2eb07..dc80c6623d 100644 --- a/docs/sphinx/api/languages/cpp_api.rst +++ b/docs/sphinx/api/languages/cpp_api.rst @@ -115,6 +115,8 @@ Noise Modeling .. doxygenclass:: cudaq::noise_model :members: +.. doxygenenum:: cudaq::noise_model_type + Kernel Builder =============== diff --git a/runtime/common/NoiseModel.cpp b/runtime/common/NoiseModel.cpp index 61b1994825..b0a71ecee8 100644 --- a/runtime/common/NoiseModel.cpp +++ b/runtime/common/NoiseModel.cpp @@ -82,7 +82,9 @@ kraus_channel::kraus_channel(std::vector &_ops) : ops(_ops) { validateCompleteness(); } -kraus_channel::kraus_channel(const kraus_channel &other) : ops(other.ops) {} +kraus_channel::kraus_channel(const kraus_channel &other) + : ops(other.ops), noise_type(other.noise_type), + parameters(other.parameters) {} std::size_t kraus_channel::size() const { return ops.size(); } @@ -94,6 +96,8 @@ kraus_op &kraus_channel::operator[](const std::size_t idx) { return ops[idx]; } kraus_channel &kraus_channel::operator=(const kraus_channel &other) { ops = other.ops; + noise_type = other.noise_type; + parameters = other.parameters; return *this; } diff --git a/runtime/common/NoiseModel.h b/runtime/common/NoiseModel.h index 43f95e79cf..2e16258c54 100644 --- a/runtime/common/NoiseModel.h +++ b/runtime/common/NoiseModel.h @@ -19,6 +19,17 @@ namespace cudaq { +/// @brief Noise model enumerated type that allows downstream simulators of +/// `kraus_channel` objects to apply simulator-specific logic for well-known +/// noise models. +enum class noise_model_type { + unknown, + depolarization_channel, + amplitude_damping_channel, + bit_flip_channel, + phase_flip_channel +}; + /// @brief A kraus_op represents a single Kraus operation, /// described as a complex matrix of specific size. The matrix /// is represented here as a 1d array (specifically a std::vector). @@ -107,6 +118,12 @@ class kraus_channel { } public: + /// @brief Noise type enumeration + noise_model_type noise_type = noise_model_type::unknown; + + /// @brief Noise parameter values + std::vector parameters; + ~kraus_channel() = default; /// @brief The nullary constructor @@ -340,6 +357,8 @@ class depolarization_channel : public kraus_channel { k3v{std::sqrt(probability / three), 0, 0, negOne * std::sqrt(probability / three)}; ops = {k0v, k1v, k2v, k3v}; + this->parameters.push_back(probability); + noise_type = noise_model_type::depolarization_channel; validateCompleteness(); } }; @@ -353,6 +372,8 @@ class amplitude_damping_channel : public kraus_channel { std::vector k0v{1, 0, 0, std::sqrt(1 - probability)}, k1v{0, std::sqrt(probability), 0, 0}; ops = {k0v, k1v}; + this->parameters.push_back(probability); + noise_type = noise_model_type::amplitude_damping_channel; validateCompleteness(); } }; @@ -367,6 +388,8 @@ class bit_flip_channel : public kraus_channel { std::sqrt(1 - probability)}, k1v{0, std::sqrt(probability), std::sqrt(probability), 0}; ops = {k0v, k1v}; + this->parameters.push_back(probability); + noise_type = noise_model_type::bit_flip_channel; validateCompleteness(); } }; @@ -382,6 +405,8 @@ class phase_flip_channel : public kraus_channel { std::sqrt(1 - probability)}, k1v{std::sqrt(probability), 0, 0, negOne * std::sqrt(probability)}; ops = {k0v, k1v}; + this->parameters.push_back(probability); + noise_type = noise_model_type::phase_flip_channel; validateCompleteness(); } };