_diffctx/config/
selection.rs1use crate::config::env_overrides::{read_env_fraction, read_env_u32};
2
3pub const DEFAULT_CORE_BUDGET_FRACTION: f64 = 0.4;
8
9#[derive(Clone)]
10pub struct SelectionConfig {
11 pub core_budget_fraction: f64,
12 pub r_cap_min: f64,
13 pub per_file_budget_fraction: f64,
19}
20
21impl Default for SelectionConfig {
22 fn default() -> Self {
23 Self {
24 core_budget_fraction: DEFAULT_CORE_BUDGET_FRACTION,
28 r_cap_min: 0.01,
29 per_file_budget_fraction: 0.25,
30 }
31 }
32}
33
34#[derive(Clone)]
35pub struct RescueConfig {
36 pub budget_fraction: f64,
37 pub min_score_percentile: f64,
38}
39
40impl Default for RescueConfig {
41 fn default() -> Self {
42 Self {
43 budget_fraction: 0.05,
44 min_score_percentile: 0.80,
45 }
46 }
47}
48
49#[derive(Clone)]
50pub struct BoltzmannConfig {
51 pub beta_lo: f64,
52 pub beta_hi: f64,
53 pub bisect_iters: u32,
54 pub calibration_tolerance: f64,
55}
56
57impl Default for BoltzmannConfig {
58 fn default() -> Self {
59 Self {
60 beta_lo: 1e-6,
61 beta_hi: 1.0,
62 bisect_iters: 24,
63 calibration_tolerance: 0.05,
64 }
65 }
66}
67
68pub fn selection() -> SelectionConfig {
69 SelectionConfig {
70 core_budget_fraction: read_env_fraction(
71 "DIFFCTX_OP_SELECTION_CORE_BUDGET_FRACTION",
72 DEFAULT_CORE_BUDGET_FRACTION,
73 ),
74 r_cap_min: read_env_fraction("DIFFCTX_OP_SELECTION_R_CAP_MIN", 0.01),
75 per_file_budget_fraction: read_env_fraction(
76 "DIFFCTX_OP_SELECTION_PER_FILE_BUDGET_FRACTION",
77 0.25,
78 ),
79 }
80}
81
82pub fn rescue() -> RescueConfig {
83 RescueConfig {
84 budget_fraction: read_env_fraction("DIFFCTX_OP_RESCUE_BUDGET_FRACTION", 0.05),
85 min_score_percentile: read_env_fraction("DIFFCTX_OP_RESCUE_MIN_SCORE_PERCENTILE", 0.80),
86 }
87}
88
89pub fn boltzmann() -> BoltzmannConfig {
90 BoltzmannConfig {
91 calibration_tolerance: read_env_fraction(
92 "DIFFCTX_OP_BOLTZMANN_CALIBRATION_TOLERANCE",
93 0.05,
94 ),
95 bisect_iters: read_env_u32("DIFFCTX_OP_BOLTZMANN_BISECT_ITERS", 24).max(1),
96 ..BoltzmannConfig::default()
97 }
98}