Skip to content

Commit

Permalink
Merge pull request #138 from nomad-coe/gxac_documentation
Browse files Browse the repository at this point in the history
Analytic Continuation: Documentation + Symmetry constrains
  • Loading branch information
moritzleucke authored Oct 28, 2024
2 parents b852707 + 2811e79 commit 4fa7e88
Show file tree
Hide file tree
Showing 38 changed files with 18,873 additions and 712 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: [push]
jobs:
paper:
runs-on: ubuntu-latest
name: Paper Draft
name: TimeFrequency Paper
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -12,12 +12,12 @@ jobs:
with:
journal: joss
# This should be the path to the paper within your repo.
paper-path: JOSS/paper.md
paper-path: JOSS/timefrequency/paper.md
- name: Upload
uses: actions/upload-artifact@v3
with:
name: paper
# This is the output path where Pandoc will write the compiled
# PDF. Note, this should be the same directory as the input
# paper.md
path: JOSS/paper.pdf
path: JOSS/timefrequency/paper.pdf
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ endif()

# Optional unit testing lib
option(ENABLE_GREENX_UNIT_TESTS "Enable GreenX Unit Testing" OFF)
if (${ENABLE_GREENX_UNIT_TESTS})
# Function for generating unit test executables (assumes Zofu)
include(cmake/unit_test_functions.cmake)
# find ZOFU in $ZOFU_PATH or build on the fly
include(cmake/Findzofu.cmake)
endif()

# Our library directories
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
Expand All @@ -104,6 +98,13 @@ endif()
# Elements to compile the libraries inside submodules
option(COMPILE_SUBMODULES "Compile GreenX component contained inside submodules" ON)
if (${COMPILE_SUBMODULES})
# zofu is needed for IDieL regression tests
if (${ENABLE_GREENX_UNIT_TESTS})
# Function for generating unit test executables (assumes Zofu)
include(cmake/unit_test_functions.cmake)
# find ZOFU in $ZOFU_PATH or build on the fly
include(cmake/Findzofu.cmake)
endif()
# Build IDieL
set(IDieL_SOURCE "${PROJECT_SOURCE_DIR}/GX-q=0/IDieL/")
set(IDieL_CMAKE_OPTIONS "" CACHE STRING "Other IDieL options to build IDieL")
Expand Down
6 changes: 3 additions & 3 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.

INPUT = ../ ../GX-AnalyticContinuation/src ../GX-TimeFrequency ../GX-TimeFrequency/src ../GX-TimeFrequency/api
INPUT = ../ ../GX-AnalyticContinuation/api ../GX-TimeFrequency ../GX-TimeFrequency/src ../GX-TimeFrequency/api

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down Expand Up @@ -1602,7 +1602,7 @@ FORMULA_MACROFILE =
# The default value is: NO.
# This tag requires that the tag GENERATE_HTML is set to YES.

USE_MATHJAX = NO
USE_MATHJAX = YES

# When MathJax is enabled you can set the default output format to be used for
# the MathJax output. See the MathJax site (see:
Expand Down Expand Up @@ -1632,7 +1632,7 @@ MATHJAX_RELPATH = https://cdn.jsdelivr.net/npm/mathjax@2
# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols
# This tag requires that the tag USE_MATHJAX is set to YES.

MATHJAX_EXTENSIONS =
MATHJAX_EXTENSIONS = TeX/AMSmath

# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces
# of code that will be used on startup of the MathJax code. See the MathJax site
Expand Down
16 changes: 8 additions & 8 deletions GX-AnalyticContinuation/CITATION.cff
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
abstract: "Electronic structure calculations based on many-body perturbation theory involve analytic continuation from imaginary axis to real axis. The AnalyticContinuation component of the GreenX library has the aim to provide such tool."
authors:
- name: "GreenX library"
- family-names : Azizi
given-names : Maryam
orcid : 0000-0001-9089-1043
cff-version: 1.2.0
contact: [email protected]
- name: ""
- family-names : ""
given-names : ""
orcid : ""
cff-version: ""
contact: ""
preferred-citation:
- doi: 10.21105/joss.05770
- doi: ""
license:
- Apache-2.0
message: "If you use this software, please cite the article from preferred-citation DOI contained in this CITATION.cff file."
repository-code: "https://github.com/nomad-coe/greenX/tree/main/GX-TimeFrequency"
repository-code: "https://github.com/nomad-coe/greenX/tree/main/GX-AnalyticContinuation"
title: "Analytic continuation component of the GreenX library"
103 changes: 89 additions & 14 deletions GX-AnalyticContinuation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set_target_properties(LibGXAC
target_include_directories(LibGXAC PUBLIC src/)
if(GMPXX_FOUND)
add_definitions(-DGMPXX_FOUND)
target_sources(LibGXAC PRIVATE src/pade_approximant.f90 src/pade_mp.cpp api/gx_ac.F90)
target_sources(LibGXAC PRIVATE src/pade_approximant.f90 src/ComplexGMP.cpp src/Symmetry_pade.cpp src/pade_mp.cpp api/gx_ac.F90)
target_include_directories(LibGXAC PRIVATE ${GMPXX_INCLUDE_DIRS})
target_link_libraries(LibGXAC GXCommon ${GMPXX_LIBRARIES} gmp)
else()
Expand All @@ -39,20 +39,95 @@ install(TARGETS LibGXAC ARCHIVE DESTINATION lib LIBRARY DESTINATION lib)
# Destination relative to ${CMAKE_INSTALL_PREFIX}, defined in top-level CMake
install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY} DESTINATION include)



# -----------------------------------------------
# Unit Testing Set-up
# Application Testing Set-Up
# -----------------------------------------------
if (${ENABLE_GREENX_UNIT_TESTS})
# Create a directory in the build folder to place generated test drivers and binaries
set(UNIT_TEST_DIR "${PROJECT_BINARY_DIR}/unit_tests/analytic-continuation")
file(MAKE_DIRECTORY ${UNIT_TEST_DIR})
message("-- Analytic continuation unit tests written to: ${UNIT_TEST_DIR}")
# Include cmake custom function
include(../cmake/testFunctions.cmake)

# Libraries on which the unit tests depend
set(LIBS_FOR_UNIT_TESTS LibGXAC)
# Set name of test sub-directory in the build directory
set(TEST_TARGET_DIR "analytic_continuation")

# For unit tests for many modules, put this in a loop
create_unit_test_executable(TARGET_TEST_DIR ${UNIT_TEST_DIR}
TEST_NAME "test_pade_approximant"
REQUIRED_LIBS ${LIBS_FOR_UNIT_TESTS})
endif()
target_include_directories(LibGXAC PUBLIC test/)

# Set pytest conftest for Localized basis library tests
add_custom_command(
TARGET LibGXAC POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/test/conftest.py
${PROJECT_BINARY_DIR}/test/${TEST_TARGET_DIR}/conftest.py)


# -----------------------------------------------
# Application Tests
# -----------------------------------------------

# Add a test target
add_executable(test_gx_analytic_continuation)

# Set binary name
set_target_properties(test_gx_analytic_continuation
PROPERTIES
RUNTIME_OUTPUT_NAME test_gx_analytic_continuation.exe)

# Define source that comprise the binary
target_sources(test_gx_analytic_continuation
PRIVATE
test/test_gx_analytic_continuation.f90
)

# Libraries that the binary links to
target_link_libraries(test_gx_analytic_continuation
PUBLIC
LibGXAC
)

# Build location of the binary
# TODO(Alex) Consider move this to test/, to sit with the python drivers
set_target_properties(test_gx_analytic_continuation
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_Fortran_BIN_DIRECTORY})

# Copy all .py test to the `build/test` directory, such that one can run pytest there
# where CMAKE_CURRENT_SOURCE_DIR => CMakeLists.txt on this level
add_custom_command(
TARGET LibGXAC POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
# Test source relative to the time-frequency (this) folder
${CMAKE_CURRENT_SOURCE_DIR}/test/test_*.py
# Location to copy the test to
${PROJECT_BINARY_DIR}/test/${TEST_TARGET_DIR}/)

# Add test to ctest
add_test(
NAME test_gx_analytic_continuation_no-greedy_64bit
COMMAND pytest -s test_gx_analytic_continuation_no-greedy_64bit.py --build-dir ${CMAKE_BINARY_DIR}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/test/${TEST_TARGET_DIR}
)
add_test(
NAME test_gx_analytic_continuation_greedy_64bit
COMMAND pytest -s test_gx_analytic_continuation_greedy_64bit.py --build-dir ${CMAKE_BINARY_DIR}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/test/${TEST_TARGET_DIR}
)
add_test(
NAME test_gx_analytic_continuation_no-greedy_128bit
COMMAND pytest -s test_gx_analytic_continuation_no-greedy_128bit.py --build-dir ${CMAKE_BINARY_DIR}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/test/${TEST_TARGET_DIR}
)
add_test(
NAME test_gx_analytic_continuation_greedy_128bit
COMMAND pytest -s test_gx_analytic_continuation_greedy_128bit.py --build-dir ${CMAKE_BINARY_DIR}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/test/${TEST_TARGET_DIR}
)
add_test(
NAME test_gx_analytic_continuation_symmetry_64bit
COMMAND pytest -s test_gx_analytic_continuation_symmetry_64bit.py --build-dir ${CMAKE_BINARY_DIR}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/test/${TEST_TARGET_DIR}
)
add_test(
NAME test_gx_analytic_continuation_symmetry_128bit
COMMAND pytest -s test_gx_analytic_continuation_symmetry_128bit.py --build-dir ${CMAKE_BINARY_DIR}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/test/${TEST_TARGET_DIR}
)
111 changes: 65 additions & 46 deletions GX-AnalyticContinuation/README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,88 @@
## GreenX library - Analytic Continuation
# GreenX library - Analytic Continuation

The analytic continuation component provides routines to interpolate functions using the thiele pade interpolant.
The analytic continuation component (GX-AC) provides routines to interpolate functions using the thiele pade interpolant.

> [!Note]
> **Key Features**
> - basic thiele pade algorithm
> - greedy algorithm for thiele pade to enhance numerical stability
> - arbitrary precision arithmetic using the GMP library for even more numerical stability

## Usage
## Building

### Basic usage pade interpolation

> **Default**:
> - use the greedy algorithm
> - use 64 bit float precision (double precision) when GMP is not linked
> - use 128 bit float precision (quadrupel precision) when linked against GMP

```fortran
use gx_ac, only: create_thiele_pade, evaluate_thiele_pade_at, &
free_params, params
If you want to compile only the Analytic Continuation (AC) component of Greenx, change to the GreenX root, then type:
```bash
mkdir build && cd build
cmake -DMINIMAX_COMPONENT=OFF -DLBASIS_COMPONENT=OFF \
-DPAW_COMPONENT=OFF -DCOMPILE_SUBMODULES=OFF ../
make -j
make install

# optional: for running the regression tests
ctest
```

complex(dp), allocatable :: x_ref(:), y_ref(:)
### Linking against GNU Multiple Precision (GMP) Library

If requested, the arithmetic operations to obtain the pade model are carried out using an user specified precision. These arbitrary precision floats are handeled by the [GMP library](https://gmplib.org/). **By default GreenX tries to find and link GMP automatically** since it is installed already on most systems that use GNU compilers. However, if GreenX is unable to find the GMP library it will note the user during the cmake configuration step.

#### Compile and link GMP manually:
If for some reason no GMP is found in your system you can build it manually and specify its path in the GreenX build. Assumes that `$GX_ROOT` is set to the root of GreenX:
```bash
cd $GX_ROOT

# ------------------- Build GMP library
mkdir external && cd external
wget https://gmplib.org/download/gmp/gmp-6.3.0.tar.xz
tar -xf gmp-6.3.0.tar.xz
cd gmp-6.3.0/ && mkdir install
GMP_INSTALL_DIR="$(realpath install)"
./configure --prefix="${GMP_INSTALL_DIR}" --enable-cxx
make -j
make install
# optionally run unit tests of GMP
# make check

cd $GX_ROOT

# ------------------- Build GreenX
mkdir build && cd build
cmake -DCMAKE_PREFIX_PATH=$GMP_INSTALL_DIR ../
make -j
make install
```

type(params) :: params_thiele
complex(dp), dimension(:), allocatable :: x_query
complex(dp), dimension(:), allocatable :: y_return
integer :: n_par ! number of pade parameters

allocate(x_ref(npar), y_ref(npar))
allocate(x_query(10), y_return(10))
#### Turn off GMP:
You can turn of linking to GMP by specifiying `ENABLE_GNU_GMP=OFF` in the cmake configuration step.
```bash
cmake -DENABLE_GNU_GMP=OFF ../ # Default: ENABLE_GNU_GMP=ON
```

! initialize x_ref, y_ref and x_quer
## Calling the Analytic Continuation Component

! create the interpolation model and store it in struct
params_thiele = create_thiele_pade(n_par, x_ref, y_ref)
Information on how to use this component is always up-to-date on the [GreenX website](https://nomad-coe.github.io/greenX/gx_ac.html).

! evaluate the interpolation model at given x points
y_return(1:10) = evaluate_thiele_pade_at(params_thiele, x_query)
Additionally, take a look at the example script in `GX-AnalyticContinuation/examples`. This script shows how this component can be used.

! Clean-up
call free_params(params_thiele)
## Build the Example Script
In the `GX-AnalyticContinuation/examples` folder you can find a stand-alone fortran program (`pade_example.f90`) showcasing the usage of the GX-AC component. After building the GreenX library, change into the `GX-AnalyticContinuation/examples` folder and type:
```bash
make
```

### Advanced usage pade interpolation
e.g. to use the plain thiele pade algorithm (non-greedy) with 10 fold float precision:
```fortran
params_thiele = create_thiele_pade(n_par, x_ref, y_ref, do_greedy=.false., precision=320)
The program can be executed by running:
```bash
./pade_example > output.dat
```
e.g. to use the greedy algorithm with the faster double precision fortran implementation (doesn't make use of GMP even if it is linked) :
```fortran
params_thiele = create_thiele_pade(n_par, x_ref, y_ref, do_greedy=.true., precision=64)
To plot the reference function and the Padé interpolation call the python script:
```bash
python plot.py output.dat comparison.png
```
The figure is saved as `comparison.png`. Feel free to change some parameters in the `pade_example.f90` script and compile again to see how it is affecting the pade interpolation.

## Running the regression tests
Regression tests of the GX-AC component use the testing framework [pytest](https://docs.pytest.org/en/stable/#). Simply type `ctest` in the build directory after the GreenX library has been build.

### Availability of GMP at runtime
For more information please refer to the main [README.md](https://github.com/nomad-coe/greenX/blob/main/README.md) of this repository.

It is possible to check whether GMP is linked against GreenX at runtime:
```fortran
use gx_ac, only: arbitrary_precision_available, create_thiele_pade

if (arbitrary_precision_available) then
! this will succeed
params_thiele = create_thiele_pade(n_par, x_ref, y_ref, do_greedy=.false., precision=320)
else if (.not. arbitrary_precision_available) then
! this will result in an error
params_thiele = create_thiele_pade(n_par, x_ref, y_ref, do_greedy=.false., precision=320)
end if
Loading

0 comments on commit 4fa7e88

Please sign in to comment.