Skip to content

x-gate with multiple control bits throws error #4141

@iqm-bhoffmann

Description

@iqm-bhoffmann

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

We found that x-gates with multiple control bits can throw the following error:

1262:loc("<builder>":1:1): error: 'quake.z' op arity does not equal coarity of wires
1262: C++ exception with description "Remote rest platform Quake lowering failed." thrown in the test body.

The error is reproducible with both C++ and Python and depends on the parameters used. So far we have seen it only when selecting the IQM backend.

Steps to reproduce the bug

We have reduced the error to the following minimal code pieces. The first throws the error reported above using the C++ implementation.

  auto kernel = cudaq::make_kernel();
  auto qubit = kernel.qalloc(4);
  auto ctrl_bits = qubit.slice(1,2);
  kernel.x<cudaq::ctrl>(ctrl_bits, qubit[0]);
  auto counts = cudaq::sample(kernel);

The following C++ code which differs in only in the set of used control bits (line 3) gives no error and runs fine:

  auto kernel = cudaq::make_kernel();
  auto qubit = kernel.qalloc(4);
  auto ctrl_bits = qubit.slice(1,3);
  kernel.x<cudaq::ctrl>(ctrl_bits, qubit[0]);
  auto counts = cudaq::sample(kernel);

The same error can be seen with this minimal Python code piece:

@cudaq.kernel
def check_mcx():
    qubits = cudaq.qvector(4)
    x.ctrl(qubits[1:3],qubits[0])

Running this code results in the below error message while the following code just using a different set of control qubits works fine:

@cudaq.kernel
def check_mcx():
    qubits = cudaq.qvector(4)
    x.ctrl(qubits[1:4],qubits[0])

The error thrown with the upper code piece is basically the same as with the C++ code:

error: 'quake.z' op arity does not equal coarity of wires
Traceback (most recent call last):
  File "/workspaces/cuda-quantum-fork/danny02.py", line 24, in <module>
    test = cudaq.sample(check_mcx,shots_count=1000).most_probable()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/cudaq/cudaq/runtime/sample.py", line 181, in sample
    kernel(*args)
  File "/usr/local/cudaq/cudaq/kernel/kernel_decorator.py", line 513, in __call__
    result = cudaq_runtime.marshal_and_launch_module(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Remote rest platform Quake lowering failed.

Expected behavior

There should not be an error thrown for any of the given code examples. The error should also not depend on the selected backend.

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

Not a regression

Environment

  • CUDA-Q version: 0.13.0 (release) but also seen on main branch fb217a5
  • Python version:
  • C++ compiler:
  • Operating system:

Suggestions

In the attempt to understand the issue we saw that the error is thrown in the input validation of the transpilation.
The issue was encountered by IQM's education head Daniel Bulmash while he was preparing a demo for the GTC 2026 event.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions