Crate logosq_os_scheduler

Crate logosq_os_scheduler 

Source
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:

  1. Circuit batching: Group similar circuits for efficient QPU utilization
  2. Resource management: Track qubit availability and backend capacity
  3. Fault tolerance: Handle backend failures with automatic retry/rerouting
  4. 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 runtime
  • redox: Enable Redox OS compatibility
  • embedded: Minimal footprint for embedded systems

§Dependencies

  • futures: Async primitives
  • crossbeam: Lock-free data structures
  • parking_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:

PriorityDescriptionUse Case
CriticalImmediate executionError recovery, calibration
HighNext available slotInteractive queries
NormalStandard queueBatch jobs
LowBackground processingOptimization, caching
IdleOnly when system is idleSpeculative 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

ScenarioTasks/secLatency (p99)
Classical only50,0000.2ms
Quantum only1,00050ms
Mixed 50/5025,0002ms

§Multi-Core Scaling

CoresRelative Throughput
11.0x
43.8x
87.2x
1613.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:

  1. Follow Rust API guidelines
  2. Add tests for new scheduling strategies
  3. Benchmark performance impact
  4. 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§

HybridWorkflow
A hybrid quantum-classical workflow.
MockBackend
A mock backend for testing.
QuantumScheduler
The main quantum-classical task scheduler.
RoutingRule
A rule for routing tasks to backends.
SchedulerConfig
Configuration for the quantum scheduler.
SchedulerMetrics
Scheduler performance metrics.
Task
A task to be scheduled for execution.
TaskBuilder
Builder for constructing tasks.
TaskHandle
Handle to a submitted task, allowing result retrieval.
TaskResult
Result of a completed task.
WorkflowResult
Result of a workflow execution.

Enums§

PreemptionStrategy
Preemption strategy for task scheduling.
RoutingCondition
Condition for a routing rule.
RoutingTarget
Target for a routing rule.
SchedulerError
Errors that can occur during scheduling operations.
TaskPriority
Task priority levels.
TaskStatus
Status of a task.
TaskType
Type of task.
WorkflowStep
A step in a hybrid workflow.

Traits§

Backend
Trait for quantum backends.