-
Notifications
You must be signed in to change notification settings - Fork 38
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
Traits interface? #87
Comments
The user experience of implementing the NLP API wasn't really prioritized in the design, so I agree that there's room for improvement. Could you expand on how this replaces |
I was basing my statement off of implementations like this, for which the suitability of a given requested feature could be decided by calling the appropriate trait-function. For example, if |
If the signature is |
I guess what I'm saying is that you can still have an internal function initialize(d, requested_features)
...stuff...
if feat == :Hess && !isa(hessiankind(d), HessianExplicit)
error("You must supply an explicit hessian to use this solver")
end
...stuff...
end EDIT: once the user sets up the proper traits for his/her type, everything else is free except for the implementations of the methods that s/he wants to support. |
I see how that could work. There are a lot of subtle implicit design points but should be tractable. How breaking is this, if at all? |
We've been using |
The advantage of traits over introspection ( |
Yes, the primary gain would be unified way for the solver to communicate what features they support. Plus, doing method lookup feels brittle (what if you define a stub method?). |
Not certain, but my inclination is to say that it's not. Users of this interface may have written methods that, because they're more specific than your fallbacks, should take precedence. |
It's worth rethinking about traits more generally, especially for jump-dev/JuMP.jl#83 |
Normally I'd just hack this up and submit a PR, but I'm feeling short of time so will first float a suggestion and see what people think.
For nonlinear optimization, the API is good and flexible, but to me it still feels like there's more boilerplate required from the user than would be ideal. I'm wondering whether it would be better to define a traits-based API, e.g.,
so the user can define
and then not have to worry about any of the
g
-related functions. Same strategy for the various Hessian options, etc. These would essentially replaceinitialize
andfeatures_available
, at least as far as users are concerned, and as illustrated the more granular design reduces the need for boilerplate stub functions.In my own code I do this via inheritance, e.g.,
but the traits-based mechanism is far better because it allows you to mix-and-match traits arbitrarily.
The text was updated successfully, but these errors were encountered: