#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "wasm")]
use wasm_bindgen::prelude::*;
#[cfg(all(feature = "wasm", target_arch = "wasm32"))]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[cfg(feature = "wasm")]
#[wasm_bindgen]
pub fn init_wasm() {
#[cfg(feature = "wasm")]
console_error_panic_hook::set_once();
}
pub mod error;
pub mod circuit_ir;
pub mod topology;
pub mod scheduler;
pub mod composer;
pub mod api;
#[cfg(feature = "wasm")]
pub mod wasm;
pub use error::{QvmError, Result};
pub use circuit_ir::{QuantumCircuit, Operation, Qubit, ClassicalBit, CircuitBuilder};
pub use topology::{Topology, Tile, Position, TopologyBuilder};
pub use scheduler::{Job, Schedule, Scheduler};
pub use composer::{CompositeCircuit, CircuitComposer};
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
#[derive(Debug, Clone)]
pub struct QvmScheduler {
topology: Topology,
scheduler: Scheduler,
composer: CircuitComposer,
}
impl QvmScheduler {
pub fn new(topology: Topology) -> Self {
Self {
topology: topology.clone(),
scheduler: Scheduler::new(topology.clone()),
composer: CircuitComposer::new(topology),
}
}
pub async fn schedule_circuits(
&mut self,
circuits: Vec<QuantumCircuit>,
) -> Result<CompositeCircuit> {
let jobs: Vec<Job> = circuits
.into_iter()
.enumerate()
.map(|(id, circuit)| Job::new(id, circuit))
.collect();
let schedule = self.scheduler.schedule(jobs).await?;
self.composer.compose(schedule).await
}
pub async fn schedule(
&self,
circuits: &[QuantumCircuit],
) -> Result<CompositeCircuit> {
let jobs: Vec<Job> = circuits
.iter()
.enumerate()
.map(|(id, circuit)| Job::new(id, circuit.clone()))
.collect();
let mut scheduler = self.scheduler.clone();
let schedule = scheduler.schedule(jobs).await?;
let mut composer = self.composer.clone();
composer.compose(schedule).await
}
pub fn topology(&self) -> &Topology {
&self.topology
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::topology::TopologyBuilder;
#[test]
fn test_qvm_scheduler_creation() {
let topology = TopologyBuilder::grid(3, 3);
let scheduler = QvmScheduler::new(topology);
assert_eq!(scheduler.topology().qubit_count(), 9);
}
#[cfg(feature = "std")]
#[tokio::test]
async fn test_empty_schedule() {
let topology = TopologyBuilder::grid(2, 2);
let mut scheduler = QvmScheduler::new(topology);
let result = scheduler.schedule_circuits(vec![]).await;
assert!(result.is_ok());
let composite = result.unwrap();
assert!(composite.circuits().is_empty());
}
}