pub mod errors;
pub mod genetic_algorithm;
pub mod gpu;
pub mod hardware;
pub mod simulated_annealing;
use scirs2_core::ndarray::Array;
use std::collections::HashMap;
pub use errors::{SamplerError, SamplerResult};
#[derive(Debug, Clone)]
pub struct SampleResult {
pub assignments: HashMap<String, bool>,
pub energy: f64,
pub occurrences: usize,
}
pub trait Sampler {
fn run_qubo(
&self,
qubo: &(
Array<f64, scirs2_core::ndarray::Ix2>,
HashMap<String, usize>,
),
shots: usize,
) -> SamplerResult<Vec<SampleResult>>;
fn run_hobo(
&self,
hobo: &(
Array<f64, scirs2_core::ndarray::IxDyn>,
HashMap<String, usize>,
),
shots: usize,
) -> SamplerResult<Vec<SampleResult>>;
}
#[allow(dead_code)]
pub(crate) fn evaluate_qubo_energy(
state: &[bool],
h_vector: &[f64],
j_matrix: &[f64],
n_vars: usize,
) -> f64 {
let mut energy = 0.0;
for i in 0..n_vars {
if state[i] {
energy += h_vector[i];
}
}
for i in 0..n_vars {
if state[i] {
for j in 0..n_vars {
if state[j] {
energy += j_matrix[i * n_vars + j];
}
}
}
}
energy
}
pub use genetic_algorithm::GASampler;
pub use gpu::ArminSampler;
pub use hardware::{DWaveSampler, MIKASAmpler};
pub use simulated_annealing::SASampler;