Sessions
Create a session
Create a session
Autorização
Para chamar esse método, deve-se ter sido designado a uma ou mais funções de acesso do IAM que incluam as ações a seguir. É possível verificar seu acesso indo para Users > User > Access
quantum-computing.session.create
Auditoria
A chamada desse método gera os seguintes eventos de auditoria.
quantum-computing.session.create
Entrada
Nome, Tipo | Descrição |
|---|---|
max_ttl integer | The maximum time (in seconds) for the session to run, subject to plan limits. Valor Padrão: 28800Valor mínimo: 1Valor máximo: 2147483647 |
mode string | Execution mode to run the session in Valores possíveis: batchdedicated |
backend string | Backend name |
backend_name string | Backend name (fallback) |
Se sua instância estiver na região eu-de, use este link: URL: https://eu-de.quantum.cloud.ibm.com/api/v1/sessions
curl -X POST \
'https://quantum.cloud.ibm.com/api/v1/sessions' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR-TOKEN' \
-H 'Service-CRN: YOUR-SERVICE-CRN' \
-H 'IBM-API-Version: 2024-01-01' Se sua instância estiver na região eu-de, use este link: URL: https://eu-de.quantum.cloud.ibm.com/api/v1/sessions
import requests
response = requests.request(
"POST",
"https://quantum.cloud.ibm.com/api/v1/sessions",
headers={
"Accept": "application/json",
"IBM-API-Version": "2024-01-01",
"Authorization": "Bearer YOUR-TOKEN",
"Service-CRN": "YOUR-SERVICE-CRN"
},
)
print(response.json())Saída
Código de status | Descrição |
|---|---|
| 200 | Ok |
| 400 | Bad Request |
| 401 | Unauthorized |
| 500 | Internal error |
{
"id": "example",
"backend_name": "example",
"started_at": "example",
"activated_at": "example",
"closed_at": "example",
"last_job_started": "example",
"last_job_completed": "example",
"interactive_ttl": 1,
"max_ttl": 1,
"active_ttl": 1,
"state": "open",
"state_reason": "example",
"accepting_jobs": true,
"mode": "batch",
"timestamps": [
{
"status": "open",
"timestamp": "example"
}
],
"user_id": "example",
"elapsed_time": 2,
"usage": {
"value": 1,
"unit": "resource_units",
"details": [
{
"value": 1,
"unit": "resource_units",
"metric": {
"id": "example",
"value": 1
}
}
]
},
"function_id": "my-function"
}{
"type": "object",
"description": "Job session",
"properties": {
"id": {
"type": "string",
"description": "Job ID"
},
"backend_name": {
"type": "string",
"description": "Backend name. May not be set when in the \"open\" state.",
"nullable": true
},
"started_at": {
"type": "string",
"format": "date-time",
"description": "Timestamp of when the session was started"
},
"activated_at": {
"type": "string",
"format": "date-time",
"description": "Timestamp of when the session state was changed to active"
},
"closed_at": {
"type": "string",
"format": "date-time",
"description": "Timestamp of when the session was closed"
},
"last_job_started": {
"type": "string",
"format": "date-time",
"description": "Timestamp of when the last job in the session started"
},
"last_job_completed": {
"type": "string",
"format": "date-time",
"description": "Timestamp of when the last job in the session completed"
},
"interactive_ttl": {
"type": "integer",
"format": "int32",
"minimum": 1,
"maximum": 2147483647,
"description": "The maximum time (in seconds) between jobs to keep the session active"
},
"max_ttl": {
"type": "integer",
"format": "int32",
"minimum": 1,
"maximum": 2147483647,
"description": "The maximum time (in seconds) for session to run, subject to plan limits"
},
"active_ttl": {
"type": "integer",
"format": "int32",
"minimum": 1,
"maximum": 2147483647,
"description": "The remaining time (in seconds) for the session to be in the active state while jobs are running."
},
"state": {
"type": "string",
"enum": [
"open",
"active",
"inactive",
"closed"
],
"description": "The state of the session.\n- open: The session is waiting to run jobs.\n- active: The session has priority to run jobs on the backend and is running jobs or is waiting for more jobs to run.\n- inactive: The session does not have priority and is not running any jobs.\n- closed: The session is not running any jobs and will not accept/run new jobs.\n"
},
"state_reason": {
"type": "string",
"description": "The reason for the state change."
},
"accepting_jobs": {
"type": "boolean",
"description": "If true, the session is actively accepting new jobs to be queued. If false, jobs will be rejected on create and the session will be immediately closed when there are no more jobs to run in the session."
},
"mode": {
"type": "string",
"description": "Execution mode to run the session in",
"enum": [
"batch",
"dedicated"
]
},
"timestamps": {
"type": "array",
"items": {
"type": "object",
"description": "Contains information about the time a specific status transition happened",
"properties": {
"status": {
"type": "string",
"enum": [
"open",
"active",
"inactive",
"closed"
],
"description": "The state of the session.\n- open: The session is waiting to run jobs.\n- active: The session has priority to run jobs on the backend and is running jobs or is waiting for more jobs to run.\n- inactive: The session does not have priority and is not running any jobs.\n- closed: The session is not running any jobs and will not accept/run new jobs.\n"
},
"timestamp": {
"type": "string",
"format": "date-time",
"description": "Timestamp of when the session transitioned into the given status"
}
},
"required": [
"status",
"timestamp"
]
}
},
"user_id": {
"type": "string",
"description": "The id of the user who created the session."
},
"elapsed_time": {
"type": "number",
"description": "Usage in seconds. Can be null for ongoing sessions.",
"example": 2
},
"usage": {
"title": "Usage",
"description": "The usage for the session split into billable metrics if there are multiple.",
"type": "object",
"properties": {
"value": {
"type": "number",
"format": "float",
"description": "The amount of usage for this metric, in resource units.",
"minimum": 0
},
"unit": {
"type": "string",
"description": "The unit of the value field.",
"enum": [
"resource_units"
]
},
"details": {
"type": "array",
"description": "A breakdown of the usage by metric.",
"minItems": 1,
"items": {
"title": "UsageDetail",
"description": "A single billable metric contributing to a job's overall usage.",
"type": "object",
"properties": {
"value": {
"type": "number",
"format": "float",
"description": "The amount of usage for this metric, in resource units.",
"minimum": 0
},
"unit": {
"type": "string",
"description": "The unit of the value field.",
"enum": [
"resource_units"
]
},
"metric": {
"title": "UsageDetailMetric",
"description": "Identifies the metric definition from which a usage detail was calculated.",
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uuid",
"description": "The identifier of the metric definition from which this usage was calculated.",
"pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$",
"minLength": 36,
"maxLength": 36
},
"value": {
"type": "number",
"description": "The amount of usage for this metric, in seconds.",
"minimum": 0
}
},
"required": [
"id",
"value"
]
}
},
"required": [
"value",
"unit",
"metric"
]
}
}
},
"required": [
"value",
"unit",
"details"
]
},
"function_id": {
"type": "string",
"description": "The ID of the Qiskit Function that the resource was created by. Omitted when it was not created by a function.",
"pattern": "^.+$",
"minLength": 1,
"maxLength": 128,
"example": "my-function"
}
},
"required": [
"id",
"backend_name",
"mode"
]
}Get a session
Get a session
Autorização
Para chamar esse método, deve-se ter sido designado a uma ou mais funções de acesso do IAM que incluam as ações a seguir. É possível verificar seu acesso indo para Users > User > Access
quantum-computing.session.read
Auditoria
A chamada desse método gera os seguintes eventos de auditoria.
quantum-computing.session.read
Entrada
Nome, Tipo | Descrição |
|---|---|
id Necessário string | Job Session ID |
Se sua instância estiver na região eu-de, use este link: URL: https://eu-de.quantum.cloud.ibm.com/api/v1/sessions/{id}
curl -X GET \
'https://quantum.cloud.ibm.com/api/v1/sessions/{id}' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR-TOKEN' \
-H 'Service-CRN: YOUR-SERVICE-CRN' \
-H 'IBM-API-Version: 2024-01-01' Se sua instância estiver na região eu-de, use este link: URL: https://eu-de.quantum.cloud.ibm.com/api/v1/sessions/{id}
import requests
response = requests.request(
"GET",
"https://quantum.cloud.ibm.com/api/v1/sessions/{id}",
headers={
"Accept": "application/json",
"IBM-API-Version": "2024-01-01",
"Authorization": "Bearer YOUR-TOKEN",
"Service-CRN": "YOUR-SERVICE-CRN"
},
)
print(response.json())Saída
Código de status | Descrição |
|---|---|
| 200 | OK |
| 401 | Unauthorized |
| 404 | Not Found |
| 500 | Internal error |
{
"id": "example",
"backend_name": "example",
"started_at": "example",
"activated_at": "example",
"closed_at": "example",
"last_job_started": "example",
"last_job_completed": "example",
"interactive_ttl": 1,
"max_ttl": 1,
"active_ttl": 1,
"state": "open",
"state_reason": "example",
"accepting_jobs": true,
"mode": "batch",
"timestamps": [
{
"status": "open",
"timestamp": "example"
}
],
"user_id": "example",
"elapsed_time": 2,
"usage": {
"value": 1,
"unit": "resource_units",
"details": [
{
"value": 1,
"unit": "resource_units",
"metric": {
"id": "example",
"value": 1
}
}
]
},
"function_id": "my-function"
}{
"type": "object",
"description": "Job session",
"properties": {
"id": {
"type": "string",
"description": "Job ID"
},
"backend_name": {
"type": "string",
"description": "Backend name. May not be set when in the \"open\" state.",
"nullable": true
},
"started_at": {
"type": "string",
"format": "date-time",
"description": "Timestamp of when the session was started"
},
"activated_at": {
"type": "string",
"format": "date-time",
"description": "Timestamp of when the session state was changed to active"
},
"closed_at": {
"type": "string",
"format": "date-time",
"description": "Timestamp of when the session was closed"
},
"last_job_started": {
"type": "string",
"format": "date-time",
"description": "Timestamp of when the last job in the session started"
},
"last_job_completed": {
"type": "string",
"format": "date-time",
"description": "Timestamp of when the last job in the session completed"
},
"interactive_ttl": {
"type": "integer",
"format": "int32",
"minimum": 1,
"maximum": 2147483647,
"description": "The maximum time (in seconds) between jobs to keep the session active"
},
"max_ttl": {
"type": "integer",
"format": "int32",
"minimum": 1,
"maximum": 2147483647,
"description": "The maximum time (in seconds) for session to run, subject to plan limits"
},
"active_ttl": {
"type": "integer",
"format": "int32",
"minimum": 1,
"maximum": 2147483647,
"description": "The remaining time (in seconds) for the session to be in the active state while jobs are running."
},
"state": {
"type": "string",
"enum": [
"open",
"active",
"inactive",
"closed"
],
"description": "The state of the session.\n- open: The session is waiting to run jobs.\n- active: The session has priority to run jobs on the backend and is running jobs or is waiting for more jobs to run.\n- inactive: The session does not have priority and is not running any jobs.\n- closed: The session is not running any jobs and will not accept/run new jobs.\n"
},
"state_reason": {
"type": "string",
"description": "The reason for the state change."
},
"accepting_jobs": {
"type": "boolean",
"description": "If true, the session is actively accepting new jobs to be queued. If false, jobs will be rejected on create and the session will be immediately closed when there are no more jobs to run in the session."
},
"mode": {
"type": "string",
"description": "Execution mode to run the session in",
"enum": [
"batch",
"dedicated"
]
},
"timestamps": {
"type": "array",
"items": {
"type": "object",
"description": "Contains information about the time a specific status transition happened",
"properties": {
"status": {
"type": "string",
"enum": [
"open",
"active",
"inactive",
"closed"
],
"description": "The state of the session.\n- open: The session is waiting to run jobs.\n- active: The session has priority to run jobs on the backend and is running jobs or is waiting for more jobs to run.\n- inactive: The session does not have priority and is not running any jobs.\n- closed: The session is not running any jobs and will not accept/run new jobs.\n"
},
"timestamp": {
"type": "string",
"format": "date-time",
"description": "Timestamp of when the session transitioned into the given status"
}
},
"required": [
"status",
"timestamp"
]
}
},
"user_id": {
"type": "string",
"description": "The id of the user who created the session."
},
"elapsed_time": {
"type": "number",
"description": "Usage in seconds. Can be null for ongoing sessions.",
"example": 2
},
"usage": {
"title": "Usage",
"description": "The usage for the session split into billable metrics if there are multiple.",
"type": "object",
"properties": {
"value": {
"type": "number",
"format": "float",
"description": "The amount of usage for this metric, in resource units.",
"minimum": 0
},
"unit": {
"type": "string",
"description": "The unit of the value field.",
"enum": [
"resource_units"
]
},
"details": {
"type": "array",
"description": "A breakdown of the usage by metric.",
"minItems": 1,
"items": {
"title": "UsageDetail",
"description": "A single billable metric contributing to a job's overall usage.",
"type": "object",
"properties": {
"value": {
"type": "number",
"format": "float",
"description": "The amount of usage for this metric, in resource units.",
"minimum": 0
},
"unit": {
"type": "string",
"description": "The unit of the value field.",
"enum": [
"resource_units"
]
},
"metric": {
"title": "UsageDetailMetric",
"description": "Identifies the metric definition from which a usage detail was calculated.",
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uuid",
"description": "The identifier of the metric definition from which this usage was calculated.",
"pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$",
"minLength": 36,
"maxLength": 36
},
"value": {
"type": "number",
"description": "The amount of usage for this metric, in seconds.",
"minimum": 0
}
},
"required": [
"id",
"value"
]
}
},
"required": [
"value",
"unit",
"metric"
]
}
}
},
"required": [
"value",
"unit",
"details"
]
},
"function_id": {
"type": "string",
"description": "The ID of the Qiskit Function that the resource was created by. Omitted when it was not created by a function.",
"pattern": "^.+$",
"minLength": 1,
"maxLength": 128,
"example": "my-function"
}
},
"required": [
"id",
"backend_name",
"mode"
]
}Update a session
Update a session
Autorização
Para chamar esse método, deve-se ter sido designado a uma ou mais funções de acesso do IAM que incluam as ações a seguir. É possível verificar seu acesso indo para Users > User > Access
quantum-computing.session.update
Auditoria
A chamada desse método gera os seguintes eventos de auditoria.
quantum-computing.session.update
Entrada
Nome, Tipo | Descrição |
|---|---|
id Necessário string | Job Session ID |
Nome, Tipo | Descrição |
|---|---|
accepting_jobs Necessário boolean | If true, the session is actively accepting new jobs to be queued. If false, jobs will be rejected on create and the session will be immediately closed when there are no more jobs to run in the session. |
Se sua instância estiver na região eu-de, use este link: URL: https://eu-de.quantum.cloud.ibm.com/api/v1/sessions/{id}
curl -X PATCH \
'https://quantum.cloud.ibm.com/api/v1/sessions/{id}' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR-TOKEN' \
-H 'Service-CRN: YOUR-SERVICE-CRN' \
-H 'IBM-API-Version: 2024-01-01' \
-H 'Content-Type: application/json' \
-d '{"accepting_jobs":true}' Se sua instância estiver na região eu-de, use este link: URL: https://eu-de.quantum.cloud.ibm.com/api/v1/sessions/{id}
import requests
response = requests.request(
"PATCH",
"https://quantum.cloud.ibm.com/api/v1/sessions/{id}",
headers={
"Accept": "application/json",
"IBM-API-Version": "2024-01-01",
"Authorization": "Bearer YOUR-TOKEN",
"Service-CRN": "YOUR-SERVICE-CRN",
"Content-Type": "application/json"
},
data="{\"accepting_jobs\":true}"
)
print(response.json())Saída
Código de status | Descrição |
|---|---|
| 204 | Successfully updated session |
| 401 | Unauthorized |
| 404 | Not Found |
| 500 | Internal error |
Close job session
Closes the runtime session. The session stops accepting new jobs and queued jobs will not run.
Existing running jobs will run to completion. This is analogous to the cancel() function in Qiskit.
Autorização
Para chamar esse método, deve-se ter sido designado a uma ou mais funções de acesso do IAM que incluam as ações a seguir. É possível verificar seu acesso indo para Users > User > Access
quantum-computing.session.update
Auditoria
A chamada desse método gera os seguintes eventos de auditoria.
quantum-computing.session.update
Entrada
Nome, Tipo | Descrição |
|---|---|
id Necessário string | Session Id |
Se sua instância estiver na região eu-de, use este link: URL: https://eu-de.quantum.cloud.ibm.com/api/v1/sessions/{id}/close
curl -X DELETE \
'https://quantum.cloud.ibm.com/api/v1/sessions/{id}/close' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR-TOKEN' \
-H 'Service-CRN: YOUR-SERVICE-CRN' \
-H 'IBM-API-Version: 2024-01-01' Se sua instância estiver na região eu-de, use este link: URL: https://eu-de.quantum.cloud.ibm.com/api/v1/sessions/{id}/close
import requests
response = requests.request(
"DELETE",
"https://quantum.cloud.ibm.com/api/v1/sessions/{id}/close",
headers={
"Accept": "application/json",
"IBM-API-Version": "2024-01-01",
"Authorization": "Bearer YOUR-TOKEN",
"Service-CRN": "YOUR-SERVICE-CRN"
},
)
print(response.json())Saída
Código de status | Descrição |
|---|---|
| 204 | Successfully closed runtime session |