Skip to content

Commit c6af91e

Browse files
authored
feat: increase gRPC max message size from 4MB to 50MB (#468)
* feat: increase gRPC max message size from 4MB to 50MB * Fix some new clippy lints
1 parent 41f762e commit c6af91e

6 files changed

Lines changed: 35 additions & 17 deletions

File tree

crates/lib/src/client.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ pub use qcs_api_client_common::configuration::LoadError;
2222
pub use qcs_api_client_grpc::channel::Error as GrpcError;
2323
pub use qcs_api_client_openapi::apis::Error as OpenApiError;
2424

25+
const DEFAULT_MAX_MESSAGE_ENCODING_SIZE: usize = 50 * 1024 * 1024;
26+
const DEFAULT_MAX_MESSAGE_DECODING_SIZE: usize = 50 * 1024 * 1024;
27+
2528
/// A type alias for the underlying gRPC connection used by all gRPC clients within this library.
2629
/// It is public so that users can create gRPC clients with different APIs using a "raw" connection
2730
/// initialized by this library. This ensures that the exact Tonic version used for such clients
@@ -106,7 +109,9 @@ impl Qcs {
106109
wrap_channel_with_retry(wrap_channel_with(channel, self.get_config().clone()));
107110
#[cfg(feature = "grpc-web")]
108111
let service = wrap_channel_with_grpc_web(service);
109-
Ok(TranslationClient::new(service))
112+
Ok(TranslationClient::new(service)
113+
.max_encoding_message_size(DEFAULT_MAX_MESSAGE_ENCODING_SIZE)
114+
.max_decoding_message_size(DEFAULT_MAX_MESSAGE_DECODING_SIZE))
110115
}
111116
}
112117

crates/lib/src/compiler/libquil.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::quilc::{self, NativeQuilMetadata};
1212
/// The errors that can arise when using libquil as a QVM client
1313
#[derive(Debug, thiserror::Error)]
1414
pub enum Error {
15-
/// Error when calling libquil_sys::quilc
15+
/// Error when calling [`libquil_sys::quilc`]
1616
#[error("error when calling libquil_sys: {0}")]
1717
Quilc(#[from] libquil_sys::quilc::Error),
1818
/// Error when serializing a program
@@ -24,7 +24,7 @@ pub enum Error {
2424
/// Error when casting u64 to u32
2525
#[error("error when casting u64 to u32: {0}")]
2626
U64Truncation(#[from] TryFromIntError),
27-
/// Error when creating a CString
27+
/// Error when creating a [`CString`]
2828
#[error("error when creating CString: {0}")]
2929
CString(#[from] NulError),
3030
}
@@ -202,14 +202,14 @@ mod test {
202202
assert_eq!(output.program.to_quil_or_debug(), EXPECTED_H0_OUTPUT);
203203
}
204204

205-
const BELL_STATE: &str = r##"DECLARE ro BIT[2]
205+
const BELL_STATE: &str = r"DECLARE ro BIT[2]
206206
207207
H 0
208208
CNOT 0 1
209209
210210
MEASURE 0 ro[0]
211211
MEASURE 1 ro[1]
212-
"##;
212+
";
213213

214214
#[tokio::test]
215215
async fn test_print_isa() {
@@ -228,7 +228,7 @@ MEASURE 1 ro[1]
228228
CompilerOpts::default(),
229229
)
230230
.expect("Could not compile");
231-
let mut results = crate::qvm::Execution::new(&output.program.to_quil_or_debug())
231+
let mut results = qvm::Execution::new(&output.program.to_quil_or_debug())
232232
.unwrap()
233233
.run(
234234
NonZeroU16::new(10).expect("value is non-zero"),

crates/lib/src/compiler/quilc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ MEASURE 1 ro[1]
398398
CompilerOpts::default(),
399399
)
400400
.expect("Could not compile");
401-
let mut results = crate::qvm::Execution::new(&output.program.to_quil_or_debug())
401+
let mut results = qvm::Execution::new(&output.program.to_quil_or_debug())
402402
.unwrap()
403403
.run(
404404
NonZeroU16::new(10).expect("value is non-zero"),

crates/lib/src/qpu/api.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! This module provides bindings to for submitting jobs to and retrieving them from
22
//! Rigetti QPUs using the QCS API.
33
4-
use std::{fmt, time::Duration};
4+
use std::{convert::TryFrom, fmt, time::Duration};
55

66
use cached::proc_macro::cached;
77
use derive_builder::Builder;
@@ -302,16 +302,18 @@ pub async fn retrieve_results(
302302
.ok_or_else(|| GrpcClientError::ResponseEmpty("Job Execution Results".into()))
303303
.map_err(QpuApiError::from)
304304
.and_then(
305-
|result| match controller_job_execution_result::Status::from_i32(result.status) {
306-
Some(controller_job_execution_result::Status::Success) => Ok(result),
307-
status => Err(QpuApiError::JobExecutionFailed {
308-
status: status
309-
.map_or("UNDEFINED", |status| status.as_str_name())
310-
.to_string(),
305+
|result| match controller_job_execution_result::Status::try_from(result.status) {
306+
Ok(controller_job_execution_result::Status::Success) => Ok(result),
307+
Ok(status) => Err(QpuApiError::JobExecutionFailed {
308+
status: status.as_str_name().to_string(),
311309
message: result
312310
.status_message
313311
.unwrap_or("No message provided.".to_string()),
314312
}),
313+
Err(s) => Err(QpuApiError::InvalidJobStatus {
314+
status: result.status,
315+
message: s.to_string(),
316+
}),
315317
},
316318
)
317319
}
@@ -688,4 +690,15 @@ pub enum QpuApiError {
688690
/// The message associated with the failed job.
689691
message: String,
690692
},
693+
694+
/// Error that can occur if a numeric status identifier cannot be converted
695+
/// into a known status type.
696+
#[error("The request returned an invalid status: {status}. {message}")]
697+
InvalidJobStatus {
698+
/// The numeric status identifier.
699+
status: i32,
700+
/// The message describing the failure to convert the numeric status
701+
/// identifier into a known status type.
702+
message: String,
703+
},
691704
}

crates/lib/src/qpu/rewrite_arithmetic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ impl RewrittenProgram {
367367
}
368368
}
369369

370+
pub(crate) type Substitutions = IndexSet<Expression>;
371+
370372
#[cfg(test)]
371373
mod describe_rewrite_arithmetic {
372374
use std::str::FromStr;
@@ -559,5 +561,3 @@ SHIFT-PHASE 0 "rf" __SUBST[0]
559561
insta::assert_snapshot!(substitutions[0].to_quil_or_debug());
560562
}
561563
}
562-
563-
pub(crate) type Substitutions = IndexSet<Expression>;

crates/python/src/execution_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl PyExecutionData {
111111
))
112112
}
113113

114-
pub fn __setstate__<'a>(&mut self, state: &PyBytes) -> PyResult<()> {
114+
pub fn __setstate__(&mut self, state: &PyBytes) -> PyResult<()> {
115115
let execution_data: ExecutionData = serde_json::from_slice(state.as_bytes())
116116
.map_err(|e| PyRuntimeError::new_err(format!("failed to deserialize: {e}")))?;
117117
*self = PyExecutionData(execution_data);

0 commit comments

Comments
 (0)