NVIDIA / NVIDIA/cuda-quantum

Conditional sampling detection not working for C++ lambda kernels

Open
#3,460 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs triage stale-notified
Dominant language
C++
Stars
1.1k
Forks
456
Avg merge
1d 22h
Merged PRs (30d)
165

Description

cudaq::kernelHasConditionalFeedback doesn't seem to work properly for kernels written as lambdas and potentially C-style functions as well.

This may lead to incorrect simulation mode being selected.

Reproducer:

#include <cudaq.h>
#include <iostream>

struct kernel_struct {
  void operator()() __qpu__ {
    cudaq::qubit q;
    h(q);
    if (mz(q))
      x(q);
    mz(q);
  }
};

int main() {
  auto kernel_lambda = []() __qpu__ {
    cudaq::qubit q;
    h(q);
    if (mz(q))
      x(q);
    mz(q);
  };

  std::cout << "Counts from kernel written as a struct:\n";
  cudaq::sample(kernel_struct{}).dump();

  std::cout << "Counts from kernel written as a lambda:\n";
  cudaq::sample(kernel_lambda).dump();
}

The results for the two kernels are different. The one written as a struct produced a correct result:

Counts from kernel written as a struct:
{ 0:1000 }
Counts from kernel written as a lambda:
{ 0:501 1:499 }

I suspected that it may have failed to look up the quake code from the registry.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied C++ reproducer and inspect cudaq::kernelHasConditionalFeedback, focusing on how lambda kernels are looked up in the quake code registry. Compare the detection path for the lambda and kernel_struct cases. Done means both kernels select the same correct simulation behavior and produce matching results.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.