scipy-lectures / scientific-python-lectures

Tutorial material on the scientific Python ecosystem
https://lectures.scientific-python.org
Other
3.08k stars 1.19k forks source link

Fix LOBPCG Sakurai typos #776

Closed jarrodmillman closed 1 month ago

jarrodmillman commented 1 month ago

Still needs work (but it runs now):

$ python advanced/scipy_sparse/examples/lobpcg_sakurai.py
/home/jarrod/src/scientific-python-lectures/advanced/scipy_sparse/examples/lobpcg_sakurai.py:47: UserWarning: Exited at iteration 500 with accuracies 
[1158100.72206623    8047.95297708    6596.98347933]
not reaching the requested tolerance 1e-06.
Use iteration 0 instead with accuracy 
2.0908717846394285.

  eigs, vecs, resnh = sp.sparse.linalg.lobpcg(
/home/jarrod/src/scientific-python-lectures/advanced/scipy_sparse/examples/lobpcg_sakurai.py:47: UserWarning: Exited postprocessing with accuracies 
[5.4496576  0.42115509 0.40180266]
not reaching the requested tolerance 1e-06.
  eigs, vecs, resnh = sp.sparse.linalg.lobpcg(
Results by LOBPCG for n=2500

[1.6384843  0.17288616 0.16788489]

Exact eigenvalues

[0.06250005 0.0625002  0.06250044]

Elapsed time 1.311448997
/home/jarrod/src/scientific-python-lectures/advanced/scipy_sparse/examples/lobpcg_sakurai.py:64: UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown
  plt.show()

According to the notes, we should be seeing:

$ python examples/lobpcg_sakurai.py
Results by LOBPCG for n=2500

[ 0.06250083  0.06250028  0.06250007]

Exact eigenvalues

[ 0.06250005  0.0625002   0.06250044]

Elapsed time 7.01
jarrodmillman commented 1 month ago

@stefanv Any idea how to fix the code?

stefanv commented 1 month ago

Should be better now.