From 97e822979a5010da18d80bfc03afc6fd3571fee1 Mon Sep 17 00:00:00 2001 From: Mark Skilbeck Date: Thu, 9 May 2024 13:17:53 +0100 Subject: [PATCH 1/2] feat: increase gRPC max message size from 4MB to 50MB --- crates/lib/src/client.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/lib/src/client.rs b/crates/lib/src/client.rs index 994bbd04..7b0c38c2 100644 --- a/crates/lib/src/client.rs +++ b/crates/lib/src/client.rs @@ -22,6 +22,9 @@ pub use qcs_api_client_common::configuration::LoadError; pub use qcs_api_client_grpc::channel::Error as GrpcError; pub use qcs_api_client_openapi::apis::Error as OpenApiError; +const DEFAULT_MAX_MESSAGE_ENCODING_SIZE: usize = 50 * 1024 * 1024; +const DEFAULT_MAX_MESSAGE_DECODING_SIZE: usize = 50 * 1024 * 1024; + /// A type alias for the underlying gRPC connection used by all gRPC clients within this library. /// It is public so that users can create gRPC clients with different APIs using a "raw" connection /// initialized by this library. This ensures that the exact Tonic version used for such clients @@ -106,7 +109,9 @@ impl Qcs { wrap_channel_with_retry(wrap_channel_with(channel, self.get_config().clone())); #[cfg(feature = "grpc-web")] let service = wrap_channel_with_grpc_web(service); - Ok(TranslationClient::new(service)) + Ok(TranslationClient::new(service) + .max_encoding_message_size(DEFAULT_MAX_MESSAGE_ENCODING_SIZE) + .max_decoding_message_size(DEFAULT_MAX_MESSAGE_DECODING_SIZE)) } } From 2db49b2fc4bdb0033b89fef2ced0df4c590bde85 Mon Sep 17 00:00:00 2001 From: Mark Skilbeck Date: Thu, 9 May 2024 14:29:28 +0100 Subject: [PATCH 2/2] Fix some new clippy lints --- clippy.toml | 2 +- crates/lib/src/compiler/libquil.rs | 10 ++++---- crates/lib/src/compiler/quilc.rs | 4 +-- crates/lib/src/qpu/api.rs | 31 +++++++++++++++++------- crates/lib/src/qpu/rewrite_arithmetic.rs | 4 +-- crates/python/src/execution_data.rs | 2 +- 6 files changed, 33 insertions(+), 20 deletions(-) diff --git a/clippy.toml b/clippy.toml index 36dd71ef..56aeb73d 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1 @@ -doc-valid-idents = ["gRPC", ".."] \ No newline at end of file +doc-valid-idents = ["gRPC", "..", "JupyterLab"] diff --git a/crates/lib/src/compiler/libquil.rs b/crates/lib/src/compiler/libquil.rs index f6b3f90d..391cbcb8 100644 --- a/crates/lib/src/compiler/libquil.rs +++ b/crates/lib/src/compiler/libquil.rs @@ -12,7 +12,7 @@ use super::quilc::{self, NativeQuilMetadata}; /// The errors that can arise when using libquil as a QVM client #[derive(Debug, thiserror::Error)] pub enum Error { - /// Error when calling libquil_sys::quilc + /// Error when calling [`libquil_sys::quilc`] #[error("error when calling libquil_sys: {0}")] Quilc(#[from] libquil_sys::quilc::Error), /// Error when serializing a program @@ -24,7 +24,7 @@ pub enum Error { /// Error when casting u64 to u32 #[error("error when casting u64 to u32: {0}")] U64Truncation(#[from] TryFromIntError), - /// Error when creating a CString + /// Error when creating a [`CString`] #[error("error when creating CString: {0}")] CString(#[from] NulError), } @@ -202,14 +202,14 @@ mod test { assert_eq!(output.program.to_quil_or_debug(), EXPECTED_H0_OUTPUT); } - const BELL_STATE: &str = r##"DECLARE ro BIT[2] + const BELL_STATE: &str = r"DECLARE ro BIT[2] H 0 CNOT 0 1 MEASURE 0 ro[0] MEASURE 1 ro[1] -"##; +"; #[tokio::test] async fn test_print_isa() { @@ -228,7 +228,7 @@ MEASURE 1 ro[1] CompilerOpts::default(), ) .expect("Could not compile"); - let mut results = crate::qvm::Execution::new(&output.program.to_quil_or_debug()) + let mut results = qvm::Execution::new(&output.program.to_quil_or_debug()) .unwrap() .run( NonZeroU16::new(10).expect("value is non-zero"), diff --git a/crates/lib/src/compiler/quilc.rs b/crates/lib/src/compiler/quilc.rs index 450f76fe..23d55ed4 100644 --- a/crates/lib/src/compiler/quilc.rs +++ b/crates/lib/src/compiler/quilc.rs @@ -228,7 +228,7 @@ pub enum CompilationError { Libquil(crate::compiler::libquil::Error), /// Errors during compilation when using RPCQ #[error("compilation error from RPCQ: {0}")] - Rpcq(crate::compiler::rpcq::Error), + Rpcq(rpcq::Error), } /// The response from quilc for a `quil_to_native_quil` request. @@ -398,7 +398,7 @@ MEASURE 1 ro[1] CompilerOpts::default(), ) .expect("Could not compile"); - let mut results = crate::qvm::Execution::new(&output.program.to_quil_or_debug()) + let mut results = qvm::Execution::new(&output.program.to_quil_or_debug()) .unwrap() .run( NonZeroU16::new(10).expect("value is non-zero"), diff --git a/crates/lib/src/qpu/api.rs b/crates/lib/src/qpu/api.rs index c1e2af54..2024e3c2 100644 --- a/crates/lib/src/qpu/api.rs +++ b/crates/lib/src/qpu/api.rs @@ -1,14 +1,14 @@ //! This module provides bindings to for submitting jobs to and retrieving them from //! Rigetti QPUs using the QCS API. -use std::{fmt, time::Duration}; +use std::{convert::TryFrom, fmt, time::Duration}; use cached::proc_macro::cached; use derive_builder::Builder; use qcs_api_client_common::configuration::RefreshError; -pub use qcs_api_client_grpc::channel::Error as GrpcError; #[cfg(feature = "grpc-web")] use qcs_api_client_grpc::channel::wrap_channel_with_grpc_web; +pub use qcs_api_client_grpc::channel::Error as GrpcError; use qcs_api_client_grpc::{ channel::{parse_uri, wrap_channel_with, wrap_channel_with_retry}, get_channel_with_timeout, @@ -302,16 +302,18 @@ pub async fn retrieve_results( .ok_or_else(|| GrpcClientError::ResponseEmpty("Job Execution Results".into())) .map_err(QpuApiError::from) .and_then( - |result| match controller_job_execution_result::Status::from_i32(result.status) { - Some(controller_job_execution_result::Status::Success) => Ok(result), - status => Err(QpuApiError::JobExecutionFailed { - status: status - .map_or("UNDEFINED", |status| status.as_str_name()) - .to_string(), + |result| match controller_job_execution_result::Status::try_from(result.status) { + Ok(controller_job_execution_result::Status::Success) => Ok(result), + Ok(status) => Err(QpuApiError::JobExecutionFailed { + status: status.as_str_name().to_string(), message: result .status_message .unwrap_or("No message provided.".to_string()), }), + Err(s) => Err(QpuApiError::InvalidJobStatus { + status: result.status, + message: s.to_string(), + }), }, ) } @@ -598,7 +600,7 @@ async fn get_accessor(quantum_processor_id: &str, client: &Qcs) -> Result; + #[cfg(test)] mod describe_rewrite_arithmetic { use std::str::FromStr; @@ -559,5 +561,3 @@ SHIFT-PHASE 0 "rf" __SUBST[0] insta::assert_snapshot!(substitutions[0].to_quil_or_debug()); } } - -pub(crate) type Substitutions = IndexSet; diff --git a/crates/python/src/execution_data.rs b/crates/python/src/execution_data.rs index f095f821..c6e620a5 100644 --- a/crates/python/src/execution_data.rs +++ b/crates/python/src/execution_data.rs @@ -111,7 +111,7 @@ impl PyExecutionData { )) } - pub fn __setstate__<'a>(&mut self, state: &PyBytes) -> PyResult<()> { + pub fn __setstate__(&mut self, state: &PyBytes) -> PyResult<()> { let execution_data: ExecutionData = serde_json::from_slice(state.as_bytes()) .map_err(|e| PyRuntimeError::new_err(format!("failed to deserialize: {e}")))?; *self = PyExecutionData(execution_data);