Unverified Commit b1cf4a2e authored by Mccaskey, Alex's avatar Mccaskey, Alex Committed by GitHub
Browse files

Merge pull request #479 from ausbin/feature/swap-shortest-path-swaps

Consider SWAPs in swap-shortest-path
parents 4b894baf 71e1aefa
Pipeline #160016 passed with stage
in 34 minutes and 55 seconds
......@@ -78,10 +78,11 @@ void SwapShort::apply(std::shared_ptr<CompositeInstruction> program,
transformations::desugar(*prog);
transformations::Inliner::config c;
// Make sure we treat map all control pauli
// ops as CNOT gates
// ops and swaps as CNOT gates
c.overrides.erase("cx");
c.overrides.erase("cy");
c.overrides.erase("cz");
c.overrides.erase("swap");
transformations::inline_ast(*prog, c);
} catch (std::exception &e) {
std::stringstream ss;
......
......@@ -99,6 +99,37 @@ irt->apply(circuit, qpu);
}
TEST(Staq_MappingTester, checkSwapShortSwap) {
auto qpu = std::make_shared<AcceleratorWithConnectivity>(
std::vector<std::pair<int, int>>{{0, 1},
{1, 2}});
auto x = xacc::qalloc(3);
x->setName("x");
xacc::storeBuffer(x);
auto irt = xacc::getIRTransformation("swap-shortest-path");
auto compiler = xacc::getCompiler("xasm");
auto program = compiler->compile(R"(__qpu__ void test_simple_swap(qreg x) {
X(x[0]);
Swap(x[0], x[2]);
Measure(x[0]);
Measure(x[2]);
})")->getComposite("test_simple_swap");
EXPECT_EQ(4, program->nInstructions());
EXPECT_EQ("Swap", program->getInstruction(1)->name());
irt->apply(program, nullptr);
EXPECT_EQ(4, program->nInstructions());
irt->apply(program, qpu);
// Staq will expand the CNOT
EXPECT_EQ(9, program->nInstructions());
std::cout << program->toString() << "\n";
}
int main(int argc, char **argv) {
xacc::Initialize(argc, argv);
xacc::set_verbose(true);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment