Skip to content

Commit

Permalink
Remove redundant gates after depth-optimal synthesis. (#336)
Browse files Browse the repository at this point in the history
## Description

Remove redundant gates in a post-processing step after depth-optimal
synthesis

Fixes #325

## Checklist:

<!---
This checklist serves as a reminder of a couple of things that ensure
your pull request will be merged swiftly.
-->

- [x] The pull request only contains commits that are related to it.
- [x] I have added appropriate tests and documentation.
- [x] I have made sure that all CI jobs on GitHub pass.
- [x] The pull request introduces no new warnings and follows the
project's style guidelines.
  • Loading branch information
pehamTom authored Jun 27, 2023
2 parents 19ba74f + 6d2a179 commit 9f1871a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
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

1 comment on commit 9f1871a

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cpp-Linter Report ✔️

No problems need attention.

Have any feedback or feature suggestions? Share it here.

Please sign in to comment.