Skip to content

Commit 7620a24

Browse files
authored
new: allow for additional "clients" for quilc and QVM (#346)
* new: allow for additional "clients" for quilc and QVM
1 parent 55f28f7 commit 7620a24

32 files changed

+957
-623
lines changed

Cargo.lock

+19-49
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/lib/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ otel-tracing = ["tracing-config", "qcs-api-client-grpc/otel-tracing", "qcs-api-c
1717

1818
[dependencies]
1919
cached = "0.44.0"
20-
dirs = "5.0.0"
2120
enum-as-inner = "0.5.1"
2221
futures = "0.3.24"
2322
indexmap = "1.9.1"
@@ -45,6 +44,7 @@ tonic = { version = "0.9.2", features = ["tls", "tls-roots"] }
4544
zmq = { version = "0.10.0" }
4645
itertools = "0.11.0"
4746
derive_builder = "0.12.0"
47+
async-trait = "0.1.73"
4848

4949
[dev-dependencies]
5050
erased-serde = "0.3.23"

crates/lib/examples/delayed_job_retrieval.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Submit a program to a QPU but don't immediately wait for the result.
22
3-
use qcs::{qpu::api::ExecutionOptions, Executable};
3+
use qcs::{client::Qcs, compiler::rpcq, qpu::api::ExecutionOptions, Executable};
44

55
const PROGRAM: &str = r#"
66
DECLARE ro BIT
@@ -10,9 +10,15 @@ MEASURE 0 ro[0]
1010

1111
const QUANTUM_PROCESSOR_ID: &str = "Aspen-M-3";
1212

13+
async fn quilc_client() -> rpcq::Client {
14+
let qcs = Qcs::load().await;
15+
let endpoint = qcs.get_config().quilc_url();
16+
rpcq::Client::new(endpoint).unwrap()
17+
}
18+
1319
#[tokio::main]
1420
async fn main() {
15-
let mut exe = Executable::from_quil(PROGRAM);
21+
let mut exe = Executable::from_quil(PROGRAM).with_quilc_client(Some(quilc_client().await));
1622
let job_handle = exe
1723
.submit_to_qpu(QUANTUM_PROCESSOR_ID, None, &ExecutionOptions::default())
1824
.await

crates/lib/examples/execute.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::f64::consts::PI;
22

3-
use qcs::{qpu::api::ExecutionOptions, Executable};
3+
use qcs::{client::Qcs, compiler::rpcq, qpu::api::ExecutionOptions, Executable};
44

55
const PROGRAM: &str = r#"
66
DECLARE ro BIT[2]
@@ -11,9 +11,15 @@ MEASURE 0 ro[0]
1111
MEASURE 1 ro[1]
1212
"#;
1313

14+
async fn quilc_client() -> rpcq::Client {
15+
let qcs = Qcs::load().await;
16+
let endpoint = qcs.get_config().quilc_url();
17+
rpcq::Client::new(endpoint).unwrap()
18+
}
19+
1420
#[tokio::main]
1521
async fn main() {
16-
let mut exe = Executable::from_quil(PROGRAM);
22+
let mut exe = Executable::from_quil(PROGRAM).with_quilc_client(Some(quilc_client().await));
1723

1824
let result = exe
1925
.with_parameter("theta", 0, PI)

crates/lib/examples/local.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::f64::consts::PI;
22

3-
use qcs::{qpu::api::ExecutionOptions, Executable};
3+
use qcs::{client::Qcs, compiler::rpcq, qpu::api::ExecutionOptions, Executable};
44

55
const PROGRAM: &str = r#"
66
DECLARE ro BIT[2]
@@ -12,9 +12,15 @@ MEASURE 0 ro[0]
1212
MEASURE 1 ro[1]
1313
"#;
1414

15+
async fn quilc_client() -> rpcq::Client {
16+
let qcs = Qcs::load().await;
17+
let endpoint = qcs.get_config().quilc_url();
18+
rpcq::Client::new(endpoint).unwrap()
19+
}
20+
1521
#[tokio::main]
1622
async fn main() {
17-
let mut exe = Executable::from_quil(PROGRAM);
23+
let mut exe = Executable::from_quil(PROGRAM).with_quilc_client(Some(quilc_client().await));
1824

1925
let result = exe
2026
.with_parameter("theta", 0, PI)

crates/lib/examples/parametric_compilation.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
use std::f64::consts::PI;
55
use std::time::Duration;
66

7+
use qcs::client::Qcs;
8+
use qcs::compiler::rpcq;
79
use qcs::qpu::api::ExecutionOptions;
810
use qcs::Executable;
911

@@ -17,10 +19,15 @@ RX(-pi / 2) 0
1719
1820
MEASURE 0 ro[0]
1921
"#;
22+
async fn quilc_client() -> rpcq::Client {
23+
let qcs = Qcs::load().await;
24+
let endpoint = qcs.get_config().quilc_url();
25+
rpcq::Client::new(endpoint).unwrap()
26+
}
2027

2128
#[tokio::main]
2229
async fn main() {
23-
let mut exe = Executable::from_quil(PROGRAM);
30+
let mut exe = Executable::from_quil(PROGRAM).with_quilc_client(Some(quilc_client().await));
2431
let mut parametric_measurements = Vec::with_capacity(200);
2532

2633
let step = 2.0 * PI / 50.0;

crates/lib/examples/quil_t.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! [pyquil]: https://pyquil-docs.rigetti.com/en/stable/quilt_getting_started.html#Another-example:-a-simple-T1-experiment
44
5-
use qcs::{qpu::api::ExecutionOptions, Executable};
5+
use qcs::{client::Qcs, compiler::rpcq, qpu::api::ExecutionOptions, Executable};
66

77
/// This program doesn't do much, the main point is that it will fail if quilc is invoked.
88
const PROGRAM: &str = r#"
@@ -12,13 +12,17 @@ FENCE 0
1212
DELAY 0 "rf" 1e-6
1313
MEASURE 0 ro
1414
"#;
15+
async fn quilc_client() -> rpcq::Client {
16+
let qcs = Qcs::load().await;
17+
let endpoint = qcs.get_config().quilc_url();
18+
rpcq::Client::new(endpoint).unwrap()
19+
}
1520

1621
#[tokio::main]
1722
async fn main() {
18-
let exe = Executable::from_quil(PROGRAM);
23+
let mut exe = Executable::from_quil(PROGRAM).with_quilc_client(Some(quilc_client().await));
1924

2025
let result = exe
21-
.compile_with_quilc(false)
2226
.execute_on_qpu("Aspen-M-3", None, &ExecutionOptions::default())
2327
.await
2428
.expect("Program should execute successfully")

crates/lib/src/compiler/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
44
mod isa;
55
pub mod quilc;
6-
mod rpcq;
6+
pub mod rpcq;

0 commit comments

Comments
 (0)