-
Notifications
You must be signed in to change notification settings - Fork 43
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
Make base algorithms (cobyla
, bobyqa
, etc.) directly available in the C API
#183
base: main
Are you sure you want to change the base?
Conversation
Thank you @emmt for the comment and proposal. However, it is clear to me that we should not do this, namely to make both individual solvers ( This has been discussed before. Let me briefly explain why. Providing both
The answer is yes. Why? Because we need to do some preprocessing and postprocessing before and after solving the problem. When In other words,
This is too complicated. This is why we should provide the user with only one interface Indeed, this also applies to the higher-level interfaces including PRIMA.jl. However, I did not point this out early enough. My fault. Consequently, we should not provide a Thanks and regards, |
Hello @zaikunzhang, This is not my point and if you look in the In other words, for a Julia user, there is no real direct access to the base algorithms, all public methods ( BTW the Julia interface is very close to what is done in the high-level C driver. This is not surpring as we all actively participated to the discussion about the scaling of variables, automatic choice of the base algorithm, etc. Thiese discussion were very fruitful and useful to design waht should be the correct "high-level API" and, for me, the current Julia public API reflects quite faithfully that consensus. Now I come to my points (sorry if I wasn't clear): My first point is a technical reason. Interfacing the high level C driver is more difficult (at least in Julia) because it requires to deal with C structures (which is possible but more prone to errors sucha as misalignement etc.). It is faster and easier to keep most of the structure of the Julia interface and update it to account for the new arguments taken by the base algorithms (none of them are structures). Dealing with C structures may also be an issue for others bindings than Julia. My second point is that Bonne journée ;-) |
Hi @emmt ,
First of all, I do NOT think the new C interface will make the public API of
This is because, as I mentioned in my last comment (copied below), PRIMA.jl currently does not include necessary pre/postprocessing yet.
It will be difficult for me to make myself understood if my previous comment failed to make things clear to you. This is because we have different understandings about what an interface is. We may have a zoom meeting so that I can explain to you. Thanks. Zaikun |
@zaikunzhang, I can see that we have different understandings, we may have a chat if you want. Where are implemented the pre-/post-processing you are mentioning? The discussion you pointed does not make these clear to me. You did not answer on my specific points... |
First of all, let me make it clear that I do not intend to change the public API of
There are many many others ... I hope you get a feeling why pre/postprocessing needs more than 2000 lines of code. The MATLAB interface has implemented all of these. The Python interface will implement them as well, mostly by inheriting what PDFO has done. Without doing so, the interfaces would only be half-baked (better than nothing). See again my post about what an interface is. I do acknowledge that proper pre/postprocessing is nontrivial to implement. Hence other interfaces may not implement all of these. In that case, we essentially leave the pre/postprocessing to the user, which is not ideal, but better than nothing.
I totally agree with this one, although I have no much to say as I am ignorant about Julia. I hope the technical problems can be solved.
I agree, and I do not intend to change the public API of |
It is clear that all these are necessary but it would be much more consistent and logical if all the pre/post processings be done by the code that every langage binding is using in the end: the Fortran 90 version of the algorithm(s)... This is the only way to make sure that all intefaces behave the same. Plus this is the way to avoid duplicating the efforts and make easier interfacing PRIMA in other langages. |
I agree with the idea in general. That is also what the Fortran backend tries to do. However, some pre/postprocessing is too complicated, if not impossible, to do in Fortran due to the limitation / nature of the language. In that case, I do believe it is more reasonable to leave the pre/postprocessing to the high-level interfaces, where the language is usually more powerful and flexible. Let me reiterate on my examples in this aspect.
This is nontrivial in Fortran, due to the lack of lambda/closure functions. I do have an idea about how to implement it, just I do not have the time yet. See #182
This is nontrivial in Fortran because of two things.
This is nontrivial in Fortran due to the lack of lambda function.
This is nontrivial in Fortran because it needs a QP (quadratic programming) solver, which is readily available in high-level languages.
This is impossible in Fortran, which does not have the concept of exception handling. I must stress that the above examples are only examples. There are many pre/postprocessing that cannot be done in the Fortran backend at all. Here are a few examples in MATLAB. I use MATLAB to avoid saying stupid things since I do not know Julia.
You may tell me that the particular examples do not apply to Julia, but the point is that pre/postprocessing may be a result of the interface itself. Thank you for thinking about it. |
OK then I think that this PR (#189) may be a better solution. |
This patch simply moves the definitions of
cobyla_c
,bobyqa_c
, etc. fromprima.c
toprima.h
.It is not that the new high level interface is bad (on the contrary, it may greatly simplify the life a C user) but the other functions (formerly
prima_bobyqa
,prima_newuoa
, etc.) have their utility. For instance, it may be easier to write langage bindings for the base algorithms because you do not have to deal with C structures, it is just needed to wrap function calls with simple arguments like values, and pointers to functions or to arrays. In that respect, updating the Julia interface inPRIMA.jl
would represent a lot of work and potentially new bugs (see this PR).I would suggest to keep the same name as before, e.g.
prima_bobyqa
instead ofbobyqa_c
, but that's of lesser importance.