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

Proposed solution to bug#745 #766

Merged
merged 24 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9d7892b
Proposed solution to bug #745
ParasPuneetSingh May 29, 2024
92ce944
Merge branch 'SciML:master' into branch-march-2024
ParasPuneetSingh May 29, 2024
0e54360
Update OptimizationBBO.jl
ParasPuneetSingh Jun 4, 2024
4bd61d4
Update utils.jl
ParasPuneetSingh Jun 4, 2024
49aa0d8
Update utils.jl
ParasPuneetSingh Jun 5, 2024
dc8c0cb
Update utils.jl
ParasPuneetSingh Jun 7, 2024
6ab7caf
Update OptimizationBBO.jl
ParasPuneetSingh Jun 7, 2024
9ae9510
Update utils.jl
ParasPuneetSingh Jun 8, 2024
140d260
Update OptimizationBBO.jl
ParasPuneetSingh Jun 8, 2024
bc5a222
Update lib/OptimizationBBO/src/OptimizationBBO.jl
Vaibhavdixit02 Jun 8, 2024
0e65d58
Update utils.jl
ParasPuneetSingh Jun 11, 2024
0cf0b4b
Update utils.jl
ParasPuneetSingh Jun 11, 2024
686327f
Update OptimizationBBO.jl
ParasPuneetSingh Jun 11, 2024
1fe2745
Update OptimizationBBO.jl
ParasPuneetSingh Jun 11, 2024
8894c9e
ReturnCode is a module so can't be used for type assertion
Vaibhavdixit02 Jun 12, 2024
375fde8
Update lib/OptimizationBBO/src/OptimizationBBO.jl
Vaibhavdixit02 Jun 13, 2024
30c40df
Update lbfgsb.jl
ParasPuneetSingh Jun 13, 2024
79eee22
Update utils.jl
ParasPuneetSingh Jun 13, 2024
a70831b
Update src/utils.jl
Vaibhavdixit02 Jun 14, 2024
99a52a9
Update lbfgsb.jl
ParasPuneetSingh Jun 15, 2024
5d69aa8
Fix retcode handling in lbfgsb
Vaibhavdixit02 Jun 16, 2024
50d7b42
Use constructor for LBFGSB object in the auglag case as well
Vaibhavdixit02 Jun 16, 2024
e8f5ea1
Missing regex pattern for maxtime
Vaibhavdixit02 Jun 16, 2024
9dc9c92
Don't need to subset the string
Vaibhavdixit02 Jun 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/OptimizationBBO/src/OptimizationBBO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ function SciMLBase.__solve(cache::Optimization.OptimizationCache{

t1 = time()

opt_ret = Symbol(opt_res.stop_reason)
# Use the improved convert function
opt_ret = convert(ReturnCode.T, opt_res.stop_reason)
stats = Optimization.OptimizationStats(;
iterations = opt_res.iterations,
time = t1 - t0,
Expand Down
85 changes: 85 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,88 @@
pkg_info[pkg].version >= VersionNumber(ver) :
pkg_info[pkg].version > VersionNumber(ver)
end


# RetCode handling for BBO and others.
using Logging
# Define the ReturnCode type using @enum
@enum ReturnCode begin
Vaibhavdixit02 marked this conversation as resolved.
Show resolved Hide resolved
Default
Success
Terminated
MaxIters
MaxTime
DtLessThanMin
Unstable
InitialFailure
ConvergenceFailure
Failure
Infeasible
end

# Define a dictionary to map regular expressions to ReturnCode values
const STOP_REASON_MAP = Dict(
Vaibhavdixit02 marked this conversation as resolved.
Show resolved Hide resolved
r"Delta fitness .* below tolerance .*" => ReturnCode.Success,
r"Fitness .* within tolerance .* of optimum" => ReturnCode.Success,
r"Terminated" => ReturnCode.Terminated,
r"MaxIters|MAXITERS_EXCEED" => ReturnCode.MaxIters,
r"MaxTime|TIME_LIMIT" => ReturnCode.MaxTime,
r"DtLessThanMin" => ReturnCode.DtLessThanMin,
r"Unstable" => ReturnCode.Unstable,
r"InitialFailure" => ReturnCode.InitialFailure,
r"ConvergenceFailure|ITERATION_LIMIT" => ReturnCode.ConvergenceFailure,
r"Infeasible|INFEASIBLE|DUAL_INFEASIBLE|LOCALLY_INFEASIBLE|INFEASIBLE_OR_UNBOUNDED" => ReturnCode.Infeasible
Vaibhavdixit02 marked this conversation as resolved.
Show resolved Hide resolved
)

# Function to deduce ReturnCode from a stop_reason string using the dictionary
function deduce_retcode(stop_reason::String)::ReturnCode
Vaibhavdixit02 marked this conversation as resolved.
Show resolved Hide resolved
for (pattern, retcode) in STOP_REASON_MAP
if occursin(pattern, stop_reason)
return retcode

Check warning on line 106 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L103-L106

Added lines #L103 - L106 were not covered by tests
end
end
@warn "Unrecognized stop reason: $stop_reason. Defaulting to ReturnCode.Failure."
return ReturnCode.Failure

Check warning on line 110 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L108-L110

Added lines #L108 - L110 were not covered by tests
end

function Base.convert(::Type{ReturnCode.T}, retcode::Union{Symbol, String})
Vaibhavdixit02 marked this conversation as resolved.
Show resolved Hide resolved
@warn "Backwards compatibility support of the new return codes to Symbols will be deprecated with the Julia v1.9 release. Please see https://docs.sciml.ai/SciMLBase/stable/interfaces/Solutions/#retcodes for more information"

Check warning on line 114 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L113-L114

Added lines #L113 - L114 were not covered by tests

if isa(retcode, Symbol)
if retcode == :Default || retcode == :DEFAULT
return ReturnCode.Default
elseif retcode == :Success || retcode == :EXACT_SOLUTION_LEFT ||

Check warning on line 119 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L116-L119

Added lines #L116 - L119 were not covered by tests
retcode == :FLOATING_POINT_LIMIT || retcode == :true || retcode == :OPTIMAL ||
retcode == :LOCALLY_SOLVED
return ReturnCode.Success
elseif retcode == :Terminated
return ReturnCode.Terminated
elseif retcode == :MaxIters || retcode == :MAXITERS_EXCEED
return ReturnCode.MaxIters
elseif retcode == :MaxTime || retcode == :TIME_LIMIT
return ReturnCode.MaxTime
elseif retcode == :DtLessThanMin
return ReturnCode.DtLessThanMin
elseif retcode == :Unstable
return ReturnCode.Unstable
elseif retcode == :InitialFailure
return ReturnCode.InitialFailure
elseif retcode == :ConvergenceFailure || retcode == :ITERATION_LIMIT
return ReturnCode.ConvergenceFailure
elseif retcode == :Failure || retcode == :false
return ReturnCode.Failure
elseif retcode == :Infeasible || retcode == :INFEASIBLE ||

Check warning on line 139 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L122-L139

Added lines #L122 - L139 were not covered by tests
retcode == :DUAL_INFEASIBLE || retcode == :LOCALLY_INFEASIBLE ||
retcode == :INFEASIBLE_OR_UNBOUNDED
return ReturnCode.Infeasible

Check warning on line 142 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L142

Added line #L142 was not covered by tests
else
return ReturnCode.Failure

Check warning on line 144 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L144

Added line #L144 was not covered by tests
end
elseif isa(retcode, String)
return deduce_retcode(retcode)

Check warning on line 147 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L146-L147

Added lines #L146 - L147 were not covered by tests
else
@warn "Unsupported retcode type: $retcode. Defaulting to ReturnCode.Failure."
return ReturnCode.Failure

Check warning on line 150 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L149-L150

Added lines #L149 - L150 were not covered by tests
end
end

Loading