Skip to content

Implement cudaq::run API #2526

Open
Open

Description

@annagrin

Required prerequisites

  • Search the issue tracker to check if your feature has already been mentioned or rejected in other issues.

Describe the feature

Implement cudaq::run API

template<typename T, typename … ARGS> 
std::vector<T> cudaq::run( 
     size_t shots, 
     std::function<T(ARGS…)>&& kernel, ARGS…); 

Examples (c++)

__qpu__ bool kernel(int n) {
  cudaq::qvector q(n);
  x(q[0]);
  return mz(q[0]);
}

int main() {
  auto results = cudaq::run<bool>(/*shots=*/1000, kernel, 2);
  std::cout << results << std::endl;
}

Output:
[1,1, ... 1] // 1000 results

Currently we would like to support returning the following types:

bool
int
float
double
std::vector<bool> // For measurements of qvectors (const size after opts)
structs of elements above (next version)

Examples (python)

@cudaq.kernel()
def kernel(n: int): bool
  q = cudaq.qvector(n)
  x(q[0])
  return mz(q[0])

results = cudaq.run(shots=1000, kernel, 2)
print(results)

Output:
[1,1, ... 1] // 1000 results

Currently we would like to support returning the following types:

bool
int
np.float32
np.float64
list[bool] // For measurements of qvectors (const size after opts)
structs of elements above (next version)

Tasks

  • Define log parsing API in c++ (no templates)

Idea:

struct OutputRecord {
 void* ptr;
 std::size_t byteSize;
};

class OutputParser {
 virtual std::vector<OutputRecord> parse(std::istream& s);
};
  • Implement log parsing API for backends that will use logs for output (quantum devices and remote simulator)
  • Implement log parsing API for backends that use memory for output (local simulators)
    • will need runtime QIR functions implementation
    • make sure we handle multiple and single shot scenarios
  • Implement cudaq::run API in c++
  • Implement cudaq.run API in Python
  • Implement retrieving logs from quantum backends (start with quantinuum)
  • Implement creating and retrieving logs from remote simulator server
  • Make sure quantum emulation works with new output log functionality
    • run LLVM generated from QIR on the simulator (needs runtime functions implementations)
  • Convert returns to log function calls in QIR

Activity

  1. added
    enhancement
    on Jan 21, 2025
  2. added a commit that references this issue on Jun 4, 2025
  3. added a commit that references this issue on Jun 17, 2025
  4. added
    stale-notified
    on Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementstale-notified

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions