Skip to content

[core] Support for apply_noise.#2603

Closed
schweitzpgi wants to merge 4 commits intoNVIDIA:mainfrom
schweitzpgi:ch-apply.noise
Closed

[core] Support for apply_noise.#2603
schweitzpgi wants to merge 4 commits intoNVIDIA:mainfrom
schweitzpgi:ch-apply.noise

Conversation

@schweitzpgi
Copy link
Collaborator

@schweitzpgi schweitzpgi commented Feb 10, 2025

Add an apply_noise operator.
Teach the bridge to recognize cudaq::apply_noise and lower it.
Add a pass to erase apply_noise operations.
Modify QIR codegen to generate the C++ callback.

Description

Add an apply_noise operator.
Teach the bridge to recognize cudaq::apply_noise and lower it.
Add a pass to erase apply_noise operations.
Modify QIR codegen to generate the C++ callback.

Signed-off-by: Eric Schweitz <eschweitz@nvidia.com>
Signed-off-by: Eric Schweitz <eschweitz@nvidia.com>
@schweitzpgi schweitzpgi requested a review from annagrin February 11, 2025 00:03
@amccaskey
Copy link
Collaborator

Probably coming in a bit too early, but pulled this to kick the tires.

Couple of bugs for this kraus_channel

#include "cudaq.h"

namespace test {

struct my_channel : public ::cudaq::kraus_channel {
  my_channel(const std::vector<double> &params) {
    std::vector<cudaq::complex> k0v{std::sqrt(1 - params[0]), 0, 0,
                                    std::sqrt(1 - params[0])},
        k1v{0, std::sqrt(params[0]), std::sqrt(params[0]), 0};
    push_back(cudaq::kraus_op(k0v));
    push_back(cudaq::kraus_op(k1v));
  }
};
} // namespace test

__qpu__ void test2(double d) {
  cudaq::qubit q;
  x(q);
  cudaq::apply_noise<test::my_channel>(d, q);
}

First one is that we do want apply_noise implemented such that the kraus_channel is returned from the noise_model. As of now we get an error for KrausChannelT not be default constructible.

/workspaces/cuda-quantum/runtime/cudaq/qis/qubit_qis.h:49:17: error: no matching constructor for initialization of 'test::my_channel'
  KrausChannelT channel;

Next issue is that the double argument here is passed by reference, so the type that the bridge sees is cc.ptr<f64> which does not pass the error checking logic in ConvertExpr.

ericNoise.cpp:23:3: error: apply_noise argument types not supported.
  cudaq::apply_noise<test::my_channel>(d, q);
  ^

qubits, which cannot be copied. Thread the pointer through all the
places where there were floating-point types. Update tests.

Add a bit more smart to the cudaq::apply_noise stub. Automatically counts
the leading number of floating-point arguments, so the user doesn't have
to supply this information. Uses the applyNoiseImpl<> template as is.

Signed-off-by: Eric Schweitz <eschweitz@nvidia.com>
Signed-off-by: Eric Schweitz <eschweitz@nvidia.com>
github-actions bot pushed a commit that referenced this pull request Feb 11, 2025
@schweitzpgi schweitzpgi deleted the ch-apply.noise branch December 9, 2025 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants