Skip to content
Snippets Groups Projects
Unverified Commit b85a9aae authored by Michiel Cottaar's avatar Michiel Cottaar
Browse files

Do not allow user to set optimiser

Only one works
parent a3ae366a
No related branches found
No related tags found
1 merge request!8Make optimisation more robust
Pipeline #25451 canceled
...@@ -34,7 +34,7 @@ Wrapper to build a sequence. ...@@ -34,7 +34,7 @@ Wrapper to build a sequence.
Use as Use as
```julia ```julia
build_sequence(scanner[, optimiser_constructor];) do build_sequence(scanner;) do
... ...
end end
``` ```
...@@ -56,7 +56,6 @@ As soon as the code block ends the sequence is optimised (if `optimise=true`) an ...@@ -56,7 +56,6 @@ As soon as the code block ends the sequence is optimised (if `optimise=true`) an
## Parameters ## Parameters
- `scanner`: Set to a [`Scanner`](@ref) to limit the gradient strength and slew rate. When this call to `build_sequence` is embedded in another, this parameter can be set to `nothing` to indicate that the same scanner should be used. - `scanner`: Set to a [`Scanner`](@ref) to limit the gradient strength and slew rate. When this call to `build_sequence` is embedded in another, this parameter can be set to `nothing` to indicate that the same scanner should be used.
- `optimiser_constructor`: A `JuMP` solver optimiser as described in the [JuMP documentation](https://jump.dev/JuMP.jl/stable/tutorials/getting_started/getting_started_with_JuMP/#What-is-a-solver?). Defaults to using [Ipopt](https://github.com/jump-dev/Ipopt.jl).
- `optimise`: Whether to optimise and fix the sequence as soon as it is returned. This defaults to `true` if a scanner is provided and `false` if no scanner is provided. - `optimise`: Whether to optimise and fix the sequence as soon as it is returned. This defaults to `true` if a scanner is provided and `false` if no scanner is provided.
- `n_attempts`: How many times to restart the optimser (default: 100). - `n_attempts`: How many times to restart the optimser (default: 100).
- `kwargs...`: Other keywords are passed on as attributes to the `optimiser_constructor` (e.g., set `print_level=3` to make the Ipopt optimiser quieter). - `kwargs...`: Other keywords are passed on as attributes to the `optimiser_constructor` (e.g., set `print_level=3` to make the Ipopt optimiser quieter).
...@@ -129,10 +128,16 @@ function optimise_with_cost_func(jump_model::Model, cost_func, n_attempts) ...@@ -129,10 +128,16 @@ function optimise_with_cost_func(jump_model::Model, cost_func, n_attempts)
end end
end end
function build_sequence(f::Function, scanner::Union{Nothing, Scanner}, optimiser_constructor; optimise=true, n_attempts=10, kwargs...) function build_sequence(f::Function, scanner::Union{Nothing, Scanner}=Default_Scanner; optimise=true, n_attempts=10, print_level=0, mu_strategy="adaptive", max_iter=10000, kwargs...)
if optimise || GLOBAL_MODEL[] == IGNORE_MODEL if optimise || GLOBAL_MODEL[] == IGNORE_MODEL
full_kwargs = Dict(
:print_level => print_level,
:mu_strategy => mu_strategy,
:max_iter => max_iter,
kwargs...
)
model = ( model = (
Model(optimizer_with_attributes(optimiser_constructor, [string(k) => v for (k, v) in kwargs]...)), Model(optimizer_with_attributes(Ipopt.Optimizer, [string(k) => v for (k, v) in full_kwargs]...)),
Tuple{Float64, AbstractJuMPScalar}[] Tuple{Float64, AbstractJuMPScalar}[]
) )
else else
...@@ -141,12 +146,6 @@ function build_sequence(f::Function, scanner::Union{Nothing, Scanner}, optimiser ...@@ -141,12 +146,6 @@ function build_sequence(f::Function, scanner::Union{Nothing, Scanner}, optimiser
build_sequence(f, scanner, model, optimise, n_attempts) build_sequence(f, scanner, model, optimise, n_attempts)
end end
function build_sequence(f::Function, scanner::Union{Nothing, Scanner}=Default_Scanner; print_level=0, mu_strategy="adaptive", max_iter=10000, kwargs...)
build_sequence(f, scanner, Ipopt.Optimizer; print_level=print_level, mu_strategy=mu_strategy, max_iter=max_iter, kwargs...)
end
build_sequence(f::Function, optimiser_constructor; kwargs...) = build_sequence(f, Default_Scanner, optimiser_constructor; kwargs...)
""" """
global_scanner() global_scanner()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment