-
Notifications
You must be signed in to change notification settings - Fork 5
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
Expose hardware prng sequence #515
Open
erichulburd
wants to merge
6
commits into
rigetti:main
Choose a base branch
from
erichulburd:expose_hardware_prng_sequence
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
33af34c
feat: prng and randomized measurements
erichulburd f24f674
chore: documentation cleaning
erichulburd e0d1233
tests: update subtest allowlist
erichulburd d58afd3
chore: update codeowners with new python structure
erichulburd 54e3d3c
chore: update maturin
erichulburd b80e053
fix: bump upper quil-rs bound
erichulburd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
crates/lib/src/qpu/experimental @erichulburd | ||
crates/python/src/qpu/experimental.rs @erichulburd | ||
crates/python/qcs_sdk/qpu/experimental @erichulburd | ||
crates/python/tests/qpu/experimental @erichulburd |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
//! This example demonstrates how to construct and then execute a program with | ||
//! randomized measurements. Specifically, we will use a ZXZXZ unitary | ||
//! decomposition to randomly draw from a | ||
//! [tetrahedral unitary ensemble](https://en.wikipedia.org/wiki/Tetrahedral_symmetry). | ||
use std::num::NonZeroU16; | ||
use std::str::FromStr; | ||
|
||
use itertools::Itertools; | ||
use qcs::qpu::experimental::random::PrngSeedValue; | ||
use qcs::qpu::experimental::randomized_measurements::{ | ||
QubitRandomization, RandomizedMeasurements, UnitarySet, | ||
}; | ||
use qcs::{qpu::api::ExecutionOptions, Executable}; | ||
use quil_rs::instruction::Measurement; | ||
use quil_rs::quil::Quil; | ||
use quil_rs::Program; | ||
|
||
include!("../src/qpu/experimental/unitary_set_zxzxz.rs"); | ||
|
||
const BASE_PROGRAM: &str = r#" | ||
DECLARE ro BIT[3] | ||
RX(pi/2) 0 | ||
RX(pi/2) 1 | ||
RX(pi/2) 2 | ||
"#; | ||
|
||
const NUM_SHOTS: u16 = 5_000; | ||
|
||
const SEED_VALUES: [(u64, u64); 3] = [(0, 555_571_734), (1, 467_091_842), (2, 925_313_021)]; | ||
|
||
const LEADING_DELAY_SECONDS: f64 = 1e-5; | ||
|
||
const DEFAULT_QUANTUM_PROCESSOR_ID: &str = "Ankaa-3"; | ||
|
||
fn quantum_processor_id() -> String { | ||
std::env::var("QUANTUM_PROCESSOR_ID") | ||
.unwrap_or_else(|_| DEFAULT_QUANTUM_PROCESSOR_ID.to_string()) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let program = | ||
Program::from_str(BASE_PROGRAM).expect("BASE_PROGRAM should be a valid Quil program"); | ||
let measurements = (0..2) | ||
.map(|q| { | ||
Measurement::new( | ||
Qubit::Fixed(q), | ||
Some(MemoryReference::new("ro".to_string(), q)), | ||
) | ||
}) | ||
.collect(); | ||
let unitary_set = | ||
ZxzxzUnitarySet::tetrahedral().expect("tetrahedral unitary set should be valid"); | ||
|
||
let leading_delay = Expression::Number(Complex64::new(LEADING_DELAY_SECONDS, 0.0)); | ||
let randomized_measurements = | ||
RandomizedMeasurements::try_new(measurements, unitary_set, leading_delay) | ||
.expect("RandomizedMeasurements should be successfully created"); | ||
let program_with_random_measurements = randomized_measurements | ||
.append_to_program(program) | ||
.expect("Program should be successfully appended with randomized measurements"); | ||
let seed_values = SEED_VALUES | ||
.iter() | ||
.copied() | ||
.map(|(qubit, seed_value)| PrngSeedValue::try_new(seed_value).map(|seed| (qubit, seed))) | ||
.try_collect() | ||
.expect("prng seeds must be valid"); | ||
let parameters = randomized_measurements | ||
.to_parameters(&seed_values) | ||
.expect("parameters should be successfully created"); | ||
|
||
let mut exe = Executable::from_quil( | ||
program_with_random_measurements | ||
.to_quil() | ||
.expect("Program should be successfully converted to Quil"), | ||
) | ||
.with_shots( | ||
NonZeroU16::new(NUM_SHOTS) | ||
.unwrap_or_else(|| panic!("{} should be a valid number of shots", NUM_SHOTS)), | ||
); | ||
parameters.into_iter().for_each(|(name, values)| { | ||
values.into_iter().enumerate().for_each(|(index, value)| { | ||
exe.with_parameter(name.clone(), index, value); | ||
}); | ||
}); | ||
|
||
let job_handle = exe | ||
.submit_to_qpu(quantum_processor_id(), None, &ExecutionOptions::default()) | ||
.await | ||
.expect("Program should be successfully submitted for execution"); | ||
let _data = exe | ||
.retrieve_results(job_handle) | ||
.await | ||
.expect("Results should be successfully retrieved"); | ||
println!("program constructed, translated, and executed successfully!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//! This module supports experimental features that meet the following criteria: | ||
//! | ||
//! * They support recent and compelling research in quantum computing. | ||
//! * Implementation is specific to Rigetti's QPUs; implementation may | ||
//! not othewrise be expressed through a generalized quantum computing | ||
//! language, such as Quil or QASM. | ||
//! | ||
//! As such, the features contained herein should be considered unstable, possibly | ||
erichulburd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//! ephemeral, and subject to specific authorization checks. | ||
pub mod random; | ||
pub mod randomized_measurements; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have push permissions to this repository, which is probably related to the error reported by Github here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shadow53 did you add Eric since this comment was made? It looks like he should already have
admin
permission.