Native Qiskit API Reference¶
This page is generated from Python docstrings in
qcsc_prefect.integrations.qiskit.
Configuration¶
qcsc_prefect.integrations.qiskit.blocks.QiskitRuntimeConfig ¶
Bases: Block
Configuration needed to create native Qiskit Runtime objects.
The block stores only the configuration needed to construct native
qiskit_ibm_runtime objects. It does not reimplement Runtime behavior.
If token is not set, Qiskit's normal saved account file and environment
variable discovery are used.
get_service ¶
get_service() -> QiskitRuntimeService
Create a native QiskitRuntimeService from configured fields.
Returns:
| Type | Description |
|---|---|
QiskitRuntimeService
|
A native |
Raises:
| Type | Description |
|---|---|
QiskitRuntimeConfigError
|
If the service cannot be created. |
get_backend ¶
get_backend() -> Any
Return the configured backend from the native Qiskit service.
Returns:
| Type | Description |
|---|---|
Any
|
The native backend returned by |
Raises:
| Type | Description |
|---|---|
QiskitRuntimeConfigError
|
If the service or backend cannot be created. |
Wrapper Classes¶
qcsc_prefect.integrations.qiskit.wrappers.QCSCSamplerV2 ¶
QCSCSamplerV2(
*,
runtime_block_name: str | None = None,
runtime_config: QiskitRuntimeConfig | None = None,
options: Mapping[str, Any] | None = None,
backend_name: str | None = None,
)
Thin SamplerV2-style facade backed by native Qiskit Prefect tasks.
QCSCSamplerV2 keeps runtime configuration and delegates execution to the
Native Qiskit Prefect task API. It does not subclass or reimplement Qiskit's
SamplerV2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runtime_block_name
|
str | None
|
Name of a saved |
None
|
runtime_config
|
QiskitRuntimeConfig | None
|
Inline runtime configuration. Mutually exclusive with
|
None
|
options
|
Mapping[str, Any] | None
|
Default native Qiskit Sampler options. |
None
|
backend_name
|
str | None
|
Optional backend name used only for submit cache input
digest construction when it cannot be inferred from
|
None
|
run_and_fetch
async
¶
run_and_fetch(
pubs: Iterable[Any],
*,
shots: int | None = None,
artifact_key: str | None = None,
options: Mapping[str, Any] | None = None,
robust: bool = True,
cache_submit: bool = False,
cache_result: bool = False,
retry_fetch: bool = False,
cache_scope: str = "flow",
cache_namespace: str | None = None,
cache_expiration: timedelta | None = None,
input_digest: str | None = None,
) -> dict[str, Any]
Submit Sampler pubs and fetch the completed task output.
With robust=True this method submits a native Qiskit Runtime job,
fetches the same job by ID, records artifacts and returns the full task
output. With robust=False it delegates to run_sampler_task.
Use :meth:run when you want the Native Qiskit-style API that returns a
job handle first, then call job.result() or job.output().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pubs
|
Iterable[Any]
|
Native Qiskit Sampler pubs. |
required |
shots
|
int | None
|
Optional number of shots passed to |
None
|
artifact_key
|
str | None
|
Optional Prefect artifact key prefix. |
None
|
options
|
Mapping[str, Any] | None
|
Optional Sampler options for this call. Replaces wrapper default options when provided. |
None
|
robust
|
bool
|
Use split submit/fetch mode. Required for cache and retry flags. |
True
|
cache_submit
|
bool
|
Cache the submit task result to avoid duplicate job submission for the same input digest. |
False
|
cache_result
|
bool
|
Persist fetched results with Prefect result caching, keyed by Qiskit Runtime job ID. |
False
|
retry_fetch
|
bool
|
Retry transient failures while fetching the existing job result. |
False
|
cache_scope
|
str
|
Input digest scope used when |
'flow'
|
cache_namespace
|
str | None
|
Optional namespace included in the input digest. |
None
|
cache_expiration
|
timedelta | None
|
Optional Prefect cache expiration for submit caching. |
None
|
input_digest
|
str | None
|
Optional precomputed digest for submit caching. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The structured dictionary returned by the underlying run or fetch |
dict[str, Any]
|
task. The native Qiskit result is available as |
run
async
¶
run(
pubs: Iterable[Any],
*,
shots: int | None = None,
artifact_key: str | None = None,
options: Mapping[str, Any] | None = None,
cache_submit: bool = False,
cache_result: bool = False,
retry_fetch: bool = False,
cache_scope: str = "flow",
cache_namespace: str | None = None,
cache_expiration: timedelta | None = None,
input_digest: str | None = None,
) -> QCSCPrimitiveJob
Submit a Sampler job and return a job-like fetch handle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pubs
|
Iterable[Any]
|
Native Qiskit Sampler pubs. |
required |
shots
|
int | None
|
Optional number of shots passed to |
None
|
artifact_key
|
str | None
|
Optional Prefect artifact key prefix used when fetching results. |
None
|
options
|
Mapping[str, Any] | None
|
Optional Sampler options for this call. |
None
|
cache_submit
|
bool
|
Cache the submit task result to avoid duplicate job submission for the same input digest. |
False
|
cache_result
|
bool
|
Persist fetched results with Prefect result caching
when |
False
|
retry_fetch
|
bool
|
Retry transient failures during |
False
|
cache_scope
|
str
|
Input digest scope used when |
'flow'
|
cache_namespace
|
str | None
|
Optional namespace included in the input digest. |
None
|
cache_expiration
|
timedelta | None
|
Optional Prefect cache expiration for submit caching. |
None
|
input_digest
|
str | None
|
Optional precomputed digest for submit caching. |
None
|
Returns:
| Type | Description |
|---|---|
QCSCPrimitiveJob
|
A |
QCSCPrimitiveJob
|
Qiskit primitive result. |
qcsc_prefect.integrations.qiskit.wrappers.QCSCEstimatorV2 ¶
QCSCEstimatorV2(
*,
runtime_block_name: str | None = None,
runtime_config: QiskitRuntimeConfig | None = None,
options: Mapping[str, Any] | None = None,
backend_name: str | None = None,
)
Thin EstimatorV2-style facade backed by native Qiskit Prefect tasks.
QCSCEstimatorV2 mirrors :class:QCSCSamplerV2 for Estimator pubs. It
delegates to native Qiskit Runtime task helpers and does not subclass or
reimplement Qiskit's EstimatorV2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runtime_block_name
|
str | None
|
Name of a saved |
None
|
runtime_config
|
QiskitRuntimeConfig | None
|
Inline runtime configuration. Mutually exclusive with
|
None
|
options
|
Mapping[str, Any] | None
|
Default native Qiskit Estimator options. |
None
|
backend_name
|
str | None
|
Optional backend name used only for submit cache input
digest construction when it cannot be inferred from
|
None
|
run_and_fetch
async
¶
run_and_fetch(
pubs: Iterable[Any],
*,
precision: float | None = None,
artifact_key: str | None = None,
options: Mapping[str, Any] | None = None,
robust: bool = True,
cache_submit: bool = False,
cache_result: bool = False,
retry_fetch: bool = False,
cache_scope: str = "flow",
cache_namespace: str | None = None,
cache_expiration: timedelta | None = None,
input_digest: str | None = None,
) -> dict[str, Any]
Submit Estimator pubs and fetch the completed task output.
With robust=True this method submits a native Qiskit Runtime job,
fetches the same job by ID, records artifacts and returns the full task
output. With robust=False it delegates to run_estimator_task.
Use :meth:run when you want the Native Qiskit-style API that returns a
job handle first, then call job.result() or job.output().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pubs
|
Iterable[Any]
|
Native Qiskit Estimator pubs. |
required |
precision
|
float | None
|
Optional target precision passed to |
None
|
artifact_key
|
str | None
|
Optional Prefect artifact key prefix. |
None
|
options
|
Mapping[str, Any] | None
|
Optional Estimator options for this call. Replaces wrapper default options when provided. |
None
|
robust
|
bool
|
Use split submit/fetch mode. Required for cache and retry flags. |
True
|
cache_submit
|
bool
|
Cache the submit task result to avoid duplicate job submission for the same input digest. |
False
|
cache_result
|
bool
|
Persist fetched results with Prefect result caching, keyed by Qiskit Runtime job ID. |
False
|
retry_fetch
|
bool
|
Retry transient failures while fetching the existing job result. |
False
|
cache_scope
|
str
|
Input digest scope used when |
'flow'
|
cache_namespace
|
str | None
|
Optional namespace included in the input digest. |
None
|
cache_expiration
|
timedelta | None
|
Optional Prefect cache expiration for submit caching. |
None
|
input_digest
|
str | None
|
Optional precomputed digest for submit caching. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The structured dictionary returned by the underlying run or fetch |
dict[str, Any]
|
task. The native Qiskit result is available as |
run
async
¶
run(
pubs: Iterable[Any],
*,
precision: float | None = None,
artifact_key: str | None = None,
options: Mapping[str, Any] | None = None,
cache_submit: bool = False,
cache_result: bool = False,
retry_fetch: bool = False,
cache_scope: str = "flow",
cache_namespace: str | None = None,
cache_expiration: timedelta | None = None,
input_digest: str | None = None,
) -> QCSCPrimitiveJob
Submit an Estimator job and return a job-like fetch handle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pubs
|
Iterable[Any]
|
Native Qiskit Estimator pubs. |
required |
precision
|
float | None
|
Optional target precision passed to |
None
|
artifact_key
|
str | None
|
Optional Prefect artifact key prefix used when fetching results. |
None
|
options
|
Mapping[str, Any] | None
|
Optional Estimator options for this call. |
None
|
cache_submit
|
bool
|
Cache the submit task result to avoid duplicate job submission for the same input digest. |
False
|
cache_result
|
bool
|
Persist fetched results with Prefect result caching
when |
False
|
retry_fetch
|
bool
|
Retry transient failures during |
False
|
cache_scope
|
str
|
Input digest scope used when |
'flow'
|
cache_namespace
|
str | None
|
Optional namespace included in the input digest. |
None
|
cache_expiration
|
timedelta | None
|
Optional Prefect cache expiration for submit caching. |
None
|
input_digest
|
str | None
|
Optional precomputed digest for submit caching. |
None
|
Returns:
| Type | Description |
|---|---|
QCSCPrimitiveJob
|
A |
QCSCPrimitiveJob
|
Qiskit primitive result. |
qcsc_prefect.integrations.qiskit.wrappers.QCSCPrimitiveJob ¶
QCSCPrimitiveJob(
*,
job_reference: Mapping[str, Any],
runtime_block_name: str | None,
runtime_config: QiskitRuntimeConfig | None,
pubs: Iterable[Any],
artifact_key: str | None,
options: Mapping[str, Any] | None,
cache_result: bool,
retry_fetch: bool,
)
Job-like handle for split native Qiskit submit/fetch execution.
The handle is returned by :meth:QCSCSamplerV2.run and
:meth:QCSCEstimatorV2.run. It stores a serializable Qiskit Runtime job
reference and fetches the existing job through fetch_qiskit_job_result_task.
This is not a native Qiskit RuntimeJobV2. It is a small Prefect-facing
facade that exposes the most common job.result() style workflow while
preserving qcsc-prefect metadata and artifact behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_reference
|
Mapping[str, Any]
|
Serializable reference returned by a submit task. |
required |
runtime_block_name
|
str | None
|
Optional saved |
required |
runtime_config
|
QiskitRuntimeConfig | None
|
Optional inline runtime configuration object. |
required |
pubs
|
Iterable[Any]
|
Native Qiskit pubs used for metadata extraction during fetch. |
required |
artifact_key
|
str | None
|
Optional Prefect artifact key prefix. |
required |
options
|
Mapping[str, Any] | None
|
Optional native Qiskit primitive options. |
required |
cache_result
|
bool
|
Persist fetched results with Prefect result caching. |
required |
retry_fetch
|
bool
|
Retry transient failures while fetching the existing job. |
required |
job_reference
property
¶
job_reference: dict[str, Any]
Return a copy of the serializable Qiskit Runtime job reference.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A copy of the submit task job reference dictionary. |
job_id ¶
job_id() -> str | None
Return the native Qiskit Runtime job ID when available.
Returns:
| Type | Description |
|---|---|
str | None
|
The Qiskit Runtime job ID, or |
str | None
|
contain one. |
output
async
¶
output() -> dict[str, Any]
Fetch and return the full qcsc-prefect task output dictionary.
The first call fetches the native Qiskit Runtime job by ID. Later calls
on the same handle reuse the in-memory output. When cache_result is
enabled, Prefect can also restore the output from result storage across
reruns that use the same Qiskit job ID.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The structured dictionary returned by |
dict[str, Any]
|
|
dict[str, Any]
|
|
result
async
¶
result() -> Any
Fetch and return the native Qiskit primitive result object.
Returns:
| Type | Description |
|---|---|
Any
|
The native Qiskit primitive result stored in |
Task API¶
qcsc_prefect.integrations.qiskit.tasks.run_sampler_task
async
¶
run_sampler_task(
pubs: Iterable[Any],
runtime_block_name: str | None = None,
shots: int | None = None,
artifact_key: str | None = None,
options: dict[str, Any] | None = None,
runtime_config: QiskitRuntimeConfig | None = None,
*,
input_digest: str | None = None,
) -> dict[str, Any]
Run native Qiskit Runtime SamplerV2 inside a Prefect task.
This is the simple one-task execution path. It submits a Qiskit Runtime job, waits for the result, records artifacts and returns the result dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pubs
|
Iterable[Any]
|
Native Qiskit Sampler pubs. |
required |
runtime_block_name
|
str | None
|
Name of a saved |
None
|
shots
|
int | None
|
Optional number of shots passed to |
None
|
artifact_key
|
str | None
|
Optional Prefect artifact key prefix. |
None
|
options
|
dict[str, Any] | None
|
Optional native Qiskit Sampler options. |
None
|
runtime_config
|
QiskitRuntimeConfig | None
|
Inline runtime configuration. Mutually exclusive with
|
None
|
input_digest
|
str | None
|
Optional input digest included in collected metadata. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A structured dictionary containing primitive, backend name, job ID, |
dict[str, Any]
|
shots, native Qiskit result and collected metadata. |
qcsc_prefect.integrations.qiskit.tasks.run_estimator_task
async
¶
run_estimator_task(
pubs: Iterable[Any],
runtime_block_name: str | None = None,
precision: float | None = None,
artifact_key: str | None = None,
options: dict[str, Any] | None = None,
runtime_config: QiskitRuntimeConfig | None = None,
*,
input_digest: str | None = None,
) -> dict[str, Any]
Run native Qiskit Runtime EstimatorV2 inside a Prefect task.
This is the simple one-task execution path. It submits a Qiskit Runtime job, waits for the result, records artifacts and returns the result dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pubs
|
Iterable[Any]
|
Native Qiskit Estimator pubs. |
required |
runtime_block_name
|
str | None
|
Name of a saved |
None
|
precision
|
float | None
|
Optional target precision passed to |
None
|
artifact_key
|
str | None
|
Optional Prefect artifact key prefix. |
None
|
options
|
dict[str, Any] | None
|
Optional native Qiskit Estimator options. |
None
|
runtime_config
|
QiskitRuntimeConfig | None
|
Inline runtime configuration. Mutually exclusive with
|
None
|
input_digest
|
str | None
|
Optional input digest included in collected metadata. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A structured dictionary containing primitive, backend name, job ID, |
dict[str, Any]
|
precision, native Qiskit result and collected metadata. |
qcsc_prefect.integrations.qiskit.tasks.submit_sampler_job_task
async
¶
submit_sampler_job_task(
pubs: Iterable[Any],
runtime_block_name: str | None = None,
shots: int | None = None,
options: dict[str, Any] | None = None,
runtime_config: QiskitRuntimeConfig | None = None,
*,
input_digest: str | None = None,
) -> QiskitJobReference
Submit a native Qiskit Runtime SamplerV2 job without waiting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pubs
|
Iterable[Any]
|
Native Qiskit Sampler pubs. |
required |
runtime_block_name
|
str | None
|
Name of a saved |
None
|
shots
|
int | None
|
Optional number of shots passed to |
None
|
options
|
dict[str, Any] | None
|
Optional native Qiskit Sampler options. |
None
|
runtime_config
|
QiskitRuntimeConfig | None
|
Inline runtime configuration. Mutually exclusive with
|
None
|
input_digest
|
str | None
|
Optional stable digest used by submit cache helpers. |
None
|
Returns:
| Type | Description |
|---|---|
QiskitJobReference
|
A serializable job reference containing primitive, backend, job ID and |
QiskitJobReference
|
optional execution settings. |
qcsc_prefect.integrations.qiskit.tasks.submit_estimator_job_task
async
¶
submit_estimator_job_task(
pubs: Iterable[Any],
runtime_block_name: str | None = None,
precision: float | None = None,
options: dict[str, Any] | None = None,
runtime_config: QiskitRuntimeConfig | None = None,
*,
input_digest: str | None = None,
) -> QiskitJobReference
Submit a native Qiskit Runtime EstimatorV2 job without waiting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pubs
|
Iterable[Any]
|
Native Qiskit Estimator pubs. |
required |
runtime_block_name
|
str | None
|
Name of a saved |
None
|
precision
|
float | None
|
Optional target precision passed to |
None
|
options
|
dict[str, Any] | None
|
Optional native Qiskit Estimator options. |
None
|
runtime_config
|
QiskitRuntimeConfig | None
|
Inline runtime configuration. Mutually exclusive with
|
None
|
input_digest
|
str | None
|
Optional stable digest used by submit cache helpers. |
None
|
Returns:
| Type | Description |
|---|---|
QiskitJobReference
|
A serializable job reference containing primitive, backend, job ID and |
QiskitJobReference
|
optional execution settings. |
qcsc_prefect.integrations.qiskit.tasks.fetch_qiskit_job_result_task
async
¶
fetch_qiskit_job_result_task(
runtime_block_name: str | None = None,
job_id: str | None = None,
job_reference: Mapping[str, Any] | None = None,
pubs: Iterable[Any] | None = None,
primitive: str | None = None,
backend_name: str | None = None,
shots: int | None = None,
precision: float | None = None,
artifact_key: str | None = None,
options: dict[str, Any] | None = None,
runtime_config: QiskitRuntimeConfig | None = None,
) -> dict[str, Any]
Fetch an existing native Qiskit Runtime job and collect its result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runtime_block_name
|
str | None
|
Name of a saved |
None
|
job_id
|
str | None
|
Qiskit Runtime job ID. Optional when |
None
|
job_reference
|
Mapping[str, Any] | None
|
Reference returned by |
None
|
pubs
|
Iterable[Any] | None
|
Original native Qiskit pubs used for best-effort metadata. |
None
|
primitive
|
str | None
|
Optional primitive type when not present in
|
None
|
backend_name
|
str | None
|
Optional backend name when not present in
|
None
|
shots
|
int | None
|
Optional shots value for metadata. |
None
|
precision
|
float | None
|
Optional precision value for metadata. |
None
|
artifact_key
|
str | None
|
Optional Prefect artifact key prefix. |
None
|
options
|
dict[str, Any] | None
|
Optional native Qiskit primitive options for metadata. |
None
|
runtime_config
|
QiskitRuntimeConfig | None
|
Inline runtime configuration. Mutually exclusive with
|
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A structured dictionary containing primitive, backend name, job ID, |
dict[str, Any]
|
native Qiskit result and collected metadata. |
Cache And Retry Helpers¶
qcsc_prefect.integrations.qiskit.cache.qiskit_sampler_submit_cache_key ¶
qiskit_sampler_submit_cache_key(
_context: Any, parameters: Mapping[str, Any]
) -> str | None
Prefect cache_key_fn helper for native Sampler submit tasks.
qcsc_prefect.integrations.qiskit.cache.qiskit_estimator_submit_cache_key ¶
qiskit_estimator_submit_cache_key(
_context: Any, parameters: Mapping[str, Any]
) -> str | None
Prefect cache_key_fn helper for native Estimator submit tasks.
qcsc_prefect.integrations.qiskit.cache.qiskit_result_fetch_cache_key ¶
qiskit_result_fetch_cache_key(
_context: Any, parameters: Mapping[str, Any]
) -> str | None
Prefect cache_key_fn helper for optional future raw result caching.
qcsc_prefect.integrations.qiskit.input_digest.build_qiskit_sampler_input_digest ¶
build_qiskit_sampler_input_digest(
pubs: Iterable[Any],
*,
backend_name: str | None = None,
runtime_block_name: str | None = None,
shots: int | None = None,
options: Mapping[str, Any] | None = None,
cache_scope: str = "flow",
cache_namespace: str | None = None,
extra: Mapping[str, Any] | None = None,
) -> str
Build an input_digest for native Qiskit Sampler submit caching.
Example:
input_digest = build_qiskit_sampler_input_digest(
pubs,
backend_name="ibm_kawasaki",
shots=1024,
options=options,
)
The digest is summary-only input identity. It is not a result serializer and
does not include Prefect task/run identity. By default it includes the
current Prefect Flow name when available. Set cache_scope="global" to
allow different Flows to share cached submit references.
qcsc_prefect.integrations.qiskit.input_digest.build_qiskit_estimator_input_digest ¶
build_qiskit_estimator_input_digest(
pubs: Iterable[Any],
*,
backend_name: str | None = None,
runtime_block_name: str | None = None,
precision: float | None = None,
options: Mapping[str, Any] | None = None,
cache_scope: str = "flow",
cache_namespace: str | None = None,
extra: Mapping[str, Any] | None = None,
) -> str
Build an input_digest for native Qiskit Estimator submit caching.
The digest includes estimator pubs, observables, backend name, precision,
options, and optional extra stable configuration. It intentionally excludes
Prefect task/run identity. By default it includes the current Prefect Flow
name when available. Set cache_scope="global" to allow different Flows
to share cache entries.
qcsc_prefect.integrations.qiskit.retry.qiskit_retry_delays ¶
qiskit_retry_delays() -> list[int]
Return conservative retry delays, in seconds, for Qiskit fetch tasks.
qcsc_prefect.integrations.qiskit.retry.should_retry_qiskit_fetch_failure ¶
should_retry_qiskit_fetch_failure(
_task: Any, _task_run: Any, state: Any
) -> bool
Return True when a failed fetch state appears transient and retryable.