From de6699d7c480b96bad35b074e22924d09324ebee Mon Sep 17 00:00:00 2001 From: Thien Nguyen <58006629+1tnguyen@users.noreply.github.com> Date: Sat, 14 Dec 2024 07:38:19 +1100 Subject: [PATCH] Always clear `threadToQpuId` when we clear `platformQPUs` (#2478) * Always clear threadToQpuId when we clear platformQPUs Signed-off-by: Thien Nguyen * Clear threadToQpuId for DefaultQuantumPlatform for consistency Signed-off-by: Thien Nguyen --------- Signed-off-by: Thien Nguyen --- runtime/cudaq/platform/default/DefaultQuantumPlatform.cpp | 2 ++ runtime/cudaq/platform/mqpu/MultiQPUPlatform.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/runtime/cudaq/platform/default/DefaultQuantumPlatform.cpp b/runtime/cudaq/platform/default/DefaultQuantumPlatform.cpp index df8a89e6f4..b24637c2ce 100644 --- a/runtime/cudaq/platform/default/DefaultQuantumPlatform.cpp +++ b/runtime/cudaq/platform/default/DefaultQuantumPlatform.cpp @@ -82,6 +82,7 @@ class DefaultQuantumPlatform : public cudaq::quantum_platform { /// specified by that variable. void setTargetBackend(const std::string &backend) override { platformQPUs.clear(); + threadToQpuId.clear(); platformQPUs.emplace_back(std::make_unique()); cudaq::info("Backend string is {}", backend); @@ -121,6 +122,7 @@ class DefaultQuantumPlatform : public cudaq::quantum_platform { auto qpuName = config.BackendConfig->PlatformQpu; cudaq::info("Default platform QPU subtype name: {}", qpuName); platformQPUs.clear(); + threadToQpuId.clear(); platformQPUs.emplace_back(cudaq::registry::get(qpuName)); if (platformQPUs.front() == nullptr) throw std::runtime_error( diff --git a/runtime/cudaq/platform/mqpu/MultiQPUPlatform.cpp b/runtime/cudaq/platform/mqpu/MultiQPUPlatform.cpp index bdde97a464..198a214c16 100644 --- a/runtime/cudaq/platform/mqpu/MultiQPUPlatform.cpp +++ b/runtime/cudaq/platform/mqpu/MultiQPUPlatform.cpp @@ -31,6 +31,7 @@ class MultiQPUQuantumPlatform : public cudaq::quantum_platform { // Make sure that we clean up the client QPUs first before cleaning up the // remote servers. platformQPUs.clear(); + threadToQpuId.clear(); platformNumQPUs = 0; m_remoteServers.clear(); } @@ -154,6 +155,7 @@ class MultiQPUQuantumPlatform : public cudaq::quantum_platform { qpuSubType)); if (qpuSubType == "NvcfSimulatorQPU") { platformQPUs.clear(); + threadToQpuId.clear(); auto simName = getOpt(description, "backend"); if (simName.empty()) simName = "custatevec-fp32"; @@ -199,6 +201,7 @@ class MultiQPUQuantumPlatform : public cudaq::quantum_platform { } else if (qpuSubType == "orca") { auto urls = cudaq::split(getOpt(description, "url"), ','); platformQPUs.clear(); + threadToQpuId.clear(); for (std::size_t qId = 0; qId < urls.size(); ++qId) { // Populate the information and add the QPUs platformQPUs.emplace_back(cudaq::registry::get("orca")); @@ -244,6 +247,7 @@ class MultiQPUQuantumPlatform : public cudaq::quantum_platform { "receiving {}, expecting {}.", sims.size(), urls.size())); platformQPUs.clear(); + threadToQpuId.clear(); for (std::size_t qId = 0; qId < urls.size(); ++qId) { const auto simName = sims.size() == 1 ? sims.front() : sims[qId]; // Populate the information and add the QPUs