Skip to content

Commit

Permalink
Throw error for invalid log_frequency values (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Sep 12, 2023
1 parent 9eff9f7 commit 7765a0c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/algorithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ Train the policy for `model`.
progress. Defaults to `SDDP.log`.
- `log_frequency::Int`: control the frequency with which the logging is
outputted (iterations/log). Defaults to `1`.
outputted (iterations/log). It must be at least `1`. Defaults to `1`.
- `log_every_seconds::Float64`: control the frequency with which the logging is
outputted (seconds/log). Defaults to `0.0`.
Expand Down Expand Up @@ -965,6 +965,10 @@ function train(
forward_pass_callback::Function = (x) -> nothing,
post_iteration_callback = result -> nothing,
)
if log_frequency <= 0
msg = "`log_frequency` must be at least `1`. Got $log_frequency."
throw(ArgumentError(msg))
end
function log_frequency_f(log::Vector{Log})
if mod(length(log), log_frequency) != 0
return false
Expand Down
13 changes: 13 additions & 0 deletions test/algorithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,19 @@ function test_print_log()
return
end

function test_log_frequency_argument_error()
model = SDDP.LinearPolicyGraph(
stages = 2,
lower_bound = 0.0,
optimizer = HiGHS.Optimizer,
) do node, stage
@variable(node, x >= 0, SDDP.State, initial_value = 0.0)
@stageobjective(node, x.out)
end
@test_throws ArgumentError SDDP.train(model; log_frequency = 0)
return
end

end # module

TestAlgorithm.runtests()

0 comments on commit 7765a0c

Please sign in to comment.