Skip to main content

Qiskit IBM Runtime service for accessing the quantum devices and simulators at IBM

Project description

Qiskit IBM Runtime

LicenseCICode style: blackCoverage Status

Qiskit is an open-source SDK for working with quantum computers at the level of circuits, algorithms, and application modules.

Qiskit Runtime is a new architecture offered by IBM Quantum that streamlines quantum computations. It is designed to use classical compute resources to execute quantum circuits with more efficiency on quantum processors.

Using Qiskit Runtime, for example, a research team at IBM Quantum was able to achieve 120x speed up in their lithium hydride simulation. For more information, see the IBM Research blog.

Qiskit Runtime allows authorized users to upload quantum programs. A quantum program, also called a Qiskit runtime program, is a piece of Python code that takes certain inputs, performs quantum and classical computation, and returns the processing results. The users can then invoke these quantum programs by simply passing in the required input parameters.

This module provides the interface to access Qiskit Runtime.

Installation

You can install this package using pip:

pip install qiskit-ibm-runtime

Account Setup

Qiskit Runtime on IBM Cloud

Qiskit Runtime is now part of the IBM Quantum Services on IBM Cloud. To use this service, you'll need to create an IBM Cloud account and a quantum service instance. This guide contains step-by-step instructions on setting this up, including directions to find your IBM Cloud API key and Cloud Resource Name (CRN), which you will need for authentication.

Qiskit Runtime on IBM Quantum

Prior to becoming an IBM Cloud service, Qiskit Runtime was offered on IBM Quantum. If you have an existing IBM Quantum account, you can continue using Qiskit Runtime on IBM Quantum, which is referred to as legacy runtime.

You will need your IBM Quantum API token to authenticate with the Qiskit Runtime service:

  1. Create an IBM Quantum account or log in to your existing account by visiting the IBM Quantum login page.

  2. Copy (and optionally regenerate) your API token from your IBM Quantum account page.

Saving Account on Disk

Once you have the account credentials, you can save them on disk, so you won't have to input them each time. The credentials are saved in the $HOME/.qiskit/qiskit-ibm.json file, where $HOME is your home directory.

:warning: Account credentials are saved in plain text, so only do so if you are using a trusted device.
from qiskit_ibm_runtime import IBMRuntimeService

# Save an IBM Cloud account.    
IBMRuntimeService.save_account(auth="cloud", token="MY_IBM_CLOUD_API_KEY", instance="MY_IBM_CLOUD_CRN")

# Save an IBM Quantum account.
IBMRuntimeService.save_account(auth="legacy", token="MY_IBM_QUANTUM_TOKEN")

Once the account is saved on disk, you can instantiate the service without any arguments:

from qiskit_ibm_runtime import IBMRuntimeService
service = IBMRuntimeService()

Loading Account from Environment Variables

Alternatively, the service can discover credentials from environment variables:

export QISKIT_IBM_TOKEN="MY_IBM_CLOUD_API_KEY"
export QISKIT_IBM_INSTANCE="MY_IBM_CLOUD_CRN"

Then instantiate the service without any arguments:

from qiskit_ibm_runtime import IBMRuntimeService
service = IBMRuntimeService()

Enabling Account for Current Session

As another alternative, you can also enable an account just for the current session by instantiating the service with your credentials.

from qiskit_ibm_runtime import IBMRuntimeService

# For an IBM Cloud account.
cloud_service = IBMRuntimeService(auth="cloud", token="MY_IBM_CLOUD_API_KEY", instance="MY_IBM_CLOUD_CRN")

# For an IBM Quantum account.
legacy_service = IBMRuntimeService(auth="legacy", token="MY_IBM_QUANTUM_TOKEN")

Accessing Qiskit Runtime Programs

Finding available programs

To list all available programs:

from qiskit_ibm_runtime import IBMRuntimeService
service = IBMRuntimeService()
service.pprint_programs()

pprint_programs() prints the summary metadata of the first 20 programs visible to you. A program's metadata consists of its ID, name, description, input parameters, return values, interim results, and other information that helps you to know more about the program. pprint_programs(detailed=True, limit=None) will print all metadata for all programs visible to you.

Executing a Program

To run a program, specify the program ID, input parameters, as well as any execution options:

from qiskit.test.reference_circuits import ReferenceCircuits
from qiskit_ibm_runtime import IBMRuntimeService

service = IBMRuntimeService()
program_inputs = {
    'circuits': ReferenceCircuits.bell()
}
options = {'backend_name': 'ibmq_qasm_simulator'}
job = service.run(
    program_id="sampler",
    options=options,
    inputs=program_inputs)
print(f"job ID: {job.job_id}")
result = job.result()

Accessing your IBM Quantum backends

A backend is a quantum device or simulator capable of running quantum circuits or pulse schedules.

You can query for the backends you have access to. Attributes and methods of the returned instances provide information, such as qubit counts, error rates, and statuses, of the backends.

from qiskit_ibm_runtime import IBMRuntimeService
service = IBMRuntimeService()

# Display all backends you have access.
print(service.backends())

# Get a specific backend.
backend = service.backend('ibmq_qasm_simulator')

Next Steps

Now you're set up and ready to check out some of the tutorials.

Contribution Guidelines

If you'd like to contribute to Qiskit IBM Runtime, please take a look at our contribution guidelines. This project adheres to Qiskit's code of conduct. By participating, you are expected to uphold to this code.

We use GitHub issues for tracking requests and bugs. Please use our slack for discussion and simple questions. To join our Slack community use the invite link at Qiskit.org. For questions that are more suited for a forum we use the Qiskit tag in Stack Exchange.

License

Apache License 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qiskit-ibm-runtime-0.1.0rc2.tar.gz (143.0 kB view details)

Uploaded Source

Built Distribution

qiskit_ibm_runtime-0.1.0rc2-py3-none-any.whl (151.7 kB view details)

Uploaded Python 3

File details

Details for the file qiskit-ibm-runtime-0.1.0rc2.tar.gz.

File metadata

  • Download URL: qiskit-ibm-runtime-0.1.0rc2.tar.gz
  • Upload date:
  • Size: 143.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for qiskit-ibm-runtime-0.1.0rc2.tar.gz
Algorithm Hash digest
SHA256 158e654db3b6012975eb2c82e0a8c697ab9ab5613f65bf616ea3509d6da29be5
MD5 f0096bf09d645c07c9193efeeea165c3
BLAKE2b-256 1e25e73e8f6bce4c67250eae74e010cc7a0b85202d5dfaf78a80a53313244d32

See more details on using hashes here.

File details

Details for the file qiskit_ibm_runtime-0.1.0rc2-py3-none-any.whl.

File metadata

  • Download URL: qiskit_ibm_runtime-0.1.0rc2-py3-none-any.whl
  • Upload date:
  • Size: 151.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for qiskit_ibm_runtime-0.1.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 f4df5d2dc0c0a340f8a71534c4d020a959271486153462a1d84bed6360f3eb62
MD5 d1a3738d0dca0b9da84c86142651ac14
BLAKE2b-256 ddfb954cb02590054ab110cdf0f07094ded4f94064c1dbc1663ac342a3fa2a7d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page