I have, let's say, the following quantum circuit:

enter image description here

The QASM code of this quantum scheme has the following form:

include "qelib1.inc";

qreg q[5];
creg c[5];

reset q[0];
reset q[1];
reset q[2];
reset q[3];
reset q[4];
x q[0];
x q[1];
x q[2];
x q[3];
x q[4];
measure q[0] -> c[0];
measure q[1] -> c[1];
measure q[2] -> c[2];
measure q[3] -> c[3];
measure q[4] -> c[4];

I want to send the QASM code to IBM and get the result. In our case, I want to get [1, 1, 1, 1, 1].

I don't understand which endpoints I should send my requests to (probably POST requests) and what I should pass in the message body (in the JSON object).

I was able to execute a GET request to log in and get my access token (access ID). But I don't know what to do next.

There is no complete documentation for the API. Here is what is available now.

In what form I would like to see the answer (here I show how to log in and get an access token):

First step: get an access token.

HTTP request method: POST
Endpoint: https://api.quantum-computing.ibm.com/v2/users/loginWithToken
JSON request:  {
                  "apiToken": "YOUR_API_TOKEN"

JSON response: {
                  "id": "YOUR_ACCESS_ID_TOKEN",
                  "ttl": "YOUR_ACCESS_ID_TOKEN_LIFETIME",
                  "created": "YOUR_ACCESS_ID_TOKEN_CREATIONDATE",
                  "userId": "YOUR_USER_ID"

Second step: I can't figure out which requests to send next to execute my QASM code and get the result [1, 1, 1, 1, 1].

  • $\begingroup$ Is using Qiskit an option? If yes sending jobs is a piece of cake :) $\endgroup$ – Cryoris Jun 2 at 15:43
  • $\begingroup$ @Cryoris This is really easy to do with Qiskit. But in this study, I need to use the IBM API, which I gave a link to in the question text. $\endgroup$ – alexhak Jun 2 at 15:49

The only API documentation available is the one you linked to. Its documentation page describes the steps needed to submit a job (although not in great details). However, you'll first need to convert your QASM string to a qObject, which is the format the API accepts. Assuming Qiskit is allowed for this part, you can first use QuantumCircuit.from_qasm_str() to convert the string to a QuantumCircuit then use assemble() to convert it to a qObject (also called Qobj). If you can't use Qiskit, you'll have to construct the Qobj manually (or using another package that's allowed), following its schema.

Once you have the Qobj, the steps to submit the job are

  1. POST to the /Network/{hubName}/Groups/{groupName}/Projects/{projectName}/Jobs endpoint to create a remote job
  2. PUT the Qobj to the URL returned by step 1
  3. POST to /Network/{hubName}/Groups/{groupName}/Projects/{projectName}/Jobs/{jobId}/jobDataUploaded to finish the job submit.

You might want to also take a look at how it's implemented in Qiskit.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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