Using a Trained Policy#

Training produces a policy: the collection of cuts. Two methods put it to work: policy() answers a single “what should I do here?” question, and simulate() evaluates the policy across many random paths.

Point queries with policy()#

policy() solves one stage at a given situation: a stage, the incoming state, and the realised noise.

decision = sddp.policy(stage="mar", state=150, noise=350, report=[R, L, Z, F])

decision.decisions          # {'R': 200.0, 'L': 250.0, 'Z': 0.0, 'F': 50.0}
decision.approx_cost_to_go  # 875.0

The returned PolicyResult carries the queried stage, the incoming_state and noise, the optimal decisions for the reported variables, and approx_cost_to_go, the immediate stage cost plus the cut-approximated future cost from here on.

  • state is a scalar for a single state variable, or a dict keyed by state-variable name when there are several.

  • report lists the variables whose optimal level to return; it defaults to the state variables. A time-only variable reports a float; a variable with extra dimensions reports a dict keyed by the non-time labels.

Note

policy() needs a trained policy. Calling it before train() warns that no cuts exist yet and returns a decision that is not the trained policy.

Monte Carlo with simulate()#

simulate() runs the policy forward on fresh sampled paths and returns the realised cost distribution.

sim = sddp.simulate(n_paths=1000, seed=0)
print(sim.summary)
n_paths    1000.000000
mean        140.000000
std         438.283119
p5            0.000000
p50           0.000000
p95        1500.000000
max        2500.000000
Name: total_cost, dtype: float64

Each simulated path is one sequence of sampled noise values across all stages. simulate() returns a SimulationResult containing:

  • total_cost: the total cost of each path, summed across all stages.

  • stage_costs: the cost at each stage of each path.

  • noise: the sampled noise value at each stage of each path.

  • variables: one table for each reported variable, containing its value at the end of each stage for each path.

sim.summary summarises the total costs across paths. It reports the number of paths, mean, standard deviation, percentiles, and maximum cost.

Use report to choose which variables to record. By default, these are the registered state variables. If seed is omitted, simulation uses the seed configured when creating the SDDP instance plus one; 42 -> 43.

After loading a saved policy with SDDP.load(...), you can call policy() and simulate() on the loaded instance without retraining. See Saving and Loading for details.

policy() and simulate() apply the solve status checks to every required solve. If a check fails, the method raises ValidationError instead of returning a result.

A solver-reported user interruption (SolveStatus.UserInterrupt) also raises ValidationError for these methods.

See also

The ClearLake tutorial runs both methods on a complete model; Risk Aversion (CVaR) interprets the skewed cost distribution that simulate() reveals here.