pub struct StudySetup {
pub stage_data: StageData,
pub stochastic: StochasticContext,
pub fcf: FutureCostFunction,
pub hydro_models: PrepareHydroModelsResult,
pub scenario_libraries: ScenarioLibraries,
pub loop_params: LoopParams,
pub simulation_config: SimulationConfig,
pub policy_path: String,
/* private fields */
}Expand description
All precomputed study state built once before training and simulation.
Constructed by StudySetup::new from a validated System and
cobre_io::Config. Owns all data so it can be held across async
boundaries (e.g., Python GIL release) without lifetime issues.
Callers build TrainingContext and StageContext by borrowing
from StudySetup.
Fields§
§stage_data: StageDataStage-indexed data: LP templates, indexer, stages, entity counts, blocks, lag transitions, noise groups, and scaling report.
stochastic: StochasticContextStochastic context holding sampling distributions, libraries, and provenance.
fcf: FutureCostFunctionFuture cost function (cut pool) updated by the backward pass during training.
hydro_models: PrepareHydroModelsResultPre-computed hydro production models (FPHA, turbine curves, etc.).
scenario_libraries: ScenarioLibrariesSampling schemes and pre-built libraries for training and simulation phases.
Replaces the 14 flat inflow_scheme / sim_inflow_scheme / … fields.
Access via scenario_libraries.training.<field> or
scenario_libraries.simulation.<field>.
loop_params: LoopParamsIteration-loop parameters projected from crate::config::LoopConfig.
Holds the five pure-data fields of crate::config::LoopConfig that are stable
across training invocations. n_fwd_threads is excluded (derived
at runtime) and supplied as a per-call argument to StudySetup::train.
simulation_config: SimulationConfigSimulation pipeline parameters, stored directly as crate::simulation::SimulationConfig.
policy_path: StringRelative path to the policy output directory (e.g. "training/policy").
Implementations§
Source§impl StudySetup
impl StudySetup
Sourcepub fn replace_fcf(&mut self, fcf: FutureCostFunction)
pub fn replace_fcf(&mut self, fcf: FutureCostFunction)
Replace the FCF with a pre-loaded policy.
Sourcepub fn set_start_iteration(&mut self, iteration: u64)
pub fn set_start_iteration(&mut self, iteration: u64)
Set the starting iteration for resumed training.
Sourcepub fn set_warm_start_basis_cache(&mut self, cache: Vec<Option<CapturedBasis>>)
pub fn set_warm_start_basis_cache(&mut self, cache: Vec<Option<CapturedBasis>>)
Seed the per-stage warm-start basis cache for warm-start / resume training.
cache carries one entry per stage (as built by
build_basis_cache_from_checkpoint
from the checkpoint’s stored solver bases). StudySetup::train takes
this out of self and replicates each stage’s basis across every
forward-pass worker so iteration 1’s cut-loaded LPs warm-start.
Leave unset (the default None) for a fresh start.
Sourcepub fn set_export_states(&mut self, export: bool)
pub fn set_export_states(&mut self, export: bool)
Enable state archiving for export.
Sourcepub fn set_budget(&mut self, budget: Option<u32>)
pub fn set_budget(&mut self, budget: Option<u32>)
Set the active-cut budget cap per stage.
Sourcepub fn energy_conversion(&self) -> &EnergyConversionSet
pub fn energy_conversion(&self) -> &EnergyConversionSet
Return the pre-computed EnergyConversionSet for this study.
Provides ρ_eq, V_ref, Q_ref, and ρ_acum (accumulated cascade
productivity) for every (hydro, stage) pair. Consumed by the
energy-balance LP constraints and inflow-energy / stored-energy extraction.
Sourcepub fn simulation_config(&self) -> &SimulationConfig
pub fn simulation_config(&self) -> &SimulationConfig
Return a reference to the simulation configuration.
Sourcepub fn stage_indexer(&self) -> &StageIndexer
pub fn stage_indexer(&self) -> &StageIndexer
Return a reference to the per-stage LP column/row indexer.
Provides LP layout constants — column and row ranges for every entity class (storage, thermal, anticipated state, etc.) — so that callers can locate specific primal or state-vector entries without hard-coding offsets.
The same indexer applies to every stage (the layout is uniform across stages in a study).
Sourcepub fn num_stages(&self) -> usize
pub fn num_stages(&self) -> usize
Number of stages in the planning horizon.
Used by the CLI summary to express the pool-level active-row total on a per-stage basis, so it is directly comparable to the per-solve rows-in-LP metric reported for Dynamic Cut Selection.
Sourcepub fn stage_ctx(&self) -> StageContext<'_>
pub fn stage_ctx(&self) -> StageContext<'_>
Construct a StageContext borrowing from this setup.
Source§impl StudySetup
impl StudySetup
Sourcepub fn train<S, C: Communicator>(
&mut self,
solver: &mut S,
comm: &C,
n_threads: usize,
solver_factory: impl Fn() -> Result<S, SolverError>,
event_sender: Option<Sender<TrainingEvent>>,
shutdown_flag: Option<&Arc<AtomicBool>>,
) -> Result<TrainingOutcome, SddpError>
pub fn train<S, C: Communicator>( &mut self, solver: &mut S, comm: &C, n_threads: usize, solver_factory: impl Fn() -> Result<S, SolverError>, event_sender: Option<Sender<TrainingEvent>>, shutdown_flag: Option<&Arc<AtomicBool>>, ) -> Result<TrainingOutcome, SddpError>
Execute the training loop.
Constructs TrainingConfig and TrainingContext, then delegates to
crate::train. Mutates self.fcf to store generated cuts.
§Errors
Returns SddpError::Infeasible, SddpError::Solver, or
SddpError::Communication on LP, solver, or MPI failure.
Sourcepub fn simulate<S, C: Communicator>(
&self,
workspaces: &mut [SolverWorkspace<S>],
comm: &C,
result_tx: &SyncSender<SimulationScenarioResult>,
event_sender: Option<Sender<TrainingEvent>>,
baked_templates: Option<&[StageTemplate]>,
stage_bases: &[Option<CapturedBasis>],
) -> Result<SimulationRunResult, SimulationError>
pub fn simulate<S, C: Communicator>( &self, workspaces: &mut [SolverWorkspace<S>], comm: &C, result_tx: &SyncSender<SimulationScenarioResult>, event_sender: Option<Sender<TrainingEvent>>, baked_templates: Option<&[StageTemplate]>, stage_bases: &[Option<CapturedBasis>], ) -> Result<SimulationRunResult, SimulationError>
Run simulation using the trained future cost function.
The caller provides channels, event sender, and thread management.
baked_templates enables the baked-template LP load path (no add_rows
per stage); pass None for the legacy load_model + add_rows fallback.
stage_bases enables warm-start; pass &[] for cold-start.
§Errors
Returns SimulationError on LP infeasibility, solver failure, channel closure,
or if baked_templates.len() != num_stages.
Sourcepub fn build_training_output(
&self,
result: &TrainingResult,
events: &[TrainingEvent],
) -> TrainingOutput
pub fn build_training_output( &self, result: &TrainingResult, events: &[TrainingEvent], ) -> TrainingOutput
Convert TrainingResult and events into training output.
Delegates to crate::build_training_output with cut statistics from self.fcf.
Sourcepub fn create_workspace_pool<S: SolverInterface + Send, C: Communicator>(
&self,
comm: &C,
n_threads: usize,
solver_factory: impl Fn() -> Result<S, SolverError>,
) -> Result<WorkspacePool<S>, SolverError>
pub fn create_workspace_pool<S: SolverInterface + Send, C: Communicator>( &self, comm: &C, n_threads: usize, solver_factory: impl Fn() -> Result<S, SolverError>, ) -> Result<WorkspacePool<S>, SolverError>
Create a WorkspacePool sized for this study.
Pool size equals n_threads. Each workspace gets a fresh solver instance.
comm is used to read the MPI rank that is stamped into each workspace’s
rank field for downstream per-worker observability.
§Errors
Returns SolverError if solver creation fails.
§Panics
Panics if comm.rank() > i32::MAX. MPI world sizes are bounded well
below this on all real systems.
Source§impl StudySetup
impl StudySetup
Sourcepub fn new(
system: &System,
config: &Config,
stochastic: StochasticContext,
hydro_models: PrepareHydroModelsResult,
) -> Result<Self, SddpError>
pub fn new( system: &System, config: &Config, stochastic: StochasticContext, hydro_models: PrepareHydroModelsResult, ) -> Result<Self, SddpError>
Build all precomputed study state from a validated system and config.
The constructor performs:
- Config field extraction (seed, forward passes, stopping rules, etc.)
- Delegates to
StudySetup::from_broadcast_paramswith the extracted values.
§Errors
SddpError::Validation— ifbuild_stage_templatessucceeds but the template list is empty (“system has no study stages”).SddpError::Solver— propagated frombuild_stage_templateson LP construction failure.SddpError::Validation— ifparse_cut_selection_configreturns an invalid config string.
Sourcepub fn from_broadcast_params(
system: &System,
stochastic: StochasticContext,
config: ConstructionConfig,
hydro_models: PrepareHydroModelsResult,
training_source: &ScenarioSource,
simulation_source: &ScenarioSource,
) -> Result<Self, SddpError>
pub fn from_broadcast_params( system: &System, stochastic: StochasticContext, config: ConstructionConfig, hydro_models: PrepareHydroModelsResult, training_source: &ScenarioSource, simulation_source: &ScenarioSource, ) -> Result<Self, SddpError>
Build all precomputed study state from pre-resolved broadcast parameters.
This constructor accepts the scalar fields already extracted from either a
cobre_io::Config (on rank 0) or a broadcast config struct (on non-root
ranks). It performs the expensive computation steps that cannot be serialised:
build_stage_templates— constructs LP skeletons for each stageStageIndexer::with_equipment— computes LP column/row offsetsbuild_initial_state— extracts initial storage and past inflows from system ICmax_iterations_from_rules— sizes the FCF cut poolFutureCostFunction::new— pre-allocates cut storageHorizonMode::Finite— wraps stage count- Risk measures from stage configs
build_entity_counts— entity ID and productivity vectors- Block layout derivation (
block_counts_per_stage,max_blocks)
§Errors
SddpError::Validation— ifbuild_stage_templatessucceeds but the template list is empty (“system has no study stages”).SddpError::Solver— propagated frombuild_stage_templateson LP construction failure.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StudySetup
impl RefUnwindSafe for StudySetup
impl Send for StudySetup
impl Sync for StudySetup
impl Unpin for StudySetup
impl UnsafeUnpin for StudySetup
impl UnwindSafe for StudySetup
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more