quantrs2_tytan/sampler/hardware/
mikas.rs

1//! MIKAS Sampler Implementation
2
3use scirs2_core::ndarray::{Array, Ix2};
4use std::collections::HashMap;
5
6use super::super::gpu::ArminSampler;
7use super::super::{SampleResult, Sampler, SamplerError, SamplerResult};
8
9/// MIKAS Sampler (Advanced GPU-accelerated version)
10///
11/// This sampler is an enhanced version of the ArminSampler with additional
12/// optimization strategies and advanced features for quantum annealing.
13#[cfg(feature = "gpu")]
14pub struct MIKASAmpler {
15    /// Underlying Armin sampler
16    armin_sampler: ArminSampler,
17    /// Enhanced optimization mode
18    optimization_mode: String,
19}
20
21#[cfg(feature = "gpu")]
22impl MIKASAmpler {
23    /// Create a new MIKAS sampler
24    ///
25    /// # Arguments
26    ///
27    /// * `seed` - An optional random seed for reproducibility
28    #[must_use]
29    pub fn new(seed: Option<u64>) -> Self {
30        Self {
31            armin_sampler: ArminSampler::new(seed),
32            optimization_mode: "advanced".to_string(),
33        }
34    }
35
36    /// Create a new MIKAS sampler with custom parameters
37    ///
38    /// # Arguments
39    ///
40    /// * `seed` - An optional random seed for reproducibility
41    /// * `mode` - Whether to use GPU ("GPU") or CPU ("CPU")
42    /// * `device` - Device to use (e.g., "cuda:0")
43    /// * `verbose` - Whether to show verbose output
44    #[must_use]
45    pub fn with_params(seed: Option<u64>, mode: &str, device: &str, verbose: bool) -> Self {
46        Self {
47            armin_sampler: ArminSampler::with_params(seed, mode, device, verbose),
48            optimization_mode: "advanced".to_string(),
49        }
50    }
51
52    /// Set optimization mode
53    pub fn with_optimization_mode(mut self, mode: &str) -> Self {
54        self.optimization_mode = mode.to_string();
55        self
56    }
57}
58
59#[cfg(feature = "gpu")]
60impl Sampler for MIKASAmpler {
61    fn run_qubo(
62        &self,
63        qubo: &(Array<f64, Ix2>, HashMap<String, usize>),
64        shots: usize,
65    ) -> SamplerResult<Vec<SampleResult>> {
66        // For now, delegate to the underlying ArminSampler
67        // In a full implementation, this would include additional
68        // optimization strategies specific to MIKAS
69        self.armin_sampler.run_qubo(qubo, shots)
70    }
71
72    fn run_hobo(
73        &self,
74        hobo: &(
75            Array<f64, scirs2_core::ndarray::IxDyn>,
76            HashMap<String, usize>,
77        ),
78        shots: usize,
79    ) -> SamplerResult<Vec<SampleResult>> {
80        // For now, delegate to the underlying ArminSampler
81        // In a full implementation, this would include specialized
82        // HOBO handling and optimization strategies
83        self.armin_sampler.run_hobo(hobo, shots)
84    }
85}
86
87// Fallback implementation when GPU feature is not enabled
88#[cfg(not(feature = "gpu"))]
89pub struct MIKASAmpler {
90    /// Fallback sampler
91    fallback_sampler: ArminSampler,
92}
93
94#[cfg(not(feature = "gpu"))]
95impl MIKASAmpler {
96    #[must_use]
97    pub const fn new(_seed: Option<u64>) -> Self {
98        Self {
99            fallback_sampler: ArminSampler::new(None),
100        }
101    }
102
103    #[must_use]
104    pub const fn with_params(
105        _seed: Option<u64>,
106        _mode: &str,
107        _device: &str,
108        _verbose: bool,
109    ) -> Self {
110        Self {
111            fallback_sampler: ArminSampler::new(None),
112        }
113    }
114}
115
116#[cfg(not(feature = "gpu"))]
117impl Sampler for MIKASAmpler {
118    fn run_qubo(
119        &self,
120        _qubo: &(Array<f64, Ix2>, HashMap<String, usize>),
121        _shots: usize,
122    ) -> SamplerResult<Vec<SampleResult>> {
123        Err(SamplerError::GpuError(
124            "GPU support not enabled".to_string(),
125        ))
126    }
127
128    fn run_hobo(
129        &self,
130        _hobo: &(
131            Array<f64, scirs2_core::ndarray::IxDyn>,
132            HashMap<String, usize>,
133        ),
134        _shots: usize,
135    ) -> SamplerResult<Vec<SampleResult>> {
136        Err(SamplerError::GpuError(
137            "GPU support not enabled".to_string(),
138        ))
139    }
140}