Crates.io | quantrs2-tytan |
lib.rs | quantrs2-tytan |
version | 0.1.0-alpha.5 |
created_at | 2025-05-13 02:03:26.743179+00 |
updated_at | 2025-06-17 12:00:38.718968+00 |
description | High-level quantum annealing interface inspired by Tytan for the QuantRS2 framework |
homepage | |
repository | https://github.com/cool-japan/quantrs |
max_upload_size | |
id | 1671327 |
size | 5,540,150 |
QuantRS2-Tytan is a comprehensive, high-performance quantum annealing library for the QuantRS2 framework. Inspired by the Python Tytan library, it provides powerful tools for formulating and solving quantum optimization problems with state-of-the-art performance.
Add to your Cargo.toml
:
[dependencies]
quantrs2-tytan = "0.1.0-alpha.5"
# Optional features
# quantrs2-tytan = { version = "0.1.0-alpha.5", features = ["gpu", "dwave", "scirs"] }
use quantrs2_tytan::sampler::{SASampler, Sampler};
use ndarray::Array2;
use std::collections::HashMap;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a QUBO matrix
let mut qubo = Array2::zeros((3, 3));
qubo[[0, 0]] = -1.0;
qubo[[1, 1]] = -1.0;
qubo[[2, 2]] = -1.0;
qubo[[0, 1]] = 2.0;
qubo[[1, 0]] = 2.0;
// Create variable map
let mut var_map = HashMap::new();
var_map.insert("x".to_string(), 0);
var_map.insert("y".to_string(), 1);
var_map.insert("z".to_string(), 2);
// Solve with simulated annealing
let solver = SASampler::new(None);
let results = solver.run_qubo(&(qubo, var_map), 100)?;
// Print best solution
let best = results.iter().min_by_key(|r| r.energy as i32).unwrap();
println!("Best energy: {}, solution: {:?}", best.energy, best.solution);
Ok(())
}
#[cfg(feature = "dwave")]
use quantrs2_tytan::{symbols, Compile};
use quantrs2_tytan::sampler::{SASampler, Sampler};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Define symbolic variables
let x = symbols("x");
let y = symbols("y");
let z = symbols("z");
// Create constraint: exactly one variable should be 1
let expr = (x + y + z - 1).pow(2);
// Compile to QUBO
let (qubo, offset) = Compile::new(&expr).get_qubo()?;
// Solve
let solver = SASampler::new(None);
let results = solver.run_qubo(&qubo, 100)?;
Ok(())
}
QuantRS2-Tytan delivers exceptional performance across all problem types:
See BENCHMARKS.md for detailed performance analysis.
use quantrs2_tytan::quantum_neural_networks::{QuantumNeuralNetwork, QNNConfig, create_qnn_for_optimization};
fn qnn_example() -> Result<(), Box<dyn std::error::Error>> {
// Create QNN for optimization
let mut qnn = create_qnn_for_optimization(4)?; // 4 qubits
// Train on quantum data
qnn.train_quantum_model()?;
// Use for quantum-enhanced optimization
let optimized_params = qnn.optimize_parameters()?;
Ok(())
}
use quantrs2_tytan::tensor_network_sampler::{create_mps_sampler, create_peps_sampler};
use quantrs2_tytan::sampler::Sampler;
fn tensor_network_example() -> Result<(), Box<dyn std::error::Error>> {
// Create MPS sampler for 1D problems
let mps_sampler = create_mps_sampler(64); // bond dimension
// Create PEPS sampler for 2D problems
let peps_sampler = create_peps_sampler(16, (5, 5)); // 5x5 lattice
// Use with existing QUBO/HOBO interface
let results = mps_sampler.run_qubo(&qubo, 100)?;
Ok(())
}
use quantrs2_tytan::advanced_performance_analysis::{create_comprehensive_analyzer, AnalysisConfig};
fn performance_analysis_example() -> Result<(), Box<dyn std::error::Error>> {
// Create performance analyzer
let mut analyzer = create_comprehensive_analyzer();
// Start analysis
analyzer.start_analysis()?;
// Run your quantum optimization
// ... optimization code ...
// Perform comprehensive analysis
analyzer.perform_comprehensive_analysis()?;
// Get bottleneck recommendations
for recommendation in &analyzer.analysis_results.optimization_recommendations {
println!("Optimization: {}", recommendation.title);
println!("Expected benefit: {:.2}%", recommendation.expected_benefit * 100.0);
}
Ok(())
}
#[cfg(feature = "gpu")]
use quantrs2_tytan::sampler::{ArminSampler, Sampler};
fn gpu_example() -> Result<(), Box<dyn std::error::Error>> {
// Check GPU availability
if !quantrs2_tytan::is_gpu_available() {
println!("GPU not available, falling back to CPU");
return Ok(());
}
// Use GPU-accelerated sampler for large problems
let solver = ArminSampler::new(None);
let results = solver.run_qubo(&large_qubo, 1000)?;
Ok(())
}
use quantrs2_tytan::parallel_tempering::{ParallelTemperingSampler, PTConfig};
fn parallel_tempering_example() -> Result<(), Box<dyn std::error::Error>> {
let solver = ParallelTemperingSampler::new(PTConfig {
num_replicas: 20,
temperature_range: (0.01, 50.0),
swap_interval: 5,
num_sweeps: 50000,
});
let results = solver.run_qubo(&qubo, 10)?;
Ok(())
}
use quantrs2_tytan::constraints::add_equality_constraint;
fn constrained_problem() -> Result<(), Box<dyn std::error::Error>> {
let mut qubo = Array2::zeros((5, 5));
// Add objective function terms
// ...
// Add constraint: x1 + x2 + x3 = 2
add_equality_constraint(&mut qubo, &[0, 1, 2], 2.0, 10.0);
// Solve
let solver = SASampler::new(None);
let results = solver.run_qubo(&(qubo, var_map), 100)?;
Ok(())
}
parallel
: Multi-threading support (enabled by default)gpu
: GPU-accelerated samplers using OpenCL/CUDAdwave
: Symbolic math and D-Wave quantum hardware supportscirs
: High-performance computing with SciRS2 librariesadvanced_optimization
: State-of-the-art optimization algorithmsgpu_accelerated
: Full GPU acceleration pipelinesimd
: SIMD optimizations for CPU operationsclustering
: Solution clustering and pattern analysisplotters
: Visualization tools for results and convergenceml
: Machine learning integrationbenchmark
: Performance benchmarking toolsQuantRS2-Tytan seamlessly integrates with the entire QuantRS2 quantum computing framework:
cargo build --release
cargo build --release --all-features
cargo build --release --features gpu,gpu_accelerated
On macOS:
brew install symengine gmp mpfr
export SYMENGINE_DIR=$(brew --prefix symengine)
export GMP_DIR=$(brew --prefix gmp)
export MPFR_DIR=$(brew --prefix mpfr)
export BINDGEN_EXTRA_CLANG_ARGS="-I$(brew --prefix symengine)/include -I$(brew --prefix gmp)/include -I$(brew --prefix mpfr)/include"
cargo build --features dwave
On Linux:
sudo apt-get install libsymengine-dev libgmp-dev libmpfr-dev
cargo build --features dwave
We welcome contributions! Please see our Contributing Guidelines for details.
# Clone the repository
git clone https://github.com/cool-japan/quantrs.git
cd quantrs/tytan
# Run tests
cargo test
# Run benchmarks
cargo bench
# Check code style
cargo fmt -- --check
cargo clippy -- -D warnings
This project is licensed under either:
at your option.