11
$\begingroup$

Qiskit can be used to submit jobs to IBM devices using Python (or Swift and JavaScript). But what if I want to use a different language?

For example, suppose I have a specific circuit I want to run. Assume I've already created it in Python Qiskit, and generated the corresponding qasm string or (ideally) the full qobj object.

I want to be able to run this and get the results back in any language of my choice.

As far as I understand, these is a way to do this via HTML. The information generated in Qiskit can be turned into a JSON, and then submitted over the web. This is the way ProjectQ sends jobs to IBM devices (though they do it in Python).

Since reverse engineering the ProjectQ code is a little daunting, I'd like a simple guide to using this feature. Especially in a language other than Python.

$\endgroup$
2
  • 2
    $\begingroup$ I often answer my own qiskit questions, but I have no easy answers this time! $\endgroup$ Jan 10, 2019 at 22:47
  • $\begingroup$ I answered to a similar question (see my answer). In order to interact with IBM Q Experience without having to install all python modules (with all the dependencies), I wrote some ad-hoc shell aliases relying on curl for submitting such jobs. See ibmq-shell. $\endgroup$ Jun 21, 2020 at 16:00

1 Answer 1

8
$\begingroup$

I will try answering this way but I have not tried it myself. Just reverse engineering reading the code with a few notions of HTML request.

Let us assume in the language of your choice, you have the ability to send HTTP requests via GET and POST methods. The api_url is https://quantumexperience.ng.bluemix.net/api/.

To submit a job, you will send a POST request with some information (like you have filled a form on the web and you want to talk to a server). It is like addressing a server with a dictionary of information. It will be to the link https://quantumexperience.ng.bluemix.net/api/Jobs with the POST request header set as application/json (showing how you submit the information). The information here is submitted in a JSON formatting in the body of the request:

{
   "data": QASM as string or JSON string,

   "params": {"access_token": access_token,
                              "deviceRunType": device,
                              "fromCache": "false",
                              "shots": shots}

}

I guess we can add in params maxCredits and other parameters for submission. device refers to the name of the backend if I follow their comments: simulator, ibmqx4, or ibmqx5. You get an answer back as JSON again with an id argument referring to the execution_id.

Once it is submitted, your job will be in queue. You will have to request by GET this job ID to get the answer from the backend. The GET URL is: https://quantumexperience.ng.bluemix.net/api/Jobs/execution_id. You will get another JSON answer (put it in a r_json variable). If it has the qasms item, see if r_json['qasms'][0] has a result item and you will get the result of the submission.

This should sum up the procedure.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.