Skip to content

Latest commit

 

History

History
127 lines (98 loc) · 4.77 KB

workflow_IBM_Quantum_Platform.md

File metadata and controls

127 lines (98 loc) · 4.77 KB

Recommended workflow for IBM Quantum Platform (IQP) APIs

(Optional) Get temporary Access token from Auth API via API Token

This is especially useful if you would like control over tokens, such as token invalidation

curl -H "Content-Type: application/json" -d "{\"apiToken\": \"$token\"}" "https://auth.quantum-computing.ibm.com/api/users/loginWithToken"

Prepare a job and (qasm) circuit to run

  • Define a QASM quantum circuit e.g.
qasm_string=''OPENQASM 3; \
include "stdgates.inc"; \
qreg q[1]; \
creg c[1]; \
x q[0]; \
c[0] = measure q[0]; ''

Transpilation

The circuit provided will need to be mapped to instructions fitting to the hardware basis instructions of the QPU, which is a process known as Transpilation

curl -X POST \
  "https://cloud-transpiler.quantum.ibm.com/transpile" \
  -H 'accept: application/json' \
  -H 'authorization: Bearer '$token \
  -d '{
    "qasm_circuits": "'$qasm_string'",
    "backend": "ibm_peekskill",
    "optimization_level": 3,
    "use_ai": false
     }'

Request the results using the task_id

curl -X GET \
  "https://cloud-transpiler.quantum.ibm.com/transpile/${task_id}" \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer '$token

Run job via Runtime API

  • Make a POST request to 'https://api.quantum-computing.ibm.com/runtime/jobs' with the following headers:     
    • 'Content-Type: application/json'     

    • 'x-access-token' with the access token obtained above

    • 'x-qx-client-application: qiskit-version-2/0.39.2/'+'your_application' specifying the application you might be running from. For an actual Integration project, this option it is invaluable to know where jobs are coming from. At this time the "qiskit-version-2/0.39.2/" string is a necessary prefix.

    • Include a JSON payload with the following

      • 'program_id': 'sampler'/’estimator’,"backend": …, "hub": …, "group": …, "project": …, "params": {"circuits": [resulting_qasm]} with the qasm that the transpilation Service outputs
curl -X POST \
  "https://api.quantum-computing.ibm.com/runtime/jobs" \
  -H 'Content-Type: application/json' \
  -H 'x-access-token: '$api_key \
  -H 'x-qx-client-application: qiskit-version-2/0.39.2/your_application' \
  -d '{
    "program_id": "sampler",
    "backend": "ibm_peekskill",
    "hub": "ibm-q-internal",
    "group": "dev-sys-software",
    "project": "internal-test",
    "start_session": "False",
    "params": {"circuits": "'$resulting_qasm'"}
    }'

(optional) Create Session

c.f. documentation at https://docs.quantum.ibm.com/api/runtime

curl -X POST "https://api.quantum-computing.ibm.com/runtime/sessions" \
  -H 'Accept: application/json' \
  -H 'x-access-token: '$api_key \
  -H 'Content-Type: application/json' \
  -d '{
    "backend": "ibm_peekskill",
    "instance": "ibm-q-internal/dev-sys-software/internal-test"
}'

Submit job(s) against resulting Session ID

curl -H 'Content-Type: application/json' -H "x-access-token: $auth_id" -H 'x-qx-client-application: qiskit-version-2/0.39.2/YOUR_APPlication' -d '{"program_id": "sampler","backend": "ibm_cusco","hub": "ibm-q-internal","group": "dev-sys-software","project": "internal-test","session_id": "YOUR_SESSION_ID","params": {"circuits": "OPENQASM 3;include \"stdgates.inc\";qreg q[1];creg c[1];x q[0];c[0] = measure q[0];"}}' 'https://api.quantum-computing.ibm.com/runtime/jobs'

Wait for results, check job status

After submitting the job, the status can be checked using the job_id.

curl -H "x-access-token: $auth_id" 'https://api.quantum-computing.ibm.com/runtime/jobs/'$job_id

The status of the job can be either “Queued“, “Running“, “Completed“ or ”Failed”.

Get results  

curl -H "x-access-token: $auth_id" 'https://api.quantum-computing.ibm.com/runtime/jobs/'$job_id'/results'

Invalidate Token (Optional)   

curl -H "x-access-token: $auth_id" 'https://auth.quantum-computing.ibm.com/api/users/logout'