|
28 | 28 | #include <sstream> |
29 | 29 | #include <stdexcept> |
30 | 30 | #include <string> |
| 31 | +#include <type_traits> |
31 | 32 | #include <utility> |
| 33 | +#include <variant> |
32 | 34 | #include <vector> |
33 | 35 |
|
34 | 36 | namespace fomac { |
@@ -285,35 +287,70 @@ std::vector<QDMI_Program_Format> Device::getSupportedProgramFormats() const { |
285 | 287 | } |
286 | 288 |
|
287 | 289 | Job Device::submitJob(const std::string& program, |
288 | | - const QDMI_Program_Format format, |
289 | | - const size_t numShots) const { |
| 290 | + const QDMI_Program_Format format, const size_t numShots, |
| 291 | + const std::optional<CustomJobParameter>& custom1, |
| 292 | + const std::optional<CustomJobParameter>& custom2, |
| 293 | + const std::optional<CustomJobParameter>& custom3, |
| 294 | + const std::optional<CustomJobParameter>& custom4, |
| 295 | + const std::optional<CustomJobParameter>& custom5) const { |
290 | 296 | QDMI_Job job = nullptr; |
291 | 297 | qdmi::throwIfError(QDMI_device_create_job(device_, &job), "Creating job"); |
292 | | - Job jobWrapper{job}; // RAII wrapper to prevent leaks in case of exceptions |
| 298 | + Job jobWrapper{job}; |
293 | 299 |
|
294 | | - // Set program format |
295 | 300 | qdmi::throwIfError(QDMI_job_set_parameter(jobWrapper, |
296 | 301 | QDMI_JOB_PARAMETER_PROGRAMFORMAT, |
297 | 302 | sizeof(format), &format), |
298 | 303 | "Setting program format"); |
299 | | - |
300 | | - // Set program |
301 | 304 | qdmi::throwIfError( |
302 | 305 | QDMI_job_set_parameter(jobWrapper, QDMI_JOB_PARAMETER_PROGRAM, |
303 | 306 | program.size() + 1, program.c_str()), |
304 | 307 | "Setting program"); |
305 | | - |
306 | | - // Set number of shots |
307 | 308 | qdmi::throwIfError(QDMI_job_set_parameter(jobWrapper, |
308 | 309 | QDMI_JOB_PARAMETER_SHOTSNUM, |
309 | 310 | sizeof(numShots), &numShots), |
310 | 311 | "Setting number of shots"); |
311 | 312 |
|
312 | | - // Submit the job |
| 313 | + if (custom1.has_value()) { |
| 314 | + setCustomJobParam(jobWrapper, QDMI_JOB_PARAMETER_CUSTOM1, *custom1); |
| 315 | + } |
| 316 | + if (custom2.has_value()) { |
| 317 | + setCustomJobParam(jobWrapper, QDMI_JOB_PARAMETER_CUSTOM2, *custom2); |
| 318 | + } |
| 319 | + if (custom3.has_value()) { |
| 320 | + setCustomJobParam(jobWrapper, QDMI_JOB_PARAMETER_CUSTOM3, *custom3); |
| 321 | + } |
| 322 | + if (custom4.has_value()) { |
| 323 | + setCustomJobParam(jobWrapper, QDMI_JOB_PARAMETER_CUSTOM4, *custom4); |
| 324 | + } |
| 325 | + if (custom5.has_value()) { |
| 326 | + setCustomJobParam(jobWrapper, QDMI_JOB_PARAMETER_CUSTOM5, *custom5); |
| 327 | + } |
| 328 | + |
313 | 329 | qdmi::throwIfError(QDMI_job_submit(jobWrapper), "Submitting job"); |
314 | 330 | return jobWrapper; |
315 | 331 | } |
316 | 332 |
|
| 333 | +void Device::setCustomJobParam(QDMI_Job job, const QDMI_Job_Parameter param, |
| 334 | + const CustomJobParameter& value) { |
| 335 | + std::visit( |
| 336 | + [&]<typename CustomValue>(const CustomValue& customValue) { |
| 337 | + using T = std::decay_t<CustomValue>; |
| 338 | + if constexpr (std::is_same_v<T, std::string>) { |
| 339 | + qdmi::throwIfError(QDMI_job_set_parameter(job, param, |
| 340 | + customValue.size() + 1, |
| 341 | + customValue.c_str()), |
| 342 | + "Setting custom parameter"); |
| 343 | + } else { |
| 344 | + static_assert(std::is_trivially_copyable_v<T>, |
| 345 | + "Custom job parameters must be trivially copyable"); |
| 346 | + qdmi::throwIfError( |
| 347 | + QDMI_job_set_parameter(job, param, sizeof(T), &customValue), |
| 348 | + "Setting custom parameter"); |
| 349 | + } |
| 350 | + }, |
| 351 | + value); |
| 352 | +} |
| 353 | + |
317 | 354 | QDMI_Job_Status Job::check() const { |
318 | 355 | QDMI_Job_Status status{}; |
319 | 356 | qdmi::throwIfError(QDMI_job_check(job_.get(), &status), |
|
0 commit comments