-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Solving chain context #3000
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
base: master
Are you sure you want to change the base?
Solving chain context #3000
Conversation
…to fix-issue-1222
…compatible with cvxpy test set
|
Benchmarks that have stayed the same: |
|
I thought we were handling this by converting power to an exotic cone and then converting later to the cones supported by the solver? |
| # solver_context : The solver context: supported constrains and bounds. | ||
| # NOTE: solver_context is currently only passed to power_canon. | ||
| self.solver_context = None | ||
|
|
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.
Add a type annotation formalizing this. If it's non-None, what can it be? Here's an example that says "it's none or it's a dict keyed by strings":
self.solver_context : Optional[dict[str,Any]] = NoneThere 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.
Thanks for the suggestion! I added the optional type annotation. The solver_context is a new SolverInfo class that we use to propagate the solver's supported constraints and bounds throughout the solving chain.
That approach is definitely possible, but I encouraged Nika to go with this design because I think it generalizes to more features in the canonicalization better. For example, I am encouraging Nika to work on adding what I'm calling "derived bounds": This would change the abs canoncalization to: if ctx.solver.SUPPORTS_BOUNDS and expr.bounds is not None:
if expr.lower_bounds < 0 and expr.upper_bounds > 0:
bounds = [0, max(expr.lower_bounds.abs(), expr.upper_bounds.abs())]
else:
bounds = [min(expr.lower_bounds.abs(), expr.upper_bounds.abs()), max(expr.lower_bounds.abs(), expr.upper_bounds.abs())]
else:
bounds = None
t = cp.Variable(bounds=bounds)
return t, [-expr <= t, expr <= t]this will help solvers like CUOPT and a future Clarabel version that take explicit bounds on |
Thanks for clarifying. The approach in this MR is fine with me then. |
agreed, that is going to be a super nice addition :). One quick question though, what is expr.upper_bounds? Is that an attribute to add later on? How would we compute that? |
…vxpy into solving-chain-context
Description
Building on PR #2999, we prefer to canonicalize the power atom without any approximations. In this PR, we automatically canonicalize to a 3D power cone (instead of the approximated SOC) if the chosen solver supports 3D power cones, unless approximation is being enforced by the user.
Similar to the discussion of PR #2987, we introduce a new class, SolverInfo, which propagates the solver's supported constraints through the solving chain. During canonicalization, the solver's supported constraints are checked and the canonicalization defaults to 3D power cones if possible.
In future PRs, the SolverInfo class can be enhanced with any additional fields that need to be passed throughout the solving chain.
Type of change
Contribution checklist