Skip to content

Commit

Permalink
[WIP] [runtime] add tests for mx and my qarray support
Browse files Browse the repository at this point in the history
  • Loading branch information
cabreraam committed Sep 30, 2024
1 parent 4d4d704 commit 76fdd9a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/AST-Quake/mx_qarray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// RUN: cudaq-quake %s | FileCheck %s

#include <cudaq.h>

template <std::size_t N>
struct ghz {
auto operator()() __qpu__ {

// Compile-time sized array like std::array
cudaq::qarray<N> q;
h(q[0]);
for (int i = 0; i < N - 1; i++) {
x<cudaq::ctrl>(q[i], q[i + 1]);
}
mx(q);
}
};

int main() {

auto kernel = ghz<10>{};
auto counts = cudaq::sample(kernel);

if (!cudaq::mpi::is_initialized() || cudaq::mpi::rank() == 0) {
counts.dump();

// Fine grain access to the bits and counts
for (auto &[bits, count] : counts) {
printf("Observed: %s, %lu\n", bits.data(), count);
}
}

return 0;
}


// CHECK-LABEL: func.func @__nvqpp__mlirgen__ghz{{.*}}{
// CHECK: %[[MEASOUT:.*]] = quake.mx %[[VAL_0:.*]] : (!quake.veq<10>) -> !cc.stdvec<!quake.measure>
38 changes: 38 additions & 0 deletions test/AST-Quake/my_qarray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// RUN: cudaq-quake %s | FileCheck %s

#include <cudaq.h>

template <std::size_t N>
struct ghz {
auto operator()() __qpu__ {

// Compile-time sized array like std::array
cudaq::qarray<N> q;
h(q[0]);
for (int i = 0; i < N - 1; i++) {
x<cudaq::ctrl>(q[i], q[i + 1]);
}
my(q);
}
};

int main() {

auto kernel = ghz<10>{};
auto counts = cudaq::sample(kernel);

if (!cudaq::mpi::is_initialized() || cudaq::mpi::rank() == 0) {
counts.dump();

// Fine grain access to the bits and counts
for (auto &[bits, count] : counts) {
printf("Observed: %s, %lu\n", bits.data(), count);
}
}

return 0;
}


// CHECK-LABEL: func.func @__nvqpp__mlirgen__ghz{{.*}}{
// CHECK: %[[MEASOUT:.*]] = quake.my %[[VAL_0:.*]] : (!quake.veq<10>) -> !cc.stdvec<!quake.measure>

0 comments on commit 76fdd9a

Please sign in to comment.