hungpham2017 / pyWannier90

A Wannier90 python interface for VASP and PySCF
BSD 3-Clause "New" or "Revised" License
34 stars 11 forks source link

undefined symbol: __w90lib_MOD_wannier_run #2

Closed houzf closed 4 years ago

houzf commented 4 years ago

In the Makefile of pyWannier90, USE_INTEL =no LIBDIR = ${HOME}/soft/cp2k/tools/toolchain/install/lapack-3.8.0 LIBS = -L$(LIBDIR)/lib -llapack -lblas -Wl,-rpath,$(W90DIR) -L$(W90DIR) -lwannier (in which the "libblas.a" and "liblapack.a" are available.) In "$(W90DIR)", the "libwannier.a" is available, which is compiled using gfortran.

The "libwannier90.cpython-37m-x86_64-linux-gnu.so" was generated normally. The path of "libwannier90.cpython-37m-x86_64-linux-gnu.so" was also added properly into the enviroment variable of "LD_LIBRARY_PATH".

However, the running of "pywannier90.py" still gave an error message:

ImportError: ~/pyWannier90/src/libwannier90.cpython-37m-x86_64-linux-gnu.so: undefined symbol: __w90lib_MOD_wannier_run

Actually, the "__w90lib_MOD_wannier_run" is actaully available in the "libwannier90.cpp".

By running "nm -D" or "ldd -r" libwannier90.cpython-37m-x86_64-linux-gnu.so, I also noted that the status of "__w90lib_MOD_wannier_run" was "-U".

How could I fix it?

hungpham2017 commented 4 years ago

ifort and gfortran are using different ABI (Application binary interface) for the Fortran module. I see that you turn off ifort by "USE_INTEL =no" which should automatically direct the compiler to the gfortran block instead of ifort one in libwannier90.cpp. Can you check the libwannier90.cpp file if there is really "#define gfortran" at line 16? It shouldn't be "#define ifort"

houzf commented 4 years ago

Thank you very much for your reply! Yes, "#define gfortran" was contained in "libwannier90.cpp".

I have actually tried the use of intel ifort to compile "libwannier90.cpp". Alternatively, a similar issue appeared for " w90lib_mp_wannierrun".

The version of g++ used: gcc version 8.2.1 20180905 (Red Hat 8.2.1-3) (GCC) Python: Anaconda 3.

hungpham2017 commented 4 years ago

Could you please go to the *wannier90-3.0.0/src/obj directory and run :

objdump -t  wannier_lib.o

and look for w90lib_ in the output?

For me, if I use gfortran then I should find:

0000000000000120 g     F .text  00000000000035b8 __w90lib_MOD_wannier_run
00000000000036e0 g     F .text  0000000000001610 __w90lib_MOD_wannier_setup

For ifort: w90lib_mp_wannierrun

0000000000002ea0 g     F .text  0000000000003600 w90lib_mp_wannier_run_
0000000000000010 g     F .text  0000000000002020 w90lib_mp_wannier_setup_

These are labels should be called in the libwannier90.cpp. So when calling libwannier90 in python, these names should be available in the wannier_lib.o object file. I think there is maybe other conventions for the new gcc that I didn't consider in my code:

houzf commented 4 years ago

In my compiled "wannier90-3.0.0", I didn't find any "w90lib_" in the "wannier_lib.o". This version of wannier90-3.0.0 may be the latest one because it was downloaded by "git clone" from the github site of wannier90.

Should I replace "wannier90-3.0.0/src/wannier_lib.F90" by "pyWannier90/src/wannier_lib.F90" and then re-compile wannier90-3.0.0?

hungpham2017 commented 4 years ago

Yes, it’s probably the reason why there are no those functions. The Wannier90 needs to be compiled with the wannier_lib.F90 from pyWannier90/src. In the future, I’m planning to fork wannier90 and merge with pyWannier90, and possibly push it to conda cloud to facilitate all of these compilation assuming if that’s okay with the wannier90 license or so.

hungpham2017 commented 4 years ago

Let me know if it works. This was my fault. I probably deleted the INSTALL.txt to notice it for users by accident. Will be pulling it to my repo soon

houzf commented 4 years ago

Thanks again for your time!

Yes, those errors were orginated from that I used the original "wannier_lib.F90" to compile wannier90 instead of your customized one.

Could you please give some suggestions for the setup of "FCOPTS=" and "LDOPTS" in the "make.inc" of "wannier90-3.0.0" since the compiling of libwannier90.cpp requires the options of "-shared -fPIC"?

By the way, there are several additional issues: 1). when running the "pywannier90.py" in "pyWannier90/src", File "pywannier90.py", line 739, in kmf = dft.KRKS(cell, abs_kpts).mix_density_fit() NameError: name 'dft' is not defined

File "pywannier90.py", line 773, in w90.export_unk(grid = grid) NameError: name 'grid' is not defined

To fix them, I make a minor modification to the 2nd line of pywannier90.py: from pyscf.pbc import df, dft and explicitly add one line just before "w90.export_unk(grid = grid)" grid=[25,25,25]

2). in "pyWannier90/examples/VASP/Si/test.py" the 2nd line should be changed from from mcu.vasp import pywannier90_vasp as pyw90 --> from mcu.wannier90 import pywannier90_vasp as pyw90.

3), "mcu/vasp/poscar.py" line 33, in init self.cell_recip = self.poscar.cell[1] AttributeError: 'POSCAR' object has no attribute 'cell'

It seems that there are some inconsistency between the "mcu" package "pyWannier90".

hungpham2017 commented 4 years ago

Thank you very much for reporting the bugs.

In the make.inc file: FCOPTS = -O3 -fPIC -g No need to specify LDOPTS. I just pushed a README file with the step-by-step installation notes (README.md).

(1) and (2) are bugs and fixed in the latest commit. You're right that I recently added the wannier90 module and moved the pywannier90_vasp from vasp module to wannier90 but hadn't updated the pyWannier90 correspondingly.

For (3), did you get the error message "Cannot find the POSCAR file (optional). Check the path: ..." It looks like the POSCAR was not read properly? I will add an assertion to stop the program whenever a file is not read successfully

hungpham2017 commented 4 years ago

another note is that the pywannier90_vasp was updated recently and I don't think the plot_WFs function to plot MLWFs directly from pywannier90 is working properly yet but you can always plot it directly by specifying that in the wannier90 input block. I will be pushing and testing the new functions thoroughly very soon. Keep in mind that MLWFs for VASP are constructed merely from the pseudo wavefunction in the WAVECAR. Theoretically, this is not the total wave function. I do not think it is the problem with plotting and viewing MLWFs but need to be careful if you construct some effective Hamiltonian in MLWFs basis to do calculation

houzf commented 4 years ago

Thanks a lot! Yes, I got the error message "Cannot find the POSCAR file (optional). Check the path: ...". Now I understand the issue of "POSCAR" in (3).

hungpham2017 commented 4 years ago

Great! If anything is okay now then I will close this issue. You can re-open it or open a new one if there is any other problem.