Skip to content

Commit 951c91f

Browse files
authored
feat: expose API execution options timeout (#516)
Timeout is exposed as QpuApiDuration
1 parent f1e0294 commit 951c91f

File tree

18 files changed

+149
-25
lines changed

18 files changed

+149
-25
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ndarray.workspace = true
2828
num = { version = "0.4.0", features = ["serde"] }
2929
opentelemetry = { version = "0.23.0" }
3030
opentelemetry_sdk = { version = "0.23.0" }
31+
pbjson-types = "0.7.0"
3132
qcs-api-client-common.workspace = true
3233
qcs-api-client-openapi.workspace = true
3334
qcs-api-client-grpc.workspace = true

crates/lib/src/executable.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,9 @@ impl Executable<'_, '_> {
344344
}
345345

346346
fn get_readouts(&self) -> &[Cow<'_, str>] {
347-
return self
348-
.readout_memory_region_names
347+
self.readout_memory_region_names
349348
.as_ref()
350-
.map_or(&[Cow::Borrowed("ro")], Vec::as_slice);
349+
.map_or(&[Cow::Borrowed("ro")], Vec::as_slice)
351350
}
352351

353352
/// Execute on a QVM which must be available at the configured URL (default <http://localhost:5000>).

crates/lib/src/qpu/api.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
44
use std::{convert::TryFrom, fmt, time::Duration};
55

6+
#[deny(clippy::module_name_repetitions)]
7+
pub use ::pbjson_types::Duration as QpuApiDuration;
68
use async_trait::async_trait;
79
use cached::proc_macro::cached;
810
use derive_builder::Builder;
@@ -382,6 +384,21 @@ impl ApiExecutionOptions {
382384
pub fn bypass_settings_protection(&self) -> bool {
383385
self.inner.bypass_settings_protection
384386
}
387+
388+
/// Get the configured `timeout` value.
389+
///
390+
/// Note, this is the timeout while running a job; the job will be evicted from
391+
/// the hardware once this time has elapsed.
392+
///
393+
/// If unset, the job's estimated duration will be used;
394+
/// if the job does not have an estimated duration, the default
395+
/// timeout is selected by the service.
396+
///
397+
/// The service may also enforce a maximum value for this field.
398+
#[must_use]
399+
pub fn timeout(&self) -> Option<::pbjson_types::Duration> {
400+
self.inner.timeout
401+
}
385402
}
386403

387404
impl From<ApiExecutionOptions> for InnerApiExecutionOptions {
@@ -404,6 +421,14 @@ impl ApiExecutionOptionsBuilder {
404421
.bypass_settings_protection = bypass_settings_protection;
405422
self
406423
}
424+
425+
/// Set the `timeout` value. See [`ApiExecutionOptions::timeout`] for more information.
426+
pub fn timeout(&mut self, timeout: Option<::pbjson_types::Duration>) -> &mut Self {
427+
self.inner
428+
.get_or_insert(InnerApiExecutionOptions::default())
429+
.timeout = timeout;
430+
self
431+
}
407432
}
408433

409434
impl ExecutionOptions {

crates/python/qcs_sdk/_tracing_subscriber/common/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515

1616
__doc__ = common.__doc__
1717
__all__ = getattr(common, "__all__", [])
18+

crates/python/qcs_sdk/_tracing_subscriber/common/__init__.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212

1313
from typing import Dict, Optional, final
1414

15+
1516
@final
1617
class InstrumentationLibrary:
1718
"""
1819
Information about a library or crate providing instrumentation.
19-
20+
2021
An instrumentation library should be named to follow any naming conventions
2122
of the instrumented library (e.g. 'middleware' for a web framework).
22-
23+
2324
See the `instrumentation libraries <https://github.com/open-telemetry/opentelemetry-specification/blob/v1.9.0/specification/overview.md#instrumentation-libraries>`_
2425
spec for more information.
2526
"""
@@ -41,3 +42,4 @@ class InstrumentationLibrary:
4142
:param attributes: The attributes of the instrumentation library.
4243
"""
4344
...
45+

crates/python/qcs_sdk/_tracing_subscriber/layers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515

1616
__doc__ = layers.__doc__
1717
__all__ = getattr(layers, "__all__", [])
18+

crates/python/qcs_sdk/_tracing_subscriber/layers/__init__.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
from __future__ import annotations
1414
from typing import TYPE_CHECKING
1515

16-
from . import file as file
16+
from . import file as file
1717
from . import otel_otlp_file as otel_otlp_file
1818
from . import otel_otlp as otel_otlp
1919

2020
if TYPE_CHECKING:
21-
from typing import Union
21+
from typing import Union
2222

23-
Config = Union[
24-
file.Config,
25-
otel_otlp_file.Config,
26-
otel_otlp.Config,
27-
]
28-
"""
23+
Config = Union[
24+
file.Config,
25+
otel_otlp_file.Config,
26+
otel_otlp.Config,
27+
]
28+
"""
2929
One of the supported layer configurations that may be set on the subscriber configuration.
3030
"""

crates/python/qcs_sdk/_tracing_subscriber/layers/file/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515

1616
__doc__ = file.__doc__
1717
__all__ = getattr(file, "__all__", [])
18+
19+

crates/python/qcs_sdk/_tracing_subscriber/layers/file/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ class Config:
3939
:param json: Whether or not to format the output as JSON. Defaults to `True`.
4040
"""
4141
...
42+

0 commit comments

Comments
 (0)