Commit 5367a4b0 authored by Nguyen, Thien's avatar Nguyen, Thien
Browse files

Added a more complex test for circuit optimizer



Testing non-conventional gate set.
Signed-off-by: Nguyen, Thien's avatarThien Nguyen <nguyentm@ornl.gov>
parent 3b39f4b6
......@@ -688,8 +688,6 @@ bool CircuitOptimizer::tryRotationMergingUsingPhasePolynomials(std::shared_ptr<C
// 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;
}
......@@ -750,6 +748,8 @@ bool CircuitOptimizer::tryRotationMergingUsingPhasePolynomials(std::shared_ptr<C
}
}
}
// Move the instruction index
++i;
}
else {
// Not a CNOT gate, continue
......
......@@ -838,6 +838,33 @@ TEST(CircuitOptimizerTester, checkCZ) {
EXPECT_EQ(before_xasm_str, after_xasm_str);
}
// Check circuit with random gates
TEST(CircuitOptimizerTester, checkComplexCircuit) {
xacc::set_verbose(true);
auto compiler = xacc::getService<xacc::Compiler>("xasm");
auto program = compiler
->compile(R"(__qpu__ void testRandom(qbit q) {
X(q[0]);
H(q[1]);
CZ(q[0], q[1]);
H(q[1]);
CNOT(q[1], q[2]);
T(q[1]);
CZ(q[1], q[0]);
Measure(q[0]);
Measure(q[1]);
Measure(q[2]);
})")
->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);
......
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