quantrs2_tytan/sampler/hardware/
mikas.rs1use scirs2_core::ndarray::{Array, Ix2};
4use std::collections::HashMap;
5
6use super::super::gpu::ArminSampler;
7use super::super::{SampleResult, Sampler, SamplerError, SamplerResult};
8
9#[cfg(feature = "gpu")]
14pub struct MIKASAmpler {
15 armin_sampler: ArminSampler,
17 optimization_mode: String,
19}
20
21#[cfg(feature = "gpu")]
22impl MIKASAmpler {
23 #[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 #[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 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 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 self.armin_sampler.run_hobo(hobo, shots)
84 }
85}
86
87#[cfg(not(feature = "gpu"))]
89pub struct MIKASAmpler {
90 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}