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

Make fallback to cp.SolverError optional/configurable #185

Open
yihengli opened this issue Jan 23, 2025 · 7 comments
Open

Make fallback to cp.SolverError optional/configurable #185

yihengli opened this issue Jan 23, 2025 · 7 comments

Comments

@yihengli
Copy link

yihengli commented Jan 23, 2025

Hi,

I notice since version 1.3.1 or 1.3.2, the package changed its default behaviour when optimization infeasible hit. Though changing solver to SCS and retry the problem might be good in some cases. I would suggest this should be a decision to be made by the user. Sometimes it might be fine just to fail the problem instead of having inconsistent results of changing solvers.

At least, there should be an option for the user to turn off the SCS rollback.

Thanks

relevant snippet: https://github.com/cvxgrp/cvxportfolio/blob/master/cvxportfolio/policies.py#L949-L969

@enzbus
Copy link
Collaborator

enzbus commented Jan 23, 2025

Hi, thanks for the suggestion. I think you're missing something there. You can refer to CVXPY documentation for the meaning of those Exceptions.

@yihengli
Copy link
Author

Sorry for the confusion. You are right, the SCS rollback is not for infeasible, it's more for other errors. But the point still holds though, sometimes it's good to crash the process or we can define what would be the user-defined downstream operations.

@enzbus
Copy link
Collaborator

enzbus commented Jan 24, 2025

To be clear: Infeasible/Unbounded are not treated as exceptions in CVXPY, those are valid result statuses. Cvxportfolio instead raises (Cvxportfolio) exceptions for those cases. SolverError is a hopefully very rare exception thrown by CVXPY (not Cvxportfolio) for errors in the underlying numerical solver. What is going on in those clauses you looked at is exception handling for the latter. (It gets confusing, I know.) If you want to use a solver of your choice, just pass it to the constructor of the optimization policy. If the solver you choose never crashes (doesn't throw SolverError) you'll never touch the fallback clause :)

@enzbus
Copy link
Collaborator

enzbus commented Jan 24, 2025

PS I don't think it's useful to expose the user to crashes of solvers; convex optimization solvers are an active area of research and development, the default ones used by CVXPY work well say in 99.99% of the cases, with tradeoffs between speed, memory usage, and stability. SCS is very stable.

@yihengli
Copy link
Author

I see your point. The scenario is that I am using commercial solvers like MOSEK, if it crashed for some weird errors, I would like to capture it and understand it. Any fallbacks to other solvers would best be disabled. In the current setup, I could still check the print logs, capture this SCS fallback message and crash the process in my own downstream. Not a big deal, if this is as intended, I guess this issue can be safely closed. Thanks for your timely response.

@enzbus
Copy link
Collaborator

enzbus commented Jan 27, 2025

I'm not sure about your application, but you can probably tweak the parameters of your solver to avoid SolverError (increase tolerances, maximum number of iterations, ...). I'll leave this open and think whether to make the fallback optional, probably you're right that it's a valid usecase. Also adding regularization to the risk model typically helps with numerical solver crashes, for example using -> https://www.cvxportfolio.com/en/stable/risks.html#cvxportfolio.RiskForecastError

@enzbus enzbus changed the title cp.SolverError when optimizing should not default to switch solver Make fallback to cp.SolverError optional/configurable Jan 28, 2025
enzbus added a commit that referenced this issue Feb 9, 2025
@enzbus
Copy link
Collaborator

enzbus commented Feb 9, 2025

Hello @yihengli ; I made a fix, open merge request #188 ; please have a look if you have time and tell me if it looks OK to you. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants