Skip to content

Commit

Permalink
fix bugs in tests
Browse files Browse the repository at this point in the history
Signed-off-by: A.M. Santana <[email protected]>
  • Loading branch information
anthony-santana committed Nov 15, 2023
1 parent 146b502 commit 1c41af5
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions unittests/integration/builder_tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,12 @@ CUDAQ_TEST(BuilderTester, checkSwap) {
// Simple two-qubit swap.
{
auto kernel = cudaq::make_kernel();
auto q = kernel.qalloc(2);
// 0th qubit into the 1-state.
kernel.x(q[0]);
auto first = kernel.qalloc();
auto second = kernel.qalloc();
// `first` qubit into the 1-state.
kernel.x(first);
// Swap their states and measure.
kernel.swap(q[0], q[1]);
// Measure.
kernel.mz(q);
kernel.swap(first, second);

auto counts = cudaq::sample(kernel);
counts.dump();
Expand All @@ -451,13 +450,12 @@ CUDAQ_TEST(BuilderTester, checkSwap) {
// Simple two-qubit swap.
{
auto kernel = cudaq::make_kernel();
auto q = kernel.qalloc(2);
// 1st qubit into the 1-state.
kernel.x(q[1]);
auto first = kernel.qalloc();
auto second = kernel.qalloc();
// `second` qubit into the 1-state.
kernel.x(second);
// Swap their states and measure.
kernel.swap(q[0], q[1]);
// Measure.
kernel.mz(q);
kernel.swap(first, second);

auto counts = cudaq::sample(kernel);
counts.dump();
Expand All @@ -468,16 +466,17 @@ CUDAQ_TEST(BuilderTester, checkSwap) {
{
auto kernel = cudaq::make_kernel();
auto ctrl = kernel.qalloc();
auto q = kernel.qalloc(2);
auto first = kernel.qalloc();
auto second = kernel.qalloc();
// ctrl and `first` in the 1-state.
kernel.x(ctrl);
// 0th qubit into the 1-state.
kernel.x(q[0]);
kernel.x(first);
// Swap their states and measure.
kernel.swap<cudaq::ctrl>(ctrl, q[0], q[1]);
kernel.swap<cudaq::ctrl>(ctrl, first, second);

auto counts = cudaq::sample(kernel);
counts.dump();
EXPECT_NEAR(counts.count("01"), 1000, 0);
EXPECT_NEAR(counts.count("101"), 1000, 0);
}

// Multi-controlled SWAP with a ctrl register.
Expand All @@ -503,9 +502,10 @@ CUDAQ_TEST(BuilderTester, checkSwap) {

auto counts = cudaq::sample(kernel);
counts.dump();
auto ctrls_state = "111";
std::string ctrls_state = "111";
// `first` is now |0>, `second` is now |1>.
auto want_state = ctrls_state + "01";
std::string want_target = "01";
auto want_state = ctrls_state + want_target;
EXPECT_NEAR(counts.count(want_state), 1000, 0);
}

Expand Down Expand Up @@ -533,9 +533,10 @@ CUDAQ_TEST(BuilderTester, checkSwap) {

auto counts = cudaq::sample(kernel);
counts.dump();
auto ctrls_state = "111";
std::string ctrls_state = "111";
// `first` is now |1>, `second` is now |0>.
auto want_state = ctrls_state + "10";
std::string want_target = "10";
auto want_state = ctrls_state + want_target;
EXPECT_NEAR(counts.count(want_state), 1000, 0);
}

Expand Down Expand Up @@ -564,9 +565,10 @@ CUDAQ_TEST(BuilderTester, checkSwap) {

auto counts = cudaq::sample(kernel);
counts.dump();
auto ctrls_state = "11111";
std::string ctrls_state = "11111";
// `first` is now |1>, `second` is now |0>.
auto want_state = ctrls_state + "10";
std::string want_target = "10";
auto want_state = ctrls_state + want_target;
EXPECT_NEAR(counts.count(want_state), 1000, 0);
}
}
Expand Down

0 comments on commit 1c41af5

Please sign in to comment.