Skip to content

Commit

Permalink
Fix for issue NVIDIA#2383. (NVIDIA#2392)
Browse files Browse the repository at this point in the history
* Fix for issue NVIDIA#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 NVIDIA#2383.

* Reformat some comments with clang-format.

---------

Signed-off-by: Eric Schweitz <[email protected]>
  • Loading branch information
schweitzpgi authored Nov 19, 2024
1 parent 0561cb1 commit 582094f
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions runtime/common/BaseRemoteRESTQPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,21 +489,19 @@ class BaseRemoteRESTQPU : public cudaq::QPU {
continue;

// Get the ansatz
auto ansatz = moduleOp.lookupSymbol<mlir::func::FuncOp>(
std::string(cudaq::runtime::cudaqGenPrefixName) + kernelName);
[[maybe_unused]] auto ansatz =
moduleOp.lookupSymbol<mlir::func::FuncOp>(
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<mlir::ModuleOp>();
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<mlir::func::FuncOp>(
cudaq::opt::createObserveAnsatzPass(binarySymplecticForm[0]));
Expand All @@ -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(
Expand Down

0 comments on commit 582094f

Please sign in to comment.