From 4b820aa51d3f7e55c45c7d33f9d2dbd27011980e Mon Sep 17 00:00:00 2001 From: Michael Bryant Date: Fri, 26 Jan 2024 11:06:20 -0800 Subject: [PATCH 1/7] fix(lib)!: replace String in unused Translation error variant with gRPC error --- crates/lib/src/executable.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/lib/src/executable.rs b/crates/lib/src/executable.rs index 357b54820..7f279f87e 100644 --- a/crates/lib/src/executable.rs +++ b/crates/lib/src/executable.rs @@ -10,7 +10,7 @@ use std::time::Duration; use qcs_api_client_common::configuration::LoadError; use quil_rs::quil::ToQuilError; -use crate::client::Qcs; +use crate::client::{GrpcClientError, Qcs}; use crate::compiler::quilc::{self, CompilerOpts}; use crate::execution_data::{self, ResultData}; use crate::qpu::api::{ExecutionOptions, JobId}; @@ -643,7 +643,7 @@ pub enum Error { Compilation(String), /// There was a problem when translating the Quil program. #[error("There was a problem translating the Quil program: {0}")] - Translation(String), + Translation(GrpcClientError), /// There was a problem when rewriting parameter arithmetic in the Quil program. #[error("There was a problem rewriting parameter arithmetic in the Quil program: {0}")] RewriteArithmetic(#[from] rewrite_arithmetic::Error), From dc7b962150d465f77e06c8babae9895dad81fc25 Mon Sep 17 00:00:00 2001 From: Michael Bryant Date: Fri, 26 Jan 2024 11:10:09 -0800 Subject: [PATCH 2/7] fix(lib)!: renamed error variants for clarity --- crates/lib/src/executable.rs | 2 +- crates/lib/src/qpu/execution.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/lib/src/executable.rs b/crates/lib/src/executable.rs index 7f279f87e..d8e60e374 100644 --- a/crates/lib/src/executable.rs +++ b/crates/lib/src/executable.rs @@ -700,7 +700,7 @@ impl From for Error { match err { ExecutionError::Unexpected(inner) => Self::Unexpected(format!("{inner:?}")), ExecutionError::Quilc { .. } => Self::Connection(Service::Quilc), - ExecutionError::QcsClient(v) => Self::Unexpected(format!("{v:?}")), + ExecutionError::Translation(e) => Self::Translation(e), ExecutionError::Isa(v) => Self::Unexpected(format!("{v:?}")), ExecutionError::ReadoutParse(v) => Self::Unexpected(format!("{v:?}")), ExecutionError::Quil(e) => Self::Quil(e), diff --git a/crates/lib/src/qpu/execution.rs b/crates/lib/src/qpu/execution.rs index 406002f53..b785dbec3 100644 --- a/crates/lib/src/qpu/execution.rs +++ b/crates/lib/src/qpu/execution.rs @@ -49,8 +49,8 @@ pub(crate) enum Error { Unexpected(#[from] Unexpected), #[error("Problem communicating with quilc at {uri}: {details}")] Quilc { uri: String, details: String }, - #[error("Problem using QCS API: {0}")] - QcsClient(#[from] GrpcClientError), + #[error("Problem translating using QCS API: {0}")] + Translation(#[from] GrpcClientError), #[error("Problem fetching ISA: {0}")] Isa(#[from] GetIsaError), #[error("Problem parsing memory readout: {0}")] From 3059425eef36a43f81a2edb40b151d32500eed25 Mon Sep 17 00:00:00 2001 From: Michael Bryant Date: Fri, 26 Jan 2024 11:14:14 -0800 Subject: [PATCH 3/7] fix(lib)!: remove all unused Error variants --- crates/lib/src/executable.rs | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/crates/lib/src/executable.rs b/crates/lib/src/executable.rs index d8e60e374..964b5e4d6 100644 --- a/crates/lib/src/executable.rs +++ b/crates/lib/src/executable.rs @@ -603,29 +603,9 @@ impl<'execution> Executable<'_, 'execution> { /// [`Executable::execute_on_qvm`].. #[derive(Debug, thiserror::Error)] pub enum Error { - /// Communicating with QCS requires appropriate settings and secrets files. By default, these - /// should be `$HOME/.qcs/settings.toml` and `$HOME/.qcs/secrets.toml`, though those files can - /// be overridden by setting the `QCS_SETTINGS_FILE_PATH` and `QCS_SECRETS_FILE_PATH` - /// environment variables. - /// - /// This error can occur when one of those files is required but missing or there is a problem - /// with the contents of those files. - #[error("There was a problem related to your QCS settings: {0}")] - Settings(String), - /// This error occurs when the SDK was unable to authenticate a request to QCS. This could mean - /// that your credentials are invalid or expired, or that you do not have access to the requested - /// QPU. - #[error("Could not authenticate a request to QCS for the requested QPU.")] - Authentication, /// An API error occurred while connecting to the QPU. #[error("An API error occurred while connecting to the QPU: {0}")] QpuApiError(#[from] qpu::api::QpuApiError), - /// This happens when the QPU is down for maintenance and not accepting new jobs. If you receive - /// this error, internal compilation caches will have been cleared as programs should be recompiled - /// with new settings after a maintenance window. If you are mid-experiment, you might want to - /// start over. - #[error("QPU currently unavailable, retry after {} seconds", .0.as_secs())] - QpuUnavailable(Duration), /// Indicates a problem connecting to an external service. Check your network connection and /// ensure that any required local services (e.g., `qvm` or `quilc`) are running. #[error("Error connecting to service {0:?}")] @@ -650,22 +630,11 @@ pub enum Error { /// There was a problem when substituting parameters in the Quil program. #[error("There was a problem substituting parameters in the Quil program: {0}")] Substitution(String), - /// The Quil program is missing readout sources. - #[error("The Quil program is missing readout sources")] - MissingRoSources, /// This error returns when a runtime check that _should_ always pass fails. This most likely /// indicates a bug in the SDK and should be reported to /// [GitHub](https://github.com/rigetti/qcs-sdk-rust/issues), #[error("An unexpected error occurred, please open an issue on GitHub: {0:?}")] Unexpected(String), - /// Occurs when [`Executable::retrieve_results`] is called with an invalid [`JobHandle`]. - /// Calling functions on [`Executable`] between [`Executable::submit_to_qpu`] and - /// [`Executable::retrieve_results`] can invalidate the handle. - #[error("The job handle was not valid")] - InvalidJobHandle, - /// Occurs when failing to construct a [`Qcs`] client. - #[error("The QCS client configuration failed to load")] - QcsConfigLoadFailure(#[from] LoadError), } #[derive(Debug, Copy, Clone, Eq, PartialEq)] From edad2280c430997b1878f21e84b454ec2997ae58 Mon Sep 17 00:00:00 2001 From: Michael Bryant Date: Fri, 26 Jan 2024 11:55:29 -0800 Subject: [PATCH 4/7] refactor(lib): apply automatic clippy fixes --- crates/lib/src/compiler/libquil.rs | 4 ++-- crates/lib/src/executable.rs | 4 ++-- crates/lib/src/qpu/rewrite_arithmetic.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/lib/src/compiler/libquil.rs b/crates/lib/src/compiler/libquil.rs index f6b3f90db..0da2c46e4 100644 --- a/crates/lib/src/compiler/libquil.rs +++ b/crates/lib/src/compiler/libquil.rs @@ -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() { diff --git a/crates/lib/src/executable.rs b/crates/lib/src/executable.rs index 964b5e4d6..c13257225 100644 --- a/crates/lib/src/executable.rs +++ b/crates/lib/src/executable.rs @@ -5,9 +5,9 @@ use std::borrow::Cow; use std::collections::HashMap; use std::num::NonZeroU16; use std::sync::Arc; -use std::time::Duration; -use qcs_api_client_common::configuration::LoadError; + + use quil_rs::quil::ToQuilError; use crate::client::{GrpcClientError, Qcs}; diff --git a/crates/lib/src/qpu/rewrite_arithmetic.rs b/crates/lib/src/qpu/rewrite_arithmetic.rs index 241c59394..479dc54f5 100644 --- a/crates/lib/src/qpu/rewrite_arithmetic.rs +++ b/crates/lib/src/qpu/rewrite_arithmetic.rs @@ -367,6 +367,8 @@ impl RewrittenProgram { } } +pub(crate) type Substitutions = IndexSet; + #[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; From a7b2105cecc2e9b932ee89188f90440c92a8dcce Mon Sep 17 00:00:00 2001 From: Michael Bryant Date: Fri, 26 Jan 2024 11:56:31 -0800 Subject: [PATCH 5/7] chore: ignore an advisory that we can't do anything about right now --- deny.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/deny.toml b/deny.toml index 7b8cba519..5355f4529 100644 --- a/deny.toml +++ b/deny.toml @@ -28,6 +28,9 @@ ignore = [ "RUSTSEC-2023-0052", # Introduced by transitive dependency `webpki`. # `hyper-proxy`, then `qcs-api-client-rust` need to update in order to remove # `webpki`. + "RUSTSEC-2024-0006" # Introduced by transitive dependency `shlex`. + # `bindgen`, then `libquil-sys` need to update in order to get a version + # of `shlex` >= 1.3.0. ] # This section is considered when running `cargo deny check licenses` From 2a6dac1342904e12e83ff60d25b77a4c2394c65d Mon Sep 17 00:00:00 2001 From: Michael Bryant Date: Fri, 26 Jan 2024 14:04:05 -0800 Subject: [PATCH 6/7] chore: remove extra newlines --- crates/lib/src/executable.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/lib/src/executable.rs b/crates/lib/src/executable.rs index c13257225..c5e3eba5a 100644 --- a/crates/lib/src/executable.rs +++ b/crates/lib/src/executable.rs @@ -6,8 +6,6 @@ use std::collections::HashMap; use std::num::NonZeroU16; use std::sync::Arc; - - use quil_rs::quil::ToQuilError; use crate::client::{GrpcClientError, Qcs}; From 03de3399be2619a9ad76d6be08e4c438db1c5e4e Mon Sep 17 00:00:00 2001 From: Michael Bryant Date: Fri, 26 Jan 2024 14:04:27 -0800 Subject: [PATCH 7/7] fix: re-export tonic so consumers can inspect gRPC errors --- crates/lib/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/lib/src/lib.rs b/crates/lib/src/lib.rs index f8c0ffae3..05717b40e 100644 --- a/crates/lib/src/lib.rs +++ b/crates/lib/src/lib.rs @@ -56,6 +56,9 @@ pub use execution_data::{ }; pub use register_data::RegisterData; +// Re-export tonic for consumers to use. +pub use tonic; + pub mod client; pub mod compiler; pub mod diagnostics;