diff --git a/.clang-tidy b/.clang-tidy index 7be7a6fa..b48db352 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -8,6 +8,7 @@ Checks: | -clang-analyzer-core.NullDereference, clang-diagnostic-*, cppcoreguidelines-*, + -cppcoreguidelines-pro-bounds-avoid-unchecked-container-access, -cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-special-member-functions, -cppcoreguidelines-avoid-magic-numbers, @@ -22,6 +23,7 @@ Checks: | -modernize-use-trailing-return-type, performance-*, portability-*, + -portability-avoid-pragma-once, readability-*, -readability-identifier-length, -readability-magic-numbers, diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 25c88c4d..eb433d9d 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -12,7 +12,7 @@ permissions: {} jobs: build-sdist: name: 🐍 Packaging - uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-python-packaging-sdist.yml@ace7363a2a8e036e5efc6717be67f1eda29a120e # v2.4.2 + uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-python-packaging-sdist.yml@17f5c58e46c51027501e7d8d38dc182654ed035c # v2.5.0 permissions: contents: read @@ -31,7 +31,7 @@ jobs: windows-2022, windows-11-arm, ] - uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-python-packaging-wheel-cibuildwheel.yml@ace7363a2a8e036e5efc6717be67f1eda29a120e # v2.4.2 + uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-python-packaging-wheel-cibuildwheel.yml@17f5c58e46c51027501e7d8d38dc182654ed035c # v2.5.0 with: runs-on: ${{ matrix.runs-on }} permissions: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d9b27ab8..5160d086 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ permissions: {} jobs: change-detection: name: 🔍 Change - uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-change-detection.yml@ace7363a2a8e036e5efc6717be67f1eda29a120e # v2.4.2 + uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-change-detection.yml@17f5c58e46c51027501e7d8d38dc182654ed035c # v2.5.0 permissions: contents: read @@ -39,7 +39,7 @@ jobs: compiler: gcc preset: debug run-on-draft: true - uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-cpp-tests-ubuntu.yml@ace7363a2a8e036e5efc6717be67f1eda29a120e # v2.4.2 + uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-cpp-tests-ubuntu.yml@17f5c58e46c51027501e7d8d38dc182654ed035c # v2.5.0 with: runs-on: ${{ matrix.runs-on }} compiler: ${{ matrix.compiler }} @@ -64,7 +64,7 @@ jobs: compiler: clang preset: debug run-on-draft: true - uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-cpp-tests-macos.yml@ace7363a2a8e036e5efc6717be67f1eda29a120e # v2.4.2 + uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-cpp-tests-macos.yml@17f5c58e46c51027501e7d8d38dc182654ed035c # v2.5.0 with: runs-on: ${{ matrix.runs-on }} compiler: ${{ matrix.compiler }} @@ -89,7 +89,7 @@ jobs: compiler: msvc preset: debug run-on-draft: true - uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-cpp-tests-windows.yml@ace7363a2a8e036e5efc6717be67f1eda29a120e # v2.4.2 + uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-cpp-tests-windows.yml@17f5c58e46c51027501e7d8d38dc182654ed035c # v2.5.0 with: runs-on: ${{ matrix.runs-on }} compiler: ${{ matrix.compiler }} @@ -102,10 +102,10 @@ jobs: name: 🇨 Lint needs: change-detection if: fromJSON(needs.change-detection.outputs.run-cpp-linter) - uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-cpp-linter.yml@ace7363a2a8e036e5efc6717be67f1eda29a120e # v2.4.2 + uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-cpp-linter.yml@17f5c58e46c51027501e7d8d38dc182654ed035c # v2.5.0 with: build-project: true - clang-version: 20 + clang-version: 23 files-changed-only: true install-pkgs: "nanobind==3.0.1" setup-python: true @@ -122,7 +122,7 @@ jobs: fail-fast: false matrix: runs-on: [ubuntu-26.04, ubuntu-26.04-arm, macos-26, windows-2022] - uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-python-tests.yml@ace7363a2a8e036e5efc6717be67f1eda29a120e # v2.4.2 + uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-python-tests.yml@17f5c58e46c51027501e7d8d38dc182654ed035c # v2.5.0 with: runs-on: ${{ matrix.runs-on }} permissions: @@ -132,7 +132,7 @@ jobs: name: 🐍 Coverage needs: [change-detection, python-tests] if: fromJSON(needs.change-detection.outputs.run-python-tests) - uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-python-coverage.yml@ace7363a2a8e036e5efc6717be67f1eda29a120e # v2.4.2 + uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-python-coverage.yml@17f5c58e46c51027501e7d8d38dc182654ed035c # v2.5.0 permissions: contents: read id-token: write @@ -141,11 +141,14 @@ jobs: name: 🐍 Lint needs: change-detection if: fromJSON(needs.change-detection.outputs.run-python-linter) - uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-python-linter.yml@ace7363a2a8e036e5efc6717be67f1eda29a120e # v2.4.2 + uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-python-linter.yml@17f5c58e46c51027501e7d8d38dc182654ed035c # v2.5.0 with: check-stubs: true enable-ty: true enable-mypy: false + secrets: + APP_ID: ${{ secrets.APP_ID }} + APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }} permissions: contents: read @@ -153,7 +156,7 @@ jobs: name: 🚀 CD needs: change-detection if: fromJSON(needs.change-detection.outputs.run-cd) - uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-python-packaging-sdist.yml@ace7363a2a8e036e5efc6717be67f1eda29a120e # v2.4.2 + uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-python-packaging-sdist.yml@17f5c58e46c51027501e7d8d38dc182654ed035c # v2.5.0 permissions: contents: read @@ -172,7 +175,7 @@ jobs: windows-2022, windows-11-arm, ] - uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-python-packaging-wheel-cibuildwheel.yml@ace7363a2a8e036e5efc6717be67f1eda29a120e # v2.4.2 + uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-python-packaging-wheel-cibuildwheel.yml@17f5c58e46c51027501e7d8d38dc182654ed035c # v2.5.0 with: runs-on: ${{ matrix.runs-on }} permissions: diff --git a/.github/workflows/update-mqt-core.yml b/.github/workflows/update-mqt-core.yml index 9ff049e3..d0adaec9 100644 --- a/.github/workflows/update-mqt-core.yml +++ b/.github/workflows/update-mqt-core.yml @@ -17,7 +17,7 @@ permissions: {} jobs: update-mqt-core: name: ⬆️ Update MQT Core - uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-mqt-core-update.yml@ace7363a2a8e036e5efc6717be67f1eda29a120e # v2.4.2 + uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-mqt-core-update.yml@17f5c58e46c51027501e7d8d38dc182654ed035c # v2.5.0 with: max-major-version: "3" secrets: diff --git a/.github/workflows/upstream.yml b/.github/workflows/upstream.yml index 1e64c900..f5cfefcd 100644 --- a/.github/workflows/upstream.yml +++ b/.github/workflows/upstream.yml @@ -21,7 +21,7 @@ jobs: fail-fast: false matrix: runs-on: [ubuntu-26.04, macos-26, windows-2022] - uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-qiskit-upstream-tests.yml@ace7363a2a8e036e5efc6717be67f1eda29a120e # v2.4.2 + uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-qiskit-upstream-tests.yml@17f5c58e46c51027501e7d8d38dc182654ed035c # v2.5.0 with: runs-on: ${{ matrix.runs-on }} setup-z3: true @@ -32,7 +32,7 @@ jobs: name: Create issue on failure needs: qiskit-upstream-tests if: ${{ always() }} - uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-qiskit-upstream-issue.yml@ace7363a2a8e036e5efc6717be67f1eda29a120e # v2.4.2 + uses: munich-quantum-toolkit/workflows/.github/workflows/reusable-qiskit-upstream-issue.yml@17f5c58e46c51027501e7d8d38dc182654ed035c # v2.5.0 with: tests-result: ${{ needs.qiskit-upstream-tests.result }} permissions: diff --git a/bindings/InterfaceBindings.cpp b/bindings/InterfaceBindings.cpp index 684da349..76a6b911 100644 --- a/bindings/InterfaceBindings.cpp +++ b/bindings/InterfaceBindings.cpp @@ -54,8 +54,6 @@ void checkOrThrow(Result result) { } } -} // namespace - /** * @brief A representation of statevectors in C++ style, using std::vector * instead of a raw pointer. @@ -68,8 +66,10 @@ struct StatevectorCPP { std::vector amplitudes; }; +} // namespace + // NOLINTNEXTLINE(misc-use-internal-linkage) -void bindFramework(nb::module_& m) { +void bindFramework(const nb::module_& m) { // Bind the Result enum nb::enum_(m, "Result", "Represents the result of an operation.") .value("OK", OK, "Indicates that the operation was successful.") @@ -555,13 +555,17 @@ index of the register. "get_state_vector_full", [](SimulationState* self) { const size_t numQubits = self->getNumQubits(self); - const std::vector amplitudes(1 << numQubits); - StatevectorCPP result{.numQubits = numQubits, - .numStates = 1ULL << numQubits, - .amplitudes = amplitudes}; - Statevector output{.numQubits = numQubits, - .numStates = result.numStates, - .amplitudes = result.amplitudes.data()}; + const std::vector amplitudes(1ULL << numQubits); + StatevectorCPP result{ + .numQubits = numQubits, + .numStates = 1ULL << numQubits, + .amplitudes = amplitudes, + }; + const Statevector output{ + .numQubits = numQubits, + .numStates = result.numStates, + .amplitudes = result.amplitudes.data(), + }; checkOrThrow(self->getStateVectorFull(self, &output)); return result; }, @@ -573,13 +577,17 @@ index of the register. "get_state_vector_sub", [](SimulationState* self, std::vector qubits) { const size_t numQubits = qubits.size(); - const std::vector amplitudes(1 << numQubits); - StatevectorCPP result{.numQubits = numQubits, - .numStates = 1ULL << numQubits, - .amplitudes = amplitudes}; - Statevector output{.numQubits = numQubits, - .numStates = result.numStates, - .amplitudes = result.amplitudes.data()}; + const std::vector amplitudes(1ULL << numQubits); + StatevectorCPP result{ + .numQubits = numQubits, + .numStates = 1ULL << numQubits, + .amplitudes = amplitudes, + }; + const Statevector output{ + .numQubits = numQubits, + .numStates = result.numStates, + .amplitudes = result.amplitudes.data(), + }; checkOrThrow(self->getStateVectorSub(self, numQubits, qubits.data(), &output)); return result; @@ -690,7 +698,7 @@ This is the main class of the `mqt-debugger` library, allowing developers to ste } // NOLINTNEXTLINE(misc-use-internal-linkage) -void bindDiagnostics(nb::module_& m) { +void bindDiagnostics(const nb::module_& m) { // Bind the ErrorCauseType enum nb::enum_(m, "ErrorCauseType", "The type of a potential error cause.") @@ -882,7 +890,7 @@ suggested position. .def( "suggest_new_assertions", [](Diagnostics* self) { - const size_t stringSize = 2 << 17; + const size_t stringSize = 2U << 17U; const size_t count = self->suggestNewAssertions(self, nullptr, nullptr, 0); std::vector positions(count); diff --git a/bindings/bindings.cpp b/bindings/bindings.cpp index 68bfb037..73de2b19 100644 --- a/bindings/bindings.cpp +++ b/bindings/bindings.cpp @@ -21,8 +21,8 @@ namespace nb = nanobind; using namespace nb::literals; // forward declarations -void bindFramework(nb::module_& m); -void bindDiagnostics(nb::module_& m); +void bindFramework(const nb::module_& m); +void bindDiagnostics(const nb::module_& m); void bindBackend(nb::module_& m); NB_MODULE(MQT_DEBUGGER_MODULE_NAME, m) { diff --git a/bindings/dd/DDSimDebugBindings.cpp b/bindings/dd/DDSimDebugBindings.cpp index 7f1cb938..5f61ed5d 100644 --- a/bindings/dd/DDSimDebugBindings.cpp +++ b/bindings/dd/DDSimDebugBindings.cpp @@ -28,7 +28,7 @@ using namespace mqt::debugger; void bindBackend(nb::module_& m) { m.def( "create_ddsim_simulation_state", - []() { + [] { // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) auto* state = new DDSimulationState(); createDDSimulationState(state); diff --git a/include/backend/dd/DDSimDebug.hpp b/include/backend/dd/DDSimDebug.hpp index 94e195f2..c6153845 100644 --- a/include/backend/dd/DDSimDebug.hpp +++ b/include/backend/dd/DDSimDebug.hpp @@ -554,18 +554,21 @@ Result ddsimGetQuantumVariableName(SimulationState* self, size_t variableIndex, * * The state vector is expected to be initialized with the correct number of * qubits and allocated space for the amplitudes before calling this method. + * Only the amplitude buffer is modified. * @param self The instance to query. * @param output A reference to a `Statevector` instance to store the state * vector. * @return The result of the operation. */ -Result ddsimGetStateVectorFull(SimulationState* self, Statevector* output); +Result ddsimGetStateVectorFull(SimulationState* self, + const Statevector* output); /** * @brief Gets a sub-state of the state vector of the simulation at the current * time. * * The state vector is expected to be initialized with the correct number of * qubits and allocated space for the amplitudes before calling this method. + * Only the amplitude buffer is modified. * \n\n * * This method also supports the re-ordering of qubits, but does not allow @@ -578,7 +581,7 @@ Result ddsimGetStateVectorFull(SimulationState* self, Statevector* output); * @return The result of the operation. */ Result ddsimGetStateVectorSub(SimulationState* self, size_t subStateSize, - const size_t* qubits, Statevector* output); + const size_t* qubits, const Statevector* output); /** * @brief Sets a breakpoint at the desired position in the code. @@ -688,7 +691,7 @@ bool checkAssertion(DDSimulationState* ddsim, * @param index The index of the classical bit. * @return The name of the classical bit. */ -std::string getClassicalBitName(DDSimulationState* ddsim, size_t index); +std::string getClassicalBitName(const DDSimulationState* ddsim, size_t index); /** * @brief Gets the name of a qubit variable by its index. @@ -696,7 +699,7 @@ std::string getClassicalBitName(DDSimulationState* ddsim, size_t index); * @param index The index of the qubit variable. * @return The name of the qubit variable. */ -std::string getQuantumBitName(DDSimulationState* ddsim, size_t index); +std::string getQuantumBitName(const DDSimulationState* ddsim, size_t index); /** * @brief Gets the qubit index from a variable name. diff --git a/include/backend/debug.h b/include/backend/debug.h index b3840132..e8cc7ef0 100644 --- a/include/backend/debug.h +++ b/include/backend/debug.h @@ -347,12 +347,14 @@ struct SimulationStateStruct { * * The state vector is expected to be initialized with the correct number of * qubits and allocated space for the amplitudes before calling this method. + * Only the amplitude buffer is modified. * @param self The instance to query. * @param output A reference to a `Statevector` instance to store the state * vector. * @return The result of the operation. */ - Result (*getStateVectorFull)(SimulationState* self, Statevector* output); + Result (*getStateVectorFull)(SimulationState* self, + const Statevector* output); /** * @brief Gets a sub-state of the state vector of the simulation at the @@ -360,6 +362,7 @@ struct SimulationStateStruct { * * The state vector is expected to be initialized with the correct number of * qubits and allocated space for the amplitudes before calling this method. + * Only the amplitude buffer is modified. * \n\n * * This method also supports the re-ordering of qubits, but does not allow @@ -372,7 +375,7 @@ struct SimulationStateStruct { * @return The result of the operation. */ Result (*getStateVectorSub)(SimulationState* self, size_t subStateSize, - const size_t* qubits, Statevector* output); + const size_t* qubits, const Statevector* output); /** * @brief Sets a breakpoint at the desired position in the code. diff --git a/include/common/ComplexMathematics.hpp b/include/common/ComplexMathematics.hpp index 647ff9b4..d5f57260 100644 --- a/include/common/ComplexMathematics.hpp +++ b/include/common/ComplexMathematics.hpp @@ -29,7 +29,7 @@ namespace mqt::debugger { * @param c The complex number. * @return The computed magnitude. */ -double complexMagnitude(Complex& c); +double complexMagnitude(const Complex& c); /** * @brief Add two complex numbers. @@ -64,7 +64,7 @@ Complex complexConjugate(const Complex& c); * @param qubit2 The second qubit to check. * @return True if the qubits are entangled, false otherwise. */ -bool areQubitsEntangled(std::vector>& densityMatrix, +bool areQubitsEntangled(const std::vector>& densityMatrix, size_t qubit1, size_t qubit2); /** diff --git a/src/backend/dd/DDSimDebug.cpp b/src/backend/dd/DDSimDebug.cpp index 5cc3b31b..b4b0f7eb 100644 --- a/src/backend/dd/DDSimDebug.cpp +++ b/src/backend/dd/DDSimDebug.cpp @@ -38,7 +38,6 @@ #include #include -#include #include #include #include @@ -187,7 +186,7 @@ void resetSimulationState(DDSimulationState* ddsim) { ddsim->dd->decRef(ddsim->simulationState); } ddsim->simulationState = - dd::makeZeroState(ddsim->qc->getNqubits(), *(ddsim->dd)); + dd::makeZeroState(ddsim->qc->getNqubits(), *ddsim->dd); ddsim->dd->incRef(ddsim->simulationState); ddsim->paused = false; // Return the classical side to its initial state (all bits false), @@ -208,7 +207,7 @@ std::vector extractBits(const std::vector& indices, size_t value) { std::vector result(indices.size()); for (size_t i = 0; i < indices.size(); i++) { - result[i] = (((value >> indices[i]) & 1) == 1); + result[i] = (((value >> indices[i]) & 1U) == 1U); } return result; } @@ -224,7 +223,7 @@ bool checkAssertionEntangled( std::unique_ptr& assertion) { Statevector sv; sv.numQubits = ddsim->interface.getNumQubits(&ddsim->interface); - sv.numStates = 1 << sv.numQubits; + sv.numStates = 1ULL << sv.numQubits; std::vector amplitudes(sv.numStates); sv.amplitudes = amplitudes.data(); ddsim->interface.getStateVectorFull(&ddsim->interface, &sv); @@ -235,7 +234,8 @@ bool checkAssertionEntangled( } std::vector> densityMatrix( - sv.numStates, std::vector(sv.numStates, {0, 0})); + sv.numStates, + std::vector(sv.numStates, {.real = 0, .imaginary = 0})); for (size_t i = 0; i < sv.numStates; i++) { for (size_t j = 0; j < sv.numStates; j++) { densityMatrix[i][j] = @@ -309,7 +309,7 @@ bool checkAssertionEqualityStatevector( Statevector sv; sv.numQubits = qubits.size(); - sv.numStates = 1 << sv.numQubits; + sv.numStates = 1ULL << sv.numQubits; std::vector amplitudes(sv.numStates); sv.amplitudes = amplitudes.data(); @@ -366,7 +366,7 @@ bool checkAssertionEqualityCircuit( Statevector sv2; sv2.numQubits = secondSimulation.interface.getNumQubits(&secondSimulation.interface); - sv2.numStates = 1 << sv2.numQubits; + sv2.numStates = 1ULL << sv2.numQubits; std::vector amplitudes2(sv2.numStates); sv2.amplitudes = amplitudes2.data(); secondSimulation.interface.getStateVectorFull(&secondSimulation.interface, @@ -374,7 +374,7 @@ bool checkAssertionEqualityCircuit( Statevector sv; sv.numQubits = qubits.size(); - sv.numStates = 1 << sv.numQubits; + sv.numStates = 1ULL << sv.numQubits; std::vector amplitudes(sv.numStates); sv.amplitudes = amplitudes.data(); if (ddsim->interface.getStateVectorSub(&ddsim->interface, sv.numQubits, @@ -407,7 +407,7 @@ std::string validCodeFromChildren(const Instruction& parent, return code; } code += " { "; - for (auto child : parent.childInstructions) { + for (const auto child : parent.childInstructions) { const auto& childInstruction = allInstructions[child]; if (childInstruction.assertion != nullptr) { continue; @@ -623,7 +623,7 @@ void compileProjectiveMeasurement( stream << "measure " << qbit << " -> " << cbit << "[0];\n"; } - for (auto& it : newQc) { + for (const auto& it : newQc) { serializer.serialize(*it, qubitIndexToRegisterMap, {}); } } @@ -826,7 +826,11 @@ Result ddsimChangeAmplitudeValue(SimulationState* self, const char* basisState, const auto numStates = 1ULL << numQubits; std::vector amplitudes(numStates); - Statevector sv{numQubits, numStates, amplitudes.data()}; + const Statevector sv{ + .numQubits = numQubits, + .numStates = numStates, + .amplitudes = amplitudes.data(), + }; if (self->getStateVectorFull(self, &sv) != OK) { return ERROR; } @@ -890,7 +894,7 @@ Result ddsimChangeAmplitudeValue(SimulationState* self, const char* basisState, } try { - auto newState = dd::makeStateFromVector(ddVector, *(ddsim->dd)); + const auto newState = dd::makeStateFromVector(ddVector, *ddsim->dd); ddsim->dd->incRef(newState); if (ddsim->simulationState.p != nullptr) { ddsim->dd->decRef(ddsim->simulationState); @@ -1067,26 +1071,28 @@ Result ddsimStepForward(SimulationState* self) { dynamic_cast(ddsim->iterator->get()) ->getClassics(); for (size_t i = 0; i < qubitsToMeasure.size(); i++) { - auto qubit = qubitsToMeasure[i]; - auto classicalBit = classicalBits[i]; + const auto qubit = qubitsToMeasure[i]; + const auto classicalBit = classicalBits[i]; auto [pZero, pOne] = dd::Package::determineMeasurementProbabilities( ddsim->simulationState, static_cast(qubit)); - auto rnd = generateRandomNumber(); - auto result = rnd < pZero; + const auto rnd = generateRandomNumber(); + const auto result = rnd < pZero; ddsim->dd->performCollapsingMeasurement(ddsim->simulationState, static_cast(qubit), result ? pZero : pOne, result); - auto name = getClassicalBitName(ddsim, classicalBit); + const auto name = getClassicalBitName(ddsim, classicalBit); if (ddsim->variables.contains(name)) { VariableValue value; value.boolValue = !result; ddsim->variables[name].value = value; } else { ddsim->variableNames.push_back(std::make_unique(name)); - const Variable newVariable{ddsim->variableNames.back()->data(), - VariableType::VarBool, - {!result}}; + const Variable newVariable{ + .name = ddsim->variableNames.back()->data(), + .type = VariableType::VarBool, + .value = {.boolValue = !result}, + }; ddsim->variables.insert({name, newVariable}); } } @@ -1099,7 +1105,7 @@ Result ddsimStepForward(SimulationState* self) { } if ((*ddsim->iterator)->getType() == qc::Reset) { // Perform the desired qubits. This will first perform a measurement. - auto qubitsToMeasure = (*ddsim->iterator)->getTargets(); + const auto qubitsToMeasure = (*ddsim->iterator)->getTargets(); ddsim->iterator++; ddsim->previousInstructionStack.clear(); ddsim->restoreCallReturnStack.clear(); @@ -1107,15 +1113,15 @@ Result ddsimStepForward(SimulationState* self) { for (const auto qubit : qubitsToMeasure) { auto [pZero, pOne] = dd::Package::determineMeasurementProbabilities( ddsim->simulationState, static_cast(qubit)); - auto rnd = generateRandomNumber(); - auto result = rnd < pZero; + const auto rnd = generateRandomNumber(); + const auto result = rnd < pZero; ddsim->dd->performCollapsingMeasurement(ddsim->simulationState, static_cast(qubit), result ? pZero : pOne, result); if (!result) { const auto x = qc::StandardOperation(qubit, qc::X); - auto tmp = ddsim->dd->multiply(dd::getDD(x, *ddsim->dd), - ddsim->simulationState); + const auto tmp = ddsim->dd->multiply(dd::getDD(x, *ddsim->dd), + ddsim->simulationState); ddsim->dd->incRef(tmp); ddsim->dd->decRef(ddsim->simulationState); ddsim->simulationState = tmp; @@ -1159,10 +1165,10 @@ Result ddsimStepForward(SimulationState* self) { applyComparison(registerValue, exp, op->getComparisonKind()); } if (conditionMet) { - auto* thenOp = op->getThenOp(); + const auto* thenOp = op->getThenOp(); currDD = dd::getDD(*thenOp, *ddsim->dd); } else if (op->getElseOp() != nullptr) { - auto* elseOp = op->getElseOp(); + const auto* elseOp = op->getElseOp(); currDD = dd::getDD(*elseOp, *ddsim->dd); } else { currDD = dd::Package::makeIdent(); @@ -1173,7 +1179,7 @@ Result ddsimStepForward(SimulationState* self) { *ddsim->dd); // retrieve the "new" current operation } - auto temp = ddsim->dd->multiply(currDD, ddsim->simulationState); + const auto temp = ddsim->dd->multiply(currDD, ddsim->simulationState); ddsim->dd->incRef(temp); ddsim->dd->decRef(ddsim->simulationState); ddsim->simulationState = temp; @@ -1254,10 +1260,10 @@ Result ddsimStepBackward(SimulationState* self) { applyComparison(registerValue, exp, op->getComparisonKind()); } if (conditionMet) { - auto* thenOp = op->getThenOp(); + const auto* thenOp = op->getThenOp(); currDD = dd::getInverseDD(*thenOp, *ddsim->dd); } else if (op->getElseOp() != nullptr) { - auto* elseOp = op->getElseOp(); + const auto* elseOp = op->getElseOp(); currDD = dd::getInverseDD(*elseOp, *ddsim->dd); } else { currDD = dd::Package::makeIdent(); @@ -1268,7 +1274,7 @@ Result ddsimStepBackward(SimulationState* self) { *ddsim->dd); // get the inverse of the current operation } - auto temp = ddsim->dd->multiply(currDD, ddsim->simulationState); + const auto temp = ddsim->dd->multiply(currDD, ddsim->simulationState); ddsim->dd->incRef(temp); ddsim->dd->decRef(ddsim->simulationState); ddsim->simulationState = temp; @@ -1278,7 +1284,7 @@ Result ddsimStepBackward(SimulationState* self) { } Result ddsimRunAll(SimulationState* self, size_t* failedAssertions) { - auto* ddsim = toDDSimulationState(self); + const auto* ddsim = toDDSimulationState(self); if (!ddsim->ready) { return ERROR; } @@ -1362,38 +1368,38 @@ Result ddsimPauseSimulation(SimulationState* self) { } bool ddsimCanStepForward(SimulationState* self) { - auto* ddsim = toDDSimulationState(self); + const auto* ddsim = toDDSimulationState(self); return ddsim->ready && ddsim->currentInstruction < ddsim->instructionTypes.size(); } bool ddsimCanStepBackward(SimulationState* self) { - auto* ddsim = toDDSimulationState(self); + const auto* ddsim = toDDSimulationState(self); return ddsim->ready && !ddsim->previousInstructionStack.empty(); } bool ddsimIsFinished(SimulationState* self) { - auto* ddsim = toDDSimulationState(self); + const auto* ddsim = toDDSimulationState(self); return ddsim->currentInstruction == ddsim->instructionTypes.size(); } bool ddsimDidAssertionFail(SimulationState* self) { - auto* ddsim = toDDSimulationState(self); + const auto* ddsim = toDDSimulationState(self); return ddsim->lastFailedAssertion == ddsim->currentInstruction; } bool ddsimWasBreakpointHit(SimulationState* self) { - auto* ddsim = toDDSimulationState(self); + const auto* ddsim = toDDSimulationState(self); return ddsim->lastMetBreakpoint == ddsim->currentInstruction; } size_t ddsimGetCurrentInstruction(SimulationState* self) { - auto* ddsim = toDDSimulationState(self); + const auto* ddsim = toDDSimulationState(self); return ddsim->currentInstruction; } size_t ddsimGetInstructionCount(SimulationState* self) { - auto* ddsim = toDDSimulationState(self); + const auto* ddsim = toDDSimulationState(self); return ddsim->instructionTypes.size(); } @@ -1430,8 +1436,8 @@ size_t ddsimGetNumQubits(SimulationState* self) { Result ddsimGetAmplitudeIndex(SimulationState* self, size_t index, Complex* output) { - auto* ddsim = toDDSimulationState(self); - auto result = ddsim->simulationState.getValueByIndex(index); + const auto* ddsim = toDDSimulationState(self); + const auto result = ddsim->simulationState.getValueByIndex(index); output->real = result.real(); output->imaginary = result.imag(); return OK; @@ -1442,7 +1448,7 @@ Result ddsimGetAmplitudeBitstring(SimulationState* self, const char* bitstring, auto* ddsim = toDDSimulationState(self); auto path = std::string(bitstring); std::ranges::reverse(path); - auto result = + const auto result = ddsim->simulationState.getValueByPath(ddsim->qc->getNqubits(), path); output->real = result.real(); output->imaginary = result.imag(); @@ -1459,12 +1465,12 @@ Result ddsimGetClassicalVariable(SimulationState* self, const char* name, return ERROR; } size_t ddsimGetNumClassicalVariables(SimulationState* self) { - auto* ddsim = toDDSimulationState(self); + const auto* ddsim = toDDSimulationState(self); return ddsim->variables.size(); } Result ddsimGetClassicalVariableName(SimulationState* self, size_t variableIndex, char* output) { - auto* ddsim = toDDSimulationState(self); + const auto* ddsim = toDDSimulationState(self); if (variableIndex >= ddsim->variables.size()) { return ERROR; @@ -1477,7 +1483,7 @@ Result ddsimGetClassicalVariableName(SimulationState* self, Result ddsimGetQuantumVariableName(SimulationState* self, size_t variableIndex, char* output) { - auto* ddsim = toDDSimulationState(self); + const auto* ddsim = toDDSimulationState(self); const auto name = getQuantumBitName(ddsim, variableIndex); @@ -1488,7 +1494,8 @@ Result ddsimGetQuantumVariableName(SimulationState* self, size_t variableIndex, return OK; } -Result ddsimGetStateVectorFull(SimulationState* self, Statevector* output) { +Result ddsimGetStateVectorFull(SimulationState* self, + const Statevector* output) { const Span amplitudes(output->amplitudes, output->numStates); for (size_t i = 0; i < output->numStates; i++) { self->getAmplitudeIndex(self, i, &litudes[i]); @@ -1497,7 +1504,7 @@ Result ddsimGetStateVectorFull(SimulationState* self, Statevector* output) { } Result ddsimGetStateVectorSub(SimulationState* self, size_t subStateSize, - const size_t* qubits, Statevector* output) { + const size_t* qubits, const Statevector* output) { const Span qubitsSpan(qubits, subStateSize); if (subStateSize == self->getNumQubits(self)) { @@ -1516,7 +1523,7 @@ Result ddsimGetStateVectorSub(SimulationState* self, size_t subStateSize, auto* ddsim = toDDSimulationState(self); Statevector fullState; fullState.numQubits = ddsim->qc->getNqubits(); - fullState.numStates = 1 << fullState.numQubits; + fullState.numStates = 1ULL << fullState.numQubits; std::vector amplitudes(fullState.numStates); const Span outAmplitudes(output->amplitudes, output->numStates); @@ -1596,7 +1603,7 @@ Result ddsimClearBreakpoints(SimulationState* self) { } Result ddsimGetStackDepth(SimulationState* self, size_t* depth) { - auto* ddsim = toDDSimulationState(self); + const auto* ddsim = toDDSimulationState(self); if (!ddsim->ready) { return ERROR; } @@ -1706,7 +1713,7 @@ size_t variableToQubit(DDSimulationState* ddsim, const std::string& variable) { } } - for (auto& reg : ddsim->qubitRegisters) { + for (const auto& reg : ddsim->qubitRegisters) { if (reg.name == var) { if (idx >= reg.size) { throw std::runtime_error("Index out of bounds"); @@ -1769,28 +1776,30 @@ bool checkAssertion(DDSimulationState* ddsim, if (assertion->getType() == AssertionType::Entanglement) { std::unique_ptr entanglementAssertion( dynamic_cast(assertion.release())); - auto result = checkAssertionEntangled(ddsim, entanglementAssertion); + const auto result = checkAssertionEntangled(ddsim, entanglementAssertion); assertion = std::move(entanglementAssertion); return result; } if (assertion->getType() == AssertionType::Superposition) { std::unique_ptr superpositionAssertion( dynamic_cast(assertion.release())); - auto result = checkAssertionSuperposition(ddsim, superpositionAssertion); + const auto result = + checkAssertionSuperposition(ddsim, superpositionAssertion); assertion = std::move(superpositionAssertion); return result; } if (assertion->getType() == AssertionType::StatevectorEquality) { std::unique_ptr svEqualityAssertion( dynamic_cast(assertion.release())); - auto result = checkAssertionEqualityStatevector(ddsim, svEqualityAssertion); + const auto result = + checkAssertionEqualityStatevector(ddsim, svEqualityAssertion); assertion = std::move(svEqualityAssertion); return result; } if (assertion->getType() == AssertionType::CircuitEquality) { std::unique_ptr circuitEqualityAssertion( dynamic_cast(assertion.release())); - auto result = + const auto result = checkAssertionEqualityCircuit(ddsim, circuitEqualityAssertion); assertion = std::move(circuitEqualityAssertion); return result; @@ -1881,7 +1890,7 @@ std::string preprocessAssertionCode(const char* code, declaration = replaceString(declaration, "\t", ""); declaration = replaceString(declaration, ";", ""); auto parts = splitString(declaration, '['); - auto name = parts[0]; + const auto& name = parts[0]; const size_t size = std::stoul(parts[1].substr(0, parts[1].size() - 1)); const size_t index = ddsim->qubitRegisters.empty() @@ -1889,7 +1898,10 @@ std::string preprocessAssertionCode(const char* code, : ddsim->qubitRegisters.back().index + ddsim->qubitRegisters.back().size; const QubitRegisterDefinition reg{ - .name = name, .index = index, .size = size}; + .name = name, + .index = index, + .size = size, + }; ddsim->qubitRegisters.push_back(reg); if (!instruction.inFunctionDefinition) { @@ -1902,7 +1914,7 @@ std::string preprocessAssertionCode(const char* code, declaration = replaceString(declaration, "\t", ""); declaration = replaceString(declaration, ";", ""); auto parts = splitString(declaration, '['); - auto& name = parts[0]; + const auto& name = parts[0]; const size_t size = std::stoul(parts[1].substr(0, parts[1].size() - 1)); const size_t index = ddsim->classicalRegisters.empty() @@ -1910,16 +1922,21 @@ std::string preprocessAssertionCode(const char* code, : ddsim->classicalRegisters.back().index + ddsim->classicalRegisters.back().size; const ClassicalRegisterDefinition reg{ - .name = removeWhitespace(name), .index = index, .size = size}; + .name = removeWhitespace(name), + .index = index, + .size = size, + }; ddsim->classicalRegisters.push_back(reg); for (auto i = 0ULL; i < size; i++) { const auto variableName = removeWhitespace(name) + "[" + std::to_string(i) + "]"; ddsim->variableNames.push_back( std::make_unique(variableName)); - const Variable newVariable{ddsim->variableNames.back()->data(), - VariableType::VarBool, - {false}}; + const Variable newVariable{ + .name = ddsim->variableNames.back()->data(), + .type = VariableType::VarBool, + .value = {.boolValue = false}, + }; ddsim->variables.insert({newVariable.name, newVariable}); } @@ -1946,8 +1963,8 @@ std::string preprocessAssertionCode(const char* code, return result; } -std::string getClassicalBitName(DDSimulationState* ddsim, size_t index) { - for (auto& reg : ddsim->classicalRegisters) { +std::string getClassicalBitName(const DDSimulationState* ddsim, size_t index) { + for (const auto& reg : ddsim->classicalRegisters) { if (index >= reg.index && index < reg.index + reg.size) { return reg.name + "[" + std::to_string(index - reg.index) + "]"; } @@ -1955,8 +1972,8 @@ std::string getClassicalBitName(DDSimulationState* ddsim, size_t index) { return "UNKNOWN"; } -std::string getQuantumBitName(DDSimulationState* ddsim, size_t index) { - for (auto& reg : ddsim->qubitRegisters) { +std::string getQuantumBitName(const DDSimulationState* ddsim, size_t index) { + for (const auto& reg : ddsim->qubitRegisters) { if (index >= reg.index && index < reg.index + reg.size) { return reg.name + "[" + std::to_string(index - reg.index) + "]"; } @@ -2008,7 +2025,7 @@ size_t compileStatisticalSlice(DDSimulationState* ddsim, char* buffer, std::string targetName = "test_" + replaceString(replaceString(target, "]", ""), "[", ""); while (assertionTargetsSet.contains(targetName)) { - targetName += "_"; + targetName += '_'; } assertionTargets[foundIndex][target] = targetName; assertionTargetsSet.insert(targetName); diff --git a/src/backend/dd/DDSimDiagnostics.cpp b/src/backend/dd/DDSimDiagnostics.cpp index cbaf4dfb..a9c8397f 100644 --- a/src/backend/dd/DDSimDiagnostics.cpp +++ b/src/backend/dd/DDSimDiagnostics.cpp @@ -203,7 +203,7 @@ getInteractionTreeAtRuntime(DDDiagnostics* ddd, size_t qubit) { continue; } - auto& actualQubits = ddd->actualQubits[i]; + const auto& actualQubits = ddd->actualQubits[i]; for (const auto& actualQubitVector : actualQubits) { if (!std::ranges::none_of(actualQubitVector, [&interactions](size_t elem) { @@ -308,7 +308,7 @@ findUniquePath(const std::set>& graph, toVisit.push_back(start); while (!toVisit.empty()) { - auto current = *toVisit.begin(); + const auto current = *toVisit.begin(); toVisit.erase(toVisit.begin()); visited.insert(current); if (current == end) { @@ -439,7 +439,7 @@ void suggestBasedOnFailedEntanglementAssertion( for (const auto& entry : generalInteractions) { const auto q1 = std::get<0>(entry); const auto q2 = std::get<1>(entry); - auto* ddsim = self->simulationState; + const auto* ddsim = self->simulationState; self->assertionsEntToInsert[instructionIndex].insert( {{getQuantumBitName(ddsim, q1), getQuantumBitName(ddsim, q2)}, std::get<2>(entry) + @@ -503,11 +503,12 @@ void suggestSplitEqualityAssertion( const auto& amplitudeSet = extractedAmplitudes[i]; const auto& targetQubitSet = targetQubits[i]; - auto toInsert = - InsertEqualityAssertion{.instructionIndex = instructionIndex, - .amplitudes = {}, - .similarity = similarity, - .targets = targetQubitSet}; + auto toInsert = InsertEqualityAssertion{ + .instructionIndex = instructionIndex, + .amplitudes = {}, + .similarity = similarity, + .targets = targetQubitSet, + }; // Round amplitudes if necessary. const auto roundingFactor = 1e8; @@ -517,7 +518,8 @@ void suggestSplitEqualityAssertion( return Complex{ .real = std::round(c.real * roundingFactor) / roundingFactor, .imaginary = - std::round(c.imaginary * roundingFactor) / roundingFactor}; + std::round(c.imaginary * roundingFactor) / roundingFactor, + }; }); // If an amplitude was rounded, we adapt the similarity if it is too high // otherwise. @@ -588,7 +590,7 @@ Result dddiagnosticsInit(Diagnostics* self) { Result dddiagnosticsGetDataDependencies(Diagnostics* self, size_t instruction, bool includeCallers, bool* instructions) { - auto* ddd = toDDDiagnostics(self); + const auto* ddd = toDDDiagnostics(self); auto* ddsim = ddd->simulationState; const Span isDependency( instructions, ddsim->interface.getInstructionCount(&ddsim->interface)); @@ -602,12 +604,12 @@ Result dddiagnosticsGetDataDependencies(Diagnostics* self, size_t instruction, : std::set{}; while (!toVisit.empty()) { - auto current = *toVisit.begin(); + const auto current = *toVisit.begin(); isDependency[current] = true; toVisit.erase(toVisit.begin()); visited.insert(current); - for (auto dep : ddsim->dataDependencies[current]) { + for (const auto dep : ddsim->dataDependencies[current]) { const auto depInstruction = dep.first; if (ddsim->instructionTypes[depInstruction] == NOP) { continue; // We don't want variable declarations as dependencies. @@ -621,7 +623,7 @@ Result dddiagnosticsGetDataDependencies(Diagnostics* self, size_t instruction, } if (unknownCallers.contains(current - 1)) { - for (auto caller : ddsim->functionCallers[current - 1]) { + for (const auto caller : ddsim->functionCallers[current - 1]) { if (!visited.contains(caller)) { toVisit.insert(caller); } @@ -634,7 +636,7 @@ Result dddiagnosticsGetDataDependencies(Diagnostics* self, size_t instruction, Result dddiagnosticsGetInteractions(Diagnostics* self, size_t beforeInstruction, size_t qubit, bool* qubitsAreInteracting) { - auto* ddd = toDDDiagnostics(self); + const auto* ddd = toDDDiagnostics(self); auto* ddsim = ddd->simulationState; std::set interactions; interactions.insert(qubit); @@ -652,7 +654,7 @@ Result dddiagnosticsGetInteractions(Diagnostics* self, size_t beforeInstruction, continue; } - auto targets = getTargetVariables(ddsim, i); + const auto targets = getTargetVariables(ddsim, i); std::set targetQubits; for (const auto& target : targets) { targetQubits.insert(variableToQubitAt(ddsim, target, i).first); @@ -672,7 +674,7 @@ Result dddiagnosticsGetInteractions(Diagnostics* self, size_t beforeInstruction, const auto qubits = Span( qubitsAreInteracting, ddsim->interface.getNumQubits(&ddsim->interface)); - for (auto interaction : interactions) { + for (const auto interaction : interactions) { qubits[interaction] = true; } @@ -683,7 +685,7 @@ size_t dddiagnosticsPotentialErrorCauses(Diagnostics* self, ErrorCause* output, size_t count) { auto* ddd = toDDDiagnostics(self); auto* ddsim = ddd->simulationState; - auto outputs = Span(output, count); + const auto outputs = Span(output, count); const size_t assertion = ddsim->lastFailedAssertion; if (assertion == -1ULL) { @@ -711,7 +713,7 @@ size_t tryFindMissingInteraction(DDDiagnostics* diagnostics, } auto targets = assertion->getTargetQubits(); - auto outputs = Span(output, count); + const auto outputs = Span(output, count); std::vector targetQubits(targets.size()); size_t index = 0; @@ -755,7 +757,7 @@ size_t tryFindZeroControls(DDDiagnostics* diagnostics, size_t instruction, diagnostics->interface.getDataDependencies(&diagnostics->interface, instruction, true, toBoolArray(dependencies.data())); - auto outputs = Span(output, count); + const auto outputs = Span(output, count); size_t index = 0; for (size_t i = 0; i < dependencies.size(); i++) { @@ -784,7 +786,7 @@ size_t tryFindZeroControls(DDDiagnostics* diagnostics, size_t instruction, Result dddiagnosticsGetZeroControlInstructions(Diagnostics* self, bool* instructions) { - auto* ddd = toDDDiagnostics(self); + const auto* ddd = toDDDiagnostics(self); const Span instructionSpan(instructions, dddiagnosticsGetInstructionCount(self)); for (size_t i = 0; i < dddiagnosticsGetInstructionCount(self); i++) { @@ -828,7 +830,11 @@ void dddiagnosticsOnStepForward(DDDiagnostics* diagnostics, const auto& controls = op->getControls(); std::vector amplitudes(2ULL << numQubits); - Statevector sv{numQubits, 2ULL << numQubits, amplitudes.data()}; + const Statevector sv{ + .numQubits = numQubits, + .numStates = 2ULL << numQubits, + .amplitudes = amplitudes.data(), + }; ddsim->interface.getStateVectorFull(&ddsim->interface, &sv); for (const auto& control : controls) { @@ -872,7 +878,7 @@ size_t dddiagnosticsSuggestNewAssertions(Diagnostics* self, size_t* suggestedPositions, char** suggestedAssertions, size_t count) { - auto* ddd = toDDDiagnostics(self); + const auto* ddd = toDDDiagnostics(self); if (count == 0) { size_t totalNumber = 0; for (const auto& entry : ddd->assertionsEntToInsert) { diff --git a/src/common/ComplexMathematics.cpp b/src/common/ComplexMathematics.cpp index 45802c0a..9f3ad515 100644 --- a/src/common/ComplexMathematics.cpp +++ b/src/common/ComplexMathematics.cpp @@ -41,7 +41,7 @@ namespace { * @return The computed trace of the square. */ Complex getTraceOfSquare(const std::vector>& matrix) { - Complex runningSum{0, 0}; + Complex runningSum{.real = 0, .imaginary = 0}; for (size_t i = 0; i < matrix.size(); i++) { for (size_t k = 0; k < matrix.size(); k++) { runningSum = complexAddition( @@ -73,13 +73,13 @@ std::pair splitBitString(size_t number, size_t n, for (size_t index = 0; index < n; index++) { if (std::ranges::find(bits, index) != bits.end()) { - first |= (number & 1) << lenFirst; + first |= (number & 1U) << lenFirst; lenFirst++; } else { - second |= (number & 1) << lenSecond; + second |= (number & 1U) << lenSecond; lenSecond++; } - number >>= 1; + number >>= 1U; } return {first, second}; } @@ -96,7 +96,7 @@ getPartialTrace(const std::vector>& matrix, const std::vector& indicesToTraceOut, size_t nQubits) { const auto traceSize = 1ULL << (nQubits - indicesToTraceOut.size()); std::vector> traceMatrix( - traceSize, std::vector(traceSize, {0, 0})); + traceSize, std::vector(traceSize, {.real = 0, .imaginary = 0})); for (size_t i = 0; i < matrix.size(); i++) { for (size_t j = 0; j < matrix.size(); j++) { const auto split1 = splitBitString(i, nQubits, indicesToTraceOut); @@ -173,18 +173,20 @@ std::string doubleToString(const double d) { Complex complexAddition(const Complex& c1, const Complex& c2) { const double real = c1.real + c2.real; const double imaginary = c1.imaginary + c2.imaginary; - return {real, imaginary}; + return {.real = real, .imaginary = imaginary}; } Complex complexMultiplication(const Complex& c1, const Complex& c2) { const double real = (c1.real * c2.real) - (c1.imaginary * c2.imaginary); const double imaginary = (c1.real * c2.imaginary) + (c1.imaginary * c2.real); - return {real, imaginary}; + return {.real = real, .imaginary = imaginary}; } -Complex complexConjugate(const Complex& c) { return {c.real, -c.imaginary}; } +Complex complexConjugate(const Complex& c) { + return {.real = c.real, .imaginary = -c.imaginary}; +} -bool areQubitsEntangled(std::vector>& densityMatrix, +bool areQubitsEntangled(const std::vector>& densityMatrix, size_t qubit1, size_t qubit2) { const auto numQubits = static_cast(std::log2(densityMatrix.size())); if (numQubits == 2) { @@ -204,7 +206,8 @@ bool areQubitsEntangled(std::vector>& densityMatrix, std::vector> toDensityMatrix(const Statevector& sv) { const Span amplitudes(sv.amplitudes, sv.numStates); std::vector> densityMatrix( - sv.numStates, std::vector(sv.numStates, {0, 0})); + sv.numStates, + std::vector(sv.numStates, {.real = 0, .imaginary = 0})); for (size_t i = 0; i < sv.numStates; i++) { for (size_t j = 0; j < sv.numStates; j++) { densityMatrix[i][j] = @@ -230,7 +233,7 @@ getPartialTraceFromStateVector(const Statevector& sv, const auto traceSize = 1ULL << (sv.numQubits - traceOut.size()); const Span amplitudes(sv.amplitudes, sv.numStates); std::vector> traceMatrix( - traceSize, std::vector(traceSize, {0, 0})); + traceSize, std::vector(traceSize, {.real = 0, .imaginary = 0})); for (size_t i = 0; i < sv.numStates; i++) { for (size_t j = 0; j < sv.numStates; j++) { const auto split1 = splitBitString(i, sv.numQubits, traceOut); @@ -260,7 +263,7 @@ toEigenMatrix(const std::vector>& matrix) { return mat; } -double complexMagnitude(Complex& c) { +double complexMagnitude(const Complex& c) { return std::sqrt((c.real * c.real) + (c.imaginary * c.imaginary)); } @@ -302,8 +305,10 @@ getSubStateVectorAmplitudes(const Statevector& sv, std::vector amplitudes(traced.size()); for (size_t i = 0; i < traced.size(); i++) { - amplitudes[i] = {.real = vectors(static_cast(i), index).real(), - .imaginary = vectors(static_cast(i), index).imag()}; + amplitudes[i] = { + .real = vectors(static_cast(i), index).real(), + .imaginary = vectors(static_cast(i), index).imag(), + }; } return amplitudes; } @@ -327,12 +332,12 @@ double dotProduct(const Statevector& sv1, const Statevector& sv2) { const Span amplitudes2(sv2.amplitudes, sv2.numStates); for (size_t i = 0; i < sv1.numStates; i++) { - resultReal += amplitudes1[i].real * amplitudes2[i].real + - amplitudes1[i].imaginary * amplitudes2[i].imaginary; - resultImag += -1 * amplitudes1[i].real * amplitudes2[i].imaginary + - amplitudes1[i].imaginary * amplitudes2[i].real; + resultReal += (amplitudes1[i].real * amplitudes2[i].real) + + (amplitudes1[i].imaginary * amplitudes2[i].imaginary); + resultImag += (-1 * amplitudes1[i].real * amplitudes2[i].imaginary) + + (amplitudes1[i].imaginary * amplitudes2[i].real); } - Complex result{resultReal, resultImag}; + const Complex result{.real = resultReal, .imaginary = resultImag}; return complexMagnitude(result); } diff --git a/src/common/parsing/AssertionParsing.cpp b/src/common/parsing/AssertionParsing.cpp index 2d294de5..45e09429 100644 --- a/src/common/parsing/AssertionParsing.cpp +++ b/src/common/parsing/AssertionParsing.cpp @@ -22,7 +22,6 @@ #include "common/parsing/Utils.hpp" #include -#include #include #include #include @@ -85,7 +84,7 @@ Complex parseComplex(std::string complexString) { double real = 0; double imaginary = 0; bool first = true; - for (auto& part : parts) { + for (const auto& part : parts) { if (part.find('i') != std::string::npos || part.find('j') != std::string::npos) { imaginary += @@ -96,7 +95,7 @@ Complex parseComplex(std::string complexString) { } first = false; } - return {real, imaginary}; + return {.real = real, .imaginary = imaginary}; } /** @@ -106,19 +105,19 @@ Complex parseComplex(std::string complexString) { */ Statevector parseStatevector(std::string statevectorString) { statevectorString = removeWhitespace(statevectorString); - auto parts = splitString(statevectorString, ','); + const auto parts = splitString(statevectorString, ','); auto amplitudes = std::make_unique>(); - for (auto& part : parts) { + for (const auto& part : parts) { amplitudes->push_back(parseComplex(part)); } size_t numQubits = 0; size_t n = amplitudes->size(); while (n > 1) { - if ((n & 1) == 1) { + if ((n & 1U) == 1) { throw ParsingError("Invalid statevector size"); } - n >>= 1; + n >>= 1U; numQubits++; } @@ -250,9 +249,11 @@ bool StatevectorEqualityAssertion::implies( }); newAmplitudes = getSubStateVectorAmplitudes(getTargetStatevector(), indexList); - targetSV = {.numQubits = indexList.size(), - .numStates = newAmplitudes.size(), - .amplitudes = newAmplitudes.data()}; + targetSV = { + .numQubits = indexList.size(), + .numStates = newAmplitudes.size(), + .amplitudes = newAmplitudes.data(), + }; } else { targetSV = getTargetStatevector(); } @@ -312,7 +313,7 @@ bool StatevectorEqualityAssertion::implies( getTargetStatevector().numStates); std::vector> densityMatrix( - sv.size(), std::vector(sv.size(), {0, 0})); + sv.size(), std::vector(sv.size(), {.real = 0, .imaginary = 0})); for (size_t i = 0; i < sv.size(); i++) { for (size_t j = 0; j < sv.size(); j++) { densityMatrix[i][j] = @@ -385,15 +386,15 @@ std::unique_ptr parseAssertion(std::string assertionString, assertionString = trim(replaceString(assertionString, ";", "")); if (assertionString.starts_with("assert-ent")) { - auto targets = extractTargetQubits(assertionString.substr(11)); + const auto targets = extractTargetQubits(assertionString.substr(11)); return std::make_unique(targets); } if (assertionString.starts_with("assert-sup")) { - auto targets = extractTargetQubits(assertionString.substr(11)); + const auto targets = extractTargetQubits(assertionString.substr(11)); return std::make_unique(targets); } if (assertionString.starts_with("assert-eq")) { - auto sub = assertionString.substr(10); + const auto sub = assertionString.substr(10); auto targets = extractTargetQubits(sub); double similarityThreshold = 0; try { @@ -407,11 +408,11 @@ std::unique_ptr parseAssertion(std::string assertionString, } if (blockContent.find(';') == std::string::npos) { - auto statevector = parseStatevector(blockContent); + const auto statevector = parseStatevector(blockContent); return std::make_unique( statevector, similarityThreshold, targets); } - auto circuitCode = trim(blockContent); + const auto circuitCode = trim(blockContent); return std::make_unique( circuitCode, similarityThreshold, targets); } diff --git a/src/common/parsing/AssertionTools.cpp b/src/common/parsing/AssertionTools.cpp index c9b3cb1e..96a94681 100644 --- a/src/common/parsing/AssertionTools.cpp +++ b/src/common/parsing/AssertionTools.cpp @@ -15,7 +15,7 @@ #include "common/parsing/Utils.hpp" #include -#include +#include #include #include #include @@ -61,25 +61,17 @@ static COMMUTATION_RULE_SUP(OTHER_1Q_GATE_INVARIANTS, //------------------------------------------------------------------------------ -const std::vector&)>> - GENERAL_COMMUTATION_RULES = { - BARRIER, +constexpr std::array GENERAL_COMMUTATION_RULES = { + +BARRIER, }; -const std::vector&)>> - ENTANGLEMENT_COMMUTATION_RULES = { - TWO_OR_MORE_TARGETS, +constexpr std::array ENTANGLEMENT_COMMUTATION_RULES = { + +TWO_OR_MORE_TARGETS, }; -const std::vector&)>> - SUPERPOSITION_COMMUTATION_RULES = { - PAULI_INVARIANT, - OTHER_1Q_GATE_INVARIANTS, +constexpr std::array SUPERPOSITION_COMMUTATION_RULES = { + +PAULI_INVARIANT, + +OTHER_1Q_GATE_INVARIANTS, }; /** diff --git a/src/common/parsing/CodePreprocessing.cpp b/src/common/parsing/CodePreprocessing.cpp index 86e27864..647c9aee 100644 --- a/src/common/parsing/CodePreprocessing.cpp +++ b/src/common/parsing/CodePreprocessing.cpp @@ -163,7 +163,7 @@ LineColumn lineColumnForTarget(const std::string& code, size_t instructionStart, const size_t lineStart = (lineStartPos == std::string::npos) ? 0 : static_cast(lineStartPos + 1); - auto lineEndPos = code.find('\n', instructionStart); + const auto lineEndPos = code.find('\n', instructionStart); const size_t lineEnd = (lineEndPos == std::string::npos) ? code.size() : static_cast(lineEndPos); @@ -202,7 +202,7 @@ std::string invalidTargetDetail(const std::string& target, std::string detail = "Invalid target qubit "; detail += target; detail += context; - detail += "."; + detail += '.'; return detail; } @@ -214,7 +214,7 @@ std::string invalidTargetDetail(const std::string& target, std::string invalidRegisterDetail(const std::string& trimmedLine) { std::string detail = "Invalid register declaration "; detail += trimmedLine; - detail += "."; + detail += '.'; return detail; } @@ -236,7 +236,7 @@ void validateTargets(const std::string& code, size_t instructionStart, if (target.empty()) { std::string detail = "Empty target"; detail += context; - detail += "."; + detail += '.'; throw makeParseError(code, instructionStart, detail); } const auto ref = parseRegisterRef(target); @@ -273,7 +273,7 @@ std::string sweepBlocks(const std::string& code, int level = 0; size_t pos = 0; while (pos < result.size()) { - auto c = result[pos]; + const auto c = result[pos]; if (c == '{') { if (level == 0) { start = pos; @@ -304,7 +304,7 @@ std::string sweepBlocks(const std::string& code, std::string removeComments(const std::string& code) { std::string result = code; for (size_t pos = 0; pos < result.size(); pos++) { - auto nextComment = result.find("//", pos); + const auto nextComment = result.find("//", pos); if (nextComment == std::string::npos) { break; } @@ -324,11 +324,11 @@ std::string removeComments(const std::string& code) { * @return The parsed function definition. */ FunctionDefinition parseFunctionDefinition(const std::string& signature) { - auto parts = splitString( + const auto parts = splitString( replaceString(replaceString(signature, "\n", " "), "\t", " "), ' '); std::string name; size_t index = 0; - for (auto& part : parts) { + for (const auto& part : parts) { index++; if (part != "gate" && !part.empty()) { name = part; @@ -340,7 +340,7 @@ FunctionDefinition parseFunctionDefinition(const std::string& signature) { for (size_t i = index; i < parts.size(); i++) { parameterParts += parts[i]; } - auto parameters = splitString(removeWhitespace(parameterParts), ','); + const auto parameters = splitString(removeWhitespace(parameterParts), ','); return {.name = name, .parameters = parameters}; } @@ -464,14 +464,16 @@ parseClassicConditionExpression(const std::string& condition) { qc::ComparisonKind kind; }; using OperatorsT = std::array; - static constexpr OperatorsT OPERATORS{{ - {.text = "<=", .kind = qc::Leq}, - {.text = ">=", .kind = qc::Geq}, - {.text = "==", .kind = qc::Eq}, - {.text = "!=", .kind = qc::Neq}, - {.text = "<", .kind = qc::Lt}, - {.text = ">", .kind = qc::Gt}, - }}; + static constexpr OperatorsT OPERATORS{ + { + {.text = "<=", .kind = qc::Leq}, + {.text = ">=", .kind = qc::Geq}, + {.text = "==", .kind = qc::Eq}, + {.text = "!=", .kind = qc::Neq}, + {.text = "<", .kind = qc::Lt}, + {.text = ">", .kind = qc::Gt}, + }, + }; auto normalized = removeWhitespace(condition); if (!normalized.empty() && normalized.front() == '(') { @@ -508,10 +510,12 @@ parseClassicConditionExpression(const std::string& condition) { } if (const auto ref = parseRegisterRef(operand); ref.has_value()) { - return ClassicCondition{.registerName = ref->name, - .bitIndex = ref->index, - .expectedValue = expected, - .kind = kind}; + return ClassicCondition{ + .registerName = ref->name, + .bitIndex = ref->index, + .expectedValue = expected, + .kind = kind, + }; } return std::nullopt; } @@ -625,10 +629,10 @@ preprocessCode(const std::string& code, size_t startIndex, } std::string line = blocksRemoved.substr(pos, end - pos + 1); - auto trimmedLine = trim(line); + const auto trimmedLine = trim(line); auto tokens = splitString(trimmedLine, ' '); - auto isAssert = isAssertion(line); - auto blockPos = line.find("$__block"); + const auto isAssert = isAssertion(line); + const auto blockPos = line.find("$__block"); const auto leadingPos = blocksRemoved.find_first_not_of(" \t\r\n", pos); const size_t trueStart = @@ -703,7 +707,7 @@ preprocessCode(const std::string& code, size_t startIndex, instructions.emplace_back(i - subInstructions.size() - 1, line, a, targets, trueStart, trueEnd, i + 1, false, "", false, true, block); - for (auto& instr : subInstructions) { + for (const auto& instr : subInstructions) { instructions.back().childInstructions.push_back(instr.lineNumber); } instructions.insert(instructions.end(), diff --git a/src/common/parsing/Utils.cpp b/src/common/parsing/Utils.cpp index 1f412118..c5e8b189 100644 --- a/src/common/parsing/Utils.cpp +++ b/src/common/parsing/Utils.cpp @@ -25,9 +25,10 @@ namespace mqt::debugger { std::string trim(const std::string& str) { - auto start = std::ranges::find_if_not(str, ::isspace); - auto end = std::ranges::find_if_not(std::ranges::reverse_view(str), ::isspace) - .base(); + const auto start = std::ranges::find_if_not(str, ::isspace); + const auto end = + std::ranges::find_if_not(std::ranges::reverse_view(str), ::isspace) + .base(); return (start < end) ? std::string(start, end) : std::string(); } diff --git a/src/frontend/cli/CliFrontEnd.cpp b/src/frontend/cli/CliFrontEnd.cpp index 52d14755..9b709c37 100644 --- a/src/frontend/cli/CliFrontEnd.cpp +++ b/src/frontend/cli/CliFrontEnd.cpp @@ -63,7 +63,7 @@ std::vector getBitStrings(size_t numQubits) { for (size_t i = 0; i < (1ULL << numQubits); i++) { std::string bitString; for (size_t j = 0; j < numQubits; j++) { - bitString.insert(bitString.begin(), (i & (1 << j)) > 0 ? '1' : '0'); + bitString.insert(bitString.begin(), (i & (1ULL << j)) > 0 ? '1' : '0'); } bitStrings.push_back(bitString); } diff --git a/test/test_assertion_creation.cpp b/test/test_assertion_creation.cpp index a7a12271..c342dc19 100644 --- a/test/test_assertion_creation.cpp +++ b/test/test_assertion_creation.cpp @@ -28,6 +28,7 @@ #include namespace mqt::debugger::test { +namespace { /** * @brief Fixture for testing the correctness of assertion creation on custom @@ -92,7 +93,8 @@ TEST_F(AssertionCreationTest, CreateEntanglementAssertionFromBigAssertion) { const std::set> expected = { {3, "assert-ent q[1], q[2];\n"}, {3, "assert-ent q[0], q[2];\n"}, - {3, "assert-ent q[0], q[1];\n"}}; + {3, "assert-ent q[0], q[1];\n"}, + }; checkNewAssertions(expected, 1); } @@ -112,7 +114,9 @@ TEST_F(AssertionCreationTest, CreateEntanglementAssertionFromTreeSimple) { )"); const std::set> expected = { - {2, "assert-ent q[0], q[1];\n"}, {3, "assert-ent q[1], q[2];\n"}}; + {2, "assert-ent q[0], q[1];\n"}, + {3, "assert-ent q[1], q[2];\n"}, + }; checkNewAssertions(expected, 1); } @@ -130,7 +134,9 @@ TEST_F(AssertionCreationTest, SplitEqualityAssertion) { )"); const std::set> expected = { - {1, "assert-eq q[0] { 1, 0 }\n"}, {1, "assert-eq q[1] { 1, 0 }\n"}}; + {1, "assert-eq q[0] { 1, 0 }\n"}, + {1, "assert-eq q[1] { 1, 0 }\n"}, + }; checkNewAssertions(expected, 1); } @@ -148,7 +154,8 @@ TEST_F(AssertionCreationTest, SplitEqualityAssertionMultipleAmplitudes) { const std::set> expected = { {0, "assert-eq 0.99999, q[0] { 0.707107, 0.707107 }\n"}, - {0, "assert-eq 0.99999, q[1] { 0.707107, 0.707107 }\n"}}; + {0, "assert-eq 0.99999, q[1] { 0.707107, 0.707107 }\n"}, + }; checkNewAssertions(expected, 1); } @@ -176,8 +183,10 @@ TEST_F(AssertionCreationTest, SplitEqualityAssertionRounded) { const std::set> expected = { {0, "assert-eq 0.99999, q[0] { 0, 1 }\n"}, {0, "assert-eq 0.99999, q[1] { 0, 1 }\n"}, - {0, "assert-eq 0.99999, q[2] { 0.707107, -0.707107 }\n"}}; + {0, "assert-eq 0.99999, q[2] { 0.707107, -0.707107 }\n"}, + }; checkNewAssertions(expected, 1); } +} // namespace } // namespace mqt::debugger::test diff --git a/test/test_assertion_movement.cpp b/test/test_assertion_movement.cpp index 76e56f66..b08a456d 100644 --- a/test/test_assertion_movement.cpp +++ b/test/test_assertion_movement.cpp @@ -23,6 +23,7 @@ #include namespace mqt::debugger::test { +namespace { /** * @brief Fixture for testing the correctness of assertion movement on custom @@ -338,4 +339,5 @@ TEST_F(AssertionMovementTest, DontMoveOutsideOfCustomGate) { checkMovements(expected); } +} // namespace } // namespace mqt::debugger::test diff --git a/test/test_compilation_projective_measurements.cpp b/test/test_compilation_projective_measurements.cpp index b091eadc..c604eeb2 100644 --- a/test/test_compilation_projective_measurements.cpp +++ b/test/test_compilation_projective_measurements.cpp @@ -23,6 +23,7 @@ #include namespace mqt::debugger::test { +namespace { using SV = std::vector; @@ -242,4 +243,5 @@ TEST_F(ProjectiveMeasurementsCompilationTest, checkNoCompilation(makeSettings(2, 1)); } +} // namespace } // namespace mqt::debugger::test diff --git a/test/test_compilation_statistical_slices.cpp b/test/test_compilation_statistical_slices.cpp index 9a07f99d..61abf191 100644 --- a/test/test_compilation_statistical_slices.cpp +++ b/test/test_compilation_statistical_slices.cpp @@ -23,6 +23,7 @@ #include namespace mqt::debugger::test { +namespace { using SV = std::vector; using DV = std::vector; @@ -831,4 +832,5 @@ TEST_F(StatisticalSlicesCompilationTest, checkNoCompilation(makeSettings(2, 2)); } +} // namespace } // namespace mqt::debugger::test diff --git a/test/test_custom_code.cpp b/test/test_custom_code.cpp index 377e2fec..4c2993e7 100644 --- a/test/test_custom_code.cpp +++ b/test/test_custom_code.cpp @@ -28,6 +28,7 @@ #include namespace mqt::debugger::test { +namespace { /** * @brief Fixture for testing the correctness of the debugger on custom code. @@ -51,7 +52,11 @@ TEST_F(CustomCodeTest, IfElseOperationFalse) { ASSERT_EQ(state->runSimulation(state), OK); std::array amplitudes{}; - Statevector sv{2, 4, amplitudes.data()}; + const Statevector sv{ + .numQubits = 2, + .numStates = 4, + .amplitudes = amplitudes.data(), + }; state->getStateVectorFull(state, &sv); ASSERT_TRUE(complexEquality(amplitudes[0], 1, 0.0)); @@ -72,7 +77,11 @@ TEST_F(CustomCodeTest, IfElseOperationTrue) { ASSERT_EQ(state->runSimulation(state), OK); std::array amplitudes{}; - Statevector sv{2, 4, amplitudes.data()}; + const Statevector sv{ + .numQubits = 2, + .numStates = 4, + .amplitudes = amplitudes.data(), + }; state->getStateVectorFull(state, &sv); ASSERT_TRUE(complexEquality(amplitudes[1], 1, 0.0)); @@ -90,7 +99,11 @@ TEST_F(CustomCodeTest, IfElseOperationMulti) { ASSERT_EQ(state->runSimulation(state), OK); std::array amplitudes{}; - Statevector sv{2, 4, amplitudes.data()}; + const Statevector sv{ + .numQubits = 2, + .numStates = 4, + .amplitudes = amplitudes.data(), + }; state->getStateVectorFull(state, &sv); ASSERT_TRUE(complexEquality(amplitudes[2], 1, 0.0)); } @@ -112,7 +125,11 @@ TEST_F(CustomCodeTest, IfElseOperationMultiMultilineBlock) { ASSERT_EQ(state->runSimulation(state), OK); std::array amplitudes{}; - Statevector sv{2, 4, amplitudes.data()}; + const Statevector sv{ + .numQubits = 2, + .numStates = 4, + .amplitudes = amplitudes.data(), + }; state->getStateVectorFull(state, &sv); ASSERT_TRUE(complexEquality(amplitudes[2], 1, 0.0)); } @@ -131,7 +148,11 @@ TEST_F(CustomCodeTest, IfElseOperationNeq) { ASSERT_EQ(state->runSimulation(state), OK); std::array amplitudes{}; - Statevector sv{2, 4, amplitudes.data()}; + const Statevector sv{ + .numQubits = 2, + .numStates = 4, + .amplitudes = amplitudes.data(), + }; state->getStateVectorFull(state, &sv); ASSERT_TRUE(complexEquality(amplitudes[1], 1, 0.0)); } @@ -150,7 +171,11 @@ TEST_F(CustomCodeTest, IfElseOperationLt) { ASSERT_EQ(state->runSimulation(state), OK); std::array amplitudes{}; - Statevector sv{2, 4, amplitudes.data()}; + const Statevector sv{ + .numQubits = 2, + .numStates = 4, + .amplitudes = amplitudes.data(), + }; state->getStateVectorFull(state, &sv); ASSERT_TRUE(complexEquality(amplitudes[1], 1, 0.0)); } @@ -169,7 +194,11 @@ TEST_F(CustomCodeTest, IfElseOperationLeq) { ASSERT_EQ(state->runSimulation(state), OK); std::array amplitudes{}; - Statevector sv{2, 4, amplitudes.data()}; + const Statevector sv{ + .numQubits = 2, + .numStates = 4, + .amplitudes = amplitudes.data(), + }; state->getStateVectorFull(state, &sv); ASSERT_TRUE(complexEquality(amplitudes[1], 1, 0.0)); } @@ -188,7 +217,11 @@ TEST_F(CustomCodeTest, IfElseOperationGt) { ASSERT_EQ(state->runSimulation(state), OK); std::array amplitudes{}; - Statevector sv{2, 4, amplitudes.data()}; + const Statevector sv{ + .numQubits = 2, + .numStates = 4, + .amplitudes = amplitudes.data(), + }; state->getStateVectorFull(state, &sv); ASSERT_TRUE(complexEquality(amplitudes[1], 1, 0.0)); } @@ -207,7 +240,11 @@ TEST_F(CustomCodeTest, IfElseOperationGeq) { ASSERT_EQ(state->runSimulation(state), OK); std::array amplitudes{}; - Statevector sv{2, 4, amplitudes.data()}; + const Statevector sv{ + .numQubits = 2, + .numStates = 4, + .amplitudes = amplitudes.data(), + }; state->getStateVectorFull(state, &sv); ASSERT_TRUE(complexEquality(amplitudes[1], 1, 0.0)); } @@ -228,7 +265,11 @@ TEST_F(CustomCodeTest, IfElseOperationSingleBit) { ASSERT_EQ(state->runSimulation(state), OK); std::array amplitudes{}; - Statevector sv{2, 4, amplitudes.data()}; + const Statevector sv{ + .numQubits = 2, + .numStates = 4, + .amplitudes = amplitudes.data(), + }; state->getStateVectorFull(state, &sv); ASSERT_TRUE(complexEquality(amplitudes[1], 1, 0.0)); } @@ -248,7 +289,11 @@ TEST_F(CustomCodeTest, IfElseOperationBackwardStep) { ASSERT_EQ(state->runSimulation(state), OK); std::array amplitudes{}; - Statevector sv{2, 4, amplitudes.data()}; + const Statevector sv{ + .numQubits = 2, + .numStates = 4, + .amplitudes = amplitudes.data(), + }; state->getStateVectorFull(state, &sv); // q[1] = 0, q[0] = 1 after the `if` fires, so amplitude index 1. ASSERT_TRUE(complexEquality(amplitudes[1], 1, 0.0)); @@ -273,7 +318,11 @@ TEST_F(CustomCodeTest, IfElseOperationBareRegisterTrue) { ASSERT_EQ(state->runSimulation(state), OK); std::array amplitudes{}; - Statevector sv{2, 4, amplitudes.data()}; + const Statevector sv{ + .numQubits = 2, + .numStates = 4, + .amplitudes = amplitudes.data(), + }; state->getStateVectorFull(state, &sv); // q[0] = 1, q[1] = 0 after the `if` flips q[1] from 1 to 0. ASSERT_TRUE(complexEquality(amplitudes[1], 1, 0.0)); @@ -290,7 +339,11 @@ TEST_F(CustomCodeTest, IfElseOperationBareRegisterFalse) { ASSERT_EQ(state->runSimulation(state), OK); std::array amplitudes{}; - Statevector sv{2, 4, amplitudes.data()}; + const Statevector sv{ + .numQubits = 2, + .numStates = 4, + .amplitudes = amplitudes.data(), + }; state->getStateVectorFull(state, &sv); // Both qubits stay at |0>; the `if` is skipped. ASSERT_TRUE(complexEquality(amplitudes[0], 1, 0.0)); @@ -309,7 +362,11 @@ TEST_F(CustomCodeTest, IfElseOperationBareBit) { ASSERT_EQ(state->runSimulation(state), OK); std::array amplitudes{}; - Statevector sv{2, 4, amplitudes.data()}; + const Statevector sv{ + .numQubits = 2, + .numStates = 4, + .amplitudes = amplitudes.data(), + }; state->getStateVectorFull(state, &sv); ASSERT_TRUE(complexEquality(amplitudes[1], 1, 0.0)); } @@ -327,7 +384,11 @@ TEST_F(CustomCodeTest, IfElseOperationBareRegisterBackwardStep) { ASSERT_EQ(state->runSimulation(state), OK); std::array amplitudes{}; - Statevector sv{2, 4, amplitudes.data()}; + const Statevector sv{ + .numQubits = 2, + .numStates = 4, + .amplitudes = amplitudes.data(), + }; state->getStateVectorFull(state, &sv); ASSERT_TRUE(complexEquality(amplitudes[1], 1, 0.0)); @@ -819,4 +880,5 @@ TEST_F(CustomCodeTest, PaperExampleGrover) { ASSERT_EQ(state->isFinished(state), true); } +} // namespace } // namespace mqt::debugger::test diff --git a/test/test_data_retrieval.cpp b/test/test_data_retrieval.cpp index 15771446..ed7dc001 100644 --- a/test/test_data_retrieval.cpp +++ b/test/test_data_retrieval.cpp @@ -28,6 +28,7 @@ #include namespace mqt::debugger::test { +namespace { /** * @brief Fixture for testing the correctness of the debugger for data retrieval @@ -37,6 +38,7 @@ namespace mqt::debugger::test { * `circuits/classical-storage`. */ class DataRetrievalTest : public LoadFromFileFixture { +protected: void SetUp() override { LoadFromFileFixture::SetUp(); loadFromFile("classical-storage"); @@ -173,7 +175,11 @@ TEST_F(DataRetrievalTest, GetClassicalVariable) { */ TEST_F(DataRetrievalTest, GetStateVectorFull) { std::array amplitudes{}; - Statevector sv{4, 16, amplitudes.data()}; + const Statevector sv{ + .numQubits = 4, + .numStates = 16, + .amplitudes = amplitudes.data(), + }; ASSERT_EQ(state->getStateVectorFull(state, &sv), OK); ASSERT_TRUE(complexEquality(amplitudes[0], 1.0, 0.0)); @@ -191,7 +197,11 @@ TEST_F(DataRetrievalTest, GetStateVectorFull) { */ TEST_F(DataRetrievalTest, GetStateVectorSub) { std::array amplitudes{}; - Statevector sv{2, 4, amplitudes.data()}; + const Statevector sv{ + .numQubits = 2, + .numStates = 4, + .amplitudes = amplitudes.data(), + }; forwardTo(6); std::array qubits = {0, 1}; @@ -286,7 +296,7 @@ TEST_F(DataRetrievalTest, ChangeClassicalVariableNullValue) { */ TEST_F(DataRetrievalTest, ChangeAmplitudeValueRescalesOtherStates) { forwardTo(12); - const Complex desired{0.5, 0.0}; + const Complex desired{.real = 0.5, .imaginary = 0.0}; ASSERT_EQ(state->changeAmplitudeValue(state, "0010", &desired), OK); Complex updated{}; @@ -301,7 +311,7 @@ TEST_F(DataRetrievalTest, ChangeAmplitudeValueRescalesOtherStates) { * @test Test that invalid bitstrings for amplitude updates are rejected. */ TEST_F(DataRetrievalTest, ChangeAmplitudeValueRejectsInvalidBitstring) { - const Complex desired{0.25, 0.0}; + const Complex desired{.real = 0.25, .imaginary = 0.0}; forwardTo(12); ASSERT_EQ(state->changeAmplitudeValue(state, "10", &desired), ERROR); ASSERT_EQ(state->changeAmplitudeValue(state, "10a1", &desired), ERROR); @@ -311,7 +321,11 @@ TEST_F(DataRetrievalTest, ChangeAmplitudeValueRejectsInvalidBitstring) { * @test Test that amplitudes with magnitude larger than one are rejected. */ TEST_F(DataRetrievalTest, ChangeAmplitudeValueRejectsMagnitudeAboveOne) { - const Complex desired{0.9, 0.6}; // norm^2 > 1, should fail. + // norm^2 > 1, should fail + const Complex desired{ + .real = 0.9, + .imaginary = 0.6, + }; forwardTo(12); ASSERT_EQ(state->changeAmplitudeValue(state, "0010", &desired), ERROR); } @@ -320,7 +334,7 @@ TEST_F(DataRetrievalTest, ChangeAmplitudeValueRejectsMagnitudeAboveOne) { * @test Test that over-normalized targets are rejected. */ TEST_F(DataRetrievalTest, ChangeAmplitudeValueRejectsOverNormalizedTarget) { - const Complex desired{1.1, 0.0}; + const Complex desired{.real = 1.1, .imaginary = 0.0}; forwardTo(12); ASSERT_EQ(state->changeAmplitudeValue(state, "0010", &desired), ERROR); } @@ -330,9 +344,10 @@ TEST_F(DataRetrievalTest, ChangeAmplitudeValueRejectsOverNormalizedTarget) { * refused. */ TEST_F(DataRetrievalTest, ChangeAmplitudeValueRejectsSubNormalizedVacuum) { - const Complex desired{0.5, 0.0}; + const Complex desired{.real = 0.5, .imaginary = 0.0}; ASSERT_EQ(state->changeAmplitudeValue(state, "0000", &desired), ERROR); ASSERT_EQ(state->changeAmplitudeValue(state, "0000", nullptr), ERROR); } +} // namespace } // namespace mqt::debugger::test diff --git a/test/test_diagnostics.cpp b/test/test_diagnostics.cpp index 4c1f5ecd..b9bf0f70 100644 --- a/test/test_diagnostics.cpp +++ b/test/test_diagnostics.cpp @@ -29,6 +29,7 @@ #include namespace mqt::debugger::test { +namespace { /** * @brief Fixture for testing the correctness of the diagnostics module. @@ -53,7 +54,8 @@ TEST_F(DiagnosticsTest, DataDependencies) { {7, {1, 2, 4, 7}}, {8, {1, 2, 4, 7, 8}}, {9, {1, 2, 4, 9}}, - {10, {1, 2, 3, 4, 7, 8, 10}}}; + {10, {1, 2, 3, 4, 7, 8, 10}}, + }; for (const auto& [instruction, expectedDependencies] : expected) { std::vector dependencies(state->getInstructionCount(state), 0); @@ -149,21 +151,54 @@ TEST_F(DiagnosticsTest, MaximumMultipleCauses) { const std::vector maxErrors = {20, 8, 7, 4}; const std::vector>> expectedTypes = { - {9, - {MissingInteraction, MissingInteraction, MissingInteraction, - MissingInteraction, MissingInteraction, MissingInteraction, - MissingInteraction, ControlAlwaysZero, ControlAlwaysZero}}, - {8, - {MissingInteraction, MissingInteraction, MissingInteraction, - MissingInteraction, MissingInteraction, MissingInteraction, - MissingInteraction, ControlAlwaysZero}}, - {7, - {MissingInteraction, MissingInteraction, MissingInteraction, - MissingInteraction, MissingInteraction, MissingInteraction, - MissingInteraction}}, - {4, - {MissingInteraction, MissingInteraction, MissingInteraction, - MissingInteraction}}, + { + 9, + { + MissingInteraction, + MissingInteraction, + MissingInteraction, + MissingInteraction, + MissingInteraction, + MissingInteraction, + MissingInteraction, + ControlAlwaysZero, + ControlAlwaysZero, + }, + }, + { + 8, + { + MissingInteraction, + MissingInteraction, + MissingInteraction, + MissingInteraction, + MissingInteraction, + MissingInteraction, + MissingInteraction, + ControlAlwaysZero, + }, + }, + { + 7, + { + MissingInteraction, + MissingInteraction, + MissingInteraction, + MissingInteraction, + MissingInteraction, + MissingInteraction, + MissingInteraction, + }, + }, + { + 4, + { + MissingInteraction, + MissingInteraction, + MissingInteraction, + MissingInteraction, + }, + }, }; for (size_t i = 0; i < maxErrors.size(); i++) { const auto [expectedCount, types] = expectedTypes[i]; @@ -246,7 +281,8 @@ TEST_F(DiagnosticsTest, DataDependenciesWithJumps) { {17, {17, 16}}, - {18, {18, 13, 10, 7, 6, 5, 2, 1, 17, 16}}}; + {18, {18, 13, 10, 7, 6, 5, 2, 1, 17, 16}}, + }; for (const auto& pair : expected) { std::vector dependencies(state->getInstructionCount(state), 0); @@ -282,7 +318,8 @@ TEST_F(DiagnosticsTest, InteractionsWithJumps) { {{10, 0}, {0}}, {{17, 0}, {0}}, {{18, 0}, {1, 2, 0}}, {{18, 1}, {0, 2, 1}}, - {{18, 2}, {0, 1, 2}}, {{18, 3}, {3}}}; + {{18, 2}, {0, 1, 2}}, {{18, 3}, {3}}, + }; for (const auto& pair : expected) { std::vector interactions(state->getNumQubits(state), 0); @@ -324,4 +361,5 @@ TEST_F(DiagnosticsTest, RuntimeInteractions) { ASSERT_EQ(errors[0].instruction, 6); } +} // namespace } // namespace mqt::debugger::test diff --git a/test/test_parsing.cpp b/test/test_parsing.cpp index 27d9a58d..9280a455 100644 --- a/test/test_parsing.cpp +++ b/test/test_parsing.cpp @@ -24,13 +24,12 @@ #include namespace mqt::debugger::test { +namespace { /** * @brief Fixture for testing the correctness of parsing functions. */ -class ParsingTest : public testing::Test { - void SetUp() override {} -}; +class ParsingTest : public testing::Test {}; /** * @test Test the parsing of equality assertions. @@ -180,4 +179,5 @@ TEST_F(ParsingTest, BadFunctionCall) { ASSERT_THROW(preprocessCode(input2, output), ParsingError); } +} // namespace } // namespace mqt::debugger::test diff --git a/test/test_simulation.cpp b/test/test_simulation.cpp index 29130cfd..3bfc6e29 100644 --- a/test/test_simulation.cpp +++ b/test/test_simulation.cpp @@ -26,6 +26,7 @@ #include namespace mqt::debugger::test { +namespace { /** * @brief Fixture for testing the correctness of the simulation methods. @@ -34,13 +35,13 @@ namespace mqt::debugger::test { * defines the specific file to run the tests on. */ class SimulationTest : public testing::TestWithParam { +protected: void SetUp() override { createDDSimulationState(&ddState); state = &ddState.interface; loadFromFile(GetParam()); } -protected: /** * @brief The DDSimulationState to use for testing. */ @@ -143,9 +144,15 @@ class SimulationTest : public testing::TestWithParam { */ TEST_P(SimulationTest, StepThroughCode) { const std::map> expected = { - {"complex-jumps", {0, 1, 4, 9, 12, 5, 6, 10, 2, 3, 11, 7, 10, 2, - 3, 11, 8, 13, 10, 2, 3, 11, 14, 10, 2, 3, 11}}, - {"failing-assertions", {0, 1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10}}}; + { + "complex-jumps", + { + 0, 1, 4, 9, 12, 5, 6, 10, 2, 3, 11, 7, 10, 2, + 3, 11, 8, 13, 10, 2, 3, 11, 14, 10, 2, 3, 11, + }, + }, + {"failing-assertions", {0, 1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10}}, + }; for (const auto exp : expected.at(GetParam())) { ASSERT_EQ(state->getCurrentInstruction(state), exp); state->stepForward(state); @@ -162,41 +169,68 @@ TEST_P(SimulationTest, StepThroughCode) { */ TEST_P(SimulationTest, StackTraceRetrieval) { const std::map> expectedDepths = { - {"complex-jumps", {1, 1, 1, 1, 1, 2, 2, 3, 4, 4, 3, 2, 3, 4, - 4, 3, 2, 1, 2, 3, 3, 2, 1, 2, 3, 3, 2}}, - {"failing-assertions", {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}}; + { + "complex-jumps", + { + 1, 1, 1, 1, 1, 2, 2, 3, 4, 4, 3, 2, 3, 4, + 4, 3, 2, 1, 2, 3, 3, 2, 1, 2, 3, 3, 2, + }, + }, + {"failing-assertions", {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}, + }; const std::map>> expectedStacks = { - {"complex-jumps", - {{0}, - {1}, - {4}, - {9}, - {12}, - {5, 12}, - {6, 12}, - {10, 6, 12}, - {2, 10, 6, 12}, - {3, 10, 6, 12}, - {11, 6, 12}, - {7, 12}, - {10, 7, 12}, - {2, 10, 7, 12}, - {3, 10, 7, 12}, - {11, 7, 12}, - {8, 12}, - {13}, - {10, 13}, - {2, 10, 13}, - {3, 10, 13}, - {11, 13}, - {14}, - {10, 14}, - {2, 10, 14}, - {3, 10, 14}, - {11, 14}}}, - {"failing-assertions", - {{0}, {1}, {2}, {3}, {4}, {5}, {6}, {6}, {7}, {8}, {9}, {9}, {10}}}}; + { + "complex-jumps", + { + {0}, + {1}, + {4}, + {9}, + {12}, + {5, 12}, + {6, 12}, + {10, 6, 12}, + {2, 10, 6, 12}, + {3, 10, 6, 12}, + {11, 6, 12}, + {7, 12}, + {10, 7, 12}, + {2, 10, 7, 12}, + {3, 10, 7, 12}, + {11, 7, 12}, + {8, 12}, + {13}, + {10, 13}, + {2, 10, 13}, + {3, 10, 13}, + {11, 13}, + {14}, + {10, 14}, + {2, 10, 14}, + {3, 10, 14}, + {11, 14}, + }, + }, + { + "failing-assertions", + { + {0}, + {1}, + {2}, + {3}, + {4}, + {5}, + {6}, + {6}, + {7}, + {8}, + {9}, + {9}, + {10}, + }, + }, + }; for (size_t index = 0; index < expectedDepths.at(GetParam()).size(); index++) { @@ -238,10 +272,13 @@ TEST_P(SimulationTest, StackTraceRetrieval) { TEST_P(SimulationTest, TopLevelBreakpoints) { const std::map> breakpointPositions = { {"complex-jumps", {174, 451, 488, 525}}, - {"failing-assertions", {58, 322, 374, 427, 487}}}; + {"failing-assertions", {58, 322, 374, 427, 487}}, + }; const std::map> - expectedBreakpointPositions = {{"complex-jumps", {4, 12, 13, 14}}, - {"failing-assertions", {1, 5, 6, 7, 8}}}; + expectedBreakpointPositions = { + {"complex-jumps", {4, 12, 13, 14}}, + {"failing-assertions", {1, 5, 6, 7, 8}}, + }; for (size_t index = 0; index < breakpointPositions.at(GetParam()).size(); index++) { @@ -416,26 +453,33 @@ TEST_P(SimulationTest, StepOver) { const std::map>> expected = { - {"complex-jumps", - { - {"of", 1}, {"of", 4}, {"sf", 9}, {"sf", 12}, {"of", 13}, - {"ob", 12}, {"sf", 5}, {"of", 6}, {"of", 7}, {"ob", 6}, - {"sf", 10}, {"of", 11}, {"ob", 10}, {"sf", 2}, {"of", 3}, - {"of", 11}, {"of", 7}, {"sb", 11}, {"of", 7}, {"of", 8}, - {"of", 13}, {"sb", 8}, {"of", 13}, {"of", 14}, - }}, - {"failing-assertions", - {{"of", 1}, {"of", 2}, {"of", 3}, - {"of", 4}, {"of", 5}, {"of", 6}, - {"of", 6}, {"assertion", 6}, {"of", 7}, - {"ob", 6}, {"assertion", 6}, {"of", 7}, - {"ob", 6}, {"assertion", 6}, {"ob", 5}, - {"of", 6}, {"of", 6}, {"assertion", 6}, - {"of", 7}, {"of", 8}, {"sf", 9}, - {"sb", 8}, {"sf", 9}, {"sf", 9}, - {"assertion", 9}, {"sb", 8}, {"sf", 9}, - {"sf", 9}, {"assertion", 9}, {"sf", 10}, - {"sb", 9}, {"assertion", 9}, {"sf", 10}}}}; + { + "complex-jumps", + { + {"of", 1}, {"of", 4}, {"sf", 9}, {"sf", 12}, {"of", 13}, + {"ob", 12}, {"sf", 5}, {"of", 6}, {"of", 7}, {"ob", 6}, + {"sf", 10}, {"of", 11}, {"ob", 10}, {"sf", 2}, {"of", 3}, + {"of", 11}, {"of", 7}, {"sb", 11}, {"of", 7}, {"of", 8}, + {"of", 13}, {"sb", 8}, {"of", 13}, {"of", 14}, + }, + }, + { + "failing-assertions", + { + {"of", 1}, {"of", 2}, {"of", 3}, + {"of", 4}, {"of", 5}, {"of", 6}, + {"of", 6}, {"assertion", 6}, {"of", 7}, + {"ob", 6}, {"assertion", 6}, {"of", 7}, + {"ob", 6}, {"assertion", 6}, {"ob", 5}, + {"of", 6}, {"of", 6}, {"assertion", 6}, + {"of", 7}, {"of", 8}, {"sf", 9}, + {"sb", 8}, {"sf", 9}, {"sf", 9}, + {"assertion", 9}, {"sb", 8}, {"sf", 9}, + {"sf", 9}, {"assertion", 9}, {"sf", 10}, + {"sb", 9}, {"assertion", 9}, {"sf", 10}, + }, + }, + }; moveAndCheck(expected.at(GetParam())); } @@ -454,23 +498,33 @@ TEST_P(SimulationTest, StepOver) { TEST_P(SimulationTest, StepOut) { const std::map>> - expected = {{"complex-jumps", - {{"sf", 1}, {"sf", 4}, {"sf", 9}, {"sf", 12}, {"sf", 5}, - {"ub", 12}, {"sf", 5}, {"sf", 6}, {"ub", 12}, {"sf", 5}, - {"of", 6}, {"of", 7}, {"ub", 12}, {"sf", 5}, {"sf", 6}, - {"sf", 10}, {"ub", 6}, {"sf", 10}, {"sf", 2}, {"sf", 3}, - {"ub", 10}, {"uf", 7}, {"ob", 6}, {"sf", 10}, {"sf", 2}, - {"uf", 11}, {"uf", 7}, {"uf", 13}}}, - {"failing-assertions", - {{"sf", 1}, - {"uf", 6}, - {"uf", 9}, - {"uf", 11}, - {"ub", 0}, - {"uf", 6}, - {"ub", 0}, - {"uf", 6}, - {"uf", 9}}}}; + expected = { + { + "complex-jumps", + { + {"sf", 1}, {"sf", 4}, {"sf", 9}, {"sf", 12}, {"sf", 5}, + {"ub", 12}, {"sf", 5}, {"sf", 6}, {"ub", 12}, {"sf", 5}, + {"of", 6}, {"of", 7}, {"ub", 12}, {"sf", 5}, {"sf", 6}, + {"sf", 10}, {"ub", 6}, {"sf", 10}, {"sf", 2}, {"sf", 3}, + {"ub", 10}, {"uf", 7}, {"ob", 6}, {"sf", 10}, {"sf", 2}, + {"uf", 11}, {"uf", 7}, {"uf", 13}, + }, + }, + { + "failing-assertions", + { + {"sf", 1}, + {"uf", 6}, + {"uf", 9}, + {"uf", 11}, + {"ub", 0}, + {"uf", 6}, + {"ub", 0}, + {"uf", 6}, + {"uf", 9}, + }, + }, + }; moveAndCheck(expected.at(GetParam())); } @@ -489,30 +543,40 @@ TEST_P(SimulationTest, StepOut) { TEST_P(SimulationTest, RunSimulation) { const std::map>> - expected = {{"complex-jumps", - {{"sf", 1}, - {"rf", 15}, - {"rb", 0}, - {"sf", 1}, - {"sf", 4}, - {"sf", 9}, - {"sf", 12}, - {"sf", 5}, - {"sf", 6}, - {"rf", 15}, - {"rb", 0}, - {"rf", 15}}}, - {"failing-assertions", - {{"sf", 1}, - {"rf", 6}, - {"rf", 9}, - {"rf", 11}, - {"rb", 0}, - {"rf", 6}, - {"rb", 0}, - {"rf", 6}, - {"rf", 9}, - {"rf", 11}}}}; + expected = { + { + "complex-jumps", + { + {"sf", 1}, + {"rf", 15}, + {"rb", 0}, + {"sf", 1}, + {"sf", 4}, + {"sf", 9}, + {"sf", 12}, + {"sf", 5}, + {"sf", 6}, + {"rf", 15}, + {"rb", 0}, + {"rf", 15}, + }, + }, + { + "failing-assertions", + { + {"sf", 1}, + {"rf", 6}, + {"rf", 9}, + {"rf", 11}, + {"rb", 0}, + {"rf", 6}, + {"rb", 0}, + {"rf", 6}, + {"rf", 9}, + {"rf", 11}, + }, + }, + }; moveAndCheck(expected.at(GetParam())); ASSERT_TRUE(state->isFinished(state)); } @@ -530,14 +594,19 @@ TEST_P(SimulationTest, InGateDefinitionBreakpoints) { } const std::map> breakpointPositions = { - {"complex-jumps", {86, 280, 411}}, {"failing-assertions", {}}}; + {"complex-jumps", {86, 280, 411}}, + {"failing-assertions", {}}, + }; const std::map> - expectedBreakpointPositions = {{"complex-jumps", {2, 7, 11}}, - {"failing-assertions", {}}}; + expectedBreakpointPositions = { + {"complex-jumps", {2, 7, 11}}, + {"failing-assertions", {}}, + }; const std::map> expectedBreakpointHits = { {"complex-jumps", {2, 11, 7, 2, 11, 2, 11, 2, 11}}, - {"failing-assertions", {}}}; + {"failing-assertions", {}}, + }; for (size_t index = 0; index < breakpointPositions.at(GetParam()).size(); index++) { @@ -627,4 +696,5 @@ INSTANTIATE_TEST_SUITE_P(StringParams, SimulationTest, ::testing::Values("complex-jumps", "failing-assertions")); +} // namespace } // namespace mqt::debugger::test diff --git a/test/test_utility.cpp b/test/test_utility.cpp index c85c500a..a967179f 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -23,6 +23,7 @@ #include namespace mqt::debugger::test { +namespace { /** * @brief Fixture for testing the correctness of utility functions. @@ -49,7 +50,8 @@ TEST_F(UtilityTest, GetInstructionPosition) { const std::map> expected = { {0, {0, 9}}, {1, {38, 112}}, {2, {79, 88}}, - {3, {112, 112}}, {4, {150, 298}}, {12, {452, 477}}}; + {3, {112, 112}}, {4, {150, 298}}, {12, {452, 477}}, + }; for (const auto& [instruction, expectedPosition] : expected) { size_t start = 0; size_t end = 0; @@ -73,4 +75,5 @@ TEST_F(UtilityTest, BadInstructionPosition) { ASSERT_EQ(state->getInstructionPosition(state, 100, &start, &end), ERROR); } +} // namespace } // namespace mqt::debugger::test diff --git a/test/utils/common_fixtures.hpp b/test/utils/common_fixtures.hpp index b138c6c7..03d7c46b 100644 --- a/test/utils/common_fixtures.hpp +++ b/test/utils/common_fixtures.hpp @@ -227,8 +227,8 @@ class CompilationTest : public CustomCodeFixture { */ static CompilationSettings makeSettings(uint8_t opt, size_t slice) { return { - /*opt=*/opt, - /*sliceIndex=*/slice, + .opt = opt, + .sliceIndex = slice, }; } diff --git a/test/utils/utils_test.hpp b/test/utils/utils_test.hpp index 86a379dd..9e4ab4e5 100644 --- a/test/utils/utils_test.hpp +++ b/test/utils/utils_test.hpp @@ -123,8 +123,9 @@ class StatEqPreambleEntry : public PreambleEntry { StatEqPreambleEntry(std::vector n, std::vector dist, double fid) : names(std::move(n)), distribution(dist.size()), fidelity(fid) { - std::ranges::transform(dist, this->distribution.begin(), - [](double value) { return Complex{value, 0.0}; }); + std::ranges::transform(dist, this->distribution.begin(), [](double value) { + return Complex{.real = value, .imaginary = 0.0}; + }); } [[nodiscard]] std::string toString() const override {