Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translating cudaq::compute_action to quake if the action contains a for-loop #1064

Closed
3 tasks done
oryarnitzky-classiq opened this issue Dec 31, 2023 · 0 comments · Fixed by #1069
Closed
3 tasks done
Assignees

Comments

@oryarnitzky-classiq
Copy link

Required prerequisites

  • 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

It seems like cudaq-quake fails to translate calls to cudaq::compute_action to quake, when the action operand contains a for loop. The following code example demonstrates this:

#include <cudaq.h>

struct entry {
  auto operator()() __qpu__ {
    cudaq::qubit p;
    cudaq::qubit q;
    cudaq::compute_action(
    [&]() { x(p); },
    [&]() {
        for (size_t i = 0; i < 1; ++i) { y(q); }
    });
  }
};

int main() {
  auto counts = cudaq::sample(entry{});
  counts.dump();
  return 0;
}

Actually having quantum logic in the code is not needed, the following also fails:

#include <cudaq.h>

struct entry {
  auto operator()() __qpu__ {
    cudaq::compute_action(
    [&]() {  },
    [&]() {
        for (size_t i = 0; i < 1; ++i) {  }
    });
  }
};

int main() {
  auto counts = cudaq::sample(entry{});
  counts.dump();
  return 0;
}

Running the command cudaq-quake --emit-llvm-file a.cpp fails with the following error:
error: 'quake.compute_action' op operand #0 must be Proxy for a C++ callable instance in cc, but got 'i64'

When inspecting the quake code, it seems like the quake.compute_action doesn't access the correct argument, but instead if accesses the result of the addition from the loop step.

Steps to reproduce the bug

  1. Create a file called a.cpp with the following content:
#include <cudaq.h>

struct entry {
  auto operator()() __qpu__ {
    cudaq::qubit p;
    cudaq::qubit q;
    cudaq::compute_action(
    [&]() { x(p); },
    [&]() {
        for (size_t i = 0; i < 1; ++i) { y(q); }
    });
  }
};

int main() {
  auto counts = cudaq::sample(entry{});
  counts.dump();
  return 0;
}
  1. Try to run cudaq-quake --emit-llvm-file a.cpp

Expected behavior

The command should succeed and an appropriate quake file should be created

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:

Suggestions

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants