Skip to content

[cpp, run] Reversed qubits in qvector when passed to cudaq::integer #3093

Open
@annagrin

Description

@annagrin

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

cudaq::to_integer sets the most significant bit for the first qubit when run from kernel.

Steps to reproduce the bug

// RUN: nvq++ -Wl,--export-dynamic -fenable-cudaq-run --target quantinuum --emulate %s -o %t && %t 

#include <cudaq.h>
#include <iostream>

__qpu__ int64_t test_to_integer() {
  cudaq::qvector qubits(4);
  x(qubits[0]);
  return cudaq::to_integer(mz(qubits));
}

int main() {
  auto resultsK = cudaq::run(2, test_to_integer);
  auto resultsNK = cudaq::to_integer(std::vector<bool>{true, false, false, false});
  std::cout << "Kernel: " << resultsK[0] << std::endl;
  std::cout << "Non-Kernel: " << resultsNK << std::endl;
  return 0;
}

// Output:
// Kernel: 8
// Non-Kernel: 1

Expected behavior

Same output for kernel and non-kernel cases

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

Not a regression

Environment

  • CUDA-Q version:
  • Python version:
  • C++ compiler:
  • Operating system:

Suggestions

No response

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