Skip to main content

_diffctx/config/
selection.rs

1use crate::config::env_overrides::{read_env_fraction, read_env_u32};
2
3#[derive(Clone)]
4pub struct SelectionConfig {
5    pub core_budget_fraction: f64,
6    pub r_cap_min: f64,
7}
8
9impl Default for SelectionConfig {
10    fn default() -> Self {
11        Self {
12            // Confirmed by the v4 re-calibration on the EGO pipeline
13            // (5x3 grid over the v1 calibration manifest): validated
14            // winner (tau, cbf) = (0.12, 0.5) at min(per_benchmark
15            // file_recall) = 0.6532. Surface is flat and monotone
16            // (top-3 within 0.004), so the choice is robust rather
17            // than tuned to a sharp optimum.
18            core_budget_fraction: 0.5,
19            r_cap_min: 0.01,
20        }
21    }
22}
23
24#[derive(Clone)]
25pub struct RescueConfig {
26    pub budget_fraction: f64,
27    pub min_score_percentile: f64,
28}
29
30impl Default for RescueConfig {
31    fn default() -> Self {
32        Self {
33            budget_fraction: 0.05,
34            min_score_percentile: 0.80,
35        }
36    }
37}
38
39#[derive(Clone)]
40pub struct BoltzmannConfig {
41    pub beta_lo: f64,
42    pub beta_hi: f64,
43    pub bisect_iters: u32,
44    pub calibration_tolerance: f64,
45}
46
47impl Default for BoltzmannConfig {
48    fn default() -> Self {
49        Self {
50            beta_lo: 1e-6,
51            beta_hi: 1.0,
52            bisect_iters: 24,
53            calibration_tolerance: 0.05,
54        }
55    }
56}
57
58pub fn selection() -> SelectionConfig {
59    SelectionConfig {
60        core_budget_fraction: read_env_fraction("DIFFCTX_OP_SELECTION_CORE_BUDGET_FRACTION", 0.5),
61        r_cap_min: read_env_fraction("DIFFCTX_OP_SELECTION_R_CAP_MIN", 0.01),
62    }
63}
64
65pub fn rescue() -> RescueConfig {
66    RescueConfig {
67        budget_fraction: read_env_fraction("DIFFCTX_OP_RESCUE_BUDGET_FRACTION", 0.05),
68        min_score_percentile: read_env_fraction("DIFFCTX_OP_RESCUE_MIN_SCORE_PERCENTILE", 0.80),
69    }
70}
71
72pub fn boltzmann() -> BoltzmannConfig {
73    BoltzmannConfig {
74        calibration_tolerance: read_env_fraction(
75            "DIFFCTX_OP_BOLTZMANN_CALIBRATION_TOLERANCE",
76            0.05,
77        ),
78        bisect_iters: read_env_u32("DIFFCTX_OP_BOLTZMANN_BISECT_ITERS", 24).max(1),
79        ..BoltzmannConfig::default()
80    }
81}