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

[Feature Request] Parameters and Variable (or Solver) Extension #225

Closed
utotch opened this issue Apr 16, 2018 · 3 comments
Closed

[Feature Request] Parameters and Variable (or Solver) Extension #225

utotch opened this issue Apr 16, 2018 · 3 comments

Comments

@utotch
Copy link

utotch commented Apr 16, 2018

I'm a heavy user of Convex.jl, but I often feel that I want some additional feature of it in comparison with CVXPY.

(1) Parameters
CVXPY has a "Parameters" feature that only change non-variable value and solve the same problem frequently.
http://www.cvxpy.org/en/latest/tutorial/intro/index.html#parameters

As you know, this kind of use often appears in Model Predictive Control, Moving Horizon Estimation, etc.
I feel Parameters feature is very useful.

(2) Variable / Solver extension
CVXPY can be easily extended default ability of "convex problem" solving algorithm and can solve some non-convex problems
e.g. Convex-Concave procedure, non-convex QP, etc.
DCCP
https://github.com/cvxgrp/dccp
QCQP
https://github.com/cvxgrp/qcqp
NCVX
https://github.com/cvxgrp/ncvx

--
I think these kinds of features are very useful.
I tried to extend Convex.jl by using traits etc, but I don't understand elegant way.

What do you think?

@utotch
Copy link
Author

utotch commented Feb 22, 2019

I found that we can already use a Parameter mechanism by doing as follows:

# Parameter
# I'm jerous of Parameter in cvxpy
# https://www.cvxpy.org/api_reference/cvxpy.expressions.html#parameter
# we don't need to recreate prob object and we can reuse it by using Constant as Parameter
# solve problem for various q value
using Convex
using SCS; solver = SCSSolver(verbose=0)

P = [1 0; 0 2]
qs = [[3.0,4.0], [5.0,6.0], [7.0,8.0]] # Should be Array{Float64}
x = Variable(2)
q_param = Constant(qs[1]) # Parameter (use Constant)
@show q_param.id_hash
prob = minimize(0.5*quadform(x,P)+dot(q_param,x), [0 <= x])
for q in qs
#    @show q_param.value
#    @show q
    copyto!(q_param.value, q) # q_param.value is immutable but we can copy value to it
    Convex.solve!(prob, solver)
    @show x.value
end

@ericphanson
Copy link
Collaborator

The functions fix! and free! can be used for this as well. You can fix! a variable to a value (fix!(x, v)), then solve the problem. Then you can fix! it again to a new variable and solve again (this was broken until #299 so it may not have worked if you tried before). You can also free!(x) to make it a variable again etc.

Does that cover your use case? (If so, maybe it's then a matter of updating the documentation to make it clear how do to this).

@odow
Copy link
Member

odow commented Jan 19, 2024

Closing because documented in https://jump.dev/Convex.jl/stable/advanced/#Fixing-and-freeing-variables.

See also #383.

@odow odow closed this as completed Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants