cobre_sddp/simulation/config.rs
1//! Simulation configuration type for the SDDP policy evaluation phase.
2//!
3//! [`SimulationConfig`] bundles all parameters that control the simulation
4//! pipeline: number of scenarios to evaluate and the bounded channel capacity
5//! that throttles the background I/O thread.
6
7/// Parameters controlling the SDDP simulation pipeline.
8///
9/// Construct this struct directly — all fields are public and there is no
10/// builder or `Default` implementation. Every field must be set explicitly
11/// to prevent silent misconfiguration.
12///
13/// # Examples
14///
15/// ```rust
16/// use cobre_sddp::simulation::SimulationConfig;
17///
18/// let config = SimulationConfig {
19/// n_scenarios: 500,
20/// io_channel_capacity: 32,
21/// };
22/// assert_eq!(config.n_scenarios, 500);
23/// assert_eq!(config.io_channel_capacity, 32);
24/// ```
25#[derive(Debug)]
26pub struct SimulationConfig {
27 /// Total number of scenarios to simulate across all MPI ranks.
28 ///
29 /// Scenarios are distributed statically across ranks using the same
30 /// two-level distribution strategy as training (see
31 /// simulation-architecture.md SS3.1). Must be at least 1.
32 pub n_scenarios: u32,
33
34 /// Bounded channel capacity for the background I/O thread.
35 ///
36 /// Controls the maximum number of [`SimulationScenarioResult`] instances
37 /// that can be buffered in the channel between simulation threads and the
38 /// background I/O thread. When the channel is full, simulation threads
39 /// block until the I/O thread consumes a result, providing backpressure.
40 ///
41 /// Larger values increase memory usage but allow the I/O thread more
42 /// headroom to absorb bursts. Default in practice is 64.
43 ///
44 /// [`SimulationScenarioResult`]: crate::simulation::SimulationScenarioResult
45 pub io_channel_capacity: usize,
46}
47
48#[cfg(test)]
49mod tests {
50 use super::SimulationConfig;
51
52 #[test]
53 fn simulation_config_construction() {
54 let config = SimulationConfig {
55 n_scenarios: 2000,
56 io_channel_capacity: 64,
57 };
58 assert_eq!(config.n_scenarios, 2000);
59 assert_eq!(config.io_channel_capacity, 64);
60 }
61
62 #[test]
63 fn simulation_config_arbitrary_values() {
64 let config = SimulationConfig {
65 n_scenarios: 1,
66 io_channel_capacity: 1,
67 };
68 assert_eq!(config.n_scenarios, 1);
69 assert_eq!(config.io_channel_capacity, 1);
70 }
71
72 #[test]
73 fn simulation_config_debug_non_empty() {
74 let config = SimulationConfig {
75 n_scenarios: 100,
76 io_channel_capacity: 16,
77 };
78 let debug = format!("{config:?}");
79 assert!(!debug.is_empty());
80 assert!(
81 debug.contains("n_scenarios"),
82 "debug must contain field name: {debug}"
83 );
84 assert!(
85 debug.contains("io_channel_capacity"),
86 "debug must contain field name: {debug}"
87 );
88 }
89}