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!: implement Python wrappers for the full Rust API #230

Merged
merged 22 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a712312
refactor(lib): remove unused module
Shadow53 Jan 6, 2023
47bf6e0
refactor(lib)!: use num::Complex instead of custom typedef
Shadow53 Jan 6, 2023
8a68b83
chore(lib): remove newly removed lint
Shadow53 Jan 6, 2023
fd97469
refactor(lib)!: use Cow<str> instead of &str for execution
Shadow53 Jan 6, 2023
c2879aa
style(lib): resolve clippy lints
Shadow53 Jan 6, 2023
aa729d1
feat(python): start directly wrapping types from the Rust SDK
Shadow53 Jan 6, 2023
dbbc6e3
refactor(lib)!: replace Box<str> -> String, &str -> Cow<str>
Shadow53 Jan 9, 2023
87a39e1
feat(python): wrap more types for Python
Shadow53 Jan 9, 2023
6ad951b
feat(python): add missing wrappers for remaining types
Shadow53 Jan 9, 2023
d1cf077
refactor(python): change how Complex64ReadoutValues converts to/from …
Shadow53 Jan 9, 2023
e847da7
chore(python): use rigetti-pyo3 from git, not local path
Shadow53 Jan 10, 2023
1ae1298
feat(python): define default arguments to methods
Shadow53 Jan 10, 2023
ef9a28e
doc(lib): explain seeming type disagreement
Shadow53 Jan 23, 2023
5600581
refactor(python): simplify code, remove TODO
Shadow53 Jan 23, 2023
bfda07d
chore(python): remove unnecessary comments
Shadow53 Jan 24, 2023
258a664
refactor(lib): avoid confusion by changing Complex32 -> Complex<f32>
Shadow53 Jan 24, 2023
94c5a99
chore(python): bump minimum python version to 3.8
Shadow53 Jan 24, 2023
11002e2
chore(python): bump rigetti-pyo3
Shadow53 Jan 24, 2023
b9c91f3
chore(python): gitignore __pycache__
Shadow53 Jan 24, 2023
2babc4d
chore(lib): update tokio, disable unused warp features
Shadow53 Jan 24, 2023
208919c
test(python): fix failing test
Shadow53 Jan 24, 2023
4c4167d
chore(python): run poetry update
Shadow53 Jan 24, 2023
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
279 changes: 164 additions & 115 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ futures = "0.3.24"
indexmap = "1.9.1"
lazy_static = "1.4.0"
log = "0.4.17"
num = "0.4.0"
num = { version = "0.4.0", features = ["serde"] }
qcs-api = "0.2.1"
qcs-api-client-common = "0.2.7"
qcs-api-client-openapi = "0.3.8"
Expand Down
24 changes: 12 additions & 12 deletions crates/lib/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use std::{collections::HashMap, str::FromStr};

use num::complex::Complex32;
use qcs_api_client_grpc::{
models::controller::{readout_values, ControllerJobExecutionResult},
services::controller::{
Expand Down Expand Up @@ -55,7 +56,7 @@ pub enum RewriteArithmeticError {

/// The result of a call to [`rewrite_arithmetic`] which provides the
/// information necessary to later patch-in memory values to a compiled program.
#[derive(Debug, Serialize)]
Shadow53 marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Clone, Debug, Serialize)]
pub struct RewriteArithmeticResult {
/// The rewritten program
pub program: String,
Expand Down Expand Up @@ -193,17 +194,13 @@ pub fn build_patch_values(
.iter()
.map(|expr| Expression::from_str(expr))
.collect::<Result<_, _>>()
.map_err(|e| format!("Unable to interpret recalculation table: {:?}", e))?;
.map_err(|e| format!("Unable to interpret recalculation table: {e:?}"))?;
rewrite_arithmetic::get_substitutions(&substitutions, memory)
}

/// A convenience type that describes a Complex-64 value whose real
/// and imaginary parts of both f32.
pub type Complex64 = [f32; 2];

Shadow53 marked this conversation as resolved.
Show resolved Hide resolved
/// Data from an individual register. Each variant contains a vector with the expected data type
/// where each value in the vector corresponds to a shot.
#[derive(Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, PartialEq, Serialize)]
#[serde(untagged)] // Don't include the discriminant name in serialized output.
pub enum Register {
/// A register of 64-bit floating point numbers
Expand All @@ -213,7 +210,10 @@ pub enum Register {
/// A register of 32-bit integers
I32(Vec<i32>),
/// A register of 64-bit complex numbers
Complex64(Vec<Complex64>),
///
/// This type is called `Complex64` because the entire complex number takes 64 bits,
/// while the inner type is called `Complex32` because both components are `f32`.
Complex64(Vec<Complex32>),
Shadow53 marked this conversation as resolved.
Show resolved Hide resolved
/// A register of 8-bit integers (bytes)
I8(Vec<i8>),
}
Expand All @@ -224,15 +224,15 @@ impl From<qpu::runner::Register> for Register {
runner::Register::F64(f) => Register::F64(f),
runner::Register::I16(i) => Register::I16(i),
runner::Register::Complex32(c) => {
Register::Complex64(c.iter().map(|c| [c.re, c.im]).collect())
Register::Complex64(c.iter().map(|c| Complex32::new(c.re, c.im)).collect())
}
runner::Register::I8(i) => Register::I8(i),
}
}
}

/// The execution readout data from a particular memory location.
#[derive(Debug, Serialize)]
#[derive(Clone, Debug, Serialize)]
pub struct ExecutionResult {
shape: Vec<usize>,
data: Register,
Expand All @@ -248,7 +248,7 @@ impl From<readout_values::Values> for ExecutionResult {
data: Register::Complex64(
c.values
.iter()
.map(|c| [c.real.unwrap_or(0.0), c.imaginary.unwrap_or(0.0)])
.map(|c| Complex32::new(c.real.unwrap_or(0.0), c.imaginary.unwrap_or(0.0)))
.collect(),
),
},
Expand All @@ -262,7 +262,7 @@ impl From<readout_values::Values> for ExecutionResult {
}

/// Execution readout data for all memory locations.
#[derive(Debug, Serialize)]
#[derive(Clone, Debug, Serialize)]
pub struct ExecutionResults {
buffers: HashMap<String, ExecutionResult>,
execution_duration_microseconds: Option<u64>,
Expand Down
198 changes: 0 additions & 198 deletions crates/lib/src/configuration/mod.rs

This file was deleted.

14 changes: 0 additions & 14 deletions crates/lib/src/configuration/path.rs

This file was deleted.

Loading