IBMQBackend
class IBMQBackend(configuration, provider, credentials, api)
Backend class interfacing with an IBM Quantum Experience device.
You can run experiments on a backend using the run()
method after assembling them into the Qobj
format. The run()
method returns an IBMQJob
instance that represents the submitted job. Each job has a unique job ID, which can later be used to retrieve the job. An example of this flow:
from qiskit import IBMQ, assemble, transpile
from qiskit.circuit.random import random_circuit
provider = IBMQ.load_account()
backend = provider.backends.ibmq_vigo
qx = random_circuit(n_qubits=5, depth=4)
qobj = assemble(transpile(qx, backend=backend), backend=backend)
job = backend.run(qobj)
retrieved_job = backend.retrieve_job(job.job_id())
You should not instantiate the IBMQBackend
class directly. Instead, use the methods provided by an AccountProvider
instance to retrieve and handle backends.
Other methods return information about the backend. For example, the status()
method returns a BackendStatus
instance. The instance contains the operational
and pending_jobs
attributes, which state whether the backend is operational and also the number of jobs in the server queue for the backend, respectively:
status = backend.status()
is_operational = status.operational
jobs_in_queue = status.pending_jobs
It is also possible to see the number of remaining jobs you are able to submit to the backend with the job_limit()
method, which returns a BackendJobLimit
instance:
job_limit = backend.job_limit()
IBMQBackend constructor.
Parameters
- configuration (
Union
[QasmBackendConfiguration
,PulseBackendConfiguration
]) – Backend configuration. - provider (
AccountProvider
) – IBM Quantum Experience account provider - credentials (
Credentials
) – IBM Quantum Experience credentials. - api (
AccountClient
) – IBM Quantum Experience client used to communicate with the server.
Methods
active_jobs
IBMQBackend.active_jobs(limit=10)
Return the unfinished jobs submitted to this backend.
Return the jobs submitted to this backend, with this provider, that are currently in an unfinished job status state. The unfinished JobStatus
states include: INITIALIZING
, VALIDATING
, QUEUED
, and RUNNING
.
Parameters
limit (int
) – Number of jobs to retrieve.
Return type
List
[IBMQJob
]
Returns
A list of the unfinished jobs for this backend on this provider.
configuration
IBMQBackend.configuration()
Return the backend configuration.
Returns
the configuration for the backend.
Return type
defaults
IBMQBackend.defaults(refresh=False)
Return the pulse defaults for the backend.
Parameters
refresh (bool
) – If True
, re-query the server for the backend pulse defaults. Otherwise, return a cached version.
Return type
Optional
[PulseDefaults
]
Returns
The backend pulse defaults or None
if the backend does not support pulse.
job_limit
IBMQBackend.job_limit()
Return the job limit for the backend.
The job limit information includes the current number of active jobs you have on the backend and the maximum number of active jobs you can have on it.
Job limit information for a backend is provider specific. For example, if you have access to the same backend via different providers, the job limit information might be different for each provider.
If the method call was successful, you can inspect the job limit for the backend by accessing the maximum_jobs
and active_jobs
attributes of the BackendJobLimit
instance returned. For example:
backend_job_limit = backend.job_limit()
maximum_jobs = backend_job_limit.maximum_jobs
active_jobs = backend_job_limit.active_jobs
If maximum_jobs
is equal to None
, then there is no limit to the maximum number of active jobs you could have on the backend.
Return type
Returns
The job limit for the backend, with this provider.
Raises
IBMQBackendApiProtocolError – If an unexpected value is received from the server.
jobs
IBMQBackend.jobs(limit=10, skip=0, status=None, job_name=None, start_datetime=None, end_datetime=None, job_tags=None, job_tags_operator='OR', descending=True, db_filter=None)
Return the jobs submitted to this backend, subject to optional filtering.
Retrieve jobs submitted to this backend that match the given filters and paginate the results if desired. Note that the server has a limit for the number of jobs returned in a single call. As a result, this function might involve making several calls to the server. See also the skip parameter for more control over pagination.
Parameters
-
limit (
int
) – Number of jobs to retrieve. -
skip (
int
) – Starting index for the job retrieval. -
status (
Union
[JobStatus
,str
,List
[Union
[JobStatus
,str
]],None
]) – Only get jobs with this status or one of the statuses. For example, you can specify status=JobStatus.RUNNING or status=”RUNNING” or status=[“RUNNING”, “ERROR”] -
job_name (
Optional
[str
]) – Filter by job name. The job_name is matched partially and regular expressions can be used. -
start_datetime (
Optional
[datetime
]) – Filter by the given start date, in local time. This is used to find jobs whose creation dates are after (greater than or equal to) this local date/time. -
end_datetime (
Optional
[datetime
]) – Filter by the given end date, in local time. This is used to find jobs whose creation dates are before (less than or equal to) this local date/time. -
job_tags (
Optional
[List
[str
]]) – Filter by tags assigned to jobs. -
job_tags_operator (
Optional
[str
]) –Logical operator to use when filtering by job tags. Valid values are “AND” and “OR”:
- If “AND” is specified, then a job must have all of the tags specified in
job_tags
to be included. - If “OR” is specified, then a job only needs to have any of the tags specified in
job_tags
to be included.
- If “AND” is specified, then a job must have all of the tags specified in
-
descending (
bool
) – IfTrue
, return the jobs in descending order of the job creation date (newest first). IfFalse
, return in ascending order. -
db_filter (
Optional
[Dict
[str
,Any
]]) –A loopback-based filter. This is an interface to a database
where
filter. Some examples of its usage are:Filter last five jobs with errors:
job_list = backend.jobs(limit=5, status=JobStatus.ERROR)
Filter last five jobs with hub name
ibm-q
:filter = {'hubInfo.hub.name': 'ibm-q'} job_list = backend.jobs(limit=5, db_filter=filter)
Return type
List
[IBMQJob
]
Returns
A list of jobs that match the criteria.
Raises
IBMQBackendValueError – If a keyword value is not recognized.
name
IBMQBackend.name()
Return the backend name.
Returns
the name of the backend.
Return type
str
properties
IBMQBackend.properties(refresh=False, datetime=None)
Return the backend properties, subject to optional filtering.
Parameters
- refresh (
bool
) – IfTrue
, re-query the server for the backend properties. Otherwise, return a cached version. - datetime (
Optional
[datetime
]) – By specifying datetime, this function returns an instance of theBackendProperties
whose timestamp is closest to, but older than, the specified datetime.
Return type
Optional
[BackendProperties
]
Returns
The backend properties or None
if the backend properties are not currently available.
provider
IBMQBackend.provider()
Return the backend Provider.
Returns
the Provider responsible for the backend.
Return type
remaining_jobs_count
IBMQBackend.remaining_jobs_count()
Return the number of remaining jobs that could be submitted to the backend.
The number of remaining jobs for a backend is provider specific. For example, if you have access to the same backend via different providers, the number of remaining jobs might be different for each. See BackendJobLimit
for the job limit information of a backend.
If None
is returned, there are no limits to the maximum number of active jobs you could have on the backend.
Return type
Optional
[int
]
Returns
The remaining number of jobs a user could submit to the backend, with this provider, before the maximum limit on active jobs is reached.
Raises
IBMQBackendApiProtocolError – If an unexpected value is received from the server.
retrieve_job
IBMQBackend.retrieve_job(job_id)
Return a single job submitted to this backend.
Parameters
job_id (str
) – The ID of the job to retrieve.
Return type
Returns
The job with the given ID.
Raises
IBMQBackendError – If job retrieval failed.
run
IBMQBackend.run(qobj, job_name=None, job_share_level=None, job_tags=None, validate_qobj=False)
Run a Qobj asynchronously.
Parameters
-
qobj (
Union
[QasmQobj
,PulseQobj
]) – The Qobj to be executed. -
job_name (
Optional
[str
]) – Custom name to be assigned to the job. This job name can subsequently be used as a filter in thejobs()
method. Job names do not need to be unique. -
job_share_level (
Optional
[str
]) –Allows sharing a job at the hub, group, project, or global level. The possible job share levels are:
global
,hub
,group
,project
, andnone
.- global: The job is public to any user.
- hub: The job is shared between the users in the same hub.
- group: The job is shared between the users in the same group.
- project: The job is shared between the users in the same project.
- none: The job is not shared at any level.
If the job share level is not specified, the job is not shared at any level.
-
job_tags (
Optional
[List
[str
]]) – Tags to be assigned to the jobs. The tags can subsequently be used as a filter in thejobs()
function call. -
validate_qobj (
bool
) – IfTrue
, run JSON schema validation against the submitted payload
Return type
Returns
The job to be executed, an instance derived from BaseJob.
Raises
- IBMQBackendApiError – If an unexpected error occurred while submitting the job.
- IBMQBackendApiProtocolError – If an unexpected value received from the server.
- IBMQBackendValueError – If an input parameter value is not valid.
status
IBMQBackend.status()
Return the backend status.
Return type
Returns
The status of the backend.
Raises
IBMQBackendApiProtocolError – If the status for the backend cannot be formatted properly.
version
IBMQBackend.version()
Return the backend version.
Returns
the X.X.X version of the backend.
Return type
str