@@ -39,7 +39,8 @@ static std::vector<py::object> readRunResults(mlir::ModuleOp module,
3939}
4040
4141static std::tuple<std::string, MlirModule, OpaqueArguments *,
42- mlir::func::FuncOp, std::string, mlir::func::FuncOp>
42+ mlir::func::FuncOp, std::string, mlir::func::FuncOp,
43+ std::vector<std::string>>
4344getKernelLaunchParameters (py::object &kernel, py::args args) {
4445 if (!py::hasattr (kernel, " arguments" ))
4546 throw std::runtime_error (
@@ -52,6 +53,9 @@ getKernelLaunchParameters(py::object &kernel, py::args args) {
5253 if (py::hasattr (kernel, " compile" ))
5354 kernel.attr (" compile" )();
5455
56+ // Process any callable args
57+ const auto callableNames = getCallableNames (kernel, args);
58+
5559 auto origKernName = kernel.attr (" name" ).cast <std::string>();
5660 auto kernelName = origKernName + " .run" ;
5761 if (!py::hasattr (kernel, " module" ) || kernel.attr (" module" ).is_none ())
@@ -76,16 +80,19 @@ getKernelLaunchParameters(py::object &kernel, py::args args) {
7680 throw std::runtime_error (
7781 " failed to autogenerate the runnable variant of the kernel." );
7882 }
79- auto *argData = toOpaqueArgs (args, kernelMod, kernelName);
83+ auto *argData =
84+ toOpaqueArgs (args, kernelMod, kernelName, getCallableArgHandler ());
8085 auto funcOp = getKernelFuncOp (kernelMod, kernelName);
81- return {kernelName, kernelMod, argData, funcOp, origKernName, origKern};
86+ return {kernelName, kernelMod, argData, funcOp,
87+ origKernName, origKern, callableNames};
8288}
8389
8490static details::RunResultSpan
8591pyRunTheKernel (const std::string &name, const std::string &origName,
8692 MlirModule module , mlir::func::FuncOp funcOp,
8793 mlir::func::FuncOp origKernel, OpaqueArguments &runtimeArgs,
8894 quantum_platform &platform, std::size_t shots_count,
95+ const std::vector<std::string> &callableNames,
8996 std::size_t qpu_id = 0 ) {
9097 auto returnTypes = origKernel.getResultTypes ();
9198 if (returnTypes.empty () || returnTypes.size () > 1 )
@@ -101,13 +108,13 @@ pyRunTheKernel(const std::string &name, const std::string &origName,
101108
102109 auto mod = unwrap (module );
103110
104- auto [rawArgs, size, returnOffset, thunk] =
105- pyAltLaunchKernelBase ( name, module , returnTy, runtimeArgs, {} , 0 , false );
111+ auto [rawArgs, size, returnOffset, thunk] = pyAltLaunchKernelBase (
112+ name, module , returnTy, runtimeArgs, callableNames , 0 , false );
106113
107114 auto results = details::runTheKernel (
108115 [&]() mutable {
109116 pyLaunchKernel (name, thunk, mod, runtimeArgs, rawArgs, size,
110- returnOffset, {} );
117+ returnOffset, callableNames );
111118 },
112119 platform, name, origName, shots_count, qpu_id);
113120
@@ -133,7 +140,7 @@ std::vector<py::object> pyRun(py::object &kernel, py::args args,
133140 if (shots_count == 0 )
134141 return {};
135142
136- auto [name, module , argData, func, origName, origKern] =
143+ auto [name, module , argData, func, origName, origKern, callableNames ] =
137144 getKernelLaunchParameters (kernel, args);
138145
139146 auto mod = unwrap (module );
@@ -149,7 +156,7 @@ std::vector<py::object> pyRun(py::object &kernel, py::args args,
149156 }
150157
151158 auto span = pyRunTheKernel (name, origName, module , func, origKern, *argData,
152- platform, shots_count);
159+ platform, shots_count, callableNames );
153160 delete argData;
154161 auto results = pyReadResults (span, module , func, origKern, shots_count);
155162
@@ -184,7 +191,7 @@ async_run_result pyRunAsync(py::object &kernel, py::args args,
184191 " ) exceeds the number of available QPUs (" +
185192 std::to_string (numQPUs) + " )" );
186193
187- auto [name, module , argData, func, origName, origKern] =
194+ auto [name, module , argData, func, origName, origKern, callableNames ] =
188195 getKernelLaunchParameters (kernel, args);
189196
190197 auto mod = unwrap (module );
@@ -219,16 +226,17 @@ async_run_result pyRunAsync(py::object &kernel, py::args args,
219226 QuantumTask wrapped = detail::make_copyable_function (
220227 [sp = std::move (spanPromise), ep = std::move (errorPromise), shots_count,
221228 qpu_id, argData, name, module , func, origKern, origName,
222- noise_model = std::move (noise_model)]() mutable {
229+ noise_model = std::move (noise_model), callableNames ]() mutable {
223230 auto &platform = get_platform ();
224231
225232 // Launch the kernel in the appropriate context.
226233 if (noise_model.has_value ())
227234 platform.set_noise (&noise_model.value ());
228235
229236 try {
230- auto span = pyRunTheKernel (name, origName, module , func, origKern,
231- *argData, platform, shots_count, qpu_id);
237+ auto span =
238+ pyRunTheKernel (name, origName, module , func, origKern, *argData,
239+ platform, shots_count, callableNames, qpu_id);
232240 delete argData;
233241 sp.set_value (span);
234242 ep.set_value (" " );
0 commit comments