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

Possible post optimization error when using a locale with a comma as floating point #99

Open
PierreMartinon opened this issue May 27, 2024 · 4 comments
Assignees

Comments

@PierreMartinon
Copy link
Member

PierreMartinon commented May 27, 2024

Sample case

using CTDirect
using QML
include("ocp.jl")
sol = solve(ocp1)

The problem is solved correctly but an error occurs after the optimization

Total seconds in IPOPT                               = 1,618

EXIT: Optimal Solution Found.
ERROR: LoadError: MethodError: no method matching +(::Float64, ::Expr)

Closest candidates are:
  +(::Any, ::Any, ::Any, ::Any...)
   @ Base operators.jl:587
  +(::AbstractFloat, ::ForwardDiff.Dual{Ty}) where Ty
   @ ForwardDiff ~/.julia/packages/ForwardDiff/PcZ48/src/dual.jl:145
  +(::AbstractFloat, ::ReverseDiff.TrackedReal)
   @ ReverseDiff ~/.julia/packages/ReverseDiff/p1MzG/src/derivatives/scalars.jl:18
  ...

Stacktrace:
  [1] solve!(solver::NLPModelsIpopt.IpoptSolver, nlp::ADNLPModels.ADNLPModel{…}, stats::SolverCore.GenericExecutionStats{…}; callback::Function, kwargs::@Kwargs{…})
    @ NLPModelsIpopt ~/.julia/packages/NLPModelsIpopt/0YgvC/src/NLPModelsIpopt.jl:249
  [2] solve!
    @ ~/.julia/packages/NLPModelsIpopt/0YgvC/src/NLPModelsIpopt.jl:161 [inlined]
  [3] #ipopt#6
    @ ~/.julia/packages/NLPModelsIpopt/0YgvC/src/NLPModelsIpopt.jl:158 [inlined]
  [4] solve(docp::CTDirect.DOCP; init::Nothing, display::Bool, print_level::Int64, mu_strategy::String, kwargs::@Kwargs{})
    @ CTDirect ~/.julia/packages/CTDirect/wWLhZ/src/solve.jl:96

Removing the using other than CTDirect removes the error.
Same with using Mousetrap. Adding the other 'using' directives present in CTDirect, or changing the order of the using directives, does not change the problem.

@PierreMartinon
Copy link
Member Author

PierreMartinon commented May 27, 2024

Tracking the error in NLPModelsIpopt.jl l.249

ipopt_output = readlines(ipopt_log_file)
Δt = 0.0
...
for line in ipopt_output
	if occursin("Total seconds", line)
		Δt += Meta.parse(split(line, "=")[2])

So the result of Meta.parse would be Expr instead of a Float ?
Does something in CTDirect.jl (or CTBase) mess up with the julia parser ?
Same error with ocp defined in non-abstract mode

@PierreMartinon
Copy link
Member Author

More tests: works fine with NonlinearSolve (although needs prefixing) (prefixing does not fix the error with the other 2)

using CTDirect
using NonlinearSolve
include("ocp.jl")
sol = CTDirect.solve(ocp1)

@PierreMartinon
Copy link
Member Author

PierreMartinon commented May 27, 2024

FOUND IT: some packages apparently change the way floating point numbers are displayed, namely with a comma instead of a dot. The resulting expression is not properly parsed as a Float in NLPModelsIpopt...

Total seconds in IPOPT                               = 0,213

vs the usual

Total seconds in IPOPT                               = 1.854

Quick fix: set locale (LC_NUMERIC) to US for instance to prevent the use of the comma. Not very satisfying though.

@PierreMartinon PierreMartinon changed the title Post optimization error when using a different package in addition to CTDirect Possible post optimization error when using a locale with a comma as floating point Jun 20, 2024
@PierreMartinon
Copy link
Member Author

Todo: signal the possible issue at NLPModelsIpopt

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

No branches or pull requests

2 participants