Giter Club home page Giter Club logo

qpth's Introduction

qpth's People

Contributors

bamos avatar dboyliao avatar heidekrueger avatar msakai avatar niklasnolte avatar sbarratt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qpth's Issues

How to suppress warning

Dear authors,

How can I suppress this warning?

qpth warning: Returning an inaccurate and potentially incorrect solution.

Missing comma in setup.py file uploaded to pipy.

While installing qpth using pip install qpth I encountered this bug. Seems to be ok on the github repo but the downloaded archive from pipy confirmed the missing comma.

Collecting qpth
  Downloading qpth-0.0.15.tar.gz (11 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [3 lines of output]
      error in qpth setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Expected end or semicolon (after version specifier)
          **numpy>=1<2**
               ~~~^
      [end of output]

Is the Sinkhorn Knopp algorithm possible?

Hi @bamos,

I'm just getting started with qpth and am just a beginner with mathematical optimisation. To be honest I'm not so sure I know what I'm doing?

Can I ask you advice please? Is it possible to implement the simple 1D Sinkhorn Knopp algorithm, (to approximate the earth movers distance), using qpth? It's not a complicated quadratic program, and doesn't have to be efficient, just understandable 👍

The algorithms implemented in numpy here, (right at the top)

https://github.com/rflamary/POT/blob/master/ot/bregman.py

and it's also been implemented as a loss layer in mocha.jl, here

https://github.com/pluskid/Mocha.jl/blob/master/src/layers/wasserstein-loss.jl#L70

so I guess it should be possible? I just don't know how to do it with qpth, in pytorch?

It definitely doe'st need any thing complicated as it can be done in about 10 lines in MATLAB,

https://uk.mathworks.com/matlabcentral/fileexchange/52930-sinkhorn-knopp-algorithm-for-matrix-normalisation?focused=5332757&tab=function

Thank you very much for your help 👍

Can we solve QP with only equality constraints?

I have set inequality variables 'G' and 'h' as dummy variable Variable(torch.Tensor()),
but line 87 in qp.py: _, nineq, nz = G.size()
will raise problem: ValueError: not enough values to unpack (expected 3, got 1)

Non convex task solver

Hi, the idea of Optnet seems to be a perfect solution to my problem. My task is non convex, but it is proved that every local optimum is global optimum. How can I apply this package on my problem? I tried to use sequential quadratic programming but it was very slow. Is there any fast way to solve my problem? Thanks!

Not compatible with torch 1.2.0

In the torch document of 1.1.0 there is the following statement:
"LU factorization with pivot = False is not available for CPU, and attempting to do so will throw an error. However, LU factorization with pivot = False is available for CUDA."

So running torch 1.2.0 with the current qpth we found the following issue:

Traceback (most recent call last):
File "/home/deiplusay/.local/lib/python3.7/site-packages/qpth/solvers/pdipm/batch.py", line 385, in pre_factor_kkt
Q_LU = btrifact_hack(Q)
File "/home/deiplusay/.local/lib/python3.7/site-packages/qpth/solvers/pdipm/batch.py", line 14, in btrifact_hack
return x.btrifact(pivot=not x.is_cuda)
AttributeError: 'Tensor' object has no attribute 'btrifact'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "optnet_test.py", line 55, in
print(opt(torch.rand(16,100)))
File "/home/deiplusay/.local/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in call
result = self.forward(*input, **kwargs)
File "optnet_test.py", line 50, in forward
x = QPFunction(verbose=False)(Q, x, self.G, h, e, e)
File "/home/deiplusay/.local/lib/python3.7/site-packages/qpth/qp.py", line 91, in forward
self.Q_LU, self.S_LU, self.R = pdipm_b.pre_factor_kkt(Q, G, A)
File "/home/deiplusay/.local/lib/python3.7/site-packages/qpth/solvers/pdipm/batch.py", line 391, in pre_factor_kkt
""")

The proposed fix should replace btrifact() with torch.lu()

RunTime Error from e = Variable(torch.Tensor())

Sorry for my troubles, but why does using the e = Variable(torch.Tensor) raise RuntimeError: expected a Variable argument, but got FloatTensor in a recursive class implementation? I mean, e is already a Variable as defined on Line 77. The relevant call stack is

RuntimeError: expected a Variable argument, but got FloatTensor
> /home/robotec/catkin_ws/src/RAL2017/pyrnn/src/model.py(77)qp_layer()
     75             h = self.h.unsqueeze(0).expand(nBatch, nineq)
     76             e = Variable(torch.Tensor())
---> 77             x = QPFunction()(x, Q, p, G, h, e, e)
     78             return x
     79         self.qp_layer = qp_layer

Tests fail under pytorch 0.4

Hi,
The folks over at pytorch are working on cutting a new 0.4 release. We'd like to make the transition as smooth as possible, so we've been testing a number of community repos.

I ran into some test errors when running qpth tests against pytorch 0.4. Here is a repro script:

# Install pytorch-nightly (Currently our pre-release branch)
conda install pytorch-nightly -c pytorch

# Run tests
cd qpth/
nosetests -v -d test.py

The outputs of these tests are listed in this gist. These failures could be problems with pytorch / I also might not be running them correctly, so I'm looking into them as well.

cc @soumith

Running Error

When I run qpth in pytorch1.1, it shows that the 'factor_kkt_eye = torch.eye(nineq).repeat(nBatch, 1, 1).type_as(R).bool()' in 'qpth/solvers/pdipm/batch.py' is error because tensor hass no attribute bool.

Can‘t solve QP problem when dimension is too high.

When I try this:

G = torch.eye(2000).expand(8,2000,2000).cuda()
e = torch.randint(0,1,[8,2000]).cuda()
C = torch.eye(2000).expand(8,2000,2000).cuda()
h = torch.randint(0,1,[8,2000]).cuda()
A = torch.randn(8,100,2000).cuda()
b = torch.zeros(8,100).cuda()
qp_sol = QPFunction(verbose=False, maxIter=15)(G, e, C, h, A, b)

I get

RuntimeError: CUDA error: invalid configuration argument

How to solve this problem? Or it can't work when dimension is too high.

Trivial problem returns NaN

Running the following trivial QP problem returns NaN:

import torch
from qpth.qp import QPFunction

Q = torch.tensor([[[1.]]]) 
q = torch.tensor([[1.]])
A_eq = torch.tensor([[[0.]]])
A_ineq = torch.tensor([[[0.]]])
b_ineq = torch.tensor([[0.]])
b_eq = torch.tensor([[0.]])
QPFunction(verbose=True)(Q, q, A_ineq, b_ineq, A_eq, b_eq)

Output:

iter: 1, pri_resid: nan, dual_resid: nan, mu: nan
iter: 2, pri_resid: nan, dual_resid: nan, mu: nan
iter: 3, pri_resid: nan, dual_resid: nan, mu: nan
tensor([[nan]])

Ask what is the reason for this error, how to deal with it?

File "/home/ubuntuserver426/guoprogram/study/BQP/models/QP_layer.py", line 24, in forward
a = qp.QPFunction(verbose=False)(Q,p,G,h,A,b)
File "/home/ubuntuserver426/guoprogram/study/BQP/models/qpth0/qp.py", line 94, in forward
self.eps, self.verbose, self.notImprovedLim, self.maxIter)
File "/home/ubuntuserver426/guoprogram/study/BQP/models/qpth0/solvers/pdipm/batch.py", line 153, in forward
Q, D, G, A, rx, rs, rz, ry)
File "/home/ubuntuserver426/guoprogram/study/BQP/models/qpth0/solvers/pdipm/batch.py", line 340, in factor_solve_kkt
S_LU = btrifact_hack(S_)
File "/home/ubuntuserver426/guoprogram/study/BQP/models/qpth0/solvers/pdipm/batch.py", line 14, in btrifact_hack
return x.btrifact(pivot=not x.is_cuda)
File "/usr/local/lib/python3.5/dist-packages/torch/tensor.py", line 252, in btrifact
return super(Tensor, self).btrifact(pivot=pivot)
RuntimeError: failed to factorize some batch elements (min info == 52, max info == 52) at /pytorch/aten/src/THC/generic/THCTensorMathBlas.cu:821

batch qp solve with equality constraints.

Hi, I am recently want to try to use qpth to solve some of my own problems (and combine it into optNet later).
So my qp problem include only equality constraints, no inequality constraints, and I have encounter some problems and have some questions want to ask:

Does it necessary to have ineq? Originally I tried to give a

e = Variable(torch.Tensor())
as shown in the denoising example, but it raise some errros.
I found that in the code, there is

_, nineq, nz = G.size()
neq = A.size(1) if A.ndimension() > 0 else 0
assert(neq > 0 or nineq > 0)

which suggest so.
Is it because in the ref paper (Mattingley & Boyd, 2012), it introduce a slack variable on ineq?

I am a bit confuse on how to transform my qp problem into batch form.
For example there are 1000 unknown variables to solve, among them, I have equality constraints on 100 of them (which suggest only 900 variables needed to be solve).
If I divide them into batches, e.g. batchSize = 100..
How do I set up those eq constraints (because them seems global to the problem)..

thx a lot~

CVXPY not defined as dependency

Seems like CVXPY is not defined as a dependency. Package was successfully installed with pip, but got ModuleNotFoundError: No module named 'cvxpy' when trying to run it.

mismatch between shapes of tensors in qpth/solvers/pdipm/batch.py

I am using pytorch 0.4 from pytorch.org
the shape of M computed in line 83 doesn't match the shape of s. same story for M in line 88.

in specific, let m = torch.min(s, 1)[0].size()[0]. i.e. the shape of M before repeat(1,nineq).

computing M using line 83 gives a tensor of shape (1,m*nineq), which does not match the shape of s or z.

my fix:

M = torch.min(s, 1)[0]
msize = M.size()[0]
M = M.view(msize,1).repeat(1,nineq)
I = M < 0
s[I] -= M[I] - 1

I just want to know if such fix is correct.

Solving with floats sometimes gives bad solutions

  • Sometimes solving a problem with floats gives a really bad solution. The current workaround is to convert everything to doubles.
  • @riceric22 mentioned that on the CPU, using doubles doesn't fix the bad solution problem when it does fix it with CUDA.

Cannot perform LU factorization on Q

Hi, I want to solve 2-classes SVM in Euclidean space using your qpth. Here is my test code.

batch_size = 2
sample_num = 3
sample_dim = 4

X = torch.rand(batch_size, sample_num, sample_dim).cuda(3)
Y = torch.rand(batch_size, sample_num).cuda(3)
Y[Y>0.8], Y[Y<=0.8] = 1, -1

DY = torch.zeros(batch_size, sample_num, sample_num).cuda(3)
DY.as_strided(Y.size(), [DY.stride(0), DY.size(2) + 1]).copy_(Y)

Q = torch.eye(sample_dim).repeat(batch_size, 1, 1).cuda(3)
p = torch.Tensor().cuda()
A = torch.Tensor().cuda()
b = torch.Tensor().cuda()
G = -torch.matmul(DY, X)
h = -torch.ones(batch_size, sample_num)
w = QPFunction(verbose=False)(Q, p, G, h, A, b)

I set Q as an eye matrix, but it reports error as 'qpth Error: Cannot perform LU factorization on Q. Please make sure that your Q matrix is PSD and has a non-zero diagonal.' Why? What should I do? Thanks for your attention.

Error in running qpth of e2e-model-learning. AttributeError: module 'torch' has no attribute 'all'

Hello Bamos

I am trying to run code of "locuslab/e2e-model-learning/power_sched" repository. I am using pytorch =0.3.1 and torchvision= 0.2 as required by that repository. But when I run that, I get an error related to qpth as shown below .

> /usr/local/lib/python3.6/dist-packages/qpth/qp.py(84)forward()
     82                 for i in range(nBatch):
     83                     e, _ = torch.eig(Q[i])
---> 84                     if not torch.all(e[:,0] > 0):
     85                         raise RuntimeError('Q is not SPD.')'''

Hard to follow the equation (7), (8) in the OptNet paper

Thank you for your excellent work.
I am trying to understand the formulae of the OptNet paper, but some parts are hard to follow for me.

Especially in Eq. (7), the paper says

Thus, if we multiply the backward pass vector by the transpose of the differential matrix ...

But I cannot get the heart of the idea to multiply the transpose of the differential matrix (also, I wonder if the Q in the transpose in Eq. (7) is not Q^T?).

I could not understand how the equations in Eq. (8) are obtained from Eqs. (6) and (7).
It would help me so much if you could give me any hints.

Missing comma in setup.py

Requirement string in install_requires in setup.py should be 'numpy>=1,<2'. Pip ignores it but I had an issue while trying to manage dependencies with conda.

Infeasibility

Hello,

When we use cvx as solver, the problem may become infeasible. How can we deal with this problem? Actually, we noticed that the qpth never throw infeasible error, in this case, what does the gradient mean? Because the gradient is derived from KKT system, if the original problem is infeasible, there is no solution to the KKT system. Therefore the gradient doesn't seem to have any rigorous math meaning.

Many thanks
Jicheng

Output of qpfunction is nan

Hello!
I'm trying to add qpth into my learing method. But in traing stage, after a few steps, the output of qpFuntcion is all nan.
But I tried to call qpth in another script and set the input paramater as same as nan's input, the output now is right.
So I want to konw why?
Thanks.

Compute the gradient of z with regard to what?

I like this work very much, it's amazing to me!
But I have some confusing about it. Specifically, in the following QP question,

            \hat z =   argmin_z 1/2 z^T Q z + p^T z
                    subject to Gz <= h
                               Az  = b

Can we compute the gradients of z with regard to Q, p, G, h, A and b?

True sudoku solution?

Hi thanks for this project!
I was looking into the sudoku example, which I really like because I didn't know about the LPI method for solving it in the first place.

So I looked upon some blogposts about this technique, and found this one. Now I think I understand how we can convert constraints (all the sums that must add up to 1) to a matrix equality.

Now I'm trying to figure out the true solution to the simplified sudoku example, to remove the magical part of A and b construction 😄

I guess we dumped the block constraint, so that makes three sets of equality, applied to 4*4 possible indices (only one number per case, only one of each possible number per column, and only one of each possible number per row). Is it fair that it would make 48 equalities ? Shouldn't A be then of size (48,64) instead of (40,64) ?

Maybe the 48 equalities are not all independant ?

Btw, I think the markdown is a bit wrong between cell 5 and 6, I think it should be

y* = argmin_y 0.5 eps y^T y - p^T y
         s.t. Ay  = b
               y >= 0

(note the z replaced by y)

btrf / btrs -> btrifact / btrisolve

It looks like in pytorch master there is btrifact as a drop-in replacement for btrf, although btrisolve has a different API from btrs. For ease of usage it would be nice to use the mainline pytorch API instead of the forked pytorch.

Query for Equation (7) and (8) in main paper

Hello,
I'm reading this paper recently while get some problems in understanding the equations in your main paper.

May I ask how can I get Equation (7) to (6) and how to get Equation(8)? I can only understand the inverse multiplication of the left-hand-side matrix while confused about the right part of [(al/az*)^T,0,0]^T . Could you pls explain more on the derivation?

Thank you!

Cases where `neq==0` with pytorch 0.4.1

Need a fix for cases without equality constraints with pytorch 0.4.1.
For example:

import torch
from qpth.qp import QPFunction, QPSolvers

N, D = 4, 16
v = torch.randn(D)
L = torch.randn(N, D)
x = QPFunction(solver=QPSolvers.PDIPM_BATCHED)(
    torch.matmul(L, L.t()), 
    torch.matmul(v, L.t()), 
    torch.eye(N), 
    torch.zeros(N), 
    torch.Tensor(), 
    torch.Tensor()
)

Stack trace:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-1-c5f8050018cf> in <module>()
     11     torch.zeros(N),
     12     torch.Tensor(),
---> 13     torch.Tensor()
     14 )

___/lib/python3.6/site-packages/qpth/qp.py in forward(self, Q_, p_, G_, h_, A_, b_)
     92             zhats, self.nus, self.lams, self.slacks = pdipm_b.forward(
     93                 Q, p, G, h, A, b, self.Q_LU, self.S_LU, self.R,
---> 94                 self.eps, self.verbose, self.notImprovedLim, self.maxIter)
     95         elif self.solver == QPSolvers.CVXPY:
     96             vals = torch.Tensor(nBatch).type_as(Q)

___/lib/python3.6/site-packages/qpth/solvers/pdipm/batch.py in forward(Q, p, G, h, A, b, Q_LU, S_LU, R, eps, verbose, notImprovedLim, maxIter, solver)
    176         rs = ((-mu * sig).repeat(nineq, 1).t() + ds_aff * dz_aff) / s
    177         rz = torch.zeros(nBatch, nineq).type_as(Q)
--> 178         ry = torch.zeros(nBatch, neq).type_as(Q)
    179
    180         if solver == KKTSolvers.LU_FULL:

RuntimeError: sizes must be non-negative

Suggestions?

Clean up tests.

  • Misc clean up
  • Add CPU test that always runs
  • Make CUDA test only run if CUDA is present

Equality constraints not working in Pytorch 0.4.1

Hello.

It seems that the equality constraints are not working in the latest version.

When I run the classification experiement of OptNet at:
https://github.com/locuslab/optnet/tree/master/cls
with the
mnist lenet --proj simproj
arguments, qpth shows the following error.

I'm using qpth v0.0.13 with PyTorch 0.4.1.

Thanks.

Stack trace:


RuntimeError Traceback (most recent call last)
in ()
280
281 if name=='main':
--> 282 main()

in main()
208 for epoch in range(1, args.nEpoch + 1):
209 adjust_opt(args, optimizer, epoch)
--> 210 train(args, epoch, net, trainLoader, optimizer, trainF)
211 test(args, epoch, net, testLoader, optimizer, testF)
212 try:

in train(args, epoch, net, trainLoader, optimizer, trainF)
228 data, target = Variable(data), Variable(target)
229 optimizer.zero_grad()
--> 230 output = net(data)
231 loss = F.nll_loss(output, target)
232 # make_graph.save('/tmp/t.dot', loss.creator); assert(False)

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
475 result = self._slow_forward(*input, **kwargs)
476 else:
--> 477 result = self.forward(*input, **kwargs)
478 for hook in self._forward_hooks.values():
479 hook_result = hook(self, input, result)

~/optnet-master/cls/models.py in forward(self, x)
47 x = F.relu(self.fc1(x))
48 x = self.fc2(x)
---> 49 return self.projF(x)
50
51 class LenetOptNet(nn.Module):

~/optnet-master/cls/models.py in projF(x)
32 A = self.A.unsqueeze(0).expand(nBatch, 1, nCls)
33 b = self.b.unsqueeze(0).expand(nBatch, 1)
---> 34 x = QPFunction()(Q, -x.double(), G, h, A, b).float()
35 x = x.log()
36 return x

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/qpth/qp.py in forward(self, Q_, p_, G_, h_, A_, b_)
89
90 if self.solver == QPSolvers.PDIPM_BATCHED:
---> 91 self.Q_LU, self.S_LU, self.R = pdipm_b.pre_factor_kkt(Q, G, A)
92 zhats, self.nus, self.lams, self.slacks = pdipm_b.forward(
93 Q, p, G, h, A, b, self.Q_LU, self.S_LU, self.R,

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/qpth/solvers/pdipm/batch.py in pre_factor_kkt(Q, G, A)
409
410 LU_A_invQ_AT = btrifact_hack(A_invQ_AT)
--> 411 P_A_invQ_AT, L_A_invQ_AT, U_A_invQ_AT = torch.btriunpack(*LU_A_invQ_AT)
412 P_A_invQ_AT = P_A_invQ_AT.type_as(A_invQ_AT)
413

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/functional.py in btriunpack(LU_data, LU_pivots, unpack_data, unpack_pivots)
121 U = LU_data.new(LU_data.size()).zero_()
122 I_diag = torch.eye(sz).type_as(LU_data).byte().unsqueeze(0).expand(nBatch, sz, sz)
--> 123 L[I_diag] = 1.0
124 L[I_L] = LU_data[I_L]
125 U[I_U] = LU_data[I_U]

RuntimeError: The shape of the mask [1, 64, 64] at index 2 does not match the shape of the indexed tensor [1, 64, 1] at index 2

Error in running code of end to end learning program

Hello Bamos

In reference to your work with Priya Donti "Task-based End-to-end Model Learning
in Stochastic Optimization" [https://github.com/locuslab/e2e-model-learning.git]
I am trying to implement the battery storage code but unable to get the results.I am getting qpth error .Below attached is the code and error.

Running the main.py file in command line interface with

gives 

```iter: 0, pri_resid: 9.11662e+01, dual_resid: 1.44910e-14, mu: 7.04911e+01
iter: 1, pri_resid: 1.55261e+01, dual_resid: 3.30352e-14, mu: 1.79035e+01
iter: 2, pri_resid: 1.32344e+00, dual_resid: 3.38888e-14, mu: 2.72255e+00
iter: 3, pri_resid: 1.31702e-01, dual_resid: 3.35632e-14, mu: 4.85668e-01
iter: 4, pri_resid: nan, dual_resid: nan, mu: nan
iter: 5, pri_resid: nan, dual_resid: nan, mu: nan
iter: 6, pri_resid: nan, dual_resid: nan, mu: nan
iter: 7, pri_resid: nan, dual_resid: nan, mu: nan
iter: 8, pri_resid: nan, dual_resid: nan, mu: nan
iter: 9, pri_resid: nan, dual_resid: nan, mu: nan
iter: 10, pri_resid: nan, dual_resid: nan, mu: nan
iter: 11, pri_resid: nan, dual_resid: nan, mu: nan
iter: 12, pri_resid: nan, dual_resid: nan, mu: nan
iter: 13, pri_resid: nan, dual_resid: nan, mu: nan
iter: 14, pri_resid: nan, dual_resid: nan, mu: nan
iter: 15, pri_resid: nan, dual_resid: nan, mu: nan
iter: 16, pri_resid: nan, dual_resid: nan, mu: nan

--------
qpth warning: Returning an inaccurate and potentially incorrect solution.

Some residual is large.
Your problem may be infeasible or difficult.

You can try using the CVXPY solver to see if your problem is feasible
and you can use the verbose option to check the convergence status of
our solver while increasing the number of iterations.

Advanced users:
You can also try to enable iterative refinement in the solver:
https://github.com/locuslab/qpth/issues/6'''

Accessing dual variables

What's the recommended way to access the dual variables lams and nus obtained in the forward pass? Only zhats is returned.

LP instead of QP?

Hi Brandon! Thanks for the great code!

In example-cls-layer, I tried to use an LP layer instead of a QP one, i.e. Q = Variable(torch.zeros(self.nCls, self.nCls)).

Expectedly, I get RuntimeError: qpth Error: Cannot perform LU factorization on Q. Please make sure that your Q matrix is PSD and has a non-zero diagonal.

Any simple modifications I could make to get the LP working? Perhaps PDIPM is not the best for this special case of QP, but I'm only interested in playing around with this.

Thanks!

btrisolve() replaced by lu_solve() in Pytorch 1.3.0

Hello,

I'm using this package as an intermediate layer in our models. I found that with the newest Pytorch version, the package indicates that btrisolve() is replaced by lu_solve() and btrifact() is replaced by lu(). Literally replacing those two functions will yield CUDA memory access errors.

Also when switching back to Pytorch 1.0.1, the qpth package works but it is significantly (70 times) slower than CPU solvers, e.g. cvxpy. I think this problem is due to the version of newer PyTorch.

Could you suggest the best working environment (like the version of PyTorch) of the qpth package? This could really help out our project.

Thanks,
He Jiang

What is the mean of print?

Hi, thanks to your great work. During my optimization, it print that

iter: 0, pri_resid: 2.00879e+01, dual_resid: 3.45980e-05, mu: 2.15564e+00
iter: 1, pri_resid: 9.38095e-01, dual_resid: 2.89040e-05, mu: 1.54378e-01
iter: 2, pri_resid: 1.10201e-01, dual_resid: 1.68656e-05, mu: 3.06670e-02
iter: 3, pri_resid: 8.88062e-03, dual_resid: 1.45111e-05, mu: 3.15341e-03
iter: 4, pri_resid: 2.95888e-03, dual_resid: 1.42403e-05, mu: 1.35999e-03
iter: 5, pri_resid: 2.78638e-04, dual_resid: 1.49785e-05, mu: 2.77934e-04
iter: 6, pri_resid: 8.51825e-06, dual_resid: 1.65200e-05, mu: 5.20932e-05
iter: 7, pri_resid: 4.42947e-07, dual_resid: 1.60216e-05, mu: 1.87964e-06
iter: 8, pri_resid: 2.40871e-07, dual_resid: 1.67323e-05, mu: 3.06535e-08
iter: 9, pri_resid: nan, dual_resid: nan, mu: nan
iter: 10, pri_resid: nan, dual_resid: nan, mu: nan

I want to know what is the mean of pri_resid, dual_resid, and mu. In addition, does output nan normal? Does this represent divergence?

Torch.lu_solve is deprecated in favor of torch.linalg.lu_solve and will be removed in a future PyTorch release

Hello,

I obtained the following warning while using this library:

/home/tae/miniconda3/envs/smartags/lib/python3.10/site-packages/qpth/solvers/pdipm/batch.py:395: UserWarning: torch.lu_solve is deprecated in favor of torch.linalg.lu_solveand will be removed in a future PyTorch release.
Note that torch.linalg.lu_solve has its arguments reversed.
X = torch.lu_solve(B, LU, pivots)
should be replaced with
X = torch.linalg.lu_solve(LU, pivots, B)

Is qpth going to keep up with PyTorch updates?

Thank you

Accuracy issues with batches

Hi,
I am using the qpth solver to solve many qp's (i.e. core price computations) as batches in parallel. Now, comparing the prices (resulting variables) with the ones I receive from gurobi shows that the ones from qpth differ quite a bit (see below). It seems like this is more likely to happen with a batch size > 1.

image

I tried to use float and double as well as cpu and gpu. The result of qpth is always the same (or at least very similar).
I also compared the result from cvxpylayer to gurobi and they are very close.

This is what I get when setting verbose to True

image

Do you know why the accuracy is so bad and how it can be improved?
I'm using pytorch 1.3.0., qpth 0.0.15, gurobi 8.1.1.
Thanks.

Not running. btrisolve() issue

Hi

I wanted to use your QP solver because it seems the perfect solution to a problem I was facing. I need to obtain solutions of a neural network that meet some equalitiy conditions. Therefore, I considered a least-squares problem in the qp format.

imagen

constrained to Qx = q.
u is the output of my network.

I was trying to run this in the net, but I've foun the following error message

~\Anaconda3\lib\site-packages\qpth\solvers\pdipm\batch.py in pre_factor_kkt(Q, G, A)
    399     # for more details.
    400 
--> 401     G_invQ_GT = torch.bmm(G, G.transpose(1, 2).btrisolve(*Q_LU))
    402     R = G_invQ_GT.clone()
    403     S_LU_pivots = torch.IntTensor(range(1, 1 + neq + nineq)).unsqueeze(0) \

TypeError: btrisolve() takes 3 positional arguments but 4 were given


My test code (avoiding the constraints and using a dummy inequality) was:

u = torch.autograd.Variable(x_iso[:, :4, :].flatten().reshape(-1, 1))
I = torch.autograd.Variable(torch.eye(x.size()[0]))
G = torch.autograd.Variable(torch.eye(x.size()[0]))
h = torch.autograd.Variable(x + torch.rand(x.size()))
e = torch.autograd.Variable(torch.Tensor())
QPFunction()(I, u, G, h, e, e)

I've also tried to run the example at the repo and I got the same error message. Also changed the solver, but the result is also an error message. I'm using python3.6 in Win10. I had disabled the cuda() options.

Thx

how should i installed dpth?

I installed conda install cvxpy -c cvxgrp
but i get ModuleNotFoundError: No module named 'qpth' for from qpth.qp import QPFunction

Test script error

Hi Brandon @bamos,

I just tried to install and test, and got this error? Any ideas how to fix please?

(pyphi) ajay@ajay-h8-1170uk:~/PythonProjects/qpth-master$ python test.py
dp_fd: [-0.007144 0.004729 -0.010438 -0.00625 -0.006003 -0.001188 0.003218
0.010014 -0.001992 0.009883]
dp: [ 196.936678 -118.395094 -567.53345 -489.509252 -547.720813
114.844011 69.658027 215.148079 1320.564678 -557.036299]
Traceback (most recent call last):
File "test.py", line 184, in
test_dl_dp()
File "test.py", line 109, in test_dl_dp
npt.assert_allclose(dp_fd, dp, rtol=RTOL, atol=ATOL)
File "/home/ajay/anaconda3/envs/pyphi/lib/python3.6/site-packages/numpy/testing/utils.py", line 1411, in assert_allclose
verbose=verbose, header=header, equal_nan=equal_nan)
File "/home/ajay/anaconda3/envs/pyphi/lib/python3.6/site-packages/numpy/testing/utils.py", line 796, in assert_array_compare
raise AssertionError(msg)
AssertionError:
Not equal to tolerance rtol=0.0001, atol=0.01
(mismatch 100.0%)
x: array([-0.007144, 0.004729, -0.010438, -0.00625 , -0.006003, -0.001188,
0.003218, 0.010014, -0.001992, 0.009883])
y: array([ 196.936678, -118.395094, -567.53345 , -489.509252,
-547.720813, 114.844011, 69.658027, 215.148079,
1320.564678, -557.036299])

Thanks for your help,
Aj

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.