Skip to content

Commit a06f059

Browse files
committed
✅ Fix all tests
1 parent e7b32bb commit a06f059

File tree

3 files changed

+56
-49
lines changed

3 files changed

+56
-49
lines changed

include/mqt-core/na/device/Device.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <cstddef>
2121
#include <cstdint>
2222
#include <memory>
23+
#include <optional>
2324
#include <string>
2425
#include <unordered_map>
2526
#include <utility>

src/na/device/Device.cpp

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -392,40 +392,38 @@ MQT_NA_QDMI_Operation_impl_d::MQT_NA_QDMI_Operation_impl_d(
392392
MQT_NA_QDMI_Operation_impl_d::MQT_NA_QDMI_Operation_impl_d(
393393
std::string name, size_t numParameters, MQT_NA_QDMI_Site zone,
394394
uint64_t meanShuttlingSpeed)
395-
: name_(std::move(name)), numParameters_(numParameters), numQubits_(0),
395+
: name_(std::move(name)), numParameters_(numParameters),
396396
meanShuttlingSpeed_(meanShuttlingSpeed), isZoned_(true) {
397397
supportedSites_.emplace_back(zone);
398398
}
399399
auto MQT_NA_QDMI_Operation_impl_d::sortSites() -> void {
400-
if (!isZoned_) {
401-
if (numQubits_ == 1) {
402-
// sort sites by their pointer address
403-
std::ranges::sort(supportedSites_);
404-
} else if (numQubits_ == 2) {
405-
// First ensure that in each site's pair the first site is the one
406-
// with the smaller pointer address
407-
std::ranges::for_each(
408-
reinterpret_cast<
409-
std::vector<std::pair<MQT_NA_QDMI_Site, MQT_NA_QDMI_Site>>&>(
410-
supportedSites_),
411-
[](auto& p) {
412-
if (p.first < p.second) {
413-
std::swap(p.first, p.second);
414-
}
415-
});
416-
// Then sort the pairs
417-
std::ranges::sort(
418-
reinterpret_cast<
419-
std::vector<std::pair<MQT_NA_QDMI_Site, MQT_NA_QDMI_Site>>&>(
420-
supportedSites_));
421-
}
400+
if (numQubits_ == 1) {
401+
// sort sites by their pointer address
402+
std::ranges::sort(supportedSites_);
403+
} else if (numQubits_ == 2) {
404+
// First ensure that in each site's pair the first site is the one
405+
// with the smaller pointer address
406+
std::ranges::for_each(
407+
reinterpret_cast<
408+
std::vector<std::pair<MQT_NA_QDMI_Site, MQT_NA_QDMI_Site>>&>(
409+
supportedSites_),
410+
[](auto& p) {
411+
if (p.first < p.second) {
412+
std::swap(p.first, p.second);
413+
}
414+
});
415+
// Then sort the pairs
416+
std::ranges::sort(
417+
reinterpret_cast<
418+
std::vector<std::pair<MQT_NA_QDMI_Site, MQT_NA_QDMI_Site>>&>(
419+
supportedSites_));
422420
}
423421
}
424422
auto MQT_NA_QDMI_Operation_impl_d::makeUniqueGlobalSingleQubit(
425423
const std::string& name, const size_t numParameters,
426424
const uint64_t duration, const double fidelity, MQT_NA_QDMI_Site zone)
427425
-> std::unique_ptr<MQT_NA_QDMI_Operation_impl_d> {
428-
MQT_NA_QDMI_Operation_impl_d op(name, numParameters, duration, fidelity,
426+
MQT_NA_QDMI_Operation_impl_d op(name, numParameters, 1U, duration, fidelity,
429427
zone);
430428
return std::make_unique<MQT_NA_QDMI_Operation_impl_d>(std::move(op));
431429
}
@@ -498,15 +496,18 @@ auto MQT_NA_QDMI_Operation_impl_d::queryProperty(
498496
return QDMI_ERROR_INVALIDARGUMENT;
499497
}
500498
if (sites != nullptr) {
501-
if (numQubits_ == 1) {
502-
// if the (single) site is not supported, return with an error
499+
// If numQubits_ == 1 or isZoned_ = true
500+
if (numSites == 1) {
501+
// If the (single) site is not supported, return with an error
503502
if (!std::ranges::binary_search(supportedSites_, *sites)) {
504503
return QDMI_ERROR_NOTSUPPORTED;
505504
}
506-
} else if (numQubits_ == 2) {
505+
} else if (numSites == 2) {
506+
// NOLINTBEGIN(cppcoreguidelines-pro-bounds-pointer-arithmetic)
507507
const std::pair needle = sites[0] < sites[1]
508508
? std::make_pair(sites[0], sites[1])
509509
: std::make_pair(sites[1], sites[0]);
510+
// NOLINTEND(cppcoreguidelines-pro-bounds-pointer-arithmetic)
510511
// if the pair of sites is not supported, return with an error
511512
if (!std::ranges::binary_search(
512513
reinterpret_cast<const std::vector<
@@ -551,7 +552,7 @@ auto MQT_NA_QDMI_Operation_impl_d::queryProperty(
551552
*numQubits_, prop, size, value, sizeRet)
552553
}
553554
if (idlingFidelity_) {
554-
ADD_SINGLE_VALUE_PROPERTY(QDMI_OPERATION_PROPERTY_QUBITSNUM, double,
555+
ADD_SINGLE_VALUE_PROPERTY(QDMI_OPERATION_PROPERTY_IDLINGFIDELITY, double,
555556
*idlingFidelity_, prop, size, value, sizeRet)
556557
}
557558
ADD_SINGLE_VALUE_PROPERTY(QDMI_OPERATION_PROPERTY_ISZONED, bool, isZoned_,

test/na/device/test_device.cpp

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -580,21 +580,21 @@ TEST_F(NADeviceTest, QuerySiteData) {
580580
}
581581

582582
TEST_F(NADeviceTest, QueryOperationData) {
583-
uint64_t duration = 0;
584-
bool isDurationSupported = false;
585-
uint64_t meanShuttlingSpeed = 0;
586-
bool isMeanShuttlingSpeedSupported = false;
587-
double fidelity = 0;
588-
bool isFidelitySupported = false;
589-
size_t numQubits = 0;
590-
bool isNumQubitsSupported = false;
591-
size_t numParameters = 0;
592-
bool isZoned = false;
593583
std::vector<MQT_NA_QDMI_Site> sites;
594584
EXPECT_NO_THROW(sites = querySites(session));
595585
std::vector<MQT_NA_QDMI_Operation> operations;
596586
EXPECT_NO_THROW(operations = queryOperations(session));
597587
for (auto* operation : operations) {
588+
uint64_t duration = 0;
589+
bool isDurationSupported = false;
590+
uint64_t meanShuttlingSpeed = 0;
591+
bool isMeanShuttlingSpeedSupported = false;
592+
double fidelity = 0;
593+
bool isFidelitySupported = false;
594+
size_t numQubits = 0;
595+
bool isNumQubitsSupported = false;
596+
size_t numParameters = 0;
597+
bool isZoned = false;
598598
size_t nameSize = 0;
599599
ASSERT_EQ(MQT_NA_QDMI_device_session_query_operation_property(
600600
session, operation, 0, nullptr, 0, nullptr,
@@ -640,32 +640,37 @@ TEST_F(NADeviceTest, QueryOperationData) {
640640
isNumQubitsSupported = true;
641641
EXPECT_GT(numQubits, 0);
642642
}
643+
EXPECT_EQ(MQT_NA_QDMI_device_session_query_operation_property(
644+
session, operation, 0, nullptr, 0, nullptr,
645+
QDMI_OPERATION_PROPERTY_ISZONED, sizeof(bool), &isZoned,
646+
nullptr),
647+
QDMI_SUCCESS);
648+
EXPECT_EQ(MQT_NA_QDMI_device_session_query_operation_property(
649+
session, operation, 0, nullptr, 0, nullptr,
650+
QDMI_OPERATION_PROPERTY_PARAMETERSNUM, sizeof(size_t),
651+
&numParameters, nullptr),
652+
QDMI_SUCCESS);
643653
// isDurationSupported <==> isFidelitySupported
644654
EXPECT_EQ(isDurationSupported, isFidelitySupported);
645655
// isMeanShuttlingSpeedSupported <==> not isDurationSupported
646656
EXPECT_EQ(isMeanShuttlingSpeedSupported, !isDurationSupported);
647657
// isMeanShuttlingSpeedSupported ==> not isNumQubitsSupported
648-
EXPECT_TRUE(!isMeanShuttlingSpeedSupported || isNumQubitsSupported);
658+
EXPECT_TRUE(!isMeanShuttlingSpeedSupported || !isNumQubitsSupported);
649659
// isMeanShuttlingSpeedSupported ==> isZoned
650660
EXPECT_TRUE(!isMeanShuttlingSpeedSupported || isZoned);
651661
// not isZoned ==> isNumQubitsSupported
652-
EXPECT_TRUE(!isZoned || isNumQubitsSupported);
662+
EXPECT_TRUE(isZoned || isNumQubitsSupported);
653663
EXPECT_EQ(MQT_NA_QDMI_device_session_query_operation_property(
654664
session, operation, 0, nullptr, 0, nullptr,
655665
QDMI_OPERATION_PROPERTY_PARAMETERSNUM, sizeof(size_t),
656666
&numParameters, nullptr),
657667
QDMI_SUCCESS);
658-
EXPECT_EQ(MQT_NA_QDMI_device_session_query_operation_property(
659-
session, operation, 0, nullptr, 0, nullptr,
660-
QDMI_OPERATION_PROPERTY_ISZONED, sizeof(bool), &isZoned,
661-
nullptr),
662-
QDMI_SUCCESS);
663668
size_t sitesSize = 0;
664669
EXPECT_EQ(MQT_NA_QDMI_device_session_query_operation_property(
665670
session, operation, 0, nullptr, 0, nullptr,
666671
QDMI_OPERATION_PROPERTY_SITES, 0, nullptr, &sitesSize),
667672
QDMI_SUCCESS);
668-
if (numQubits == 1) {
673+
if (isNumQubitsSupported && numQubits == 1) {
669674
std::unordered_set<MQT_NA_QDMI_Site> supportedSites;
670675
for (const auto& site : sites) {
671676
result = MQT_NA_QDMI_device_session_query_operation_property(
@@ -746,18 +751,18 @@ TEST_F(NADeviceTest, QueryOperationData) {
746751
const std::unordered_set queriedSupportedSitesSet(
747752
queriedSupportedSitesVec.cbegin(), queriedSupportedSitesVec.cend());
748753
EXPECT_EQ(queriedSupportedSitesSet, supportedSites);
749-
} else if (numQubits == 2) {
754+
} else if (isNumQubitsSupported && numQubits == 2) {
750755
if (!isZoned) {
751756
EXPECT_EQ(MQT_NA_QDMI_device_session_query_operation_property(
752757
session, operation, 0, nullptr, 0, nullptr,
753758
QDMI_OPERATION_PROPERTY_INTERACTIONRADIUS, 0, nullptr,
754759
nullptr),
755-
QDMI_ERROR_NOTSUPPORTED);
760+
QDMI_SUCCESS);
756761
EXPECT_EQ(MQT_NA_QDMI_device_session_query_operation_property(
757762
session, operation, 0, nullptr, 0, nullptr,
758763
QDMI_OPERATION_PROPERTY_BLOCKINGRADIUS, 0, nullptr,
759764
nullptr),
760-
QDMI_ERROR_NOTSUPPORTED);
765+
QDMI_SUCCESS);
761766
EXPECT_EQ(MQT_NA_QDMI_device_session_query_operation_property(
762767
session, operation, 0, nullptr, 0, nullptr,
763768
QDMI_OPERATION_PROPERTY_IDLINGFIDELITY, 0, nullptr,

0 commit comments

Comments
 (0)