Skip to content

Commit d76451d

Browse files
[docs] measuring_kernels: explicit vector<bool> return + to_bools
PR NVIDIA#4409 made MLIR-mode `mz(qview)` return `std::vector<measure_handle>`, so `__qpu__ auto kernel2()` now deduces a handle-bearing return. `Marshal.cpp::hasLegalType` filters such kernels out of `GenKernelExecution`'s worklist, the `.run` companion is never generated, and `cudaq::run(1000, kernel2)` fails at runtime with `runnable kernel ... is not present`. Spell the return as `std::vector<bool>` and wrap `mz(q)` with `cudaq::to_bools(...)` so the kernel signature stays in the host-visible subset. Host-side `result[0]` is now a `bool` and `static_cast<int>(result[0])` is well-defined; previously it would have routed through `measure_handle::operator bool()`, which `std::abort()`s in MLIR mode. The `[Begin Run0]` / `[End Run0]` Sphinx literalinclude markers are unchanged. Signed-off-by: Pradnya Khalate <pkhalate@nvidia.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 68a1f8f commit d76451d

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

docs/sphinx/examples/cpp/measuring_kernels.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ __qpu__ void kernel1() {
2727
// [End Sample2]
2828

2929
// [Begin Run0]
30-
__qpu__ auto kernel2() {
30+
__qpu__ std::vector<bool> kernel2() {
3131
cudaq::qvector q(2);
3232
h(q[0]);
3333
auto b0 = mz(q[0]);
@@ -37,7 +37,7 @@ __qpu__ auto kernel2() {
3737
if (b0) {
3838
h(q[1]);
3939
}
40-
return mz(q);
40+
return cudaq::to_bools(mz(q));
4141
}
4242

4343
int main() {

0 commit comments

Comments
 (0)