Skip to content

Commit

Permalink
Fix: DEFCAL MEASURE serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
kalzoo committed Jun 8, 2022
1 parent 0325730 commit d5488dc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ impl fmt::Display for Instruction {

writeln!(
f,
" %{}:\n\t{}",
" {}:\n\t{}",
parameter,
format_instructions(instructions)
)
Expand Down
20 changes: 19 additions & 1 deletion src/parser/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ pub fn parse_block_instruction<'a>(input: ParserInput<'a>) -> ParserResult<'a, I
#[cfg(test)]
mod tests {
use std::collections::HashMap;
use std::str::FromStr;

use crate::expression::Expression;
use crate::instruction::{
Expand All @@ -164,7 +165,7 @@ mod tests {
WaveformDefinition, WaveformInvocation,
};
use crate::parser::lexer::lex;
use crate::{make_test, real};
use crate::{make_test, real, Program};

use super::parse_instructions;

Expand Down Expand Up @@ -842,4 +843,21 @@ mod tests {
assert_eq!(remainder.len(), 0);
assert_eq!(parsed, expected);
}

/// Assert that an instruction can be parsed and then identically re-serialized to string.
#[test]
fn parse_and_serialize() {
let inputs = vec![
r#"DEFCAL MEASURE 0 dest:
DECLARE iq REAL[2]
CAPTURE 0 "out" flat(duration: 1.0, iqs: (2.0+3.0i)) iq[0]"#,
];

for input in inputs {
let program = Program::from_str(input).unwrap();
let output = program.to_string(true);

assert_eq!(input.trim(), output.trim());
}
}
}
2 changes: 1 addition & 1 deletion src/parser/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ mod tests {
DEFCAL RX(%theta) 0:
\tPULSE 0 \"xy\" my_waveform()
DEFCAL MEASURE 0 %dest:
DEFCAL MEASURE 0 dest:
\tDECLARE iq REAL[2]
\tCAPTURE 0 \"out\" flat(duration: 1000000, iqs: (2+3i)) iq[0]
Expand Down
5 changes: 5 additions & 0 deletions src/program/calibration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ impl CalibrationSet {
self.calibrations
.iter()
.map(|c| Instruction::CalibrationDefinition(c.clone()))
.chain(
self.measure_calibrations
.iter()
.map(|c| Instruction::MeasureCalibrationDefinition(c.clone())),
)
.collect()
}
}
Expand Down

0 comments on commit d5488dc

Please sign in to comment.