From bad75e20079728c10c3fc8dde874fd2b5beef2f2 Mon Sep 17 00:00:00 2001 From: q-posev <45995097+q-posev@users.noreply.github.com> Date: Wed, 5 Jan 2022 12:58:43 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20TREX-CoE?= =?UTF-8?q?/trexio@c687c80f92121b705b517872d64abc37b84c14b1=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.html | 4 +- examples.html | 82 ++--- index.html | 4 +- templator_front.html | 810 +++++++++++++++++++++++++++++++------------ templator_hdf5.html | 64 ++-- templator_text.html | 82 ++--- trex.html | 116 +++---- 7 files changed, 769 insertions(+), 393 deletions(-) diff --git a/README.html b/README.html index ec7e1d2..4d9f75d 100644 --- a/README.html +++ b/README.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- + @@ -347,7 +347,7 @@ and bug reports should be submitted at diff --git a/examples.html b/examples.html index 739f74f..d9b6e4a 100644 --- a/examples.html +++ b/examples.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + -program print_energy @@ -413,8 +413,8 @@ One needs to read from the TREXIO file:
integer :: i, j, k, l, m @@ -429,8 +429,8 @@ One needs to read from the TREXIO file:
call getarg(1, filename) @@ -446,8 +446,8 @@ f = trexio_open (filename, 'r', TREXIO_HDF5
rc = trexio_read_nucleus_repulsion(f, E_nn)
@@ -461,8 +461,8 @@ f = trexio_open (filename, 'r', TREXIO_HDF5
rc = trexio_read_mo_num(f, n)
@@ -476,8 +476,8 @@ f = trexio_open (filename, 'r', TREXIO_HDF5
allocate( D(n,n), h0(n,n) )
@@ -489,8 +489,8 @@ W(:,:,:,:) = 0.d0
rc = trexio_has_mo_1e_int_core_hamiltonian(f) @@ -522,8 +522,8 @@ rc = trexio_read_rdm_1e(f, D)
Reading is done with OpenMP. Each thread reads its own buffer, and @@ -539,8 +539,8 @@ to be protected in the critical section when modified.
rc = trexio_has_mo_2e_int_eri(f) @@ -589,8 +589,8 @@ icount = BUFSIZE
rc = trexio_has_rdm_2e(f) @@ -634,8 +634,8 @@ icount = bufsize
As \((n,m)\) 2D arrays are stored in memory as \((\n times m)\) 1D @@ -669,8 +669,8 @@ E = E + E_nn
deallocate( D, h0, G, W )
@@ -685,7 +685,7 @@ E = E + E_nn
stdint.h
Memory allocation of structures can be facilitated by using the @@ -513,8 +514,8 @@ The maximum string size for the filenames is 4096 characters.
All calls to TREXIO are thread-safe. @@ -522,10 +523,10 @@ TREXIO front end is modular, which simplifies implementation of new back ends.
Max value of indices | +Internal representation (in the TREXIO file) | +
---|---|
UINT8_MAX (e.g. \(< 255\)) |
+8-bit unsigned int | +
UINT16_MAX (e.g. \(< 65535\)) |
+16-bit unsigned int | +
Otherwise (e.g. \(\ge 65535\)) | +32-bit signed int | +
+This section concerns API calls related to sparse data structures. +
+ +Function name | +Description | +Precision | +
---|---|---|
trexio_has_$group_dset$ |
+Check if a sparse dset is present in a file | +--- | +
trexio_read_$group_dset$ |
+Read indices and values of a sparse dset | +Single/Double for indices/values | +
trexio_read_$group_dset$_size |
+Read the number of sparse data elements stored in the file | +Double for size | +
trexio_write_$group_dset$ |
+Write indices and values of a sparse dset | +Single/Double for indices/values | +
trexio_read_safe_$group_dset$ |
+Safe (bounded) read of indices and values (for Python API) | +Single/Double for indices/values | +
trexio_write_safe_$group_dset$ |
+Safe (bounded) write of indices and values (for Python API) | +Single/Double for indices/values | +
trexio_exit_code +trexio_exit_code trexio_read_safe_$group_dset$(trexio_t* const file, + const int64_t offset_file, + int64_t* const buffer_size_read, + int32_t* const index_sparse_read, + const int64_t size_index_read, + double* const value_sparse_read, + const int64_t size_value_read + ) +{ + return trexio_read_$group_dset$(file, offset_file, buffer_size_read, index_sparse_read, value_sparse_read); +} + +trexio_exit_code trexio_read_$group_dset$(trexio_t* const file, const int64_t offset_file, int64_t* const buffer_size, @@ -3491,13 +3602,25 @@ the values of the integrals, or only the indices.-trexio_exit_code +trexio_exit_code trexio_write_safe_$group_dset$(trexio_t* const file, + const int64_t offset_file, + const int64_t buffer_size, + const int32_t* index_sparse_write, + const int64_t size_index_write, + const double* value_sparse_write, + const int64_t size_value_write + ) +{ + return trexio_write_$group_dset$(file, offset_file, buffer_size, index_sparse_write, value_sparse_write); +} + +trexio_exit_code trexio_write_$group_dset$(trexio_t* const file, - const int64_t offset_file, - const int64_t buffer_size, - const int32_t* index_sparse, - const double* value_sparse - ) + const int64_t offset_file, + const int64_t buffer_size, + const int32_t* index_sparse, + const double* value_sparse + ) { if (file == NULL) return TREXIO_INVALID_ARG_1; if (offset_file < 0L) return TREXIO_INVALID_ARG_2; @@ -3601,8 +3724,8 @@ the values of the integrals, or only the indices.
The Fortran
templates that provide an access to the C
API calls from Fortran
.
@@ -3622,6 +3745,22 @@ These templates are based on the use of iso_c_binding
. Pointers hav
double precision, intent(in) :: value_sparse(*)
end function trexio_write_$group_dset$
end interface
+
+interface
+ integer function trexio_write_safe_$group_dset$ (trex_file, &
+ offset_file, buffer_size, &
+ index_sparse, index_size, &
+ value_sparse, value_size) bind(C)
+ use, intrinsic :: iso_c_binding
+ integer(8), intent(in), value :: trex_file
+ integer(8), intent(in), value :: offset_file
+ integer(8), intent(in), value :: buffer_size
+ integer(4), intent(in) :: index_sparse(*)
+ integer(8), intent(in), value :: index_size
+ double precision, intent(in) :: value_sparse(*)
+ integer(8), intent(in), value :: value_size
+ end function trexio_write_safe_$group_dset$
+end interface
iso_c_binding
. Pointers hav
double precision, intent(out) :: value_sparse(*)
end function trexio_read_$group_dset$
end interface
+
+interface
+ integer function trexio_read_safe_$group_dset$ (trex_file, &
+ offset_file, buffer_size, &
+ index_sparse, index_size, &
+ value_sparse, value_size) bind(C)
+ use, intrinsic :: iso_c_binding
+ integer(8), intent(in), value :: trex_file
+ integer(8), intent(in), value :: offset_file
+ integer(8), intent(inout) :: buffer_size
+ integer(4), intent(out) :: index_sparse(*)
+ integer(8), intent(in), value :: index_size
+ double precision, intent(out) :: value_sparse(*)
+ integer(8), intent(in), value :: value_size
+ end function trexio_read_safe_$group_dset$
+end interface
iso_c_binding
. Pointers hav
def write_$group_dset$(trexio_file: File, offset_file: int, buffer_size: int, indices: list, values: list) -> None: + """Write the $group_dset$ indices and values in the TREXIO file. + + Parameters: + + trexio_file: + TREXIO File object. + + offset_file: int + The number of integrals to be skipped in the file when writing. + + buffer_size: int + The number of integrals to write in the file from the provided sparse arrays. + + values: list OR numpy.ndarray + Array of $group_dset$ indices to be written. If array data type does not correspond to int32, the conversion is performed. + + values: list OR numpy.ndarray + Array of $group_dset$ values to be written. If array data type does not correspond to float64, the conversion is performed. + + Raises: + - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error. + - Exception from some other error (e.g. RuntimeError). + """ + + try: + import numpy as np + except ImportError: + raise Exception("NumPy cannot be imported.") + + if not isinstance(offset_file, int): + raise TypeError("offset_file argument has to be an integer.") + if not isinstance(buffer_size, int): + raise TypeError("buffer_size argument has to be an integer.") + if not isinstance(indices, (list, tuple, np.ndarray)): + raise TypeError("indices argument has to be an array (list, tuple or NumPy ndarray).") + if not isinstance(values, (list, tuple, np.ndarray)): + raise TypeError("values argument has to be an array (list, tuple or NumPy ndarray).") + + convertIndices = False + convertValues = False + flattenIndices = False + if isinstance(indices, np.ndarray): + # convert to int32 if input indices are in a different precision + if not indices.dtype==np.int32: + convertIndices = True + + if len(indices.shape) > 1: + flattenIndices = True + if convertIndices: + indices_32 = np.int32(indices).flatten() + else: + indices_32 = np.array(indices, dtype=np.int32).flatten() + else: + if convertIndices: + indices_32 = np.int32(indices) + else: + # if input array is a multidimensional list or tuple, we have to convert it + try: + doFlatten = True + # if list of indices is flat - the attempt to compute len(indices[0]) will raise a TypeError + ncol = len(indices[0]) + indices_32 = np.array(indices, dtype=np.int32).flatten() + except TypeError: + doFlatten = False + pass + + if isinstance(values, np.ndarray): + # convert to float64 if input values are in a different precision + if not values.dtype==np.float64: + convertValues = True + if convertValues: + values_64 = np.float64(values) + + if (convertIndices or flattenIndices) and convertValues: + rc = pytr.trexio_write_safe_$group_dset$(trexio_file.pytrexio_s, offset_file, buffer_size, indices_32, values_64) + elif (convertIndices or flattenIndices) and not convertValues: + rc = pytr.trexio_write_safe_$group_dset$(trexio_file.pytrexio_s, offset_file, buffer_size, indices_32, values) + elif not (convertIndices or flattenIndices) and convertValues: + rc = pytr.trexio_write_safe_$group_dset$(trexio_file.pytrexio_s, offset_file, buffer_size, indices, values_64) + else: + rc = pytr.trexio_write_safe_$group_dset$(trexio_file.pytrexio_s, offset_file, buffer_size, indices, values) + + if rc != TREXIO_SUCCESS: + raise Error(rc) +
def read_$group_dset$(trexio_file: File, offset_file: int, buffer_size: int) -> tuple: + """Read the $group_dset$ indices and values from the TREXIO file. + + Parameters: + + trexio_file: + TREXIO File object. + + offset_file: int + The number of integrals to be skipped in the file when reading. + + buffer_size: int + The number of integrals to read from the file. + + Returns: + (indices, values, n_int_read, eof_flag) tuple where + - indices and values are NumPy arrays [numpy.ndarray] with the default int32 and float64 precision, respectively; + - n_int_read [int] is the number of integrals read from the trexio_file + (either strictly equal to buffer_size or less than buffer_size if EOF has been reached); + - eof_flag [bool] is True when EOF has been reached (i.e. when call to low-level pytrexio API returns TREXIO_END) + False otherwise. + + Raises: + - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS + and prints the error message using trexio_string_of_error. + - Exception from some other error (e.g. RuntimeError). + """ + + try: + import numpy as np + except ImportError: + raise Exception("NumPy cannot be imported.") + + if not isinstance(offset_file, int): + raise TypeError("offset_file argument has to be an integer.") + if not isinstance(buffer_size, int): + raise TypeError("buffer_size argument has to be an integer.") + + + # read the number of integrals already in the file + integral_num = read_$group_dset$_size(trexio_file) + + # additional modification needed to avoid allocating more memory than needed if EOF will be reached during read + overflow = offset_file + buffer_size - integral_num + eof_flag = False + if overflow > 0: + verified_size = buffer_size - overflow + eof_flag = True + else: + verified_size = buffer_size + + # main call to the low-level (SWIG-wrapped) trexio_read function, which also requires the sizes of the output to be provided + # as the last 2 arguments (for numpy arrays of indices and values, respectively) + # read_buf_size contains the number of elements being read from the file, useful when EOF has been reached + rc, n_int_read, indices, values = pytr.trexio_read_safe_$group_dset$(trexio_file.pytrexio_s, + offset_file, + verified_size, + verified_size * $group_dset_rank$, + verified_size) + if rc != TREXIO_SUCCESS: + raise Error(rc) + if n_int_read == 0: + raise ValueError("No integrals have been read from the file.") + if indices is None or values is None: + raise ValueError("Returned NULL array from the low-level pytrexio API.") + + # conversion to custom types can be performed on the user side, here we only reshape the returned flat array of indices according to group_dset_rank + shape = tuple([verified_size, $group_dset_rank$]) + indices_reshaped = np.reshape(indices, shape, order='C') + + return (indices_reshaped, values, n_int_read, eof_flag) + + +def read_$group_dset$_size(trexio_file) -> int: + """Read the number of $group_dset$ integrals stored in the TREXIO file. + + Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function. + + Returns: + ~num_integral~: int + Integer value of corresponding to the size of the $group_dset$ sparse array from ~trexio_file~. + + Raises: + - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error. + - Exception from some other error (e.g. RuntimeError). + """ + + try: + rc, num_integral = pytr.trexio_read_$group_dset$_size(trexio_file.pytrexio_s) + if rc != TREXIO_SUCCESS: + raise Error(rc) + except: + raise + + return num_integral ++
def has_$group_dset$(trexio_file) -> bool: + """Check that $group_dset$ variable exists in the TREXIO file. + + Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function. + + Returns: + True if the variable exists, False otherwise + + Raises: + - Exception from trexio.Error class if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error. + - Exception from some other error (e.g. RuntimeError). + """ + + try: + rc = pytr.trexio_has_$group_dset$(trexio_file.pytrexio_s) + if rc == TREXIO_FAILURE: + raise Error(rc) + except: + raise + + if rc == TREXIO_SUCCESS: + return True + else: + return False ++
This section concerns API calls related to datasets of strings. @@ -3711,8 +4087,8 @@ This section concerns API calls related to datasets of strings.
First parameter is the TREXIO
file handle. Second parameter is the variable to be written/read
@@ -3720,12 +4096,12 @@ to/from the TREXIO
file (except for trexio_has_
functi
trexio_exit_code @@ -3979,8 +4355,8 @@ to/from theTREXIO
file (except fortrexio_has_
functi
The Fortran
templates that provide an access to the C
API calls from Fortran
.
@@ -4076,8 +4452,8 @@ These templates are based on the use of iso_c_binding
. Pointers hav
def write_$group_dset$(trexio_file, dset_w: list) -> None:
@@ -4193,12 +4569,12 @@ These templates are based on the use of iso_c_binding
. Pointers hav
This section concerns API calls related to string attributes. @@ -4238,16 +4614,16 @@ This section concerns API calls related to string attributes.
trexio_exit_code
@@ -4359,8 +4735,8 @@ This section concerns API calls related to string attributes.
The Fortran
templates that provide an access to the C
API calls from Fortran.
@@ -4437,8 +4813,8 @@ These templates are based on the use of iso_c_binding
. Pointers hav
def write_$group_str$(trexio_file, str_w: str) -> None:
@@ -4528,8 +4904,8 @@ These templates are based on the use of iso_c_binding
. Pointers hav
The function below adapts the original C-based trexio_open
for Fortran.
@@ -4664,7 +5040,7 @@ two code are identical, i.e. if the assert
statement pass.
#define $GROUP$_GROUP_NAME "$group$" @@ -345,8 +345,8 @@ for the JavaScript code in this tag.
typedef struct trexio_hdf5_s { @@ -360,8 +360,8 @@ for the JavaScript code in this tag.
trexio_exit_code
@@ -441,8 +441,8 @@ for the JavaScript code in this tag.
trexio_exit_code
@@ -536,8 +536,8 @@ for the JavaScript code in this tag.
trexio_exit_code
@@ -660,8 +660,8 @@ for the JavaScript code in this tag.
Sparse data is stored using extensible datasets of HDF5. Extensibility is required @@ -862,8 +862,8 @@ due to the fact that the sparse data will be written in chunks of user-defined s
trexio_exit_code
@@ -1068,8 +1068,8 @@ due to the fact that the sparse data will be written in chunks of user-defined s
trexio_exit_code
@@ -1192,8 +1192,8 @@ due to the fact that the sparse data will be written in chunks of user-defined s
trexio_exit_code
@@ -1443,7 +1443,7 @@ due to the fact that the sparse data will be written in chunks of user-defined s
The "file" produced by the text back end is a directory with one @@ -353,8 +353,8 @@ The file is written when closed, or when the flush function is called.
typedef struct $group$_s { @@ -373,8 +373,8 @@ The file is written when closed, or when the flush function is called.
typedef struct trexio_text_s { @@ -387,8 +387,8 @@ The file is written when closed, or when the flush function is called.
trexio_exit_code
@@ -519,8 +519,8 @@ The file is written when closed, or when the flush function is called.
trexio_exit_code
@@ -542,8 +542,8 @@ The file is written when closed, or when the flush function is called.
$group$_t* @@ -835,8 +835,8 @@ trexio_text_read_$group$ (trexio_text_t*
trexio_exit_code @@ -901,8 +901,8 @@ trexio_text_read_$group$ (trexio_text_t*
Memory is allocated when reading. The following function frees memory. @@ -947,8 +947,8 @@ Memory is allocated when reading. The following function frees memory.
trexio_exit_code
@@ -1011,8 +1011,8 @@ Memory is allocated when reading. The following function frees memory.
The group_dset
array is assumed allocated with the appropriate size.
@@ -1108,8 +1108,8 @@ The group_dset
array is assumed allocated with the appropriate size
The group_dset
array is assumed allocated with the appropriate size.
@@ -1210,8 +1210,8 @@ The group_dset
array is assumed allocated with the appropriate size
trexio_exit_code
@@ -1285,8 +1285,8 @@ The group_dset
array is assumed allocated with the appropriate size
Each sparse array is stored in a separate .txt
file due to the fact that sparse I/O has to be decoupled
@@ -1563,7 +1563,7 @@ User provides indices and values of the sparse array as two separate variables.
As we expect our files to be archived in open-data repositories, we @@ -420,7 +420,7 @@ which have participated to the creation of the file, a list of authors of the file, and a textual description.
-For example, consider H2 with the following basis set (in GAMESS @@ -1032,8 +1032,8 @@ prim_factor =
Going from the atomic basis set to AOs implies a systematic @@ -1081,13 +1081,13 @@ shell, as in the GAMESS convention where
In such a case, one should set the normalization of the shell (in -the Basis set section) to \(\mathcal{N}_{z^2}\), which is the +the Basis set section) to \(\mathcal{N}_{z^2}\), which is the normalization factor of the atomic orbitals in spherical coordinates. The normalization factor of the \(xy\) function which should be introduced here should be \(\frac{\mathcal{N}_{xy}}{\mathcal{N}_{z^2}}\).
-