Skip to content

Commit

Permalink
Add AutomaticDifferentiationBackend (#2386)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Jan 4, 2024
1 parent ea5f1a6 commit 9ae1a89
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/src/manual/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ The following attributes are available:
* [`ObjectiveFunction`](@ref)
* [`ObjectiveFunctionType`](@ref)
* [`ObjectiveSense`](@ref)

## AbstractOptimizer API

The following attributes are available:
Expand All @@ -104,3 +105,4 @@ The following attributes are available:
* [`TimeLimitSec`](@ref)
* [`ObjectiveLimit`](@ref)
* [`SolutionLimit`](@ref)
* [`AutomaticDifferentiationBackend`](@ref)
1 change: 1 addition & 0 deletions docs/src/reference/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ NumberOfThreads
RawSolver
AbsoluteGapTolerance
RelativeGapTolerance
AutomaticDifferentiationBackend
```

List of attributes useful for optimizers
Expand Down
14 changes: 14 additions & 0 deletions src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,20 @@ struct ListOfSupportedNonlinearOperators <: AbstractOptimizerAttribute end
OTHER_ERROR,
)

"""
AutomaticDifferentiationBackend() <: AbstractOptimizerAttribute
An [`AbstractOptimizerAttribute`](@ref) for setting the automatic differentiation
backend used by the solver.
The value must be a subtype of [`Nonlinear.AbstractAutomaticDifferentiation`](@ref).
"""
struct AutomaticDifferentiationBackend <: AbstractOptimizerAttribute end

function attribute_value_type(::AutomaticDifferentiationBackend)
return Nonlinear.AbstractAutomaticDifferentiation
end

"""
TerminationStatus()
Expand Down
6 changes: 6 additions & 0 deletions test/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ function test_scalar_nonlinear_function_set_objective()
return
end

function test_attributes_AutomaticDifferentiationBackend()
@test MOI.attribute_value_type(MOI.AutomaticDifferentiationBackend()) ==
MOI.Nonlinear.AbstractAutomaticDifferentiation
return
end

function runtests()
for name in names(@__MODULE__; all = true)
if startswith("$name", "test_")
Expand Down

0 comments on commit 9ae1a89

Please sign in to comment.