Qiskit Connector

2.4.6 · active · verified Fri Apr 17

Qiskit Connector is a Python library (current version 2.4.6) that acts as an extension for the Qiskit SDK, designed to simplify and automate the connection to IBM Quantum Computing QPUs. It handles authentication, plan detection, and backend selection, reducing the boilerplate code required for quantum development. It receives frequent updates, often multiple releases per month, ensuring compatibility with the latest Qiskit and IBM Quantum versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Qiskit Connector, authenticate with IBM Quantum, and retrieve an available backend. Ensure your IBM Quantum API token is set as an environment variable named `IBM_QUANTUM_TOKEN`.

import os
from qiskit_connector import QiskitConnector

# Set your IBM Quantum API token as an environment variable, e.g.,
# os.environ['IBM_QUANTUM_TOKEN'] = 'YOUR_API_TOKEN'
# os.environ['IBM_QUANTUM_URL'] = 'https://quantum-computing.ibm.com/api' # Optional, defaults to this

def main():
    token = os.environ.get("IBM_QUANTUM_TOKEN")
    url = os.environ.get("IBM_QUANTUM_URL", "https://quantum-computing.ibm.com/api")

    if not token:
        print("Error: IBM_QUANTUM_TOKEN environment variable not set. Please set it to your IBM Quantum API token.")
        return

    try:
        # Initialize the connector. 'instance' can be adjusted to your specific IBM Quantum instance.
        connector = QiskitConnector(
            token=token,
            instance="ibmq-q/open/main",
            url=url
        )

        authenticated = connector.authenticate()
        if authenticated:
            print("Successfully authenticated with IBM Quantum.")
            backend = connector.get_backend()
            if backend:
                print(f"Selected backend: {backend.name}")
                print(f"Backend status: {backend.status().status_msg}")
                # You can now use the 'backend' object with Qiskit for running circuits.
            else:
                print("No suitable backend found. Check availability or instance settings.")
        else:
            print("Authentication failed. Check your token and URL.")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

if __name__ == "__main__":
    main()

view raw JSON →