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

Writing user extension for Tulip.KKT.AbstractKKTBackend, Tulip.KKT.AbstractKKTSolver etc. #145

Closed
pratyai opened this issue Dec 13, 2023 · 1 comment

Comments

@pratyai
Copy link
Contributor

pratyai commented Dec 13, 2023

Hi,

I am trying to write a custom KKT backend and solver for Tulip that could exploit the known structure of a certain class of problems. The problem details etc. are not particularly relevant, but I would like to write a module like:

module MyKKT

using Tulip

struct Backend <: AbstractKKTBackend    # custom backend class to pass to Tulip parameters
end

mutable struct Solver{Tv<:Number,Ti<:Integer} <: AbstractKKTSolver{Tv}   # custom solver class that knows the problem structure
  # problem specific data
end

backend(::Solver) = "CustomBackend"
linear_system(::Solver) = "Normal equations (K1)"

function setup(A::AbstractSparseMatrix{Tv,Ti}, ::K1, ::Backend) where {Tv<:Number,Ti<:Integer}
  # setup work
end

function update!(kkt::Solver{Tv,Ti}, θ::AbstractVector{Tv}, regP::AbstractVector{Tv}, regD::AbstractVector{Tv}) where {Tv<:Number,Ti<:Integer}
  # update work
end

function solve!(dx::AbstractVector{Tv}, dy::AbstractVector{Tv}, kkt::Solver{Tv,Ti}, ξp::AbstractVector{Tv}, ξd::AbstractVector{Tv}) where {Tv<:Number,Ti<:Integer}
  # solve work
end

end

The problem is that the rest of the Tulip framework heavily relies on the KKT module and its specific functions, e.g. this setup call.

I don't understand if it's possible to define a setup() function (as shown above) completely outside Tulip, and still be able to reuse the rest of the Tulip (i.e. I don't have to work on a fork). I couldn't find any example if that's possible to do so. If not right now, how difficult it could be to make the KKT module extendable (I'm happy to make an attempt if the maintainers are open to it)?

@pratyai
Copy link
Contributor Author

pratyai commented Dec 13, 2023

I just realised that I could just write

function Tulip.KKT.setup(A::AbstractSparseMatrix{Tv,Ti}, ::K1, ::Backend) where {Tv<:Number,Ti<:Integer}
  # setup work
end

and so on, and that would be enough to extend those functions from KKT module. Didn't know I could do that in Julia before. Closing the issue, since it's a non-issue after all.

@pratyai pratyai closed this as completed Dec 13, 2023
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

1 participant