Skip to content

Commit 7a06117

Browse files
fix!: update qcs-api deps to use a >=9 version of jsonwebtoken (#483)
* chore: update qcs-api deps to use a >=9 version of jsonwebtoken * chore: refactor to update to latest qcs-api-client * chore: bump zerovec to fix yank crate error * chore: fix lints * chore: use default instead on unwrapping in new * chore: make PyQcsClient load never async * chore: update pyi definiteions * chore: downgrade dirs to remove need for copyleft * chore: fix test
1 parent 7856072 commit 7a06117

24 files changed

+382
-171
lines changed

Cargo.lock

+239-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ resolver = "2"
44

55
[workspace.dependencies]
66
qcs-api = "0.2.1"
7-
qcs-api-client-common = "0.7.14"
8-
qcs-api-client-grpc = "0.7.16"
9-
qcs-api-client-openapi = "0.8.15"
7+
qcs-api-client-common = "0.8.4"
8+
qcs-api-client-grpc = "0.8.4"
9+
qcs-api-client-openapi = "0.9.4"
1010
serde_json = "1.0.86"
1111
thiserror = "1.0.57"
1212
tokio = "1.36.0"

crates/lib/examples/delayed_job_retrieval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ MEASURE 0 ro[0]
1111
const QUANTUM_PROCESSOR_ID: &str = "Aspen-M-3";
1212

1313
async fn quilc_client() -> rpcq::Client {
14-
let qcs = Qcs::load().await;
14+
let qcs = Qcs::load();
1515
let endpoint = qcs.get_config().quilc_url();
1616
rpcq::Client::new(endpoint).unwrap()
1717
}

crates/lib/examples/execute.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ MEASURE 1 ro[1]
1212
"#;
1313

1414
async fn quilc_client() -> rpcq::Client {
15-
let qcs = Qcs::load().await;
15+
let qcs = Qcs::load();
1616
let endpoint = qcs.get_config().quilc_url();
1717
rpcq::Client::new(endpoint).unwrap()
1818
}

crates/lib/examples/local.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ MEASURE 1 ro[1]
1313
"#;
1414

1515
async fn quilc_client() -> rpcq::Client {
16-
let qcs = Qcs::load().await;
16+
let qcs = Qcs::load();
1717
let endpoint = qcs.get_config().quilc_url();
1818
rpcq::Client::new(endpoint).unwrap()
1919
}

crates/lib/examples/parametric_compilation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ RX(-pi / 2) 0
2020
MEASURE 0 ro[0]
2121
"#;
2222
async fn quilc_client() -> rpcq::Client {
23-
let qcs = Qcs::load().await;
23+
let qcs = Qcs::load();
2424
let endpoint = qcs.get_config().quilc_url();
2525
rpcq::Client::new(endpoint).unwrap()
2626
}

crates/lib/examples/quil_t.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ DELAY 0 "rf" 1e-6
1313
MEASURE 0 ro
1414
"#;
1515
async fn quilc_client() -> rpcq::Client {
16-
let qcs = Qcs::load().await;
16+
let qcs = Qcs::load();
1717
let endpoint = qcs.get_config().quilc_url();
1818
rpcq::Client::new(endpoint).unwrap()
1919
}

crates/lib/src/client.rs

+27-19
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
55
use std::time::Duration;
66

7-
use qcs_api_client_common::configuration::{ClientConfiguration, RefreshError};
7+
use qcs_api_client_common::configuration::{ClientConfiguration, TokenError};
88
#[cfg(feature = "grpc-web")]
9-
use qcs_api_client_grpc::channel::{wrap_channel_with_grpc_web, GrpcWebWrapperLayerService};
9+
use qcs_api_client_grpc::tonic::{wrap_channel_with_grpc_web, GrpcWebWrapperLayerService};
1010
use qcs_api_client_grpc::{
11-
channel::{
11+
services::translation::translation_client::TranslationClient,
12+
tonic::{
1213
get_channel, parse_uri, wrap_channel_with, wrap_channel_with_retry, RefreshService,
1314
RetryService,
1415
},
15-
services::translation::translation_client::TranslationClient,
1616
};
1717
use qcs_api_client_openapi::apis::configuration::Configuration as OpenApiConfiguration;
1818
use tonic::transport::Channel;
1919
use tonic::Status;
2020

2121
pub use qcs_api_client_common::configuration::LoadError;
22-
pub use qcs_api_client_grpc::channel::Error as GrpcError;
22+
pub use qcs_api_client_grpc::tonic::Error as GrpcError;
2323
pub use qcs_api_client_openapi::apis::Error as OpenApiError;
2424

2525
const DEFAULT_MAX_MESSAGE_ENCODING_SIZE: usize = 50 * 1024 * 1024;
@@ -45,24 +45,24 @@ pub type GrpcConnection =
4545
pub(crate) static DEFAULT_HTTP_API_TIMEOUT: Duration = Duration::from_secs(10);
4646

4747
/// A client providing helper functionality for accessing QCS APIs
48-
#[derive(Debug, Clone, Default)]
48+
#[derive(Debug, Clone)]
4949
pub struct Qcs {
5050
config: ClientConfiguration,
5151
}
5252

5353
impl Qcs {
5454
/// Create a [`Qcs`] and initialize it with the user's default [`ClientConfiguration`]
55-
pub async fn load() -> Self {
56-
let config = if let Ok(config) = ClientConfiguration::load_default().await {
57-
config
55+
#[must_use]
56+
pub fn load() -> Self {
57+
if let Ok(config) = ClientConfiguration::load_default() {
58+
Self::with_config(config)
5859
} else {
5960
#[cfg(feature = "tracing")]
6061
tracing::info!(
6162
"No QCS client configuration found. QPU data and QCS will be inaccessible and only generic QVMs will be available for execution"
6263
);
63-
ClientConfiguration::default()
64-
};
65-
Self::with_config(config)
64+
Self::default()
65+
}
6666
}
6767

6868
/// Create a [`Qcs`] and initialize it with the given [`ClientConfiguration`]
@@ -77,10 +77,8 @@ impl Qcs {
7777
///
7878
/// A [`LoadError`] will be returned if QCS credentials are
7979
/// not correctly configured or the given profile is not defined.
80-
pub async fn with_profile(profile: String) -> Result<Qcs, LoadError> {
81-
ClientConfiguration::load_profile(profile)
82-
.await
83-
.map(Self::with_config)
80+
pub fn with_profile(profile: String) -> Result<Qcs, LoadError> {
81+
ClientConfiguration::load_profile(profile).map(Self::with_config)
8482
}
8583

8684
/// Return a reference to the underlying [`ClientConfiguration`] with all settings parsed and resolved from configuration sources.
@@ -95,14 +93,14 @@ impl Qcs {
9593

9694
pub(crate) fn get_translation_client(
9795
&self,
98-
) -> Result<TranslationClient<GrpcConnection>, GrpcError<RefreshError>> {
96+
) -> Result<TranslationClient<GrpcConnection>, GrpcError<TokenError>> {
9997
self.get_translation_client_with_endpoint(self.get_config().grpc_api_url())
10098
}
10199

102100
pub(crate) fn get_translation_client_with_endpoint(
103101
&self,
104102
translation_grpc_endpoint: &str,
105-
) -> Result<TranslationClient<GrpcConnection>, GrpcError<RefreshError>> {
103+
) -> Result<TranslationClient<GrpcConnection>, GrpcError<TokenError>> {
106104
let uri = parse_uri(translation_grpc_endpoint)?;
107105
let channel = get_channel(uri)?;
108106
let service =
@@ -115,6 +113,16 @@ impl Qcs {
115113
}
116114
}
117115

116+
impl Default for Qcs {
117+
fn default() -> Self {
118+
Self::with_config(
119+
ClientConfiguration::builder()
120+
.build()
121+
.expect("builder should be valid with all defaults"),
122+
)
123+
}
124+
}
125+
118126
/// Errors that may occur while trying to use a `gRPC` client
119127
#[derive(Debug, thiserror::Error)]
120128
pub enum GrpcClientError {
@@ -128,7 +136,7 @@ pub enum GrpcClientError {
128136

129137
/// Error due to `gRPC` error
130138
#[error("gRPC error: {0}")]
131-
GrpcError(#[from] GrpcError<RefreshError>),
139+
GrpcError(#[from] GrpcError<TokenError>),
132140
}
133141

134142
/// Errors that may occur while trying to use an `OpenAPI` client

crates/lib/src/compiler/quilc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ mod tests {
358358
}
359359

360360
async fn rpcq_client() -> rpcq::Client {
361-
let qcs = Qcs::load().await;
361+
let qcs = Qcs::load();
362362
let endpoint = qcs.get_config().quilc_url();
363363
rpcq::Client::new(endpoint).unwrap()
364364
}
@@ -387,7 +387,7 @@ MEASURE 1 ro[1]
387387

388388
#[tokio::test]
389389
async fn run_compiled_bell_state_on_qvm() {
390-
let client = Qcs::load().await;
390+
let client = Qcs::load();
391391
let client = qvm::http::HttpClient::from(&client);
392392
let output = rpcq_client()
393393
.await

crates/lib/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct Diagnostics {
3838

3939
impl Diagnostics {
4040
async fn gather() -> Self {
41-
let client = Qcs::load().await;
41+
let client = Qcs::load();
4242

4343
let (qcs, qvm) = futures::future::join(
4444
QcsApiDiagnostics::gather(&client),

crates/lib/src/executable.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use quil_rs::program::ProgramError;
4444
/// async fn main() {
4545
/// use std::num::NonZeroU16;
4646
/// use qcs::qvm;
47-
/// let qvm_client = qvm::http::HttpClient::from(&Qcs::load().await);
47+
/// let qvm_client = qvm::http::HttpClient::from(&Qcs::load());
4848
/// let mut result = Executable::from_quil(PROGRAM).with_qcs_client(Qcs::default()).with_shots(NonZeroU16::new(4).unwrap()).execute_on_qvm(&qvm_client).await.unwrap();
4949
/// // "ro" is the only source read from by default if you don't specify a .read_from()
5050
///
@@ -158,7 +158,7 @@ impl<'executable> Executable<'executable, '_> {
158158
///
159159
/// #[tokio::main]
160160
/// async fn main() {
161-
/// let qvm_client = qvm::http::HttpClient::from(&Qcs::load().await);
161+
/// let qvm_client = qvm::http::HttpClient::from(&Qcs::load());
162162
/// let mut result = Executable::from_quil(PROGRAM)
163163
/// .with_qcs_client(Qcs::default()) // Unnecessary if you have ~/.qcs/settings.toml
164164
/// .read_from("first")
@@ -228,7 +228,7 @@ impl<'executable> Executable<'executable, '_> {
228228
///
229229
/// #[tokio::main]
230230
/// async fn main() {
231-
/// let qvm_client = qvm::http::HttpClient::from(&Qcs::load().await);
231+
/// let qvm_client = qvm::http::HttpClient::from(&Qcs::load());
232232
/// let mut exe = Executable::from_quil(PROGRAM)
233233
/// .with_qcs_client(Qcs::default()) // Unnecessary if you have ~/.qcs/settings.toml
234234
/// .read_from("theta");
@@ -301,11 +301,11 @@ impl<'executable> Executable<'executable, '_> {
301301
/// Get a reference to the [`Qcs`] client used by the executable.
302302
///
303303
/// If one has not been set, a default client is loaded, set, and returned.
304-
pub async fn qcs_client(&mut self) -> Arc<Qcs> {
304+
pub fn qcs_client(&mut self) -> Arc<Qcs> {
305305
if let Some(client) = &self.qcs_client {
306306
client.clone()
307307
} else {
308-
let client = Arc::new(Qcs::load().await);
308+
let client = Arc::new(Qcs::load());
309309
self.qcs_client = Some(client.clone());
310310
client
311311
}
@@ -413,7 +413,7 @@ impl<'execution> Executable<'_, 'execution> {
413413
self.quil.clone(),
414414
self.shots,
415415
id,
416-
self.qcs_client().await,
416+
self.qcs_client(),
417417
self.quilc_client.clone(),
418418
self.compiler_options,
419419
)
@@ -804,7 +804,7 @@ mod describe_get_config {
804804
use crate::{compiler::rpcq, Executable};
805805

806806
async fn quilc_client() -> rpcq::Client {
807-
let qcs = Qcs::load().await;
807+
let qcs = Qcs::load();
808808
let endpoint = qcs.get_config().quilc_url();
809809
rpcq::Client::new(endpoint).unwrap()
810810
}
@@ -835,7 +835,7 @@ mod describe_qpu_for_id {
835835
use crate::{client::Qcs, Executable};
836836

837837
async fn quilc_client() -> rpcq::Client {
838-
let qcs = Qcs::load().await;
838+
let qcs = Qcs::load();
839839
let endpoint = qcs.get_config().quilc_url();
840840
rpcq::Client::new(endpoint).unwrap()
841841
}
@@ -844,7 +844,7 @@ mod describe_qpu_for_id {
844844
async fn it_refreshes_auth_token() {
845845
// Default config has no auth, so it should try to refresh
846846
let mut exe = Executable::from_quil("")
847-
.with_qcs_client(Qcs::default())
847+
.with_qcs_client(Qcs::load())
848848
.with_quilc_client(Some(quilc_client().await));
849849
let result = exe.qpu_for_id("blah").await;
850850
let Err(err) = result else {
@@ -864,7 +864,7 @@ mod describe_qpu_for_id {
864864
"".into(),
865865
shots,
866866
"Aspen-M-3".into(),
867-
exe.qcs_client().await,
867+
exe.qcs_client(),
868868
exe.quilc_client.clone(),
869869
CompilerOpts::default(),
870870
)

crates/lib/src/qpu/api.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ use std::{convert::TryFrom, fmt, time::Duration};
55

66
use cached::proc_macro::cached;
77
use derive_builder::Builder;
8-
use qcs_api_client_common::configuration::RefreshError;
8+
use qcs_api_client_common::configuration::TokenError;
99
#[cfg(feature = "grpc-web")]
10-
use qcs_api_client_grpc::channel::wrap_channel_with_grpc_web;
11-
pub use qcs_api_client_grpc::channel::Error as GrpcError;
10+
use qcs_api_client_grpc::tonic::wrap_channel_with_grpc_web;
11+
pub use qcs_api_client_grpc::tonic::Error as GrpcError;
1212
use qcs_api_client_grpc::{
13-
channel::{parse_uri, wrap_channel_with, wrap_channel_with_retry},
1413
get_channel_with_timeout,
1514
models::controller::{
1615
controller_job_execution_result, data_value::Value, ControllerJobExecutionResult,
@@ -22,6 +21,7 @@ use qcs_api_client_grpc::{
2221
CancelControllerJobsRequest, ExecuteControllerJobRequest,
2322
ExecutionOptions as InnerApiExecutionOptions, GetControllerJobResultsRequest,
2423
},
24+
tonic::{parse_uri, wrap_channel_with, wrap_channel_with_retry},
2525
};
2626
pub use qcs_api_client_openapi::apis::Error as OpenApiError;
2727
use qcs_api_client_openapi::apis::{
@@ -644,7 +644,7 @@ async fn get_default_endpoint(
644644
pub enum QpuApiError {
645645
/// Error due to a bad gRPC configuration
646646
#[error("Error configuring gRPC request: {0}")]
647-
GrpcError(#[from] GrpcError<RefreshError>),
647+
GrpcError(#[from] GrpcError<TokenError>),
648648

649649
/// Error due to missing gRPC endpoint for endpoint ID
650650
#[error("Missing gRPC endpoint for endpoint ID: {0}")]

crates/lib/src/qvm/execution.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ mod describe_execution {
8282
use crate::{client::Qcs, qvm};
8383

8484
async fn qvm_client() -> qvm::http::HttpClient {
85-
let qcs = Qcs::load().await;
85+
let qcs = Qcs::load();
8686
qvm::http::HttpClient::from(&qcs)
8787
}
8888

crates/lib/tests/basic_qvm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ MEASURE 1 second
1717
"##;
1818

1919
async fn quilc_client() -> rpcq::Client {
20-
let qcs = Qcs::load().await;
20+
let qcs = Qcs::load();
2121
let endpoint = qcs.get_config().quilc_url();
2222
rpcq::Client::new(endpoint).unwrap()
2323
}
2424

2525
async fn qvm_client() -> qvm::http::HttpClient {
26-
let qcs = Qcs::load().await;
26+
let qcs = Qcs::load();
2727
qvm::http::HttpClient::from(&qcs)
2828
}
2929

@@ -33,7 +33,7 @@ async fn test_bell_state() {
3333

3434
let data = Executable::from_quil(PROGRAM)
3535
.with_quilc_client(Some(quilc_client().await))
36-
.with_qcs_client(Qcs::load().await)
36+
.with_qcs_client(Qcs::load())
3737
.with_shots(shots)
3838
.read_from("first")
3939
.read_from("second")

crates/lib/tests/mocked_qpu.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async fn setup() {
6464
}
6565

6666
async fn quilc_client() -> rpcq::Client {
67-
let qcs = Qcs::load().await;
67+
let qcs = Qcs::load();
6868
let endpoint = qcs.get_config().quilc_url();
6969
rpcq::Client::new(endpoint).unwrap()
7070
}

crates/lib/tests/parametric_compilation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ MEASURE 0 ro[0]
1717
"#;
1818

1919
async fn quilc_client() -> rpcq::Client {
20-
let qcs = Qcs::load().await;
20+
let qcs = Qcs::load();
2121
let endpoint = qcs.get_config().quilc_url();
2222
rpcq::Client::new(endpoint).unwrap()
2323
}
2424

2525
async fn qvm_client() -> qvm::http::HttpClient {
26-
let qcs = Qcs::load().await;
26+
let qcs = Qcs::load();
2727
qvm::http::HttpClient::from(&qcs)
2828
}
2929

crates/lib/tests/qvm_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ MEASURE 1 ro[1]
2222
"##;
2323

2424
async fn http_qvm_client() -> HttpClient {
25-
let qcs_client = Qcs::load().await;
25+
let qcs_client = Qcs::load();
2626
HttpClient::from(&qcs_client)
2727
}
2828

0 commit comments

Comments
 (0)