Expand description
§LogosQ OS Scheduler
A hybrid quantum-classical task scheduler for the LogosQ Quantum Operating System, enabling efficient management of quantum circuits and classical computations.
§Overview
This crate provides a sophisticated scheduler designed for quantum-classical hybrid workloads. It handles task batching, priority queuing, backend routing, and preemption strategies without the limitations of Python’s GIL.
§Key Features
- Hybrid scheduling: Interleave quantum circuits with classical ML/optimization
- Priority queues: Configurable task priorities with preemption support
- Backend routing: Automatic routing to optimal quantum backends
- No GIL: True parallelism for classical tasks via Rust’s async runtime
- OS integration: Compatible with Redox OS and embedded systems
§Role in Quantum OS
The scheduler serves as the central coordinator for:
- Circuit batching: Group similar circuits for efficient QPU utilization
- Resource management: Track qubit availability and backend capacity
- Fault tolerance: Handle backend failures with automatic retry/rerouting
- Workload balancing: Distribute tasks across available backends
§Installation
Add to your Cargo.toml:
[dependencies]
logosq-os-scheduler = "0.1"
tokio = { version = "1.35", features = ["full"] }§Feature Flags
tokio-runtime(default): Use Tokio async runtimeredox: Enable Redox OS compatibilityembedded: Minimal footprint for embedded systems
§Dependencies
futures: Async primitivescrossbeam: Lock-free data structuresparking_lot: Fast synchronization primitives
§Usage Examples
§Basic Task Scheduling
ⓘ
use logosq_os_scheduler::{QuantumScheduler, Task, TaskPriority};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create scheduler with 4 worker threads
let scheduler = QuantumScheduler::new(4)?;
// Submit a quantum task
let quantum_task = Task::quantum("bell_state")
.with_priority(TaskPriority::High)
.with_circuit(bell_circuit());
let handle = scheduler.submit(quantum_task).await?;
// Submit a classical task
let classical_task = Task::classical("optimize_params")
.with_priority(TaskPriority::Normal)
.with_function(|| optimize_vqe_params());
scheduler.submit(classical_task).await?;
// Wait for quantum result
let result = handle.await?;
println!("Result: {:?}", result);
Ok(())
}§Interleaving Quantum and Classical Work
ⓘ
use logosq_os_scheduler::{QuantumScheduler, HybridWorkflow, WorkflowStep};
// Define a VQE workflow
let workflow = HybridWorkflow::new("vqe_h2")
.add_step(WorkflowStep::Classical {
name: "init_params",
function: Box::new(|| initialize_parameters()),
})
.add_step(WorkflowStep::Quantum {
name: "measure_energy",
circuit_builder: Box::new(|params| build_ansatz(params)),
})
.add_step(WorkflowStep::Classical {
name: "update_params",
function: Box::new(|energy| optimizer_step(energy)),
})
.with_iterations(100);
let result = scheduler.run_workflow(workflow).await?;§Configuration Options
§Priority Queues
Tasks are scheduled based on priority levels:
| Priority | Description | Use Case |
|---|---|---|
| Critical | Immediate execution | Error recovery, calibration |
| High | Next available slot | Interactive queries |
| Normal | Standard queue | Batch jobs |
| Low | Background processing | Optimization, caching |
| Idle | Only when system is idle | Speculative execution |
§Backend Routing Rules
ⓘ
use logosq_os_scheduler::RoutingRule;
let rules = vec![
RoutingRule::new()
.when_qubit_count_exceeds(20)
.route_to("ibm_brisbane"),
RoutingRule::new()
.when_requires_all_to_all()
.route_to("ionq_aria"),
RoutingRule::new()
.default()
.route_to_shortest_queue(),
];
scheduler.set_routing_rules(rules);§Preemption Strategies
- None: Tasks run to completion
- Cooperative: Tasks yield at checkpoints
- Preemptive: Higher priority tasks interrupt lower priority
§Integration with LogosQ Ecosystem
§End-to-End VQE Workflow
ⓘ
use logosq_os_scheduler::QuantumScheduler;
use logosq_algorithms::{VQE, HardwareEfficientAnsatz};
use logosq_optimizer::Adam;
use logosq_hardware_integrator::IbmBackend;
async fn run_vqe_on_hardware() -> Result<f64, Box<dyn std::error::Error>> {
let scheduler = QuantumScheduler::new(4)?;
let backend = IbmBackend::new_from_env().await?;
// Register backend with scheduler
scheduler.register_backend("ibm", backend).await?;
// Create VQE task
let vqe_task = Task::hybrid("vqe_h2")
.with_algorithm(VQE::new(hamiltonian, ansatz))
.with_optimizer(Adam::new())
.with_backend("ibm");
let result = scheduler.submit(vqe_task).await?.await?;
Ok(result.energy)
}§Performance and Scalability
§Task Throughput Benchmarks
| Scenario | Tasks/sec | Latency (p99) |
|---|---|---|
| Classical only | 50,000 | 0.2ms |
| Quantum only | 1,000 | 50ms |
| Mixed 50/50 | 25,000 | 2ms |
§Multi-Core Scaling
| Cores | Relative Throughput |
|---|---|
| 1 | 1.0x |
| 4 | 3.8x |
| 8 | 7.2x |
| 16 | 13.5x |
§Security and Safety
§Task Isolation
- Each task runs in isolated memory space
- No shared mutable state between tasks (unless explicit)
- Quantum results are cryptographically signed (optional)
§Resource Limits
ⓘ
use logosq_os_scheduler::QuantumScheduler;
use std::time::Duration;
let scheduler = QuantumScheduler::new(4).unwrap()
.with_max_concurrent_quantum(10)
.with_max_queue_depth(1000)
.with_task_timeout(Duration::from_secs(3600));§Atomic Operations
All scheduler state updates use atomic operations or lock-free data structures to prevent race conditions.
§Contributing
To contribute:
- Follow Rust API guidelines
- Add tests for new scheduling strategies
- Benchmark performance impact
- Document OS-specific considerations
§OS-Specific Testing
# Linux/macOS
cargo test --all-features
# Redox OS
cargo test --features redox --no-default-features§License
MIT OR Apache-2.0
Compatible with Redox OS (MIT) and Linux kernel modules (GPL-compatible).
§Changelog
§v0.1.0
- Initial release with priority scheduling
- Backend routing and load balancing
- Hybrid workflow support
Structs§
- Hybrid
Workflow - A hybrid quantum-classical workflow.
- Mock
Backend - A mock backend for testing.
- Quantum
Scheduler - The main quantum-classical task scheduler.
- Routing
Rule - A rule for routing tasks to backends.
- Scheduler
Config - Configuration for the quantum scheduler.
- Scheduler
Metrics - Scheduler performance metrics.
- Task
- A task to be scheduled for execution.
- Task
Builder - Builder for constructing tasks.
- Task
Handle - Handle to a submitted task, allowing result retrieval.
- Task
Result - Result of a completed task.
- Workflow
Result - Result of a workflow execution.
Enums§
- Preemption
Strategy - Preemption strategy for task scheduling.
- Routing
Condition - Condition for a routing rule.
- Routing
Target - Target for a routing rule.
- Scheduler
Error - Errors that can occur during scheduling operations.
- Task
Priority - Task priority levels.
- Task
Status - Status of a task.
- Task
Type - Type of task.
- Workflow
Step - A step in a hybrid workflow.
Traits§
- Backend
- Trait for quantum backends.