Required prerequisites
Describe the feature
Two related gaps make "one external control qubit + an ancilla register"
control sets awkward in Python kernels:
- 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.
- 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.
Required prerequisites
Describe the feature
Two related gaps make "one external control qubit + an ancilla register"
control sets awkward in Python kernels:
qviewin one control set isrejected (
invalid argument type for control operand). All-qubit andsingle-view control sets work.
cudaq.control(kernel, control, args...)works for leafkernels (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.
Workaround: co-allocate the control qubit and the ancillas in one register
and slice views (
register.front(...)/register.back(...)) — but thatleaks 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 compositeoperations.
Environment
0be565550f4c23affdcbed9e4eaec38d2d0915e6qpp-cpu(library mode)All reproducers below were executed and verified against this build.