Replace f2py Fortran module with pure Python for Elk PMAT.OUT reader#282
Replace f2py Fortran module with pure Python for Elk PMAT.OUT reader#282the-hampel merged 1 commit intounstablefrom
Conversation
The elktools converter previously used an f2py-compiled Fortran module to read binary PMAT.OUT files. This has been replaced with a pure Python implementation that provides identical functionality without requiring a Fortran compiler at build time. Changes: - Add python/triqs_dft_tools/converters/elktools/getpmatelk.py Pure Python implementation to read Elk's Fortran unformatted binary files - Update python/triqs_dft_tools/converters/elk.py Modified import to use new Python module - Update python/triqs_dft_tools/converters/elktools/__init__.py Export getpmatelk function for direct import - Remove python/triqs_dft_tools/converters/elktools/elkwrappers/ Deleted f2py build infrastructure and Fortran source - Update CMakeLists.txt Removed elkwrappers subdirectory from build Benefits: - Eliminates Fortran compiler dependency for this component - Simplifies build process (no f2py compilation needed) - Easier to maintain and debug - Better error messages and handling - Resolves historical f2py compatibility issues on Intel/macOS Implementation details: - Correctly handles Fortran direct-access unformatted binary files - Properly reads column-major array ordering - Maintains exact compatibility with original Fortran version - All validation and error checking preserved Testing: - All 5 Elk converter tests pass - Output matches reference files exactly (verified with h5diff) - Tested with actual Elk PMAT.OUT files (41 states, 10 k-points) Cc: @AlynJ
|
Hi Nils, I've reviewed the pure Python implementation and it looks good to me (especially with the test passing). I've currently not got the time to run it locally to examine it in more detail, but I'll try to look at it in the near future and let you know if I encounter any issues. Apologies for the hassle using f2py has been with this. I believe my logic at the time of implementation was that it may be easier to update the Fortran code to mirror how Elk reads/writes the PMAT.OUT Fortran binary file within Elk's future release, but evidently having the implementation within Python is the best way forward. It may be worth noting the latest version of the Elk-TRIQS repository which this implementation is compatible with (which I believe is 8.4.21) for internal reference. Let me know if there are any other queries. Thanks, |
the-hampel
left a comment
There was a problem hiding this comment.
I think this is a very nice change. Getting rid of the fortran code here is good. I think the python code looks clean enough to facilitate future changes. Of course the dependency in dmftproj on fortran still remains. But this part is of course now simpler.
Thank you @Wentzell for the improvements.
Summary
This PR replaces the f2py-compiled Fortran module for reading Elk's PMAT.OUT files with a pure Python implementation, eliminating the Fortran compiler dependency for the elktools converter.
Changes:
python/triqs_dft_tools/converters/elktools/getpmatelk.py- pure Python replacementpython/triqs_dft_tools/converters/elk.pyto use new modulepython/triqs_dft_tools/converters/elktools/__init__.pyto exposegetpmatelkCMakeLists.txtpython/triqs_dft_tools/converters/elktools/elkwrappers/directory (Fortran source and build files)Technical details:
order='F'@AlynJ - As the original author of the Fortran implementation, could you please review this translation to ensure it correctly captures all the intended behavior?
Test plan