Commit 4fab9039 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Fix bug in finding position in comp vector, add a few more tests


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 3c6df472
...@@ -32,11 +32,6 @@ std::vector<std::string> _generate_gray_code(int num_bits) { ...@@ -32,11 +32,6 @@ std::vector<std::string> _generate_gray_code(int num_bits) {
} }
} }
// for (auto r : result) {
// std::cout << r << " ";
// }
// std::cout << "\n";
auto int_to_str = [&](int n) -> std::string { auto int_to_str = [&](int n) -> std::string {
const int size = sizeof(n) * 8; const int size = sizeof(n) * 8;
std::string res; std::string res;
...@@ -57,8 +52,8 @@ std::vector<std::string> _generate_gray_code(int num_bits) { ...@@ -57,8 +52,8 @@ std::vector<std::string> _generate_gray_code(int num_bits) {
std::vector<std::string> ret; std::vector<std::string> ret;
for (auto r : result) { for (auto r : result) {
// std::cout << int_to_str(r) << "\n";
ret.push_back(int_to_str(r)); ret.push_back(int_to_str(r));
// std::cout << "HI: " << ret.back() << "\n";
} }
return ret; return ret;
...@@ -125,12 +120,19 @@ void _apply_mcu_graycode(std::shared_ptr<CompositeInstruction> circuit, ...@@ -125,12 +120,19 @@ void _apply_mcu_graycode(std::shared_ptr<CompositeInstruction> circuit,
comp.push_back(i != j); comp.push_back(i != j);
} }
// std::cout << pattern << " " << last_pattern << " [";
// for (auto c : comp) std::cout << std::boolalpha << c << " ";
// std::cout << "], ";
int pos = -1; int pos = -1;
auto true_itr = std::find(comp.begin(), comp.end(), true); for (int i = 0; i < comp.size(); i++) {
if (true_itr != comp.end()) { if (comp[i]) {
pos = comp[std::distance(comp.begin(), true_itr)]; pos = i;
break;
}
} }
// std::cout << pos << "\n";
if (pos != -1) { if (pos != -1) {
if (pos != lm_pos) { if (pos != lm_pos) {
circuit->addInstruction(provider->createInstruction( circuit->addInstruction(provider->createInstruction(
...@@ -180,6 +182,12 @@ std::shared_ptr<CompositeInstruction> __gray_code_mcu_gen( ...@@ -180,6 +182,12 @@ std::shared_ptr<CompositeInstruction> __gray_code_mcu_gen(
auto __lam = inst->isParameterized() ? inst->getParameter(0).as<double>() auto __lam = inst->isParameterized() ? inst->getParameter(0).as<double>()
: constants::pi; : constants::pi;
lam = __lam * (1 / (std::pow(2, n_c - 1))); lam = __lam * (1 / (std::pow(2, n_c - 1)));
} else if (name == "Rx" || name == "X") {
auto __theta = inst->isParameterized() ? inst->getParameter(0).as<double>()
: constants::pi;
theta = __theta * (1 / (std::pow(2, n_c - 1)));
phi = -constants::pi / 2.;
lam = constants::pi / 2.;
} }
_apply_mcu_graycode(circuit, theta, phi, lam, ctrl_qubits, target_qubit); _apply_mcu_graycode(circuit, theta, phi, lam, ctrl_qubits, target_qubit);
...@@ -292,7 +300,7 @@ bool ControlledU::expand(const xacc::HeterogeneousMap &runtimeOptions) { ...@@ -292,7 +300,7 @@ bool ControlledU::expand(const xacc::HeterogeneousMap &runtimeOptions) {
auto should_run_gray_mcu_synth = [ctrlU, &ctrlIdxs]() { auto should_run_gray_mcu_synth = [ctrlU, &ctrlIdxs]() {
if (ctrlU->nInstructions() == 1) { if (ctrlU->nInstructions() == 1) {
std::vector<std::string> allowed{"Z"}; std::vector<std::string> allowed{"X", "Rx", "Z", "Rz"};
auto inst = ctrlU->getInstruction(0); auto inst = ctrlU->getInstruction(0);
if (xacc::container::contains(allowed, inst->name()) && if (xacc::container::contains(allowed, inst->name()) &&
ctrlIdxs.size() > 2) { ctrlIdxs.size() > 2) {
...@@ -323,9 +331,13 @@ bool ControlledU::expand(const xacc::HeterogeneousMap &runtimeOptions) { ...@@ -323,9 +331,13 @@ bool ControlledU::expand(const xacc::HeterogeneousMap &runtimeOptions) {
} }
} }
for (auto iter = zero_rotation_idxs.rbegin(); for (int instId = 0; instId < ctrlU->nInstructions(); ++instId) {
iter != zero_rotation_idxs.rend(); ++iter) { // Only add instructions that are not NOOPs
ctrlU->removeInstruction(*iter); if (std::find(zero_rotation_idxs.begin(), zero_rotation_idxs.end(),
instId) == zero_rotation_idxs.end()) {
auto inst = ctrlU->getInstruction(instId)->clone();
addInstruction(inst);
}
} }
} else { } else {
...@@ -334,12 +346,12 @@ bool ControlledU::expand(const xacc::HeterogeneousMap &runtimeOptions) { ...@@ -334,12 +346,12 @@ bool ControlledU::expand(const xacc::HeterogeneousMap &runtimeOptions) {
for (const auto &ctrlIdx : ctrlIdxs) { for (const auto &ctrlIdx : ctrlIdxs) {
ctrlU = applyControl(ctrlU, ctrlIdx); ctrlU = applyControl(ctrlU, ctrlIdx);
} }
}
for (int instId = 0; instId < ctrlU->nInstructions(); ++instId) { for (int instId = 0; instId < ctrlU->nInstructions(); ++instId) {
auto inst = ctrlU->getInstruction(instId)->clone(); auto inst = ctrlU->getInstruction(instId)->clone();
addInstruction(inst); addInstruction(inst);
} }
}
return true; return true;
} }
......
...@@ -8,73 +8,74 @@ ...@@ -8,73 +8,74 @@
using namespace xacc; using namespace xacc;
using namespace xacc::quantum; using namespace xacc::quantum;
TEST(ControlledGateTester, checkSimple) TEST(ControlledGateTester, checkSimple) {
{
auto gateRegistry = xacc::getService<xacc::IRProvider>("quantum"); auto gateRegistry = xacc::getService<xacc::IRProvider>("quantum");
auto t = std::make_shared<T>(0); auto t = std::make_shared<T>(0);
auto rz = std::make_shared<Rz>(0, 3.1415); auto rz = std::make_shared<Rz>(0, 3.1415);
auto u1 = std::make_shared<U1>(0, 3.1415); auto u1 = std::make_shared<U1>(0, 3.1415);
auto x = std::make_shared<X>(0); auto x = std::make_shared<X>(0);
const std::vector<size_t> expectedBits { 1, 0}; const std::vector<size_t> expectedBits{1, 0};
{ {
std::shared_ptr<xacc::CompositeInstruction> comp = gateRegistry->createComposite("__COMPOSITE__X"); std::shared_ptr<xacc::CompositeInstruction> comp =
gateRegistry->createComposite("__COMPOSITE__X");
comp->addInstruction(x->clone()); comp->addInstruction(x->clone());
auto ctrlKernel = std::dynamic_pointer_cast<CompositeInstruction>(xacc::getService<Instruction>("C-U")); auto ctrlKernel = std::dynamic_pointer_cast<CompositeInstruction>(
ctrlKernel->expand({ xacc::getService<Instruction>("C-U"));
std::make_pair("U", comp), ctrlKernel->expand(
std::make_pair("control-idx", 1) {std::make_pair("U", comp), std::make_pair("control-idx", 1)});
});
EXPECT_EQ(ctrlKernel->nInstructions(), 1); EXPECT_EQ(ctrlKernel->nInstructions(), 1);
EXPECT_EQ(ctrlKernel->getInstruction(0)->name(), "CNOT"); EXPECT_EQ(ctrlKernel->getInstruction(0)->name(), "CNOT");
EXPECT_EQ(ctrlKernel->getInstruction(0)->name(), "CNOT"); EXPECT_EQ(ctrlKernel->getInstruction(0)->name(), "CNOT");
EXPECT_EQ(ctrlKernel->getInstruction(0)->bits(), expectedBits); EXPECT_EQ(ctrlKernel->getInstruction(0)->bits(), expectedBits);
} }
{ {
std::shared_ptr<xacc::CompositeInstruction> comp = gateRegistry->createComposite("__COMPOSITE__T"); std::shared_ptr<xacc::CompositeInstruction> comp =
gateRegistry->createComposite("__COMPOSITE__T");
comp->addInstruction(t->clone()); comp->addInstruction(t->clone());
auto ctrlKernel = std::dynamic_pointer_cast<CompositeInstruction>(xacc::getService<Instruction>("C-U")); auto ctrlKernel = std::dynamic_pointer_cast<CompositeInstruction>(
ctrlKernel->expand({ xacc::getService<Instruction>("C-U"));
std::make_pair("U", comp), ctrlKernel->expand(
std::make_pair("control-idx", 1) {std::make_pair("U", comp), std::make_pair("control-idx", 1)});
});
// T -> CPhase(pi/4) // T -> CPhase(pi/4)
EXPECT_EQ(ctrlKernel->nInstructions(), 1); EXPECT_EQ(ctrlKernel->nInstructions(), 1);
EXPECT_EQ(ctrlKernel->getInstruction(0)->name(), "CPhase"); EXPECT_EQ(ctrlKernel->getInstruction(0)->name(), "CPhase");
EXPECT_NEAR(ctrlKernel->getInstruction(0)->getParameter(0).as<double>(), M_PI_4, 1e-4); EXPECT_NEAR(ctrlKernel->getInstruction(0)->getParameter(0).as<double>(),
M_PI_4, 1e-4);
EXPECT_EQ(ctrlKernel->getInstruction(0)->bits(), expectedBits); EXPECT_EQ(ctrlKernel->getInstruction(0)->bits(), expectedBits);
} }
{ {
std::shared_ptr<xacc::CompositeInstruction> comp = gateRegistry->createComposite("__COMPOSITE__Rz"); std::shared_ptr<xacc::CompositeInstruction> comp =
gateRegistry->createComposite("__COMPOSITE__Rz");
comp->addInstruction(rz->clone()); comp->addInstruction(rz->clone());
auto ctrlKernel = std::dynamic_pointer_cast<CompositeInstruction>(xacc::getService<Instruction>("C-U")); auto ctrlKernel = std::dynamic_pointer_cast<CompositeInstruction>(
ctrlKernel->expand({ xacc::getService<Instruction>("C-U"));
std::make_pair("U", comp), ctrlKernel->expand(
std::make_pair("control-idx", 1) {std::make_pair("U", comp), std::make_pair("control-idx", 1)});
});
// Rz -> CRz // Rz -> CRz
EXPECT_EQ(ctrlKernel->nInstructions(), 1); EXPECT_EQ(ctrlKernel->nInstructions(), 1);
EXPECT_EQ(ctrlKernel->getInstruction(0)->name(), "CRZ"); EXPECT_EQ(ctrlKernel->getInstruction(0)->name(), "CRZ");
EXPECT_EQ(ctrlKernel->getInstruction(0)->getParameter(0), rz->getParameter(0)); EXPECT_EQ(ctrlKernel->getInstruction(0)->getParameter(0),
rz->getParameter(0));
EXPECT_EQ(ctrlKernel->getInstruction(0)->bits(), expectedBits); EXPECT_EQ(ctrlKernel->getInstruction(0)->bits(), expectedBits);
} }
{ {
std::shared_ptr<xacc::CompositeInstruction> comp = gateRegistry->createComposite("__COMPOSITE__U1"); std::shared_ptr<xacc::CompositeInstruction> comp =
gateRegistry->createComposite("__COMPOSITE__U1");
comp->addInstruction(u1->clone()); comp->addInstruction(u1->clone());
auto ctrlKernel = std::dynamic_pointer_cast<CompositeInstruction>(xacc::getService<Instruction>("C-U")); auto ctrlKernel = std::dynamic_pointer_cast<CompositeInstruction>(
ctrlKernel->expand({ xacc::getService<Instruction>("C-U"));
std::make_pair("U", comp), ctrlKernel->expand(
std::make_pair("control-idx", 1) {std::make_pair("U", comp), std::make_pair("control-idx", 1)});
});
// U1 -> CPhase (cU1) // U1 -> CPhase (cU1)
EXPECT_EQ(ctrlKernel->nInstructions(), 1); EXPECT_EQ(ctrlKernel->nInstructions(), 1);
EXPECT_EQ(ctrlKernel->getInstruction(0)->name(), "CPhase"); EXPECT_EQ(ctrlKernel->getInstruction(0)->name(), "CPhase");
EXPECT_EQ(ctrlKernel->getInstruction(0)->getParameter(0), u1->getParameter(0)); EXPECT_EQ(ctrlKernel->getInstruction(0)->getParameter(0),
u1->getParameter(0));
EXPECT_EQ(ctrlKernel->getInstruction(0)->bits(), expectedBits); EXPECT_EQ(ctrlKernel->getInstruction(0)->bits(), expectedBits);
} }
} }
TEST(ControlledGateTester, checkMultipleControl) TEST(ControlledGateTester, checkMultipleControl) {
{
auto gateRegistry = xacc::getService<xacc::IRProvider>("quantum"); auto gateRegistry = xacc::getService<xacc::IRProvider>("quantum");
auto x = std::make_shared<X>(0); auto x = std::make_shared<X>(0);
std::shared_ptr<xacc::CompositeInstruction> comp = std::shared_ptr<xacc::CompositeInstruction> comp =
...@@ -87,29 +88,27 @@ TEST(ControlledGateTester, checkMultipleControl) ...@@ -87,29 +88,27 @@ TEST(ControlledGateTester, checkMultipleControl)
std::cout << "HOWDY: \n" << ccx->toString() << "\n"; std::cout << "HOWDY: \n" << ccx->toString() << "\n";
// Test truth table // Test truth table
auto acc = xacc::getAccelerator("qpp", { std::make_pair("shots", 8192)}); auto acc = xacc::getAccelerator("qpp", {std::make_pair("shots", 8192)});
auto xGate0 = gateRegistry->createInstruction("X", { 0 }); auto xGate0 = gateRegistry->createInstruction("X", {0});
auto xGate1 = gateRegistry->createInstruction("X", { 1 }); auto xGate1 = gateRegistry->createInstruction("X", {1});
auto xGate2 = gateRegistry->createInstruction("X", { 2 }); auto xGate2 = gateRegistry->createInstruction("X", {2});
auto measureGate0 = gateRegistry->createInstruction("Measure", { 0 }); auto measureGate0 = gateRegistry->createInstruction("Measure", {0});
auto measureGate1 = gateRegistry->createInstruction("Measure", { 1 }); auto measureGate1 = gateRegistry->createInstruction("Measure", {1});
auto measureGate2 = gateRegistry->createInstruction("Measure", { 2 }); auto measureGate2 = gateRegistry->createInstruction("Measure", {2});
const auto runTestCase = [&](bool in_bit0, bool in_bit1, bool in_bit2) { const auto runTestCase = [&](bool in_bit0, bool in_bit1, bool in_bit2) {
static int counter = 0; static int counter = 0;
auto composite = gateRegistry->createComposite("__TEMP_COMPOSITE__" + std::to_string(counter)); auto composite = gateRegistry->createComposite("__TEMP_COMPOSITE__" +
std::to_string(counter));
counter++; counter++;
// State prep: // State prep:
if (in_bit0) if (in_bit0) {
{
composite->addInstruction(xGate0); composite->addInstruction(xGate0);
} }
if (in_bit1) if (in_bit1) {
{
composite->addInstruction(xGate1); composite->addInstruction(xGate1);
} }
if (in_bit2) if (in_bit2) {
{
composite->addInstruction(xGate2); composite->addInstruction(xGate2);
} }
...@@ -121,7 +120,7 @@ TEST(ControlledGateTester, checkMultipleControl) ...@@ -121,7 +120,7 @@ TEST(ControlledGateTester, checkMultipleControl)
// Add ccx // Add ccx
composite->addInstructions(ccx->getInstructions()); composite->addInstructions(ccx->getInstructions());
// Mesurement: // Mesurement:
composite->addInstructions({ measureGate0, measureGate1, measureGate2 }); composite->addInstructions({measureGate0, measureGate1, measureGate2});
auto buffer = xacc::qalloc(3); auto buffer = xacc::qalloc(3);
acc->execute(buffer, composite); acc->execute(buffer, composite);
...@@ -131,30 +130,27 @@ TEST(ControlledGateTester, checkMultipleControl) ...@@ -131,30 +130,27 @@ TEST(ControlledGateTester, checkMultipleControl)
const auto expectedBitString = [&inputBitString]() -> std::string { const auto expectedBitString = [&inputBitString]() -> std::string {
// If both control bits are 1's // If both control bits are 1's
// q0q1q2 // q0q1q2
if (inputBitString == "011") if (inputBitString == "011") {
{
return "111"; return "111";
} }
if (inputBitString == "111") if (inputBitString == "111") {
{
return "011"; return "011";
} }
// Otherwise, no changes // Otherwise, no changes
return inputBitString; return inputBitString;
}(); }();
// Check bit string // Check bit string
EXPECT_NEAR(buffer->computeMeasurementProbability(expectedBitString), 1.0, 0.1); EXPECT_NEAR(buffer->computeMeasurementProbability(expectedBitString), 1.0,
0.1);
}; };
// 3 bits: run all test cases (8) // 3 bits: run all test cases (8)
for (int i = 0; i < (1 << 3); ++i) for (int i = 0; i < (1 << 3); ++i) {
{
runTestCase(i & 0x001, i & 0x002, i & 0x004); runTestCase(i & 0x001, i & 0x002, i & 0x004);
} }
} }
TEST(ControlledGateTester, checkMultipleControlQregs) TEST(ControlledGateTester, checkMultipleControlQregs) {
{
// Reference circuit (index-based) // Reference circuit (index-based)
const std::string ref_circuit_str = []() { const std::string ref_circuit_str = []() {
auto gateRegistry = xacc::getService<xacc::IRProvider>("quantum"); auto gateRegistry = xacc::getService<xacc::IRProvider>("quantum");
...@@ -200,8 +196,7 @@ TEST(ControlledGateTester, checkMultipleControlQregs) ...@@ -200,8 +196,7 @@ TEST(ControlledGateTester, checkMultipleControlQregs)
EXPECT_EQ(ref_circuit_str, new_circ_str); EXPECT_EQ(ref_circuit_str, new_circ_str);
} }
TEST(ControlledGateTester, checkControlSwap) TEST(ControlledGateTester, checkControlSwap) {
{
auto gateRegistry = xacc::getService<xacc::IRProvider>("quantum"); auto gateRegistry = xacc::getService<xacc::IRProvider>("quantum");
auto swap = std::make_shared<Swap>(0, 1); auto swap = std::make_shared<Swap>(0, 1);
std::shared_ptr<xacc::CompositeInstruction> comp = std::shared_ptr<xacc::CompositeInstruction> comp =
...@@ -215,29 +210,27 @@ TEST(ControlledGateTester, checkControlSwap) ...@@ -215,29 +210,27 @@ TEST(ControlledGateTester, checkControlSwap)
// 2 CNOT + CCNOT (15 gates) // 2 CNOT + CCNOT (15 gates)
EXPECT_EQ(cswap->nInstructions(), 15 + 2); EXPECT_EQ(cswap->nInstructions(), 15 + 2);
// Test truth table // Test truth table
auto acc = xacc::getAccelerator("qpp", { std::make_pair("shots", 1024)}); auto acc = xacc::getAccelerator("qpp", {std::make_pair("shots", 1024)});
auto xGate0 = gateRegistry->createInstruction("X", { 0 }); auto xGate0 = gateRegistry->createInstruction("X", {0});
auto xGate1 = gateRegistry->createInstruction("X", { 1 }); auto xGate1 = gateRegistry->createInstruction("X", {1});
auto xGate2 = gateRegistry->createInstruction("X", { 2 }); auto xGate2 = gateRegistry->createInstruction("X", {2});
auto measureGate0 = gateRegistry->createInstruction("Measure", { 0 }); auto measureGate0 = gateRegistry->createInstruction("Measure", {0});
auto measureGate1 = gateRegistry->createInstruction("Measure", { 1 }); auto measureGate1 = gateRegistry->createInstruction("Measure", {1});
auto measureGate2 = gateRegistry->createInstruction("Measure", { 2 }); auto measureGate2 = gateRegistry->createInstruction("Measure", {2});
const auto runTestCase = [&](bool in_bit0, bool in_bit1, bool in_bit2) { const auto runTestCase = [&](bool in_bit0, bool in_bit1, bool in_bit2) {
static int counter = 0; static int counter = 0;
auto composite = gateRegistry->createComposite("__TEMP_COMPOSITE__" + std::to_string(counter)); auto composite = gateRegistry->createComposite("__TEMP_COMPOSITE__" +
std::to_string(counter));
counter++; counter++;
// State prep: // State prep:
if (in_bit0) if (in_bit0) {
{
composite->addInstruction(xGate0); composite->addInstruction(xGate0);
} }
if (in_bit1) if (in_bit1) {
{
composite->addInstruction(xGate1); composite->addInstruction(xGate1);
} }
if (in_bit2) if (in_bit2) {
{
composite->addInstruction(xGate2); composite->addInstruction(xGate2);
} }
...@@ -249,7 +242,7 @@ TEST(ControlledGateTester, checkControlSwap) ...@@ -249,7 +242,7 @@ TEST(ControlledGateTester, checkControlSwap)
// Add cswap // Add cswap
composite->addInstructions(cswap->getInstructions()); composite->addInstructions(cswap->getInstructions());
// Mesurement: // Mesurement:
composite->addInstructions({ measureGate0, measureGate1, measureGate2 }); composite->addInstructions({measureGate0, measureGate1, measureGate2});
auto buffer = xacc::qalloc(3); auto buffer = xacc::qalloc(3);
acc->execute(buffer, composite); acc->execute(buffer, composite);
...@@ -259,30 +252,29 @@ TEST(ControlledGateTester, checkControlSwap) ...@@ -259,30 +252,29 @@ TEST(ControlledGateTester, checkControlSwap)
const auto expectedBitString = [&inputBitString]() -> std::string { const auto expectedBitString = [&inputBitString]() -> std::string {
// If q2 is 1 and q0 and q1 are different ==> swap // If q2 is 1 and q0 and q1 are different ==> swap
// q0q1q2 // q0q1q2
if (inputBitString == "011") if (inputBitString == "011") {
{
return "101"; return "101";
} }
if (inputBitString == "101") if (inputBitString == "101") {
{
return "011"; return "011";
} }
// Otherwise, no changes // Otherwise, no changes
return inputBitString; return inputBitString;
}(); }();
// Check bit string // Check bit string
EXPECT_NEAR(buffer->computeMeasurementProbability(expectedBitString), 1.0, 0.1); EXPECT_NEAR(buffer->computeMeasurementProbability(expectedBitString), 1.0,
0.1);
}; };
// 3 bits: run all test cases (8) // 3 bits: run all test cases (8)
for (int i = 0; i < (1 << 3); ++i) for (int i = 0; i < (1 << 3); ++i) {
{
runTestCase(i & 0x001, i & 0x002, i & 0x004); runTestCase(i & 0x001, i & 0x002, i & 0x004);
} }
} }
TEST(ControlledGateTester, checkEltonBug) { TEST(ControlledGateTester, checkEltonBug) {
auto gateRegistry = xacc::getService<xacc::IRProvider>("quantum"); auto gateRegistry = xacc::getService<xacc::IRProvider>("quantum");
{
auto z = std::make_shared<Z>(4); auto z = std::make_shared<Z>(4);
z->setBufferNames(std::vector<std::string>{"q"}); z->setBufferNames(std::vector<std::string>{"q"});
...@@ -291,31 +283,74 @@ TEST(ControlledGateTester, checkEltonBug) { ...@@ -291,31 +283,74 @@ TEST(ControlledGateTester, checkEltonBug) {
comp->addInstruction(z); comp->addInstruction(z);
auto multi_ctrl_z = std::dynamic_pointer_cast<CompositeInstruction>( auto multi_ctrl_z = std::dynamic_pointer_cast<CompositeInstruction>(
xacc::getService<Instruction>("C-U")); xacc::getService<Instruction>("C-U"));
const std::vector<int> ctrl_idxs{0,1,2,3}; const std::vector<int> ctrl_idxs{0, 1, 2, 3};
multi_ctrl_z->expand({{"U", comp}, {"control-idx", ctrl_idxs}}); multi_ctrl_z->expand({{"U", comp}, {"control-idx", ctrl_idxs}});
std::cout << "HOWDY: \n" << multi_ctrl_z->toString() << "\n"; // std::cout << "HOWDY: \n" << multi_ctrl_z->toString() << "\n";
std::cout << multi_ctrl_z->nInstructions() << "\n"; std::cout << multi_ctrl_z->nInstructions() << "\n";
// Eigen::MatrixXcd expected = Eigen::MatrixXcd::Identity(32,32);
// expected(31,31) = -1;
// std::cout << expected << "\n";
xacc::quantum::CountGatesOfTypeVisitor<CNOT> vis(multi_ctrl_z); xacc::quantum::CountGatesOfTypeVisitor<CNOT> vis(multi_ctrl_z);
xacc::quantum::CountGatesOfTypeVisitor<U> visu(multi_ctrl_z); xacc::quantum::CountGatesOfTypeVisitor<U> visu(multi_ctrl_z);
// QiskitImpl Reports: OrderedDict([('cx', 44), ('p', 30), ('u', 30)]) // QiskitImpl Reports: OrderedDict([('cx', 44), ('p', 30), ('u', 30)])
// all ours are U+CX, and we remove U(0,0,0). // all ours are U+CX, and we remove U(0,0,0).
// There are 8 U(0,0,0). So should have 44 CX, 60-8=52 Us // There are 8 U(0,0,0). So should have 44 CX, 60-8=52 Us
EXPECT_EQ(vis.countGates(), 44); EXPECT_EQ(vis.countGates(), 44);
EXPECT_EQ(visu.countGates(), 52); EXPECT_EQ(visu.countGates(), 52);
}
{
auto z = std::make_shared<Z>(6);
z->setBufferNames(std::vector<std::string>{"q"});
std::shared_ptr<xacc::CompositeInstruction> comp =
gateRegistry->createComposite("__COMPOSITE__Z");
comp->addInstruction(z);
auto multi_ctrl_z = std::dynamic_pointer_cast<CompositeInstruction>(
xacc::getService<Instruction>("C-U"));
const std::vector<int> ctrl_idxs{0, 1, 2, 3, 4, 5};
multi_ctrl_z->expand({{"U", comp}, {"control-idx", ctrl_idxs}});
<