Skip to main contentIBM Quantum Documentation Preview
This is a preview build of IBM Quantum™ documentation. Refer to docs.quantum.ibm.com for the official documentation.

Introduction to Qiskit Functions

Note

Qiskit Functions are an experimental feature available only to IBM Quantum™ Premium Plan users. They are in preview release status and subject to change.

Qiskit Functions simplify and accelerate utility-scale algorithm discovery and application development, by abstracting away parts of the quantum software development workflow. In this way, Qiskit Functions free up time normally spent hand-writing code and fine-tuning experiments.

Overview of Qiskit Functions Functions come in two forms:

TypeWhat does it do?Example inputs and outputsWho is it for?
Circuit functionSimplified interface for running circuits. Abstracts transpilation, error suppression, error mitigationInput: Abstract PUBs
Output: Mitigated expectation values
Researchers using Qiskit to discover new algorithms and applications, without needing to focus on optimizing for hardware or handling error. Circuit functions can be used to build custom application functions.
Application functionCovers higher-level tasks, like exploring algorithms and domain-specific use cases. Abstracts quantum workflow to solve tasks, with classical inputs and outputsInput: Molecules, graphs
Output: Energy, cost
Researchers in non-quantum domains, integrating quantum into existing large-scale classical workflows, without needing to map classical data to quantum circuits.

Functions are provided by IBM® and third-party partners. Each is performant for specific workload characteristics and have unique performance-tuning options. Premium Plan users can get started with IBM Qiskit Functions for free, or procure a license from one of the partners who have contributed a function to the catalog.


Get started with Qiskit Functions

Install Qiskit Functions Catalog client

  1. To start using Qiskit Functions, install the IBM Qiskit Functions Catalog client:

    pip install qiskit-ibm-catalog
    
  2. Retrieve your API token from the IBM Quantum account page, and activate your Python virtual environment. See the installation instructions if you do not already have a virtual environment set up.

    If you are working in a trusted Python environment (such as on a personal laptop or workstation), use the save_account() method to save your credentials locally. (Skip to the next step if you are not using a trusted environment, such as a shared or public computer, to authenticate to IBM Quantum Platform.)

    To use save_account(), run python in your shell to open a REPL (read-eval-print loop), then enter the following:

    from qiskit_ibm_catalog import QiskitFunctionsCatalog
     
    QiskitFunctionsCatalog.save_account(token="<your-token>")

    Close out of the REPL with exit(). From now on, whenever you need to authenticate to the service, you can load your credentials with QiskitFunctionsCatalog().

# Load saved credentials
from qiskit_ibm_catalog import QiskitFunctionsCatalog
 
catalog = QiskitFunctionsCatalog()
  1. Avoid executing code on an untrusted machine or an external cloud Python environment to minimize security risks. If you must use an untrusted environment (on, for example, a public computer), change your API token after each use by expiring it on the IBM Quantum Platform dashboard (click the refresh button in the API token field) to reduce risk. To initialize the service in this situation, expand the following section to view code you can use:

    Initialize the service in an untrusted environment
    from qiskit_ibm_catalog import QiskitFunctionsCatalog
     
    # After using the following code, go to your dashboard (https://quantum.ibm.com/)
    # and expire your API token (click the refresh button in the API token field)
    catalog = QiskitFunctionsCatalog(token="<MY_IBM_QUANTUM_TOKEN>")
    Caution

    Protect your API token! Never include your token in source code, Python script, or notebook file. When sharing code with others, ensure that your API token is not embedded directly within the Python script. Instead, share the script without the token and provide instructions for securely setting it up.

    If you accidentally share your token with someone or include it in version control like Git, immediately revoke your token by expiring it on the IBM Quantum Platform dashboard (click the refresh button in the API token field) to reduce risk.

  2. Once you have authenticated, you can list the functions from the Qiskit Functions Catalog that you have access to:

catalog.list()

Output:

[QiskitFunction(ibm/circuit-function)]

Run enabled functions

Once a catalog object has been instantiated, you can select a function using catalog.load(provider/function-name):

ibm_cf = catalog.load("ibm/circuit-function")

Each Qiskit Function has custom inputs, options, and outputs. Check the specific documentation pages for the function you want to run for more information. By default, all users can only run one function job at a time:

job = ibm_cf.run(
    pubs=[(circuit, observable)],
    instance=instance,  # E.g. "ibm-q/open/main"
    backend_name=backend_name,  # E.g. "ibm_kyiv"
)
 
job.job_id

Output:

0ede4d0f-06d6-4360-86a1-5028ca511b3f

Check job status

Tip

Currently, the IBM Quantum workloads table only reflects Qiskit Runtime workloads. Use job.status() to see your Qiskit Function workload's current status.

With your Qiskit Function job_id, you can check the status of running jobs. This includes the following statuses:

  • QUEUED: The remote program is in the Qiskit Function queue. The queue priority is based on how much you've used Qiskit Functions.
  • INITIALIZING: The remote program is starting; this includes setting up the remote environment and installing dependencies.
  • RUNNING: The program is running.
  • DONE: The program is complete, and you can retrieve result data with job.results().
  • ERROR: The program stopped running because of a problem. Use job.result() to get the error message.
  • CANCELED: The program was canceled; either by a user, the service, or the server.
job.status()

Output:

'DONE'

Retrieve results

Once a program is DONE, you can use job.results() to fetch the result. This output format varies with each function, so be sure to follow the specific documentation:

result = job.result()
print(result)

Output:


PubResult(data=DataBin(evs=np.ndarray(<shape=(20,), dtype=float64>), stds=np.ndarray(<shape=(20,), dtype=float64>), evs_noise_factors=np.ndarray(<shape=(20, 3), dtype=float64>), stds_noise_factors=np.ndarray(<shape=(20, 3), dtype=float64>), ensemble_stds_noise_factors=np.ndarray(<shape=(20, 3), dtype=float64>), evs_extrapolated=np.ndarray(<shape=(20, 2, 4), dtype=float64>), stds_extrapolated=np.ndarray(<shape=(20, 2, 4), dtype=float64>), shape=(20,)), metadata={'shots': 4096, 'target_precision': 0.015625, 'circuit_metadata': {}, 'resilience': {'zne': {'extrapolator': array(['exponential', 'exponential', 'exponential', 'exponential',
       'exponential', 'exponential', 'exponential', 'exponential',
       'exponential', 'exponential', 'exponential', 'exponential',
       'exponential', 'exponential', 'exponential', 'exponential',
       'exponential', 'exponential', 'exponential', 'exponential'],
      dtype='<U11')}, 'layer_noise': {'noise_overhead': 1, 'total_mitigated_layers': 0, 'unique_mitigated_layers': 0, 'unique_mitigated_layers_noise_overhead': []}}, 'num_randomizations': 32})
      

At any time, you can also cancel a job:

job.stop()

Output:

'Job has been stopped.'

List previously run jobs run with Qiskit Functions

You can use jobs() to list all jobs submitted to Qiskit Functions:

old_jobs = catalog.jobs()
old_jobs

Output:

[<Job | 0ede4d0f-06d6-4360-86a1-5028ca511b3f>,
 <Job | abf78e9a-b554-4e38-966a-f99cff877b8c>,
 <Job | 90e1109e-809f-4768-a2dc-f45bf71a97b4>,
 <Job | 313050f2-aa78-4d7d-99f4-44bdfe98e4d7>]

Fetch error messages

If a program status is ERROR, use job.result() to fetch the error message to help debug as follows:

print(job.result())

Next steps

Recommendations