Skip to content

Commit

Permalink
Merge pull request #15 from rigetti/7-implement-compile-protoquil
Browse files Browse the repository at this point in the history
implement compile_protoquil
  • Loading branch information
MarquessV authored Dec 2, 2022
2 parents 6bfadb4 + 06d477c commit 3d6fbb9
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ pub fn compile_program(program: &Program, chip: &Chip) -> Program {
Program(compiled_program)
}

pub fn compile_protoquil(program: &Program, chip: &Chip) -> Program {
init_libquilc();
let mut compiled_program: quil_program = std::ptr::null_mut();

unsafe {
quilc_compile_protoquil.unwrap()(program.0, chip.0, &mut compiled_program);
}

Program(compiled_program)
}

/// Get an arbritrary Chip.
pub fn get_chip() -> Chip {
init_libquilc();
Expand All @@ -76,3 +87,35 @@ pub fn print_program(program: &Program) {
quilc_print_program.unwrap()(program.0);
}
}

#[cfg(test)]
mod tests {
use super::*;

fn new_quil_program() -> Program {
let sample_quil = r#"
DECLARE ro BIT[2]
DECLARE theta REAL
RX(theta) 0
X 0
CNOT 0 1
MEASURE 0 ro[0]
MEASURE 1 ro[1]
"#
.to_string();

parse_program(sample_quil)
}

#[test]
fn test_compile_protoquil() {
let program = new_quil_program();
let chip = get_chip();
compile_protoquil(&program, &chip);

// Since there is no way to inspect the return compiled program yet,
// just make sure the code doesn't panic before getting to this point.
// See: https://github.com/rigetti/libquil-sys/issues/12
assert!(false)
}
}

0 comments on commit 3d6fbb9

Please sign in to comment.