From 582094ff6d244432e6d09b13e88fbd2c01904374 Mon Sep 17 00:00:00 2001 From: Eric Schweitz Date: Tue, 19 Nov 2024 12:11:18 -0800 Subject: [PATCH] Fix for issue #2383. (#2392) * Fix for issue #2383. Instead of erroneously trying to copy a part of the moduleOp, clone the entire moduleOp so that any referenced artifacts are properly copied. Fixes issue #2383. * Reformat some comments with clang-format. --------- Signed-off-by: Eric Schweitz --- runtime/common/BaseRemoteRESTQPU.h | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/runtime/common/BaseRemoteRESTQPU.h b/runtime/common/BaseRemoteRESTQPU.h index 0834bc7e3e..9f5af9d88b 100644 --- a/runtime/common/BaseRemoteRESTQPU.h +++ b/runtime/common/BaseRemoteRESTQPU.h @@ -489,21 +489,19 @@ class BaseRemoteRESTQPU : public cudaq::QPU { continue; // Get the ansatz - auto ansatz = moduleOp.lookupSymbol( - std::string(cudaq::runtime::cudaqGenPrefixName) + kernelName); + [[maybe_unused]] auto ansatz = + moduleOp.lookupSymbol( + cudaq::runtime::cudaqGenPrefixName + kernelName); + assert(ansatz && "could not find the ansatz kernel"); // Create a new Module to clone the ansatz into it - auto tmpModuleOp = builder.create(); - tmpModuleOp.push_back(ansatz.clone()); - moduleOp.walk([&](quake::WireSetOp wireSetOp) { - tmpModuleOp.push_back(wireSetOp.clone()); - }); + auto tmpModuleOp = moduleOp.clone(); // Extract the binary symplectic encoding auto [binarySymplecticForm, coeffs] = term.get_raw_data(); - // Create the pass manager, add the quake observe ansatz pass - // and run it followed by the canonicalizer + // Create the pass manager, add the quake observe ansatz pass and run it + // followed by the canonicalizer mlir::PassManager pm(&context); pm.addNestedPass( cudaq::opt::createObserveAnsatzPass(binarySymplecticForm[0])); @@ -527,10 +525,9 @@ class BaseRemoteRESTQPU : public cudaq::QPU { modules.emplace_back(kernelName, moduleOp); if (emulate) { - // If we are in emulation mode, we need to first get a - // full QIR representation of the code. Then we'll map to - // an LLVM Module, create a JIT ExecutionEngine pointer - // and use that for execution + // If we are in emulation mode, we need to first get a full QIR + // representation of the code. Then we'll map to an LLVM Module, create a + // JIT ExecutionEngine pointer and use that for execution for (auto &[name, module] : modules) { auto clonedModule = module.clone(); jitEngines.emplace_back(