1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-11-19 20:42:50 +01:00

Fixes in Fortran interface

This commit is contained in:
Anthony Scemama 2023-09-11 17:05:41 +02:00
parent c176cd86c3
commit cbc8b9bd58
9 changed files with 231 additions and 189 deletions

View File

@ -2976,7 +2976,7 @@ qmckl_get_ao_basis_primitive_vgl (qmckl_context context,
implicit none
integer (c_int64_t) , intent(in) , value :: context
double precision, intent(out) :: primitive_vgl(*)
real(c_double), intent(out) :: primitive_vgl(*)
integer (c_int64_t) , intent(in) , value :: size_max
end function
end interface
@ -3037,7 +3037,7 @@ qmckl_get_ao_basis_shell_vgl (qmckl_context context,
implicit none
integer (c_int64_t) , intent(in) , value :: context
double precision, intent(out) :: shell_vgl(*)
real(c_double), intent(out) :: shell_vgl(*)
integer (c_int64_t) , intent(in) , value :: size_max
end function
end interface
@ -3098,7 +3098,7 @@ qmckl_get_ao_basis_ao_vgl (qmckl_context context,
import
implicit none
integer (c_int64_t) , intent(in) , value :: context
double precision, intent(out) :: ao_vgl(*)
real(c_double), intent(out) :: ao_vgl(*)
integer (c_int64_t) , intent(in) , value :: size_max
end function qmckl_get_ao_basis_ao_vgl
end interface
@ -3164,7 +3164,7 @@ qmckl_get_ao_basis_ao_vgl_inplace (qmckl_context context,
import
implicit none
integer (c_int64_t) , intent(in) , value :: context
double precision, intent(out) :: ao_vgl(*)
real(c_double), intent(out) :: ao_vgl(*)
integer (c_int64_t) , intent(in) , value :: size_max
end function qmckl_get_ao_basis_ao_vgl_inplace
end interface
@ -3225,7 +3225,7 @@ qmckl_get_ao_basis_ao_value (qmckl_context context,
import
implicit none
integer (c_int64_t) , intent(in) , value :: context
double precision, intent(out) :: ao_value(*)
real(c_double) , intent(out) :: ao_value(*)
integer (c_int64_t) , intent(in) , value :: size_max
end function qmckl_get_ao_basis_ao_value
end interface
@ -3291,7 +3291,7 @@ qmckl_get_ao_basis_ao_value_inplace (qmckl_context context,
import
implicit none
integer (c_int64_t) , intent(in) , value :: context
double precision, intent(out) :: ao_value(*)
real(c_double) , intent(out) :: ao_value(*)
integer (c_int64_t) , intent(in) , value :: size_max
end function qmckl_get_ao_basis_ao_value_inplace
end interface

View File

@ -1098,8 +1098,8 @@ end function qmckl_dgemm_f
implicit none
integer (c_int64_t) , intent(in) , value :: context
character , intent(in) , value :: TransA
character , intent(in) , value :: TransB
character(c_char) , intent(in) , value :: TransA
character(c_char) , intent(in) , value :: TransB
integer (c_int64_t) , intent(in) , value :: m
integer (c_int64_t) , intent(in) , value :: n
integer (c_int64_t) , intent(in) , value :: k
@ -1133,8 +1133,8 @@ end function qmckl_dgemm_f
implicit none
integer (c_int64_t) , intent(in) , value :: context
character , intent(in) , value :: TransA
character , intent(in) , value :: TransB
character(c_char) , intent(in) , value :: TransA
character(c_char) , intent(in) , value :: TransB
integer (c_int64_t) , intent(in) , value :: m
integer (c_int64_t) , intent(in) , value :: n
integer (c_int64_t) , intent(in) , value :: k
@ -1386,8 +1386,8 @@ end function qmckl_dgemm_safe_f
implicit none
integer (c_int64_t) , intent(in) , value :: context
character , intent(in) , value :: TransA
character , intent(in) , value :: TransB
character(c_char) , intent(in) , value :: TransA
character(c_char) , intent(in) , value :: TransB
integer (c_int64_t) , intent(in) , value :: m
integer (c_int64_t) , intent(in) , value :: n
integer (c_int64_t) , intent(in) , value :: k
@ -1424,8 +1424,8 @@ end function qmckl_dgemm_safe_f
implicit none
integer (c_int64_t) , intent(in) , value :: context
character , intent(in) , value :: TransA
character , intent(in) , value :: TransB
character(c_char) , intent(in) , value :: TransA
character(c_char) , intent(in) , value :: TransB
integer (c_int64_t) , intent(in) , value :: m
integer (c_int64_t) , intent(in) , value :: n
integer (c_int64_t) , intent(in) , value :: k

View File

@ -236,8 +236,8 @@ end function qmckl_distance_sq_f
implicit none
integer (c_int64_t) , intent(in) , value :: context
character , intent(in) , value :: transa
character , intent(in) , value :: transb
character(c_char) , intent(in) , value :: transa
character(c_char) , intent(in) , value :: transb
integer (c_int64_t) , intent(in) , value :: m
integer (c_int64_t) , intent(in) , value :: n
real (c_double ) , intent(in) :: A(lda,*)
@ -267,8 +267,8 @@ end function qmckl_distance_sq_f
implicit none
integer (c_int64_t) , intent(in) , value :: context
character , intent(in) , value :: transa
character , intent(in) , value :: transb
character(c_char) , intent(in) , value :: transa
character(c_char) , intent(in) , value :: transb
integer (c_int64_t) , intent(in) , value :: m
integer (c_int64_t) , intent(in) , value :: n
real (c_double ) , intent(in) :: A(lda,*)
@ -649,8 +649,8 @@ end function qmckl_distance_f
implicit none
integer (c_int64_t) , intent(in) , value :: context
character , intent(in) , value :: transa
character , intent(in) , value :: transb
character(c_char) , intent(in) , value :: transa
character(c_char) , intent(in) , value :: transb
integer (c_int64_t) , intent(in) , value :: m
integer (c_int64_t) , intent(in) , value :: n
real (c_double ) , intent(in) :: A(lda,*)
@ -680,8 +680,8 @@ end function qmckl_distance_f
implicit none
integer (c_int64_t) , intent(in) , value :: context
character , intent(in) , value :: transa
character , intent(in) , value :: transb
character(c_char) , intent(in) , value :: transa
character(c_char) , intent(in) , value :: transb
integer (c_int64_t) , intent(in) , value :: m
integer (c_int64_t) , intent(in) , value :: n
real (c_double ) , intent(in) :: A(lda,*)
@ -1076,8 +1076,8 @@ end function qmckl_distance_rescaled_f
implicit none
integer (c_int64_t) , intent(in) , value :: context
character , intent(in) , value :: transa
character , intent(in) , value :: transb
character(c_char) , intent(in) , value :: transa
character(c_char) , intent(in) , value :: transb
integer (c_int64_t) , intent(in) , value :: m
integer (c_int64_t) , intent(in) , value :: n
real (c_double ) , intent(in) :: A(lda,*)
@ -1108,8 +1108,8 @@ end function qmckl_distance_rescaled_f
implicit none
integer (c_int64_t) , intent(in) , value :: context
character , intent(in) , value :: transa
character , intent(in) , value :: transb
character(c_char) , intent(in) , value :: transa
character(c_char) , intent(in) , value :: transb
integer (c_int64_t) , intent(in) , value :: m
integer (c_int64_t) , intent(in) , value :: n
real (c_double ) , intent(in) :: A(lda,*)
@ -1599,8 +1599,8 @@ end function qmckl_distance_rescaled_gl_f
implicit none
integer (c_int64_t) , intent(in) , value :: context
character , intent(in) , value :: transa
character , intent(in) , value :: transb
character(c_char) , intent(in) , value :: transa
character(c_char) , intent(in) , value :: transb
integer (c_int64_t) , intent(in) , value :: m
integer (c_int64_t) , intent(in) , value :: n
real (c_double ) , intent(in) :: A(lda,*)
@ -1631,8 +1631,8 @@ end function qmckl_distance_rescaled_gl_f
implicit none
integer (c_int64_t) , intent(in) , value :: context
character , intent(in) , value :: transa
character , intent(in) , value :: transb
character(c_char) , intent(in) , value :: transa
character(c_char) , intent(in) , value :: transb
integer (c_int64_t) , intent(in) , value :: m
integer (c_int64_t) , intent(in) , value :: n
real (c_double ) , intent(in) :: A(lda,*)

View File

@ -347,9 +347,9 @@ interface
implicit none
integer (c_int64_t) , intent(in) , value :: context
character , intent(in) , value :: transp
character(c_char) , intent(in) , value :: transp
integer (c_int64_t) , intent(in) , value :: walk_num
double precision , intent(in) :: coord(*)
real(c_double) , intent(in) :: coord(*)
integer (c_int64_t) , intent(in) , value :: size_max
end function
end interface

View File

@ -362,7 +362,7 @@ void qmckl_string_of_error_f(const qmckl_exit_code error, char result[<<MAX_STRI
import
implicit none
integer (qmckl_exit_code), intent(in), value :: error
character, intent(out) :: string(<<MAX_STRING_LENGTH()>>)
character(c_char), intent(out) :: string(<<MAX_STRING_LENGTH()>>)
end subroutine qmckl_string_of_error
end interface
#+end_src
@ -603,7 +603,7 @@ qmckl_last_error(qmckl_context context, char* buffer) {
import
implicit none
integer (c_int64_t) , intent(in), value :: context
character, intent(out) :: string(*)
character(c_char), intent(out) :: string(*)
end subroutine qmckl_last_error
end interface
#+end_src

View File

@ -2,12 +2,53 @@
#+SETUPFILE: ../tools/theme.setup
#+INCLUDE: ../tools/lib.org
In this section, we present examples of usage of QMCkl.
For simplicity, we assume that the wave function parameters are stored
in a [[https://github.com/TREX-CoE/trexio][TREXIO]] file.
In this section, we provide hands-on examples to demonstrate the capabilities
of the QMCkl library. We furnish code samples in C, Fortran, and Python,
serving as exhaustive tutorials for effectively leveraging QMCkl.
For simplicity, we assume that the wave function parameters are stored in a
[[https://github.com/TREX-CoE/trexio][TREXIO]] file.
* Python
** Check numerically that MOs are orthonormal
* Overlap matrix in the MO basis
The focal point of this example is the numerical evaluation of the overlap
matrix in the MO basis. Utilizing QMCkl, we approximate the MOs at
discrete grid points to compute the overlap matrix \( S_{ij} \) as follows:
\[
S_{ij} = \int \phi_i(\mathbf{r})\, \phi_j(\mathbf{r}) \text{d}\mathbf{r} \approx
\sum_k \phi_i(\mathbf{r}_k)\, \phi_j(\mathbf{r}_k) \delta\mathbf{r}
\]
The code starts by reading a wave function from a TREXIO file. This is
accomplished using the ~qmckl_trexio_read~ function, which populates a
~qmckl_context~ with the necessary wave function parameters. The context
serves as the primary interface for interacting with the QMCkl library,
encapsulating the state and configurations of the system.
Subsequently, the code retrieves various attributes such as the number of
nuclei ~nucl_num~ and coordinates ~nucl_coord~.
These attributes are essential for setting up the integration grid.
The core of the example lies in the numerical computation of the overlap
matrix. To achieve this, the code employs a regular grid in three-dimensional
space, and the grid points are then populated into the ~qmckl_context~ using
the ~qmckl_set_point~ function.
The MO values at these grid points are computed using the
~qmckl_get_mo_basis_mo_value~ function. These values are then used to
calculate the overlap matrix through a matrix multiplication operation
facilitated by the ~qmckl_dgemm~ function.
The code is also instrumented to measure the execution time for the MO
value computation, providing an empirical assessment of the computational
efficiency. Error handling is robustly implemented at each stage to ensure the
reliability of the simulation.
In summary, this example serves as a holistic guide for leveraging the QMCkl
library, demonstrating its ease of use. It provides a concrete starting point
for researchers and developers interested in integrating QMCkl into their QMC
code.
** Python
:PROPERTIES:
:header-args: :tangle mo_ortho.py
:END:
@ -168,8 +209,9 @@ print (overlap)
1.18264754e-09 8.97215950e-01]]
#+end_example
* C
** Check numerically that MOs are orthonormal, with cusp fitting
** C
In this example, electron-nucleus cusp fitting is added.
:PROPERTIES:
:header-args: :tangle mo_ortho.c
:END:

View File

@ -957,7 +957,7 @@ interface
import
implicit none
integer (qmckl_context) , intent(in) , value :: context
double precision, intent(in), value :: kappa_ee
real(c_double), intent(in), value :: kappa_ee
end function qmckl_set_jastrow_champ_rescale_factor_ee
integer(qmckl_exit_code) function qmckl_set_jastrow_champ_rescale_factor_en (context, &
@ -967,7 +967,7 @@ interface
implicit none
integer (qmckl_context) , intent(in) , value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(in) :: kappa_en(size_max)
real(c_double), intent(in) :: kappa_en(size_max)
end function qmckl_set_jastrow_champ_rescale_factor_en
integer(qmckl_exit_code) function qmckl_set_jastrow_champ_aord_num (context, &
@ -1023,7 +1023,7 @@ interface
implicit none
integer (qmckl_context) , intent(in) , value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(in) :: a_vector(size_max)
real(c_double), intent(in) :: a_vector(size_max)
end function qmckl_set_jastrow_champ_a_vector
integer(qmckl_exit_code) function qmckl_set_jastrow_champ_b_vector(context, &
@ -1033,7 +1033,7 @@ interface
implicit none
integer (qmckl_context) , intent(in) , value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(in) :: b_vector(size_max)
real(c_double), intent(in) :: b_vector(size_max)
end function qmckl_set_jastrow_champ_b_vector
integer(qmckl_exit_code) function qmckl_set_jastrow_champ_c_vector(context, &
@ -1043,7 +1043,7 @@ interface
implicit none
integer (qmckl_context) , intent(in) , value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(in) :: c_vector(size_max)
real(c_double), intent(in) :: c_vector(size_max)
end function qmckl_set_jastrow_champ_c_vector
end interface
@ -1449,7 +1449,7 @@ interface
import
implicit none
integer (qmckl_context) , intent(in) , value :: context
double precision, intent(out) :: kappa_ee
real(c_double), intent(out) :: kappa_ee
end function qmckl_get_jastrow_champ_rescale_factor_ee
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_rescale_factor_en (context, &
@ -1459,7 +1459,7 @@ interface
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: kappa_en(size_max)
real(c_double), intent(out) :: kappa_en(size_max)
end function qmckl_get_jastrow_champ_rescale_factor_en
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_aord_num (context, &
@ -1515,7 +1515,7 @@ interface
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: a_vector(size_max)
real(c_double), intent(out) :: a_vector(size_max)
end function qmckl_get_jastrow_champ_a_vector
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_b_vector(context, &
@ -1525,7 +1525,7 @@ interface
implicit none
integer (qmckl_context) , intent(in) , value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: b_vector(size_max)
real(c_double), intent(out) :: b_vector(size_max)
end function qmckl_get_jastrow_champ_b_vector
integer(qmckl_exit_code) function qmckl_get_jastrow_champ_c_vector(context, &
@ -1535,7 +1535,7 @@ interface
implicit none
integer (qmckl_context) , intent(in) , value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: c_vector(size_max)
real(c_double), intent(out) :: c_vector(size_max)
end function qmckl_get_jastrow_champ_c_vector
end interface
@ -1726,7 +1726,7 @@ interface
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: asymp_jasb(size_max)
real(c_double), intent(out) :: asymp_jasb(size_max)
end function qmckl_get_jastrow_champ_asymp_jasb
end interface
#+end_src
@ -2123,7 +2123,7 @@ interface
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: factor_ee(size_max)
real(c_double), intent(out) :: factor_ee(size_max)
end function qmckl_get_jastrow_champ_factor_ee
end interface
#+end_src
@ -2589,7 +2589,7 @@ interface
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: factor_ee_gl(size_max)
real(c_double), intent(out) :: factor_ee_gl(size_max)
end function qmckl_get_jastrow_champ_factor_ee_gl
end interface
#+end_src
@ -3713,7 +3713,7 @@ interface
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: asymp_jasa(size_max)
real(c_double), intent(out) :: asymp_jasa(size_max)
end function qmckl_get_jastrow_champ_asymp_jasa
end interface
#+end_src
@ -3973,7 +3973,7 @@ interface
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: factor_en(size_max)
real(c_double), intent(out) :: factor_en(size_max)
end function qmckl_get_jastrow_champ_factor_en
end interface
#+end_src
@ -4370,7 +4370,7 @@ interface
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: factor_en_gl(size_max)
real(c_double), intent(out) :: factor_en_gl(size_max)
end function qmckl_get_jastrow_champ_factor_en_gl
end interface
#+end_src
@ -8448,7 +8448,7 @@ interface
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: factor_een(size_max)
real(c_double), intent(out) :: factor_een(size_max)
end function qmckl_get_jastrow_champ_factor_een
end interface
#+end_src
@ -8982,7 +8982,7 @@ interface
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: factor_een_gl(size_max)
real(c_double), intent(out) :: factor_een_gl(size_max)
end function qmckl_get_jastrow_champ_factor_een_gl
end interface
#+end_src
@ -9792,7 +9792,7 @@ interface
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: value(size_max)
real(c_double), intent(out) :: value(size_max)
end function qmckl_get_jastrow_champ_value
end interface
#+end_src
@ -10150,7 +10150,7 @@ interface
implicit none
integer (qmckl_context) , intent(in), value :: context
integer(c_int64_t), intent(in), value :: size_max
double precision, intent(out) :: gl(size_max)
real(c_double), intent(out) :: gl(size_max)
end function qmckl_get_jastrow_champ_gl
end interface
#+end_src

View File

@ -726,7 +726,7 @@ interface
import
implicit none
integer (c_int64_t) , intent(in), value :: context
double precision , intent(out) :: coefficient(*)
real(c_double) , intent(out) :: coefficient(*)
integer (c_int64_t) , intent(in), value :: size_max
end function qmckl_get_mo_basis_coefficient
end interface
@ -738,7 +738,7 @@ interface
import
implicit none
integer (c_int64_t) , intent(in), value :: context
double precision , intent(in) :: r_cusp(*)
real(c_double) , intent(in) :: r_cusp(*)
integer (c_int64_t) , intent(in), value :: size_max
end function qmckl_set_mo_basis_r_cusp
end interface
@ -906,7 +906,7 @@ qmckl_get_mo_basis_mo_value(qmckl_context context,
implicit none
integer (c_int64_t) , intent(in) , value :: context
double precision, intent(out) :: mo_value(*)
real(c_double), intent(out) :: mo_value(*)
integer (c_int64_t) , intent(in) , value :: size_max
end function qmckl_get_mo_basis_mo_value
end interface
@ -972,7 +972,7 @@ qmckl_get_mo_basis_mo_value_inplace (qmckl_context context,
import
implicit none
integer (c_int64_t) , intent(in) , value :: context
double precision, intent(out) :: mo_value(*)
real(c_double), intent(out) :: mo_value(*)
integer (c_int64_t) , intent(in) , value :: size_max
end function qmckl_get_mo_basis_mo_value_inplace
end interface
@ -1394,7 +1394,7 @@ qmckl_get_mo_basis_mo_vgl(qmckl_context context,
implicit none
integer (c_int64_t) , intent(in) , value :: context
double precision, intent(out) :: mo_vgl(*)
real(c_double), intent(out) :: mo_vgl(*)
integer (c_int64_t) , intent(in) , value :: size_max
end function qmckl_get_mo_basis_mo_vgl
end interface
@ -1460,7 +1460,7 @@ qmckl_get_mo_basis_mo_vgl_inplace (qmckl_context context,
import
implicit none
integer (c_int64_t) , intent(in) , value :: context
double precision, intent(out) :: mo_vgl(*)
real(c_double), intent(out) :: mo_vgl(*)
integer (c_int64_t) , intent(in) , value :: size_max
end function qmckl_get_mo_basis_mo_vgl_inplace
end interface

View File

@ -46,7 +46,7 @@ f_of_c_d = { '' : ''
, 'uint64_t' : 'integer (c_int64_t)'
, 'float' : 'real (c_float )'
, 'double' : 'real (c_double )'
, 'char' : 'character'
, 'char' : 'character(c_char )'
}
#+END_SRC