Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions test/common/modeling_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ end

"""
Every problem solved on its default grid in each configuration, and reported, not tested
(#360); an exception still fails. The second solve is timed, once compiled.
(#360); an exception still fails. The solve is timed once compiled: by a first solve on the
default grid, or by the `warmup` of the adapter when it has one (a cheaper solve, #435).
"""
function test_convergence(backend, adapter)
name = modeling(backend)
Expand All @@ -129,7 +130,12 @@ function test_convergence(backend, adapter)
pb = getfield(OCP, problem)(backend)
N = OCP.grid_size_data(problem)
scheme = adapter.scheme(config)
sol = adapter.solve(pb, config; grid_size=N)
warmup = get(adapter, :warmup, nothing)
if isnothing(warmup)
adapter.solve(pb, config; grid_size=N)
else
warmup(pb, config)
end
time = @elapsed sol = adapter.solve(pb, config; grid_size=N) # compiled
# convergence is reported, not tested (#360); an exception still fails
Main.TestStatus.result!(
Expand Down
12 changes: 11 additions & 1 deletion test/common/modelingtoolkit_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ function analytic_objective(problem, grid_size, scheme)
return isnothing(ref) ? nothing : ref.objective
end

"""What the shared tests need of the ModelingToolkit solves (see `common/modeling_tests.jl`)."""
"""
What the shared tests need of the ModelingToolkit solves (see `common/modeling_tests.jl`).
The warmup compiles on the smoke grid, a few iterations: a second solve on the default grid
costs as much as the first one (#435).
"""
function adapter()
S = Main.SolveModelingToolkit
return (
solve=(pb, config; kwargs...) -> S.solve(pb, config; kwargs...),
warmup=(pb, config) -> S.solve(
pb,
config;
grid_size=Main.TestConfigs.SMOKE_GRID,
max_iter=Main.TestConfigs.SMOKE_MAX_ITER,
),
objective=S.objective,
settings=S.settings,
scheme=S.scheme,
Expand Down
3 changes: 3 additions & 0 deletions test/common/solve_modelingtoolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ function solver_options(
tol=o.TOL,
max_iter=max_iter,
mu_strategy=o.MU_STRATEGY,
# a quasi-Newton Hessian, as in the examples of Corleone: the exact one, by ForwardDiff
# through the integration of every control interval, is dense and costly (#435)
hessian_approximation="limited-memory",
linear_solver="mumps",
max_wall_time=o.MAX_WALL_TIME,
sb=o.SB,
Expand Down
Loading