Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant gates after depth-optimal synthesis. #336

Merged
merged 18 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/cliffordsynthesis/CliffordSynthesizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class CliffordSynthesizer {
const Configuration& config);
static void updateResults(const Configuration& config,
const Results& newResults, Results& currentResults);
void removeRedundantGates();
};

} // namespace cs
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ testpaths = ["test/python"]
addopts = ["-ra", "--strict-markers", "--strict-config", "--showlocals"]
log_cli_level = "INFO"
xfail_strict = true
filterwarnings = ["error"]
filterwarnings = ["error", 'ignore:Conversion.*to a scalar is deprecated.*:DeprecationWarning:qiskit:']

[tool.coverage.run]
source = ["mqt.qmap"]
Expand Down
27 changes: 27 additions & 0 deletions src/cliffordsynthesis/CliffordSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
#include "cliffordsynthesis/CliffordSynthesizer.hpp"

#include "LogicTerm/Logic.hpp"
#include "QuantumComputation.hpp"
#include "cliffordsynthesis/Tableau.hpp"
#include "utils/logging.hpp"

#include <chrono>
#include <fstream>
#include <future>
#include <memory>
#include <thread>

namespace cs {
Expand Down Expand Up @@ -226,6 +229,12 @@ void CliffordSynthesizer::depthOptimalSynthesis(
// fixed depth limit and the goal to minimize the number of gates.
minimizeGatesFixedDepth(config);
}

if (!initialTableau.hasDestabilizers()) {
// If destabilizers aren't considered, the synthesis might include gates
// that have no impact on the final tableau, so we can remove them
removeRedundantGates();
}
}

void CliffordSynthesizer::minimizeGatesFixedDepth(EncoderConfig config) {
Expand Down Expand Up @@ -518,4 +527,22 @@ CliffordSynthesizer::synthesizeSubcircuit(
synth.initResultCircuitFromResults();
return synth.resultCircuit;
}

void CliffordSynthesizer::removeRedundantGates() {
Tableau prev = initialTableau;
Tableau curr = initialTableau;
initResultCircuitFromResults();
qc::QuantumComputation reducedResult(resultCircuit->getNqubits());

for (auto& gate : *resultCircuit) {
curr.applyGate(gate.get());
if (prev != curr) {
prev.applyGate(gate.get());
reducedResult.emplace_back(std::move(gate));
}
}

results.setResultCircuit(reducedResult);
results.setSingleQubitGates(reducedResult.getNsingleQubitOps());
}
} // namespace cs