Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ExecutionOptions::default() now respects defaults used in ExecutionOptionsBuilder::default() #499

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions crates/lib/src/qpu/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,26 +327,34 @@ pub type QpuConnectionOptions = ExecutionOptions;
/// Builder for setting up [`QpuConnectionOptions`].
pub type QpuConnectionOptionsBuilder = ExecutionOptionsBuilder;

/// Options avaialable when executing a job on a QPU.
/// Options available when executing a job on a QPU.
///
/// Use [`Default`] to get a reasonable set of defaults, or start with [`ExecutionOptionsBuilder`]
/// to build a custom set of options.
#[derive(Builder, Clone, Debug, Default, PartialEq)]
#[derive(Builder, Clone, Debug, PartialEq)]
pub struct ExecutionOptions {
#[doc = "The [`ConnectionStrategy`] to use to establish a connection to the QPU."]
#[builder(default)]
connection_strategy: ConnectionStrategy,
#[doc = "The timeout to use for the request, defaults to 30 seconds. If set to `None`, then there is no timeout."]
#[builder(default = "Some(Duration::from_secs(30))")]
timeout: Option<Duration>,
#[doc = "Options avaialable when executing a job on a QPU, particular to the execution service's API."]
#[doc = "Options available when executing a job on a QPU, particular to the execution service's API."]
#[builder(default = "None")]
api_options: Option<InnerApiExecutionOptions>,
}

impl Default for ExecutionOptions {
fn default() -> Self {
ExecutionOptionsBuilder::default().build().expect(
"Should be able to derive a default set of the ExecutionOptions from the builder.",
)
}
}

impl Eq for ExecutionOptions {}

/// Options avaialable when executing a job on a QPU, particular to the execution service's API.
/// Options available when executing a job on a QPU, particular to the execution service's API.
/// This is a conventent alias for [`InnerApiExecutionOptions`] which provides a builder.
///
/// Use [`Default`] to get a reasonable set of defaults, or start with [`ApiExecutionOptionsBuilder`]
Expand Down Expand Up @@ -702,3 +710,18 @@ pub enum QpuApiError {
message: String,
},
}

#[cfg(test)]
mod test {
use crate::qpu::api::ExecutionOptions;

use super::ExecutionOptionsBuilder;

#[test]
fn test_default_execution_options() {
assert_eq!(
ExecutionOptions::default(),
ExecutionOptionsBuilder::default().build().unwrap(),
);
}
}
Loading