NVIDIA / NVIDIA/cuda-quantum

[python] Control sets cannot mix a qubit with a qview, and cudaq.control fails on kernels that call other kernels

Open
#4,848 1 comment 0 reactions 1 assignee View on GitHub

@schweitzpgi is already working on this.

Since Jul 8, 2026.

stale-notified
Dominant language
C++
Stars
1.1k
Forks
455
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.
Describe the feature

Two related gaps make "one external control qubit + an ancilla register"
control sets awkward in Python kernels:

  1. Gate level: any mix of a bare qubit and a qview in one control set is
    rejected (invalid argument type for control operand). All-qubit and
    single-view control sets work.
  2. Kernel level: cudaq.control(kernel, control, args...) works for leaf
    kernels (including list arguments) but fails with "Could not
    successfully apply kernel specialization" when the controlled kernel
    itself calls another kernel — so composite operations cannot be
    controlled wholesale.
import cudaq
cudaq.set_target("qpp-cpu")

# (1) mixed control set
@cudaq.kernel
def mixed():
    c = cudaq.qubit()
    q = cudaq.qvector(3)
    x.ctrl(c, q.front(2), q[2])   # error: invalid argument type for control operand

# (2) cudaq.control of a composite kernel
@cudaq.kernel
def leaf(q: cudaq.qview):
    for i in range(q.size()):
        x(q[i])

@cudaq.kernel
def composite(q: cudaq.qview):
    leaf(q)

@cudaq.kernel
def caller():
    c = cudaq.qubit()
    q = cudaq.qvector(2)
    x(c)
    cudaq.control(leaf, c, q)       # OK
    cudaq.control(composite, c, q)  # RuntimeError: Could not successfully apply kernel specialization.

Workaround: co-allocate the control qubit and the ancillas in one register
and slice views (register.front(...)/register.back(...)) — but that
leaks into public APIs: users must co-allocate their control qubit with a
library's ancilla register instead of passing any qubit they own (e.g. a
QPE counting qubit). Either fixing (1) or (2) would remove the constraint;
(2) alone would allow cudaq.control(subroutine, ctrl, ...) over composite
operations.

Environment
  • CUDA-Q built from source at commit 0be565550f4c23affdcbed9e4eaec38d2d0915e6
  • Python 3.11.x, target qpp-cpu (library mode)
  • AlmaLinux 8.10, x86_64

All reproducers below were executed and verified against this build.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.