1#![cfg_attr(not(feature = "std"), no_std)]
7
8#[cfg(feature = "wasm")]
10use wasm_bindgen::prelude::*;
11
12#[cfg(all(feature = "wasm", target_arch = "wasm32"))]
13#[global_allocator]
14static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
15
16#[cfg(feature = "wasm")]
17#[wasm_bindgen]
18pub fn init_wasm() {
19 #[cfg(feature = "wasm")]
20 console_error_panic_hook::set_once();
21}
22
23pub mod error;
25pub mod circuit_ir;
26pub mod topology;
27pub mod scheduler;
28pub mod composer;
29
30pub mod api;
32
33#[cfg(feature = "wasm")]
35pub mod wasm;
36
37pub use error::{QvmError, Result};
39pub use circuit_ir::{QuantumCircuit, Operation, Qubit, ClassicalBit, CircuitBuilder};
40pub use topology::{Topology, Tile, Position, TopologyBuilder};
41pub use scheduler::{Job, Schedule, Scheduler};
42pub use composer::{CompositeCircuit, CircuitComposer};
43
44pub const VERSION: &str = env!("CARGO_PKG_VERSION");
46
47#[derive(Debug, Clone)]
49pub struct QvmScheduler {
50 topology: Topology,
51 scheduler: Scheduler,
52 composer: CircuitComposer,
53}
54
55impl QvmScheduler {
56 pub fn new(topology: Topology) -> Self {
58 Self {
59 topology: topology.clone(),
60 scheduler: Scheduler::new(topology.clone()),
61 composer: CircuitComposer::new(topology),
62 }
63 }
64
65 pub async fn schedule_circuits(
67 &mut self,
68 circuits: Vec<QuantumCircuit>,
69 ) -> Result<CompositeCircuit> {
70 let jobs: Vec<Job> = circuits
71 .into_iter()
72 .enumerate()
73 .map(|(id, circuit)| Job::new(id, circuit))
74 .collect();
75
76 let schedule = self.scheduler.schedule(jobs).await?;
77 self.composer.compose(schedule).await
78 }
79
80 pub async fn schedule(
82 &self,
83 circuits: &[QuantumCircuit],
84 ) -> Result<CompositeCircuit> {
85 let jobs: Vec<Job> = circuits
86 .iter()
87 .enumerate()
88 .map(|(id, circuit)| Job::new(id, circuit.clone()))
89 .collect();
90
91 let mut scheduler = self.scheduler.clone();
92 let schedule = scheduler.schedule(jobs).await?;
93
94 let mut composer = self.composer.clone();
95 composer.compose(schedule).await
96 }
97
98 pub fn topology(&self) -> &Topology {
100 &self.topology
101 }
102}
103
104#[cfg(test)]
105mod tests {
106 use super::*;
107 use crate::topology::TopologyBuilder;
108
109 #[test]
110 fn test_qvm_scheduler_creation() {
111 let topology = TopologyBuilder::grid(3, 3);
112 let scheduler = QvmScheduler::new(topology);
113 assert_eq!(scheduler.topology().qubit_count(), 9);
114 }
115
116 #[cfg(feature = "std")]
117 #[tokio::test]
118 async fn test_empty_schedule() {
119 let topology = TopologyBuilder::grid(2, 2);
120 let mut scheduler = QvmScheduler::new(topology);
121
122 let result = scheduler.schedule_circuits(vec![]).await;
123 assert!(result.is_ok());
124
125 let composite = result.unwrap();
126 assert!(composite.circuits().is_empty());
127 }
128}