Skip to content

added slepc eigensolver as an option for megaman #90

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

keceli
Copy link

@keceli keceli commented Feb 16, 2018

Currently works for eigendecompositon of symmetric matrices.
Passes unit tests, but I haven't run any benchmarks to see the performance.

@yuchaz
Copy link
Collaborator

yuchaz commented Feb 17, 2018

Hi @keceli can you check your code for python3.4 and 3.5? Seems like it failed on both versions.

@keceli
Copy link
Author

keceli commented Feb 18, 2018

Hi @yuchaz. I couldn't figure out what is incompatible with Python 3 in my code. Any suggestions?

@yuchaz
Copy link
Collaborator

yuchaz commented Feb 18, 2018

Hi @keceli

That is caused by the relative import issue in python 3. See PEP-404#Imports for details. In short, the implicit relative import is no longer supported in python 3. Therefore, you will have to do the following changes in eigendecomp.py:

# In line 2, add
from __future__ import absolute_import
# this is for python 2 compatibility 

# In line 28, change it to
from . import slepctools as slepc

Something needed to be added

  1. In eigendecomp.py line 308, need to add the error msg for SLPEC as well.
  2. The SLEPC_LOADED flag is not used, you have to use it in check_eigen_solver function.
  3. Add slepc4py in the installation guide under the Installation from source section in README.md.
  4. That will be good if you can run some benchmarking and write some descriptions about why should we use SLPEC.

Thanks for your contribution!

Added info for slepc4py on README file.
@keceli
Copy link
Author

keceli commented Feb 19, 2018 via email

@yuchaz
Copy link
Collaborator

yuchaz commented Feb 19, 2018

Hi @keceli Sadly I cannot reproduce the test failure on my computer with python=3.4 therefore I am not 100% sure where the bug comes from.

I printed out the reconstruction error of each eigensolvers and found out that the reconstruction error of slepc is twice larger than other solvers. I suspect it's from the null space computation since you compute it using arpack solver directly and the arpack eigensolver is not so numerically stable.

Some workarounds will be use other solver to compute null space when using the slepc eigensolver (e.g. dense or lobpcg). But it will be nice if you can finish the null space computation for slepc since it will be more consistent. :)

Thank you!

@keceli
Copy link
Author

keceli commented Feb 22, 2018

I tested it on theta and printed reconstruction errors. I don't get any failures.

(base) 19:36:46|thetalogin5|megaman-slepc> nosetests --nocapture /home/keceli/miniconda2/lib/python2.7/site-packages/megaman/embedding/tests/test_lle.py
/home/keceli/.local/lib/python2.7/site-packages/petsc4py/lib/__init__.py:121: UserWarning: ignored arch: 'arch-theta-opt-cray', using: 'arch-gcc-opt'
  (os.path.pathsep.join(arch_env), arch))
../home/keceli/miniconda2/lib/python2.7/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
************************************
Reconstruction error: auto 0.0400798930466
************************************
/home/keceli/miniconda2/lib/python2.7/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
************************************
Reconstruction error: dense 0.0400798930466
************************************
/home/keceli/miniconda2/lib/python2.7/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
************************************
Reconstruction error: arpack 0.0694767617058
************************************
/home/keceli/miniconda2/lib/python2.7/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
/home/keceli/miniconda2/lib/python2.7/site-packages/megaman/utils/eigendecomp.py:63: UserWarning: lobpcg does not perform well with small matrices or with large numbers of vectors. Switching to 'dense'
  warnings.warn("lobpcg does not perform well with small matrices or "
************************************
Reconstruction error: lobpcg 0.0400798930466
************************************
/home/keceli/miniconda2/lib/python2.7/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
************************************
Reconstruction error: slepc 0.0380200814498
************************************
/home/keceli/miniconda2/lib/python2.7/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
************************************
Reconstruction error: amg 0.0400798930466
************************************
./home/keceli/miniconda2/lib/python2.7/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
/home/keceli/miniconda2/lib/python2.7/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
/home/keceli/miniconda2/lib/python2.7/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
/home/keceli/miniconda2/lib/python2.7/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
/home/keceli/miniconda2/lib/python2.7/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
/home/keceli/miniconda2/lib/python2.7/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
.
----------------------------------------------------------------------
Ran 4 tests in 1.399s

OK

@yuchaz
Copy link
Collaborator

yuchaz commented Feb 22, 2018

Hi @keceli I ran on my computer with python=3.5 and got the reconstruction error. I think it's because of some numerical instability issue. Can you try with another environment? I will also try to debug it :)

Yuchia

@keceli
Copy link
Author

keceli commented Feb 22, 2018

Thanks @yuchaz for looking into it. I tried with python 3.6 and it still doesn't give an error. I get errors only when I change the seed, but that error comes from arpack.

(base) 21:58:00|thetalogin5|megaman-slepc>  nosetests --nocapture /home/keceli/miniconda3/lib/python3.6/site-packages/megaman/embedding/tests/test_lle.py
..*************
Reconstruction error for numpy: 0.040312589381387036
*************
/home/keceli/miniconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
*************
Reconstruction error for auto: 0.04007989304659544
*************
/home/keceli/miniconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
*************
Reconstruction error for dense: 0.04007989304659544
*************
/home/keceli/miniconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
*************
Reconstruction error for arpack: 0.06947676170584381
*************
/home/keceli/miniconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
/home/keceli/miniconda3/lib/python3.6/site-packages/megaman/utils/eigendecomp.py:63: UserWarning: lobpcg does not perform well with small matrices or with large numbers of vectors. Switching to 'dense'
  warnings.warn("lobpcg does not perform well with small matrices or "
*************
Reconstruction error for lobpcg: 0.04007989304659566
*************
/home/keceli/miniconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
*************
Reconstruction error for slepc: 0.038020081449784554
*************
/home/keceli/miniconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
*************
Reconstruction error for amg: 0.04007989304659555
*************
./home/keceli/miniconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
/home/keceli/miniconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
/home/keceli/miniconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
/home/keceli/miniconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
/home/keceli/miniconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
/home/keceli/miniconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:393: DeprecationWarning: Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.
  " instead.", DeprecationWarning)
.
----------------------------------------------------------------------
Ran 4 tests in 1.404s

OK

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

Successfully merging this pull request may close these issues.

2 participants