Skip to content

Commit

Permalink
⬆️ update mqt-core (#350)
Browse files Browse the repository at this point in the history
## Description

This PR was triggered by the failures in #349 and its purpose is to
better isolate the changes into separate PRs.
- cda-tum/mqt-core#515

has dropped the submodules in `mqt-core` and replaced them with
`FetchContent`. As such, the `googletest` test dependency is no longer
available at its typical location.
Consequently, this PR now also uses `FetchContent` to get `googletest`.
In a future PR, this will most likely be extended to the `mqt-core`
submodule as well.

This should unblock #349.

## 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.

---------

Signed-off-by: burgholzer <[email protected]>
  • Loading branch information
burgholzer authored Jan 5, 2024
1 parent 63e1b9e commit 1ab1ffa
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 49 deletions.
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# set required cmake version
cmake_minimum_required(VERSION 3.19...3.27)
cmake_minimum_required(VERSION 3.19...3.28)

project(
qcec
Expand All @@ -19,7 +19,9 @@ endmacro()

check_submodule_present(mqt-core)

option(BUILD_MQT_QCEC_TESTS "Also build tests for the MQT QCEC project" ON)
option(BUILD_MQT_QCEC_BINDINGS "Build the MQT QCEC Python bindings" OFF)

if(BUILD_MQT_QCEC_BINDINGS)
# ensure that the BINDINGS option is set
set(BINDINGS
Expand All @@ -42,11 +44,12 @@ if(BUILD_MQT_QCEC_BINDINGS)
OPTIONAL_COMPONENTS Development.SABIModule)
endif()

include(cmake/ExternalDependencies.cmake)

# add main library code
add_subdirectory(src)

# add test code
option(BUILD_MQT_QCEC_TESTS "Also build tests for the MQT QCEC project" ON)
if(BUILD_MQT_QCEC_TESTS)
enable_testing()
include(GoogleTest)
Expand Down
83 changes: 83 additions & 0 deletions cmake/ExternalDependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Declare all external dependencies and make sure that they are available.

include(FetchContent)
set(FETCH_PACKAGES "")

# A macro to declare a dependency that takes into account the different CMake
# versions and the features that they make available. In particular: - CMake
# 3.24 introduced the `FIND_PACKAGE_ARGS` option to `FetchContent` which allows
# to combine `FetchContent_Declare` and `find_package` in a single call. - CMake
# 3.25 introduced the `SYSTEM` option to `FetchContent_Declare` which marks the
# dependency as a system dependency. This is useful to avoid compiler warnings
# from external header only libraries. - CMake 3.28 introduced the
# `EXCLUDE_FROM_ALL` option to `FetchContent_Declare` which allows to exclude
# all targets from the dependency from the `all` target.
macro(DECLARE_DEPENDENCY)
cmake_parse_arguments(DEPENDENCY "SYSTEM;EXCLUDE_FROM_ALL"
"NAME;URL;MD5;MIN_VERSION;ALT_NAME" "" ${ARGN})
set(ADDITIONAL_OPTIONS "")
if(DEPENDENCY_SYSTEM AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.25)
list(APPEND ADDITIONAL_OPTIONS SYSTEM)
endif()
if(DEPENDENCY_EXCLUDE_FROM_ALL AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.28)
list(APPEND ADDITIONAL_OPTIONS EXCLUDE_FROM_ALL)
endif()
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28)
FetchContent_Declare(
${DEPENDENCY_NAME}
URL ${DEPENDENCY_URL}
URL_MD5 ${DEPENDENCY_MD5}
${ADDITIONAL_OPTIONS} FIND_PACKAGE_ARGS ${DEPENDENCY_MIN_VERSION} NAMES
${DEPENDENCY_ALT_NAME})
list(APPEND FETCH_PACKAGES ${DEPENDENCY_NAME})
elseif(CMAKE_VERSION VERSION_GREATER_EQUAL 3.25)
FetchContent_Declare(
${DEPENDENCY_NAME}
URL ${DEPENDENCY_URL}
URL_MD5 ${DEPENDENCY_MD5}
${ADDITIONAL_OPTIONS} FIND_PACKAGE_ARGS ${DEPENDENCY_MIN_VERSION} NAMES
${DEPENDENCY_ALT_NAME})
list(APPEND FETCH_PACKAGES ${DEPENDENCY_NAME})
elseif(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
FetchContent_Declare(
${DEPENDENCY_NAME}
URL ${DEPENDENCY_URL}
URL_MD5 ${DEPENDENCY_MD5}
${ADDITIONAL_OPTIONS} FIND_PACKAGE_ARGS ${DEPENDENCY_MIN_VERSION} NAMES
${DEPENDENCY_ALT_NAME})
list(APPEND FETCH_PACKAGES ${DEPENDENCY_NAME})
else()
# try to get the system installed version
find_package(${DEPENDENCY_NAME} ${DEPENDENCY_MIN_VERSION} QUIET NAMES
${DEPENDENCY_ALT_NAME})
if(NOT ${DEPENDENCY_NAME}_FOUND)
FetchContent_Declare(
${DEPENDENCY_NAME}
URL ${DEPENDENCY_URL}
URL_MD5 ${DEPENDENCY_MD5})
list(APPEND FETCH_PACKAGES ${DEPENDENCY_NAME})
endif()
endif()
endmacro()

if(BUILD_MQT_QCEC_TESTS)
set(gtest_force_shared_crt # cmake-lint: disable=C0103
ON
CACHE BOOL "" FORCE)
declare_dependency(
NAME
googletest
URL
https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz
MD5
c8340a482851ef6a3fe618a082304cfc
MIN_VERSION
1.14.0
ALT_NAME
GTest
SYSTEM
EXCLUDE_FROM_ALL)
endif()

# Make all declared dependencies available.
FetchContent_MakeAvailable(${FETCH_PACKAGES})
2 changes: 1 addition & 1 deletion extern/mqt-core
Submodule mqt-core updated 76 files
+1 −1 .cirrus.yml
+0 −1 .github/codecov.yml
+0 −11 .github/dependabot.yml
+0 −25 .gitmodules
+0 −2 .pre-commit-config.yaml
+0 −4 .readthedocs.yaml
+5 −17 CMakeLists.txt
+9 −0 README.md
+0 −10 cmake/CheckSubmodule.cmake
+141 −0 cmake/ExternalDependencies.cmake
+1 −6 docs/DevelopmentGuide.md
+10 −25 docs/quickstart.ipynb
+3 −3 eval/eval_dd_package.cpp
+0 −1 extern/boost/config
+0 −1 extern/boost/multiprecision
+0 −1 extern/googletest
+0 −1,018 extern/hls_colorwheel.svg
+0 −1 extern/json
+0 −1 extern/pybind11_json
+12 −3 include/Definitions.hpp
+25 −0 include/QuantumComputation.hpp
+1 −1 include/dd/Benchmark.hpp
+6 −10 include/dd/FunctionalityConstruction.hpp
+65 −74 include/dd/Operations.hpp
+12 −14 include/dd/Simulation.hpp
+1 −1 include/dd/UniqueTable.hpp
+1 −2 include/dd/statistics/PackageStatistics.hpp
+2 −1 include/dd/statistics/Statistics.hpp
+2 −0 include/operations/StandardOperation.hpp
+3 −3 include/parsers/qasm3_parser/Exception.hpp
+2 −2 include/python/pybind11.hpp
+1 −1 include/python/qiskit/QuantumCircuit.hpp
+0 −9 pyproject.toml
+0 −46 src/CMakeLists.txt
+3 −3 src/QuantumComputation.cpp
+4 −4 src/dd/Benchmark.cpp
+0 −1 src/dd/CMakeLists.txt
+62 −68 src/dd/FunctionalityConstruction.cpp
+6 −6 src/dd/Operations.cpp
+51 −53 src/dd/Simulation.cpp
+1 −1 src/dd/statistics/MemoryManagerStatistics.cpp
+1 −1 src/dd/statistics/Statistics.cpp
+1 −1 src/dd/statistics/TableStatistics.cpp
+2 −1 src/dd/statistics/UniqueTableStatistics.cpp
+0 −1 src/ecc/CMakeLists.txt
+4 −2 src/mqt/core/_core/__init__.pyi
+5 −5 src/mqt/core/_core/operations.pyi
+8 −3 src/mqt/core/io.py
+60 −25 src/operations/StandardOperation.cpp
+0 −12 src/python/CMakeLists.txt
+2 −3 src/python/operations/register_operation.cpp
+16 −23 src/python/register_quantum_computation.cpp
+1 −1 src/python/symbolic/register_expression.cpp
+5 −20 src/zx/CMakeLists.txt
+2 −17 test/CMakeLists.txt
+24 −20 test/algorithms/eval_dynamic_circuits.cpp
+2 −2 test/algorithms/test_bernsteinvazirani.cpp
+1 −1 test/algorithms/test_grcs.cpp
+1 −1 test/algorithms/test_qft.cpp
+6 −6 test/algorithms/test_qpe.cpp
+0 −1 test/algorithms/test_wstate.cpp
+1 −1 test/dd/test_complex.cpp
+88 −34 test/dd/test_dd_functionality.cpp
+4 −4 test/dd/test_dd_noise_functionality.cpp
+1 −1 test/dd/test_edge_functionality.cpp
+1 −1 test/dd/test_package.cpp
+32 −2 test/python/test_io.py
+2 −2 test/unittests/test_ecc_functionality.cpp
+27 −33 test/unittests/test_io.cpp
+201 −534 test/unittests/test_qasm3_parser.cpp
+6 −6 test/unittests/test_qfr_functionality.cpp
+1 −1 test/zx/test_expression.cpp
+1 −1 test/zx/test_rational.cpp
+1 −1 test/zx/test_simplify.cpp
+1 −1 test/zx/test_zx.cpp
+17 −19 test/zx/test_zx_functionality.cpp
6 changes: 3 additions & 3 deletions include/checker/dd/TaskManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,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 @@ -95,7 +95,7 @@ template <class DDType, class Config = dd::DDPackageConfig> class TaskManager {
void finish() { finish(internalState); }

void changePermutation(DDType& state) {
dd::changePermutation(state, permutation, qc->outputPermutation, package,
dd::changePermutation(state, permutation, qc->outputPermutation, *package,
static_cast<bool>(direction));
}
void changePermutation() { changePermutation(internalState); }
Expand Down
41 changes: 20 additions & 21 deletions include/checker/dd/simulation/StateGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ class StateGenerator {
}
StateGenerator() : StateGenerator(0U) {}

template <class DDPackage = dd::Package<>>
template <class Config = dd::DDPackageConfig>
qc::VectorDD
generateRandomState(std::unique_ptr<DDPackage>& dd,
const std::size_t totalQubits,
const std::size_t ancillaryQubits = 0U,
const StateType type = StateType::ComputationalBasis) {
generateRandomState(dd::Package<Config>& dd, const std::size_t totalQubits,
const std::size_t ancillaryQubits = 0U,
const StateType type = StateType::ComputationalBasis) {
switch (type) {
case ec::StateType::Random1QBasis:
return generateRandom1QBasisState(dd, totalQubits, ancillaryQubits);
Expand All @@ -39,9 +38,9 @@ class StateGenerator {
}
}

template <class DDPackage = dd::Package<>>
template <class Config = dd::DDPackageConfig>
qc::VectorDD generateRandomComputationalBasisState(
std::unique_ptr<DDPackage>& dd, const std::size_t totalQubits,
dd::Package<Config>& dd, const std::size_t totalQubits,
const std::size_t ancillaryQubits = 0U) {
// determine how many qubits truly are random
const std::size_t randomQubits = totalQubits - ancillaryQubits;
Expand Down Expand Up @@ -87,14 +86,14 @@ class StateGenerator {
}

// return the appropriate decision diagram
return dd->makeBasisState(totalQubits, stimulusBits);
return dd.makeBasisState(totalQubits, stimulusBits);
}

template <class DDPackage = dd::Package<>>
template <class Config = dd::DDPackageConfig>
qc::VectorDD
generateRandom1QBasisState(std::unique_ptr<DDPackage>& dd,
const std::size_t totalQubits,
const std::size_t ancillaryQubits = 0U) {
generateRandom1QBasisState(dd::Package<Config>& dd,
const std::size_t totalQubits,
const std::size_t ancillaryQubits = 0U) {
// determine how many qubits truly are random
const std::size_t randomQubits = totalQubits - ancillaryQubits;

Expand Down Expand Up @@ -127,14 +126,14 @@ class StateGenerator {
}

// return the appropriate decision diagram
return dd->makeBasisState(totalQubits, randomBasisState);
return dd.makeBasisState(totalQubits, randomBasisState);
}

template <class DDPackage = dd::Package<>>
template <class Config = dd::DDPackageConfig>
qc::VectorDD
generateRandomStabilizerState(std::unique_ptr<DDPackage>& dd,
const std::size_t totalQubits,
const std::size_t ancillaryQubits = 0U) {
generateRandomStabilizerState(dd::Package<Config>& dd,
const std::size_t totalQubits,
const std::size_t ancillaryQubits = 0U) {
// determine how many qubits truly are random
const std::size_t randomQubits = totalQubits - ancillaryQubits;

Expand All @@ -145,16 +144,16 @@ class StateGenerator {

// generate the associated stabilizer state by simulating the Clifford
// circuit
auto stabilizer = simulate(&rcs, dd->makeZeroState(randomQubits), dd);
auto stabilizer = simulate(&rcs, dd.makeZeroState(randomQubits), dd);

// decrease the ref count right after so that it stays correct later on
dd->decRef(stabilizer);
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()});
initial = dd.makeDDNode(static_cast<dd::Qubit>(p),
std::array{initial, qc::VectorDD::zero()});
}

// return the resulting decision diagram
Expand Down
8 changes: 0 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ sdist.exclude = [
"**/plots",
"**/test",
"**/tests",
"extern/mqt-core/extern/json/include",
"extern/mqt-core/extern/googletest",
"extern/mqt-core/extern/boost/config/checks",
"extern/mqt-core/extern/boost/config/tools",
"extern/mqt-core/extern/boost/multiprecision/config",
"extern/mqt-core/extern/boost/multiprecision/example",
"extern/mqt-core/extern/boost/multiprecision/performance",
"extern/mqt-core/extern/boost/multiprecision/tools"
]

[tool.scikit-build.cmake.define]
Expand Down
2 changes: 1 addition & 1 deletion src/checker/dd/DDSimulationChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void DDSimulationChecker::setRandomInitialState(StateGenerator& generator) {
const auto stateType = configuration.simulation.stateType;

initialState =
generator.generateRandomState(dd, nqubits, nancillary, stateType);
generator.generateRandomState(*dd, nqubits, nancillary, stateType);
}

} // namespace ec
9 changes: 0 additions & 9 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
if(NOT TARGET gtest OR NOT TARGET gmock)
# Prevent overriding the parent project's compiler/linker settings on Windows
set(gtest_force_shared_crt # cmake-lint: disable=C0103
ON
CACHE BOOL "" FORCE)
add_subdirectory("${PROJECT_SOURCE_DIR}/extern/mqt-core/extern/googletest"
"extern/mqt-core/extern/googletest" EXCLUDE_FROM_ALL)
endif()

package_add_test(
${PROJECT_NAME}_test
${PROJECT_NAME}
Expand Down
4 changes: 2 additions & 2 deletions test/test_simple_circuit_identities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class SimpleCircuitIdentitiesTest
void SetUp() override {
const auto [circ1, circ2] = GetParam().second;
std::stringstream ss1{circ1};
qcOriginal.import(ss1, qc::Format::OpenQASM);
qcOriginal.import(ss1, qc::Format::OpenQASM2);
std::stringstream ss2{circ2};
qcAlternative.import(ss2, qc::Format::OpenQASM);
qcAlternative.import(ss2, qc::Format::OpenQASM2);

config.optimizations.reconstructSWAPs = false;
config.optimizations.fuseSingleQubitGates = false;
Expand Down
4 changes: 2 additions & 2 deletions test/test_zx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ TEST_F(ZXTest, NonEquivalent) {
qcOriginal.import(
std::stringstream("OPENQASM 2.0;\ninclude \"qelib1.inc\";\nqreg "
"q[2];\ncx q[0], q[1];\n"),
qc::Format::OpenQASM);
qc::Format::OpenQASM2);
qcAlternative.import(
std::stringstream("OPENQASM 2.0;\ninclude \"qelib1.inc\";\nqreg q[2];\nh "
"q[0]; cx q[1], q[0]; h q[0]; h q[1];\n"),
qc::Format::OpenQASM);
qc::Format::OpenQASM2);
ecm = std::make_unique<ec::EquivalenceCheckingManager>(qcOriginal,
qcAlternative, config);

Expand Down

0 comments on commit 1ab1ffa

Please sign in to comment.