Skip to content

Commit

Permalink
chore: test that similar calibrations with different sites are not fi…
Browse files Browse the repository at this point in the history
…ltered (#268)

* wip: test that similar calibrations with different sites are not
de-duplicated

* use snapshot testing, rstest file globbing
  • Loading branch information
MarquessV authored Aug 3, 2023
1 parent 27ba509 commit 0c6dd84
Show file tree
Hide file tree
Showing 13 changed files with 493 additions and 8 deletions.
29 changes: 22 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion quil-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ insta = "1.7.1"
petgraph = "0.6.2"
proptest = "1.0.0"
proptest-derive = "0.3.0"
rstest = "0.17.0"
rstest = "0.18.1"

# These are described in the crate README.md
[features]
Expand Down
19 changes: 19 additions & 0 deletions quil-rs/tests/calibration_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::fs::read_to_string;
use std::path::PathBuf;
use std::str::FromStr;

use insta::assert_snapshot;
use rstest::rstest;

use quil_rs::program::Program;

/// A test to ensure that a Program doesn't incorrectly filter out calibrations
/// when it is parsed.
#[rstest]
fn test_calibration_filtering(#[files("tests/programs/calibration_*.quil")] path: PathBuf) {
let program_text =
read_to_string(&path).unwrap_or_else(|_| panic!("Should be able to load file: {:?}", path));
let program = Program::from_str(&program_text).expect("Should be able to parse test program.");

assert_snapshot!(path.file_name().unwrap().to_str(), program.to_string());
}
28 changes: 28 additions & 0 deletions quil-rs/tests/programs/calibration_cz.quil
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
DEFCAL CZ 110 111:
FENCE
NONBLOCKING PULSE 110 111 "cz" q110_q111_cz/CZ
DELAY 110 "rf" 1.6e-07
SHIFT-PHASE 110 "rf" 0.6
DELAY 111 "rf" 1.6e-07
SHIFT-PHASE 111 "rf" 0.4
FENCE
SHIFT-PHASE 110 111 "xy" 0.3
SHIFT-PHASE 110 117 "xy" 0.3
SHIFT-PHASE 110 111 "xy" -0.2
SHIFT-PHASE 111 112 "xy" -0.2
SHIFT-PHASE 111 126 "xy" -0.2

DEFCAL CZ 111 110:
FENCE
NONBLOCKING PULSE 110 111 "cz" q110_q111_cz/CZ
DELAY 110 "rf" 1.6e-07
SHIFT-PHASE 110 "rf" 0.6
DELAY 111 "rf" 1.6e-07
SHIFT-PHASE 111 "rf" 0.4
FENCE
SHIFT-PHASE 110 111 "xy" 0.3
SHIFT-PHASE 110 117 "xy" 0.3
SHIFT-PHASE 110 111 "xy" -0.2
SHIFT-PHASE 111 112 "xy" -0.2
SHIFT-PHASE 111 126 "xy" -0.2

62 changes: 62 additions & 0 deletions quil-rs/tests/programs/calibration_cz_phase.quil
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
DEFCAL CZ 110 111:
FENCE
NONBLOCKING PULSE 110 111 "cz" q110_q111_cz/CZ
DELAY 110 "rf" 1.6e-07
SHIFT-PHASE 110 "rf" 0.6
DELAY 111 "rf" 1.6e-07
SHIFT-PHASE 111 "rf" 0.4
FENCE
SHIFT-PHASE 110 111 "xy" 0.3
SHIFT-PHASE 110 117 "xy" 0.3
SHIFT-PHASE 110 111 "xy" -0.2
SHIFT-PHASE 111 112 "xy" -0.2
SHIFT-PHASE 111 126 "xy" -0.2

DEFCAL CZ 111 110:
FENCE
NONBLOCKING PULSE 110 111 "cz" q110_q111_cz/CZ
DELAY 110 "rf" 1.6e-07
SHIFT-PHASE 110 "rf" 0.6
DELAY 111 "rf" 1.6e-07
SHIFT-PHASE 111 "rf" 0.4
FENCE
SHIFT-PHASE 110 111 "xy" 0.3
SHIFT-PHASE 110 117 "xy" 0.3
SHIFT-PHASE 110 111 "xy" -0.2
SHIFT-PHASE 111 112 "xy" -0.2
SHIFT-PHASE 111 126 "xy" -0.2

DEFCAL CPHASE(%theta) 110 111:
FENCE
NONBLOCKING PULSE 110 111 "cphase" q110_q111_cphase/sqrtCPHASE
SHIFT-PHASE 110 111 "cphase" -1.2 + 0.5*%theta
NONBLOCKING PULSE 110 111 "cphase" q110_q111_cphase/sqrtCPHASE
SHIFT-PHASE 110 111 "cphase" -1*(-1.2 + 0.5*%theta)
DELAY 110 "rf" 3.2e-07
SHIFT-PHASE 110 "rf" 2.2
DELAY 111 "rf" 3.2e-07
SHIFT-PHASE 111 "rf" 1.2
FENCE
SHIFT-PHASE 110 111 "xy" 1.1
SHIFT-PHASE 110 117 "xy" 1.1
SHIFT-PHASE 110 111 "xy" -0.6
SHIFT-PHASE 111 112 "xy" -0.6
SHIFT-PHASE 111 126 "xy" -0.6

DEFCAL CPHASE(%theta) 111 110:
FENCE
NONBLOCKING PULSE 110 111 "cphase" q110_q111_cphase/sqrtCPHASE
SHIFT-PHASE 110 111 "cphase" -1.2 + 0.5*%theta
NONBLOCKING PULSE 110 111 "cphase" q110_q111_cphase/sqrtCPHASE
SHIFT-PHASE 110 111 "cphase" -1*(-1.2 + 0.5*%theta)
DELAY 110 "rf" 3.2e-07
SHIFT-PHASE 110 "rf" 2.2
DELAY 111 "rf" 3.2e-07
SHIFT-PHASE 111 "rf" 1.2
FENCE
SHIFT-PHASE 110 111 "xy" 1.1
SHIFT-PHASE 110 117 "xy" 1.1
SHIFT-PHASE 110 111 "xy" -0.6
SHIFT-PHASE 111 112 "xy" -0.6
SHIFT-PHASE 111 126 "xy" -0.6

39 changes: 39 additions & 0 deletions quil-rs/tests/programs/calibration_measure.quil
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
DEFCAL MEASURE 0 addr:
FENCE 0
DECLARE q0_unclassified REAL[2]
PULSE 0 "rf_f12" gaussian(duration: 6e-08, fwhm: 1.6e-08, t0: 3e-08, scale: 0.5, phase: 0.0, detuning: 0.0)
NONBLOCKING PULSE 0 "ro_tx" flat(duration: 1.6e-06, iq: 1.0, scale: 0.1, phase: 0.0, detuning: 0.0)
NONBLOCKING CAPTURE 0 "ro_rx" boxcar_kernel(duration: 1.6e-06, scale: 1.0, phase: 0.0, detuning: 0.0) q0_unclassified[0]
PRAGMA FILTER-NODE q0_unclassified "{'module':'standard.filters.io','filter_type':'DataBuffer','source':'q0_ro_rx/filter','publish':true,'params':{},'_type':'FilterNode'}"
PRAGMA LOAD-MEMORY q0_unclassified "q0_unclassified[0]"
PRAGMA FILTER-NODE q0_classified "{'module':'standard.filters.classifiers','filter_type':'SingleQLinear','source':'q0_ro_rx/filter','publish':false,'params':{'a':[1.0,0.0],'threshold':0.01},'_type':'FilterNode'}"
PRAGMA FILTER-NODE q0 "{'module':'standard.filters.io','filter_type':'DataBuffer','source':'q0_classified','publish':true,'params':{},'_type':'FilterNode'}"
PRAGMA LOAD-MEMORY q0 "addr"
FENCE 0

DEFCAL MEASURE 10 addr:
FENCE 10
DECLARE q10_unclassified REAL[2]
PULSE 10 "rf_f12" gaussian(duration: 7e-08, fwhm: 1.7e-08, t0: 3e-08, scale: 0.5, phase: 0.0, detuning: 0.0)
NONBLOCKING PULSE 10 "ro_tx" flat(duration: 1.6e-06, iq: 1.0, scale: 0.1, phase: 0.0, detuning: 0.0)
NONBLOCKING CAPTURE 10 "ro_rx" boxcar_kernel(duration: 1.6e-06, scale: 1.0, phase: 0.0, detuning: 0.0) q10_unclassified[0]
PRAGMA FILTER-NODE q10_unclassified "{'module':'standard.filters.io','filter_type':'DataBuffer','source':'q10_ro_rx/filter','publish':true,'params':{},'_type':'FilterNode'}"
PRAGMA LOAD-MEMORY q10_unclassified "q10_unclassified[0]"
PRAGMA FILTER-NODE q10_classified "{'module':'standard.filters.classifiers','filter_type':'SingleQLinear','source':'q10_ro_rx/filter','publish':false,'params':{'a':[1.0,0.0],'threshold':0.01},'_type':'FilterNode'}"
PRAGMA FILTER-NODE q10 "{'module':'standard.filters.io','filter_type':'DataBuffer','source':'q10_classified','publish':true,'params':{},'_type':'FilterNode'}"
PRAGMA LOAD-MEMORY q10 "addr"
FENCE 10

DEFCAL MEASURE 100 addr:
FENCE 100
DECLARE q100_unclassified REAL[2]
PULSE 100 "rf_f12" gaussian(duration: 8e-08, fwhm: 1.8e-08, t0: 3e-08, scale: 0.5, phase: 0.0, detuning: 0.0)
NONBLOCKING PULSE 100 "ro_tx" flat(duration: 1.6e-06, iq: 1.0, scale: 0.1, phase: 0.0, detuning: 0.0)
NONBLOCKING CAPTURE 100 "ro_rx" boxcar_kernel(duration: 1.6e-06, scale: 1.0, phase: 0.0, detuning: 0.0) q100_unclassified[0]
PRAGMA FILTER-NODE q100_unclassified "{'module':'standard.filters.io','filter_type':'DataBuffer','source':'q100_ro_rx/filter','publish':true,'params':{},'_type':'FilterNode'}"
PRAGMA LOAD-MEMORY q100_unclassified "q100_unclassified[0]"
PRAGMA FILTER-NODE q100_classified "{'module':'standard.filters.classifiers','filter_type':'SingleQLinear','source':'q10_ro_rx/filter','publish':false,'params':{'a':[1.0,0.0],'threshold':0.01},'_type':'FilterNode'}"
PRAGMA FILTER-NODE q100 "{'module':'standard.filters.io','filter_type':'DataBuffer','source':'q100_classified','publish':true,'params':{},'_type':'FilterNode'}"
PRAGMA LOAD-MEMORY q100 "addr"
FENCE 100

40 changes: 40 additions & 0 deletions quil-rs/tests/programs/calibration_rx.quil
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
DEFCAL RX(pi/2) 0:
FENCE 0
NONBLOCKING PULSE 0 "rf" drag_gaussian(duration: 1e-08, fwhm: 1e-08, t0: 1e-08, anh: -100000000.0, alpha: -0.1, scale: 0.1, phase: 0.0, detuning: 0.0)
FENCE 0

DEFCAL RX(-pi/2) 0:
FENCE 0
NONBLOCKING PULSE 0 "rf" drag_gaussian(duration: 1e-08, fwhm: 1e-08, t0: 1e-08, anh: -100000000.0, alpha: -0.2, scale: 0.2, phase: 0.0, detuning: 0.0)
FENCE 0

DEFCAL RX(pi) 0:
FENCE 0
NONBLOCKING PULSE 0 "rf" drag_gaussian(duration: 1e-08, fwhm: 1e-08, t0: 1e-08, anh: -100000000.0, alpha: -0.3, scale: 0.3, phase: 0.0, detuning: 0.0)
FENCE 0

DEFCAL RX(-pi) 0:
FENCE 0
NONBLOCKING PULSE 0 "rf" drag_gaussian(duration: 1e-08, fwhm: 1e-08, t0: 1e-08, anh: -100000000.0, alpha: -0.4, scale: 0.4, phase: 0.0, detuning: 0.0)
FENCE 0

DEFCAL RX(pi/2) 3:
FENCE 3
NONBLOCKING PULSE 3 "rf" drag_gaussian(duration: 2e-08, fwhm: 1e-08, t0: 1e-08, anh: -100000000.0, alpha: -0.1, scale: 0.1, phase: 0.0, detuning: 0.0)
FENCE 3

DEFCAL RX(-pi/2) 3:
FENCE 3
NONBLOCKING PULSE 3 "rf" drag_gaussian(duration: 2e-08, fwhm: 1e-08, t0: 1e-08, anh: -100000000.0, alpha: -0.2, scale: 0.2, phase: 0.0, detuning: 0.0)
FENCE 3

DEFCAL RX(pi) 3:
FENCE 3
NONBLOCKING PULSE 3 "rf" drag_gaussian(duration: 2e-08, fwhm: 1e-08, t0: 1e-08, anh: -100000000.0, alpha: -0.3, scale: 0.3, phase: 0.0, detuning: 0.0)
FENCE 3

DEFCAL RX(-pi) 3:
FENCE 3
NONBLOCKING PULSE 3 "rf" drag_gaussian(duration: 2e-08, fwhm: 1e-08, t0: 1e-08, anh: -100000000.0, alpha: -0.4, scale: 0.4, phase: 0.0, detuning: 0.0)
FENCE 3

52 changes: 52 additions & 0 deletions quil-rs/tests/programs/calibration_xy.quil
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
DEFCAL XY(%theta) 110 111:
FENCE
SHIFT-PHASE 110 111 "xy" 0.4
NONBLOCKING PULSE 110 111 "xy" q110_q111_xy/sqrtiSWAP
SHIFT-PHASE 110 111 "xy" -0.4
SHIFT-PHASE 110 111 "xy" 1.8 + -0.5*%theta
NONBLOCKING PULSE 110 111 "xy" q110_q111_xy/sqrtiSWAP
SHIFT-PHASE 110 111 "xy" -1*(1.8 + -0.5*%theta)
DELAY 110 "rf" 1.2e-07
SHIFT-PHASE 110 "rf" 0.8
DELAY 111 "rf" 1.2e-07
SHIFT-PHASE 111 "rf" 0.4
SHIFT-PHASE 111 "rf" 0.5*%theta
SHIFT-PHASE 110 "rf" -0.5*%theta
FENCE
SHIFT-PHASE 110 111 "xy" 0.4
SHIFT-PHASE 110 117 "xy" 0.4
SHIFT-PHASE 110 111 "xy" -0.2
SHIFT-PHASE 111 112 "xy" -0.2
SHIFT-PHASE 111 126 "xy" -0.2
SHIFT-PHASE 110 111 "xy" -0.25*%theta
SHIFT-PHASE 111 112 "xy" -0.25*%theta
SHIFT-PHASE 111 126 "xy" -0.25*%theta
SHIFT-PHASE 110 111 "xy" -0.25*%theta
SHIFT-PHASE 110 117 "xy" -0.25*%theta

DEFCAL XY(%theta) 111 110:
FENCE
SHIFT-PHASE 110 111 "xy" 0.4
NONBLOCKING PULSE 110 111 "xy" q110_q111_xy/sqrtiSWAP
SHIFT-PHASE 110 111 "xy" -0.4
SHIFT-PHASE 110 111 "xy" 1.8 + -0.5*%theta
NONBLOCKING PULSE 110 111 "xy" q110_q111_xy/sqrtiSWAP
SHIFT-PHASE 110 111 "xy" -1*(1.8 + -0.5*%theta)
DELAY 110 "rf" 1.2e-07
SHIFT-PHASE 110 "rf" 0.8
DELAY 111 "rf" 1.2e-07
SHIFT-PHASE 111 "rf" 0.4
SHIFT-PHASE 111 "rf" 0.5*%theta
SHIFT-PHASE 110 "rf" -0.5*%theta
FENCE
SHIFT-PHASE 110 111 "xy" 0.4
SHIFT-PHASE 110 117 "xy" 0.4
SHIFT-PHASE 110 111 "xy" -0.2
SHIFT-PHASE 111 112 "xy" -0.2
SHIFT-PHASE 111 126 "xy" -0.2
SHIFT-PHASE 110 111 "xy" -0.25*%theta
SHIFT-PHASE 111 112 "xy" -0.25*%theta
SHIFT-PHASE 111 126 "xy" -0.25*%theta
SHIFT-PHASE 110 111 "xy" -0.25*%theta
SHIFT-PHASE 110 117 "xy" -0.25*%theta

31 changes: 31 additions & 0 deletions quil-rs/tests/snapshots/calibration_test__calibration_cz.quil.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
source: quil-rs/tests/calibration_test.rs
expression: program.to_string()
---
DEFCAL CZ 110 111:
FENCE
NONBLOCKING PULSE 110 111 "cz" q110_q111_cz/CZ
DELAY 110 "rf" 1.6e-7
SHIFT-PHASE 110 "rf" 0.6
DELAY 111 "rf" 1.6e-7
SHIFT-PHASE 111 "rf" 0.4
FENCE
SHIFT-PHASE 110 111 "xy" 0.3
SHIFT-PHASE 110 117 "xy" 0.3
SHIFT-PHASE 110 111 "xy" -0.2
SHIFT-PHASE 111 112 "xy" -0.2
SHIFT-PHASE 111 126 "xy" -0.2
DEFCAL CZ 111 110:
FENCE
NONBLOCKING PULSE 110 111 "cz" q110_q111_cz/CZ
DELAY 110 "rf" 1.6e-7
SHIFT-PHASE 110 "rf" 0.6
DELAY 111 "rf" 1.6e-7
SHIFT-PHASE 111 "rf" 0.4
FENCE
SHIFT-PHASE 110 111 "xy" 0.3
SHIFT-PHASE 110 117 "xy" 0.3
SHIFT-PHASE 110 111 "xy" -0.2
SHIFT-PHASE 111 112 "xy" -0.2
SHIFT-PHASE 111 126 "xy" -0.2

Loading

0 comments on commit 0c6dd84

Please sign in to comment.