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

ENH: re-enabled old sv lapack routine as defaults #7879

Closed
wants to merge 4 commits into from

Conversation

zerothi
Copy link
Contributor

@zerothi zerothi commented Sep 17, 2017

This fixes the speed regression in #7847. Since the default
change of sv to svx the solve routine suffered a huge performance
penalty for anything but low order NRHS.

This commit fixes that issue by enabling the use of either 1) the
svx or 2) the sv routines. With a default on the latter.

However, the main funtionality by using svx was the easy check
of the condition number to assert a non-singular matrix.
This commit adds a call to the con routines to extract the
appropriate condition number. This force the addition of:

  • lamch (machine precision extraction)
  • gecon (condition number calculation from LU factorization)
  • lange (1-norm of matrix)

This commit adds to arguments (and deprecates one) by:

  • refine, bool, decides whether the svx (true) or sv (false)
    routines should be used.
  • form = 'none', 'trans', 'conj' which refers to the form
    of the solution step. This is only valid if refine=True
    A ValueError will be issued if not none and refine=False.
    This keyword deprecates the "transposed" boolean value which
    only allowed 'T' (real) and 'C' (complex) but not 'T' for
    complex.

A fix for the deprecated sym_pos keyword which wasn't used in the previous
version.

A couple of additional tests have been added, mainly to check the arguments.

@zerothi
Copy link
Contributor Author

zerothi commented Sep 17, 2017

Lets see if it passes tests through ci, it does so locally.

@pv
Copy link
Member

pv commented Sep 17, 2017

Please make, as a first step, a PR that does not add any new options but only reverts to the gesv+gecon approach. I don't think we want to add them to 1.0.0 at the least --- it's already branched and only bugfixes (such as the one concerning the performance) should go in.

After that, we can discuss about the possibility to have the added options.

@ilayn
Copy link
Member

ilayn commented Sep 17, 2017

Also there are symmetric but not hermitian complex matrices and "T" is used for these matrices for right inversion. Thus zsysv and zhesv solves different problems.

@zerothi
Copy link
Contributor Author

zerothi commented Sep 18, 2017

@ilayn for the gesvx routines one can pass TRANS='T' or TRANS='C', for a^T x = b and a^H x = b, respectively. Both TRANS/='N' are only for the gesvx routines. Anything, but 'N' are not accepted for he/sy/po routines.

@zerothi
Copy link
Contributor Author

zerothi commented Sep 18, 2017

@pv But the change to the other routines has a regression on the precision of the algorithm. The only way to circumvent this is by using the x routines of LAPACK.
Is this wanted?

@pv
Copy link
Member

pv commented Sep 18, 2017 via email

@pv
Copy link
Member

pv commented Sep 18, 2017 via email

@zerothi
Copy link
Contributor Author

zerothi commented Sep 18, 2017

Ok, I will amend, this forces me to remove the transposed keyword (issue a deprecation warning) as it is only available for the gesvx routines.

@rgommers
Copy link
Member

@zerothi there's nothing wrong with this PR for master, so how about leaving the desired behavior in here, and sending a separate PR against 1.0.x that simply reverts to the pre-0.19.0 situation?

@zerothi
Copy link
Contributor Author

zerothi commented Sep 18, 2017

ok, will do. Will then just add a deprecation warning for the the transposed keyword in this pr to make it follow the PR i will create for 1.0.x.

@pv
Copy link
Member

pv commented Sep 18, 2017 via email

@zerothi
Copy link
Contributor Author

zerothi commented Sep 18, 2017

As I said, I won't remove it, simply deprecate it?

@zerothi
Copy link
Contributor Author

zerothi commented Sep 18, 2017

What I can do is:

for master enable getrf + gesv with my newly changed form keyword

  1. This current PR with some minor changes to allow form for assume_a = 'gen', regardless of used routine (gesv vs. gesvx).
  2. Deprecate transposed keyword

for 1.0.x, do not allow gesv and transposed keyword. Its use only allowed T for real, and C for complex, it didn't allow T for complex cases. So if you want the same functionality you are imposing certain constraints on the user, i.e. the user may expect to get T for a complex solution, whereas it actually does C?
My point being, transposed=True isn't a ^T x = b when a is complex in the current solve.

Or would you rather that transposed in 1.0.x behaves as in the old version, which in my opinion will just be a serious regression when they go to 1.X>0.Y?

@pv
Copy link
Member

pv commented Sep 18, 2017 via email

@zerothi
Copy link
Contributor Author

zerothi commented Sep 18, 2017

@pv i think the transposed keyword was passing 'H' in the old scipy, whereas it only accepts 'C'. Hence the argument error. So yes, a bug in the previous solve for complex cases.

As for 1.1. Since the transposed keyword is ambiguous, wouldn't it be better to rename it to form? I mean the form of the equations to be solved is non-ambiguous whereas transposed is not so much, could be a^T, or x^T.

I will hardly think many people are aware of its existence (it just entered in 0.19) and we can retain it in 1.1 as a backfall (same as sym_pos keyword).

I much prefer fixing non-ideal keyword names, rather than continuing with ambiguous names?

So, for master, I know what to do, for 1.0.x, please suggest your preferred way of route, still transposed={False, 'N', 'T', 'C'}, or as I suggested: form={'none', 'trans', 'conj'}?

@ilayn
Copy link
Member

ilayn commented Sep 18, 2017

I'm having hard time following the discussion but I think I'm a bit closer to what @pv mentioned about reverting it to old version (if it is really the problem, since we also didn't have any complaints regarding the speed until now). Because there is a time pressure for 1.0 or not touching it and performing a full surgery until 1.0.1 or 1.1. Yesterday, I've done some tests and indeed the time is mostly spent on refinement steps.

Keyword names are of course open for improvement or renaming. But transpose issue is simple: complex matrices can also have T keyword for complex generic matrices and if sym is given for complex matrices it shouldn't switch to hermitian solution. Otherwise it is not correct.

I didn't test line by line but just mentioning it if that's the case. But form is not related to the thing it represents or maybe I don't understand what form refers to. It's a switch between AX=B and A^(T)X=B so it's a property of the coefficient matrix. Also LAPACK naming is similar with trans keyword.

@ilayn
Copy link
Member

ilayn commented Sep 18, 2017

I'll check about the bug as soon as I have some time.

@zerothi
Copy link
Contributor Author

zerothi commented Sep 18, 2017

@ilayn yes, I agree to the TRANS name, however the lapack documentation specifies that the equation has the form (hence the name) which I think justifies the name, short and concise.
If there are other, better names, I am very much open to suggestions ;)

This fixes the speed regression in scipy#7847. Since the default
change of sv to svx the solve routine suffered a huge performance
penalty for anything but low order NRHS.

This commit fixes that issue by enabling the use of either 1) the
svx or 2) the sv routines. With a default on the latter.

However, the main funtionality by using svx was the easy check
of the condition number to assert a non-singular matrix.
This commit adds a call to the con routines to extract the
appropriate condition number. This forces the addition of:

   - lamch (machine precision extraction)
   - gecon (condition number calculation from LU factorization)
   - lange (1/I-norm of matrix)

This commit adds to arguments (and deprecates one) by:
  - refine, bool, decides whether the svx (true) or sv (false)
    routines should be used.
  - form = 'none', 'trans', 'conj' which refers to the form
    of the solution step. This is only valid if assume_a='gen'.
    A ValueError will be issued if not 'gen'.
    This keyword deprecates the "transposed" boolean value which
    only allowed 'T' (real) and 'C' (complex) but not 'T' for
    complex.

A fix for the deprecated sym_pos keyword which wasn't used in the previous
version. This has sadly resulted in two delocalized tests failing because
sym_pos, see the OptimizeWarning for scipy/optimize/tests/test_linprog.py.

A couple of additional tests have been added, mainly to check the arguments.

Signed-off-by: Nick Papior <nickpapior@gmail.com>
The solve routine, when using the sym_pos keyword, can when the
optimization approaches result be inaccurate. Hence, the fallback should
be allowed in the tests. I.e. added a catch of OptimizeWarnings.

Signed-off-by: Nick Papior <nickpapior@gmail.com>
@zerothi
Copy link
Contributor Author

zerothi commented Sep 19, 2017

I have now squashed some testing commits into two commits and here are some final remarks that needs either approval or change, but at least requires some comments from you:

  1. When reverting to the gesv routines certain tests was failing. One was fixed in c7370f3 which I think can easily be justified from the documentation of the linprog routine, i.e. it automatically backfalls to the non-symmetric case. This wasn't seen when using the gesvx routines because the sym_pos keyword was affected by the bug as mentioned above. I can't see this should be a problem.

  2. Another error arises in the TestExpM.test_triangularity_perturbation (scipy/sparse/linalg/tests/test_matfuncs.py)
    Here a RuntimeWarning is issued due to the condition number. In all older versions of scipy, (pre gesvx) this could not have been issued due to no checks. For the 0.19.X versions the gesvx routines actually passes these tests and thus it was a hidden failure. I am not sure what you think should be the path forward? I am not experienced enough to see if this is due to a corner case of the created test, or whether the _solve_P_Q should fall-back on the gesvx routines?

Could you comment on the above things?
Sadly, when backporting this to 1.0.X the second option will be a problem because you intent to remove gesvx. How should we go about that?

@pv
Copy link
Member

pv commented Sep 19, 2017 via email

@zerothi
Copy link
Contributor Author

zerothi commented Sep 19, 2017

Ok, I can add that, but what about 1.0.X?

@pv
Copy link
Member

pv commented Sep 19, 2017 via email

@zerothi
Copy link
Contributor Author

zerothi commented Sep 19, 2017

Ah, yes, of course. I see. I will do that!

Signed-off-by: Nick Papior <nickpapior@gmail.com>
zerothi added a commit to zerothi/scipy that referenced this pull request Sep 19, 2017
This fixes the speed regression in scipy#7847. Since the default
change of sv to svx the solve routine suffered a huge performance
penalty for anything but low order NRHS.

This commit fixes that issue by converting to the sx routines,
with condition number checking.

However, the main funtionality by using svx was the easy check
of the condition number to assert a non-singular matrix.
This commit adds a call to the con routines to extract the
appropriate condition number. This forces the addition of:

   - lamch (machine precision extraction)
   - gecon (condition number calculation from LU factorization)
   - lange (1/I-norm of matrix)

This commit adds a ValueError issued for complex matrices
an transposed=True (which was a bug in prior versions).
The complex transposed case could be solved, but it is ambiguous whether
it should be the transposed or Hermitian transposed. Hence, a valueerror is
raised. See master (scipy#7879) for a fix.

A couple of additional tests have been added, mainly to check the arguments.

Signed-off-by: Nick Papior <nickpapior@gmail.com>
@zerothi
Copy link
Contributor Author

zerothi commented Sep 19, 2017

@pv @rgommers @ilayn ready for review

Signed-off-by: Nick Papior <nickpapior@gmail.com>
@rgommers rgommers added enhancement A new feature or improvement scipy.linalg labels Sep 22, 2017
@rgommers rgommers added this to the 1.1.0 milestone Sep 22, 2017
pv pushed a commit that referenced this pull request Sep 23, 2017
This fixes the speed regression in gh-7847. Since the default
change of sv to svx the solve routine suffered a huge performance
penalty for anything but low order NRHS.

This commit fixes that issue by converting to the sx routines,
with condition number checking.

However, the main funtionality by using svx was the easy check
of the condition number to assert a non-singular matrix.
This commit adds a call to the con routines to extract the
appropriate condition number. This forces the addition of:

   - lamch (machine precision extraction)
   - gecon (condition number calculation from LU factorization)
   - lange (1/I-norm of matrix)

This commit adds a ValueError issued for complex matrices
an transposed=True (which was a bug in prior versions).
The complex transposed case could be solved, but it is ambiguous whether
it should be the transposed or Hermitian transposed. Hence, a valueerror is
raised. See master (#7879) for a fix.

A couple of additional tests have been added, mainly to check the arguments.
rgommers pushed a commit to rgommers/scipy that referenced this pull request Sep 26, 2017
This fixes the speed regression in scipygh-7847. Since the default
change of sv to svx the solve routine suffered a huge performance
penalty for anything but low order NRHS.

This commit fixes that issue by converting to the sx routines,
with condition number checking.

However, the main funtionality by using svx was the easy check
of the condition number to assert a non-singular matrix.
This commit adds a call to the con routines to extract the
appropriate condition number. This forces the addition of:

   - lamch (machine precision extraction)
   - gecon (condition number calculation from LU factorization)
   - lange (1/I-norm of matrix)

This commit adds a ValueError issued for complex matrices
an transposed=True (which was a bug in prior versions).
The complex transposed case could be solved, but it is ambiguous whether
it should be the transposed or Hermitian transposed. Hence, a valueerror is
raised. See master (scipy#7879) for a fix.

A couple of additional tests have been added, mainly to check the arguments.

(cherry picked from commit 8e56f42)
@ilayn
Copy link
Member

ilayn commented Mar 29, 2018

@zerothi I think after the cherrypicking the commits this is also now redundant right?

@zerothi
Copy link
Contributor Author

zerothi commented Mar 29, 2018

Agreed, this PR was trying to retain both vx and v routines. Since the discussion landed on not needed I will close, thanks!

@zerothi zerothi closed this Mar 29, 2018
@pv pv modified the milestone: 1.1.0 Apr 15, 2018
@zerothi zerothi deleted the solve-speed branch August 6, 2020 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or improvement scipy.linalg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants