|
QDMI v1.4.0
Quantum Device Management Interface
|
Provides functions to manage jobs on a device.
A job is a task submitted to a device for execution. Most jobs are quantum circuits to be executed on a quantum device. However, jobs can also be a different type of task, such as calibration.
The typical workflow for a device job is as follows:
Alternatively, a driver may retrieve a previously submitted job with QDMI_device_session_retrieve_device_job_by_id and continue managing it through the same interface.
Typedefs | |
| typedef struct QDMI_Device_Job_impl_d * | QDMI_Device_Job |
| A handle for a device job. | |
Functions | |
| int | QDMI_device_session_create_device_job (QDMI_Device_Session session, QDMI_Device_Job *job) |
| Create a job. | |
| int | QDMI_device_session_retrieve_device_job_by_id (QDMI_Device_Session session, const char *job_id, QDMI_Device_Job *job) |
| Retrieve an existing device job by its ID. | |
| int | QDMI_device_job_set_parameter (QDMI_Device_Job job, QDMI_Device_Job_Parameter param, size_t size, const void *value) |
| Set a parameter for a job. | |
| int | QDMI_device_job_set_programs (QDMI_Device_Job job, QDMI_Program_Format format, size_t count, const size_t *sizes, const void *const *programs) |
| Set one or more programs for a job. | |
| int | QDMI_device_job_get_program (QDMI_Device_Job job, size_t program_index, size_t size, void *data, size_t *size_ret) |
| Retrieve one program in input order. | |
| int | QDMI_device_job_get_program_status (QDMI_Device_Job job, size_t program_index, QDMI_Job_Status *status) |
| Query the current status of one program in a device job. | |
| int | QDMI_device_job_query_property (QDMI_Device_Job job, QDMI_Device_Job_Property prop, size_t size, void *value, size_t *size_ret) |
| Query a job property. | |
| int | QDMI_device_job_submit (QDMI_Device_Job job) |
| Submit a job to the device. | |
| int | QDMI_device_job_cancel (QDMI_Device_Job job) |
| Cancel an already submitted job. | |
| int | QDMI_device_job_check (QDMI_Device_Job job, QDMI_Job_Status *status) |
| Check the status of a job. | |
| int | QDMI_device_job_wait (QDMI_Device_Job job, size_t timeout) |
| Wait for a job to finish. | |
| int | QDMI_device_job_get_results (QDMI_Device_Job job, size_t program_index, QDMI_Job_Result result, size_t size, void *data, size_t *size_ret) |
| Retrieve one program's results from a job. | |
| void | QDMI_device_job_free (QDMI_Device_Job job) |
| Free a job. | |
| typedef struct QDMI_Device_Job_impl_d* QDMI_Device_Job |
A handle for a device job.
An opaque pointer to a type defined by the device that encapsulates all information about a job on a device.
| int QDMI_device_session_create_device_job | ( | QDMI_Device_Session | session, |
| QDMI_Device_Job * | job ) |
Create a job.
This is the main entry point for a driver to create a job for a device. The returned handle can be used throughout the device job interface to refer to the job.
| [in] | session | The session to create the job on. Must not be NULL. |
| [out] | job | A pointer to a handle that will store the created job. Must not be NULL. The job must be freed by calling QDMI_device_job_free when it is no longer used. |
session or job are NULL. | int QDMI_device_session_retrieve_device_job_by_id | ( | QDMI_Device_Session | session, |
| const char * | job_id, | ||
| QDMI_Device_Job * | job ) |
Retrieve an existing device job by its ID.
Creates a new local device-job handle for the existing remote job identified by job_id. Retrieving a job does not submit, clone, or otherwise modify the remote job. The returned handle can be used to query properties, check or wait for completion, cancel the job, and retrieve results.
The job is accessed with the credentials and configuration of session. The job ID is an identifier, not an authentication credential. Parameters cannot be set on a retrieved job, and a retrieved job cannot be submitted again. The device must reconstruct the program count and input-to-result mapping. If historical input metadata is unavailable, queries for the original format or program bytes may return QDMI_ERROR_NOTSUPPORTED without preventing retrieval.
| [in] | session | The initialized session with which to retrieve the job. Must not be NULL. |
| [in] | job_id | The nonempty, null-terminated ID returned by QDMI_DEVICE_JOB_PROPERTY_ID. Must not be NULL. |
| [out] | job | A pointer to a handle that will store the retrieved job. Must not be NULL. The handle must be freed by calling QDMI_device_job_free when it is no longer used. |
session, job_id, or job is NULL, or if job_id is empty. job_id exists. session is not initialized. session is not permitted to access the job. | int QDMI_device_job_set_parameter | ( | QDMI_Device_Job | job, |
| QDMI_Device_Job_Parameter | param, | ||
| size_t | size, | ||
| const void * | value ) |
Set a parameter for a job.
| [in] | job | A handle to a job for which to set param. Must not be NULL. |
| [in] | param | The parameter whose value will be set. Must be one of the values specified for QDMI_Device_Job_Parameter. |
| [in] | size | The size of the data pointed to by value in bytes. Must not be zero, except when value is NULL, in which case it is ignored. |
| [in] | value | A pointer to the memory location that contains the value of the parameter to be set. The data pointed to by value is copied and can be safely reused after this function returns. If this is NULL, it is ignored. |
param and, when value is not NULL, the parameter was successfully set. job is NULL,param is invalid, orvalue is not NULL and size is zero or not the expected size for the parameter (if specified by the QDMI_Device_Job_Parameter documentation). By calling this function with value set to NULL, the function can be used to check if the device supports the specified parameter without setting the parameter and without the need to provide a value.
For example, to check whether the device supports setting the number of shots for a quantum circuit job, the following code pattern can be used:
| int QDMI_device_job_set_programs | ( | QDMI_Device_Job | job, |
| QDMI_Program_Format | format, | ||
| size_t | count, | ||
| const size_t * | sizes, | ||
| const void *const * | programs ) |
Set one or more programs for a job.
All programs use the same format and the same job parameters, including the shot count. On success, the device replaces the complete program list with a deep copy of sizes and the program bytes. If validation or copying fails, the existing program list remains unchanged. A device that accepts a list must report its size through QDMI_DEVICE_JOB_PROPERTY_PROGRAMSNUM and expose each result through QDMI_device_job_get_results. A result's index equals its input program's index; execution order is unspecified. The list has one ID, status, wait operation, and cancellation operation. The job reaches QDMI_JOB_STATUS_DONE only after all programs succeed. Failed or canceled jobs become terminal only after all programs have stopped. Optional per-program outcomes are available through QDMI_device_job_get_program_status; results of successful programs remain accessible when other programs fail or are canceled.
| [in] | job | A handle to the job. Must not be NULL. |
| [in] | format | The exact format of every program. Must be a valid QDMI_Program_Format, including for a single program. |
| [in] | count | The number of programs. Must be greater than zero. A support check succeeds only if the device supports this exact cardinality with the configured job parameters. |
| [in] | sizes | An array of count program sizes in bytes. Must not be NULL and each size must be greater than zero when programs is not NULL. A text program contains exactly one '\0' as its final byte. Binary programs are arbitrary nonempty byte sequences. When programs is NULL, sizes is ignored. |
| [in] | programs | An array of count program pointers. When the array is not NULL, each pointer must not be NULL. The device copies all input data before returning. If the array is NULL, the function checks support for the format and cardinality without changing the job. |
format and, when programs is not NULL, set the complete list. job is NULL, count is zero, or format is not valid, orprograms is not NULL, and sizes is NULL, an element of programs is NULL, an element of sizes is zero, or a text program does not contain exactly one trailing '\0'. | int QDMI_device_job_get_program | ( | QDMI_Device_Job | job, |
| size_t | program_index, | ||
| size_t | size, | ||
| void * | data, | ||
| size_t * | size_ret ) |
Retrieve one program in input order.
The returned bytes include the terminating NUL for text formats. A retrieved job may return QDMI_ERROR_NOTSUPPORTED when its original program bytes are unavailable. The program count is reported by QDMI_DEVICE_JOB_PROPERTY_PROGRAMSNUM.
| [in] | job | The job to query. Must not be NULL. |
| [in] | program_index | The zero-based program index. |
| [in] | size | The size of data in bytes. Ignored if data is NULL. |
| [out] | data | The buffer for the program bytes, or NULL for a size query. |
| [out] | size_ret | The required buffer size, or NULL. |
data is NULL. program_index is out of range. job is NULL or data is non-NULL and size is too small. | int QDMI_device_job_get_program_status | ( | QDMI_Device_Job | job, |
| size_t | program_index, | ||
| QDMI_Job_Status * | status ) |
Query the current status of one program in a device job.
Individual outcomes are optional. Once reached, a program's terminal status cannot change. An out-of-range index returns QDMI_ERROR_OUTOFRANGE even if individual outcomes are unsupported; results of successful programs remain available when siblings fail or are canceled. A temporary retrieval failure is an error, not QDMI_ERROR_NOTSUPPORTED.
| [in] | job | The job to query. Must not be NULL. |
| [in] | program_index | The zero-based input program index. |
| [out] | status | The program status. Must not be NULL when individual outcomes are supported. An implementation that always returns QDMI_ERROR_NOTSUPPORTED need not inspect this pointer. |
program_index is out of range. job is NULL, or if individual outcomes are supported and status is NULL. | int QDMI_device_job_query_property | ( | QDMI_Device_Job | job, |
| QDMI_Device_Job_Property | prop, | ||
| size_t | size, | ||
| void * | value, | ||
| size_t * | size_ret ) |
Query a job property.
| [in] | job | A handle to a job for which to query prop. Must not be NULL. |
| [in] | prop | The property to query. Must be one of the values specified for QDMI_Device_Job_Property. |
| [in] | size | The size of the memory pointed to by value in bytes. Must be greater or equal to the size of the return type specified for prop, except when value is NULL, in which case it is ignored. |
| [out] | value | A pointer to the memory location where the value of the property will be stored. If this is NULL, it is ignored. |
| [out] | size_ret | The actual size of the data being queried in bytes. If this is NULL, it is ignored. |
value is not NULL, the property was successfully retrieved. job is NULL,prop is invalid, orvalue is not NULL and size is less than the size of the data being queried. By calling this function with value set to NULL, the function can be used to check if the job supports the specified property without retrieving the property and without the need to provide a buffer for it. Additionally, the size of the buffer needed to retrieve the property is returned in size_ret if size_ret is not NULL.
For example, to query the ID of a job, the following code pattern can be used:
| int QDMI_device_job_submit | ( | QDMI_Device_Job | job | ) |
Submit a job to the device.
This function can either be blocking until the job is finished or non-blocking and return while the job is running. In the latter case, the functions QDMI_device_job_check and QDMI_device_job_wait can be used to check the status and wait for the job to finish.
| [in] | job | The job to submit. Must not be NULL. |
job is NULL. | int QDMI_device_job_cancel | ( | QDMI_Device_Job | job | ) |
Cancel an already submitted job.
Remove the job from the queue of waiting jobs. This changes the status of the job to QDMI_JOB_STATUS_CANCELED.
| [in] | job | The job to cancel. Must not be NULL. |
job is NULL or the job already has the status QDMI_JOB_STATUS_DONE. | int QDMI_device_job_check | ( | QDMI_Device_Job | job, |
| QDMI_Job_Status * | status ) |
Check the status of a job.
This function is non-blocking and returns immediately with the job status. It is not required to call this function before calling QDMI_device_job_get_results.
| [in] | job | The job to check the status of. Must not be NULL. |
| [out] | status | The status of the job. Must not be NULL. |
job or status is NULL. | int QDMI_device_job_wait | ( | QDMI_Device_Job | job, |
| size_t | timeout ) |
Wait for a job to finish.
This function blocks until the job reaches QDMI_JOB_STATUS_DONE, QDMI_JOB_STATUS_CANCELED, or QDMI_JOB_STATUS_FAILED, or until the timeout is reached. Call QDMI_device_job_check after a successful wait to distinguish terminal states. If timeout is not zero, this function returns latest after the specified number of seconds.
| [in] | job | The job to wait for. Must not be NULL. |
| [in] | timeout | The timeout in seconds. If this is zero, the function waits indefinitely for a terminal state. |
job is NULL. timeout is not zero and the job did not reach a terminal state within the specified time. | int QDMI_device_job_get_results | ( | QDMI_Device_Job | job, |
| size_t | program_index, | ||
| QDMI_Job_Result | result, | ||
| size_t | size, | ||
| void * | data, | ||
| size_t * | size_ret ) |
Retrieve one program's results from a job.
Results are available when the selected program has succeeded, even if other programs are still running, failed, or canceled. Devices exposing only aggregate outcomes provide results after the job reaches QDMI_JOB_STATUS_DONE.
| [in] | job | The job to retrieve the results from. Must not be NULL. |
| [in] | program_index | The zero-based program index. Must be less than QDMI_DEVICE_JOB_PROPERTY_PROGRAMSNUM. |
| [in] | result | The result to retrieve. Must be one of the values specified for QDMI_Job_Result. |
| [in] | size | The size of the buffer pointed to by data in bytes. Must be greater than or equal to the size of the requested result, except when data is NULL, in which case it is ignored. |
| [out] | data | The buffer in which to store the result. If this is NULL, it is ignored. |
| [out] | size_ret | The required buffer size in bytes. If this is NULL, it is ignored. |
data is not NULL, retrieved it successfully. program_index is greater than or equal to the number of programs in the job. job is NULL,result is invalid, ordata is not NULL and size is too small. Calling this function with data set to NULL checks support and returns the required buffer size in size_ret when it is not NULL.
For example, to query the first program's measurement results:
| void QDMI_device_job_free | ( | QDMI_Device_Job | job | ) |
Free a job.
Free the resources associated with a job. Using a job handle after it was freed is undefined behavior. Freeing a job handle does not necessarily cancel or delete the underlying job; this behavior is device-specific.
| [in] | job | The job to free. |