Skip to content

Commit

Permalink
Merge pull request #2 from notmgsk/classical-instructions
Browse files Browse the repository at this point in the history
Support classical instructions
  • Loading branch information
notmgsk authored Jul 11, 2021
2 parents 3ca1cd5 + 8b4fd33 commit f529826
Show file tree
Hide file tree
Showing 6 changed files with 989 additions and 285 deletions.
38 changes: 34 additions & 4 deletions Cargo.lock

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

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"

[dependencies]
structopt = "0.3.13"
quil = { git = "ssh://git@github.com/rigetti/quil-rust.git", branch = "semicolon" }
quil = { git = "https://github.com/rigetti/quil-rust.git", tag = "v0.2.1" }
num = "0.4.0"
ndarray = "0.15.3"
num-complex = "0.4.0"
Expand All @@ -18,9 +18,8 @@ num-traits = "0.2.14"
itertools = "0.10.1"
log = "*"
env_logger = "*"
thiserror = "1.0.24"
anyhow = "1.0.39"

[dev-dependencies]
pretty_assertions = "0.7.2"

#[patch."ssh://[email protected]/rigetti/quil-rust.git"]
#quil = { path = "../../rigetti/quil-rust" }
28 changes: 21 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
use itertools::Itertools;
use quil::{
instruction::{Instruction, Qubit},
program::Program,
};
use std::{
collections::HashSet,
fs,
io::{self, Read},
str::FromStr,
};
use structopt::StructOpt;

use anyhow::Result;
use thiserror::Error;

use quil::{
instruction::{Instruction, Qubit},
program::Program,
};

use vm::VM;

pub mod gates;
pub mod matrix;
pub mod vm;
pub mod wavefunction;

#[derive(Error, Debug)]
pub enum SimquilError {
#[error("failed to execute program")]
ExecutionError(#[from] vm::VMError),
}

#[derive(StructOpt)]
struct Cli {
quil_file: Option<String>,
}

fn run(cli: Cli) {
fn run(cli: Cli) -> Result<()> {
let quil = match cli.quil_file {
Some(path) => fs::read_to_string(path).expect("bad read"),
None => {
Expand All @@ -38,7 +49,7 @@ fn run(cli: Cli) {

let mut vm = VM::new(max_qubits_needed, program);

vm.run();
vm.run().map_err(SimquilError::ExecutionError)?;
println!("Wavefunction amplitudes:");
println!();
println!("{:?}", vm);
Expand All @@ -49,10 +60,13 @@ fn run(cli: Cli) {
.iter()
.sorted_by_key(|x| x.0)
.for_each(|(mref, data)| println!("{}[0..{}]:\t {:?}", mref, data.len(), data));

Ok(())
}

fn main() {
fn main() -> Result<()> {
env_logger::init();

run(Cli::from_args())
}

Expand Down
Loading

0 comments on commit f529826

Please sign in to comment.