English
Languages
English
Japanese
Spanish

QiskitRuntimeService

class QiskitRuntimeService(channel=None, token=None, url=None, filename=None, name=None, instance=None, proxies=None, verify=None, channel_strategy=None)[source]

Class for interacting with the Qiskit Runtime service.

Qiskit Runtime is a new architecture offered by IBM Quantum that streamlines computations requiring many iterations. These experiments will execute significantly faster within its improved hybrid quantum/classical process.

A sample workflow of using the runtime service:

from qiskit_ibm_runtime import QiskitRuntimeService, Session, Sampler, Estimator, Options
from qiskit.test.reference_circuits import ReferenceCircuits
from qiskit.circuit.library import RealAmplitudes
from qiskit.quantum_info import SparsePauliOp

# Initialize account.
service = QiskitRuntimeService()

# Set options, which can be overwritten at job level.
options = Options(optimization_level=1)

# Prepare inputs.
bell = ReferenceCircuits.bell()
psi = RealAmplitudes(num_qubits=2, reps=2)
H1 = SparsePauliOp.from_list([("II", 1), ("IZ", 2), ("XI", 3)])
theta = [0, 1, 1, 2, 3, 5]

with Session(service=service, backend="ibmq_qasm_simulator") as session:
    # Submit a request to the Sampler primitive within the session.
    sampler = Sampler(session=session, options=options)
    job = sampler.run(circuits=bell)
    print(f"Sampler results: {job.result()}")

    # Submit a request to the Estimator primitive within the session.
    estimator = Estimator(session=session, options=options)
    job = estimator.run(
        circuits=[psi], observables=[H1], parameter_values=[theta]
    )
    print(f"Estimator results: {job.result()}")
    # Close the session only if all jobs are finished
    # and you don't need to run more in the session.
    session.close()

The example above uses the dedicated Sampler and Estimator classes. You can also use the run() method directly to invoke a Qiskit Runtime program.

If the program has any interim results, you can use the callback parameter of the run() method to stream the interim results. Alternatively, you can use the RuntimeJob.stream_results() method to stream the results at a later time, but before the job finishes.

The run() method returns a RuntimeJob object. You can use its methods to perform tasks like checking job status, getting job result, and canceling job.

QiskitRuntimeService constructor

An account is selected in the following order:

  • Account with the input name, if specified.

  • Default account for the channel type, if channel is specified but token is not.

  • Account defined by the input channel and token, if specified.

  • Account defined by the environment variables, if defined.

  • Default account for the ibm_cloud account, if one is available.

  • Default account for the ibm_quantum account, if one is available.

instance, proxies, and verify can be used to overwrite corresponding values in the loaded account.

Parameters:
  • channel (Optional[Literal[‘ibm_cloud’, ‘ibm_quantum’]]) – Channel type. ibm_cloud or ibm_quantum.

  • token (Optional[str]) – IBM Cloud API key or IBM Quantum API token.

  • url (Optional[str]) – The API URL. Defaults to https://cloud.ibm.com (ibm_cloud) or https://auth.quantum-computing.ibm.com/api (ibm_quantum).

  • filename (Optional[str]) – Full path of the file where the account is created. Default: _DEFAULT_ACCOUNT_CONFIG_JSON_FILE

  • name (Optional[str]) – Name of the account to load.

  • instance (Optional[str]) – The service instance to use. For ibm_cloud runtime, this is the Cloud Resource Name (CRN) or the service name. For ibm_quantum runtime, this is the hub/group/project in that format.

  • 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), username_ntlm, password_ntlm (username and password to enable NTLM user authentication)

  • verify (Optional[bool]) – Whether to verify the server’s TLS certificate.

  • channel_strategy (Optional[str]) – Error mitigation strategy.

Returns:

An instance of QiskitRuntimeService.

Raises:

IBMInputValueError – If an input is invalid.

Attributes

QiskitRuntimeService.auth

Return the authentication type used.

QiskitRuntimeService.channel

Return the channel type used.

QiskitRuntimeService.global_service

QiskitRuntimeService.runtime

Return self for compatibility with IBMQ provider.

QiskitRuntimeService.version

Methods

QiskitRuntimeService.active_account()

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

QiskitRuntimeService.backend([name, instance])

Return a single backend matching the specified filtering.

QiskitRuntimeService.backends([name, ...])

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

QiskitRuntimeService.delete_account([...])

Delete a saved account from disk.

QiskitRuntimeService.delete_job(job_id)

Delete a runtime job.

QiskitRuntimeService.delete_program(program_id)

Delete a runtime program.

QiskitRuntimeService.get_backend([name])

Return a single backend matching the specified filtering.

QiskitRuntimeService.instances()

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

QiskitRuntimeService.job(job_id)

Retrieve a runtime job.

QiskitRuntimeService.jobs([limit, skip, ...])

Retrieve all runtime jobs, subject to optional filtering.

QiskitRuntimeService.least_busy([...])

Return the least busy available backend.

QiskitRuntimeService.pprint_programs([...])

Pretty print information about available runtime programs.

QiskitRuntimeService.program(program_id[, ...])

Retrieve a runtime program.

QiskitRuntimeService.programs([refresh, ...])

Return available runtime programs.

QiskitRuntimeService.run(program_id, inputs)

Execute the runtime program.

QiskitRuntimeService.save_account([token, ...])

Save the account to disk for future use.

QiskitRuntimeService.saved_accounts([...])

List the accounts saved on disk.

QiskitRuntimeService.set_program_visibility(...)

Sets a program's visibility.

QiskitRuntimeService.update_program(program_id)

Update a runtime program.

QiskitRuntimeService.upload_program(data[, ...])

Upload a runtime program.