Skip to content

Commit

Permalink
* Unpack arguments based on the caller's execution context
Browse files Browse the repository at this point in the history
  • Loading branch information
khalatepradnya committed Sep 23, 2024
1 parent 7697be5 commit 57e6416
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion python/cudaq/kernel/kernel_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,17 @@ def __call__(self, *args):
raise RuntimeError(
"The 'photonics' target must be used with a valid function."
)
PhotonicsHandler(self.kernelFunction)(*args)
# NOTE: Since this handler does not support MLIR mode (yet), just
# invoke the kernel. If calling from a bound function, need to
# unpack the arguments, for example, see `pyGetStateLibraryMode`
try:
context_name = cudaq_runtime.getExecutionContextName()
except RuntimeError:
context_name = None
callable_args = args
if "extract-state" == context_name and len(args) == 1:
callable_args = args[0]
PhotonicsHandler(self.kernelFunction)(*callable_args)
return

# Prepare captured state storage for the run
Expand Down
4 changes: 4 additions & 0 deletions python/runtime/common/py_ExecutionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@ void bindExecutionContext(py::module &mod) {
auto &platform = cudaq::get_platform();
return platform.supports_conditional_feedback();
});
mod.def("getExecutionContextName", []() {
auto &self = cudaq::get_platform();
return self.get_exec_ctx()->name;
});
}
} // namespace cudaq

0 comments on commit 57e6416

Please sign in to comment.