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

feat: increase gRPC max message size from 4MB to 50MB #468

Merged
merged 3 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion crates/lib/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
notmgsk marked this conversation as resolved.
Show resolved Hide resolved

/// 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
Expand Down Expand Up @@ -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))
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/lib/src/compiler/libquil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/src/compiler/quilc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
27 changes: 20 additions & 7 deletions crates/lib/src/qpu/api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! 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;
Expand Down Expand Up @@ -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(),
}),
},
)
}
Expand Down Expand Up @@ -688,4 +690,15 @@ pub enum QpuApiError {
/// The message associated with the failed job.
message: String,
},

/// Error that can occur if a numeric status identifier cannot be converted
/// into a known status type.
#[error("The request returned an invalid status: {status}. {message}")]
InvalidJobStatus {
/// The numeric status identifier.
status: i32,
/// The message describing the failure to convert the numeric status
/// identifier into a known status type.
message: String,
},
}
4 changes: 2 additions & 2 deletions crates/lib/src/qpu/rewrite_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ impl RewrittenProgram {
}
}

pub(crate) type Substitutions = IndexSet<Expression>;

#[cfg(test)]
mod describe_rewrite_arithmetic {
use std::str::FromStr;
Expand Down Expand Up @@ -559,5 +561,3 @@ SHIFT-PHASE 0 "rf" __SUBST[0]
insta::assert_snapshot!(substitutions[0].to_quil_or_debug());
}
}

pub(crate) type Substitutions = IndexSet<Expression>;
2 changes: 1 addition & 1 deletion crates/python/src/execution_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading