Scipy interface#705
Conversation
|
@FrancoisGallard I think the only breaking change is that the Lagrangian convention should be set with |
|
@FrancoisGallard You can have a look at the Scipy interface to clean it up, I probably forgot some np.array -> list conversions. Edit: ah, I wouldn't test the SLP preset. It converges very slowly and there's few reasons to use it. |
|
The Scipy tests pass ✌️ |
|
Well done, thanks Charlie ! I'll have give it a try |
|
The GEMSEO tests pass because we only look at the solution, but the |
|
I tried under windows and unopy 0.4.7, it works well, thanks a lot ! IPOPt works too. I have the same numerical issue as you. |
|
@FrancoisGallard
Same issue with the constraint Jacobian (I get some 6 instead of some 3). Is there a function somewhere that preprocesses/modifies the problem after the call to |
Yes, by default GEMSEO scales the design variables and the solver sees all bounds as [0, 1]. This can be deactivated with the solver opitons: |
| settings_ = self._filter_settings(self._settings.model_dump(), UNO_Settings) | ||
|
|
||
| # Deactivate stopping criteria which are handled by GEMSEO | ||
| tolerance = 0.0 |
There was a problem hiding this comment.
This sets the primal-dual tolerances to 0, therefore Uno most likely won't terminate (see Power2 test).
There was a problem hiding this comment.
GEMSEO has its own stop criteria based on xtol, ftol, maxiter or KKT, so we always deactivate the solver tolerances to have consistent stopping criteria when the user changes of optimizer.
There was a problem hiding this comment.
But how do you expect the optimizer to terminate if you set the tolerance to 0? Surely you usually pass a termination callback of some sort? It's not the case for Uno (yet).
There was a problem hiding this comment.
It does not by itself, we raise an exception in the objective function call and that stops the optimization, then we catch it and handle the search for the best point. We can also add an option to activate the solver stopping criteria if you want to check that all goes well.
There was a problem hiding this comment.
Ooh that's a brittle strategy. That works for (say) Fortran codes because they cannot catch exceptions, but you cannot assume any solver will behave the way you expect. Uno always catches the evaluation exceptions and backtracks. In the Power2 case, I can read from the Uno log: A function could not be evaluated. The trust-region radius will be reduced: indeed the radius is decreased 30 times in a row until Uno terminates with Algorithmic error.
A good alternative would be to keep the tolerances to 0 and set a user termination callback based on GEMSEO criteria. It's implemented in the C API (see here, and used here in the Uno outer loop), so it would be minimal effort to add this to unopy.
There was a problem hiding this comment.
I think ensuring that we catch the exception in pyuno and manage the solver stop there would be better. It will appear in many user scripts independently of gemseo that exceptions be raised when calling the objective.
There was a problem hiding this comment.
@cvanaret if you can expose to unopy the uno_termination_callback from the c API, I will try to make this work.
There was a problem hiding this comment.
If you are OK I propose to add a try catch around the evaluation of the functions in the scipy interface, if an exception is catched, we return a NaN and then store this state of error in a global variable, and the termination callback returns True based on this global state.
There was a problem hiding this comment.
Let's give it a shot and we'll see what it looks like.
|
@FrancoisGallard got it. The bug is identified (see review above). |
(fullensqp with constr) and unopy v 0.2.0
This is a proposal for a scipy-like interface of UNO.
It works with unopy 0.2.0 under linux. Porting to the latest unopy version needs to be done @cvanaret help is welcome on this.
Since unopy supports array asignation ( vectyor[:] = myarray) this needs to be used once ported.
I first implemented it manually, and stuggled with the Hessian lagrangian. I asked @jgiret for help, we used Claude code, I provided the unit tests and the specification (method comments and signature), the agent looped until tests worked. I manually reviewed the code and did some minor changes.
It could be further reviewed.
One test (funnelsqp on constrained problem) is non deterministic on my machine (still unopy v0.2.0), the status is "solver error", sometimes it passes, so I think it is not an issue in the interface but rather in the C code, that has maybe been fixed in the latest version.