Skip to main contentIBM Quantum Documentation

IBMProvider

IBMProvider(token=None, url=None, name=None, instance=None, proxies=None, verify=None) GitHub(opens in a new tab)

Provides access to the IBM Quantum services available to an account.

Authenticate against IBM Quantum for use from saved credentials or during session.

Credentials can be saved to disk by calling the save_account() method:

from qiskit_ibm_provider import IBMProvider
IBMProvider.save_account(token=<INSERT_IBM_QUANTUM_TOKEN>)

You can set the default project using the hub, group, and project keywords in save_account(). Once credentials are saved you can simply instantiate the provider like below to load the saved account and default project:

from qiskit_ibm_provider import IBMProvider
provider = IBMProvider()

Instead of saving credentials to disk, you can also set the environment variables QISKIT_IBM_TOKEN, QISKIT_IBM_URL and QISKIT_IBM_INSTANCE and then instantiate the provider as below:

from qiskit_ibm_provider import IBMProvider
provider = IBMProvider()

You can also enable an account just for the current session by instantiating the provider with the API token:

from qiskit_ibm_provider import IBMProvider
provider = IBMProvider(token=<INSERT_IBM_QUANTUM_TOKEN>)

token is the only required attribute that needs to be set using one of the above methods. If no url is set, it defaults to ‘https://auth.quantum-computing.ibm.com/api(opens in a new tab)’.

Note

The hub/group/project is selected based on the below selection order, in decreasing order of priority.

  • The hub/group/project you explicity specify when calling a service. Ex: provider.get_backend(), etc.
  • The hub/group/project required for the service.
  • The default hub/group/project you set using save_account().
  • A premium hub/group/project in your account.
  • An open access hub/group/project.

The IBMProvider offers the IBMBackendService which gives access to the IBM Quantum devices and simulators.

You can obtain an instance of the service as an attribute of the IBMProvider instance. For example:

backend_service = provider.backend

Since IBMBackendService is the main service, some of the backend-related methods are available through this class for convenience.

The backends() method returns all the backends available to this account:

backends = provider.backends()

The get_backend() method returns a backend that matches the filters passed as argument. An example of retrieving a backend that matches a specified name:

simulator_backend = provider.get_backend('ibmq_qasm_simulator')

IBMBackend’s are uniquely identified by their name. If you invoke get_backend() twice, you will get the same IBMBackend instance, and any previously updated options will be reset to the default values.

It is also possible to use the backend attribute to reference a backend. As an example, to retrieve the same backend from the example above:

simulator_backend = provider.backend.ibmq_qasm_simulator
Note

The backend attribute can be used to autocomplete the names of backends available to this account. To autocomplete, press tab after provider.backend.. This feature may not be available if an error occurs during backend discovery. Also note that this feature is only available in interactive sessions, such as in Jupyter Notebook and the Python interpreter.

IBMProvider constructor

Parameters

Returns

An instance of IBMProvider

Raises

IBMInputValueError – If an input is invalid.


Attributes

backend

Return the backend service.

Return type

IBMBackendService

Returns

The backend service instance.

version

= 1


Methods

active_account

active_account() GitHub(opens in a new tab)

Return the IBM Quantum account currently in use for the session.

Return type

Optional[Dict[str, str]]

Returns

A dictionary with information about the account currently in the session.

backends

backends(name=None, filters=None, min_num_qubits=None, instance=None, **kwargs) GitHub(opens in a new tab)

Return all backends accessible via this account, subject to optional filtering.

Parameters

  • name (Optional[str]) – Backend name to filter by.

  • min_num_qubits (Optional[int]) – Minimum number of qubits the backend must have.

  • instance (Optional[str]) – The provider in the hub/group/project format.

  • filters (Optional[Callable[[List[IBMBackend]], bool]]) –

    More complex filters, such as lambda functions. For example:

    IBMProvider.backends(filters=lambda b: b.max_shots > 50000)
    IBMProvider.backends(filters=lambda x: ("rz" in x.basis_gates )
  • **kwargs

    Simple filters that require a specific value for an attribute in backend configuration, backend status, or provider credentials. Examples:

    # Get the operational real backends
    IBMProvider.backends(simulator=False, operational=True)
    # Get the backends with at least 127 qubits
    IBMProvider.backends(min_num_qubits=127)
    # Get the backends that support OpenPulse
    IBMProvider.backends(open_pulse=True)

    For the full list of backend attributes, see the IBMBackend class documentation <api/qiskit/providers_models>

Return type

List[IBMBackend]

Returns

The list of available backends that match the filter.

delete_account

static delete_account(name=None) GitHub(opens in a new tab)

Delete a saved account from disk.

Parameters

name (Optional[str]) – Name of the saved account to delete.

Return type

bool

Returns

True if the account was deleted. False if no account was found.

get_backend

get_backend(name=None, instance=None, **kwargs) GitHub(opens in a new tab)

Return a single backend matching the specified filtering.

Parameters

  • name (str) – Name of the backend.
  • instance (Optional[str]) – The provider in the hub/group/project format.
  • **kwargs – Dict used for filtering.

Returns

a backend matching the filtering.

Return type

Backend

Raises

  • QiskitBackendNotFoundError – if no backend could be found or more than one backend matches the filtering criteria.
  • IBMProviderValueError – If only one or two parameters from hub, group, project are specified.

instances

instances() GitHub(opens in a new tab)

Return the IBM Quantum instances list currently in use for the session.

Return type

List[str]

Returns

A list with instances currently in the session.

jobs

jobs(limit=10, skip=0, backend_name=None, status=None, start_datetime=None, end_datetime=None, job_tags=None, descending=True, instance=None, legacy=False) GitHub(opens in a new tab)

Return a list of jobs, subject to optional filtering.

Retrieve jobs 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.

Parameters

  • limit (Optional[int]) – Number of jobs to retrieve. None means no limit. Note that the number of sub-jobs within a composite job count towards the limit.
  • skip (int) – Starting index for the job retrieval.
  • backend_name (Optional[str]) – Name of the backend to retrieve jobs from.
  • status (Optional[Literal[‘pending’, ‘completed’]]) – Filter jobs with either “pending” or “completed” status.
  • 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. Matched jobs are associated with all tags.
  • descending (bool) – If True, return the jobs in descending order of the job creation date (i.e. newest first) until the limit is reached.
  • instance (Optional[str]) – The provider in the hub/group/project format.
  • legacy (bool) – If True, only retrieve jobs run from the deprecated qiskit-ibmq-provider.
  • Otherwise
  • qiskit-ibm-provider. (only retrieve jobs run from) –

Return type

List[IBMJob]

Returns

A list of IBMJob instances.

retrieve_job

retrieve_job(job_id) GitHub(opens in a new tab)

Return a single job.

Parameters

job_id (str) – The ID of the job to retrieve.

Return type

IBMJob

Returns

The job with the given id.

save_account

static save_account(token=None, url=None, instance=None, name=None, proxies=None, verify=None, overwrite=False) GitHub(opens in a new tab)

Save the account to disk for future use.

Parameters

  • token (Optional[str]) – IBM Quantum API token.
  • url (Optional[str]) – The API URL. Defaults to https://auth.quantum-computing.ibm.com/api(opens in a new tab)
  • instance (Optional[str]) – The hub/group/project.
  • name (Optional[str]) – Name of the account to save.
  • proxies (Optional[dict]) – Proxy configuration. Supported optional keys are urls (a dictionary mapping protocol or protocol and host to the URL of the proxy, documented at https://docs.python-requests.org/en/latest/api/#requests.Session.proxies(opens in a new tab)), username_ntlm, password_ntlm (username and password to enable NTLM user authentication)
  • verify (Optional[bool]) – Verify the server’s TLS certificate.
  • overwrite (Optional[bool]) – True if the existing account is to be overwritten.

Return type

None

saved_accounts

static saved_accounts(default=None, name=None) GitHub(opens in a new tab)

List the accounts saved on disk.

Parameters

  • default (Optional[bool]) – If set to True, only default accounts are returned.
  • name (Optional[str]) – If set, only accounts with the given name are returned.

Return type

dict

Returns

A dictionary with information about the accounts saved on disk.

Raises

ValueError – If an invalid account is found on disk.

Was this page helpful?