NVIDIA / NVIDIA/cuda-quantum

Infinite loop when looping through kernel builder qubits

Open
#1,679 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Required prerequisites
  • Consult the security policy. If reporting a security vulnerability, do not report the bug using this form. Use the process described in the policy to report the issue.
  • Make sure you've read the documentation. Your issue may be addressed there.
  • Search the issue tracker to verify that this hasn't already been reported. +1 or comment there if it has.
  • If possible, make a PR with a failing test to give us a starting point to work on!
Describe the bug

The following will run an infinite loop:

import cudaq

kernel = cudaq.make_kernel()
qubits = kernel.qalloc(2)

for qubit in qubits:
    print(qubit)

which prints

.
.
.
Value(%1060 = quake.extract_ref %0[%c1059_i64] : (!quake.veq<2>, i64) -> !quake.ref)
Value(%1061 = quake.extract_ref %0[%c1060_i64] : (!quake.veq<2>, i64) -> !quake.ref)
Value(%1062 = quake.extract_ref %0[%c1061_i64] : (!quake.veq<2>, i64) -> !quake.ref)
Value(%1063 = quake.extract_ref %0[%c1062_i64] : (!quake.veq<2>, i64) -> !quake.ref)
Value(%1064 = quake.extract_ref %0[%c1063_i64] : (!quake.veq<2>, i64) -> !quake.ref)
Value(%1065 = quake.extract_ref %0[%c1064_i64] : (!quake.veq<2>, i64) -> !quake.ref)
Value(%1066 = quake.extract_ref %0[%c1065_i64] : (!quake.veq<2>, i64) -> !quake.ref)
Value(%1067 = quake.extract_ref %0[%c1066_i64] : (!quake.veq<2>, i64) -> !quake.ref)
Value(%1068 = quake.extract_ref %0[%c1067_i64] : (!quake.veq<2>, i64) -> !quake.ref)
Value(%1069 = quake.extract_ref %0[%c1068_i64] : (!quake.veq<2>, i64) -> !quake.ref)
Value(%1070 = quake.extract_ref %0[%c1069_i64] : (!quake.veq<2>, i64) -> !quake.ref)
Value(%1071 = quake.extract_ref %0[%c1070_i64] : (!quake.veq<2>, i64) -> !quake.ref)
Value(%1072 = quake.extract_ref %0[%c1071_i64] : (!quake.veq<2>, i64) -> !quake.ref)
Value(%1073 = quake.extract_ref %0[%c1072_i64] : (!quake.veq<2>, i64) -> !quake.ref)
.
.
.
Steps to reproduce the bug

See attached code

Expected behavior

We expect an error or for the loop to terminate properly.

Is this a regression? If it is, put the last known working version (or commit) here.

Not a regression

Environment
  • CUDA Quantum version:
  • Python version:
  • C++ compiler:
  • Operating system:

All latest

Suggestions

No response

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 by running the provided Python snippet using cudaq.make_kernel(), kernel.qalloc(2), and iteration over qubits. Trace how the kernel builder represents and iterates allocated qubits, then add or run a regression test for this reproducer. Done means iteration terminates after the allocated qubits or reports a defined error instead of producing unbounded extract_ref values.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
quantum-computing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.