Skip to content

Commit

Permalink
Add enumerated noise_model_type to noise interface (#2200)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmhowe23 authored Oct 7, 2024
1 parent ebaf920 commit aa6d2dd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/sphinx/api/languages/cpp_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ Noise Modeling
.. doxygenclass:: cudaq::noise_model
:members:

.. doxygenenum:: cudaq::noise_model_type

Kernel Builder
===============

Expand Down
6 changes: 5 additions & 1 deletion runtime/common/NoiseModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ kraus_channel::kraus_channel(std::vector<kraus_op> &_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(); }

Expand All @@ -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;
}

Expand Down
25 changes: 25 additions & 0 deletions runtime/common/NoiseModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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<real> parameters;

~kraus_channel() = default;

/// @brief The nullary constructor
Expand Down Expand Up @@ -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();
}
};
Expand All @@ -353,6 +372,8 @@ class amplitude_damping_channel : public kraus_channel {
std::vector<cudaq::complex> 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();
}
};
Expand All @@ -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();
}
};
Expand All @@ -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();
}
};
Expand Down

0 comments on commit aa6d2dd

Please sign in to comment.