From 4d6b081fd7cbf33e095578254469cf089d4de6a8 Mon Sep 17 00:00:00 2001 From: Esteban Ginez <175813+eginez@users.noreply.github.com> Date: Sun, 31 Dec 2023 15:09:05 -0800 Subject: [PATCH 1/5] adds diagnotics for program execution --- Cargo.lock | 24 ++++++++++++++-- crates/lib/Cargo.toml | 1 + crates/lib/src/bin/diagnostics.rs | 1 + crates/lib/src/diagnostics.rs | 46 +++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ccc92a268..75227ee28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -224,7 +224,7 @@ dependencies = [ "cfg-if 0.1.10", "clang-sys", "clap", - "env_logger", + "env_logger 0.7.1", "lazy_static", "lazycell", "log", @@ -681,7 +681,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" dependencies = [ "atty", - "humantime", + "humantime 1.3.0", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "env_logger" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +dependencies = [ + "humantime 2.1.0", + "is-terminal", "log", "regex", "termcolor", @@ -1018,6 +1031,12 @@ dependencies = [ "quick-error", ] +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "hyper" version = "0.14.27" @@ -2062,6 +2081,7 @@ dependencies = [ "cached", "derive_builder", "enum-as-inner", + "env_logger 0.10.1", "erased-serde", "float-cmp", "futures", diff --git a/crates/lib/Cargo.toml b/crates/lib/Cargo.toml index 492bf1f47..d4431c4a1 100644 --- a/crates/lib/Cargo.toml +++ b/crates/lib/Cargo.toml @@ -17,6 +17,7 @@ otel-tracing = ["tracing-config", "qcs-api-client-grpc/otel-tracing", "qcs-api-c libquil = ["dep:libquil-sys"] [dependencies] +env_logger = "0.10" cached = "0.44.0" enum-as-inner = "0.5.1" futures = "0.3.24" diff --git a/crates/lib/src/bin/diagnostics.rs b/crates/lib/src/bin/diagnostics.rs index 9700badda..e682a715b 100644 --- a/crates/lib/src/bin/diagnostics.rs +++ b/crates/lib/src/bin/diagnostics.rs @@ -1,5 +1,6 @@ #[tokio::main] async fn main() { + env_logger::init(); let diagnostics = qcs::diagnostics::get_report().await; println!("{diagnostics}"); } diff --git a/crates/lib/src/diagnostics.rs b/crates/lib/src/diagnostics.rs index 2b5f52583..480e3c9ae 100644 --- a/crates/lib/src/diagnostics.rs +++ b/crates/lib/src/diagnostics.rs @@ -2,16 +2,32 @@ //! in debugging and remote user support. use std::{borrow::Cow, time::Duration}; +use std::f64::consts::PI; +//use qcs::Executable; +//use qcs::qpu::api::ExecutionOptions; + use qcs_api_client_openapi::models::User; +use crate::compiler::quilc::CompilerOpts; use crate::{ build_info, client::Qcs, compiler::{quilc::Client as _, rpcq}, qvm::{self, Client as _, QvmOptions}, + Executable, + qpu::api::ExecutionOptions, }; +const PROGRAM: &str = r#" +DECLARE ro BIT[2] +DECLARE theta REAL +RX(theta) 0 +CNOT 0 1 +MEASURE 0 ro[0] +MEASURE 1 ro[1] +"#; + /// Collect package diagnostics in string form pub async fn get_report() -> String { Diagnostics::gather().await.to_string() @@ -34,6 +50,30 @@ struct Diagnostics { quilc: QuilcDiagnostics, qvm: QvmDiagnostics, libquil: LibquilDiagnostics, + send_program: bool, + +} + +async fn execute_simple_circuit() -> bool { + // Load qcs client + let qcs = Qcs::load().await; + let endpoint = qcs.get_config().quilc_url(); + let quilc_client = crate::compiler::rpcq::Client::new(endpoint).unwrap(); + let mut exe = Executable::from_quil(PROGRAM) + .with_quilc_client(Some(quilc_client)) + .compiler_options(CompilerOpts{ + timeout: Some(10.0), + protoquil: None, + + }); + tracing::info!("Executing"); + let result = exe + .with_parameter("theta", 0, PI) + .execute_on_qpu("Aspen-M-3", None, &ExecutionOptions::default()) + .await + .expect("Program should execute successfully"); + + return true; } impl Diagnostics { @@ -45,6 +85,8 @@ impl Diagnostics { QvmDiagnostics::gather(&client), ) .await; + + let prg_execute = execute_simple_circuit(); Self { version: build_info::PKG_VERSION.to_owned(), rust_version: build_info::RUSTC_VERSION.to_owned(), @@ -53,6 +95,7 @@ impl Diagnostics { quilc: QuilcDiagnostics::gather(&client), qvm, libquil: LibquilDiagnostics::gather().await, + send_program: prg_execute.await, } } } @@ -90,6 +133,7 @@ impl std::fmt::Display for Diagnostics { " qvm version: {}", format_option(self.libquil.qvm_version.as_ref()) )?; + writeln!(f, " send program: {}", self.send_program)?; Ok(()) } } @@ -276,3 +320,5 @@ where None => "-".into(), } } + + From 1a81ee0d991b17f02689505cf950e8dbeebbbbf6 Mon Sep 17 00:00:00 2001 From: Esteban Ginez <175813+eginez@users.noreply.github.com> Date: Sun, 31 Dec 2023 15:13:46 -0800 Subject: [PATCH 2/5] Add documentatin --- README.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index aedbb574c..57104e6b6 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ Most development tasks are automated with [cargo-make] (like make, but you can h In order to run all checks exactly the same way that CI does, use `makers ci-flow` from the project root (workspace). - ### Commits Commits should follow the conventional commit syntax, with one of the following [scopes](scopes): @@ -44,8 +43,9 @@ Any tests which cannot be run in CI should be run with `makers manual`. These te [`libquil`](https://github.com/rigetti/libquil) provides [quilc](https://github.com/quil-lang/quilc) and [QVM](https://github.com/quil-lang/qvm) as a shared library, which can be used by `qcs-sdk-rust` as an alternative client for those tools. To use `libquil`: -* install the library (see [installation instructions](https://github.com/rigetti/libquil#automated-installation)) -* enable the feature with `--features libquil` + +- install the library (see [installation instructions](https://github.com/rigetti/libquil#automated-installation)) +- enable the feature with `--features libquil` ### Linting @@ -73,3 +73,17 @@ This repository uses GitHub actions for its CI. If you are making changes to a w [rustdoc]: https://doc.rust-lang.org/rustdoc/index.html [docs.rs]: https://docs.rs/qcs [scopes]: https://www.conventionalcommits.org/en/v1.0.0/#commit-message-with-scope + +## To build extendend diagnostics + +### Build + +``` +cargo build --feature tracing +``` + +### Execute + +``` +RUST_LOG=debug target/debug/diagnostics +``` From c898f0aa8d7bb07d23bf90b8a596c4ca99d04ce7 Mon Sep 17 00:00:00 2001 From: Esteban Ginez <175813+eginez@users.noreply.github.com> Date: Tue, 9 Jan 2024 09:54:45 -0800 Subject: [PATCH 3/5] adds configration for connection timeout --- crates/lib/src/qpu/api.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/lib/src/qpu/api.rs b/crates/lib/src/qpu/api.rs index 20c974983..90a687f7e 100644 --- a/crates/lib/src/qpu/api.rs +++ b/crates/lib/src/qpu/api.rs @@ -202,6 +202,9 @@ pub struct ExecutionOptions { #[doc = "The timeout to use for the request, defaults to 30 seconds. If set to `None`, then there is no timeout."] #[builder(default = "Some(Duration::from_secs(30))")] timeout: Option, + #[doc = "The timeout to use for the connection, defaults to `None`seconds. If set to `None`, then there is no timeout."] + #[builder(default = "Some(Duration::from_secs(30))")] + connection_timeout: Option, } impl ExecutionOptions { @@ -222,6 +225,11 @@ impl ExecutionOptions { pub fn timeout(&self) -> Option { self.timeout } + /// Get the connection timeout. + #[must_use] + pub fn connection_timeout(&self) -> Option { + self.connection_timeout + } } /// The connection strategy to use when submitting and retrieving jobs from a QPU. @@ -319,7 +327,7 @@ impl ExecutionOptions { client: &Qcs, ) -> Result { let uri = parse_uri(address).map_err(QpuApiError::GrpcError)?; - let channel = get_channel_with_timeout(uri, self.timeout()) + let channel = get_channel_with_timeout(uri, self.timeout(), self.connection_timeout()) .map_err(|err| QpuApiError::GrpcError(err.into()))?; Ok(wrap_channel_with(channel, client.get_config().clone())) } From 8652b15ea7dd8fbba5226f6b10f83e744b52fa02 Mon Sep 17 00:00:00 2001 From: Esteban Ginez <175813+eginez@users.noreply.github.com> Date: Tue, 9 Jan 2024 09:58:42 -0800 Subject: [PATCH 4/5] undo changes --- Cargo.lock | 24 ++---------------------- README.md | 20 +++----------------- crates/lib/Cargo.toml | 1 - crates/lib/src/bin/diagnostics.rs | 1 - 4 files changed, 5 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 75227ee28..ccc92a268 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -224,7 +224,7 @@ dependencies = [ "cfg-if 0.1.10", "clang-sys", "clap", - "env_logger 0.7.1", + "env_logger", "lazy_static", "lazycell", "log", @@ -681,20 +681,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" dependencies = [ "atty", - "humantime 1.3.0", - "log", - "regex", - "termcolor", -] - -[[package]] -name = "env_logger" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" -dependencies = [ - "humantime 2.1.0", - "is-terminal", + "humantime", "log", "regex", "termcolor", @@ -1031,12 +1018,6 @@ dependencies = [ "quick-error", ] -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "hyper" version = "0.14.27" @@ -2081,7 +2062,6 @@ dependencies = [ "cached", "derive_builder", "enum-as-inner", - "env_logger 0.10.1", "erased-serde", "float-cmp", "futures", diff --git a/README.md b/README.md index 57104e6b6..aedbb574c 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Most development tasks are automated with [cargo-make] (like make, but you can h In order to run all checks exactly the same way that CI does, use `makers ci-flow` from the project root (workspace). + ### Commits Commits should follow the conventional commit syntax, with one of the following [scopes](scopes): @@ -43,9 +44,8 @@ Any tests which cannot be run in CI should be run with `makers manual`. These te [`libquil`](https://github.com/rigetti/libquil) provides [quilc](https://github.com/quil-lang/quilc) and [QVM](https://github.com/quil-lang/qvm) as a shared library, which can be used by `qcs-sdk-rust` as an alternative client for those tools. To use `libquil`: - -- install the library (see [installation instructions](https://github.com/rigetti/libquil#automated-installation)) -- enable the feature with `--features libquil` +* install the library (see [installation instructions](https://github.com/rigetti/libquil#automated-installation)) +* enable the feature with `--features libquil` ### Linting @@ -73,17 +73,3 @@ This repository uses GitHub actions for its CI. If you are making changes to a w [rustdoc]: https://doc.rust-lang.org/rustdoc/index.html [docs.rs]: https://docs.rs/qcs [scopes]: https://www.conventionalcommits.org/en/v1.0.0/#commit-message-with-scope - -## To build extendend diagnostics - -### Build - -``` -cargo build --feature tracing -``` - -### Execute - -``` -RUST_LOG=debug target/debug/diagnostics -``` diff --git a/crates/lib/Cargo.toml b/crates/lib/Cargo.toml index d4431c4a1..492bf1f47 100644 --- a/crates/lib/Cargo.toml +++ b/crates/lib/Cargo.toml @@ -17,7 +17,6 @@ otel-tracing = ["tracing-config", "qcs-api-client-grpc/otel-tracing", "qcs-api-c libquil = ["dep:libquil-sys"] [dependencies] -env_logger = "0.10" cached = "0.44.0" enum-as-inner = "0.5.1" futures = "0.3.24" diff --git a/crates/lib/src/bin/diagnostics.rs b/crates/lib/src/bin/diagnostics.rs index e682a715b..9700badda 100644 --- a/crates/lib/src/bin/diagnostics.rs +++ b/crates/lib/src/bin/diagnostics.rs @@ -1,6 +1,5 @@ #[tokio::main] async fn main() { - env_logger::init(); let diagnostics = qcs::diagnostics::get_report().await; println!("{diagnostics}"); } From 35b03e7c697e3ff5fd6ac1fd6945c74b44d95f64 Mon Sep 17 00:00:00 2001 From: Esteban Ginez <175813+eginez@users.noreply.github.com> Date: Tue, 9 Jan 2024 09:59:19 -0800 Subject: [PATCH 5/5] more changes to undo --- crates/lib/src/diagnostics.rs | 46 ----------------------------------- 1 file changed, 46 deletions(-) diff --git a/crates/lib/src/diagnostics.rs b/crates/lib/src/diagnostics.rs index 480e3c9ae..2b5f52583 100644 --- a/crates/lib/src/diagnostics.rs +++ b/crates/lib/src/diagnostics.rs @@ -2,32 +2,16 @@ //! in debugging and remote user support. use std::{borrow::Cow, time::Duration}; -use std::f64::consts::PI; -//use qcs::Executable; -//use qcs::qpu::api::ExecutionOptions; - use qcs_api_client_openapi::models::User; -use crate::compiler::quilc::CompilerOpts; use crate::{ build_info, client::Qcs, compiler::{quilc::Client as _, rpcq}, qvm::{self, Client as _, QvmOptions}, - Executable, - qpu::api::ExecutionOptions, }; -const PROGRAM: &str = r#" -DECLARE ro BIT[2] -DECLARE theta REAL -RX(theta) 0 -CNOT 0 1 -MEASURE 0 ro[0] -MEASURE 1 ro[1] -"#; - /// Collect package diagnostics in string form pub async fn get_report() -> String { Diagnostics::gather().await.to_string() @@ -50,30 +34,6 @@ struct Diagnostics { quilc: QuilcDiagnostics, qvm: QvmDiagnostics, libquil: LibquilDiagnostics, - send_program: bool, - -} - -async fn execute_simple_circuit() -> bool { - // Load qcs client - let qcs = Qcs::load().await; - let endpoint = qcs.get_config().quilc_url(); - let quilc_client = crate::compiler::rpcq::Client::new(endpoint).unwrap(); - let mut exe = Executable::from_quil(PROGRAM) - .with_quilc_client(Some(quilc_client)) - .compiler_options(CompilerOpts{ - timeout: Some(10.0), - protoquil: None, - - }); - tracing::info!("Executing"); - let result = exe - .with_parameter("theta", 0, PI) - .execute_on_qpu("Aspen-M-3", None, &ExecutionOptions::default()) - .await - .expect("Program should execute successfully"); - - return true; } impl Diagnostics { @@ -85,8 +45,6 @@ impl Diagnostics { QvmDiagnostics::gather(&client), ) .await; - - let prg_execute = execute_simple_circuit(); Self { version: build_info::PKG_VERSION.to_owned(), rust_version: build_info::RUSTC_VERSION.to_owned(), @@ -95,7 +53,6 @@ impl Diagnostics { quilc: QuilcDiagnostics::gather(&client), qvm, libquil: LibquilDiagnostics::gather().await, - send_program: prg_execute.await, } } } @@ -133,7 +90,6 @@ impl std::fmt::Display for Diagnostics { " qvm version: {}", format_option(self.libquil.qvm_version.as_ref()) )?; - writeln!(f, " send program: {}", self.send_program)?; Ok(()) } } @@ -320,5 +276,3 @@ where None => "-".into(), } } - -