Skip to content

Qiskit Plugin Getting Started

Install

pip install "openquantum-sdk[qiskit]"

This installs the Qiskit plugin along with openquantum-sdk (Core SDK) and qiskit>=2.0.0.

Create a Service

With Credentials

from openquantum_sdk.auth import ClientCredentials
from openquantum_sdk_qiskit import OpenQuantumService

service = OpenQuantumService(
    creds=ClientCredentials(
        client_id="s_your_client_id",
        client_secret="your_client_secret",
    ),
)

With a Saved Account

If you have previously saved credentials (see Authentication):

from openquantum_sdk_qiskit import OpenQuantumService

service = OpenQuantumService.from_saved_account(name="default")

With a JWT Token

from openquantum_sdk_qiskit import OpenQuantumService

service = OpenQuantumService(token="your_jwt_token")

Auto-Load

If you have a saved account named "default", the service loads it automatically:

service = OpenQuantumService()

Tip

Set OPENQUANTUM_NO_AUTOLOAD=1 to disable automatic account loading.

Run a Simple Circuit

from qiskit.circuit import QuantumCircuit

# Get a backend
backend = service.return_backend("ionq:forte-1")

# Build a Bell state circuit
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])

# Run on Open Quantum
job = backend.run(qc, shots=1024)
result = job.result()
counts = result.get_counts()
print(counts)

Expected output:

{'0x0': 512, '0x3': 512}

Note

The backend returns counts with hexadecimal keys. 0x0 corresponds to bitstring 00 and 0x3 corresponds to bitstring 11.

Get Results

The backend.run() method returns an immediate result job. Call .result() to access the Qiskit Result object:

job = backend.run(qc, shots=1024)
result = job.result()

# Get counts
counts = result.get_counts()

# Get memory (individual shot results)
memory = result.get_memory()

Clean Up

Close the service when done to release HTTP connections:

service.close()

Or use the context manager:

with OpenQuantumService(creds=creds) as service:
    backend = service.return_backend("ionq:forte-1")
    job = backend.run(qc, shots=1024)
    result = job.result()

Next Steps