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

Exception thrown by objective function is not rethrown by nlopt #156

Closed
ikirill opened this issue Jan 22, 2021 · 1 comment · Fixed by #194
Closed

Exception thrown by objective function is not rethrown by nlopt #156

ikirill opened this issue Jan 22, 2021 · 1 comment · Fixed by #194

Comments

@ikirill
Copy link
Contributor

ikirill commented Jan 22, 2021

The following test fails for me using ] dev NLopt. I expected the exception from within obj to be rethrown to the called on NLopt.optimize

using Test

x0 = [0.5,0.7]
obj(x) = (error("test"); dot(x,x))
opt = NLopt.Opt(:LN_SBPLX, length(x0))
opt.lower_bounds = [-1,-1]
opt.upper_bounds = [1,1]
opt.min_objective=obj

# @show NLopt.optimize(opt, x0)
@test_throws ErrorException NLopt.optimize(opt, x0)
Test Failed at /home/kirill/Sandboxes/SportsModelling/test/nlopt_exceptions.jl:11
  Expression: NLopt.optimize(opt, x0)
    Expected: ErrorException
  No exception thrown

Instead optimize returns:

NLopt.optimize(opt, x0) = (0.0, [0.5, 0.7], :FORCED_STOP)
julia> versioninfo()
Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: AMD Ryzen 7 3700X 8-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, znver2)

(@v1.5) pkg> status
Status `~/.julia/environments/v1.5/Project.toml`
  [764a87c0] BoundaryValueDiffEq v2.7.0
  [336ed68f] CSV v0.8.2
  [a2cac450] ColorBrewer v0.4.0
  [5ae59095] Colors v0.12.6
  [a93c6f00] DataFrames v0.22.2
  [0c46a032] DifferentialEquations v6.16.0
  [31c24e10] Distributions v0.24.10
  [442a2c76] FastGaussQuadrature v0.4.4
  [53c48c17] FixedPointNumbers v0.8.4
  [28b8d3ca] GR v0.53.0
  [cc18c42c] GaussianMixtures v0.3.4
  [7073ff75] IJulia v1.23.1
  [82e4d734] ImageIO v0.4.1
  [6218d12a] ImageMagick v1.1.6
  [02fcd773] ImageTransformations v0.8.8
  [916415d5] Images v0.23.3
  [a98d9a8b] Interpolations v0.13.1
  [76087f3c] NLopt v0.6.2 `~/.julia/dev/NLopt`
  [9b87118b] PackageCompiler v1.2.3
  [91a5bcdd] Plots v1.10.1
  [1fd47b50] QuadGK v2.4.1
  [295af30f] Revise v3.1.9
  [2913bbd2] StatsBase v0.33.2
  [bd369af6] Tables v1.2.2
@ikirill
Copy link
Contributor Author

ikirill commented Jan 22, 2021

Quote from readme:

You can do this by throwing any exception inside your objective/constraint functions: the optimization will be halted gracefully, and the same exception will be thrown to the caller.

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

Successfully merging a pull request may close this issue.

1 participant