Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Optimization kwarg autoad to adtype #2168

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

ElOceanografo
Copy link
Contributor

Changing the name of this keyword argument to optim_problem and related functions from autoad to adtype, so that it matches the interface used for constructing samplers and in Optimization.jl.

In addition to just making things more consistent, this also fixes a bug where adtype is mistaken for a generic kwarg and ends up passed to Optim.Options, where it causes an error:

# Turing v0.30.3
using Turing
using Optimization, OptimizationOptimJL
using ReverseDiff

@model function example(x, y)
    a ~ Normal()
    b ~ Normal()
    σ ~ Gamma()

    μ = a .+ b .* x
    y ~ MvNormal(μ, σ)
end

x = rand(10)
y = 1 .+ 2x + randn(10)

m = example(x, y)
prob = optim_problem(m, MAP(), adtype=AutoReverseDiff())
solve(prob.prob, LBFGS())

ERROR: MethodError: no method matching Optim.Options(; extended_trace::Bool, adtype::AutoReverseDiff, callback::OptimizationOptimJL.var"#_cb#12"{})

Closest candidates are:
  Optim.Options(; x_tol, f_tol, g_tol, x_abstol, x_reltol, f_abstol, f_reltol, g_abstol, g_reltol, outer_x_tol, outer_f_tol, outer_g_tol, outer_x_abstol, outer_x_reltol, outer_f_abstol, outer_f_reltol, outer_g_abstol, outer_g_reltol, f_calls_limit, g_calls_limit, h_calls_limit, allow_f_increases, allow_outer_f_increases, successive_f_tol, iterations, outer_iterations, store_trace, trace_simplex, show_trace, extended_trace, show_warnings, show_every, callback, time_limit) got unsupported keyword argument "adtype"
   @ Optim C:\Users\...\.julia\packages\Optim\EJwLF\src\types.jl:75
  Optim.Options(::T, ::T, ::T, ::T, ::T, ::T, ::T, ::T, ::T, ::T, ::T, ::T, ::Int64, ::Int64, ::Int64, ::Bool, ::Bool, ::Int64, ::Int64, ::Int64, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Int64, ::TCallback, ::Float64) where {T, TCallback} got unsupported keyword arguments "extended_trace", "adtype", "callback"
   @ Optim C:\Users\...\.julia\packages\Optim\EJwLF\src\types.jl:45

Stacktrace:
 [1] kwerr(kw::@NamedTuple{}, args::Type)
   @ Base .\error.jl:165
 [2] __map_optimizer_args(cache::OptimizationCache{…}, opt::LBFGS{…}; callback::Function, maxiters::Nothing, local_maxiters::Nothing, maxtime::Nothing, abstol::Nothing, reltol::Nothing, kwargs::@Kwargs{})
   @ OptimizationOptimJL C:\Users\...\.julia\packages\OptimizationOptimJL\yMF3E\src\OptimizationOptimJL.jl:65
 [3] __solve(cache::OptimizationCache{…})
   @ OptimizationOptimJL C:\Users\...\.julia\packages\OptimizationOptimJL\yMF3E\src\OptimizationOptimJL.jl:204
 [4] solve!(cache::OptimizationCache{…})
   @ SciMLBase C:\Users\...\.julia\packages\SciMLBase\OK4PC\src\solve.jl:179
 [5] solve(::OptimizationProblem{…}, ::LBFGS{…}; kwargs::@Kwargs{})
   @ SciMLBase C:\Users\...\.julia\packages\SciMLBase\OK4PC\src\solve.jl:96
 [6] solve(::OptimizationProblem{…}, ::LBFGS{…})
   @ SciMLBase C:\Users\...\.julia\packages\SciMLBase\OK4PC\src\solve.jl:93

Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me. Can you also add a test for the bugfix?

Copy link

codecov bot commented Feb 14, 2024

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (39f5d5b) 0.00% compared to head (bd8cbff) 0.00%.
Report is 1 commits behind head on master.

Files Patch % Lines
src/optimisation/Optimisation.jl 0.00% 5 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##           master   #2168   +/-   ##
======================================
  Coverage    0.00%   0.00%           
======================================
  Files          22      22           
  Lines        1386    1386           
======================================
  Misses       1386    1386           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 7811167391

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • -5 of 5 (0.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 0.0%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/optimisation/Optimisation.jl 0 5 0.0%
Totals Coverage Status
Change from base Build 7687829147: 0.0%
Covered Lines: 0
Relevant Lines: 1386

💛 - Coveralls

@yebai yebai merged commit 93d3114 into TuringLang:master Feb 15, 2024
13 checks passed
@yebai
Copy link
Member

yebai commented Feb 15, 2024

Thanks @ElOceanografo and @devmotion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants