Skip to content

Commit 52f4031

Browse files
committed
Adding qasm lang + improving CLI
1 parent 0f1e3e4 commit 52f4031

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+5933
-603
lines changed

Cargo.lock

Lines changed: 192 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ bytemuck = { version = "1", features = ["derive"] }
4040
bitflags = "2"
4141
dyn-clone = "1"
4242
regex = "1"
43+
pest = "2.7"
4344

4445
pecos-core = { version = "0.1.1", path = "crates/pecos-core" }
4546
pecos-qsim = { version = "0.1.1", path = "crates/pecos-qsim" }
47+
pecos-qasm = { version = "0.1.1", path = "crates/pecos-qasm" }
4648
pecos-engines = { version = "0.1.1", path = "crates/pecos-engines" }
4749
pecos-qec = { version = "0.1.1", path = "crates/pecos-qec" }
4850
pecos = { version = "0.1.1", path = "crates/pecos" }

crates/pecos-cli/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ path = "src/main.rs"
2020
pecos.workspace = true
2121
clap.workspace = true
2222
env_logger.workspace = true
23+
rand.workspace = true
24+
log.workspace = true
2325

2426
[dev-dependencies]
2527
assert_cmd = "2.0"
2628
predicates = "3.0"
2729
tempfile = "3.8"
30+
serde_json = "1.0"
2831

2932
[lints]
3033
workspace = true
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use log::debug;
2+
use pecos::prelude::*;
3+
use std::error::Error;
4+
use std::path::Path;
5+
6+
/// Sets up a classical engine for the CLI based on the program type
7+
///
8+
/// This function handles all engine types including QIR, PHIR, and QASM.
9+
pub fn setup_cli_engine(
10+
program_path: &Path,
11+
shots: Option<usize>,
12+
) -> Result<Box<dyn ClassicalEngine>, Box<dyn Error>> {
13+
debug!("Setting up engine for path: {}", program_path.display());
14+
15+
// Create build directory for engine outputs
16+
let build_dir = program_path.parent().unwrap().join("build");
17+
debug!("Build directory: {}", build_dir.display());
18+
std::fs::create_dir_all(&build_dir)?;
19+
20+
match detect_program_type(program_path)? {
21+
ProgramType::QIR => {
22+
debug!("Setting up QIR engine");
23+
let mut engine = QirEngine::new(program_path.to_path_buf());
24+
25+
// Set the number of shots assigned to this engine if specified
26+
if let Some(num_shots) = shots {
27+
engine.set_assigned_shots(num_shots)?;
28+
}
29+
30+
// Pre-compile the QIR library for efficient cloning
31+
engine.pre_compile()?;
32+
33+
Ok(Box::new(engine))
34+
}
35+
ProgramType::PHIR => {
36+
debug!("Setting up PHIR engine");
37+
let engine = PHIREngine::new(program_path)?;
38+
Ok(Box::new(engine))
39+
}
40+
ProgramType::QASM => {
41+
debug!("Setting up QASM engine");
42+
43+
// Create a new QASMEngine from the path
44+
// Let MonteCarloEngine handle all seeding and randomness
45+
let engine = QASMEngine::with_file(program_path)?;
46+
47+
Ok(Box::new(engine))
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)