Skip to content

WIP: Objective starting values#3271

Closed
blegat wants to merge 2 commits intomasterfrom
bl/slack_start
Closed

WIP: Objective starting values#3271
blegat wants to merge 2 commits intomasterfrom
bl/slack_start

Conversation

@blegat
Copy link
Copy Markdown
Member

@blegat blegat commented Mar 7, 2023

Proof of concept solution for #3270 copy-pasted from src/copy_dual.jl of jump-dev/DiffOpt.jl#231
Most of it should be in MOI which is why it's more of a POC PR.
The example of #3270 works after this PR:

julia> using SCS, JuMP

julia> model = Model(SCS.Optimizer);

julia> @variable(model, x);

julia> @objective(model, Min, x^2);

julia> optimize!(model)
------------------------------------------------------------------
	       SCS v3.2.1 - Splitting Conic Solver
	(c) Brendan O'Donoghue, Stanford University, 2012
------------------------------------------------------------------
problem:  variables n: 2, constraints m: 3
cones: 	  q: soc vars: 3, qsize: 1
settings: eps_abs: 1.0e-04, eps_rel: 1.0e-04, eps_infeas: 1.0e-07
	  alpha: 1.50, scale: 1.00e-01, adaptive_scale: 1
	  max_iters: 100000, normalize: 1, rho_x: 1.00e-06
	  acceleration_lookback: 10, acceleration_interval: 10
lin-sys:  sparse-direct-amd-qdldl
	  nnz(A): 3, nnz(P): 0
------------------------------------------------------------------
 iter | pri res | dua res |   gap   |   obj   |  scale  | time (s)
------------------------------------------------------------------
     0| 2.07e+01  1.00e+00  2.83e+01 -1.41e+01  1.00e-01  9.90e-05 
    25| 1.14e-05  2.44e-08  1.61e-05  8.04e-06  1.00e-01  1.18e-04 
------------------------------------------------------------------
status:  solved
timings: total: 1.19e-04s = setup: 7.40e-05s + solve: 4.48e-05s
	 lin-sys: 3.28e-06s, cones: 2.97e-06s, accel: 9.37e-07s
------------------------------------------------------------------
objective = 0.000008
------------------------------------------------------------------

julia> set_start_values(model)

julia> model.moi_backend.optimizer.model.model_cache.varattr
Dict{MathOptInterface.AbstractVariableAttribute, Dict{MathOptInterface.VariableIndex, Any}} with 1 entry:
  VariablePrimalStart() => Dict(VariableIndex(2)=>0.0, VariableIndex(1)=>0.0)

julia> model.moi_backend.optimizer.model.model_cache.conattr
Dict{MathOptInterface.AbstractConstraintAttribute, Dict{MathOptInterface.ConstraintIndex, Any}} with 2 entries:
  ConstraintDualStart()   => Dict(ConstraintIndex{VectorAffineFunction{Float64}, SecondOrderCone}(1)=>[0.707107, -0.707107, -0.0])
  ConstraintPrimalStart() => Dict(ConstraintIndex{VectorAffineFunction{Float64}, SecondOrderCone}(1)=>[0.707107, 0.707107, 0.0])

julia> optimize!(model)
------------------------------------------------------------------
	       SCS v3.2.1 - Splitting Conic Solver
	(c) Brendan O'Donoghue, Stanford University, 2012
------------------------------------------------------------------
problem:  variables n: 2, constraints m: 3
cones: 	  q: soc vars: 3, qsize: 1
settings: eps_abs: 1.0e-04, eps_rel: 1.0e-04, eps_infeas: 1.0e-07
	  alpha: 1.50, scale: 1.00e-01, adaptive_scale: 1
	  max_iters: 100000, normalize: 1, rho_x: 1.00e-06
	  acceleration_lookback: 10, acceleration_interval: 10
lin-sys:  sparse-direct-amd-qdldl
	  nnz(A): 3, nnz(P): 0
------------------------------------------------------------------
 iter | pri res | dua res |   gap   |   obj   |  scale  | time (s)
------------------------------------------------------------------
     0| 2.61e-15  2.22e-16  3.55e-15 -1.78e-15  1.00e-01  5.50e-05 
------------------------------------------------------------------
status:  solved
timings: total: 5.61e-05s = setup: 4.21e-05s + solve: 1.40e-05s
	 lin-sys: 6.56e-07s, cones: 1.33e-06s, accel: 2.90e-08s
------------------------------------------------------------------
objective = -0.000000
------------------------------------------------------------------

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 7, 2023

Codecov Report

Patch coverage: 13.79% and project coverage change: -0.52 ⚠️

Comparison is base (0919995) 98.10% compared to head (904b391) 97.59%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3271      +/-   ##
==========================================
- Coverage   98.10%   97.59%   -0.52%     
==========================================
  Files          34       34              
  Lines        4704     4733      +29     
==========================================
+ Hits         4615     4619       +4     
- Misses         89      114      +25     
Impacted Files Coverage Δ
src/optimizer_interface.jl 88.42% <13.79%> (-8.46%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@odow odow changed the title Objective starting values WIP: Objective starting values Mar 7, 2023
@odow
Copy link
Copy Markdown
Member

odow commented Mar 7, 2023

I dunno, this feels too niche. Couldn't the Objective.SlackBridge have a final_touch that checked for VariablePrimalStart and set any ConstraintPrimalStart/ConstraintDualStart appropriately?

@blegat
Copy link
Copy Markdown
Member Author

blegat commented Mar 8, 2023

These attributes could be defined in the bridge itself. Doing it in final_touch is weird. It's confusing to have starting values set without the user asking for it.
If users use this JuMP function they it will all be under the hood

@odow
Copy link
Copy Markdown
Member

odow commented Mar 8, 2023

Doing it in final_touch is weird

Why? The start value depends on other parts of the model that may not be present at the time of the caller. That's exactly why we added final_touch.

If users use this JuMP function they it will all be under the hood

It seems weird to have a JuMP function for a very specific part of MOI (MOI.Bridges.Objective.SlackBridge).

@blegat
Copy link
Copy Markdown
Member Author

blegat commented Mar 9, 2023

Why? The start value depends on other parts of the model that may not be present at the time of the caller. That's exactly why we added final_touch.

Because you will have starting values set to the solver even if you didn't set any

It seems weird to have a JuMP function for a very specific part of MOI (MOI.Bridges.Objective.SlackBridge).

We wouldn't have a JuMP function just for this. set_start_values would just take care of setting these attributes that would be defined in MOI (possible even inside the bridges

@odow
Copy link
Copy Markdown
Member

odow commented Jun 8, 2023

If jump-dev/MathOptInterface.jl#2194 is merged, this PR would become

MOI.set(model, MOI.Bridges.Objective.SlackBridgePrimalDualStart(), true)

@odow
Copy link
Copy Markdown
Member

odow commented Jun 9, 2023

Closing for now. Once the MOI PR is merged we can look at this again. The issue will stay open.

@odow odow closed this Jun 9, 2023
@odow odow deleted the bl/slack_start branch August 27, 2023 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants