Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
quantrs2
Unified facade for QuantRS2: simplified quantum computing in Rust
The quantrs2 facade crate provides a unified entry point to the entire QuantRS2 quantum computing framework. It offers hierarchical preludes, comprehensive system management, and developer utilitiesβall with zero runtime overhead.
β¨ Key Features
- π― Hierarchical Preludes: Import exactly what you need (essentials β circuits β simulation β algorithms)
- βοΈ System Management: Global configuration, diagnostics, and version checking
- π οΈ Developer Utilities: Memory estimation, testing helpers, error handling
- π Zero Runtime Overhead: Feature-gated re-exports with compile-time optimization
- π Comprehensive Documentation: 8 runnable examples and detailed guides
π Quick Start
Add to your Cargo.toml:
[]
# Choose your level of functionality
= { = "0.1.0-beta.3", = ["circuit", "sim"] }
# Or enable everything
= { = "0.1.0-beta.3", = ["full"] }
Example: Bell State with Hierarchical Prelude
use *; // Includes essentials + circuits + simulators
Example: System Management
use ;
Available Features
| Feature | Description | Dependencies |
|---|---|---|
circuit |
Quantum circuit construction and optimization | quantrs2-circuit |
sim |
Quantum simulators (state vector, stabilizer, etc.) | quantrs2-sim, circuit |
anneal |
Quantum annealing algorithms | quantrs2-anneal, circuit |
device |
Hardware backends and device interfaces | quantrs2-device, circuit |
ml |
Quantum machine learning algorithms | quantrs2-ml, sim, anneal |
tytan |
TYTAN quantum annealing integration | quantrs2-tytan, anneal |
symengine |
Symbolic computation with SymEngine | quantrs2-symengine |
full |
All features enabled | All of the above |
Module Structure
When you enable features, the corresponding modules become available:
// Core is always available
use core;
// Available with "circuit" feature
use circuit;
// Available with "sim" feature
use sim;
// Available with "anneal" feature
use anneal;
// Available with "device" feature
use device;
// Available with "ml" feature
use ml;
// Available with "tytan" feature
use tytan;
// Available with "symengine" feature
use symengine;
π Examples
The facade crate includes 8 comprehensive examples in the examples/ directory:
| Example | Description | Run Command |
|---|---|---|
basic_usage.rs |
Facade basics: version, config, diagnostics | cargo run --example basic_usage |
configuration.rs |
Global configuration management | cargo run --example configuration |
diagnostics.rs |
System diagnostics and health checks | cargo run --example diagnostics |
utility_functions.rs |
Memory estimation and utilities | cargo run --example utility_functions |
prelude_hierarchy.rs |
Prelude levels and feature selection | cargo run --example prelude_hierarchy |
memory_estimation.rs |
Capacity planning for quantum circuits | cargo run --example memory_estimation |
error_handling.rs |
Error handling and recovery patterns | cargo run --example error_handling |
testing_helpers.rs |
Testing utilities for quantum algorithms | cargo run --example testing_helpers |
π― Hierarchical Preludes
Choose the right prelude for your use case:
// Level 1: Essentials (always available, fastest compile)
use *;
// Includes: QubitId, Error types, Version
// Level 2: Circuit construction
use *;
// Includes: essentials + Circuit, Gates
// Level 3: Quantum simulation
use *;
// Includes: circuits + StateVectorSimulator, Backends
// Level 4: Algorithms and ML
use *;
// Includes: simulation + VQE, QAOA, QNNs
// Level 5: Hardware integration
use *;
// Includes: circuits + IBM, Azure, AWS
// Level 6: Quantum annealing
use *;
// Includes: essentials + QUBO, Ising, D-Wave
// Level 7: Tytan DSL
use *;
// Includes: quantum_annealing + Tytan API
// Full: Everything (slowest compile)
use *;
Recommendation: Start with essentials and add features as needed for faster compilation.
π οΈ Facade Features
1. Configuration Management
use Config;
// Global singleton with builder pattern
builder
.num_threads
.memory_limit_gb
.log_level
.default_backend
.apply;
// Or configure directly
let cfg = global;
cfg.set_gpu_enabled;
cfg.set_simd_enabled;
Supports environment variables: QUANTRS2_NUM_THREADS, QUANTRS2_LOG_LEVEL, etc.
2. System Diagnostics
use diagnostics;
// Comprehensive system check
let report = run_diagnostics;
println!; // Detailed report
// Quick checks
if is_ready
Detects: CPU cores, memory, GPU, SIMD capabilities, compatibility issues.
3. Memory Estimation
use utils;
// Estimate memory for N qubits
let mem = estimate_statevector_memory;
println!; // "16.00 GB"
// Find max qubits for available memory
let max = max_qubits_for_memory;
println!; // 30
// Validate configuration
if is_valid_qubit_count
4. Error Handling
use ;
let err = NetworkError;
// Categorize errors
match err.category
// Add context
let err = with_context;
// User-friendly messages
eprintln!;
5. Testing Helpers
use testing;
// Floating-point assertions
assert_approx_eq;
// Vector assertions
assert_vec_approx_eq;
// Stochastic measurement assertions
assert_measurement_counts_close;
// Reproducible test data
let data = generate_random_test_data;
6. Version Management
use version;
// Version information
println!;
println!;
// Detailed info
let info = current;
println!;
// Compatibility checking
check_compatibility?;
π Documentation
- FEATURES.md: Comprehensive feature documentation
- CHANGELOG.md: Version history and migration guides
- SCIRS2_INTEGRATION_GUIDE.md: How QuantRS2 uses SciRS2
- CLAUDE.md: Development guidelines and architecture
- SCIRS2_INTEGRATION_POLICY.md: SciRS2 usage patterns
- API Documentation: Generated API docs
Feature Dependencies
Some features automatically enable others:
simβ enablescircuitannealβ enablescircuitdeviceβ enablescircuitmlβ enablessimandannealtytanβ enablesanneal
When to Use This Crate
Use quantrs2 when:
- You want a simple, unified dependency
- You're building applications that use multiple QuantRS2 components
- You prefer feature flags over managing multiple crate dependencies
- You want the convenience of a single import namespace
Use individual crates when:
- You only need specific functionality (e.g., just
quantrs2-core) - You want minimal compile times and dependencies
- You're building libraries that should have minimal dependencies
- You need fine-grained control over versions
Example Configurations
Minimal quantum programming:
= { = "0.1.0-beta.3", = ["circuit"] }
Circuit simulation:
= { = "0.1.0-beta.3", = ["sim"] }
Quantum machine learning:
= { = "0.1.0-beta.3", = ["ml"] }
Hardware interaction:
= { = "0.1.0-beta.3", = ["device", "sim"] }
Everything:
= { = "0.1.0-beta.3", = ["full"] }
Alternative: Individual Crates
If you prefer to use individual crates instead of the facade:
[]
= "0.1.0-beta.3"
= "0.1.0-beta.3"
= "0.1.0-beta.3"
# etc.
π― Use Case Examples
Use Case 1: Quantum Algorithm Research
Scenario: Researcher developing and benchmarking quantum algorithms
[]
= { = "0.1.0-beta.3", = ["circuit", "sim"] }
use *;
Why quantrs2? Single dependency, fast compilation, comprehensive testing utilities.
Use Case 2: Quantum Machine Learning Application
Scenario: ML engineer building quantum neural networks for classification
[]
= { = "0.1.0-beta.3", = ["ml"] }
use *;
Why quantrs2? Integrated VQE/QAOA optimizers, GPU acceleration, SciRS2 autodiff support.
Use Case 3: Quantum Annealing Optimization
Scenario: Operations research solving vehicle routing with quantum annealing
[]
= { = "0.1.0-beta.3", = ["tytan"] }
use *;
Why quantrs2? High-level Tytan DSL, multiple solvers (SA, GPU, D-Wave), visualization tools.
Use Case 4: Real Quantum Hardware Integration
Scenario: Enterprise application running on IBM Quantum
[]
= { = "0.1.0-beta.3", = ["device", "circuit"] }
use *;
Why quantrs2? Unified device API (IBM/Azure/AWS), automatic transpilation, error mitigation.
Use Case 5: Production Quantum Service
Scenario: Cloud service offering quantum computation APIs
[]
= { = "0.1.0-beta.3", = ["full"] }
use ;
Why quantrs2? Complete feature set, comprehensive diagnostics, production-ready error handling.
π Facade vs Individual Crates Comparison
When to Use quantrs2 Facade
| Aspect | Facade Crate | Individual Crates |
|---|---|---|
| Dependency Management | Single quantrs2 entry |
Multiple quantrs2-* dependencies |
| Feature Selection | Cargo feature flags | Manual version coordination |
| Import Style | use quantrs2::prelude::* |
use quantrs2_circuit::*; use quantrs2_sim::*; |
| Compilation Time | Feature-dependent (10s - 60s) | Minimal for specific needs (5s - 20s) |
| Version Compatibility | Guaranteed compatible versions | Manual version matching required |
| API Discoverability | Unified namespace, hierarchical | Separate documentation per crate |
| Binary Size | Optimized out unused features | Minimal (only what you use) |
| Best For | Applications, prototypes, research | Libraries, minimal dependencies |
Facade Feature Compilation Times
# Benchmarked on Apple M1 Max, 32GB RAM
# Individual crates (for comparison)
Example: Dependency Management Comparison
Using Facade (Recommended for Applications):
[]
= { = "0.1.0-beta.3", = ["ml"] }
Using Individual Crates (Recommended for Libraries):
[]
= "0.1.0-beta.3"
= "0.1.0-beta.3"
= "0.1.0-beta.3"
= "0.1.0-beta.3"
# Must manually ensure version compatibility!
π Performance Tips
1. Choose Optimal Prelude Level
// β FAST: Use specific prelude
use *; // Only circuits, ~8s compile
// β SLOW: Use full prelude when unnecessary
use *; // Everything, ~45s compile
2. Enable Hardware Acceleration
use Config;
global
.set_gpu_enabled // 10-100x speedup for large circuits
.set_simd_enabled // 2-4x speedup for CPU operations
.set_num_threads; // Parallel gate application
3. Estimate Memory Before Simulation
use utils;
let qubits = 25;
let required_memory = estimate_statevector_memory;
let available = 16 * 1024 * 1024 * 1024; // 16 GB
if required_memory > available else
4. Profile Your Quantum Algorithms
use bench;
let timer = start;
let result = run_quantum_algorithm;
let duration = timer.elapsed;
println!;
5. Common Pitfalls
// β DON'T: Forget to check system readiness
// β
DO: Validate environment first
End-to-End Example
This example builds a Bell state on 2 qubits and prints the probabilities. Enable features circuit and sim.
use *;
use ;
use StateVectorSimulator;
Advanced Features
Hierarchical Prelude System
QuantRS2 provides hierarchical prelude modules for convenient imports:
// Minimal imports for basic quantum programming
use *;
// Circuit construction
use *;
// Quantum simulation
use *;
// Algorithm development with ML
use *;
// Real quantum hardware
use *;
// All features
use *;
Unified Error Handling
Comprehensive error handling with categorization and user-friendly messages:
use ;
Version Compatibility Checking
Automatic version and environment validation:
use ;
// Print version information
let info = current;
println!;
// Check compatibility
if let Err = check_compatibility
Global Configuration
Centralized configuration for all QuantRS2 components:
use ;
// Configure via builder pattern
builder
.num_threads
.log_level
.memory_limit_gb
.default_backend
.enable_gpu
.apply;
// Or configure directly
let config = global;
config.set_num_threads;
config.set_log_level;
Configuration can also be set via environment variables:
QUANTRS2_NUM_THREADS: Number of threadsQUANTRS2_LOG_LEVEL: Logging level (trace, debug, info, warn, error)QUANTRS2_MEMORY_LIMIT_GB: Memory limit in GBQUANTRS2_BACKEND: Default backend (cpu, gpu, tensor_network, stabilizer, auto)
System Diagnostics
Comprehensive system validation and health checks:
use diagnostics;
// Run full diagnostic check
let report = run_diagnostics;
println!;
// Quick readiness check
if !is_ready
// Validate at startup (panics if not ready)
validate_or_panic;
Documentation
Subcrates
quantrs2-core: Core types, math, error handling, and APIs β https://github.com/cool-japan/quantrs/tree/master/corequantrs2-circuit: Circuit builder, DSL, optimization β https://github.com/cool-japan/quantrs/tree/master/circuitquantrs2-sim: Simulators (statevector, stabilizer, MPS, etc.) β https://github.com/cool-japan/quantrs/tree/master/simquantrs2-anneal: Quantum annealing algorithms and workflows β https://github.com/cool-japan/quantrs/tree/master/annealquantrs2-device: Hardware/device connectors and scheduling β https://github.com/cool-japan/quantrs/tree/master/devicequantrs2-ml: Quantum machine learning utilities β https://github.com/cool-japan/quantrs/tree/master/mlquantrs2-tytan: High-level annealing interface inspired by TYTAN β https://github.com/cool-japan/quantrs/tree/master/tytanquantrs2-symengine: Symbolic computation bindings β https://github.com/cool-japan/quantrs/tree/master/quantrs2-symengine
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.