diff --git a/src/OptimalControl.jl b/src/OptimalControl.jl index 72b30d66..86542525 100644 --- a/src/OptimalControl.jl +++ b/src/OptimalControl.jl @@ -101,4 +101,4 @@ include(joinpath(@__DIR__, "solve", "descriptive.jl")) export methods # non useful since it is already in Base -end \ No newline at end of file +end diff --git a/src/helpers/descriptive_routing.jl b/src/helpers/descriptive_routing.jl index d3160466..cb20313f 100644 --- a/src/helpers/descriptive_routing.jl +++ b/src/helpers/descriptive_routing.jl @@ -314,9 +314,7 @@ function _build_components_from_routed( ) # Resolve method with parameter information as early as possible families = _descriptive_families() - resolved = CTBase.Orchestration.resolve_method( - complete_description, families, registry - ) + resolved = CTBase.Orchestration.resolve_method(complete_description, families, registry) # Build strategies using resolved method discretizer = CTBase.Orchestration.build_strategy_from_resolved( diff --git a/src/helpers/strategy_builders.jl b/src/helpers/strategy_builders.jl index ad9ad30a..f226ca94 100644 --- a/src/helpers/strategy_builders.jl +++ b/src/helpers/strategy_builders.jl @@ -171,7 +171,9 @@ skipping directly to processing the solver component. - Delegates to solver processing - Terminal case in the recursion chain """ -function _build_partial_tuple(::Nothing, solver::Union{CTSolvers.Solvers.AbstractNLPSolver,Nothing}) +function _build_partial_tuple( + ::Nothing, solver::Union{CTSolvers.Solvers.AbstractNLPSolver,Nothing} +) return _build_partial_tuple(solver) end @@ -330,5 +332,7 @@ function _build_or_use_strategy( registry::CTBase.Strategies.StrategyRegistry, ) # Build path: construct from resolved method - return CTBase.Orchestration.build_strategy_from_resolved(resolved, family_name, families, registry) + return CTBase.Orchestration.build_strategy_from_resolved( + resolved, family_name, families, registry + ) end diff --git a/test/helpers/capabilities.jl b/test/helpers/capabilities.jl index 07ff2117..e7f5a346 100644 --- a/test/helpers/capabilities.jl +++ b/test/helpers/capabilities.jl @@ -44,8 +44,7 @@ is_cuda_on() = CUDA.functional() `CUDSS` are all in the session. CPU-runnable: it says nothing about whether a device exists. """ -gpu_extension_armed() = - Base.get_extension(CTSolvers, :CTSolversMadNLPGPU) !== nothing +gpu_extension_armed() = Base.get_extension(CTSolvers, :CTSolversMadNLPGPU) !== nothing """ on_gpu_runner() diff --git a/test/helpers/reexport.jl b/test/helpers/reexport.jl index c51b5e53..d0da611c 100644 --- a/test/helpers/reexport.jl +++ b/test/helpers/reexport.jl @@ -63,7 +63,8 @@ end match. Use it when the owner is awkward to name (e.g. `Base` generics extended downstream). """ -same_object(mod::Module, name::Symbol, ref) = - isdefined(mod, name) && getfield(mod, name) === ref +function same_object(mod::Module, name::Symbol, ref) + return isdefined(mod, name) && getfield(mod, name) === ref +end end # module diff --git a/test/problems/beam.jl b/test/problems/beam.jl index b417a643..d8acec84 100644 --- a/test/problems/beam.jl +++ b/test/problems/beam.jl @@ -14,7 +14,7 @@ Return the beam problem as a [`TestProblem`](@ref). function Beam(form::Symbol=:abstract) check_form(form) return cached(:beam, form, ()) do - form === :abstract ? _beam_abstract() : _beam_functional() + return form === :abstract ? _beam_abstract() : _beam_functional() end end diff --git a/test/problems/common.jl b/test/problems/common.jl index d74562e8..8f741b1f 100644 --- a/test/problems/common.jl +++ b/test/problems/common.jl @@ -151,9 +151,8 @@ Throw a readable `ArgumentError` on an unknown form rather than letting it fall through to a `MethodError` three frames down. """ function check_form(form::Symbol) - form in FORMS || throw( - ArgumentError("unknown form $(repr(form)); expected one of $(FORMS)") - ) + form in FORMS || + throw(ArgumentError("unknown form $(repr(form)); expected one of $(FORMS)")) return form end diff --git a/test/problems/control_free.jl b/test/problems/control_free.jl index 62dab60b..2c7414dc 100644 --- a/test/problems/control_free.jl +++ b/test/problems/control_free.jl @@ -20,7 +20,7 @@ Growth-rate estimation: fit `ẋ = p·x`, `x(0) = 2` to the analytical data function ExponentialGrowth(form::Symbol=:abstract) check_form(form) return cached(:exponential_growth, form, ()) do - form === :abstract ? _exp_growth_abstract() : _exp_growth_functional() + return form === :abstract ? _exp_growth_abstract() : _exp_growth_functional() end end @@ -101,7 +101,7 @@ minimising `ω²`. The analytical solution is `ω = π/2`, so the objective is function HarmonicOscillator(form::Symbol=:abstract) check_form(form) return cached(:harmonic_oscillator, form, ()) do - form === :abstract ? _harmonic_abstract() : _harmonic_functional() + return form === :abstract ? _harmonic_abstract() : _harmonic_functional() end end diff --git a/test/problems/double_integrator.jl b/test/problems/double_integrator.jl index 8a607a68..f2ccb4d1 100644 --- a/test/problems/double_integrator.jl +++ b/test/problems/double_integrator.jl @@ -84,7 +84,10 @@ function _di_energy_cons_shoot_builder(ocp, d) f_interior = OptimalControl.Flow(ocp, (x, p) -> p[2]; hamiltonian_type) f_boundary = OptimalControl.Flow( - ocp, (x, p) -> 0.0; constraint=(x, u) -> g(x), multiplier=(x, p) -> μ(p), + ocp, + (x, p) -> 0.0; + constraint=(x, u) -> g(x), + multiplier=(x, p) -> μ(p), hamiltonian_type, ) @@ -122,7 +125,7 @@ Minimise the final time for `ẋ = (x₂, u)`, `u ∈ [-1, 1]`, from `(-1, 0)` t function DoubleIntegratorTime(form::Symbol=:abstract) check_form(form) return cached(:double_integrator_time, form, ()) do - form === :abstract ? _di_time_abstract() : _di_time_functional() + return form === :abstract ? _di_time_abstract() : _di_time_functional() end end @@ -234,14 +237,12 @@ which makes this the cheapest shooting fixture in the library. function DoubleIntegratorEnergy(form::Symbol=:abstract) check_form(form) return cached(:double_integrator_energy, form, ()) do - form === :abstract ? _di_energy_abstract() : _di_energy_functional() + return form === :abstract ? _di_energy_abstract() : _di_energy_functional() end end const _DI_ENERGY_OBJ = 6.0 -const _DI_ENERGY_DATA = ( - x0=[-1.0, 0.0], xf=[0.0, 0.0], t0=0.0, tf=1.0, p0=[12.0, 6.0] -) +const _DI_ENERGY_DATA = (x0=[-1.0, 0.0], xf=[0.0, 0.0], t0=0.0, tf=1.0, p0=[12.0, 6.0]) function _di_energy_abstract() @def ocp begin @@ -329,7 +330,11 @@ boundary arc between `t₁ = 0.25` and `t₂ = 0.75`. function DoubleIntegratorEnergyConstrained(form::Symbol=:abstract) check_form(form) return cached(:double_integrator_energy_constrained, form, ()) do - form === :abstract ? _di_energy_cons_abstract() : _di_energy_cons_functional() + return if form === :abstract + _di_energy_cons_abstract() + else + _di_energy_cons_functional() + end end end diff --git a/test/problems/goddard.jl b/test/problems/goddard.jl index c616d07f..155bb4db 100644 --- a/test/problems/goddard.jl +++ b/test/problems/goddard.jl @@ -20,8 +20,11 @@ plus the constants the shooting function is written against (`vmax`, `mf`, function Goddard(form::Symbol=:abstract; vmax=0.1, Tmax=3.5) check_form(form) return cached(:goddard, form, (vmax, Tmax)) do - form === :abstract ? _goddard_abstract(; vmax, Tmax) : - _goddard_functional(; vmax, Tmax) + return if form === :abstract + _goddard_abstract(; vmax, Tmax) + else + _goddard_functional(; vmax, Tmax) + end end end @@ -61,9 +64,7 @@ function _goddard_constants(; vmax, Tmax) ) tf_ref = 0.20204744057100849 - return (; - Cd, β, b, r0, v0, m0, mf, vmax, Tmax, x0, F0, F1, p0, switching_times, tf_ref - ) + return (; Cd, β, b, r0, v0, m0, mf, vmax, Tmax, x0, F0, F1, p0, switching_times, tf_ref) end """ diff --git a/test/problems/quadrotor.jl b/test/problems/quadrotor.jl index 86a49ea8..e2f11089 100644 --- a/test/problems/quadrotor.jl +++ b/test/problems/quadrotor.jl @@ -14,7 +14,11 @@ Return the quadrotor tracking problem as a [`TestProblem`](@ref). function Quadrotor(form::Symbol=:abstract; T=1, g=9.8, r=0.1) check_form(form) return cached(:quadrotor, form, (T, g, r)) do - form === :abstract ? _quadrotor_abstract(; T, g, r) : _quadrotor_functional(; T, g, r) + return if form === :abstract + _quadrotor_abstract(; T, g, r) + else + _quadrotor_functional(; T, g, r) + end end end diff --git a/test/problems/registry.jl b/test/problems/registry.jl index 88851171..476e3f36 100644 --- a/test/problems/registry.jl +++ b/test/problems/registry.jl @@ -50,9 +50,8 @@ rather than a `KeyError`. """ function build(name::Symbol, form::Symbol=:abstract; kwargs...) check_form(form) - haskey(_CONSTRUCTORS, name) || throw( - ArgumentError("unknown problem $(repr(name)); expected one of $(PROBLEMS)") - ) + haskey(_CONSTRUCTORS, name) || + throw(ArgumentError("unknown problem $(repr(name)); expected one of $(PROBLEMS)")) return _CONSTRUCTORS[name](form; kwargs...) end @@ -85,5 +84,4 @@ end Names only — cheaper than [`problems_for`](@ref) when the problems themselves are not needed (building them expands `@def`). """ -problem_names_for(method::Symbol) = - [pb.name for pb in problems_for(method)] +problem_names_for(method::Symbol) = [pb.name for pb in problems_for(method)] diff --git a/test/problems/transfer.jl b/test/problems/transfer.jl index 4a0e2297..c8266943 100644 --- a/test/problems/transfer.jl +++ b/test/problems/transfer.jl @@ -63,7 +63,11 @@ Return the orbital transfer problem as a [`TestProblem`](@ref). function Transfer(form::Symbol=:abstract; Tmax=60) check_form(form) return cached(:transfer, form, (Tmax,)) do - form === :abstract ? _transfer_abstract(; Tmax) : _transfer_functional(; Tmax) + return if form === :abstract + _transfer_abstract(; Tmax) + else + _transfer_functional(; Tmax) + end end end @@ -168,9 +172,7 @@ function _transfer_functional(; Tmax) ocp = CTModels.Building.build(pre) tf_i = 15 - init = ( - state=t -> x0 + (xf - x0) * t / tf_i, control=[0.1, 0.5, 0.0], variable=tf_i - ) + init = (state=t -> x0 + (xf - x0) * t / tf_i, control=[0.1, 0.5, 0.0], variable=tf_i) return TestProblem(:transfer, :functional, ocp, _TRANSFER_OBJ, init, c) end diff --git a/test/suite/builders/test_options_forwarding.jl b/test/suite/builders/test_options_forwarding.jl index 8fe663b3..b69ecba1 100644 --- a/test/suite/builders/test_options_forwarding.jl +++ b/test/suite/builders/test_options_forwarding.jl @@ -56,9 +56,7 @@ function test_options_forwarding() # shows up in the summary, a missing branch does not. Test.@testset "backend (CUDA)" begin gpu_x0_is_cuarray() = begin - modeler = OptimalControl.Exa{OptimalControl.GPU}( - backend=CUDA.CUDABackend() - ) + modeler = OptimalControl.Exa{OptimalControl.GPU}(backend=CUDA.CUDABackend()) nlp = OptimalControl.nlp_model(docp, normalized_init, modeler) # With CUDA backend, x0 should be a CUDA array nlp.meta.x0 isa CUDA.CuArray diff --git a/test/suite/flows/test_flow_api.jl b/test/suite/flows/test_flow_api.jl index 24b14e2c..5f01d381 100644 --- a/test/suite/flows/test_flow_api.jl +++ b/test/suite/flows/test_flow_api.jl @@ -42,12 +42,12 @@ function build_labelled() CTModels.Building.time!(pre; t0=T0, tf=TF) CTModels.Building.state!(pre, 2) CTModels.Building.control!(pre, 1) - CTModels.Building.dynamics!(pre, (r, t, x, u, v) -> (r[1] = x[2]; r[2] = u[1]; nothing)) + CTModels.Building.dynamics!(pre, (r, t, x, u, v) -> (r[1]=x[2]; r[2]=u[1]; nothing)) CTModels.Building.objective!(pre, :min; lagrange=(t, x, u, v) -> 0.5 * u[1]^2) CTModels.Building.constraint!( pre, :path; - f=(r, t, x, u, v) -> (r[1] = x[2]; nothing), + f=(r, t, x, u, v) -> (r[1]=x[2]; nothing), lb=[-Inf], ub=[VMAX], label=:vmax, @@ -71,7 +71,7 @@ function build_nonfixed() CTModels.Building.time!(pre; t0=T0, indf=1) CTModels.Building.state!(pre, 2) CTModels.Building.control!(pre, 1) - CTModels.Building.dynamics!(pre, (r, t, x, u, v) -> (r[1] = x[2]; r[2] = u[1]; nothing)) + CTModels.Building.dynamics!(pre, (r, t, x, u, v) -> (r[1]=x[2]; r[2]=u[1]; nothing)) CTModels.Building.objective!(pre, :min; mayer=(x0, xf, v) -> v[1]) CTModels.Building.time_dependence!(pre; autonomous=true) return CTModels.Building.build(pre) @@ -206,7 +206,9 @@ function test_flow_api() end Test.@testset "multiplier accepts a Data object" begin - f = Flow(ocp, (x, p) -> 0.0; constraint=:vmax, multiplier=Multiplier((x, p) -> p[1])) + f = Flow( + ocp, (x, p) -> 0.0; constraint=:vmax, multiplier=Multiplier((x, p) -> p[1]) + ) Test.@test f(T0, X0, P0, TF) isa Tuple end diff --git a/test/suite/flows/test_gpu_routing.jl b/test/suite/flows/test_gpu_routing.jl index 6559b8e7..ed285816 100644 --- a/test/suite/flows/test_gpu_routing.jl +++ b/test/suite/flows/test_gpu_routing.jl @@ -83,8 +83,13 @@ function test_gpu_routing() ) for (id, family) in ( - (:adnlp, M), (:exa, M), - (:ipopt, N), (:madnlp, N), (:uno, N), (:madncl, N), (:knitro, N), + (:adnlp, M), + (:exa, M), + (:ipopt, N), + (:madnlp, N), + (:uno, N), + (:madncl, N), + (:knitro, N), ) Test.@testset "$id" begin params = S.available_parameters(id, family, registry) @@ -149,9 +154,7 @@ function test_gpu_routing() end Test.@testset "an unknown method is rejected" begin - Test.@test_throws CTBase.Exceptions.CTException Flow( - vf(); method=:quantum - ) + Test.@test_throws CTBase.Exceptions.CTException Flow(vf(); method=:quantum) end end diff --git a/test/suite/helpers/test_describe.jl b/test/suite/helpers/test_describe.jl index 7a5c04a3..8b556a13 100644 --- a/test/suite/helpers/test_describe.jl +++ b/test/suite/helpers/test_describe.jl @@ -41,8 +41,13 @@ const S = CTBase.Strategies # Every strategy id OptimalControl registers, across both registries. const ALL_STRATEGIES = ( :collocation, # discretizer - :adnlp, :exa, # NLP modelers - :ipopt, :madnlp, :madncl, :uno, :knitro, # NLP solvers + :adnlp, + :exa, # NLP modelers + :ipopt, + :madnlp, + :madncl, + :uno, + :knitro, # NLP solvers :di, # AD backend :sciml, # ODE integrator ) @@ -82,9 +87,7 @@ function test_describe() flow_reg = CTFlows.Flows.flow_registry() Test.@test isempty(intersect(ids(solve_reg), ids(flow_reg))) - Test.@test isempty( - intersect(keys(solve_reg.families), keys(flow_reg.families)) - ) + Test.@test isempty(intersect(keys(solve_reg.families), keys(flow_reg.families))) # `:cpu`/`:gpu` exist on both sides; they must be the same types, # or the merge would silently pick one binding over the other. diff --git a/test/suite/helpers/test_kwarg_extraction.jl b/test/suite/helpers/test_kwarg_extraction.jl index dae02d0a..db400091 100644 --- a/test/suite/helpers/test_kwarg_extraction.jl +++ b/test/suite/helpers/test_kwarg_extraction.jl @@ -64,12 +64,15 @@ function test_kwarg_extraction() Test.@testset "Extracts all three component types" begin kw = pairs((; discretizer=DISC, modeler=MOD, solver=SOL, print_level=0)) - Test.@test OptimalControl._extract_kwarg(kw, CTSolvers.DOCP.AbstractDiscretizer) === - DISC - Test.@test OptimalControl._extract_kwarg(kw, CTSolvers.Modelers.AbstractNLPModeler) === - MOD - Test.@test OptimalControl._extract_kwarg(kw, CTSolvers.Solvers.AbstractNLPSolver) === - SOL + Test.@test OptimalControl._extract_kwarg( + kw, CTSolvers.DOCP.AbstractDiscretizer + ) === DISC + Test.@test OptimalControl._extract_kwarg( + kw, CTSolvers.Modelers.AbstractNLPModeler + ) === MOD + Test.@test OptimalControl._extract_kwarg( + kw, CTSolvers.Solvers.AbstractNLPSolver + ) === SOL end # ==================================================================== @@ -291,7 +294,9 @@ function test_kwarg_extraction() Test.@testset "Multiple matching types in kwargs" begin # Test when multiple instances of the same type are present kw = pairs((; discretizer=DISC, another_disc=DISC)) - result = OptimalControl._extract_kwarg(kw, CTSolvers.DOCP.AbstractDiscretizer) + result = OptimalControl._extract_kwarg( + kw, CTSolvers.DOCP.AbstractDiscretizer + ) Test.@test result === DISC # Should return the first match end @@ -299,7 +304,9 @@ function test_kwarg_extraction() # Test with more complex types kw = pairs((; discretizer=DISC, some_string="hello", some_number=42)) - result1 = OptimalControl._extract_kwarg(kw, CTSolvers.DOCP.AbstractDiscretizer) + result1 = OptimalControl._extract_kwarg( + kw, CTSolvers.DOCP.AbstractDiscretizer + ) result2 = OptimalControl._extract_kwarg(kw, String) result3 = OptimalControl._extract_kwarg(kw, Int) @@ -352,7 +359,9 @@ function test_kwarg_extraction() # Extract components disc = OptimalControl._extract_kwarg(kw, CTSolvers.DOCP.AbstractDiscretizer) - mod = OptimalControl._extract_kwarg(kw, CTSolvers.Modelers.AbstractNLPModeler) + mod = OptimalControl._extract_kwarg( + kw, CTSolvers.Modelers.AbstractNLPModeler + ) sol = OptimalControl._extract_kwarg(kw, CTSolvers.Solvers.AbstractNLPSolver) Test.@test disc === DISC @@ -381,7 +390,9 @@ function test_kwarg_extraction() )) disc = OptimalControl._extract_kwarg(kw, CTSolvers.DOCP.AbstractDiscretizer) - mod = OptimalControl._extract_kwarg(kw, CTSolvers.Modelers.AbstractNLPModeler) + mod = OptimalControl._extract_kwarg( + kw, CTSolvers.Modelers.AbstractNLPModeler + ) sol = OptimalControl._extract_kwarg(kw, CTSolvers.Solvers.AbstractNLPSolver) Test.@test isnothing(disc) diff --git a/test/suite/helpers/test_registry.jl b/test/suite/helpers/test_registry.jl index 20e4aa39..a2c54b42 100644 --- a/test/suite/helpers/test_registry.jl +++ b/test/suite/helpers/test_registry.jl @@ -31,14 +31,18 @@ function test_registry() Test.@testset "Discretizer Family" begin registry = OptimalControl.get_strategy_registry() - ids = CTBase.Strategies.strategy_ids(CTSolvers.DOCP.AbstractDiscretizer, registry) + ids = CTBase.Strategies.strategy_ids( + CTSolvers.DOCP.AbstractDiscretizer, registry + ) Test.@test :collocation in ids Test.@test length(ids) >= 1 end Test.@testset "Modeler Family" begin registry = OptimalControl.get_strategy_registry() - ids = CTBase.Strategies.strategy_ids(CTSolvers.Modelers.AbstractNLPModeler, registry) + ids = CTBase.Strategies.strategy_ids( + CTSolvers.Modelers.AbstractNLPModeler, registry + ) Test.@test :adnlp in ids Test.@test :exa in ids Test.@test length(ids) == 2 @@ -46,7 +50,9 @@ function test_registry() Test.@testset "Solver Family" begin registry = OptimalControl.get_strategy_registry() - ids = CTBase.Strategies.strategy_ids(CTSolvers.Solvers.AbstractNLPSolver, registry) + ids = CTBase.Strategies.strategy_ids( + CTSolvers.Solvers.AbstractNLPSolver, registry + ) Test.@test :ipopt in ids Test.@test :madnlp in ids Test.@test :uno in ids @@ -218,12 +224,16 @@ function test_registry() Test.@test :collocation in discretizer_ids # Test modeler parameter support - modeler_ids = CTBase.Strategies.strategy_ids(CTSolvers.Modelers.AbstractNLPModeler, registry) + modeler_ids = CTBase.Strategies.strategy_ids( + CTSolvers.Modelers.AbstractNLPModeler, registry + ) Test.@test :adnlp in modeler_ids # CPU-only Test.@test :exa in modeler_ids # CPU+GPU # Test solver parameter support - solver_ids = CTBase.Strategies.strategy_ids(CTSolvers.Solvers.AbstractNLPSolver, registry) + solver_ids = CTBase.Strategies.strategy_ids( + CTSolvers.Solvers.AbstractNLPSolver, registry + ) Test.@test :ipopt in solver_ids # CPU-only Test.@test :madnlp in solver_ids # CPU+GPU Test.@test :uno in solver_ids # CPU-only @@ -238,8 +248,12 @@ function test_registry() discretizer_ids = CTBase.Strategies.strategy_ids( CTSolvers.DOCP.AbstractDiscretizer, registry ) - modeler_ids = CTBase.Strategies.strategy_ids(CTSolvers.Modelers.AbstractNLPModeler, registry) - solver_ids = CTBase.Strategies.strategy_ids(CTSolvers.Solvers.AbstractNLPSolver, registry) + modeler_ids = CTBase.Strategies.strategy_ids( + CTSolvers.Modelers.AbstractNLPModeler, registry + ) + solver_ids = CTBase.Strategies.strategy_ids( + CTSolvers.Solvers.AbstractNLPSolver, registry + ) # Test that each family has strategies Test.@test length(discretizer_ids) >= 1 @@ -333,8 +347,12 @@ function test_registry() ) Test.@test modeler_ids1 == modeler_ids2 - solver_ids1 = CTBase.Strategies.strategy_ids(CTSolvers.Solvers.AbstractNLPSolver, registry1) - solver_ids2 = CTBase.Strategies.strategy_ids(CTSolvers.Solvers.AbstractNLPSolver, registry2) + solver_ids1 = CTBase.Strategies.strategy_ids( + CTSolvers.Solvers.AbstractNLPSolver, registry1 + ) + solver_ids2 = CTBase.Strategies.strategy_ids( + CTSolvers.Solvers.AbstractNLPSolver, registry2 + ) Test.@test solver_ids1 == solver_ids2 end @@ -381,8 +399,12 @@ function test_registry() discretizer_ids = CTBase.Strategies.strategy_ids( CTSolvers.DOCP.AbstractDiscretizer, registry ) - modeler_ids = CTBase.Strategies.strategy_ids(CTSolvers.Modelers.AbstractNLPModeler, registry) - solver_ids = CTBase.Strategies.strategy_ids(CTSolvers.Solvers.AbstractNLPSolver, registry) + modeler_ids = CTBase.Strategies.strategy_ids( + CTSolvers.Modelers.AbstractNLPModeler, registry + ) + solver_ids = CTBase.Strategies.strategy_ids( + CTSolvers.Solvers.AbstractNLPSolver, registry + ) Test.@test length(discretizer_ids) >= 1 Test.@test length(modeler_ids) >= 1 diff --git a/test/suite/indirect/test_shooting_sweep.jl b/test/suite/indirect/test_shooting_sweep.jl index 8cd5ae7b..ae70ef3d 100644 --- a/test/suite/indirect/test_shooting_sweep.jl +++ b/test/suite/indirect/test_shooting_sweep.jl @@ -48,7 +48,8 @@ const VERBOSE = isdefined(Main, :TestOptions) ? Main.TestOptions.VERBOSE : true const SHOWTIMING = isdefined(Main, :TestOptions) ? Main.TestOptions.SHOWTIMING : true function test_shooting_sweep() - Test.@testset "Shooting sweep (indirect fixtures)" verbose = VERBOSE showtiming = SHOWTIMING begin + Test.@testset "Shooting sweep (indirect fixtures)" verbose = VERBOSE showtiming = + SHOWTIMING begin for form in TestProblems.FORMS Test.@testset "$form" begin for pb in TestProblems.problems_for(:indirect, form) diff --git a/test/suite/problems/test_forms_equivalent.jl b/test/suite/problems/test_forms_equivalent.jl index 03f6ddff..e6522cc7 100644 --- a/test/suite/problems/test_forms_equivalent.jl +++ b/test/suite/problems/test_forms_equivalent.jl @@ -109,8 +109,7 @@ function test_forms_equivalent() t, x, u, v = sample_point(a) if is_lagrange_cost_defined(a.ocp) - Test.@test lagrange(a.ocp)(t, x, u, v) ≈ - lagrange(f.ocp)(t, x, u, v) + Test.@test lagrange(a.ocp)(t, x, u, v) ≈ lagrange(f.ocp)(t, x, u, v) end if is_mayer_cost_defined(a.ocp) Test.@test mayer(a.ocp)(x, x, v) ≈ mayer(f.ocp)(x, x, v) diff --git a/test/suite/reexport/test_ctbase.jl b/test/suite/reexport/test_ctbase.jl index 3a81c8a2..6a754552 100644 --- a/test/suite/reexport/test_ctbase.jl +++ b/test/suite/reexport/test_ctbase.jl @@ -327,7 +327,8 @@ function test_ctbase() # `value` and `name` are genuine homonyms across CTBase.Options # and CTModels.Components. `name` goes to CTModels (§8); # `value` is internal on both sides and exported by neither. - Test.@test getfield(OptimalControl, :name) !== getfield(CTBase.Options, :name) + Test.@test getfield(OptimalControl, :name) !== + getfield(CTBase.Options, :name) Test.@test !is_exported(OptimalControl, :value) # `description` is a homonym across Options and Strategies. Test.@test !is_exported(OptimalControl, :description) diff --git a/test/suite/reexport/test_ctdirect.jl b/test/suite/reexport/test_ctdirect.jl index 289ff6e4..ecbf2b3a 100644 --- a/test/suite/reexport/test_ctdirect.jl +++ b/test/suite/reexport/test_ctdirect.jl @@ -36,8 +36,7 @@ function test_ctdirect() Test.@testset "Ownership after the move" begin # The abstraction belongs to CTSolvers now… - Test.@test parentmodule(OptimalControl.AbstractDiscretizer) === - CTSolvers.DOCP + Test.@test parentmodule(OptimalControl.AbstractDiscretizer) === CTSolvers.DOCP Test.@test parentmodule(discretize) === CTSolvers.DOCP # …and CTDirect implements it. Test.@test OptimalControl.Collocation <: OptimalControl.AbstractDiscretizer @@ -46,8 +45,7 @@ function test_ctdirect() Test.@testset "Method Signatures" begin Test.@test hasmethod( - discretize, - Tuple{OptimalControl.AbstractModel,OptimalControl.Collocation}, + discretize, Tuple{OptimalControl.AbstractModel,OptimalControl.Collocation} ) end diff --git a/test/suite/reexport/test_ctflows.jl b/test/suite/reexport/test_ctflows.jl index 576892d9..a91ed96e 100644 --- a/test/suite/reexport/test_ctflows.jl +++ b/test/suite/reexport/test_ctflows.jl @@ -82,14 +82,13 @@ function test_ctflows() Test.@testset "$T" begin Test.@test isdefined(OptimalControl, T) Test.@test is_exported(OptimalControl, T) - Test.@test getfield(OptimalControl, T) === getfield(CTFlows.MultiPhase, T) + Test.@test getfield(OptimalControl, T) === + getfield(CTFlows.MultiPhase, T) end end # `*` concatenates flows. It is `Base.:*`, extended by MultiPhase, # so it needs no re-export of its own — but the method must exist. - Test.@test any( - m -> parentmodule(m) === CTFlows.MultiPhase, methods(*) - ) + Test.@test any(m -> parentmodule(m) === CTFlows.MultiPhase, methods(*)) end Test.@testset "Moved away from CTFlows" begin diff --git a/test/suite/reexport/test_ctlie.jl b/test/suite/reexport/test_ctlie.jl index 17dd2467..d6ead3e6 100644 --- a/test/suite/reexport/test_ctlie.jl +++ b/test/suite/reexport/test_ctlie.jl @@ -140,7 +140,8 @@ function test_ctlie() X1 = VectorField(x -> [x[2], -x[1]]) X2 = VectorField(x -> [x[1], x[2]]) Test.@test (@Lie [X1, X2]) isa VectorField - Test.@test (@Lie [[X1, X2], VectorField(x -> [2x[1], 3x[2]])]) isa VectorField + Test.@test (@Lie [[X1, X2], VectorField(x -> [2x[1], 3x[2]])]) isa + VectorField H1 = Hamiltonian((x, p) -> x[1] * p[1]) H2 = Hamiltonian((x, p) -> x[2] * p[2]) @@ -196,7 +197,8 @@ function test_ctlie() # deferred through `Core.eval` — writing it inline would break # the whole file at load. Test.@test_throws OptimalControl.IncorrectArgument Core.eval( - CurrentModule, :(OptimalControl.@Lie [LIE_X1, LIE_X2] autonomous = false) + CurrentModule, + :(OptimalControl.@Lie [LIE_X1, LIE_X2] autonomous = false), ) end end diff --git a/test/suite/reexport/test_ctmodels.jl b/test/suite/reexport/test_ctmodels.jl index 075d962f..baea935f 100644 --- a/test/suite/reexport/test_ctmodels.jl +++ b/test/suite/reexport/test_ctmodels.jl @@ -251,9 +251,7 @@ function test_ctmodels() Test.@test !isdefined(CTModels, :time) || getfield(CTModels, :time) === Base.time # The extension itself must still be there. - Test.@test any( - m -> parentmodule(m) === CTModels.Components, methods(Base.time) - ) + Test.@test any(m -> parentmodule(m) === CTModels.Components, methods(Base.time)) end Test.@testset "traits live in CTBase now" begin @@ -277,7 +275,9 @@ function test_ctmodels() ) end Test.@testset "import_ocp_solution" begin - Test.@test hasmethod(import_ocp_solution, Tuple{OptimalControl.AbstractModel}) + Test.@test hasmethod( + import_ocp_solution, Tuple{OptimalControl.AbstractModel} + ) end end end diff --git a/test/suite/shape/test_shape_contract.jl b/test/suite/shape/test_shape_contract.jl index 06f64a95..fd6d3779 100644 --- a/test/suite/shape/test_shape_contract.jl +++ b/test/suite/shape/test_shape_contract.jl @@ -44,18 +44,20 @@ const SEEN = Dict{Symbol,Any}() # Written with `[1]`-indexing so the fakes are valid whether the caller hands a # Number or a length-1 vector — only the *assertions* below distinguish the # two. Writing them scalar-style would beg the question. -rec_dyn!(r, t, x, u, v) = ( - SEEN[:dyn] = (x, u, v); - for i in eachindex(r) - r[i] = -x[i] + u[min(i, length(u))] - end; - nothing -) +function rec_dyn!(r, t, x, u, v) + return ( + SEEN[:dyn]=(x, u, v); + for i in eachindex(r) + r[i] = -x[i] + u[min(i, length(u))] + end; + nothing + ) +end -rec_lagrange(t, x, u, v) = (SEEN[:lag] = (x, u, v); sum(abs2, u)) +rec_lagrange(t, x, u, v) = (SEEN[:lag]=(x, u, v); sum(abs2, u)) rec_boundary!(r, x0, xf, v) = ( - SEEN[:bnd] = (x0, xf, v); + SEEN[:bnd]=(x0, xf, v); for i in eachindex(r) r[i] = x0[i] - 1.0 end; diff --git a/test/suite/solve/test_bypass.jl b/test/suite/solve/test_bypass.jl index 3fb466b8..0ec3aa49 100644 --- a/test/suite/solve/test_bypass.jl +++ b/test/suite/solve/test_bypass.jl @@ -164,7 +164,9 @@ function test_bypass() initial_guess=init, display=false, registry=registry, - unknown_opt=CTBase.Strategies.route_to(ipopt=CTBase.Strategies.bypass(42)), + unknown_opt=CTBase.Strategies.route_to( + ipopt=CTBase.Strategies.bypass(42) + ), ) Test.@test sol isa MockBypassSolution # The bypassed option should be inside the solver's options @@ -183,11 +185,14 @@ function test_bypass() initial_guess=init, display=false, registry=registry, - disc_custom=CTBase.Strategies.route_to(collocation=CTBase.Strategies.bypass(:fine)), + disc_custom=CTBase.Strategies.route_to( + collocation=CTBase.Strategies.bypass(:fine) + ), ) Test.@test sol isa MockBypassSolution Test.@test CTBase.Strategies.has_option(sol.discretizer, :disc_custom) - Test.@test CTBase.Strategies.option_value(sol.discretizer, :disc_custom) == :fine + Test.@test CTBase.Strategies.option_value(sol.discretizer, :disc_custom) == + :fine end Test.@testset "Bypass on modeler" begin @@ -199,11 +204,14 @@ function test_bypass() initial_guess=init, display=false, registry=registry, - mod_custom=CTBase.Strategies.route_to(adnlp=CTBase.Strategies.bypass("sparse_mode")), + mod_custom=CTBase.Strategies.route_to( + adnlp=CTBase.Strategies.bypass("sparse_mode") + ), ) Test.@test sol isa MockBypassSolution Test.@test CTBase.Strategies.has_option(sol.modeler, :mod_custom) - Test.@test CTBase.Strategies.option_value(sol.modeler, :mod_custom) == "sparse_mode" + Test.@test CTBase.Strategies.option_value(sol.modeler, :mod_custom) == + "sparse_mode" end Test.@testset "Multi-bypass: two strategies simultaneously" begin @@ -216,14 +224,16 @@ function test_bypass() display=false, registry=registry, shared_opt=CTBase.Strategies.route_to( - ipopt=CTBase.Strategies.bypass(100), adnlp=CTBase.Strategies.bypass(:dense) + ipopt=CTBase.Strategies.bypass(100), + adnlp=CTBase.Strategies.bypass(:dense), ), ) Test.@test sol isa MockBypassSolution Test.@test CTBase.Strategies.has_option(sol.solver, :shared_opt) Test.@test CTBase.Strategies.option_value(sol.solver, :shared_opt) == 100 Test.@test CTBase.Strategies.has_option(sol.modeler, :shared_opt) - Test.@test CTBase.Strategies.option_value(sol.modeler, :shared_opt) == :dense + Test.@test CTBase.Strategies.option_value(sol.modeler, :shared_opt) == + :dense end Test.@testset "Bypass with nothing value" begin @@ -235,11 +245,15 @@ function test_bypass() initial_guess=init, display=false, registry=registry, - nullable_opt=CTBase.Strategies.route_to(ipopt=CTBase.Strategies.bypass(nothing)), + nullable_opt=CTBase.Strategies.route_to( + ipopt=CTBase.Strategies.bypass(nothing) + ), ) Test.@test sol isa MockBypassSolution Test.@test CTBase.Strategies.has_option(sol.solver, :nullable_opt) - Test.@test isnothing(CTBase.Strategies.option_value(sol.solver, :nullable_opt)) + Test.@test isnothing( + CTBase.Strategies.option_value(sol.solver, :nullable_opt) + ) end end @@ -260,7 +274,8 @@ function test_bypass() ) Test.@test sol isa MockBypassSolution Test.@test CTBase.Strategies.has_option(sol.solver, :unknown_opt) - Test.@test CTBase.Strategies.option_value(sol.solver, :unknown_opt) == "passed" + Test.@test CTBase.Strategies.option_value(sol.solver, :unknown_opt) == + "passed" end end @@ -276,11 +291,15 @@ function test_bypass() :ipopt; display=false, registry=registry, - custom_backend_opt=CTBase.Strategies.route_to(ipopt=CTBase.Strategies.bypass(99)), + custom_backend_opt=CTBase.Strategies.route_to( + ipopt=CTBase.Strategies.bypass(99) + ), ) Test.@test sol isa MockBypassSolution Test.@test CTBase.Strategies.has_option(sol.solver, :custom_backend_opt) - Test.@test CTBase.Strategies.option_value(sol.solver, :custom_backend_opt) == 99 + Test.@test CTBase.Strategies.option_value( + sol.solver, :custom_backend_opt + ) == 99 end Test.@testset "Explicit via solve" begin @@ -295,7 +314,9 @@ function test_bypass() ) Test.@test sol isa MockBypassSolution Test.@test CTBase.Strategies.has_option(sol.solver, :custom_backend_opt) - Test.@test CTBase.Strategies.option_value(sol.solver, :custom_backend_opt) == 99 + Test.@test CTBase.Strategies.option_value( + sol.solver, :custom_backend_opt + ) == 99 end end end diff --git a/test/suite/solve/test_canonical.jl b/test/suite/solve/test_canonical.jl index 87c719dd..64fe4737 100644 --- a/test/suite/solve/test_canonical.jl +++ b/test/suite/solve/test_canonical.jl @@ -124,9 +124,11 @@ function run_test( Test.@test solve_result isa OptimalControl.AbstractSolution # Use absolute tolerance when reference objective is near zero if abs(pb.objective) < 1e-6 - Test.@test OptimalControl.objective(solve_result) ≈ pb.objective atol = OBJ_ATOL + Test.@test OptimalControl.objective(solve_result) ≈ pb.objective atol = + OBJ_ATOL else - Test.@test OptimalControl.objective(solve_result) ≈ pb.objective rtol = OBJ_RTOL + Test.@test OptimalControl.objective(solve_result) ≈ pb.objective rtol = + OBJ_RTOL end end end diff --git a/test/suite/solve/test_descriptive.jl b/test/suite/solve/test_descriptive.jl index 10542eb5..0a395668 100644 --- a/test/suite/solve/test_descriptive.jl +++ b/test/suite/solve/test_descriptive.jl @@ -114,7 +114,8 @@ function test_descriptive() ) Test.@test result isa CTModels.AbstractSolution Test.@test OptimalControl.successful(result) - Test.@test OptimalControl.objective(result) ≈ TestProblems.Goddard().objective rtol=1e-2 + Test.@test OptimalControl.objective(result) ≈ + TestProblems.Goddard().objective rtol=1e-2 end Test.@testset "Partial description - Goddard" begin @@ -137,7 +138,8 @@ function test_descriptive() ) Test.@test result isa CTModels.AbstractSolution Test.@test OptimalControl.successful(result) - Test.@test OptimalControl.objective(result) ≈ TestProblems.Goddard().objective rtol=1e-2 + Test.@test OptimalControl.objective(result) ≈ + TestProblems.Goddard().objective rtol=1e-2 end end diff --git a/test/suite/solve/test_descriptive_routing.jl b/test/suite/solve/test_descriptive_routing.jl index adbdef47..5743c477 100644 --- a/test/suite/solve/test_descriptive_routing.jl +++ b/test/suite/solve/test_descriptive_routing.jl @@ -54,9 +54,7 @@ CTBase.Strategies.options(s::MockCollocation) = s.options CTBase.Strategies.parameter(::Type{<:MockCollocation}) = nothing function MockCollocation(; mode::Symbol=:strict, kwargs...) - opts = CTBase.Strategies.build_strategy_options( - MockCollocation; mode=mode, kwargs... - ) + opts = CTBase.Strategies.build_strategy_options(MockCollocation; mode=mode, kwargs...) return MockCollocation(opts) end @@ -294,7 +292,8 @@ function test_descriptive_routing() ocp, MOCK_METHOD, MOCK_REGISTRY, routed ) - Test.@test CTBase.Strategies.option_value(components.discretizer, :grid_size) == 42 + Test.@test CTBase.Strategies.option_value(components.discretizer, :grid_size) == + 42 Test.@test CTBase.Strategies.option_value(components.solver, :max_iter) == 7 end @@ -309,7 +308,8 @@ function test_descriptive_routing() ocp, MOCK_METHOD, MOCK_REGISTRY, routed ) - Test.@test CTBase.Strategies.option_value(components.modeler, :backend) === :sparse + Test.@test CTBase.Strategies.option_value(components.modeler, :backend) === + :sparse Test.@test CTBase.Strategies.option_value(components.solver, :backend) === :gpu end @@ -445,7 +445,9 @@ function test_descriptive_routing() Test.@testset "Parameter Resolution" begin # Test that parameter information is correctly resolved families = OptimalControl._descriptive_families() - resolved = CTBase.Orchestration.resolve_method(MOCK_METHOD, families, MOCK_REGISTRY) + resolved = CTBase.Orchestration.resolve_method( + MOCK_METHOD, families, MOCK_REGISTRY + ) Test.@test resolved isa CTBase.Orchestration.ResolvedMethod # Parameter might be nothing if not explicitly supported by mocks diff --git a/test/suite/solve/test_dispatch.jl b/test/suite/solve/test_dispatch.jl index bbbabffc..1a1a1013 100644 --- a/test/suite/solve/test_dispatch.jl +++ b/test/suite/solve/test_dispatch.jl @@ -41,9 +41,7 @@ CTBase.Strategies.options(d::MockDiscretizer) = d.options # generic throws `NotImplemented` by default, unlike the old `get_parameter_type`). CTBase.Strategies.parameter(::Type{<:MockDiscretizer}) = nothing function MockDiscretizer(; mode::Symbol=:strict, kwargs...) - opts = CTBase.Strategies.build_strategy_options( - MockDiscretizer; mode=mode, kwargs... - ) + opts = CTBase.Strategies.build_strategy_options(MockDiscretizer; mode=mode, kwargs...) return MockDiscretizer(opts) end diff --git a/test/suite/solve/test_dispatch_logic.jl b/test/suite/solve/test_dispatch_logic.jl index 56a0d5c9..7d4032ad 100644 --- a/test/suite/solve/test_dispatch_logic.jl +++ b/test/suite/solve/test_dispatch_logic.jl @@ -107,9 +107,7 @@ function MockDiscretizer{ID}(; mode::Symbol=:strict, kwargs...) where {ID} end function MockModeler{ID}(; mode::Symbol=:strict, kwargs...) where {ID} - opts = CTBase.Strategies.build_strategy_options( - MockModeler{ID}; mode=mode, kwargs... - ) + opts = CTBase.Strategies.build_strategy_options(MockModeler{ID}; mode=mode, kwargs...) return MockModeler{ID}(opts) end