Commit 71e1aefa authored by Adams, Austin Joel's avatar Adams, Austin Joel
Browse files

Consider SWAPs in swap-shortest-path

Remove SWAP gates from the two-qubit gate whitelist for Staq placement
also modified in f1eedf04. Otherwise, Swap instructions between
non-adjacent qubits can slip through the swap-shortest-path
IRTransformation. An example of this would be the QCOR qft() routine,
which can generate a Swap between far-away qubits at the end.

Combined with f1eedf04

, fixes ORNL-QCI/qcor#199.

Signed-off-by: Adams, Austin Joel's avatarAustin Adams <aja@gatech.edu>
parent 4b894baf
...@@ -78,10 +78,11 @@ void SwapShort::apply(std::shared_ptr<CompositeInstruction> program, ...@@ -78,10 +78,11 @@ void SwapShort::apply(std::shared_ptr<CompositeInstruction> program,
transformations::desugar(*prog); transformations::desugar(*prog);
transformations::Inliner::config c; transformations::Inliner::config c;
// Make sure we treat map all control pauli // 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("cx");
c.overrides.erase("cy"); c.overrides.erase("cy");
c.overrides.erase("cz"); c.overrides.erase("cz");
c.overrides.erase("swap");
transformations::inline_ast(*prog, c); transformations::inline_ast(*prog, c);
} catch (std::exception &e) { } catch (std::exception &e) {
std::stringstream ss; std::stringstream ss;
......
...@@ -99,6 +99,37 @@ irt->apply(circuit, qpu); ...@@ -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) { int main(int argc, char **argv) {
xacc::Initialize(argc, argv); xacc::Initialize(argc, argv);
xacc::set_verbose(true); xacc::set_verbose(true);
......
Supports Markdown
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