Transpiler methods
Qiskit & AI transpiler methods
Transpile circuits
Transpile abstract circuits into a circuit that obeys the backend's instruction set architecture (ISA), either using Qiskit SDK or AI-powered transpilation. Returns a task ID; use the '/transpile/{taskId}' endpoint to get the result.
Query Parameters
Name, Type | Description |
---|---|
backend string | The name of the backend to transpile the circuit for. Refer to https://docs.quantum.ibm.com/run/get-backend-information. If not specified, you must specify `backend_coupling_map` in the request body. Example: "ibm_kyoto" |
optimization_level integer | How much to optimize the circuit. Refer to https://docs.quantum.ibm.com/transpile/set-optimization Default value: 3 |
use_ai boolean | Deprecated: Use the `ai` parameter instead. |
ai string | Whether to use the Qiskit SDK transpile function, the AI-powered features, or let the service to select the best method. Possible values: true false auto Default value: auto |
ai_layout_mode string | Specifies how to handle the layout selection Possible values: keep optimize improve Default value: optimize |
use_fractional_gates boolean | Wether to use fractional gates or not in the transpilation process Default value: false |
Body Parameters (application/json)
Name, Type | Description |
---|---|
qasm_circuits Required string[] | string | One or more OpenQASM circuits to transpile. Both OpenQASM 2 and OpenQASM 3 are supported. Example: ["OPENQASM 3; include \"stdgates.inc\"; bit[2] meas; qubit[2] q; h q[0]; cx q[0], q[1]; barrier q[0], q[1]; meas[0] = measure q[0]; meas[1] = measure q[1];","OPENQASM 2.0;\ninclude \"qelib1.inc\";\ngate dcx q0,q1 { cx q0,q1; cx q1,q0; }\nqreg q[3];\ncz q[0],q[2];\nsdg q[1];\ndcx q[2],q[1];\nu3(3.890139082217223,3.447697582994976,1.1583481971959322) q[0];\ncrx(2.3585459177723522) q[1],q[0];\ny q[2];"] |
qiskit_transpile_options object | null | Dictionary with inputs to configure the transpile endpoint. Accepts the same inputs as the Qiskit transpile() method https://docs.quantum.ibm.com/api/qiskit/compiler#transpile, except for `circuits` and `backend`. Example: {"basis_gates":["u1","u2","u3","cx"],"seed_transpiler":0} |
backend_coupling_map integer[][] | null | A list of pairs that represents physical links between qubits. Must be specified if the query parameter `backend` is not set. Example: [[1,2],[2,1]] |
optimization_preferences string | string[] | null | Describe your preferences with a value or a list of values when prioritizing optimization. Allowed options: noise, n_cnots, n_gates, cnot_layers, layers. Example: ["noise","n_gates"] Example: "n_cnots" |
HTTP Response Status Codes
Status code | Description |
---|---|
200 | Successful Response |
422 | Validation Error |
Code samples
curl -X POST \
https://cloud-transpiler.quantum.ibm.com/transpile \
-H 'Authorization: Bearer YOUR-TOKEN' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"qasm_circuits":["OPENQASM 3; include \"stdgates.inc\"; bit[2] meas; qubit[2] q; h q[0]; cx q[0], q[1]; barrier q[0], q[1]; meas[0] = measure q[0]; meas[1] = measure q[1];","OPENQASM 2.0;\ninclude \"qelib1.inc\";\ngate dcx q0,q1 { cx q0,q1; cx q1,q0; }\nqreg q[3];\ncz q[0],q[2];\nsdg q[1];\ndcx q[2],q[1];\nu3(3.890139082217223,3.447697582994976,1.1583481971959322) q[0];\ncrx(2.3585459177723522) q[1],q[0];\ny q[2];"]}'
import requests
response = requests.request(
"POST",
"https://cloud-transpiler.quantum.ibm.com/transpile",
headers={
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_TOKEN_HERE"
},
data="{\"qasm_circuits\":[\"OPENQASM 3; include \\\"stdgates.inc\\\"; bit[2] meas; qubit[2] q; h q[0]; cx q[0], q[1]; barrier q[0], q[1]; meas[0] = measure q[0]; meas[1] = measure q[1];\",\"OPENQASM 2.0;\
include \\\"qelib1.inc\\\";\
gate dcx q0,q1 { cx q0,q1; cx q1,q0; }\
qreg q[3];\
cz q[0],q[2];\
sdg q[1];\
dcx q[2],q[1];\
u3(3.890139082217223,3.447697582994976,1.1583481971959322) q[0];\
crx(2.3585459177723522) q[1],q[0];\
y q[2];\"]}"
)
print(response.json())
Responses
{
"task_id": "example"
}
{
"properties": {
"task_id": {
"type": "string",
"title": "Task Id"
}
},
"type": "object",
"required": [
"task_id"
],
"title": "TaskIdResponse"
}
Get transpilation result
Gets a task transpilation result. The Task ID needed for this endpoint is returned by /transpile
Code samples
curl -X GET \
https://cloud-transpiler.quantum.ibm.com/transpile/{task_id} \
-H 'Authorization: Bearer YOUR-TOKEN' \
-H 'Accept: application/json'
import requests
response = requests.request(
"GET",
"https://cloud-transpiler.quantum.ibm.com/transpile/{task_id}",
headers={
"Accept": "application/json",
"Authorization": "Bearer YOUR_API_TOKEN_HERE"
},
)
print(response.json())
Responses
{
"state": "example",
"result": null
}
{
"properties": {
"state": {
"type": "string",
"title": "State"
},
"result": {
"anyOf": [
{
"properties": {
"qasm": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Qasm"
},
"success": {
"type": "boolean",
"title": "Success"
},
"layout": {
"anyOf": [
{
"properties": {
"initial": {
"items": {
"type": "integer"
},
"type": "array",
"title": "Initial"
},
"final": {
"items": {
"type": "integer"
},
"type": "array",
"title": "Final"
}
},
"type": "object",
"required": [
"initial",
"final"
],
"title": "LayoutResult",
"description": "Enum for layout result"
},
{
"type": "null"
}
]
},
"error": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Error"
}
},
"type": "object",
"required": [
"success"
],
"title": "RlResult",
"description": "Enum for Rl Result information"
},
{
"items": {
"properties": {
"qasm": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Qasm"
},
"success": {
"type": "boolean",
"title": "Success"
},
"layout": {
"anyOf": [
{
"properties": {
"initial": {
"items": {
"type": "integer"
},
"type": "array",
"title": "Initial"
},
"final": {
"items": {
"type": "integer"
},
"type": "array",
"title": "Final"
}
},
"type": "object",
"required": [
"initial",
"final"
],
"title": "LayoutResult",
"description": "Enum for layout result"
},
{
"type": "null"
}
]
},
"error": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Error"
}
},
"type": "object",
"required": [
"success"
],
"title": "RlResult",
"description": "Enum for Rl Result information"
},
"type": "array"
},
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Result"
}
},
"type": "object",
"required": [
"state"
],
"title": "TaskResultResponse"
}