-
Notifications
You must be signed in to change notification settings - Fork 52
Python bindings and profiles #124
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check-spelling found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
7fce72a to
291c251
Compare
|
Ideally, the (standalone) PRIMA Python package should have the same API as pdfo. |
I see from the PDFO usage notes that it aims to be API compatibility with |
79604aa to
a96abcb
Compare
185e770 to
44ae896
Compare
f6751f1 to
9771fbb
Compare
In a worst case scenario, if a process had picked a port that was in use, all of the attempts to solve problems on that port for that process would fail.
Per Zaikun, we will use maxfev in Python to set the maxfun value in order to be consistent with both PDFO and SciPy.
…ason in pycutest it's 5000.
b5d1974 to
629598c
Compare
|
For COBYLA, it seems that many of the problems in the list don't actually have nonlinear constraints, and this was leading the Python setup to fail on those problems (because no nonlinear constraint was provided, not even a blank one), whereas it seems the MATLAB one was continuing to solve those. I modified the code to reject and problems without nonlinear constraints for COBYLA and ran it again. For default and non_default options we again get vertical lines. For different options Python edges out MATLAB. cobyla_default_options.pdf.zip |
This is precisely why I updated the problem lists and suggested testing all possible types of problems. Do you mean that the current version of COBYLA cannot solve problems without nonlinear constraints? COBYLA should be able to solve all types of problems, with or without (nonlinear) constraints. If the user does not provide nonlinear constraints, COBYLA should handle it by, for example, setting the nonlinear constraints to none internally. Similar comments apply to other solvers. For example, LINCOA should be able to solver unconstrained, bound-constrained, and linear constrained problems, not only the last type (linearly constrained problems). If the user does not specify linear constraints at all, then LINCOA handles it by, for example, setting linear constraints to none internally. You may check how PDFO handles these situations. Thank you. |
|
I note that the discrepancy in NEWUOA becomes much more visible when the options are the default, but not so much with non-default options. Do they really receive the same default options? Thank you. |
Also added tests for it. Also removed a comment that referred to a previous way of doing thing, and also made the method names lowercase since users may look at these tests as a guide, and I wouldn't want them to come away with the impression that the method needed to be all uppercase.
I modified the Fortran to print out rhobeg_loc, rhoend_loc, etc. in newuoa.f90 to examine the options are they were being received from Python, and for MATLAB I printed the options values just before the call to the Fortran code (since in MATLAB it's necessary to use mexprintf and I didn't want to deal with that, particularly since MATLAB has
Yes, this was an oversight on my part. I've fixed it and also added tests to make sure it doesn't happen again. Below are the PDFs from re-running with COBYLA allowed to run on problems without nonlinear constraints. There appear to be a few problems that the MATLAB version takes more function evaluations to solve. I did some digging and came up with the following information: I'm confused as to why the performance ratio on the graph is so high. The ratio of the above 3 is between 1.1 and 1.2, and yet even if I just run with these 3, the x-axis still gets up to 16. Am I misunderstanding how the x-axis is supposed to work? I'm happy to keep doing performance profiles if we think there's a serious issue with any of these algorithms worth investigating, but I would need some guidance as to what exactly to investigate or what sort of data to come up with. cobyla_default_options.pdf.zip |
219d746 to
0c49d2a
Compare
|
Thank you @nbelakovski for the huge efforts! I think we are close to the merge. I will check it and come back soon. If there is nothing too serious, we will just merge and continue the investigations and refinements after that. |
|
Hi @nbelakovski ,
Great! Let us tolerate the fact that there is a discrepency in the profiles of NEWUOA, but we also need to keep this fact in mind. It may be just an artifact of rounding errors. Otherwise, it may bother us again in the future, when we may have better insights.
Great! The profiles look good, except for the large ratios as you mention below. We will continue to investigage this issue after the merge. It may be a bug of OptiProfiler @ragonneau @OptHuang .
I am confused as well. Is it possible to record the numbers of function evaluations for each solver (given a tolerance) and check whether there is a difference up to 16 times? Maybe the final numbers are close but the actual numbers needed to satisfy a given tolerance are very different. If this is not the case, it will be a bug of OptiProfiler. @ragonneau @OptHuang I am ready to press the merge button. Do you have more changes to make before that? Many thanks! Zaikun |
|
Hi @nbelakovski ,
I hope the huge difference in the computing time comes from the fact that the MATLAB version communicated with the objective function using TCP. What do you think? Thanks! Zaikun |
|
This may be a stupid question due to my ignorance about Python. I saw the following in python/examples/lincoa_example.py, python/examples/lincoa_example.py, and python/examples/rosenbrock.py: from prima import minimize, LinearConstraint as LCfrom prima import minimize, NonlinearConstraint as NLCfrom prima import minimize, Bounds, LinearConstraint, NonlinearConstraintDoes this mean that users are expected to use Bounds, LinearConstraint, and NonlinearConstraint provided by PRIMA? Couldn't they just use the standard constraints from SciPy? Old versions of PDFO used to provide Bounds, LinearConstraint, and NonlinearConstraint. They have been removed in the latest version. Isn't it better to use the standard facilities provided by SciPy? See https://github.com/pdfo/pdfo/blob/main/python/examples/rosenbrock.py |
I hope so too 😁 ! But really, I think it is. I haven't investigated but that seems likely to me. Particularly for problems that have both an objective function and a nonlinear constraint function, since that requires two separate connections.
If you look at
🥳 🥳 🥳 There's one outstanding item. At first I thought it would be a couple line fix, but there's a little more to it so I propose making an issue to keep track of it and fixing it in a follow-on PR. I can make that PR tomorrow or later this week, I just want to make sure the issue gets proper discussion. Does that sound good to you? |
|
Hi @nbelakovski ,
Will it work if people do the following? from prima import minimize
from scipy import Bounds, LinearConstraint, NonlinearConstraint
|
|
Hi @nbelakovski ,
Yes, it sounds good. Thanks. |
|
I have made an announcement on Fortran Discourse: https://fortran-lang.discourse.group/t/prima-has-got-a-python-interface/7942 Thank you very much, Nickolai @nbelakovski ! |
Current status:
BOBYQA, LINCOA, NEWUOA, and UOBYQA work on Linux and Mac
COBLYA works on Linux and Mac but only with NonlinearConstraints OR LinearConstraints at the moment (there's a minor todo to allow both), and it also has some sort of GIL issue (I think it's related to the fact that NonlinearConstraints holds a function).
TODO:
WindowsLet constraints be a list so that both Linear and Nonlinear constraints may be accepted for COBYLAFlesh out testingFlesh out test_compatible_interface.pyTest the non-COBYLA algorithms between pdfo and prima.Add support for constraint dictionaries in prima.Move the code about warning when providing bounds or constraints to a method which does not use them into a separate PRWarn user if they have provided information that will not be used #134Doesprima_is_successhave a complete list of successful return codes?Create issue to discuss static vs shared libraries (maybe both).Static vs shared libs? #125Create separate PR to modify the C and Fortran examples as follows: objective function shall beRefactor examples #131(x1-5)^2 + (x2-4)^2. The rationale is that this lets the initial point be (0,0), and since users will be copying the example for their own usage it makes sense to give them a sensible point to copy. This is not strictly related to python bindings, but it is something we'd like to do and it makes sense to do it ahead of the python bindings so their examples can be built correctly in the first place. This discussion is about what we call the "API example" - there will be more examples with more interesting functions to demonstrate the capabilities of the solvers.Include script used to run optiprofiler and create performance profiles vs pdfoRun latest performance profiles for all solversCreate performance profiles comparing Python bindings to MATLAB bindings in order to validate the Python bindings