optora.solvers.saddle_point¶
Primal-dual saddle-point solver for the DRO minimax problem.
SaddlePointProblem
dataclass
¶
Minimax problem solved by SaddlePointSolver.
Represents \(\min_x \max_y \mathrm{objective}(x, y)\), the shape of the DRO
minimax problem once a decision variable x and an ambiguity set over
distributions y are both in play.
Attributes:
| Name | Type | Description |
|---|---|---|
objective |
Callable[[Tensor, Tensor], Tensor]
|
Differentiable scalar-valued function
|
primal_initial_point |
Tensor
|
Starting point for the primal (minimizing) variable. |
dual_initial_point |
Tensor
|
Starting point for the dual (maximizing) variable. |
dual_projection |
Callable[[Tensor], Tensor] | None
|
Callable applied to the dual iterate after every
ascent step to keep it inside its feasible set, for example the
Euclidean projection onto the probability simplex. Defaults to
the identity (unconstrained ascent) when |
SaddlePointResult
dataclass
¶
Bases: ConvergenceDiagnostics
Outcome of a SaddlePointSolver solve.
Attributes:
| Name | Type | Description |
|---|---|---|
primal_point |
Tensor
|
Final primal (minimizing) iterate. |
dual_point |
Tensor
|
Final dual (maximizing) iterate. |
value |
Tensor
|
Objective value at |
status |
ConvergenceStatus
|
Convergence diagnostics of the solve, exposed on the host
as |
SaddlePointSolver
¶
Bases: Solver[SaddlePointProblem, SaddlePointResult]
Primal-dual gradient ascent-descent for a minimax problem.
Solves \(\min_x \max_y \mathrm{objective}(x, y)\) by alternating, at every iteration, a gradient descent step on the primal variable \(x\) and a gradient ascent step on the dual variable \(y\),
dual_projection keeps y feasible after each ascent step. For a DRO
problem, x is the decision variable, y ranges over candidate
distributions, and dual_projection maps y back onto the feasible
set, for example the probability simplex. optora.dro.MinimaxSolver
does not use this solver. It replaces the ascent over y by the
ambiguity set's own worst-case solve and minimizes the result over x.
The gradient-norm test is evaluated on the iterates' device and read
back to the host only every check_interval iterations. Iterations
taken after convergence are frozen, so the solution does not depend on
that interval. Keep check_interval=1 when the objective is expensive,
for example when each iteration costs an inner solve.
See optora.core.convergence.ConvergenceTracker. The returned
diagnostics stay on the device as well (see
optora.core.convergence.ConvergenceStatus), so a solve nobody
inspects never synchronizes for them.
The solve composes with torch.func transforms of its caller, as
optora.solvers.GradientDescent does. Inside one, where
Tensor.requires_grad_ and torch.autograd.grad are unsupported, both
gradients are taken with torch.func.grad_and_value instead, and under
torch.func.vmap every mapped element runs the whole iteration budget,
since a batched convergence flag has no single value to read on the
host (see ConvergenceTracker.should_stop). Each iterate is detached
either way, so a caller differentiating through the solve sees none of
its steps.
Attributes:
| Name | Type | Description |
|---|---|---|
primal_step_size |
Positive learning rate for the descent step on the primal variable. |
|
dual_step_size |
Positive learning rate for the ascent step on the dual variable. |
|
max_iter |
Maximum number of ascent-descent iterations. |
|
tol |
Convergence tolerance on the combined primal/dual gradient norm. |
|
check_interval |
Number of iterations between host reads of the convergence flag. |
__init__(primal_step_size=0.01, dual_step_size=0.01, max_iter=1000, tol=1e-06, check_interval=DEFAULT_CHECK_INTERVAL)
¶
Initialize the saddle-point solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
primal_step_size
|
float
|
Positive learning rate for the descent step on the primal variable. |
0.01
|
dual_step_size
|
float
|
Positive learning rate for the ascent step on the dual variable. |
0.01
|
max_iter
|
int
|
Maximum number of ascent-descent iterations. |
1000
|
tol
|
float
|
Convergence tolerance on the combined primal/dual gradient norm. |
1e-06
|
check_interval
|
int
|
Number of iterations between host reads of the convergence flag. Raise it to trade redundant frozen iterations for fewer device synchronizations, but only when an iteration is cheap relative to a synchronization. |
DEFAULT_CHECK_INTERVAL
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
solve(problem)
¶
Find a saddle point of problem.objective.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
SaddlePointProblem
|
Objective, initial primal/dual points, and optional dual feasibility projection to solve from. |
required |
Returns:
| Type | Description |
|---|---|
SaddlePointResult
|
A |
SaddlePointResult
|
and convergence diagnostics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |