Skip to content

Commit

Permalink
Related to eclipse#478
Browse files Browse the repository at this point in the history
The procedure was not properly taking into account non-IBM gateset, i.e., 2-q gates may not be CNOT.

Signed-off-by: Thien Nguyen <[email protected]>
  • Loading branch information
Thien Nguyen committed Aug 17, 2021
1 parent 520fc16 commit 3b39f4b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
15 changes: 15 additions & 0 deletions quantum/plugins/optimizers/simple/CircuitOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,21 @@ bool CircuitOptimizer::tryRotationMergingUsingPhasePolynomials(std::shared_ptr<C
}
}
else if (instruction->bits().size() == 2) {
// If this gate not involved the qubits that we are checking
if (!container::contains(qubits, instruction->bits()[0]) &&
!container::contains(qubits, instruction->bits()[1])) {
// Skip
continue;
}

// This 2-q gate **involves** at least one qubit:
if (instruction->name() != "CNOT") {
// Not a CNOT: we need to terminate, hence prune the subcircuit.
// Move the outer loop index to after this gate.
i = idx + 1;
break;
}

assert(instruction->name() == "CNOT");
// If the control is *outside* the boundary, we need to terminate, hence prune the subcircuit.
const auto controlIdx = instruction->bits()[0];
Expand Down
20 changes: 20 additions & 0 deletions quantum/plugins/optimizers/simple/tests/CircuitOptimizerTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,26 @@ measure q[3] -> c[3];
EXPECT_EQ(truthTableBefore, truthTableAfter);
}

TEST(CircuitOptimizerTester, checkCZ) {
xacc::set_verbose(true);
auto compiler = xacc::getService<xacc::Compiler>("xasm");
auto program = compiler
->compile(R"(__qpu__ void testCz(qbit q) {
CNOT(q[0], q[1]);
CZ(q[0], q[1]);
Measure(q[0]);
Measure(q[1]);
})")
->getComposites()[0];

const auto before_xasm_str = program->toString();
auto optimizer = xacc::getService<IRTransformation>("circuit-optimizer");
optimizer->apply(program, nullptr);
std::cout << "FINAL CIRCUIT:\n" << program->toString() << "\n";
const auto after_xasm_str = program->toString();
EXPECT_EQ(before_xasm_str, after_xasm_str);
}

int main(int argc, char **argv) {
xacc::Initialize(argc, argv);
::testing::InitGoogleTest(&argc, argv);
Expand Down

0 comments on commit 3b39f4b

Please sign in to comment.