Skip to content

PennyLane Plugin Overview

The openquantum-sdk[pennylane] plugin connects PennyLane to the Open Quantum platform, allowing you to run PennyLane quantum circuits on real QPU hardware. It depends on the Core SDK (openquantum-sdk) for authentication and job submission.

Installation

pip install "openquantum-sdk[pennylane]"

The plugin automatically registers itself with PennyLane via Python entry points. Just import pennylane as qml and use qml.device("openquantum.device", ...).

What the Plugin Does

The plugin registers an openquantum.device with PennyLane. When you execute a QNode using this device, the plugin:

  1. Checks backend status — reports whether the target QPU is online, its queue depth, and shows alternatives if it is unavailable.
  2. Converts your PennyLane circuit to an OpenQASM 2.0 program.
  3. Prepares and quotes — uploads the QASM, prepares the job, and computes the credit cost.
  4. Confirms — shows the total cost and prompts for confirmation in terminal sessions (unless auto_confirm=True). In Jupyter notebooks, execution proceeds immediately.
  5. Submits with live status — shows a spinner during execution. While the job is pending, you can interrupt (Ctrl+C / Jupyter stop button) to cancel it on the platform.
  6. Downloads results — fetches the measurement counts and converts them into the result type you requested (counts, expectation values, probabilities, etc.).
  7. Tracks spending — prints credits used and maintains a cumulative total_credits_used counter.

Quick Example

Run a Bell state circuit on Open Quantum hardware with PennyLane:

import pennylane as qml

dev = qml.device(
    "openquantum.device",
    wires=2,
    shots=1024,
    backend="ionq:forte-1",
    client_id="s_your_client_id",
    client_secret="your_client_secret",
)

@qml.qnode(dev)
def bell_state():
    qml.Hadamard(wires=0)
    qml.CNOT(wires=[0, 1])
    return qml.counts()

result = bell_state()
print(result)
# {'00': 507, '11': 517}

Tip

Set OPENQUANTUM_CLIENT_ID and OPENQUANTUM_CLIENT_SECRET as environment variables to avoid passing credentials in code. See the Authentication guide.

Key Components

Component Description
OpenQuantumDevice PennyLane Device subclass. Implements execute() to run circuits on Open Quantum.
QASM Serializer Converts PennyLane tapes to OpenQASM 2.0 strings with proper gate mapping.
API Client HTTP client handling upload, preparation, submission, polling, and result download.
Keycloak Auth Manages SDK key authentication, JWT token caching, and automatic refresh.

Supported Backends

The plugin works with any backend available on the Open Quantum platform. Backends are identified by their short_code (e.g., "ionq:forte-1").

Type Description Use Case
QPU Real quantum hardware (e.g., IonQ trapped-ion processors) Production workloads, hardware noise characterization

To see all available backends, use the Core SDK, the Qiskit plugin, or the Open Quantum Portal. See Backend Selection for details.

Shot-Based Execution Only

Open Quantum is a shot-based execution platform. Every circuit execution requires a finite number of shots.

# Correct: specify shots
dev = qml.device("openquantum.device", wires=2, shots=1024, backend="ionq:forte-1")

# Incorrect: shots=None is not supported
dev = qml.device("openquantum.device", wires=2, shots=None, backend="ionq:forte-1")

Note

Analytic mode (shots=None) is not supported. The device will raise an error if you attempt to use it. All measurement results are estimated from finite samples.

How Measurements Work

The plugin uses PennyLane's measurements_from_counts preprocessing transform to handle all measurement types. This works in three steps:

  1. Preprocessing: PennyLane inserts any diagonalizing rotations needed for the requested observables and replaces all measurements with a single qml.counts() call.
  2. Execution: The plugin runs the modified circuit and obtains raw bitstring count dictionaries from the backend.
  3. Post-processing: PennyLane converts the raw counts into the requested measurement types (expectation values, variances, probabilities, or samples).

This approach means the plugin only needs to handle counts -- all measurement conversions are handled by PennyLane's battle-tested transforms.

Device API

The plugin uses PennyLane's modern Device base class (v0.38+) with a TOML capabilities file. This is the current recommended approach, replacing the deprecated QubitDevice base class.

For the full list of supported gates, observables, and measurements, see Supported Operations.

Next Steps