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

Simplify solve_docp core #272

Closed
ocots opened this issue Sep 3, 2024 · 1 comment
Closed

Simplify solve_docp core #272

ocots opened this issue Sep 3, 2024 · 1 comment
Assignees
Labels
internal dev Modification to the code is requested and should not affect user experiment

Comments

@ocots
Copy link
Member

ocots commented Sep 3, 2024

@PierreMartinon We could replace

CTDirect.jl/src/solve.jl

Lines 131 to 143 in 5a2105a

abstract type SolverTag end
struct IpoptTag <: SolverTag end
struct MadNLPTag <: SolverTag end
function solve_docp(solver_tag, args...; kwargs...)
if typeof(solver_tag) == IpoptTag
throw(ExtensionError(:NLPModelsIpopt))
elseif typeof(solver_tag) == MadNLPTag
throw(ExtensionError(:MadNLP))
else
error("Unknown solver type", typeof(solver_tag))
end
end

by

abstract type AbstractSolverBackend end
struct IpoptBackend <: AbstractSolverBackend end
struct MadNLPBackend <: AbstractSolverBackend end

weakdeps = Dict(IpoptBackend => :NLPModelsIpopt, MadNLPBackend => :MadNLP)

function solve_docp(solver_tag::T, args...; kwargs...) where {T <: AbstractSolverBackend}
    throw(ExtensionError(weakdeps[T]))
end
@ocots ocots self-assigned this Sep 3, 2024
@ocots ocots added the internal dev Modification to the code is requested and should not affect user experiment label Sep 3, 2024
@PierreMartinon
Copy link
Member

@PierreMartinon We could replace

CTDirect.jl/src/solve.jl

Lines 131 to 143 in 5a2105a

abstract type SolverTag end
struct IpoptTag <: SolverTag end
struct MadNLPTag <: SolverTag end
function solve_docp(solver_tag, args...; kwargs...)
if typeof(solver_tag) == IpoptTag
throw(ExtensionError(:NLPModelsIpopt))
elseif typeof(solver_tag) == MadNLPTag
throw(ExtensionError(:MadNLP))
else
error("Unknown solver type", typeof(solver_tag))
end
end

by

abstract type AbstractSolverBackend end
struct IpoptBackend <: AbstractSolverBackend end
struct MadNLPBackend <: AbstractSolverBackend end

weakdeps = Dict(IpoptBackend => :NLPModelsIpopt, MadNLPBackend => :MadNLP)

function solve_docp(solver_tag::T, args...; kwargs...) where {T <: AbstractSolverBackend}
    throw(ExtensionError(weakdeps[T]))
end

This looks so neat and classy OO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal dev Modification to the code is requested and should not affect user experiment
Projects
None yet
Development

No branches or pull requests

2 participants