API Reference¶
Complete reference documentation for all Open Quantum SDK classes, methods, and data models.
Core SDK¶
SchedulerClient¶
SchedulerClient
¶
Bases: BaseClient
Client for the OpenQuantum Scheduler API.
Handles the full job lifecycle: uploading circuit files, preparing quotes, submitting jobs, polling for completion, and downloading results.
The high-level submit_job() method wraps the entire flow in a single
call. Lower-level methods (upload_job_input, prepare_job,
wait_for_preparation, choose_plan_and_priority, create_job,
wait_for_job) are available when the caller needs to stop between
the quote and the spend.
Example
from openquantum_sdk.auth import ClientCredentials, ClientCredentialsAuth from openquantum_sdk.clients import SchedulerClient, JobSubmissionConfig auth = ClientCredentialsAuth( ... creds=ClientCredentials(client_id="s_...", client_secret="...") ... ) scheduler = SchedulerClient(auth=auth) config = JobSubmissionConfig( ... backend_class_id="ionq:aria-1", ... name="My Job", ... job_subcategory_id="phys:oth", ... shots=1024, ... ) job = scheduler.submit_job(config, file_path="circuit.qasm")
submit_job
¶
Submit a job end-to-end: upload, prepare, approve, create, and poll.
This is the recommended way to run a circuit. It handles the full lifecycle automatically:
- Upload the circuit file.
- Prepare the job and fetch a pricing quote.
- Select (or auto-select) the execution plan and queue priority.
- Approve the quote and create the job.
- Poll until the job completes (or times out).
Provide exactly one of file_content or file_path.
Returns:
| Type | Description |
|---|---|
JobRead
|
A |
JobRead
|
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If preparation fails, the user declines the quote, or the job fails or is canceled. |
TimeoutError
|
If the job does not complete within
|
Example
config = JobSubmissionConfig( ... backend_class_id="ionq:aria-1", ... name="Bell State", ... job_subcategory_id="phys:oth", ... shots=1024, ... ) job = scheduler.submit_job(config, file_path="bell.qasm") output = scheduler.download_job_output(job)
upload_job_input
¶
Upload a circuit file and return the upload ID.
Provide exactly one of file_content or file_path.
Returns:
| Type | Description |
|---|---|
str
|
The upload endpoint ID used to reference this file in subsequent |
str
|
preparation and submission calls. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both or neither of |
TypeError
|
If |
prepare_job
¶
Submit a job preparation request.
Preparation validates the circuit, calculates pricing, and returns
a preparation ID that can be polled via get_preparation_result().
Returns:
| Type | Description |
|---|---|
JobPreparationResponse
|
A |
get_preparation_result
¶
Get the status and pricing quote for a job preparation.
Poll this method until the returned status is "Completed"
or "Failed". On completion, the quote field contains the
available execution plans and queue priorities with pricing.
Returns:
| Type | Description |
|---|---|
JobPreparationResultResponse
|
A |
JobPreparationResultResponse
|
circuit metadata. |
create_job
¶
Create and submit a job from a completed preparation.
This deducts credits and places the job in the execution queue.
Organization is taken from the preparation; organization_id on
JobCreate is optional.
Returns:
| Type | Description |
|---|---|
JobRead
|
A |
get_job
¶
Get the current status of a job.
Returns:
| Type | Description |
|---|---|
JobRead
|
A |
cancel_job
¶
Cancel a queued or running job.
list_jobs
¶
List jobs for an organization.
Returns:
| Type | Description |
|---|---|
PaginatedJobs
|
A |
PaginatedJobs
|
metadata. |
download_job_output
¶
Download and parse the output of a completed job.
Returns:
| Type | Description |
|---|---|
Any
|
The parsed JSON result from the job output. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the job has no |
ValueError
|
If the output cannot be parsed as JSON. |
download_job_calibration
¶
Download and parse the calibration snapshot tagged on a job.
Calibration is optional: only present if reported.
Returns:
| Type | Description |
|---|---|
Any
|
Parsed JSON calibration payload. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the job has no |
ValueError
|
If the body cannot be parsed as JSON. |
wait_for_preparation
¶
Poll a preparation until it completes or fails.
A Failed preparation raises RuntimeError. A timeout raises
TimeoutError. Not-found responses (the preparation row is not
visible yet) are retried until the timeout.
wait_for_job
¶
Poll a job until it reaches a terminal status or times out.
Terminal statuses are Completed, Failed, and Canceled
(see :data:TERMINAL_JOB_STATUSES).
Returns:
| Type | Description |
|---|---|
JobRead
|
The latest |
choose_plan_and_priority
¶
Choose a plan and priority from a completed preparation.
See :func:select_plan_and_priority for the selection rules.
prefer_public=True ranks Public plans first when the plan is
"auto" (the MCP spend policy). The default keeps cheapest-wins.
Plan selection¶
openquantum_sdk.clients.select_plan_and_priority(quote, execution_plan='auto', queue_priority='auto', *, prefer_public=False)
¶
Pick an execution plan and queue priority from a preparation quote.
"auto" minimizes total cost (base price + priority increase), then
base price. Friendly names ("public", "private", "standard",
"priority", "instant"), ExecutionPlanType /
QueuePriorityType members, and raw UUIDs select that option exactly.
prefer_public only affects execution_plan="auto": Public plans
are ranked ahead of Private ones, then the cheapest pair inside that
group wins. The MCP server sets this so Spark credits can apply. The
default (False) keeps the historical cheapest-plan behavior used by
submit_job.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the quote is empty or the requested plan/priority is not in it. |
OpenQuantumClient¶
Framework-agnostic session used by PennyLane, Cirq, Qrisp, and the MCP server. from_env() resolves environment credentials and the playbook URL variables and does not autoload a saved account.
openquantum_sdk.session.OpenQuantumClient
¶
Authenticated session holding a management + scheduler client pair.
Authentication is resolved in this order:
- An explicit
tokenorcredsargument. - A saved account on disk (autoloaded when neither is given and
auto_loadis true). SetOPENQUANTUM_NO_AUTOLOAD=1orauto_load=Falseto disable.OPENQUANTUM_ACCOUNT_NAMEselects the account (default"default").
Environment-variable credential resolution (OPENQUANTUM_TOKEN etc.) is
intentionally not performed in __init__. Callers that want env
credentials and service URLs without a saved-account autoload should use
:meth:from_env. This keeps autoload and explicit-env behavior separable.
Use as a context manager to close HTTP sessions on exit.
from_env(*, token=None, creds=None, client_id=None, client_secret=None, sdk_key_path=None, keycloak_base=None, realm=None, scheduler_url=None, management_url=None, require=True, **kwargs)
classmethod
¶
Build a client from arguments and environment variables.
Does not autoload a saved account. Credential resolution uses
:func:openquantum_sdk.credentials.resolve_env_credentials. Service
URLs fall back to OPENQUANTUM_SCHEDULER_URL /
OPENQUANTUM_MANAGEMENT_URL / OPENQUANTUM_KEYCLOAK_BASE /
OPENQUANTUM_KEYCLOAK_REALM, then the production defaults.
When require is true (the default) and no credential resolves,
raises :class:~openquantum_sdk.exceptions.AuthenticationError.
Pass an already-resolved creds or token to skip env lookup.
organizations()
¶
List organizations the authenticated user belongs to.
backends(*, name=None, online=None, device_type=None, vendor_id=None, min_num_qubits=None, limit=50)
¶
List available backend classes with optional client-side filtering.
Returns a list of dicts with id, name, description,
type, provider_id, short_code, queue_depth,
accepting_jobs, and status.
login(*, token=None, creds=None, save=False, name='default', filename=None, **kwargs)
classmethod
¶
Authenticate and return a client, optionally saving the credentials.
close()
¶
Close the underlying HTTP sessions.
ManagementClient¶
ManagementClient
¶
Bases: BaseClient
Client for the OpenQuantum Management API.
Provides backend discovery, provider listing, and organization lookup. The management API is read-only and does not require an organization context.
Example
from openquantum_sdk.auth import ClientCredentials, ClientCredentialsAuth auth = ClientCredentialsAuth( ... creds=ClientCredentials(client_id="s_...", client_secret="...") ... ) mgmt = ManagementClient(auth=auth) backends = mgmt.list_backend_classes()
list_backend_classes
¶
List available backend classes (QPUs and simulators).
Returns:
| Type | Description |
|---|---|
PaginatedBackendClasses
|
A |
PaginatedBackendClasses
|
pagination metadata. Each |
PaginatedBackendClasses
|
backend's name, type, status, queue depth, and short_code. |
list_providers
¶
List quantum hardware providers on the platform.
Returns:
| Type | Description |
|---|---|
PaginatedProviders
|
A |
PaginatedProviders
|
pagination metadata. |
list_user_organizations
¶
List organizations the authenticated user belongs to.
Returns:
| Type | Description |
|---|---|
PaginatedOrganizations
|
A |
PaginatedOrganizations
|
and pagination metadata. |
JobSubmissionConfig¶
openquantum_sdk.clients.JobSubmissionConfig
dataclass
¶
Configuration for submitting a job via SchedulerClient.submit_job().
This dataclass bundles every option needed to upload a circuit, prepare a quote, and submit the job in a single call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend_class_id
|
str
|
Backend class ID or short_code (e.g., |
required |
name
|
str
|
Human-readable name for the job (visible in the portal). |
required |
job_subcategory_id
|
str
|
Job subcategory ID or short_code (e.g., |
required |
shots
|
Optional[int]
|
Optional measurement shot count (legacy). Prefer
|
None
|
organization_id
|
Optional[str]
|
Organization UUID. Optional if the user belongs to exactly one organization — the SDK resolves it automatically. |
None
|
configuration_data
|
Optional[Dict[str, Any]]
|
Optional backend-specific configuration dictionary. |
None
|
execution_plan
|
Union[str, ExecutionPlanType, AutoChoice]
|
|
'auto'
|
queue_priority
|
Union[str, QueuePriorityType, AutoChoice]
|
|
'auto'
|
auto_approve_quote
|
bool
|
If |
True
|
verbose
|
bool
|
If |
False
|
job_timeout_seconds
|
int
|
Maximum seconds to wait for the job to complete. Defaults to 86 400 (1 day). |
86400
|
submitted_with
|
Optional[str]
|
Client/surface that submitted this preparation
(e.g. |
'sdk'
|
input_format
|
Optional[str]
|
Circuit input language family (e.g. |
None
|
Example
config = JobSubmissionConfig( ... backend_class_id="ionq:aria-1", ... name="Bell State", ... job_subcategory_id="phys:oth", ... shots=1024, ... ) job = scheduler.submit_job(config, file_path="circuit.qasm")
Authentication¶
openquantum_sdk.auth.ClientCredentialsAuth
¶
Keycloak client-credentials OAuth2 helper with thread-safe token caching.
Manages the full token lifecycle: initial fetch, automatic refresh when
the token is within leeway_seconds of expiry, and forced refresh on
401 retries. All token operations are thread-safe.
The token endpoint is constructed as:
{keycloak_base}/realms/{realm}/protocol/openid-connect/token
token_endpoint
property
¶
The full Keycloak token endpoint URL for this realm.
__init__(creds, keycloak_base='https://id.openquantum.com', realm='platform', scope=None, leeway_seconds=30, session=None)
¶
Initialize the auth helper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
creds
|
ClientCredentials
|
Client credentials containing the client ID and secret. |
required |
keycloak_base
|
str
|
Base URL of the Keycloak server.
Defaults to |
'https://id.openquantum.com'
|
realm
|
str
|
Keycloak realm name. Defaults to |
'platform'
|
scope
|
Optional[str]
|
Optional OAuth2 scope to request. |
None
|
leeway_seconds
|
int
|
Seconds before token expiry to trigger a proactive refresh. Defaults to 30. |
30
|
session
|
Optional[Session]
|
Optional |
None
|
apply_auth_header(headers)
¶
Add a Bearer authorization header using the current access token.
Does not mutate the input dict; returns a new dict with the
Authorization header added.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
headers
|
Dict[str, str]
|
Existing headers to augment. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
A new headers dict containing all entries from |
Dict[str, str]
|
the |
get_access_token(force=False)
¶
Return a valid access token, refreshing if needed.
Uses double-checked locking to ensure only one thread fetches a new token at a time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A valid OAuth2 access token string. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the Keycloak response is missing an access token. |
HTTPError
|
If the token request fails. |
openquantum_sdk.auth.ClientCredentials
dataclass
¶
SDK key credentials for machine-to-machine authentication.
Attributes:
| Name | Type | Description |
|---|---|---|
client_id |
str
|
The OAuth2 client ID (SDK key ID). |
client_secret |
str
|
The OAuth2 client secret (SDK key secret). |
Models¶
openquantum_sdk.models.APIError
¶
Bases: OpenQuantumError
Exception raised when the Open Quantum API returns an error response.
Wraps an ErrorResponse and produces a human-readable message that
includes the status code, error messages, and request ID.
Attributes:
| Name | Type | Description |
|---|---|---|
error_response |
The parsed |
Exceptions¶
The shared exception hierarchy raised across the SDK and all framework plugins.
Catch OpenQuantumError to handle any Open Quantum failure uniformly.
openquantum_sdk.exceptions
¶
Exception hierarchy for the Open Quantum SDK and its framework plugins.
Everything the SDK or a plugin raises derives from :class:OpenQuantumError,
so except OpenQuantumError catches any Open Quantum failure regardless of
which framework surface produced it. Below the root are a small set of
semantic errors, caught by the kind of failure rather than by framework:
- :class:
AuthenticationError-- missing or invalid credentials. - :class:
CircuitValidationError-- the circuit cannot be serialized or is not accepted by the target backend (unsupported gate, missing measurement, bad structure). - :class:
JobError-- a submitted job failed, was cancelled, or returned a result the client could not interpret.
APIError (raised for HTTP-level API responses) is reparented onto this
root in :mod:openquantum_sdk.models, so it too is an OpenQuantumError.
Simple argument validation (an empty backend, a bad export_format) stays a
plain :class:ValueError, matching normal Python convention.
AuthenticationError
¶
Bases: OpenQuantumError
Raised when credentials are missing or cannot authenticate the client.
CircuitValidationError
¶
Bases: OpenQuantumError
Raised when a circuit cannot be serialized or is rejected by the backend.
JobError
¶
Bases: OpenQuantumError
Raised when a job fails, is cancelled, or returns an unreadable result.
OpenQuantumError
¶
Bases: Exception
Base class for every error raised by the Open Quantum SDK and plugins.
Qiskit Plugin¶
QASM export¶
Public helper. Import export_circuit_to_qasm from openquantum_sdk_qiskit, not from the private _qasm module.
openquantum_sdk_qiskit.export_circuit_to_qasm(circuit, fmt, *, backend=None)
¶
Export a circuit to QASM, optionally validating against a backend first.
If backend is provided and has a validate_circuit method, it will be
called before export. This provides early, capability-aware rejection
(custom gates, shot limits when combined with higher-level callers, etc.).
OpenQuantumService¶
openquantum_sdk_qiskit.oq_service.OpenQuantumService
¶
Bases: OpenQuantumClient
Entry point for the OpenQuantum Qiskit plugin.
Inherits authentication, saved-account management, and backend/organization
discovery from
OpenQuantumClient, and adds
the Qiskit-specific factories: building a Qiskit Target or
BackendV2 for a device, and creating Sampler / Estimator primitives
that submit jobs to the OpenQuantum platform.
The service can be instantiated directly with a token or creds,
loaded from a saved account on disk, or created via the convenience
:meth:login classmethod. When neither token nor creds is supplied
the constructor attempts to auto-load the saved account named by
OPENQUANTUM_ACCOUNT_NAME (default "default"). If that account is
missing or cannot be loaded, it falls back to
:func:openquantum_sdk.credentials.resolve_env_credentials
(OPENQUANTUM_TOKEN, an SDK key file, or
OPENQUANTUM_CLIENT_ID + OPENQUANTUM_CLIENT_SECRET). Set
OPENQUANTUM_NO_AUTOLOAD=1 or auto_load=False to skip the saved
account and use only those environment credentials.
Use as a context manager to close HTTP sessions on exit.
Example
Attributes:
| Name | Type | Description |
|---|---|---|
management |
The underlying
|
|
scheduler |
The underlying
|
__init__(*, token=None, creds=None, keycloak_base=DEFAULT_KEYCLOAK_BASE, realm=DEFAULT_REALM, scheduler_url=DEFAULT_SCHEDULER_URL, management_url=DEFAULT_MANAGEMENT_URL, auto_load=True, account_name=None, accounts_file=None)
¶
return_backend(name, *, config=None, export_format='qasm3', verbose=None, job_timeout_seconds=None)
¶
Create an OpenQuantumBackend (Qiskit BackendV2) for name.
The returned backend works with Qiskit's transpiler and can submit
circuits via its :meth:~OpenQuantumBackend.run method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Backend identifier ( |
required |
config
|
Optional[Dict[str, Any]]
|
Optional platform submission metadata. |
None
|
export_format
|
str
|
|
'qasm3'
|
verbose
|
Optional[bool]
|
Print submission progress and the credit cost.
Defaults to |
None
|
job_timeout_seconds
|
Optional[int]
|
Maximum seconds to wait for a job to
complete. Defaults to |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If capabilities for the named backend cannot be found. |
return_target(name)
¶
Build a Qiskit Target for the named backend.
The Target describes the backend's native gate set, qubit count,
and coupling map, and is used by the Qiskit transpiler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Backend identifier ( |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If capabilities for the named backend cannot be found. |
create_sampler(*, backend, organization_id=None, job_subcategory_id='oth:oth', name=None, configuration_data=None, execution_plan='auto', queue_priority='auto', export_format='qasm3', verbose=None, job_timeout_seconds=None)
¶
Create an :class:OQSampler (Qiskit SamplerV2) backed by OpenQuantum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
'BackendV2'
|
A Qiskit |
required |
organization_id
|
Optional[str]
|
Billing organization UUID. Optional. |
None
|
job_subcategory_id
|
str
|
Workload subcategory (default |
'oth:oth'
|
name
|
Optional[str]
|
Job name prefix. |
None
|
configuration_data
|
Optional[Dict[str, Any]]
|
Provider-specific configuration passthrough. |
None
|
execution_plan
|
str
|
|
'auto'
|
queue_priority
|
str
|
|
'auto'
|
export_format
|
str
|
|
'qasm3'
|
verbose
|
Optional[bool]
|
Print submission progress and the credit cost.
When omitted, the backend's flag is used ( |
None
|
job_timeout_seconds
|
Optional[int]
|
Maximum seconds to wait for a job to
complete. When omitted, the backend's timeout is used
( |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If Qiskit is not installed. |
ValueError
|
If backend_class_id cannot be determined. |
create_estimator(*, backend, organization_id=None, job_subcategory_id='oth:oth', name=None, configuration_data=None, execution_plan='auto', queue_priority='auto', export_format='qasm3', verbose=None, job_timeout_seconds=None)
¶
Create an :class:OQEstimator (Qiskit EstimatorV2) backed by OpenQuantum.
Arguments mirror :meth:create_sampler.
Raises:
| Type | Description |
|---|---|
ImportError
|
If Qiskit is not installed. |
ValueError
|
If backend_class_id cannot be determined. |
OpenQuantumBackend¶
openquantum_sdk_qiskit.oq_backend.OpenQuantumBackend
¶
Bases: BackendV2
Qiskit BackendV2 implementation for the OpenQuantum platform.
Wraps the OpenQuantum scheduler so that circuits can be submitted
and results retrieved through the standard Qiskit backend interface.
The backend's Target (native gate set, coupling map, qubit
count) is derived from a capabilities dictionary that is either
supplied explicitly or resolved from built-in data.
This backend is typically obtained via
:meth:OpenQuantumService.return_backend rather than constructed
directly.
__init__(name, *, capabilities=None, scheduler=None, config=None, export_format='qasm3', configuration_schema=None, verbose=None, job_timeout_seconds=None, **kwargs)
¶
Initialise the backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Backend identifier used for capabilities lookup and as the Qiskit backend name. |
required |
capabilities
|
Optional[Dict[str, Any]]
|
Hardware capabilities dictionary describing
qubit count, native gates, and topology. When |
None
|
scheduler
|
Optional[SchedulerClient]
|
A
:class: |
None
|
config
|
Optional[Dict[str, Any]]
|
Optional platform submission metadata for the
backend. |
None
|
export_format
|
str
|
Circuit serialisation format -- |
'qasm3'
|
configuration_schema
|
Optional[Dict[str, Any]]
|
BackendClass.configuration_schema from
the platform API. Property defaults become Qiskit
|
None
|
verbose
|
Optional[bool]
|
Print submission progress and the credit cost.
Defaults to |
None
|
job_timeout_seconds
|
Optional[int]
|
Maximum seconds to wait for a job to
complete. Defaults to |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
run(circuits, /, *, job_subcategory_id=None, backend_class_id=None, organization_id=None, name=None, configuration_data=None, execution_plan=None, queue_priority=None, **run_options)
¶
Submit one or more circuits to the OpenQuantum platform.
Each circuit is serialised to QASM, submitted to the scheduler,
and the results are downloaded synchronously. The method
returns immediately with a job-like wrapper around the
collected Result.
Job submission metadata (job_subcategory_id, etc.) can be supplied here at the point of job creation, or as defaults via the config passed to the backend constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
circuits
|
Iterable[Any]
|
A single |
required |
job_subcategory_id
|
Optional[str]
|
Workload subcategory for this job.
Defaults to |
None
|
backend_class_id
|
Optional[str]
|
Override for the target backend class. Defaults to the value derived at backend construction (usually the name passed to return_backend). |
None
|
organization_id
|
Optional[str]
|
Override organization for billing. |
None
|
name
|
Optional[str]
|
Job name prefix for this submission. |
None
|
configuration_data
|
Optional[Dict[str, Any]]
|
Per-job configuration data. |
None
|
execution_plan, queue_priority
|
Scheduling overrides for this job. |
required | |
**run_options
|
Other options including:
|
{}
|
Returns:
| Type | Description |
|---|---|
|
A job-like object whose |
|
|
Qiskit |
|
|
submitted circuit. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no |
ValueError
|
If |
OQSampler (SamplerV2)¶
openquantum_sdk_qiskit.oq_sampler.OQSampler
¶
Bases: BaseSamplerV2
Qiskit SamplerV2 implementation backed by the OpenQuantum platform.
Submits sampling PUBs (Primitive Unified Blocs) to the OpenQuantum
scheduler and returns results using Qiskit's primitives containers
(DataBin, BitArray, SamplerPubResult, PrimitiveResult).
Typically obtained via
:meth:OpenQuantumService.create_sampler rather than constructed
directly.
Example
__init__(*, backend, options=None, scheduler=None, config=None, export_format='qasm3', verbose=None, job_timeout_seconds=None)
¶
Initialise the sampler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
BackendV2
|
A Qiskit |
required |
options
|
Optional[dict]
|
Primitive options dict (currently unused, reserved for future use). |
None
|
scheduler
|
Optional[SchedulerClient]
|
A
:class: |
None
|
config
|
Optional[Dict[str, Any]]
|
Platform submission metadata for this sampler
( |
None
|
export_format
|
str
|
Circuit serialisation format -- |
'qasm3'
|
verbose
|
Optional[bool]
|
Print submission progress and the credit cost.
Defaults to the backend's |
None
|
job_timeout_seconds
|
Optional[int]
|
Maximum seconds to wait for a job to
complete. Defaults to the backend's timeout when that
attribute is an int, otherwise |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
run(pubs, *, shots=None, export_format=None)
¶
Submit sampling PUBs to the OpenQuantum platform.
Each PUB's circuit is serialised, parameter-bound, and
submitted to the scheduler. Results are collected and returned
as Qiskit SamplerPubResult objects containing BitArray
measurement data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pubs
|
Iterable[SamplerPubLike]
|
One or more sampler PUBs. Each element can be a
|
required |
shots
|
int | None
|
Number of measurement shots per PUB. Overrides the
shot count embedded in each PUB. Defaults to |
None
|
export_format
|
Optional[str]
|
Override the sampler's default circuit
serialisation format ( |
None
|
Returns:
| Type | Description |
|---|---|
PrimitiveJob[PrimitiveResult[SamplerPubResult]]
|
A |
PrimitiveJob[PrimitiveResult[SamplerPubResult]]
|
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no |
ValueError
|
If |
OQEstimator (EstimatorV2)¶
openquantum_sdk_qiskit.oq_estimator.OQEstimator
¶
Bases: BaseEstimatorV2
Qiskit EstimatorV2 implementation backed by the OpenQuantum platform.
Computes expectation values of observables by delegating to Qiskit's
BackendEstimatorV2 with an :class:OpenQuantumBackend that
submits circuits to the OpenQuantum scheduler.
Typically obtained via
:meth:OpenQuantumService.create_estimator rather than constructed
directly.
Example
__init__(*, backend, options=None, scheduler=None, config=None, export_format='qasm3', verbose=None, job_timeout_seconds=None)
¶
Initialise the estimator.
Internally creates a shallow copy of the supplied backend
and injects the scheduler and config into it, then
wraps it with Qiskit's BackendEstimatorV2 to handle
observable decomposition and expectation-value computation.
The backend proxy's run method is patched to fully transpile
measurement-basis circuits into the device native gate set
before submission (see module-level note on BackendEstimatorV2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
BackendV2
|
A Qiskit |
required |
options
|
Optional[dict]
|
Options forwarded to the underlying
|
None
|
scheduler
|
Optional[SchedulerClient]
|
A
:class: |
None
|
config
|
Optional[Dict[str, Any]]
|
Platform submission metadata (derived
|
None
|
export_format
|
str
|
Circuit serialisation format -- |
'qasm3'
|
verbose
|
Optional[bool]
|
Print submission progress and the credit cost on the
jobs this estimator submits. When omitted, the backend's
own |
None
|
job_timeout_seconds
|
Optional[int]
|
Maximum seconds to wait for each job.
When omitted, the backend's timeout is kept ( |
None
|
run(pubs, *, precision=None)
¶
Estimate expectation values for one or more PUBs.
Delegates to the internal BackendEstimatorV2 which
decomposes observables, executes the required circuits on the
OpenQuantum backend, and combines shot results into
expectation-value estimates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pubs
|
Iterable[EstimatorPubLike]
|
One or more estimator PUBs. Each element can be an
|
required |
precision
|
float | None
|
Target precision for the expectation-value
estimates. When |
None
|
Returns:
| Type | Description |
|---|---|
PrimitiveJob[PrimitiveResult[PubResult]]
|
A |
PrimitiveJob[PrimitiveResult[PubResult]]
|
|
PrimitiveJob[PrimitiveResult[PubResult]]
|
values and standard errors. |
PennyLane Plugin¶
Device¶
pennylane_openquantum.device.OpenQuantumDevice
¶
Bases: Device
PennyLane device for the OpenQuantum quantum computing platform.
Authenticates via one of three methods (checked in order):
1. A pre-built OpenQuantumClient passed as client.
2. A bearer token (e.g. from OPENQUANTUM_TOKEN).
3. client_id + client_secret for the OAuth2 client-credentials
flow (env vars OPENQUANTUM_CLIENT_ID / OPENQUANTUM_CLIENT_SECRET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
int | list[int]
|
Number of qubits or iterable of wire labels. |
required |
shots
|
int | None
|
Number of measurement shots (required). |
None
|
backend
|
str
|
Backend class ID or short_code (e.g. |
''
|
auto_confirm
|
bool
|
If |
False
|
client
|
OpenQuantumClient | None
|
Pre-built |
None
|
token
|
str | None
|
Bearer token for the API. Falls back to |
None
|
client_id
|
str | None
|
OAuth2 client ID. Falls back to |
None
|
client_secret
|
str | None
|
OAuth2 client secret. Falls back to
|
None
|
organization_id
|
str | None
|
Organization UUID. Falls back to
|
None
|
scheduler_url
|
str | None
|
Scheduler API base URL. |
None
|
management_url
|
str | None
|
Management API base URL. |
None
|
keycloak_base
|
str | None
|
Keycloak base URL for OAuth2. |
None
|
realm
|
str | None
|
Keycloak realm name. |
None
|
job_subcategory_id
|
str
|
Job subcategory ID or short_code. |
'oth:oth'
|
execution_plan
|
str
|
|
'auto'
|
queue_priority
|
str
|
|
'auto'
|
verbose
|
bool
|
Print submission progress and the credit cost. Defaults
to |
False
|
job_timeout_seconds
|
int
|
Maximum time to wait for job completion. |
86400
|
__init__(wires, shots=None, backend='', *, auto_confirm=False, client=None, token=None, client_id=None, client_secret=None, organization_id=None, scheduler_url=None, management_url=None, keycloak_base=None, realm=None, job_subcategory_id='oth:oth', execution_plan='auto', queue_priority='auto', configuration_data=None, verbose=False, job_timeout_seconds=86400)
¶
execute(circuits, execution_config=ExecutionConfig())
¶
Execute one or more circuits on the OpenQuantum platform.
Before submitting: - Checks the target backend status and queue depth. - If the backend is offline or not accepting jobs, shows online alternatives and prompts for confirmation. - Prints a live updating status line during job execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
circuits
|
QuantumScript | list[QuantumScript]
|
A single tape or list of tapes to execute. |
required |
execution_config
|
ExecutionConfig
|
Execution configuration. |
ExecutionConfig()
|
Returns:
| Type | Description |
|---|---|
Union[tuple, list[tuple]]
|
Results for each circuit. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the user declines or a job fails. |
preprocess(execution_config=ExecutionConfig())
¶
Build the preprocessing transform program.
QASM Serializer¶
pennylane_openquantum.qasm_serializer
¶
PennyLane tape to OpenQASM 2.0 serialization.
This module converts PennyLane quantum tapes into OpenQASM 2.0 program
strings. It uses OPERATION_MAP to translate PennyLane gate names
(e.g. "PauliX", "CNOT") to their OpenQASM 2.0 gate identifiers
(e.g. "x", "cx").
When backend capabilities are provided, gates that the backend supports
are emitted directly without inline definitions. Otherwise, gates not
known by the backend parser are emitted as inline gate definitions
in terms of u1/u2/u3/cx/ccx.
OPERATION_MAP = {'PauliX': 'x', 'PauliY': 'y', 'PauliZ': 'z', 'Hadamard': 'h', 'CNOT': 'cx', 'CZ': 'cz', 'SWAP': 'swap', 'RX': 'rx', 'RY': 'ry', 'RZ': 'rz', 'PhaseShift': 'p', 'S': 's', 'T': 't', 'SX': 'sx', 'Toffoli': 'ccx', 'CSWAP': 'cswap', 'CRX': 'crx', 'CRY': 'cry', 'CRZ': 'crz', 'Identity': 'id'}
module-attribute
¶
circuit_to_qasm(tape, num_wires, capabilities=None)
¶
Convert a PennyLane tape to an OpenQASM 2.0 string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tape
|
QuantumScript
|
A PennyLane QuantumScript/tape containing operations. |
required |
num_wires
|
int
|
The number of qubits in the circuit. |
required |
capabilities
|
BackendCapabilities | None
|
Optional backend capabilities. When provided, gates the backend supports are emitted directly without inline definitions, producing cleaner QASM. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A valid OpenQASM 2.0 program string. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unsupported operation is encountered. |
Exceptions¶
pennylane_openquantum.exceptions
¶
Custom exception classes for the Open Quantum PennyLane plugin.
OpenQuantumCircuitError
¶
Bases: OpenQuantumDeviceError
Raised when circuit serialization or validation fails.
Common causes include unsupported gate operations or invalid circuit structure that cannot be converted to OpenQASM 2.0.
OpenQuantumDeviceError
¶
Bases: OpenQuantumError
Base exception for Open Quantum PennyLane device errors.
Raised for device-level issues such as invalid device configuration.
Missing credentials raise
:class:openquantum_sdk.exceptions.AuthenticationError instead, matching
the other plugins. Subclasses
:class:openquantum_sdk.exceptions.OpenQuantumError, so callers can catch
any Open Quantum failure uniformly.
Cirq Plugin¶
OpenQuantumSampler¶
cirq_openquantum.sampler.OpenQuantumSampler
¶
Bases: Sampler
Cirq sampler that executes circuits on the Open Quantum platform.
Use it anywhere a cirq.Sampler is accepted::
sampler = OpenQuantumSampler(
backend="qr:gpu-gb10",
configuration_data={"engine": "amber_quantum_rings"},
)
result = sampler.run(circuit, repetitions=1024)
print(result.histogram(key="m"))
Authentication mirrors the other Open Quantum plugins and is resolved in this order:
- A pre-built :class:
openquantum_sdk.OpenQuantumClientpassed asclient(full control over auth, URLs, saved accounts). - A bearer
token(falls back toOPENQUANTUM_TOKEN). client_id+client_secretfor the OAuth2 client-credentials flow (fall back toOPENQUANTUM_CLIENT_ID/OPENQUANTUM_CLIENT_SECRET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
str
|
Backend class ID or short_code (e.g. |
required |
client
|
Optional[Any]
|
Pre-built |
None
|
token
|
Optional[str]
|
Bearer token for the API. Falls back to |
None
|
client_id
|
Optional[str]
|
OAuth2 client ID. Falls back to |
None
|
client_secret
|
Optional[str]
|
OAuth2 client secret. Falls back to
|
None
|
organization_id
|
Optional[str]
|
Organization UUID. Falls back to
|
None
|
scheduler_url
|
Optional[str]
|
Scheduler API base URL. |
None
|
management_url
|
Optional[str]
|
Management API base URL. |
None
|
keycloak_base
|
Optional[str]
|
Keycloak base URL for OAuth2. |
None
|
realm
|
Optional[str]
|
Keycloak realm name. |
None
|
job_subcategory_id
|
str
|
Job subcategory ID or short_code (default
|
'oth:oth'
|
execution_plan
|
str
|
|
'auto'
|
queue_priority
|
str
|
|
'auto'
|
export_format
|
str
|
Circuit serialisation format, |
'qasm3'
|
configuration_data
|
Optional[Dict[str, Any]]
|
Backend-specific configuration passthrough (e.g.
|
None
|
reverse_bits
|
bool
|
Reverse the bit order of returned bitstrings. The
platform returns counts little-endian (the first classical bit is
the rightmost character, Qiskit-style), while Cirq is big-endian
(the first measured qubit is the most-significant bit). The default
( |
True
|
verbose
|
bool
|
Print submission progress and the credit cost to stdout.
Defaults to |
False
|
job_timeout_seconds
|
int
|
Maximum seconds to wait for a job to complete
(default |
86400
|
backend
property
¶
Alias for :attr:backend_class_id (matches the other plugins).
backend_class_id
property
¶
The Open Quantum backend class ID or short_code this sampler targets.
run_sweep(program, params, repetitions=1)
¶
Submit a circuit once per parameter resolver and collect results.
Implementing run_sweep gives run, sample, run_async, and
run_batch for free (Cirq's Sampler routes them all here).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
program
|
AbstractCircuit
|
The circuit to run. Must contain at least one measurement. |
required |
params
|
Sweepable
|
A |
required |
repetitions
|
int
|
Shot count per resolver. |
1
|
Returns:
| Type | Description |
|---|---|
Sequence[Result]
|
One |
Result Helpers¶
cirq_openquantum.result.result_from_counts(counts, circuit, params=None, *, reverse_bits=False, qasm=None)
¶
Reconstruct a cirq.ResultDict from a platform counts histogram.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
counts
|
Mapping[str, int]
|
|
required |
circuit
|
The resolved |
required | |
params
|
The |
None
|
|
reverse_bits
|
bool
|
Reverse each platform bitstring before mapping. The
platform returns counts little-endian (classical bit 0 is the
rightmost character), so this must be |
False
|
qasm
|
Optional[str]
|
The exact OpenQASM submitted for this circuit. When omitted it is
regenerated with |
None
|
Returns:
| Type | Description |
|---|---|
|
A |
|
|
|
Qrisp Plugin¶
OpenQuantumBackend¶
qrisp_openquantum.backend.OpenQuantumBackend
¶
Bases: Backend
Qrisp backend that executes circuits on the Open Quantum platform.
Pass an instance to any Qrisp execution call, e.g.
qv.get_measurement(backend=oq, shots=1024) or
qc.run(backend=oq, shots=1024).
Authentication mirrors the other Open Quantum plugins and is resolved in this order:
- A pre-built :class:
openquantum_sdk_qiskit.OpenQuantumServicepassed asservice(full control over auth, URLs, saved accounts). - A bearer
token(falls back toOPENQUANTUM_TOKEN). client_id+client_secretfor the OAuth2 client-credentials flow (fall back toOPENQUANTUM_CLIENT_ID/OPENQUANTUM_CLIENT_SECRET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
str
|
Backend class ID or short_code (e.g. |
required |
shots
|
int
|
Default shot count used when a Qrisp call does not specify one. |
1024
|
service
|
Optional[Any]
|
Pre-built |
None
|
token
|
Optional[str]
|
Bearer token for the API. Falls back to |
None
|
client_id
|
Optional[str]
|
OAuth2 client ID. Falls back to |
None
|
client_secret
|
Optional[str]
|
OAuth2 client secret. Falls back to
|
None
|
organization_id
|
Optional[str]
|
Organization UUID. Falls back to
|
None
|
scheduler_url
|
Optional[str]
|
Scheduler API base URL. |
None
|
management_url
|
Optional[str]
|
Management API base URL. |
None
|
keycloak_base
|
Optional[str]
|
Keycloak base URL for OAuth2. |
None
|
realm
|
Optional[str]
|
Keycloak realm name. |
None
|
job_subcategory_id
|
str
|
Job subcategory ID or short_code (default
|
'oth:oth'
|
execution_plan
|
str
|
|
'auto'
|
queue_priority
|
str
|
|
'auto'
|
export_format
|
str
|
Circuit serialisation format, |
'qasm3'
|
configuration_data
|
Optional[Dict[str, Any]]
|
Backend-specific configuration passthrough (e.g.
|
None
|
reverse_bits
|
bool
|
Reverse the bit order of returned bitstrings. The default
( |
False
|
name
|
Optional[str]
|
Optional Qrisp backend name (defaults to |
None
|
verbose
|
bool
|
Print submission progress and the credit cost to stdout.
Defaults to |
False
|
job_timeout_seconds
|
int
|
Maximum seconds to wait for a job to complete
(default |
86400
|
backend
property
¶
Alias for :attr:backend_class_id (matches the other plugins).
backend_class_id
property
¶
The Open Quantum backend class ID or short_code targeted by this backend.
run_async(circuits, shots=None)
¶
Submit one or more Qrisp circuits and return a completed job.
Each circuit is converted to a Qiskit circuit, validated against the backend's capabilities, serialised to QASM, and submitted to the platform synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
circuits
|
A single Qrisp |
required | |
shots
|
Union[int, List[int], None]
|
Shot count. An |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
An |
OpenQuantumJob
|
class: |
OpenQuantumJob¶
qrisp_openquantum.job.OpenQuantumJob
¶
Bases: Job
A completed Open Quantum job wrapping one counts dict per circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
The :class: |
required | |
counts
|
Sequence[dict]
|
One |
required |
job_id
|
str | None
|
Optional platform job identifier (the id of the last submitted circuit, for reference). |
None
|