Skip to content

Commit

Permalink
[python runtime] Use argument synthesis pass
Browse files Browse the repository at this point in the history
These changes convert the python runtime over to use the new argument
synthesis pass.
  • Loading branch information
schweitzpgi committed Aug 16, 2024
1 parent 78f0715 commit c99b6dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 deletions python/runtime/cudaq/platform/py_alt_launch_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
******************************************************************************/

#include "JITExecutionCache.h"
#include "common/ArgumentConversion.h"
#include "common/ArgumentWrapper.h"
#include "common/Environment.h"
#include "cudaq/Optimizer/Builder/Factory.h"
#include "cudaq/Optimizer/Builder/Runtime.h"
#include "cudaq/Optimizer/CAPI/Dialects.h"
#include "cudaq/Optimizer/CodeGen/OpenQASMEmitter.h"
#include "cudaq/Optimizer/CodeGen/Passes.h"
Expand All @@ -22,7 +24,6 @@
#include "cudaq/platform/qpu.h"
#include "utils/OpaqueArguments.h"
#include "utils/PyTypes.h"

#include "llvm/Support/Error.h"
#include "mlir/Bindings/Python/PybindAdaptors.h"
#include "mlir/CAPI/ExecutionEngine.h"
Expand All @@ -31,7 +32,6 @@
#include "mlir/InitAllPasses.h"
#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
#include "mlir/Target/LLVMIR/Export.h"

#include <fmt/core.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
Expand Down Expand Up @@ -510,8 +510,17 @@ MlirModule synthesizeKernel(const std::string &name, MlirModule module,
auto enablePrintMLIREachPass =
getEnvBool("CUDAQ_MLIR_PRINT_EACH_PASS", false);

cudaq::opt::ArgumentConverter argCon(name, unwrap(module));
argCon.gen(runtimeArgs.getArgs());
std::string kernName = cudaq::runtime::cudaqGenPrefixName + name;
SmallVector<StringRef> kernels = {kernName};
std::string substBuff;
llvm::raw_string_ostream ss(substBuff);
ss << argCon.getSubstitutionModule();
SmallVector<StringRef> substs = {substBuff};
PassManager pm(context);
pm.addPass(cudaq::opt::createQuakeSynthesizer(name, rawArgs, 0, true));
pm.addNestedPass<func::FuncOp>(
cudaq::opt::createArgumentSynthesisPass(kernels, substs));
pm.addPass(createCanonicalizerPass());

// Run state preparation for quantum devices only.
Expand Down
2 changes: 2 additions & 0 deletions python/utils/OpaqueArguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class OpaqueArguments {
public:
using OpaqueArgDeleter = std::function<void(void *)>;

const std::vector<void *> &getArgs() const { return args; }

private:
/// @brief The opaque argument pointers
std::vector<void *> args;
Expand Down

0 comments on commit c99b6dc

Please sign in to comment.