Search code examples
juliaipoptjulia-pkg

Julia OptimalControl Package: MethodError with `String(::Tuple{...})` in `CTDirect`


More details of the problem: https://github.com/control-toolbox/OptimalControl.jl/issues/375

I am solving an optimal control problem using the OptimalControl package in Julia. The solver (solve) finds an optimal solution, but an error occurs afterward, preventing me from processing or displaying the solution. Here’s the relevant output:

.
.
.
EXIT: Optimal Solution Found.
ERROR: MethodError: no method matching String(::Tuple{Symbol, MathOptInterface.TerminationStatusCode, MathOptInterface.ResultStatusCode})
The type `String` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  String(::LazyString)
   @ Base strings/lazy.jl:80
  String(::Vector{UInt8})
   @ Base strings/string.jl:72
  String(::Base.CodeUnits{UInt8, String})
   @ Base strings/string.jl:126
  ...

Stacktrace:
 [1] OptimalControlSolution(docp::CTDirect.DOCP, docp_solution::SolverCore.GenericExecutionStats{…})
   @ CTDirect ~/.julia/packages/CTDirect/5NADh/src/solution.jl:18
 [2] direct_solve(::OptimalControlModel{…}; init::Nothing, grid_size::Int64, time_grid::Nothing, kwargs::@Kwargs{})
   @ CTDirect ~/.julia/packages/CTDirect/5NADh/src/solve.jl:122
 [3] direct_solve(::OptimalControlModel{Autonomous, Fixed})
   @ CTDirect ~/.julia/packages/CTDirect/5NADh/src/solve.jl:90
 [4] solve(::OptimalControlModel{Autonomous, Fixed}; kwargs::@Kwargs{})
   @ OptimalControl ~/.julia/packages/OptimalControl/6SuFg/src/solve.jl:61
 [5] solve(::OptimalControlModel{Autonomous, Fixed})
   @ OptimalControl ~/.julia/packages/OptimalControl/6SuFg/src/solve.jl:55
 [6] top-level scope
   @ ~/Code/Tutorial.jl:15
Some type information was truncated. Use `show(err)` to see complete types.

What I've Tried:

  • I updated all relevant packages using Pkg.update("OptimalControl") and Pkg.update("CTDirect").
  • Reinstalled Julia and all related packages from scratch.
  • Tried using Pkg.develop to check for and manually modify the CTDirect package code, but this led to compatibility issues with OptimalControl.

The issue seems to stem from how CTDirect processes the solution. Specifically, it tries to convert a tuple (Symbol, MathOptInterface.TerminationStatusCode, MathOptInterface.ResultStatusCode) into a String, which fails because no method is defined for this combination.

My Setup:

-Julia Version: `1.11.1`
-OptimalControl Version: `0.12.3`
-CTDirect Version: `0.12.0`

Questions:

  1. Is this a known issue with CTDirect or OptimalControl? Are there better workarounds?
  2. How can I patch this locally if the package dependencies are causing conflicts during Pkg.develop?
  3. Would it be better to report this issue to the CTDirect repository, and if so, what details should I include?

Solution

  • Problem solved with all details here: https://github.com/control-toolbox/OptimalControl.jl/issues/375.