QDMI Devices v0.1
Quantum Device Management Interface Devices
|
The QDMI Device implementation of the Qaptiva Device at Leibniz Supercomputing Centre.
Qaptiva enables enterprises and institutions to anticipate the availability of advanced quantum computers and implement real-world use cases by harnessing innovation through quantum computing technology. This device implementation allows a QDMI Client
to submit quantum job, query the device information.
Classes | |
struct | QAPTIVA_QDMI_Device_Session_impl_t |
The implementation of the encapsulated type QDMI_Device_Session on the device-side. More... | |
struct | QAPTIVA_QDMI_Device_Job_impl_t |
Device-side implementation of the encapsulated type QDMI_Device_Job . More... | |
struct | QAPTIVA_QDMI_Site_impl_t |
The implementation of the encapsulated type QDMI_Site on the device-side. More... | |
Macros | |
#define | SCRIPT_LOCATION "QLM_AUXILIARY_SCRIPT_LOCATION" |
The definition for the auxiliary script's location. | |
#define | SCRIPT_NAME "QLM_AUXILIARY_SCRIPT_NAME" |
The file name of the auxiliary script. | |
#define | REMOTE_QPU_CREATE_FUNCTION_NAME "create_remote_qpu" |
The name of the function that used to create remote qpu. | |
#define | SUBMIT_JOB_FUNCTION_NAME "submit_job" |
The name of the function that used to submit quantum job. | |
#define | DEFAULT_NUM_SHOT 0 |
The default number of the shot for a quantum job. | |
#define | ADD_STRING_PROPERTY(prop_name, prop_value, prop, size, value, size_ret) |
Adds a string property to the device. | |
#define | ADD_SINGLE_VALUE_PROPERTY(prop_name, prop_type, prop_value, prop, size, value, size_ret) |
Adds a primitive typed value property to the device. | |
#define | ADD_LIST_PROPERTY(prop_name, prop_type, prop_values, prop_length, prop, size, value, size_ret) |
Adds a list typed value property to the device. | |
#define | CHECK_PYTHON_ERROR(value, from_python) |
Checks if there is a Python related error. | |
#define | CHECK_QDMI_ERROR(value) |
Checks whether the value is QDMI_SUCCESS . | |
#define | GET_VALUE_DATA(type, multiplier) |
Writes and casts results to the data_ptr | |
Enumerations | |
enum | QAPTIVA_QDMI_DEVICE_SESSION_STATUS { ALLOCATED , INITIALIZED } |
Enum of the session status that can be set internally. More... | |
Functions | |
static QDMI_Device_Status * | QAPTIVA_QDMI_get_device_status (void) |
Static function to maintain the device status. | |
QDMI_Device_Status | QAPTIVA_QDMI_read_device_status (void) |
The local function to read the device status. | |
void | QAPTIVA_QDMI_set_device_status (QDMI_Device_Status status) |
The local function to set the device status. | |
static int * | isFromPython (void) |
Static function to check if the driver is written in Python. | |
static PyObject ** | get_remote_qpu (void) |
Static function to get the remote qpu . | |
static PyObject ** | get_custom_python_module (void) |
Static function to get the auxiliary Python Module. | |
int | QAPTIVA_QDMI_device_session_query_operation_property (QAPTIVA_QDMI_Device_Session session, QAPTIVA_QDMI_Operation operation, const size_t num_sites, const QAPTIVA_QDMI_Site *sites, const size_t num_params, const double *params, const QDMI_Operation_Property prop, const size_t size, void *value, size_t *size_ret) |
Queries a operation property. | |
int | QAPTIVA_QDMI_device_session_query_device_property (QAPTIVA_QDMI_Device_Session session, const QDMI_Device_Property prop, const size_t size, void *value, size_t *size_ret) |
Queries the device's properties. | |
int | QAPTIVA_QDMI_device_session_query_site_property (QAPTIVA_QDMI_Device_Session session, QAPTIVA_QDMI_Site site, const QDMI_Site_Property prop, const size_t size, void *value, size_t *size_ret) |
Query a site property. | |
int | QAPTIVA_QDMI_device_session_create_device_job (QAPTIVA_QDMI_Device_Session session, QAPTIVA_QDMI_Device_Job *job) |
Create a job. | |
int | QAPTIVA_QDMI_device_job_set_parameter (QAPTIVA_QDMI_Device_Job job, const QDMI_Device_Job_Parameter param, const size_t size, const void *value) |
Set a parameter for a job. | |
int | submit_job (QAPTIVA_QDMI_Device_Job job) |
An auxiliary function for submitting job. | |
int | QAPTIVA_QDMI_device_job_submit (QAPTIVA_QDMI_Device_Job job) |
Submit a job to the device. | |
int | QAPTIVA_QDMI_device_job_cancel (QAPTIVA_QDMI_Device_Job job) |
Cancel an already created job. | |
int | QAPTIVA_QDMI_device_job_check (QAPTIVA_QDMI_Device_Job job, QDMI_Job_Status *status) |
Check the status of a job. | |
int | QAPTIVA_QDMI_device_job_wait (QAPTIVA_QDMI_Device_Job job, size_t timeout) |
Wait for a job to finish. | |
int | QAPTIVA_QDMI_device_job_get_results (QAPTIVA_QDMI_Device_Job job, QDMI_Job_Result result, size_t size, void *data, size_t *size_ret) |
Retrieve the results of a job. | |
void | QAPTIVA_QDMI_device_job_free (QAPTIVA_QDMI_Device_Job job) |
Free a job. | |
int | QAPTIVA_QDMI_device_job_query_property (QAPTIVA_QDMI_Device_Job job, QDMI_Device_Job_Property prop, size_t size, void *value, size_t *size_ret) |
Query a job property. | |
int | initialize_python (void) |
Initializes the Python interpreter. | |
int | create_remote_qpu (const char *hostname) |
Connects to the remote qpu. | |
int | check_env_variable (void) |
Checks if the required environment variables are set. | |
int | QAPTIVA_QDMI_device_initialize (void) |
Initializes the device. | |
int | QAPTIVA_QDMI_device_finalize (void) |
Finalizes the device. | |
int | QAPTIVA_QDMI_device_session_alloc (QAPTIVA_QDMI_Device_Session *session) |
Allocates a new device session. | |
int | QAPTIVA_QDMI_device_session_init (QAPTIVA_QDMI_Device_Session session) |
Initializes a device session. | |
void | QAPTIVA_QDMI_device_session_free (QAPTIVA_QDMI_Device_Session session) |
Free a QDMI device session. | |
int | QAPTIVA_QDMI_device_session_set_parameter (QAPTIVA_QDMI_Device_Session session, const QDMI_Device_Session_Parameter param, const size_t size, const void *value) |
Set a parameter for a device session. | |
Variables | |
const QAPTIVA_QDMI_Site | DEVICE_SITES [] |
The array of the sites. | |
#define SCRIPT_LOCATION "QLM_AUXILIARY_SCRIPT_LOCATION" |
The definition for the auxiliary script's location.
QLM_AUXILIARY_SCRIPT_LOCATION
is an environment variable that corresponse to location of the qlm_auxiliary.py
. In this project, it should be {PROJECT_SOURCE_DIR}/src/eviden/
#define SCRIPT_NAME "QLM_AUXILIARY_SCRIPT_NAME" |
The file name of the auxiliary script.
QLM_AUXILIARY_SCRIPT_NAME
is an environment variable that corresponse to the file name of the auxiliary script. In this project, it should be qlm_auxiliary
#define ADD_STRING_PROPERTY | ( | prop_name, | |
prop_value, | |||
prop, | |||
size, | |||
value, | |||
size_ret ) |
Adds a string property to the device.
This macro copies the value of the prop_value
to the value
if prop_name
and the prop
matches. If specified, the required size is written in size_ret
.
prop_name | The name of the property |
prop_value | The string value of the property (char* ) |
prop | The property name passed as input |
size | The size of the memory pointed to by value . |
value | Pointer to the memory location where prop_value will be copied. |
size_ret | If specified, the required size is written. |
size
is not sufficient, QDMI_ERROR_INVALIDARGUMENT#define ADD_SINGLE_VALUE_PROPERTY | ( | prop_name, | |
prop_type, | |||
prop_value, | |||
prop, | |||
size, | |||
value, | |||
size_ret ) |
Adds a primitive typed value property to the device.
This macro copies the value of the prop_value
to the value
if prop_name
and the prop
matches. If specified, the required size is written in size_ret
.
prop_name | The name of the property |
prop_type | The type of the property, i.e, char , ìnt . |
prop_value | The value of the property. |
prop | The property name passed as input |
size | The size of the memory pointed to by value . |
value | Pointer to the memory location where prop_value will be copied. |
size_ret | If specified, the required size is written. |
size
is not sufficient, QDMI_ERROR_INVALIDARGUMENT#define ADD_LIST_PROPERTY | ( | prop_name, | |
prop_type, | |||
prop_values, | |||
prop_length, | |||
prop, | |||
size, | |||
value, | |||
size_ret ) |
Adds a list typed value property to the device.
This macro copies the value of the prop_value
to the value
if prop_name
and the prop
matches. If specified, the required size is written in size_ret
.
prop_name | The name of the property |
prop_type | The type of the property, i.e, double , ìnt . |
prop_values | The values of the property. |
prop | The property name passed as input |
size | The size of the memory pointed to by value . |
value | Pointer to the memory location where prop_value will be copied. |
size_ret | If specified, the required size is written. |
size
is not sufficient, QDMI_ERROR_INVALIDARGUMENT#define CHECK_PYTHON_ERROR | ( | value, | |
from_python ) |
Checks if there is a Python related error.
This macro checks whether the value
is NULL
or Py_None
. If it is, it returns the ret_val
.
value | The value to be checked |
from_python | True means that the QDMI_Driver that initiate the device is written in Python. Therefore, we don't need to release the GIL. |
value
is NULL
or Py_None
, it returns the ret_val
#define CHECK_QDMI_ERROR | ( | value | ) |
Checks whether the value
is QDMI_SUCCESS
.
value | The value to be checked |
value
if it is not QDMI_SUCCESS
#define GET_VALUE_DATA | ( | type, | |
multiplier ) |
Writes and casts results to the data_ptr
type | The type to results will be cast. |
multiplier | The value that results will be multiplied by |
|
static |
Static function to maintain the device status.
QDMI_Device_Status QAPTIVA_QDMI_read_device_status | ( | void | ) |
The local function to read the device status.
void QAPTIVA_QDMI_set_device_status | ( | QDMI_Device_Status | status | ) |
The local function to set the device status.
status | the new device status. |
|
static |
Static function to check if the driver is written in Python.
|
static |
Static function to get the remote qpu
.
The remote qpu
is created while initialting the session and re-used while submitting jobs.
remote qpu
pointer if it is created. Otherwise, NULL;
|
static |
Static function to get the auxiliary Python Module.
The auxiliary Python Module is frequintly used thoughtout the backend after it is imported while initialting the session.
custom python module
pointer if it is created. Otherwise, NULL; int QAPTIVA_QDMI_device_session_query_operation_property | ( | QAPTIVA_QDMI_Device_Session | session, |
QAPTIVA_QDMI_Operation | operation, | ||
const size_t | num_sites, | ||
const QAPTIVA_QDMI_Site * | sites, | ||
const size_t | num_params, | ||
const double * | params, | ||
const QDMI_Operation_Property | prop, | ||
const size_t | size, | ||
void * | value, | ||
size_t * | size_ret ) |
Queries a operation property.
Since it is a emulator, there is no native gate set.
[in] | session | The session used for the query. |
[in] | operation | The operation to query. |
[in] | num_sites | The number of sites that the operation is applied to. |
[in] | sites | A pointer to a list of handles where the sites that the operation is applied to are stored. |
[in] | num_params | The number of parameters that the operation takes. |
[in] | params | A pointer to a list of parameters the operation takes. |
[in] | prop | The property to query. |
[in] | size | The size of the memory pointed to by value in bytes. |
[out] | value | A pointer to the memory location where the value of the property will be stored. |
[out] | size_ret | The actual size of the data being queried in bytes. |
int QAPTIVA_QDMI_device_session_query_device_property | ( | QAPTIVA_QDMI_Device_Session | session, |
const QDMI_Device_Property | prop, | ||
const size_t | size, | ||
void * | value, | ||
size_t * | size_ret ) |
Queries the device's properties.
[in] | session | The session used for the query. Must not be NULL . |
[in] | prop | The property to query. Must be one of the values specified for QDMI_Device_Property. |
[in] | size | The size of the memory is 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. session
is NULL
,prop
is invalid, orvalue
is not NULL
and the size
is less than the size of the data being queried. int QAPTIVA_QDMI_device_session_query_site_property | ( | QAPTIVA_QDMI_Device_Session | session, |
QAPTIVA_QDMI_Site | site, | ||
const QDMI_Site_Property | prop, | ||
const size_t | size, | ||
void * | value, | ||
size_t * | size_ret ) |
Query a site property.
The Qaptiva device's QDMI_Site
s only has indexes. Therefore, only their indexes can be queried.
[in] | session | The session used for the query. Must not be NULL . |
[in] | site | The site to query. Must not be NULL . |
[in] | prop | The property to query. Must be one of the values specified for QDMI_Site_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. session
or site
is NULL
,prop
is invalid, orvalue
is not NULL
and size
is less than the size of the data being queried. int QAPTIVA_QDMI_device_session_create_device_job | ( | QAPTIVA_QDMI_Device_Session | session, |
QAPTIVA_QDMI_Device_Job * | job ) |
Create a job.
This is the main entry point for a driver to create a job for a device. After the required memory is allocated, the job is initiaited
[in] | session | The session to create the job on. |
[out] | job | A pointer to a handle that will store the created job. The job must be freed by calling QAPTIVA_QDMI_device_job_free when it is no longer used. |
session
or job
are NULL
.int QAPTIVA_QDMI_device_job_set_parameter | ( | QAPTIVA_QDMI_Device_Job | job, |
const QDMI_Device_Job_Parameter | param, | ||
const 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).int submit_job | ( | QAPTIVA_QDMI_Device_Job | job | ) |
An auxiliary function for submitting job.
[in] | job | A handle to a job to be submitted |
To submit a job this device, we need to use Qaptiva's Python Package named myQLM. Therefore, this function calls the submit_job
from the qlm_auxiliary
to submit the given job.
int QAPTIVA_QDMI_device_job_submit | ( | QAPTIVA_QDMI_Device_Job | job | ) |
Submit a job to the device.
To submit a job this device, we need to use Qaptiva's Python Package named myQLM. The out-of-the box job submission function is a blocking-function that waits
[in] | job | The job to submit. Must not be NULL . |
job
is NULL
. int QAPTIVA_QDMI_device_job_cancel | ( | QAPTIVA_QDMI_Device_Job | job | ) |
Cancel an already created job.
The submitted jobs cannot be canceled due to nature of the device. Therefore, we can only cancel the created jobs.
[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 QAPTIVA_QDMI_device_job_check | ( | QAPTIVA_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.
[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 QAPTIVA_QDMI_device_job_wait | ( | QAPTIVA_QDMI_Device_Job | job, |
size_t | timeout ) |
Wait for a job to finish.
Since QAPTIVA_QDMI_device_job_submit is a blocking function, this function makes sure that status is set to QDMI_JOB_STATUS_DONE.
[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 until the job has finished. |
job
is NULL
. int QAPTIVA_QDMI_device_job_get_results | ( | QAPTIVA_QDMI_Device_Job | job, |
QDMI_Job_Result | result, | ||
size_t | size, | ||
void * | data, | ||
size_t * | size_ret ) |
Retrieve the results of a job.
The QLM device returns the results as a state-probability pair. Therefore, this function provides the probability values, keys, and density, as well as the histogram keys and values, which are calculated by multiplying the probability values by the number of shots.
[in] | job | The job to retrieve the results from. Must not be NULL . |
[in] | result | The result to retrieve. Must be one of the values specifie for QDMI_Job_Result |
[in] | size | The size of the buffer pointed to by data in bytes. Must be greater or equal to the size of the return type specified for the QDMI_Job_Result result , except when data is NULL , in which case it is ignored. |
[out] | data | A pointer to the memory location where the results 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. |
data
is not NULL
, the results were successfully retrieved. job
is NULL
,job
has not completed,result
is invalid, ordata
is not NULL
and size
is smaller than the size of the data being queried. void QAPTIVA_QDMI_device_job_free | ( | QAPTIVA_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.
[in] | job | The job to free. |
int QAPTIVA_QDMI_device_job_query_property | ( | QAPTIVA_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 a href="https://munich-quantum-software-stack.github.io/QDMI/constants_8h.html#a6e4d18c7fa5d383bbcc1498abe090d4f">QDMI_Device_Job_Property result , except when data is NULL , in which case it is ignored.. |
[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. int initialize_python | ( | void | ) |
Initializes the Python interpreter.
Since we are obligated to use myQLM Python package, we need to initialize the interpreter. However, if the library is used by a Python based client, the interpreter does not need to be initialized.
This function initializes the Python interpreter and imports the custom auxiliary module which is named qlm_auxiliary.py by default. The module is used in create_remote_qpu and submit_job.
int create_remote_qpu | ( | const char * | hostname | ) |
Connects to the remote qpu.
This function is connects to the remote qpu by using the create_remote_qpu function from the qlm_auxiliary.
[in] | hostname | The name of the host where the device is located. Must be in the form "host:port". |
int check_env_variable | ( | void | ) |
Checks if the required environment variables are set.
Two environment variables needs to be set to locate the custom auxiliary module: SCRIPT_LOCATION indicates the location of the file and SCRIPT_NAME indicates the name of the file.
int QAPTIVA_QDMI_device_initialize | ( | void | ) |
Initializes the device.
This function check if the required environment variables are set and the Python interpreter can be initialized.
int QAPTIVA_QDMI_device_finalize | ( | void | ) |
Finalizes the device.
This function finalizes the device by freeing the custom module, and finalizesthe Python interpreter.
int QAPTIVA_QDMI_device_session_alloc | ( | QAPTIVA_QDMI_Device_Session * | session | ) |
Allocates a new device session.
[out] | session | A handle to the session that is allocated. Must not be NULL . |
session
is NULL
. int QAPTIVA_QDMI_device_session_init | ( | QAPTIVA_QDMI_Device_Session | session | ) |
Initializes a device session.
This function initializes the device session and prepares it for use based on the set parameters.
[out] | session | A handle to the session that is allocated. |
session
is NULL
. void QAPTIVA_QDMI_device_session_free | ( | QAPTIVA_QDMI_Device_Session | session | ) |
Free a QDMI device session.
[in] | session | The session to free. |
int QAPTIVA_QDMI_device_session_set_parameter | ( | QAPTIVA_QDMI_Device_Session | session, |
const QDMI_Device_Session_Parameter | param, | ||
const size_t | size, | ||
const void * | value ) |
Set a parameter for a device session.
[in] | session | A handle to the session to set the parameter for. |
[in] | param | The parameter to set. Must be one of the values specified for QDMI_Device_Session_Parameter. |
[in] | size | The size of the data pointed by value in bytes. |
[in] | value | A pointer to the memory location that contains the value of the parameter to be set. |
value
is not NULL
, the value of the parameter was set successfully. session
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_Session_Parameter documentation). const QAPTIVA_QDMI_Site DEVICE_SITES[] |
The array of the sites.