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

osqp does not always return the same result eventhough parameters are unchanged #19

Closed
MetoriGit opened this issue Jun 1, 2020 · 4 comments

Comments

@MetoriGit
Copy link

Hi Gentlemen,

I notice that OSQP does not always return the same result eventhough the parameters are the same (see hereafter a test I ran on my PC):

data.zip

load(file = "C:/temp/data.RData")

tries <- data.frame()
for(i in 1:200)
{
quadraticProgram <- osqp::osqp(P = osqp.P, q = osqp.q, A = osqp.A, l = osqp.l, u = osqp.u, pars = osqp::osqpSettings(eps_abs = 0.000001, eps_rel = 0.000001, verbose = FALSE))
result_RstudioDesktop <- quadraticProgram$Solve()

tries <- rbind(tries, data.frame(try <- i, iter <- result_RstudioDesktop$info$iter, pri_res <- result_RstudioDesktop$info$pri_res, dua_res <- result_RstudioDesktop$info$dua_res))
}

most of the time the solver returns the same result after 950 iterations but few times it ended after 875 or 850 iterations with another result (not far from the other one).

Reading the documentation of the solver, I can't find what is the default starting point of the algorithm (x0, y0, and z0). I wonder if the difference comes from a different starting point or if it comes from machine precision at a key point of the algorithm (test for stopping conditions or checking for a change on step size parameters).

Can you confirm that OSQP should always return the same result when called with the same parameter (cold start)? Can you help me finding out why I observed this unwilled phenomenon?

Kind regards,

Philippe Carpentier

@goulart-paul
Copy link
Collaborator

goulart-paul commented Jun 1, 2020

The reason is that the adaptive_rho feature is configured by default to update rho and refactor the linear system in the solver based on the relative time taken between the factor phase and the iteration phase of the solver. The factorisation code is deterministic, but the execution time can vary b/c it is competing for CPU resources with other things on the machine.

If you want completely repeatable behaviour, I would suggest configuring the solver the update rho instead after a fixed number of iterations (maybe try 50-100 to start).

@MetoriGit
Copy link
Author

Hi Paul,

Many thanks Paul for your quick and comprehensive answer!
It works fine on my side. But just to be sure, can you confirm that I only need to add in osqpSettings:
adaptive_rho_interval = 100

Kind regards,

Philippe Carpentier

@goulart-paul
Copy link
Collaborator

I think that should work, yes. Reopen the issue if not though.

@MetoriGit
Copy link
Author

Once more, many thanks Paul,

Philippe Carpentier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants