use super::super::{ErrorKind, ValidationContext, schema::ParsedData};
pub(super) fn check_sobol_power_of_2(data: &ParsedData, ctx: &mut ValidationContext) {
use cobre_core::temporal::NoiseMethod;
for stage in &data.stages.stages {
if stage.id < 0 {
continue; }
let bf = stage.scenario_config.branching_factor;
if stage.scenario_config.noise_method == NoiseMethod::QmcSobol && !bf.is_power_of_two() {
let suggestion = if bf > 0 {
let lower = 1usize << (usize::BITS - bf.leading_zeros() - 1);
let upper = lower << 1;
format!("consider {lower} or {upper}")
} else {
"consider a positive power of 2".to_string()
};
ctx.add_warning(
ErrorKind::ModelQuality,
"stages.json",
Some(format!("Stage {}", stage.id)),
format!(
"Stage {}: qmc_sobol with num_scenarios={bf} which is not a \
power of 2; Sobol sequences have optimal uniformity at powers \
of 2 ({suggestion})",
stage.id,
),
);
}
}
}