Skip to content

Commit f29d17c

Browse files
committed
Split QIR capabilities to pecos-qir crate
1 parent ee9a5b1 commit f29d17c

32 files changed

+249
-140
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pecos-core = { version = "0.1.1", path = "crates/pecos-core" }
4747
pecos-qsim = { version = "0.1.1", path = "crates/pecos-qsim" }
4848
pecos-qasm = { version = "0.1.1", path = "crates/pecos-qasm" }
4949
pecos-engines = { version = "0.1.1", path = "crates/pecos-engines" }
50+
pecos-qir = { version = "0.1.1", path = "crates/pecos-qir" }
5051
pecos-qec = { version = "0.1.1", path = "crates/pecos-qec" }
5152
pecos = { version = "0.1.1", path = "crates/pecos" }
5253
pecos-cli = { version = "0.1.1", path = "crates/pecos-cli" }

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ calls to Wasm VMs, conditional branching, and more.
2222
- Fast Simulation: Leverages a fast stabilizer simulation algorithm.
2323
- Multi-language extensions: Core functionalities implemented via Rust for performance and safety. Additional add-ons
2424
and extension support in C/C++ via Cython.
25-
- QIR Support: Execute Quantum Intermediate Representation programs (requires LLVM version 14 with the 'llc' tool).
25+
- QIR Support: Execute Quantum Intermediate Representation programs (requires LLVM version 14 with the 'llc' tool). PECOS now includes a dedicated `pecos-qir` crate with an improved QIR implementation.
2626

2727
## Getting Started
2828

@@ -40,6 +40,10 @@ PECOS now consists of multiple interconnected components:
4040
- `/crates/pecos-core/`: Core Rust functionalities
4141
- `/crates/pecos-qsims/`: A collection of quantum simulators
4242
- `/crates/pecos-qec/`: Rust code for analyzing and exploring quantum error correction (QEC)
43+
- `/crates/pecos-qasm/`: Implementation of QASM parsing and execution
44+
- `/crates/pecos-qir/`: Implementation of QIR (Quantum Intermediate Representation) execution
45+
- `/crates/pecos-engines/`: Quantum and classical engines for simulations
46+
- `/crates/pecos-cli/`: Command-line interface for PECOS
4347
- `/crates/pecos-python/`: Rust code for Python extensions
4448
- `/crates/benchmarks/`: A collection of benchmarks to test the performance of the crates
4549

crates/pecos-cli/src/engine_setup.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,7 @@ pub fn setup_cli_engine(
3030
match program_type {
3131
ProgramType::QIR => {
3232
debug!("Setting up QIR engine");
33-
let mut engine = QirEngine::new(program_path.to_path_buf());
34-
35-
// Set the number of shots assigned to this engine if specified
36-
if let Some(num_shots) = shots {
37-
engine.set_assigned_shots(num_shots)?;
38-
}
39-
40-
// Pre-compile the QIR library for efficient cloning
41-
engine.pre_compile()?;
42-
43-
Ok(Box::new(engine))
33+
setup_qir_engine(program_path, shots)
4434
}
4535
ProgramType::PHIR => {
4636
debug!("Setting up PHIR engine");

crates/pecos-cli/src/main.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use clap::{Args, Parser, Subcommand};
22
use env_logger::Env;
3+
use log::debug;
34
use pecos::prelude::*;
45

56
mod engine_setup;
@@ -93,7 +94,7 @@ impl std::str::FromStr for OutputFormatType {
9394
}
9495
}
9596

96-
#[derive(Args)]
97+
#[derive(Args, Clone)]
9798
struct RunArgs {
9899
/// Path to the quantum program (LLVM IR, JSON, or QASM)
99100
program: String,
@@ -227,15 +228,15 @@ fn parse_general_noise_probabilities(noise_str_opt: Option<&String>) -> (f64, f6
227228
}
228229
}
229230

230-
/// Run a quantum program with the specified arguments
231-
///
232-
/// This function sets up the appropriate engines and noise models based on
233-
/// the command line arguments, then runs the specified program and outputs
234-
/// the results.
235231
fn run_program(args: &RunArgs) -> Result<(), PecosError> {
236232
// get_program_path now includes proper context in its errors
237233
let program_path = get_program_path(&args.program)?;
238234

235+
// Detect the program type (for informational purposes)
236+
let program_type = detect_program_type(&program_path)?;
237+
debug!("Detected program type: {:?}", program_type);
238+
239+
// Set up the engine
239240
let classical_engine =
240241
setup_cli_engine(&program_path, Some(args.shots.div_ceil(args.workers)))?;
241242

crates/pecos-engines/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ keywords.workspace = true
1111
categories.workspace = true
1212
description = "Provides simulator engines for PECOS simulations."
1313

14-
1514
[lib]
1615
crate-type = ["cdylib", "rlib"]
1716

@@ -25,8 +24,6 @@ rand_chacha.workspace = true
2524
bytemuck.workspace = true
2625
bitflags.workspace = true
2726
dyn-clone.workspace = true
28-
libloading.workspace = true
29-
regex.workspace = true
3027

3128
pecos-core.workspace = true
3229
pecos-qsim.workspace = true

crates/pecos-engines/src/engines.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pub mod hybrid;
33
pub mod monte_carlo;
44
pub mod noise;
55
pub mod phir;
6-
pub mod qir;
76
pub mod quantum;
87
pub mod quantum_system;
98

crates/pecos-engines/src/engines/classical.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::byte_message::ByteMessage;
22
use crate::core::shot_results::ShotResult;
3-
use crate::engines::{ControlEngine, Engine, EngineStage, phir, qir};
3+
use crate::engines::{ControlEngine, Engine, EngineStage, phir};
44
use dyn_clone::DynClone;
55
use log::debug;
66
use pecos_core::errors::PecosError;
@@ -188,36 +188,6 @@ impl Engine for Box<dyn ClassicalEngine> {
188188
}
189189
}
190190

191-
/// Sets up a basic QIR engine.
192-
///
193-
/// This function creates a QIR engine from the provided path.
194-
///
195-
/// # Parameters
196-
///
197-
/// - `program_path`: A reference to the path of the QIR program file
198-
/// - `shots`: Optional number of shots to set for the engine
199-
///
200-
/// # Returns
201-
///
202-
/// Returns a `Box<dyn ClassicalEngine>` containing the QIR engine
203-
pub fn setup_qir_engine(
204-
program_path: &Path,
205-
shots: Option<usize>,
206-
) -> Result<Box<dyn ClassicalEngine>, PecosError> {
207-
debug!("Setting up QIR engine for: {}", program_path.display());
208-
let mut engine = qir::QirEngine::new(program_path.to_path_buf());
209-
210-
// Set the number of shots assigned to this engine if specified
211-
if let Some(num_shots) = shots {
212-
engine.set_assigned_shots(num_shots)?;
213-
}
214-
215-
// Pre-compile the QIR library to prepare for efficient cloning
216-
engine.pre_compile()?;
217-
218-
Ok(Box::new(engine))
219-
}
220-
221191
/// Sets up a basic PHIR engine.
222192
///
223193
/// This function creates a PHIR engine from the provided path.

crates/pecos-engines/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ pub use engines::{
1313
monte_carlo::MonteCarloEngine,
1414
noise::{DepolarizingNoiseModel, NoiseModel, PassThroughNoiseModel},
1515
phir::PHIREngine,
16-
qir::QirEngine,
1716
quantum::QuantumEngine,
1817
quantum_system::QuantumSystem,
1918
};
2019
pub use pecos_core::errors::PecosError;
2120

2221
// Re-export engine setup functions
23-
pub use engines::classical::{setup_phir_engine, setup_qir_engine};
22+
pub use engines::classical::setup_phir_engine;

crates/pecos-qir/Cargo.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "pecos-qir"
3+
version.workspace = true
4+
edition.workspace = true
5+
readme.workspace = true
6+
authors.workspace = true
7+
homepage.workspace = true
8+
repository.workspace = true
9+
license.workspace = true
10+
keywords.workspace = true
11+
categories.workspace = true
12+
description = "QIR (Quantum Intermediate Representation) execution capabilities for PECOS."
13+
14+
[dependencies]
15+
log.workspace = true
16+
pecos-core.workspace = true
17+
pecos-engines.workspace = true
18+
regex.workspace = true
19+
libloading.workspace = true
20+
21+
[build-dependencies]
22+
# No specific build dependencies required
23+
24+
[lints]
25+
workspace = true

0 commit comments

Comments
 (0)