Skip to content

Commit

Permalink
⬆️👽 update to latest MQT Core version (#531)
Browse files Browse the repository at this point in the history
## Description

This PR updates the MQT Core version used in QCEC to the latest version.
This includes changes from cda-tum/mqt-core#674 and
cda-tum/mqt-core#764.
SWAP eliding is now performed explicitly in QCEC instead of implicitly
in the `getDD` method of MQT Core.
Furthermore, states generated by the DD package now have their ref count
increased by default, which required subtle changes to the ref counting
scheme.

## 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
burgholzer authored Jan 8, 2025
2 parents 0ed735c + 4c57cfd commit c3fbfc2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
needs: change-detection
if: fromJSON(needs.change-detection.outputs.run-python-tests)
uses: cda-tum/mqt-workflows/.github/workflows/[email protected]
with:
# Runs all Python tests in separate jobs to maximize parallelism
run-tests-individually: true

code-ql:
name: 📝 CodeQL
Expand Down
2 changes: 1 addition & 1 deletion cmake/ExternalDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ endif()
# cmake-format: off
set(MQT_CORE_VERSION 2.7.1
CACHE STRING "MQT Core version")
set(MQT_CORE_REV "ee7482834c75c6ba7b5ce5fbd74829cb513e3c01"
set(MQT_CORE_REV "a7032324072fef82cc5edc8798ca8b72870fb8d2"
CACHE STRING "MQT Core identifier (tag, branch or commit hash)")
set(MQT_CORE_REPO_OWNER "cda-tum"
CACHE STRING "MQT Core repository owner (change when using a fork)")
Expand Down
21 changes: 14 additions & 7 deletions include/checker/dd/TaskManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
#include "ir/operations/OpType.hpp"
#include "ir/operations/Operation.hpp"

#include <cassert>
#include <cstddef>
#include <memory>
#include <utility>

namespace ec {
enum class Direction : bool { Left = true, Right = false };
Expand Down Expand Up @@ -53,10 +55,10 @@ template <class DDType, class Config = dd::DDPackageConfig> class TaskManager {
}

[[nodiscard]] qc::MatrixDD getDD() {
return dd::getDD((*iterator).get(), *package, permutation);
return dd::getDD(iterator->get(), *package, permutation);
}
[[nodiscard]] qc::MatrixDD getInverseDD() {
return dd::getInverseDD((*iterator).get(), *package, permutation);
return dd::getInverseDD(iterator->get(), *package, permutation);
}

[[nodiscard]] const qc::QuantumComputation* getCircuit() const noexcept {
Expand Down Expand Up @@ -85,17 +87,22 @@ template <class DDType, class Config = dd::DDPackageConfig> class TaskManager {
++iterator;
}

void applySwapOperations(DDType& state) {
while (!finished() && (*iterator)->getType() == qc::SWAP) {
applyGate(state);
void applySwapOperations() {
while (!finished() && (*iterator)->getType() == qc::SWAP &&
!(*iterator)->isControlled()) {
const auto& targets = (*iterator)->getTargets();
assert(targets.size() == 2);
const auto t1 = targets[0];
const auto t2 = targets[1];
std::swap(permutation.at(t1), permutation.at(t2));
++iterator;
}
}
void applySwapOperations() { applySwapOperations(internalState); }

void advance(DDType& state, const std::size_t steps) {
for (std::size_t i = 0U; i < steps && !finished(); ++i) {
applyGate(state);
applySwapOperations(state);
applySwapOperations();
}
}
void advance(DDType& state) { advance(state, 1U); }
Expand Down
4 changes: 2 additions & 2 deletions src/checker/dd/DDAlternatingChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ void DDAlternatingChecker::initialize() {
void DDAlternatingChecker::execute() {
while (!taskManager1.finished() && !taskManager2.finished() && !isDone()) {
// skip over any SWAP operations
taskManager1.applySwapOperations(functionality);
taskManager2.applySwapOperations(functionality);
taskManager1.applySwapOperations();
taskManager2.applySwapOperations();

if (!taskManager1.finished() && !taskManager2.finished() && !isDone()) {
// whenever the current functionality resembles the identity, identical
Expand Down
1 change: 1 addition & 0 deletions src/checker/dd/DDSimulationChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ EquivalenceCriterion DDSimulationChecker::checkEquivalence() {
// adjust reference counts to facilitate reuse of the simulation checker
taskManager1.decRef();
taskManager2.decRef();
dd->decRef(initialState);

return equivalence;
}
Expand Down
6 changes: 3 additions & 3 deletions src/checker/dd/simulation/StateGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ qc::VectorDD StateGenerator::generateRandomStabilizerState(
// circuit
auto stabilizer = simulate(&rcs, dd.makeZeroState(randomQubits), dd);

// decrease the ref count right after so that it stays correct later on
dd.decRef(stabilizer);

// 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()});
}
// properly set the reference count for the state
dd.incRef(initial);
dd.decRef(stabilizer);

// return the resulting decision diagram
return initial;
Expand Down

0 comments on commit c3fbfc2

Please sign in to comment.