Skip to content

Commit

Permalink
Added two-qubit zx tests and made qcec compatible to new core version.
Browse files Browse the repository at this point in the history
  • Loading branch information
pehamTom committed Oct 30, 2023
1 parent 815ed06 commit 9781f7c
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 67 deletions.
2 changes: 1 addition & 1 deletion extern/mqt-core
Submodule mqt-core updated 130 files
6 changes: 4 additions & 2 deletions include/checker/dd/simulation/StateGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "StateType.hpp"
#include "algorithms/RandomCliffordCircuit.hpp"
#include "checker/dd/TaskManager.hpp"
#include "dd/Node.hpp"
#include "dd/Package.hpp"
#include "dd/Simulation.hpp"

Expand Down Expand Up @@ -153,8 +154,9 @@ class StateGenerator {
// add |0> edges for all the ancillary qubits
auto initial = stabilizer;
for (std::size_t p = randomQubits; p < totalQubits; ++p) {
initial = dd->makeDDNode(static_cast<dd::Qubit>(p),
std::array{initial, qc::VectorDD::zero});
initial = dd->makeDDNode(
static_cast<dd::Qubit>(p),
std::array<dd::vEdge, 2>{initial, qc::VectorDD::zero()});
}

// return the resulting decision diagram
Expand Down
4 changes: 2 additions & 2 deletions src/EquivalenceCheckingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ void EquivalenceCheckingManager::run() {
EquivalenceCheckingManager::EquivalenceCheckingManager(
const qc::QuantumComputation& circ1, const qc::QuantumComputation& circ2,
Configuration config)
: qc1(circ1.size() > circ2.size() ? circ2.clone() : circ1.clone()),
qc2(circ1.size() > circ2.size() ? circ1.clone() : circ2.clone()),
: qc1(circ1.size() > circ2.size() ? circ2 : circ1),
qc2(circ1.size() > circ2.size() ? circ1 : circ2),
configuration(std::move(config)) {
// clones both circuits (the circuit with fewer gates always gets to be qc1)

Expand Down
36 changes: 18 additions & 18 deletions src/checker/dd/applicationscheme/GateCostApplicationScheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ legacyCostFunction(const GateCostLookupTableKeyType& key) noexcept {
case qc::Y:
case qc::Z:
case qc::S:
case qc::Sdag:
case qc::Sdg:
case qc::T:
case qc::Tdag:
case qc::Phase:
case qc::Tdg:
case qc::P:
case qc::U2:
case qc::U3:
case qc::U:
case qc::SX:
case qc::SXdag:
case qc::SXdg:
case qc::V:
case qc::Vdag:
case qc::Vdg:
case qc::RX:
case qc::RY:
case qc::RZ:
Expand All @@ -51,36 +51,36 @@ legacyCostFunction(const GateCostLookupTableKeyType& key) noexcept {
switch (gate) {
case qc::X:
return 2UL * (nc - 2UL) *
((2UL * legacyCostFunction({qc::Phase, 0})) +
((2UL * legacyCostFunction({qc::P, 0})) +
(2UL * legacyCostFunction({qc::U2, 0})) +
(3UL * legacyCostFunction({qc::X, 1}))) +
(6UL * legacyCostFunction({qc::X, 1})) +
(8UL * legacyCostFunction({qc::U3, 0}));
case qc::U3:
(8UL * legacyCostFunction({qc::U, 0}));
case qc::U:
case qc::U2:
case qc::V:
case qc::Vdag:
case qc::Vdg:
case qc::RX:
case qc::RY:
case qc::H:
case qc::SX:
case qc::SXdag:
case qc::SXdg:
// heuristic
return (2U * legacyCostFunction({qc::X, nc})) +
(4U * legacyCostFunction({qc::U3, 0}));
case qc::Phase:
(4U * legacyCostFunction({qc::U, 0}));
case qc::P:
case qc::S:
case qc::Sdag:
case qc::Sdg:
case qc::T:
case qc::Tdag:
case qc::Tdg:
case qc::RZ:
// heuristic
return (2U * legacyCostFunction({qc::X, nc})) +
(3U * legacyCostFunction({qc::Phase, 0}));
(3U * legacyCostFunction({qc::P, 0}));
case qc::Y:
case qc::Z:
return legacyCostFunction({qc::X, nc}) +
(2U * legacyCostFunction({qc::U3, 0}));
(2U * legacyCostFunction({qc::U, 0}));
case qc::SWAP:
return legacyCostFunction({qc::X, nc}) +
(2U * legacyCostFunction({qc::X, 1}));
Expand All @@ -89,7 +89,7 @@ legacyCostFunction(const GateCostLookupTableKeyType& key) noexcept {
(2U * legacyCostFunction({qc::S, nc})) +
(2U * legacyCostFunction({qc::H, nc}));
case qc::Peres:
case qc::Peresdag:
case qc::Peresdg:
return legacyCostFunction({qc::X, nc + 1U}) +
legacyCostFunction({qc::X, nc});
default:
Expand Down
20 changes: 10 additions & 10 deletions test/legacy/test_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,21 @@ TEST_F(GeneralTest, NoGateCancellation) {
qc2.x(0);

// two-qubit gates that cannot be cancelled
qc1.x(0, 1_pc);
qc2.x(1, 0_pc);
qc1.x(0, 1_pc);
qc2.x(1, 0_pc);
qc1.cx(1_pc, 0);
qc2.cx(0_pc, 1);
qc1.cx(1_pc, 0);
qc2.cx(0_pc, 1);

// gates with parameters that cannot be cancelled
qc1.phase(0, 2.0);
qc2.phase(0, -2.0);
qc1.phase(0, -2.0);
qc2.phase(0, 2.0);
qc1.p(2.0, 0);
qc2.p(-2.0, 0);
qc1.p(-2.0, 0);
qc2.p(2.0, 0);

// gates with different number of controls that cannot be cancelled
qc1.x(0);
qc2.x(0, 1_pc);
qc1.x(0, 1_pc);
qc2.cx(1_pc, 0);
qc1.cx(1_pc, 0);
qc2.x(0);

auto config = ec::Configuration{};
Expand Down
12 changes: 6 additions & 6 deletions test/test_equality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ TEST_F(EqualityTest, CloseButNotEqualAlternating) {
qc1.x(0);

qc2.x(0);
qc2.phase(0, dd::PI / 1024.);
qc2.p(dd::PI / 1024., 0);

config.functionality.traceThreshold = 1e-2;
config.execution.runAlternatingChecker = true;
Expand All @@ -66,7 +66,7 @@ TEST_F(EqualityTest, CloseButNotEqualConstruction) {
qc1.x(0);

qc2.x(0);
qc2.phase(0, dd::PI / 1024.);
qc2.p(dd::PI / 1024., 0);

config.functionality.traceThreshold = 1e-2;
config.execution.runConstructionChecker = true;
Expand All @@ -80,7 +80,7 @@ TEST_F(EqualityTest, CloseButNotEqualAlternatingGlobalPhase) {
qc1.x(0);

qc2.x(0);
qc2.phase(0, dd::PI / 1024.);
qc2.p(dd::PI / 1024., 0);
// add a global phase of -1
qc2.z(0);
qc2.x(0);
Expand All @@ -100,7 +100,7 @@ TEST_F(EqualityTest, CloseButNotEqualSimulation) {
qc1.h(0);

qc2.h(0);
qc2.phase(0, dd::PI / 1024.);
qc2.p(dd::PI / 1024., 0);

config.simulation.fidelityThreshold = 1e-2;
config.execution.runSimulationChecker = true;
Expand All @@ -116,9 +116,9 @@ TEST_F(EqualityTest, SimulationMoreThan64Qubits) {
qc1 = qc::QuantumComputation(65U);
qc1.h(0);
for (auto i = 0U; i < 64U; ++i) {
qc1.x(i + 1, 0_pc);
qc1.cx(0_pc, i + 1);
}
qc2 = qc1.clone();
qc2 = qc1;
config.execution.runSimulationChecker = true;
ec::EquivalenceCheckingManager ecm(qc1, qc2, config);
ecm.run();
Expand Down
4 changes: 2 additions & 2 deletions test/test_gate_cost_application_scheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ TEST_F(GateCostApplicationSchemeTest, SchemeFromProfile) {
ofs.close();

// apply Toffoli gate
qc.x(0, {1_pc, 2_pc});
qc.mcx({1_pc, 2_pc}, 0);

auto tm = ec::TaskManager<qc::MatrixDD>(qc, dd);

Expand Down Expand Up @@ -71,7 +71,7 @@ TEST_F(GateCostApplicationSchemeTest, iSWAP) {
TEST_F(GateCostApplicationSchemeTest, Peres) {
using namespace qc::literals;

qc.peres(1, 2, 0_pc);
qc.cperes(0_pc, 1, 2);

auto tm = ec::TaskManager<qc::MatrixDD>(qc, dd);

Expand Down
20 changes: 10 additions & 10 deletions test/test_symbolic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class SymbolicTest : public ::testing::Test {
};

TEST_F(SymbolicTest, SymbolicEqu) {
symQc1.rx(0, xMonom);
symQc1.rx(xMonom, 0);

symQc2.h(0);
symQc2.rz(0, xMonom);
symQc2.rz(xMonom, 0);
symQc2.h(0);

auto ecm = ec::EquivalenceCheckingManager(symQc1, symQc2);
Expand All @@ -35,10 +35,10 @@ TEST_F(SymbolicTest, SymbolicEqu) {
}

TEST_F(SymbolicTest, SymbolicNonEqu) {
symQc1.rx(0, xMonom);
symQc1.rx(xMonom, 0);

symQc2.h(0);
symQc2.rz(0, xMonomNeg);
symQc2.rx(xMonomNeg, 0);
symQc2.h(0);

auto ecm = ec::EquivalenceCheckingManager(symQc1, symQc2);
Expand All @@ -53,11 +53,11 @@ TEST_F(SymbolicTest, Timeout) {
symQc1 = qc::QuantumComputation(2);
symQc2 = qc::QuantumComputation(2);
for (auto i = 0; i < numLayers; ++i) {
symQc1.x(0, 1_pc);
symQc1.rx(0, xMonom);
symQc1.cx(1_pc, 0);
symQc1.rx(xMonom, 0);

symQc2.x(0, 1_pc);
symQc2.rx(0, xMonom);
symQc2.cx(1_pc, 0);
symQc2.rx(xMonom, 0);
}
ec::Configuration config{};
config.execution.timeout = 1;
Expand All @@ -70,8 +70,8 @@ TEST_F(SymbolicTest, Timeout) {

TEST_F(SymbolicTest, InvalidCircuit) {
auto qc = qc::QuantumComputation(4);
qc.x(0, {1_pc, 2_pc, 3_pc});
qc.rx(0, xMonom);
qc.mcx({1_pc, 2_pc, 3_pc}, 0);
qc.rx(xMonom, 0);
auto ecm = ec::EquivalenceCheckingManager(qc, qc);
ecm.run();

Expand Down
Loading

0 comments on commit 9781f7c

Please sign in to comment.