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
andEstimator
classes. You can also use therun()
method directly to invoke a Qiskit Runtime program.If the program has any interim results, you can use the
callback
parameter of therun()
method to stream the interim results. Alternatively, you can use theRuntimeJob.stream_results()
method to stream the results at a later time, but before the job finishes.The
run()
method returns aRuntimeJob
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
oribm_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_FILEname (
Optional
[str
]) – Name of the account to load.instance (
Optional
[str
]) – The service instance to use. Foribm_cloud
runtime, this is the Cloud Resource Name (CRN) or the service name. Foribm_quantum
runtime, this is the hub/group/project in that format.proxies (
Optional
[dict
]) – Proxy configuration. Supported optional keys areurls
(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
Return the authentication type used.
Return the channel type used.
Return self for compatibility with IBMQ provider.
Methods
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.
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.
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.
Return the least busy available backend.
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.
List the accounts saved on disk.
Sets a program's visibility.
QiskitRuntimeService.update_program
(program_id)Update a runtime program.
QiskitRuntimeService.upload_program
(data[, ...])Upload a runtime program.