1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2025-04-29 03:44:45 +02:00

Compare commits

...

75 Commits

Author SHA1 Message Date
192e415a8f Merge branch 'debug_flags' 2025-01-09 15:51:58 +01:00
2b7498016a Fixing CI fo GH pages (emacs) 2025-01-09 15:51:03 +01:00
173fc3b6f1
Merge pull request #169 from TREX-CoE/debug_flags
Debug flags
2025-01-09 11:14:03 +01:00
ff6e556030 Update TREXIO exit codes decoding function 2025-01-08 15:19:43 +01:00
a889bb846e TREXIO exit codes decoding function 2025-01-08 15:14:24 +01:00
fd1e23ad3d +2 -> +1 2025-01-08 15:01:56 +01:00
Evgeny Posenitskiy
3321cb3ce6
Merge pull request #174 from sheepforce/haskell-readme
add Haskell bindings section to README
2025-01-06 15:53:10 +01:00
Phillip Seeber
43eb5f1944 add Haskell bindings section to README 2025-01-06 15:34:14 +01:00
q-posev
fb4e23481d Implement a check to prevent data corruption for sparse I/O 2025-01-03 20:57:51 +01:00
q-posev
b62ddcba12 Remove useless n_chunks 2025-01-03 20:32:59 +01:00
q-posev
155d69571a Remove TODO - the error handling is manual 2025-01-03 10:00:59 +01:00
q-posev
22be7fa615 Silence prints in tests 2025-01-03 09:53:46 +01:00
q-posev
a7cf0553cc Install valgrind for the CI 2025-01-02 23:33:05 +01:00
q-posev
68d6780d76 Fix CI 2025-01-02 23:24:34 +01:00
q-posev
0533cc67c0 Fix CI 2025-01-02 23:17:34 +01:00
q-posev
a9cdc2773d Fix CI 2025-01-02 23:14:21 +01:00
q-posev
1513eecaab Refactored CI: first do valgrind and then debug configure 2025-01-02 23:07:46 +01:00
q-posev
d804b14678 No need for -g in FCFLAGS 2025-01-02 23:03:58 +01:00
q-posev
0fd9779a1e Add hardcore valgring checking 2025-01-02 23:03:22 +01:00
Evgeny Posenitskiy
886561a847
Merge branch 'master' into debug_flags 2025-01-02 22:19:20 +01:00
Evgeny Posenitskiy
ccb9bf8587
Merge pull request #168 from TREX-CoE/det-checks
Fix text backend for determinants + check consistency of determinants
2025-01-02 22:14:37 +01:00
q-posev
4f1d44b920 Clear debug prints 2025-01-02 22:10:21 +01:00
Evgeny Posenitskiy
4d78926015
Rollback parallel tests 2025-01-02 22:06:43 +01:00
q-posev
91585a6811 Fix Python tests: align with the C ones 2025-01-02 21:29:36 +01:00
deb0e65fa5 Merge branch 'master' into debug_flags 2024-12-30 03:21:20 +01:00
156f09ff8a Merge branch 'master' of github.com:TREX-CoE/trexio 2024-12-30 03:21:09 +01:00
8cbc71ecb2 Fixed previous commit 2024-12-30 03:20:56 +01:00
0ba81ac715
Merge pull request #172 from TREX-CoE/madelung
Add Madelung correction
2024-12-30 03:02:49 +01:00
8bb2c1e179 Improved text backend 2024-12-30 02:54:24 +01:00
c502a6166d Merge branch 'master' into debug_flags 2024-12-30 02:40:37 +01:00
35795a9c35 Update determinant test such that last chunk is smaller (100 dets in 7 chunks) 2024-12-30 00:09:19 +01:00
d2c5dc7fa1 Merge branch 'master' into debug_flags 2024-12-12 09:51:05 +01:00
5a657b4035 Merge branch 'master' into madelung 2024-12-12 09:50:34 +01:00
Phillip Seeber
df0e3a8e1c
add nix build instructions and README section (#173)
# Conflicts:
#	README.md
2024-12-11 16:15:12 +01:00
9e8b2e92f3 Add Madelung 2024-12-07 11:41:33 +01:00
751b3c9d79 Fixed valgrind issue with trim 2024-12-06 11:20:26 +01:00
c7d5d4255b Fixed valgrind test_f.f90 2024-12-06 11:09:55 +01:00
cd369bd187 Fix previous commit 2024-12-05 18:24:43 +01:00
72619db8c4 Removed strnlen 2024-12-05 14:09:46 +01:00
a5d39acc92 Replaced some strnlen by memcpy 2024-12-05 14:00:13 +01:00
770b136c59 Revert "Fixed strncpy"
This reverts commit 363851314be6712254846016a974baee8f14d028.
2024-12-05 13:29:23 +01:00
363851314b Fixed strncpy 2024-12-05 13:23:59 +01:00
66bb1e9c21 Fixed bug for arrays of strings in text backend 2024-12-05 13:10:00 +01:00
e5a30615a6 Merge branch 'master' into debug_flags 2024-12-04 17:12:35 +01:00
Evgeny Posenitskiy
3d76eab5dd
Add codes supporting TREXIO (#171)
* [skip ci] Add codes supporting TREXIO -> review needed

* [skip ci] Update README.md

* [skip ci] Include Anthony's comments

* [skip ci] Remove integrals to avoid confusion
2024-12-04 16:48:29 +01:00
a7c92b6903 Forgot offset in example 2024-11-21 09:46:36 +01:00
0a6a537f97 Merge branch 'master' of github.com:TREX-CoE/trexio 2024-11-20 15:28:34 +01:00
4d3d4c4607 Added download link of tar.gz in documentation 2024-11-20 15:28:04 +01:00
1a07e6527f Added download link of tar.gz in documentation 2024-11-20 15:27:38 +01:00
8d534d8769 Fixed unused parameters in hdf5 2024-11-12 19:46:35 +01:00
38a4b60906 Added missing prototypes in the text backend 2024-11-12 19:26:28 +01:00
fad2df80b0 Added sanitizer flags for fortran 2024-11-12 15:21:32 +01:00
d9e56c5578 Merge branch 'det-checks' into debug_flags 2024-11-12 15:20:41 +01:00
2c7d8eab7f Fixed bug in test_f.f90 2024-11-12 15:19:53 +01:00
4bd147415c Merge branch 'det-checks' into debug_flags 2024-11-12 12:00:40 +01:00
e8ac919678 Removed O2 from default fortran configuration 2024-11-12 12:00:19 +01:00
q-posev
c9029293d2 Fix a typo in the comment 2024-11-11 20:03:40 +01:00
debee617d0 No warnings in trexio.c 2024-11-11 19:05:15 +01:00
d14b98b8a5 More checks 2024-11-11 18:09:38 +01:00
cda0ad70a6 Removed many warnings + added more checks 2024-11-11 17:26:51 +01:00
ff8e44d386 Add -g to compiler flags 2024-11-11 03:27:05 +01:00
9204ecb891 Retry tests 2024-11-11 03:20:46 +01:00
9459377a3f Changes after review 2024-11-11 02:54:28 +01:00
Evgeny Posenitskiy
59a836bba2
Try pinned SWIG from PyPI 2024-11-10 21:57:54 +01:00
Evgeny Posenitskiy
f5ed4afb66
SWIG 4.3 failed Python tests => downgrade 2024-11-10 21:46:56 +01:00
Evgeny Posenitskiy
04453266a6
Fix Python version in the CI testing 2024-11-10 21:34:27 +01:00
08674345a8 Fix text interface for determinants 2024-11-10 19:20:09 +01:00
0a153491c9 Fixed rust makefile 2024-11-10 13:03:53 +01:00
44b81fbc8f
Merge pull request #166 from TREX-CoE/solid-harmonics
Solid harmonics
2024-10-17 19:26:37 +02:00
9ea712a434 Fix ocaml version 2024-10-16 17:00:19 +02:00
da62668b1f Introduced real solid harmonics in the documentation 2024-10-16 16:54:56 +02:00
b68fe5a18a Merge branch 'master' of github.com:TREX-CoE/trexio 2024-10-16 16:17:17 +02:00
q-posev
d88358fb7b
[skip ci] Bump the patch version following 2.5.0 release 2024-09-11 10:20:56 +02:00
q-posev
908842122e
[wheel build] Release 2.5.0 + updated README 2024-09-11 09:47:14 +02:00
097162a624 Updated OCaml binding 2024-05-27 15:21:52 +02:00
33 changed files with 1154 additions and 328 deletions

View File

@ -52,15 +52,20 @@ jobs:
diff configure_v rust_v
diff configure_v ocaml_v
- name: setup fixed Python version for testing
uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f
with:
python-version: '3.10'
- name: install dependencies
run: |
sudo apt-get update
sudo apt-get install libhdf5-dev emacs
sudo apt-get install libhdf5-dev emacs libtool-bin valgrind
- name: configure with autotools
run: |
./autogen.sh
./configure --enable-silent-rules
./configure --enable-silent-rules
- name: compile TREXIO
run: make -j2
@ -68,6 +73,11 @@ jobs:
- name: check TREXIO
run: make -j2 check
- name: check via valgrind
run: |
which libtool
cd tests && ./run_valgrind.sh
- name: Archive test log file
if: failure()
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6
@ -108,15 +118,15 @@ jobs:
- name: maintainer clean
run: make maintainer-clean
- name: reconfigure with clang and AddressSanitizer
- name: reconfigure with debugging
run: |
./autogen.sh
./configure CC=clang-15 CFLAGS="-O2 -fsanitize=address -fno-omit-frame-pointer" LDFLAGS="-fsanitize=address" --enable-silent-rules
./configure --enable-silent-rules --enable-debug --enable-sanitizer
- name: recompile TREXIO
run: make -j2
- name: recheck TREXIO for memory leaks
- name: recheck TREXIO
run: make -j2 check
- name: Archive test log file
@ -140,17 +150,24 @@ jobs:
steps:
- uses: actions/checkout@e2f20e631ae6d7dd3b768f56a5d2af784dd54791
- name: setup fixed Python version for testing
uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f
with:
python-version: '3.12'
- name: install dependencies
run: |
brew install emacs
brew install hdf5@1.14
brew install automake
brew install libtool
brew install swig
brew --prefix hdf5
# SWIG 4.3.0 from homebrew with clang failed CI for macos@aarch64 - lol what?
pip install swig==4.2.1.post0
swig -version
- name: configure with autotools
run: |
brew --prefix hdf5
./autogen.sh
./configure CC=gcc-12 FC=gfortran-12 --enable-silent-rules

View File

@ -13,9 +13,6 @@ jobs:
with:
submodules: true
- name: install extra repository
run: sudo add-apt-repository ppa:kelleyk/emacs
- name: refresh apt
run: sudo apt-get update

View File

@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.16)
# Initialize the CMake project.
project(Trexio
VERSION 2.5.0
VERSION 2.5.1
DESCRIPTION "TREX I/O library"
LANGUAGES C Fortran
)

100
README.md
View File

@ -15,31 +15,50 @@ which enables fast read and write operations. It is compatible with a variety
of platforms and has interfaces for the Fortran, Python, OCaml and Rust
programming languages.
* [TREXIO](#trexio)
* [Installation](#installation)
* [Installation using a package manager](#installation-using-a-package-manager)
* [Conda](#conda)
* [Spack](#spack)
* [Guix](#guix)
* [Debian/Ubuntu](#debianubuntu)
* [Installation from source](#installation-from-source)
* [Minimal requirements (for users):](#minimal-requirements-for-users)
* [Recommended: Installation from the release tarball](#recommended-installation-from-the-release-tarball)
* [Compilation without the HDF5 library](#compilation-without-the-hdf5-library)
* [For TREXIO developers: from the GitHub repo clone](#for-trexio-developers-from-the-github-repo-clone)
* [Using CMake instead of Autotools](#using-cmake-instead-of-autotools)
* [Using TREXIO](#using-trexio)
* [Naming convention](#naming-convention)
* [Tutorial](#tutorial)
* [Documentation](#documentation)
* [Linking to your program](#linking-to-your-program)
* [Distributing TREXIO with your code](#distributing-trexio-with-your-code)
* [APIs for other languages](#apis-for-other-languages)
* [Python](#python)
* [Rust](#rust)
* [OCaml](#ocaml)
* [Citation](#citation)
* [Miscellaneous](#miscellaneous)
Below is the list of codes that adopted TREXIO for reading and/or writing
single- and/or multi-reference wave functions:
| Software | Single-reference | Multi-reference |
| ------------------------------------------------------------------------------ | ---------------- | --------------- |
| [Quantum Package](https://github.com/QuantumPackage/qp2) | Write/Read | Write/Read |
| [PySCF](https://github.com/pyscf/pyscf) | Write/Read | Write/Read |
| [FHI-aims](https://fhi-aims.org/) | Write | --- |
| [CP2K](https://github.com/cp2k/cp2k) | Write | --- |
| [CHAMP](https://github.com/filippi-claudia/champ) | Read | Read |
| [GammCor](https://github.com/pernalk/GAMMCOR) | Read | Read |
| [ipie](https://github.com/JoonhoLee-Group/ipie) | Read | Read |
| [TurboRVB](https://github.com/sissaschool/turborvb) | Read | --- |
| [Spicy](https://gitlab.com/theoretical-chemistry-jena/quantum-chemistry/Spicy) | Read | --- |
| [QMC=Chem](https://github.com/TREX-CoE/qmcchem2) | Read | --- |
| [QMCkl](https://github.com/TREX-CoE/qmckl) | Read | --- |
* [Installation](#installation)
* [Installation using a package manager](#installation-using-a-package-manager)
* [Conda](#conda)
* [Spack](#spack)
* [Guix](#guix)
* [Nix](#nix)
* [Debian/Ubuntu](#debianubuntu)
* [Installation from source](#installation-from-source)
* [Minimal requirements (for users):](#minimal-requirements-for-users)
* [Recommended: Installation from the release tarball](#recommended-installation-from-the-release-tarball)
* [Compilation without the HDF5 library](#compilation-without-the-hdf5-library)
* [For TREXIO developers: from the GitHub repo clone](#for-trexio-developers-from-the-github-repo-clone)
* [Using CMake instead of Autotools](#using-cmake-instead-of-autotools)
* [Using TREXIO](#using-trexio)
* [Naming convention](#naming-convention)
* [Tutorial](#tutorial)
* [Documentation](#documentation)
* [Linking to your program](#linking-to-your-program)
* [Distributing TREXIO with your code](#distributing-trexio-with-your-code)
* [APIs for other languages](#apis-for-other-languages)
* [Python](#python)
* [Rust](#rust)
* [OCaml](#ocaml)
* [Haskell](#haskell)
* [Citation](#citation)
* [Miscellaneous](#miscellaneous)
## Installation
@ -83,6 +102,23 @@ It can be installed as follows:
guix package --cores=`getconf _NPROCESSORS_ONLN` --install-from-file=trexio.scm
```
#### Nix
The official releases of TREXIO `>=2.5.` can be used and installed via [Nix](https://nixos.org/).
This repository provides a [Nix Flake](https://nixos.wiki/wiki/Flakes), where [tools/nix/trexio.nix](https://github.com/TREX-CoE/trexio/blob/master/tools/nix/trexio.nix) provides the build specification.
You can inspect the flake or build the package with
```
nix flake show github:TREX-CoE/trexio
nix build github:TREX-CoE/trexio
```
TREXIO is also part of [NixPkgs](https://github.com/NixOS/nixpkgs) and can be used via that channel.
```
nix build nixpkgs#trexio
```
#### Debian/Ubuntu
The official release of TREXIO `2.2.0` is available as a Debian (`.deb`) package thanks to the [Debichem Team](https://wiki.debian.org/Debichem).
@ -111,7 +147,7 @@ sudo apt-get update && sudo apt-get install libtrexio-dev
3. `cd trexio-<version>`
4. `./configure`
5. ```make -j 4 ```
6. ```make -j 4 check```
6. ```make -j $(nproc) check```
7. `sudo make install`
In environments where `sudo` access is unavailable, a common workaround for
@ -156,7 +192,7 @@ Additional requirements:
3. `./autogen.sh`
4. `./configure`
5. ```make -j 4```
6. ```make -j 4 check```
6. ```make -j $(nproc) check```
7. `sudo make install`
#### Using CMake instead of Autotools
@ -167,7 +203,7 @@ The aforementioned instructions rely on [Autotools](https://www.gnu.org/software
1. `cmake -S. -Bbuild`
2. `cd build`
3. ```make -j 4```
4. ```ctest -j 4```
4. ```ctest -j $(nproc)```
5. `sudo make install`
**Note**: on systems with no `sudo` access, one can add `-DCMAKE_INSTALL_PREFIX=build` as an argument to the `cmake` command so that `make install/uninstall` can be run without `sudo` privileges.
@ -298,6 +334,14 @@ make
opam install .
```
### Haskell
The Haskell bindings are available at <https://github.com/TREX-CoE/trexio-hs> and published on Hackage <https://hackage.haskell.org/package/trexio-hs>.
```
cabal update
cabal install trexio-hs
```
## Citation
The journal article reference describing TREXIO can be cited as follows:

View File

@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([trexio],[2.5.0],[https://github.com/TREX-CoE/trexio/issues])
AC_INIT([trexio],[2.5.1],[https://github.com/TREX-CoE/trexio/issues])
AC_CONFIG_SRCDIR([Makefile.in])
AC_CONFIG_HEADERS([include/config.h])
@ -43,6 +43,7 @@ AC_SUBST([UNAME])
# Fortran API [default: --with-fortran], do not disable in the dev mode
AC_PROG_FC
AC_ARG_WITH(fortran, [AS_HELP_STRING([--without-fortran],[do not test and install the Fortran API])], ok=$withval, ok=yes)
AS_IF([test "$ok" = "yes"],[
AC_FC_FREEFORM
@ -130,7 +131,7 @@ AC_ARG_WITH([hdf5],
AS_HELP_STRING([--with-hdf5=PATH], [Path to HDF5 library and headers]), [
with_hdf5="$withval"], [with_hdf5="yes"])
AS_IF([test "x$with_hdf5" == "xno"], [],
AS_IF([test "x$with_hdf5" == "xno"], [],
[test "x$with_hdf5" != "xyes"], [
HDF5_LIBS="-lhdf5"
HDF5_PATH="$with_hdf5"
@ -311,6 +312,21 @@ AC_CHECK_HEADERS([math.h])
AC_SEARCH_LIBS([pthread_create], [pthread], [], AC_MSG_ERROR([The pthread library is required]))
AC_CHECK_HEADERS([pthread.h])
# Debug flags
AC_ARG_ENABLE(debug, [AS_HELP_STRING([--enable-debug],[enable gcc and gfortran debug flags])], ok=$enableval, ok=no)
if test "$ok" = "yes"; then
CFLAGS="${CFLAGS} -Wall -Wextra -Wpedantic -Werror -Wshadow -Wformat -Wfloat-equal -Wconversion -Wcast-align -Wnull-dereference -Wstrict-aliasing -Winline -Wmissing-prototypes -Wunreachable-code -fstack-protector-strong -fdiagnostics-show-option -Wfloat-conversion -Wcast-qual -fno-inline -fno-omit-frame-pointer -Wno-sign-conversion -Wno-cast-qual -Wno-float-conversion" # -Wno-unused-variable"
FCFLAGS="${FCFLAGS} -g -fcheck=all -Waliasing -Wampersand -Wconversion -Wsurprising -Wintrinsics-std -Wno-tabs -Wintrinsic-shadow -Wline-truncation -Wreal-q-constant -Wuninitialized -fbacktrace -ffpe-trap=zero,overflow -finit-real=nan"
fi
AC_ARG_ENABLE(sanitizer, [AS_HELP_STRING([--enable-sanitizer],[enable sanitizer debug flags])], ok=$enableval, ok=no)
if test "$ok" = "yes"; then
CFLAGS="${CFLAGS} -fsanitize=address -fsanitize=undefined -fsanitize=leak -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=bounds -fsanitize=bounds-strict"
FCFLAGS="${FCFLAGS} -fsanitize=address -fsanitize=undefined -fsanitize=leak -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=bounds -fsanitize=bounds-strict"
fi
AC_CONFIG_FILES([Makefile
pkgconfig/trexio.pc])

View File

@ -491,6 +491,7 @@ feof = False
W = np.zeros( (n,n,n,n) )
while not feof:
buffer_index, buffer_values, icount, feof = trexio.read_mo_2e_int_eri(f, offset, icount)
offset += icount
for m in range(icount):
i, j, k, l = buffer_index[m]
W[i,j,k,l] = buffer_values[m]
@ -515,6 +516,7 @@ feof = False
G = np.zeros( (n,n,n,n) )
while not feof:
buffer_index, buffer_values, icount, feof = trexio.read_rdm_2e(f, offset, icount)
offset += icount
for m in range(icount):
i, j, k, l = buffer_index[m]
G[i,j,k,l] = buffer_values[m]

60
flake.lock generated Normal file
View File

@ -0,0 +1,60 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1733852629,
"narHash": "sha256-lXMmrcEg1WxEdPiXpUfkxbJij0xS5acao1Jz4lnrNPY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "9ad61cfc19c1f66e7d7d1ac9c71ae1b187065580",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

24
flake.nix Normal file
View File

@ -0,0 +1,24 @@
{
description = "TREX I/O library";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
let overlay = import ./tools/nix/overlay.nix;
in flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ overlay ];
};
in
{
packages.default = pkgs.trexio;
}
) // {
overlays.default = overlay;
};
}

View File

@ -1,7 +1,7 @@
(lang dune 3.1)
(name trexio)
(version 2.5.0)
(version 2.5.1)
(generate_opam_files false)

View File

@ -8,10 +8,10 @@ ml_file = "trexio.ml"
mli_file = ml_file+"i"
def check_version():
with open('trexio.opam','r') as f:
with open('dune-project','r') as f:
for line in f:
if line.startswith("version"):
ocaml_version = line.split(':')[1].strip()[1:-1]
if line.startswith("(version"):
ocaml_version = line.split()[1].strip().replace(')','')
break
with open('../../configure.ac','r') as f:
for line in f:

View File

@ -1,6 +1,6 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "2.4.2"
version: "2.5.1"
synopsis: "Binding for the TREXIO Input/Output library"
description:
"TREXIO is a file format and library for storing wave functions and integrals for quantum chemistry."

View File

@ -11,8 +11,8 @@ can be used to convert data from one input/output file format into another.
## Requirements
- python3 (>= 3.6)
- numpy (>= 1.17.3)
- python3 (>= 3.8)
- numpy (>= 1.17.3)
## Installation from PyPI
@ -27,10 +27,6 @@ However, it is good practice to first check for updates of the build-system pack
**Note: we highly recommend to use virtual environments to avoid compatibility issues and to improve reproducibility.**
For more details, see the corresponding part of the [Python documentation](https://docs.python.org/3/library/venv.html#creating-virtual-environments).
**Note: our build farm (GitHub Actions) does not support ARM64 architectures (including the Mac M1/M2 chips). Therefore, `pip install trexio` does not work on an ARM64-based machine. Thus, we recommend to install TREXIO from source on an ARM64-based machine. If one uses a Mac where HDF5 is installed with brew (i.e., `brew install hdf5`), a workaround is to execute the following 2 lines before doing `pip install trexio`:**
- `export H5_CFLAGS="-I$(brew --prefix hdf5)/include"`
- `export H5_LDFLAGS="-L$(brew --prefix hdf5)/lib"`
## Additional requirements (for installation from source)
@ -50,6 +46,9 @@ For more details, see the corresponding part of the [Python documentation](https
The following two steps can be skipped if HDF5 is properly configured for `pkg-config` (i.e. if executing `pkg-config --libs hdf5` returns a list of options).
- `export H5_CFLAGS=-I/path/to/hdf5/include`
- `export H5_LDFLAGS=-L/path/to/hdf5/lib`
On MacOS where HDF5 is installed with homebrew (i.e. `brew install hdf5`), one can use the following:
- `export H5_CFLAGS="-I$(brew --prefix hdf5)/include"`
- `export H5_LDFLAGS="-L$(brew --prefix hdf5)/lib"`
6. `pip install .` (this installs `trexio` in your environment)
7. `cd test && python -m pytest -v test_api.py` (this executes several tests that verify the installation)

View File

@ -1 +1 @@
__version__ = "2.5.0"
__version__ = "2.5.1"

View File

@ -6,6 +6,62 @@ import trexio
from benzene_data import *
# this function is copied from the trexio-tools github repository (BSD-3 license):
# https://github.com/TREX-CoE/trexio_tools/blob/master/src/trexio_tools/group_tools/determinant.py
def to_determinant_list(orbital_list: list, int64_num: int) -> list:
"""
Convert a list of occupied orbitals from the `orbital_list`
into a list of Slater determinants (in their bit string representation).
Orbitals in the `orbital_list` should be 0-based, namely the lowest orbital has index 0, not 1.
int64_num is the number of 64-bit integers needed to represent a Slater determinant bit string.
It depends on the number of molecular orbitals as follows: int64_num = int((mo_num-1)/64) + 1
"""
if not isinstance(orbital_list, list):
raise TypeError(f"orbital_list should be a list, not {type(orbital_list)}")
det_list = []
bitfield = 0
shift = 0
# since orbital indices are 0-based but the code below works for 1-based --> increment the input indices by +1
orb_list_upshifted = [ orb+1 for orb in orbital_list]
# orbital list has to be sorted in increasing order for the bitfields to be set correctly
orb_list_sorted = sorted(orb_list_upshifted)
for orb in orb_list_sorted:
if orb-shift > 64:
# this removes the 0 bit from the beginning of the bitfield
bitfield = bitfield >> 1
# append a bitfield to the list
det_list.append(bitfield)
bitfield = 0
modulo = int((orb-1)/64)
shift = modulo*64
bitfield |= (1 << (orb-shift))
# this removes the 0 bit from the beginning of the bitfield
bitfield = bitfield >> 1
det_list.append(bitfield)
#print('Popcounts: ', [bin(d).count('1') for d in det_list)
#print('Bitfields: ', [bin(d) for d in det_list])
bitfield_num = len(det_list)
if bitfield_num > int64_num:
raise Exception(f'Number of bitfields {bitfield_num} cannot be more than the int64_num {int64_num}.')
if bitfield_num < int64_num:
for _ in range(int64_num - bitfield_num):
print("Appending an empty bitfield.")
det_list.append(0)
return det_list
def clean(back_end, filename):
"""Remove test files."""
if back_end == trexio.TREXIO_HDF5:
@ -206,16 +262,36 @@ class TestIO:
"""Write CI determinants and coefficients."""
self.open()
# write mo_num (needed later to write determinants)
trexio.write_mo_num(self.test_file, mo_num)
MO_NUM_TEST = 100
trexio.write_mo_num(self.test_file, MO_NUM_TEST)
# get the number of bit-strings per spin component
INT64_NUM_TEST = int((MO_NUM_TEST-1)/64) + 1
int_num = trexio.get_int64_num(self.test_file)
assert int_num == int64_num
assert int_num == INT64_NUM_TEST
# write the number of up and down electrons
trexio.write_electron_up_num(self.test_file, 4)
trexio.write_electron_dn_num(self.test_file, 3)
# orbital lists
orb_list_up = [0,1,2,3]
orb_list_dn = [0,1,2]
# data to write
DET_NUM_TEST = 100
det_up = to_determinant_list(orb_list_up, INT64_NUM_TEST)
det_dn = to_determinant_list(orb_list_dn, INT64_NUM_TEST)
det_list = []
coeff_list = []
for i in range(DET_NUM_TEST):
det_list.append(det_up + det_dn)
coeff_list.append(3.14 + float(i))
# write the data for the ground state
offset = 0
trexio.write_state_id(self.test_file, 0)
trexio.write_determinant_list(self.test_file, offset, det_num, dets)
trexio.write_determinant_list(self.test_file, offset, DET_NUM_TEST, det_list)
assert trexio.has_determinant_list(self.test_file)
trexio.write_determinant_coefficient(self.test_file, offset, det_num, coeffs)
trexio.write_determinant_coefficient(self.test_file, offset, DET_NUM_TEST, coeff_list)
assert trexio.has_determinant_coefficient(self.test_file)
# manually check the consistency between coefficient_size and number of determinants
assert trexio.read_determinant_coefficient_size(self.test_file) == trexio.read_determinant_num(self.test_file)
@ -350,26 +426,6 @@ class TestIO:
if self.test_file.isOpen:
self.test_file.close()
def test_determinant_read(self):
"""Read the CI determinants."""
self.open(mode='r')
# read determinants (list of ints and float coefficients)
buf_size = 100
offset_file = 0
# read full buf_size (i.e. the one that does not reach EOF)
dets_np, read_buf_size, eof = trexio.read_determinant_list(self.test_file, offset_file, buf_size)
#print(f'First complete read of determinant list: {read_buf_size}')
assert not eof
assert read_buf_size == buf_size
assert dets_np[0][0] == 0
assert dets_np[read_buf_size-1][int64_num*2-1] == read_buf_size * int64_num * 2- 1
coefficients_np, read_buf_size, eof = trexio.read_determinant_coefficient(self.test_file, offset_file, buf_size)
#print(f'First complete read of determinant coefficients: {read_buf_size}')
assert not eof
assert read_buf_size == buf_size
if self.test_file.isOpen:
self.test_file.close()
def test_array_str_read(self):
"""Read an array of strings."""

View File

@ -1,6 +1,6 @@
[package]
name = "trexio"
version = "2.5.0"
version = "2.5.1"
edition = "2021"
license = "BSD-3-Clause"
authors = ["Anthony Scemama <scemama@irsamc.ups-tlse.fr>", "Evgeny Posenitskiy"]

View File

@ -1,10 +1,7 @@
default: src/generated.rs
default:
cargo build
cargo test
src/generated.rs: build.py
python3 build.py
test: default
- cargo test -- --show-output

View File

@ -19,6 +19,9 @@ and two different back-ends: a text back-end and a binary back-end utilizing
the HDF5 library enabling fast read and write speeds. It is compatible with a
variety of platforms and has interfaces for Fortran, Python, and OCaml.
TREXIO can be downloaded here:
https://github.com/TREX-CoE/trexio/releases/latest
If you use TREXIO, please cite this article published in the [[https://doi.org/10.1063/5.0148161][Journal of Chemical Physics]]:
#+begin_src latex
@article{trexio_2023,

View File

@ -32,7 +32,7 @@ with open('../../trex.json','r') as f:
res += line.rstrip()+'\n'
res += "*/"
return res
#+end_src
#+end_src
#+RESULTS: trex_json
:results:
@ -470,12 +470,20 @@ __trexio_path__ = None
| ~TREXIO_INVALID_STATE~ | 35 | 'Inconsistent state of the file' |
| ~TREXIO_VERSION_PARSING_ISSUE~ | 36 | 'Failed to parse package_version' |
| ~TREXIO_PHASE_CHANGE~ | 37 | 'The function succeeded with a change of sign' |
| ~TREXIO_INVALID_MO_INDEX~ | 38 | 'Invalid MO index' |
| ~TREXIO_INVALID_ARG_9~ | 39 | 'Invalid argument 9' |
| ~TREXIO_INVALID_ARG_10~ | 40 | 'Invalid argument 10' |
| ~TREXIO_INVALID_ARG_11~ | 41 | 'Invalid argument 11' |
| ~TREXIO_INVALID_ARG_12~ | 42 | 'Invalid argument 12' |
| ~TREXIO_INVALID_ARG_13~ | 43 | 'Invalid argument 13' |
| ~TREXIO_INVALID_ARG_14~ | 44 | 'Invalid argument 14' |
| ~TREXIO_CORRUPTION_ATTEMPT~ | 45 | 'File offset is wrong, corruption risk' |
# We need to force Emacs not to indent the Python code:
# -*- org-src-preserve-indentation: t
*IMPORTANT!*
The code below has to be executed within Emacs each time
The 2 code blocks below have to be executed within Emacs each time
a new error code is added to the table above. Otherwise, the codes
and the corresponding message are not propagated to the source code.
@ -511,7 +519,6 @@ return '\n'.join(result)
#+end_src
#+RESULTS:
:results:
#+begin_src c :tangle prefix_front.h :exports none
@ -554,6 +561,14 @@ return '\n'.join(result)
#define TREXIO_INVALID_STATE ((trexio_exit_code) 35)
#define TREXIO_VERSION_PARSING_ISSUE ((trexio_exit_code) 36)
#define TREXIO_PHASE_CHANGE ((trexio_exit_code) 37)
#define TREXIO_INVALID_MO_INDEX ((trexio_exit_code) 38)
#define TREXIO_INVALID_ARG_9 ((trexio_exit_code) 39)
#define TREXIO_INVALID_ARG_10 ((trexio_exit_code) 40)
#define TREXIO_INVALID_ARG_11 ((trexio_exit_code) 41)
#define TREXIO_INVALID_ARG_12 ((trexio_exit_code) 42)
#define TREXIO_INVALID_ARG_13 ((trexio_exit_code) 43)
#define TREXIO_INVALID_ARG_14 ((trexio_exit_code) 44)
#define TREXIO_CORRUPTION_ATTEMPT ((trexio_exit_code) 45)
#+end_src
#+begin_src f90 :tangle prefix_fortran.f90 :exports none
@ -596,6 +611,14 @@ return '\n'.join(result)
integer(trexio_exit_code), parameter :: TREXIO_INVALID_STATE = 35
integer(trexio_exit_code), parameter :: TREXIO_VERSION_PARSING_ISSUE = 36
integer(trexio_exit_code), parameter :: TREXIO_PHASE_CHANGE = 37
integer(trexio_exit_code), parameter :: TREXIO_INVALID_MO_INDEX = 38
integer(trexio_exit_code), parameter :: TREXIO_INVALID_ARG_9 = 39
integer(trexio_exit_code), parameter :: TREXIO_INVALID_ARG_10 = 40
integer(trexio_exit_code), parameter :: TREXIO_INVALID_ARG_11 = 41
integer(trexio_exit_code), parameter :: TREXIO_INVALID_ARG_12 = 42
integer(trexio_exit_code), parameter :: TREXIO_INVALID_ARG_13 = 43
integer(trexio_exit_code), parameter :: TREXIO_INVALID_ARG_14 = 44
integer(trexio_exit_code), parameter :: TREXIO_CORRUPTION_ATTEMPT = 45
#+end_src
#+begin_src python :tangle prefix_python.py :exports none
@ -639,31 +662,17 @@ return '\n'.join(result)
TREXIO_INVALID_STATE = 35
TREXIO_VERSION_PARSING_ISSUE = 36
TREXIO_PHASE_CHANGE = 37
TREXIO_INVALID_MO_INDEX = 38
TREXIO_INVALID_ARG_9 = 39
TREXIO_INVALID_ARG_10 = 40
TREXIO_INVALID_ARG_11 = 41
TREXIO_INVALID_ARG_12 = 42
TREXIO_INVALID_ARG_13 = 43
TREXIO_INVALID_ARG_14 = 44
TREXIO_CORRUPTION_ATTEMPT = 45
#+end_src
:end:
*** Decoding errors
The ~trexio_string_of_error~ converts an exit code into a string. The
string is assumed to be large enough to contain the error message
(typically 128 characters).
To decode the error messages, ~trexio_string_of_error~ converts an
error code into a string.
#+NAME: MAX_STRING_LENGTH
: 128
#+begin_src c :tangle prefix_front.h :exports none :noweb yes
const char* trexio_string_of_error(const trexio_exit_code error);
void trexio_string_of_error_f(const trexio_exit_code error, char result[<<MAX_STRING_LENGTH()>>]);
#+end_src
*IMPORTANT!*
The code below has to be executed within Emacs each time
a new error code is added to the table above. Otherwise, the codes
and the corresponding message are not propagated to the source code.
#+NAME:cases
#+begin_src python :var table=table-exit-codes :exports none :noweb yes
""" This script extracts the text associated with the error codes
@ -795,8 +804,49 @@ return '\n'.join(result)
case TREXIO_VERSION_PARSING_ISSUE:
return "Failed to parse package_version";
break;
case TREXIO_PHASE_CHANGE:
return "The function succeeded with a change of sign";
break;
case TREXIO_INVALID_MO_INDEX:
return "Invalid MO index";
break;
case TREXIO_INVALID_ARG_9:
return "Invalid argument 9";
break;
case TREXIO_INVALID_ARG_10:
return "Invalid argument 10";
break;
case TREXIO_INVALID_ARG_11:
return "Invalid argument 11";
break;
case TREXIO_INVALID_ARG_12:
return "Invalid argument 12";
break;
case TREXIO_INVALID_ARG_13:
return "Invalid argument 13";
break;
case TREXIO_INVALID_ARG_14:
return "Invalid argument 14";
break;
case TREXIO_CORRUPTION_ATTEMPT:
return "File offset is wrong, corruption risk";
break;
#+end_example
*** Decoding errors
The ~trexio_string_of_error~ converts an exit code into a string. The
string is assumed to be large enough to contain the error message
(typically 128 characters).
To decode the error messages, ~trexio_string_of_error~ converts an
error code into a string.
#+begin_src c :tangle prefix_front.h :exports none :noweb yes
const char* trexio_string_of_error(const trexio_exit_code error);
void trexio_string_of_error_f(const trexio_exit_code error, const int32_t size_string, char* const result);
#+end_src
**** C source code
#+begin_src c :tangle prefix_front.c :noweb yes
@ -810,9 +860,17 @@ trexio_string_of_error (const trexio_exit_code error)
}
void
trexio_string_of_error_f (const trexio_exit_code error, char result[<<MAX_STRING_LENGTH()>>])
trexio_string_of_error_f (const trexio_exit_code error, const int32_t str_size, char* const result)
{
strncpy(result, trexio_string_of_error(error), <<MAX_STRING_LENGTH()>>);
const char* pSrc = trexio_string_of_error(error);
int32_t sizeCp = (int32_t) strlen(pSrc);
if (sizeCp > str_size) {
sizeCp = str_size;
}
memcpy(result, pSrc, sizeCp);
for (int32_t i=sizeCp ; i<str_size ; ++i) {
result[i] = ' ';
}
}
#+end_src
@ -820,11 +878,12 @@ trexio_string_of_error_f (const trexio_exit_code error, char result[<<MAX_STRING
#+begin_src f90 :tangle prefix_fortran.f90 :noexport :noweb yes
interface
subroutine trexio_string_of_error (error, string) bind(C, name='trexio_string_of_error_f')
subroutine trexio_string_of_error_f (error, str_size, string) bind(C)
import
integer(trexio_exit_code), intent(in), value :: error
character(kind=c_char), intent(out) :: string(<<MAX_STRING_LENGTH()>>)
end subroutine trexio_string_of_error
integer(c_int32_t), intent(in), value :: str_size
character(kind=c_char), intent(out) :: string(str_size)
end subroutine trexio_string_of_error_f
end interface
#+end_src
@ -1262,8 +1321,11 @@ trexio_open(const char* file_name, const char mode,
/* Data for the parent type */
strncpy(result->file_name, file_name, TREXIO_MAX_FILENAME_LENGTH);
if (result->file_name[TREXIO_MAX_FILENAME_LENGTH-1] != '\0') {
// See https://stackoverflow.com/a/50198398/4151327
size_t lenSrc = strnlen(file_name, TREXIO_MAX_FILENAME_LENGTH-1);
if (lenSrc < TREXIO_MAX_FILENAME_LENGTH) {
memcpy(result->file_name, file_name, lenSrc+1);
} else {
if (rc_open != NULL) *rc_open = TREXIO_INVALID_ARG_1;
free(result);
return NULL;
@ -1281,11 +1343,9 @@ trexio_open(const char* file_name, const char mode,
}
// assert (irc == 0);
trexio_exit_code rc;
/* Back end initialization */
rc = TREXIO_OPEN_ERROR;
trexio_exit_code rc = TREXIO_OPEN_ERROR;
switch (back_end_local) {
@ -2086,8 +2146,6 @@ trexio_pre_close (trexio_t* file)
if (file == NULL) return TREXIO_FILE_ERROR;
trexio_exit_code rc;
/* Check consistency between number of determinants and coefficients stored in the file */
if (file->version_major >= 2 && file->version_minor >= 2) {
@ -2097,6 +2155,8 @@ trexio_pre_close (trexio_t* file)
int64_t ndet, ncoeff;
if (has_det && has_coeff) {
trexio_exit_code rc = TREXIO_FAILURE;
rc = trexio_read_determinant_num_64(file, &ndet);
if (rc != TREXIO_SUCCESS) return rc;
@ -2116,7 +2176,11 @@ trexio_pre_close (trexio_t* file)
bool has_updn = (trexio_has_electron_num(file) == TREXIO_SUCCESS);
if (file->mode != 'r') {
if (has_updn && has_up && has_dn) {
trexio_exit_code rc = TREXIO_FAILURE;
rc = trexio_read_electron_up_num(file, &nup);
if (rc != TREXIO_SUCCESS) return rc;
@ -2135,7 +2199,11 @@ trexio_pre_close (trexio_t* file)
return TREXIO_INVALID_ELECTRON_NUM;
}
}
} else if (has_up && has_dn) {
trexio_exit_code rc = TREXIO_FAILURE;
rc = trexio_read_electron_up_num(file, &nup);
if (rc != TREXIO_SUCCESS) return rc;
@ -2145,7 +2213,11 @@ trexio_pre_close (trexio_t* file)
nelec = nup + ndn;
rc = trexio_write_electron_num(file, nelec);
if (rc != TREXIO_SUCCESS) return rc;
} else if (has_up) {
trexio_exit_code rc = TREXIO_FAILURE;
rc = trexio_read_electron_up_num(file, &nup);
if (rc != TREXIO_SUCCESS) return rc;
@ -2156,7 +2228,11 @@ trexio_pre_close (trexio_t* file)
nelec = nup;
rc = trexio_write_electron_num(file, nelec);
if (rc != TREXIO_SUCCESS) return rc;
} else if (has_dn) {
trexio_exit_code rc = TREXIO_FAILURE;
rc = trexio_read_electron_dn_num(file, &ndn);
if (rc != TREXIO_SUCCESS) return rc;
@ -2167,6 +2243,7 @@ trexio_pre_close (trexio_t* file)
nelec = ndn;
rc = trexio_write_electron_num(file, nelec);
if (rc != TREXIO_SUCCESS) return rc;
}
}
@ -2788,9 +2865,10 @@ trexio_read_$group_dset$_64 (trexio_t* const file, $group_dset_dtype_double$* co
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
trexio_exit_code rc;
int64_t $group_dset_dim$ = 0;
trexio_exit_code rc = TREXIO_FAILURE;
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
@ -2851,10 +2929,9 @@ trexio_write_$group_dset$_64 (trexio_t* const file, const $group_dset_dtype_doub
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (trexio_has_$group_dset$(file) == TREXIO_SUCCESS && file->mode != 'u') return TREXIO_DSET_ALREADY_EXISTS;
trexio_exit_code rc;
int64_t $group_dset_dim$ = 0;
trexio_exit_code rc = TREXIO_FAILURE;
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
@ -2948,9 +3025,10 @@ trexio_read_$group_dset$_32 (trexio_t* const file, $group_dset_dtype_single$* co
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
trexio_exit_code rc;
int64_t $group_dset_dim$ = 0;
trexio_exit_code rc = TREXIO_FAILURE;
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
@ -3022,9 +3100,10 @@ trexio_write_$group_dset$_32 (trexio_t* const file, const $group_dset_dtype_sing
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (trexio_has_$group_dset$(file) == TREXIO_SUCCESS && file->mode != 'u') return TREXIO_DSET_ALREADY_EXISTS;
trexio_exit_code rc;
int64_t $group_dset_dim$ = 0;
trexio_exit_code rc = TREXIO_FAILURE;
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
@ -3088,9 +3167,11 @@ trexio_write_$group_dset$_32 (trexio_t* const file, const $group_dset_dtype_sing
#+NAME:dimCheck
#+begin_src c
trexio_exit_code rc;
int64_t $group_dset_dim$ = 0;
trexio_exit_code rc = TREXIO_FAILURE;
(void) rc; // Avoids unused parameter error for scalar variables
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
@ -3574,6 +3655,12 @@ trexio_exit_code trexio_read_safe_$group_dset$(trexio_t* const file,
const int64_t size_value_read
)
{
/* To be set by generator : number of indices */
const uint32_t rank = $group_dset_rank$;
if (size_index_read < rank * (*buffer_size_read)) return TREXIO_INVALID_ARG_5;
if (size_value_read < (*buffer_size_read)) return TREXIO_INVALID_ARG_7;
return trexio_read_$group_dset$(file, offset_file, buffer_size_read, index_sparse_read, value_sparse_read);
}
@ -3595,10 +3682,9 @@ trexio_read_$group_dset$(trexio_t* const file,
const uint32_t rank = $group_dset_rank$; // To be set by generator : number of indices
int64_t size_max; // Max number of integrals (already in the file)
trexio_exit_code rc;
/* Read the max number of integrals stored in the file */
rc = trexio_read_$group_dset$_size(file, &size_max);
trexio_exit_code rc = trexio_read_$group_dset$_size(file, &size_max);
if (rc != TREXIO_SUCCESS) return rc;
/* To be set by generator : number of unique dimensions
@ -3706,6 +3792,12 @@ trexio_exit_code trexio_write_safe_$group_dset$(trexio_t* const file,
const int64_t size_value_write
)
{
/* To be set by generator : number of indices */
const uint32_t rank = $group_dset_rank$;
if (size_index_write < rank * buffer_size) return TREXIO_INVALID_ARG_5;
if (size_value_write < buffer_size) return TREXIO_INVALID_ARG_7;
return trexio_write_$group_dset$(file, offset_file, buffer_size, index_sparse_write, value_sparse_write);
}
@ -3727,13 +3819,15 @@ trexio_write_$group_dset$(trexio_t* const file,
const uint32_t rank = $group_dset_rank$;
int64_t size_max = 0L; // Max number of integrals (already in the file)
trexio_exit_code rc;
/* Read the max number of integrals stored in the file */
rc = trexio_read_$group_dset$_size(file, &size_max);
trexio_exit_code rc = trexio_read_$group_dset$_size(file, &size_max);
if (rc != TREXIO_SUCCESS && rc != TREXIO_DSET_MISSING) return rc;
if (rc == TREXIO_DSET_MISSING) size_max = 0L;
/* Dummy check to avoid overwriting existing data */
if (offset_file < size_max) return TREXIO_CORRUPTION_ATTEMPT;
/* To be set by generator : number of unique dimensions
(e.g. 1 for ERI in AO basis because only ao_num is present in the list of dimensions) */
#define unique_rank $group_dset_unique_rank$
@ -4178,11 +4272,10 @@ trexio_read_$group_dset$_low (trexio_t* const file, char* dset_out, const int32_
if (max_str_len <= 0) return TREXIO_INVALID_ARG_3;
if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
trexio_exit_code rc;
int64_t $group_dset_dim$ = 0;
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
trexio_exit_code rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM;
@ -4221,11 +4314,10 @@ trexio_read_$group_dset$ (trexio_t* const file, char** dset_out, const int32_t m
assert(file->back_end < TREXIO_INVALID_BACK_END);
trexio_exit_code rc;
int64_t dset_dim = 0;
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &(dset_dim));
trexio_exit_code rc = trexio_read_$group_dset_dim$_64(file, &(dset_dim));
if (dset_dim == 0L) return TREXIO_INVALID_NUM;
@ -4268,11 +4360,10 @@ trexio_write_$group_dset$_low (trexio_t* const file, char* dset_in, const int32_
if (max_str_len <= 0) return TREXIO_INVALID_ARG_3;
if (trexio_has_$group_dset$(file) == TREXIO_SUCCESS && file->mode != 'u') return TREXIO_DSET_ALREADY_EXISTS;
trexio_exit_code rc;
int64_t $group_dset_dim$ = 0;
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
trexio_exit_code rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM;
@ -4354,11 +4445,10 @@ trexio_write_$group_dset$ (trexio_t* const file, const char** dset_in, const int
assert(file->back_end < TREXIO_INVALID_BACK_END);
trexio_exit_code rc;
int64_t dset_dim = 0;
/* Error handling for this call is added by the generator */
rc = trexio_read_$group_dset_dim$_64(file, &(dset_dim));
trexio_exit_code rc = trexio_read_$group_dset_dim$_64(file, &(dset_dim));
if (dset_dim == 0L) return TREXIO_INVALID_NUM;
@ -4627,7 +4717,7 @@ trexio_read_$group_dset$ (trexio_t* const file, const int64_t offset_file, int64
if (dset == NULL) return TREXIO_INVALID_ARG_2;
if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
trexio_exit_code rc;
trexio_exit_code rc = TREXIO_FAILURE;
uint32_t rank = 1;
uint64_t det_size = (uint64_t) (*buffer_size_read);
@ -4656,8 +4746,8 @@ trexio_read_$group_dset$ (trexio_t* const file, const int64_t offset_file, int64
break;
,*/
default:
rc = TREXIO_FAILURE; /* Impossible case */
break;
rc = TREXIO_FAILURE;
break; /* Impossible case */
}
if (rc != TREXIO_SUCCESS && rc != TREXIO_END) return rc;
@ -4705,6 +4795,7 @@ trexio_read_$group_dset$_size(trexio_t* const file, int64_t* const size_max)
trexio_exit_code
trexio_read_safe_$group_dset$ (trexio_t* const file, const int64_t offset_file, int64_t* const buffer_size_read, double* const dset_out, const int64_t dim_out)
{
if (dim_out < (*buffer_size_read)) return TREXIO_INVALID_ARG_5;
return trexio_read_$group_dset$(file, offset_file, buffer_size_read, dset_out);
}
#+end_src
@ -4751,6 +4842,9 @@ trexio_write_$group_dset$ (trexio_t* const file, const int64_t offset_file, cons
trexio_exit_code
trexio_write_safe_$group_dset$ (trexio_t* const file, const int64_t offset_file, const int64_t buffer_size, const double* dset_in, const int64_t dim_in)
{
/* Check that dim_in is large enough */
if (dim_in < buffer_size) return TREXIO_INVALID_ARG_5;
return trexio_write_$group_dset$(file, offset_file, buffer_size, dset_in);
}
#+end_src
@ -5182,11 +5276,7 @@ end interface
integer(c_int32_t), intent(in), value :: max_str_len
character(len=*), intent(in) :: str
character(len=len_trim(str)+1) :: str_c
str_c = trim(str) // c_null_char
trexio_write_$group_str$ = trexio_write_$group_str$_c(trex_file, str_c, max_str_len)
trexio_write_$group_str$ = trexio_write_$group_str$_c(trex_file, trim(str) // c_null_char, max_str_len)
end function trexio_write_$group_str$
#+end_src
@ -5384,7 +5474,7 @@ trexio_get_int64_num(trexio_t* const file, int32_t* const num)
/* Compute how many integer numbers is needed to represent a determinant */
int32_t int_num = 0;
int_num = (mo_num - 1L)/64 + 1;
int_num = (int32_t) (mo_num - 1L)/64 + 1;
*num = int_num;
@ -5398,7 +5488,10 @@ trexio_read_determinant_list (trexio_t* const file, const int64_t offset_file, i
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (dset == NULL) return TREXIO_INVALID_ARG_2;
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (buffer_size_read == NULL) return TREXIO_INVALID_ARG_3;
if (*buffer_size_read < 0) return TREXIO_INVALID_ARG_3;
if (dset == NULL) return TREXIO_INVALID_ARG_4;
if (trexio_has_determinant_list(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
/* Get the number of int bit fields per determinant */
@ -5449,17 +5542,44 @@ trexio_read_determinant_list (trexio_t* const file, const int64_t offset_file, i
trexio_exit_code
trexio_read_safe_determinant_list (trexio_t* const file, const int64_t offset_file, int64_t* const buffer_size_read, int64_t* const dset_out, const int64_t dim_out)
{
/* Get the number of int bit fields per determinant */
int32_t int_num = 0;
trexio_exit_code rc = trexio_get_int64_num(file, &int_num);
if (rc != TREXIO_SUCCESS) return rc;
/* Check that dset_out is large enough */
if (dim_out < (*buffer_size_read) * int_num * 2) return TREXIO_INVALID_ARG_5;
return trexio_read_determinant_list(file, offset_file, buffer_size_read, dset_out);
}
#+end_src
When writing a determinant list, the indices of the MOs are checked. If they
are out of bounds (<0 or >= mo_num), the error ~TREXIO_INVALID_MO_INDEX~ is returned.
If the number of orbitals in up-spin or down-spin determinants is different from
the number of up-spin and down-spin electrons, the error ~TREXIO_INVALID_ELECTRON_NUM~
is returned.
#+begin_src c :tangle write_determinant_front.c
trexio_exit_code
trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file, const int64_t buffer_size, const int64_t* dset)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (dset == NULL) return TREXIO_INVALID_ARG_2;
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (buffer_size <= 0) return TREXIO_INVALID_ARG_3;
if (dset == NULL) return TREXIO_INVALID_ARG_4;
// Update the determinant_num value with the number of determinants written
int64_t det_num_current = 0L;
// Read the determinant_num if it exists already
if (trexio_has_determinant_num(file) == TREXIO_SUCCESS) {
trexio_exit_code rc = trexio_read_determinant_num_64(file, &det_num_current);
if (rc != TREXIO_SUCCESS) return rc;
}
/* Dummy check to avoid overwriting existing data */
if (offset_file < det_num_current) return TREXIO_CORRUPTION_ATTEMPT;
/* Get the number of int bit fields per determinant */
int32_t int_num = 0;
@ -5471,6 +5591,59 @@ trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file,
assert(file->back_end < TREXIO_INVALID_BACK_END);
/* Read the number of mos */
int64_t mo_num = 0L;
rc = trexio_read_mo_num_64(file, &mo_num);
if (rc != TREXIO_SUCCESS) return rc;
// Read up/dn num
int32_t nup = 0;
rc = trexio_read_electron_up_num(file, &nup);
if (rc != TREXIO_SUCCESS) return rc;
int32_t ndn = 0;
rc = trexio_read_electron_dn_num(file, &ndn);
if (rc != TREXIO_SUCCESS) return rc;
/* Check all determinants */
int32_t occ_num_up = 0;
int32_t occ_num_dn = 0;
/* list_up contains first the up-spin orbitals, then the down-spin */
int32_t* list_up = (int32_t*) calloc(nup+ndn,sizeof(int32_t));
if (list_up == NULL) {
return TREXIO_ALLOCATION_FAILED;
}
int32_t* list_dn = &(list_up[nup]);
for (int64_t i=0 ; i<buffer_size ; i+= 2*int_num) {
rc = trexio_to_orbital_list_up_dn(int_num, &dset[i],
list_up, list_dn,
&occ_num_up, &occ_num_dn);
if (rc != TREXIO_SUCCESS) {
free(list_up);
return rc;
}
if (occ_num_up != nup || occ_num_dn != ndn) {
free(list_up);
return TREXIO_INVALID_ELECTRON_NUM;
}
for (int32_t j=0 ; j<nup+ndn ; ++j) {
if (list_up[j] < 0 || list_up[j] >= mo_num) {
free(list_up);
return TREXIO_INVALID_MO_INDEX;
}
}
}
free(list_up);
/* Up to this point, all the determinants have been checked to
have the correct sizes (number of electrons), and MOs in the
correct range */
switch (file->back_end) {
case TREXIO_TEXT:
@ -5523,6 +5696,14 @@ trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file,
trexio_exit_code
trexio_write_safe_determinant_list (trexio_t* const file, const int64_t offset_file, const int64_t buffer_size, const int64_t* dset_in, const int64_t dim_in)
{
/* Get the number of int bit fields per determinant */
int32_t int_num = 0;
trexio_exit_code rc = trexio_get_int64_num(file, &int_num);
if (rc != TREXIO_SUCCESS) return rc;
/* Check that dim_in is large enough */
if (dim_in < buffer_size * int_num * 2) return TREXIO_INVALID_ARG_5;
return trexio_write_determinant_list(file, offset_file, buffer_size, dset_in);
}
#+end_src
@ -5868,18 +6049,18 @@ trexio_exit_code trexio_convert_nao_radius_py (const double r,
double* grid_r, int32_t n_grid_r, double* const log_r_out);
trexio_exit_code trexio_evaluate_nao_radial (const int32_t shell_index,
const double r, const int32_t* const grid_start, const int32_t* const grid_size,
const double* const grid_r, const double* const interpolator,
const double* const grid_r, const double* const interpolator,
const double* const normalization, double* const amplitude);
trexio_exit_code trexio_evaluate_nao_radial_all (const int32_t shell_num,
const int32_t* const nucleus_index, const double* const nucleus_coords,
const int32_t* const grid_start, const int32_t* const grid_size,
const double* const grid_r, const double* const interpolator, const double* const normalization,
const int32_t* const nucleus_index, const double* const nucleus_coords,
const int32_t* const grid_start, const int32_t* const grid_size,
const double* const grid_r, const double* const interpolator, const double* const normalization,
const double rx, const double ry, const double rz, double* const amplitude);
trexio_exit_code trexio_evaluate_nao_radial_py (const int shell_index,
trexio_exit_code trexio_evaluate_nao_radial_py (const int shell_index,
const double r, int64_t* grid_start, int n_grid_st, int64_t* grid_size,
int n_grid_si, double* grid_r, int n_grid_r, double* interpolator,
int n_grid_si, double* grid_r, int n_grid_r, double* interpolator,
int n_interp, double* normalization, int n_norm, double* const amplitude);
trexio_exit_code trexio_evaluate_nao_radial_all_py (const int32_t shell_num,
@ -5984,10 +6165,8 @@ trexio_exit_code trexio_to_orbital_list_up_dn(const int32_t N_int,
if (occ_num_up == NULL) return TREXIO_INVALID_ARG_5;
if (occ_num_dn == NULL) return TREXIO_INVALID_ARG_6;
trexio_exit_code rc;
/* First process up-spin electrons */
rc = trexio_to_orbital_list(N_int, &d1[0], list_up, occ_num_up);
trexio_exit_code rc = trexio_to_orbital_list(N_int, &d1[0], list_up, occ_num_up);
if (rc != TREXIO_SUCCESS) return rc;
/* Now process down-spin electrons */
@ -6007,6 +6186,14 @@ trexio_safe_to_orbital_list (const int32_t N_int,
const int64_t dim_out,
int32_t* const num)
{
if (dim_in < N_int) return TREXIO_INVALID_ARG_3;
/* Count number of up electrons in first bitfield */
int count = 0;
for (int i=0 ; i<N_int; i++) {
count += popcnt(dset_in[i]);
}
if (dim_out < count) return TREXIO_INVALID_ARG_5;
return trexio_to_orbital_list(N_int, dset_in, dset_out, num);
}
@ -6021,6 +6208,21 @@ trexio_safe_to_orbital_list_up_dn (const int32_t N_int,
int32_t* const num_up,
int32_t* const num_dn)
{
if (dim_in < 2*N_int) return TREXIO_INVALID_ARG_3;
/* Count number of up electrons in first bitfield */
int count = 0;
for (int i=0 ; i<N_int; i++) {
count += popcnt(dset_in[i]);
}
if (dim_up_out < count) return TREXIO_INVALID_ARG_5;
/* Count number of up electrons in second bitfield */
count = 0;
for (int i=N_int ; i<2*N_int; i++) {
count += popcnt(dset_in[i]);
}
if (dim_dn_out < count) return TREXIO_INVALID_ARG_7;
return trexio_to_orbital_list_up_dn(N_int, dset_in, dset_up_out, dset_dn_out, num_up, num_dn);
}
#+end_src
@ -6029,23 +6231,22 @@ trexio_safe_to_orbital_list_up_dn (const int32_t N_int,
trexio_exit_code
trexio_convert_nao_radius_32 (const float r, const float* const grid_r, float* const log_r_out)
{
if (r < 0) return TREXIO_INVALID_ARG_1;
if (r <= 0.) return TREXIO_INVALID_ARG_1;
if (grid_r == NULL) return TREXIO_INVALID_ARG_2;
if (log_r_out == NULL) return TREXIO_INVALID_ARG_3;
*log_r_out = log(r / grid_r[0]) / log(grid_r[1] / grid_r[0]);
,*log_r_out = (float) log((double) r / grid_r[0]) / log((double) grid_r[1] / grid_r[0]);
return TREXIO_SUCCESS;
}
trexio_exit_code
trexio_convert_nao_radius_64 (const double r, const double* const grid_r, double* const log_r_out)
{
if (r < 0) return TREXIO_INVALID_ARG_1;
if (r <= 0.) return TREXIO_INVALID_ARG_1;
if (grid_r == NULL) return TREXIO_INVALID_ARG_2;
if (log_r_out == NULL) return TREXIO_INVALID_ARG_3;
*log_r_out = log(r / grid_r[0]) / log(grid_r[1] / grid_r[0]);
,*log_r_out = log(r / grid_r[0]) / log(grid_r[1] / grid_r[0]);
return TREXIO_SUCCESS;
}
@ -6053,11 +6254,12 @@ trexio_convert_nao_radius_64 (const double r, const double* const grid_r, double
trexio_exit_code
trexio_convert_nao_radius_py (const double r, double* grid_r, int32_t n_grid, double* const log_r_out)
{
if (r < 0) return TREXIO_INVALID_ARG_1;
if (r <= 0.) return TREXIO_INVALID_ARG_1;
if (grid_r == NULL) return TREXIO_INVALID_ARG_2;
if (log_r_out == NULL) return TREXIO_INVALID_ARG_3;
if (n_grid < 2) return TREXIO_INVALID_ARG_3;
if (log_r_out == NULL) return TREXIO_INVALID_ARG_4;
*log_r_out = log(r / grid_r[0]) / log(grid_r[1] / grid_r[0]);
,*log_r_out = log(r / grid_r[0]) / log(grid_r[1] / grid_r[0]);
return TREXIO_SUCCESS;
}
@ -6077,12 +6279,12 @@ trexio_evaluate_nao_radial (const int32_t shell_index, const double r, const int
if (interpolator == 0) return TREXIO_INVALID_ARG_6;
if (normalization == 0) return TREXIO_INVALID_ARG_7;
const int32_t i0 = 4*grid_start[shell_index];
const int64_t i0 = 4*grid_start[shell_index];
// Convert radius to logarithmic units
// Convert radius to logarithmic units
double r_log = 0.0;
trexio_convert_nao_radius_64 (r, grid_r + grid_start[shell_index], &r_log);
int32_t i_log = (int32_t) r_log;
int64_t i_log = (int64_t) r_log;
if (i_log < 0)
i_log = 0;
else if (i_log >= grid_size[shell_index])
@ -6094,13 +6296,13 @@ trexio_evaluate_nao_radial (const int32_t shell_index, const double r, const int
val_spline += t * t * interpolator[i0 + 4*i_log + 2];
val_spline += t * t * t * interpolator[i0 + 4*i_log + 3];
*amplitude = val_spline * normalization[shell_index] / r;
,*amplitude = val_spline * normalization[shell_index] / r;
return TREXIO_SUCCESS;
}
trexio_exit_code
trexio_evaluate_nao_radial_all (const int32_t shell_num, const int32_t* const nucleus_index, const double* const nucleus_coords, const int32_t* const grid_start,
const int32_t* const grid_size, const double* const grid_r, const double* const interpolator,
const int32_t* const grid_size, const double* const grid_r, const double* const interpolator,
const double* const normalization, const double rx, const double ry, const double rz, double* const amplitude)
{
if (shell_num < 0) return TREXIO_INVALID_ARG_1;
@ -6112,8 +6314,6 @@ trexio_evaluate_nao_radial_all (const int32_t shell_num, const int32_t* const nu
if (interpolator == 0) return TREXIO_INVALID_ARG_7;
if (normalization == 0) return TREXIO_INVALID_ARG_8;
trexio_exit_code rc;
for (int shell_index = 0; shell_index < shell_num; shell_index++) {
const int32_t nuc_index = nucleus_index[shell_index];
const double dx = nucleus_coords[3*nuc_index + 0] - rx;
@ -6122,7 +6322,7 @@ trexio_evaluate_nao_radial_all (const int32_t shell_num, const int32_t* const nu
const double r = sqrt(dx*dx + dy*dy + dz*dz);
// All possibly reported errors have been caught above
rc = trexio_evaluate_nao_radial(shell_index, r, grid_start,
trexio_exit_code rc = trexio_evaluate_nao_radial(shell_index, r, grid_start,
grid_size, grid_r, interpolator, normalization, &amplitude[shell_index]);
if (rc != TREXIO_SUCCESS)
@ -6132,42 +6332,50 @@ trexio_evaluate_nao_radial_all (const int32_t shell_num, const int32_t* const nu
return TREXIO_SUCCESS;
}
trexio_exit_code trexio_evaluate_nao_radial_py (const int shell_index,
trexio_exit_code trexio_evaluate_nao_radial_py (const int shell_index,
const double r, int64_t* grid_start, int n_grid_st,
int64_t* grid_size, int n_grid_si, double* grid_r, int n_grid_r,
double* interpolator, int n_interp, double* normalization, int n_norm, double* const amplitude)
int64_t* grid_size, int n_grid_si, double* grid_r, int n_grid_r,
double* interpolator, int n_interp, double* normalization, int n_norm,
double* const amplitude)
{
// Code needs to be copied because of the use of int64_t mandated by Python
// If a 64-bit version is implemented, this can be avoided
if (shell_index < 0) return TREXIO_INVALID_ARG_1;
if (r < 0) return TREXIO_INVALID_ARG_2;
if (grid_start == 0) return TREXIO_INVALID_ARG_3;
if (grid_size == 0) return TREXIO_INVALID_ARG_4;
if (grid_r == NULL) return TREXIO_INVALID_ARG_5;
if (interpolator == 0) return TREXIO_INVALID_ARG_6;
if (normalization == 0) return TREXIO_INVALID_ARG_7;
if (n_grid_st < shell_index) return TREXIO_INVALID_ARG_4;
if (grid_size == 0) return TREXIO_INVALID_ARG_5;
if (n_grid_si < shell_index) return TREXIO_INVALID_ARG_6;
if (grid_r == NULL) return TREXIO_INVALID_ARG_7;
if (n_grid_r < grid_start[shell_index]) return TREXIO_INVALID_ARG_8;
if (interpolator == NULL) return TREXIO_INVALID_ARG_9;
if (normalization == 0) return TREXIO_INVALID_ARG_11;
if (n_norm < shell_index) return TREXIO_INVALID_ARG_12;
const int32_t i0 = 4*grid_start[shell_index];
const int64_t i0 = 4*grid_start[shell_index];
if (n_interp < i0) return TREXIO_INVALID_ARG_10;
// Convert radius to logarithmic units
// Convert radius to logarithmic units
double r_log = 0.0;
trexio_convert_nao_radius_64 (r, grid_r + grid_start[shell_index], &r_log);
int32_t i_log = (int32_t) r_log;
int64_t i_log = (int64_t) r_log;
if (i_log < 0) {
*amplitude = interpolator[i0] * normalization[shell_index] / r;
,*amplitude = interpolator[i0] * normalization[shell_index] / r;
return TREXIO_SUCCESS;
} else if (i_log >= grid_size[shell_index]) {
*amplitude = 0.0;
,*amplitude = 0.0;
return TREXIO_SUCCESS; // NAOs vanish at the boundary by definition
}
double t = r_log - (double) i_log;
if (n_interp < i0+4*i_log+3) return TREXIO_INVALID_ARG_10;
double val_spline = interpolator[i0 + 4*i_log + 0];
val_spline += t * interpolator[i0 + 4*i_log + 1];
val_spline += t * t * interpolator[i0 + 4*i_log + 2];
val_spline += t * t * t * interpolator[i0 + 4*i_log + 3];
*amplitude = val_spline * normalization[shell_index] / r;
,*amplitude = val_spline * normalization[shell_index] / r;
return TREXIO_SUCCESS;
}
@ -6176,29 +6384,38 @@ trexio_exit_code trexio_evaluate_nao_radial_all_py (const int32_t shell_num,
int64_t* grid_start, int n_grid_st, int64_t* grid_size, int n_grid_si,
double* grid_r, int n_grid_r, double* interpolator, int n_interp,
double* normalization, int n_norm,
const double rx, const double ry, const double rz, double* const amplitudes, int amplitude_cnt)
const double rx, const double ry, const double rz,
double* const amplitudes, int amplitude_cnt)
{
if (shell_num < 0) return TREXIO_INVALID_ARG_1;
if (nucleus_index == 0) return TREXIO_INVALID_ARG_2;
if (nucleus_coords == 0) return TREXIO_INVALID_ARG_3;
if (grid_start == 0) return TREXIO_INVALID_ARG_4;
if (grid_size == 0) return TREXIO_INVALID_ARG_5;
if (grid_r == NULL) return TREXIO_INVALID_ARG_6;
if (interpolator == 0) return TREXIO_INVALID_ARG_7;
if (normalization == 0) return TREXIO_INVALID_ARG_8;
if (nucleus_index == NULL) return TREXIO_INVALID_ARG_2;
if (nucleus_coords == NULL) return TREXIO_INVALID_ARG_4;
if (grid_start == NULL) return TREXIO_INVALID_ARG_6;
if (grid_size == NULL) return TREXIO_INVALID_ARG_8;
if (grid_r == NULL) return TREXIO_INVALID_ARG_10;
if (interpolator == NULL) return TREXIO_INVALID_ARG_12;
if (normalization == NULL) return TREXIO_INVALID_ARG_14;
trexio_exit_code rc;
assert (amplitudes != NULL); // 19 arguments!!! Don't want to make TREXIO_INVALID_ARG_19
assert (amplitude_cnt > shell_num);
if (n_nuc_id < shell_num) return TREXIO_INVALID_ARG_3;
if (n_nuc_co < 3*nucleus_index[shell_num-1]+2) return TREXIO_INVALID_ARG_5;
for (int shell_index = 0; shell_index < shell_num; shell_index++) {
const int32_t nuc_index = nucleus_index[shell_index];
const int64_t nuc_index = nucleus_index[shell_index];
const double dx = nucleus_coords[3*nuc_index + 0] - rx;
const double dy = nucleus_coords[3*nuc_index + 1] - ry;
const double dz = nucleus_coords[3*nuc_index + 2] - rz;
const double r = sqrt(dx*dx + dy*dy + dz*dz);
// All possibly reported errors have been caught above
rc = trexio_evaluate_nao_radial_py(shell_index, r, grid_start, n_grid_st,
grid_size, n_grid_si, grid_r, n_grid_r, interpolator, n_interp, normalization, n_norm, &amplitudes[shell_index]);
trexio_exit_code rc =
trexio_evaluate_nao_radial_py(shell_index, r, grid_start, n_grid_st, grid_size,
n_grid_si, grid_r, n_grid_r, interpolator, n_interp,
normalization, n_norm, &amplitudes[shell_index]);
if (rc != TREXIO_SUCCESS)
return rc;
}
@ -6501,14 +6718,14 @@ def to_orbital_list_up_dn(n_int: int, determinant: list) -> tuple:
def convert_nao_radius(r: float, grid_r) -> float:
"""Converts the radius r as a distance from a nucleus to the shell
s logarithmic grid.
Input:
~r~ - the radius to be converted
~grid_r~ - The radial grid of the shell. Note that this is only the
grid of the shell of interest, not the array of all shells.
Returns:
Float that gives the radius in the shell's logarithmic units
Float that gives the radius in the shell's logarithmic units
Raises:
- Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.
@ -6525,7 +6742,7 @@ def convert_nao_radius(r: float, grid_r) -> float:
def evaluate_nao_radial(shell_index, r, grid_start, grid_size, grid_r, interpolator, normalization) -> float:
"""Evaluates the radial function of a given NAO shell at a distance from its center.
Input:
~shell_index~ - index of the shell of interest
~r~ - distance from the shell center
@ -6538,7 +6755,7 @@ def evaluate_nao_radial(shell_index, r, grid_start, grid_size, grid_r, interpola
~normalization~ - array of radial function normalization constants.
Returns:
Value of the spline at the given radius
Value of the spline at the given radius
Raises:
- Error from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.
@ -6555,7 +6772,7 @@ def evaluate_nao_radial(shell_index, r, grid_start, grid_size, grid_r, interpola
def evaluate_nao_radial_all(nucleus_index, nucleus_coords, grid_start,
grid_size, grid_r, interpolator, normalization, r) -> float:
"""Evaluates the radial functions of all NAO shells at a given position in space.
Input:
~nucleus_index~ - array giving the centers of the NAO
~nucleus_coords~ - array giving the coordinates of the NAO centers
@ -6569,7 +6786,7 @@ def evaluate_nao_radial_all(nucleus_index, nucleus_coords, grid_start,
~r~ - the position in space at which the functions are evaluated
Returns:
Array of spline values at ~r~
Array of spline values at ~r~
Raises:
- Error if ~r~ is not three dimensional
@ -6600,6 +6817,18 @@ contains
end function trexio_info
#+end_src
This function adds the string length as an extra argument to help the C code
check that the passed string is large enough.
#+begin_src f90 :tangle helper_fortran.f90 :noweb yes
subroutine trexio_string_of_error (error, string)
implicit none
integer(trexio_exit_code), intent(in) :: error
character*(*), intent(out) :: string
call trexio_string_of_error_f(error, len(string), string)
end subroutine trexio_string_of_error
#+end_src
The function below adapts the original C-based ~trexio_open~ for Fortran.
This is needed due to the fact that strings in C are terminated by ~NULL~ character ~\0~
unlike strings in Fortran.
@ -6612,11 +6841,9 @@ contains
character, intent(in), value :: mode
integer(trexio_back_end_t), intent(in), value :: back_end
integer(trexio_exit_code), intent(out) :: rc_open
character(len=len_trim(filename)+1) :: filename_c
integer(trexio_exit_code) :: rc
filename_c = trim(filename) // c_null_char
trexio_open = trexio_open_c(filename_c, mode, back_end, rc_open)
trexio_open = trexio_open_c(trim(filename) // c_null_char, mode, back_end, rc_open)
if (trexio_open == 0_8 .or. rc_open /= TREXIO_SUCCESS) then
return
endif
@ -6636,10 +6863,8 @@ contains
integer(trexio_exit_code) function trexio_inquire (filename)
implicit none
character(len=*), intent(in) :: filename
character(len=len_trim(filename)+1) :: filename_c
filename_c = trim(filename) // c_null_char
trexio_inquire = trexio_inquire_c(filename_c)
trexio_inquire = trexio_inquire_c(trim(filename) // c_null_char)
end function trexio_inquire
#+end_src
@ -6650,12 +6875,8 @@ contains
implicit none
character(len=*), intent(in) :: source
character(len=*), intent(in) :: destination
character(len=len_trim(source)+1) :: source_c
character(len=len_trim(destination)+1) :: destination_c
source_c = trim(source) // c_null_char
destination_c = trim(destination) // c_null_char
trexio_cp = trexio_cp_c(source_c, destination_c)
trexio_cp = trexio_cp_c(trim(source) // c_null_char, trim(destination) // c_null_char)
end function trexio_cp
#+end_src

View File

@ -277,6 +277,7 @@ trexio_hdf5_write_$group_num$ (trexio_t* const file, const $group_num_dtype_doub
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (num < 0) return TREXIO_INVALID_ARG_2;
trexio_hdf5_t* const f = (trexio_hdf5_t*) file;
@ -355,6 +356,8 @@ trexio_hdf5_read_$group_dset$ (trexio_t* const file, $group_dset_dtype$* const $
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (rank < 1) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
const trexio_hdf5_t* f = (const trexio_hdf5_t*) file;
@ -412,6 +415,8 @@ trexio_hdf5_write_$group_dset$ (trexio_t* const file, const $group_dset_dtype$*
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (rank < 1) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
trexio_hdf5_t* f = (trexio_hdf5_t*) file;
@ -502,6 +507,11 @@ trexio_hdf5_write_$group_dset$ (trexio_t* const file,
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (size < 0) return TREXIO_INVALID_ARG_3;
if (size_max < 0) return TREXIO_INVALID_ARG_4;
if (index_sparse == NULL) return TREXIO_INVALID_ARG_5;
if (value_sparse == NULL) return TREXIO_INVALID_ARG_6;
trexio_hdf5_t* f = (trexio_hdf5_t*) file;
@ -593,7 +603,12 @@ trexio_hdf5_read_$group_dset$ (trexio_t* const file,
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (size < 0) return TREXIO_INVALID_ARG_3;
if (size_max < 0) return TREXIO_INVALID_ARG_4;
if (eof_read_size == NULL) return TREXIO_INVALID_ARG_5;
if (index_read == NULL) return TREXIO_INVALID_ARG_6;
if (value_read == NULL) return TREXIO_INVALID_ARG_7;
const trexio_hdf5_t* f = (const trexio_hdf5_t*) file;
@ -703,6 +718,9 @@ trexio_exit_code trexio_hdf5_read_$group_dset$(trexio_t* const file,
double* const dset)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (rank != 1) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
if (eof_read_size == NULL) return TREXIO_INVALID_ARG_5;
if (dset == NULL) return TREXIO_INVALID_ARG_6;
@ -728,6 +746,9 @@ trexio_exit_code trexio_hdf5_write_$group_dset$(trexio_t* const file,
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (rank != 1) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
if (dset == NULL) return TREXIO_INVALID_ARG_5;
const char* dset_name = "$group_dset$";
@ -832,6 +853,9 @@ trexio_hdf5_read_$group_dset$ (trexio_t* const file, char* const $group_dset$, c
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (rank < 1) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
if (max_str_len < 1) return TREXIO_INVALID_ARG_5;
const trexio_hdf5_t* f = (const trexio_hdf5_t*) file;
@ -938,6 +962,8 @@ trexio_hdf5_write_$group_dset$ (trexio_t* const file, const char** $group_dset$,
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (rank < 1) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
trexio_hdf5_t* f = (trexio_hdf5_t*) file;
@ -1031,6 +1057,7 @@ trexio_hdf5_read_$group_str$ (trexio_t* const file, char* const str, const uint3
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (str == NULL) return TREXIO_INVALID_ARG_2;
if (max_str_len < 1) return TREXIO_INVALID_ARG_3;
const trexio_hdf5_t* f = (const trexio_hdf5_t*) file;
/* Quit if the string attribute is missing in the file */
@ -1202,6 +1229,9 @@ trexio_exit_code trexio_hdf5_read_determinant_list(trexio_t* const file,
int64_t* const list)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (rank < 2) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
if (eof_read_size == NULL) return TREXIO_INVALID_ARG_5;
if (list == NULL) return TREXIO_INVALID_ARG_6;
@ -1227,6 +1257,9 @@ trexio_exit_code trexio_hdf5_write_determinant_list(trexio_t* const file,
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (rank < 2) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
if (list == NULL) return TREXIO_INVALID_ARG_5;
trexio_hdf5_t* f = (trexio_hdf5_t*) file;
@ -1292,6 +1325,9 @@ trexio_hdf5_create_write_dset_sparse (const hid_t group_id,
const hsize_t* chunk_dims,
const void* data_sparse)
{
assert (chunk_dims != NULL);
assert (data_sparse != NULL);
assert (dset_name != NULL);
const int h5_rank = 1;
const hsize_t maxdims[1] = {H5S_UNLIMITED};

View File

@ -222,6 +222,7 @@ trexio_text_init (trexio_t* const file)
char file_name[TREXIO_MAX_FILENAME_LENGTH];
strncpy (file_name, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
file_name[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
strncat (file_name, lock_file_name, TREXIO_MAX_FILENAME_LENGTH-strlen(lock_file_name));
if (file_name[TREXIO_MAX_FILENAME_LENGTH-1] != '\0') {
@ -241,6 +242,7 @@ trexio_text_init (trexio_t* const file)
char dirname[TREXIO_MAX_FILENAME_LENGTH] = "/tmp/trexio.XXXXXX";
if (mkdtemp(dirname) == NULL) return TREXIO_ERRNO;
strncpy (file_name, dirname, TREXIO_MAX_FILENAME_LENGTH);
file_name[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
strncat (file_name, lock_file_name, TREXIO_MAX_FILENAME_LENGTH-strlen(lock_file_name));
f->lock_file = open(file_name,O_WRONLY|O_CREAT|O_TRUNC, 0644);
remove(file_name);
@ -332,8 +334,7 @@ trexio_text_flush (trexio_t* const file)
trexio_exit_code rc;
trexio_text_t* f = (trexio_text_t*) file;
/* Error handling for this call is added by the generator */
rc = trexio_text_flush_$group$(f);
rc = trexio_text_flush_$group$(f); if (rc != TREXIO_SUCCESS) return rc;
return TREXIO_SUCCESS;
@ -368,6 +369,7 @@ trexio_text_read_$group$ (trexio_text_t* const file)
const char* $group$_file_name = "/$group$.txt";
strncpy ($group$->file_name, file->parent.file_name, TREXIO_MAX_FILENAME_LENGTH);
$group$->file_name[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
strncat ($group$->file_name, $group$_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen($group$_file_name));
@ -394,7 +396,9 @@ trexio_text_read_$group$ (trexio_text_t* const file)
}
int rc = 0;
(void) rc; // Avoid unused variable;
trexio_exit_code rc_free = TREXIO_FAILURE;
(void) rc_free; // Avoid unused variable;
/* workaround for the case of missing blocks in the file */
// START REPEAT GROUP_DSET_ALL
@ -466,16 +470,16 @@ trexio_text_read_$group$ (trexio_text_t* const file)
}
/* WARNING: this tmp array allows to avoid allocation of space for each element of array of string
* BUT it's size has to be number_of_str*max_len_str where max_len_str is somewhat arbitrary, e.g. 32.
*/
,* BUT it's size has to be number_of_str*max_len_str where max_len_str is somewhat arbitrary, e.g. 32.
,*/
char* tmp_$group_dset$;
tmp_$group_dset$ = CALLOC(size_$group_dset$*32, char);
for (uint64_t i=0 ; i<size_$group_dset$ ; ++i) {
$group$->$group_dset$[i] = tmp_$group_dset$;
/* conventional fcanf with "%s" only return the string before the first space character
* to read string with spaces use "%[^\n]" possible with space before or after, i.e. " %[^\n]"
*/
,* to read string with spaces use "%[^\n]" possible with space before or after, i.e. " %[^\n]"
,*/
rc = fscanf(f, " %1023[^\n]", buffer);
if (rc != 1) {
trexio_text_free_read_$group$(buffer, f, file, $group$);
@ -484,6 +488,7 @@ trexio_text_read_$group$ (trexio_text_t* const file)
size_t tmp_$group_dset$_len = strlen(buffer);
strncpy(tmp_$group_dset$, buffer, 32);
tmp_$group_dset$[31] = '\0';
tmp_$group_dset$ += tmp_$group_dset$_len + 1;
}
}
@ -548,6 +553,7 @@ trexio_text_read_$group$ (trexio_text_t* const file)
}
/* Safer string conversion to avoid buffer overflow in fscanf */
strncpy($group$->$group_str$, buffer, $group$->len_$group_str$);
$group$->$group_str$[$group$->len_$group_str$-1] = '\0';
}
// END REPEAT GROUP_ATTR_STR
@ -592,6 +598,7 @@ trexio_text_has_$group$ (trexio_t* const file)
const char* $group$_file_name = "/$group$.txt";
strncpy ($group$_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
$group$_full_path[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
strncat ($group$_full_path, $group$_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen($group$_file_name));
@ -721,6 +728,10 @@ trexio_text_free_$group$ (trexio_text_t* const file)
This function is called upon the non-successful exit from the ~trexio_text_read_group~ function.
#+begin_src c :tangle free_group_text.h :exports none
trexio_exit_code trexio_text_free_read_$group$ (char* buffer, FILE* txt_file, trexio_text_t* trexio_file, $group$_t* $group$);
#+end_src
#+begin_src c :tangle free_group_text.c
trexio_exit_code
trexio_text_free_read_$group$ (char* buffer, FILE* txt_file, trexio_text_t* trexio_file, $group$_t* $group$)
@ -820,6 +831,8 @@ trexio_text_read_$group_dset$ (trexio_t* const file, $group_dset_dtype$* const $
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (rank < 1) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
$group$_t* const $group$ = trexio_text_read_$group$((trexio_text_t*) file);
if ($group$ == NULL) return TREXIO_FAILURE;
@ -849,6 +862,8 @@ trexio_text_write_$group_dset$ (trexio_t* const file, const $group_dset_dtype$*
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (rank < 1) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
if (file->mode == 'r') return TREXIO_READONLY;
@ -966,9 +981,10 @@ trexio_text_write_$group_dset$ (trexio_t* const file, const char** dset, const u
if (tmp_str == NULL) return TREXIO_ALLOCATION_FAILED;
for (uint64_t i=0 ; i<dims[0] ; ++i) {
size_t tmp_len = strlen(dset[i]);
size_t tmp_len = strlen(dset[i])+1;
$group$->$group_dset$[i] = tmp_str;
strncpy(tmp_str, dset[i], tmp_len);
tmp_str[tmp_len-1] = '\0';
tmp_str += tmp_len + 1;
}
@ -1017,6 +1033,7 @@ trexio_text_read_$group_str$ (trexio_t* const file, char* const str, const uint3
if ($group$ == NULL) return TREXIO_FAILURE;
strncpy(str, $group$->$group_str$, max_str_len);
str[max_str_len-1] = '\0';
return TREXIO_SUCCESS;
@ -1046,6 +1063,7 @@ trexio_text_write_$group_str$ (trexio_t* const file, const char *str)
$group$->len_$group_str$ = tmp_len + 1;
strncpy($group$->$group_str$, str, tmp_len + 1);
$group$->$group_str$[tmp_len] = '\0';
$group$->to_flush = 1;
@ -1109,6 +1127,7 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file,
/* Copy directory name in file_full_path */
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
file_full_path[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
/* Append name of the file with sparse data */
strncat (file_full_path, $group_dset$_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen($group_dset$_file_name));
@ -1121,6 +1140,8 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file,
the line_length is 69 because 10 per index + 4 spaces + 24 for floating point value + 1 for the new line char.
CURRENTLY NO OFFSET IS USED WHEN WRITING !
,*/
(void) offset_file; // Avoid unused variable error
int64_t line_length = 0L;
char format_str[256];
@ -1128,12 +1149,15 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file,
if (size_max < UINT8_MAX) {
line_length = $sparse_line_length_8$; // 41 for 4 indices
strncpy(format_str, $sparse_format_printf_8$, 256);
format_str[255] = '\0';
} else if (size_max < UINT16_MAX) {
line_length = $sparse_line_length_16$; // 49 for 4 indices
strncpy(format_str, $sparse_format_printf_16$, 256);
format_str[255] = '\0';
} else {
line_length = $sparse_line_length_32$; //69 for 4 indices
strncpy(format_str, $sparse_format_printf_32$, 256);
format_str[255] = '\0';
}
strncat(format_str, "\n", 2);
@ -1183,6 +1207,7 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file,
memset (file_full_path, 0, TREXIO_MAX_FILENAME_LENGTH);
/* Copy directory name in file_full_path */
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
file_full_path[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
/* Append name of the file with sparse data */
strncat (file_full_path, $group$_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen($group$_file_name));
@ -1222,6 +1247,7 @@ trexio_exit_code trexio_text_read_$group_dset$(trexio_t* const file,
/* Copy directory name in file_full_path */
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
file_full_path[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
/* Append name of the file with sparse data */
strncat (file_full_path, $group_dset$_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen($group_dset$_file_name));
@ -1297,6 +1323,7 @@ trexio_exit_code trexio_text_read_$group_dset$_size(trexio_t* const file, int64_
/* Copy directory name in file_full_path */
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
file_full_path[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
/* Append name of the file with sparse data */
strncat (file_full_path, $group_dset$_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen($group_dset$_file_name));
@ -1347,6 +1374,7 @@ trexio_exit_code trexio_text_has_$group_dset$(trexio_t* const file)
/* Copy directory name in file_full_path */
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
file_full_path[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
/* Append name of the file with sparse data */
strncat (file_full_path, $group_dset$_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen($group_dset$_file_name));
@ -1383,6 +1411,9 @@ trexio_exit_code trexio_text_read_$group_dset$(trexio_t* const file,
double* const dset)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (rank < 1) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
if (eof_read_size == NULL) return TREXIO_INVALID_ARG_5;
if (dset == NULL) return TREXIO_INVALID_ARG_6;
@ -1392,6 +1423,7 @@ trexio_exit_code trexio_text_read_$group_dset$(trexio_t* const file,
char file_full_path[TREXIO_MAX_FILENAME_LENGTH];
/* Copy directory name in file_full_path */
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
file_full_path[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
/* Append name of the file with sparse data */
strncat (file_full_path, file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(file_name));
@ -1454,6 +1486,7 @@ trexio_text_read_$group_dset$_size(trexio_t* const file, int64_t* const size_max
char file_full_path[TREXIO_MAX_FILENAME_LENGTH];
/* Copy directory name in file_full_path */
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
file_full_path[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
/* Append name of the file with sparse data */
strncat (file_full_path, file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(file_name));
@ -1495,6 +1528,9 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file,
const double* dset)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (rank < 1) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
if (dset == NULL) return TREXIO_INVALID_ARG_5;
const char file_name[256] = "/$group_dset$.txt";
@ -1504,6 +1540,7 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file,
char file_full_path[TREXIO_MAX_FILENAME_LENGTH];
/* Copy directory name in file_full_path */
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
file_full_path[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
/* Append name of the file with sparse data */
strncat (file_full_path, file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(file_name));
@ -1551,6 +1588,7 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file,
memset (file_full_path, 0, TREXIO_MAX_FILENAME_LENGTH);
/* Copy directory name in file_full_path */
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
file_full_path[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
/* Append name of the file with sparse data */
strncat (file_full_path, group_file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(group_file_name));
@ -1579,6 +1617,7 @@ trexio_exit_code trexio_text_has_$group_dset$(trexio_t* const file)
char file_full_path[TREXIO_MAX_FILENAME_LENGTH];
/* Copy directory name in file_full_path */
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
file_full_path[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
/* Append name of the file with sparse data */
strncat (file_full_path, file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(file_name));
@ -1642,6 +1681,9 @@ trexio_exit_code trexio_text_read_determinant_list(trexio_t* const file,
int64_t* const list)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (rank != 2) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
if (eof_read_size == NULL) return TREXIO_INVALID_ARG_5;
if (list == NULL) return TREXIO_INVALID_ARG_6;
@ -1651,6 +1693,7 @@ trexio_exit_code trexio_text_read_determinant_list(trexio_t* const file,
/* Copy directory name in file_full_path */
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
file_full_path[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
/* Append name of the file with sparse data */
strncat (file_full_path, determinant_list_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen(determinant_list_file_name));
@ -1660,12 +1703,13 @@ trexio_exit_code trexio_text_read_determinant_list(trexio_t* const file,
if (f == NULL) return TREXIO_FILE_ERROR;
/* Specify the line length in order to offset properly.
Each 64-bit integer takes at most 10 slots and requires one space,
Each 64-bit integer takes 20 slots and requires one space,
we have int_num integers per up-spin determinant,
then this number is doubled because we have the same number for down-spin electrons,
and then one newline char.
,*/
uint64_t line_length = dims[1]*11UL + 1UL; // 10 digits per int64_t bitfield + 1 space = 11 spots + 1 newline char
uint64_t line_length = dims[1]*21UL + 1UL; // 20 digits per int64_t bitfield + 1 space = 21 spots + 1 newline char
/* Offset in the file according to the provided value of offset_file and optimal line_length */
fseek(f, (long) offset_file * line_length, SEEK_SET);
@ -1673,11 +1717,11 @@ trexio_exit_code trexio_text_read_determinant_list(trexio_t* const file,
/* Read the data from the file and check the return code of fprintf to verify that > 0 bytes have been read or reached EOF */
int rc;
/* Declare fixed buffer which will be used to read the determinant string <a1 a2 ... a/\ b1 b2 ... b\/> */
char buffer[1024];
uint32_t buf_size = sizeof(buffer);
char buffer[line_length+1];
size_t buf_size = sizeof(buffer);
/* Parameters to post-process the buffer and to get bit fields integers */
uint64_t accum = 0UL;
uint32_t shift_int64 = 11U;
uint32_t shift_int64 = 21U;
/* Counter for number of elements beind processed */
uint64_t count = 0UL;
for (uint64_t i=0UL; i < dims[0]; ++i) {
@ -1685,7 +1729,7 @@ trexio_exit_code trexio_text_read_determinant_list(trexio_t* const file,
accum = 0UL;
memset(buffer, 0, buf_size);
if (fgets(buffer, buf_size-1, f) == NULL){
if (fgets(buffer, ( (int) line_length)+1, f) == NULL){
fclose(f);
,*eof_read_size = count;
@ -1697,7 +1741,7 @@ trexio_exit_code trexio_text_read_determinant_list(trexio_t* const file,
Thus, we parse the buffer string int_num*2 times to get the bit field determinants.
,*/
for (uint32_t j=0; j < (uint32_t) dims[1]; ++j) {
rc = sscanf(buffer+accum, "%10" SCNd64, list + dims[1]*i + j);
rc = sscanf(buffer+accum, "%20" SCNd64, list + dims[1]*i + j);
if (rc <= 0) {
fclose(f);
return TREXIO_FAILURE;
@ -1724,7 +1768,10 @@ trexio_exit_code trexio_text_write_determinant_list(trexio_t* const file,
const uint64_t* dims,
const int64_t* list)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (rank != 2) return TREXIO_INVALID_ARG_3;
if (dims == NULL) return TREXIO_INVALID_ARG_4;
if (list == NULL) return TREXIO_INVALID_ARG_5;
const char determinant_list_file_name[256] = "/determinant_list.txt";
@ -1733,6 +1780,7 @@ trexio_exit_code trexio_text_write_determinant_list(trexio_t* const file,
/* Copy directory name in file_full_path */
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
file_full_path[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
/* Append name of the file with sparse data */
strncat (file_full_path, determinant_list_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen(determinant_list_file_name));
@ -1747,7 +1795,7 @@ trexio_exit_code trexio_text_write_determinant_list(trexio_t* const file,
/* The loop below is needed to write a line with int bit fields for alpha and beta electrons */
for (uint32_t j=0; j < (uint32_t) dims[1]; ++j) {
rc = fprintf(f, "%10" PRId64 " ", *(list + i*dims[1] + j));
rc = fprintf(f, "%20" PRId64 " ", *(list + i*dims[1] + j));
if (rc <= 0) {
fclose(f);
return TREXIO_FAILURE;
@ -1767,6 +1815,7 @@ trexio_exit_code trexio_text_write_determinant_list(trexio_t* const file,
memset (file_full_path, 0, TREXIO_MAX_FILENAME_LENGTH);
/* Copy directory name in file_full_path */
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
file_full_path[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
/* Append name of the file with sparse data */
strncat (file_full_path, det_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen(det_file_name));
@ -1795,6 +1844,7 @@ trexio_exit_code trexio_text_has_determinant_list(trexio_t* const file)
/* Copy directory name in file_full_path */
strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
file_full_path[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
/* Append name of the file with sparse data */
strncat (file_full_path, determinant_list_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen(determinant_list_file_name));

View File

@ -5,7 +5,7 @@
#include <stdint.h>
#define SIZE 100
#define N_CHUNKS 5
#define N_CHUNKS 7
#define STATE_TEST 2
static int test_write_determinant (const char* file_name, const back_end_t backend, const int64_t offset, const int mo_num) {
@ -32,6 +32,16 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
assert(rc == TREXIO_SUCCESS);
}
// write number of up and down electrons for checking consistency of determinants
if (trexio_has_electron_up_num(file) == TREXIO_HAS_NOT) {
rc = trexio_write_electron_up_num(file, 4);
assert(rc == TREXIO_SUCCESS);
}
if (trexio_has_electron_dn_num(file) == TREXIO_HAS_NOT) {
rc = trexio_write_electron_dn_num(file, 3);
assert(rc == TREXIO_SUCCESS);
}
// get the number of int64 bit fields per determinant
int int_num;
rc = trexio_get_int64_num(file, &int_num);
@ -42,7 +52,6 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
det_list = (int64_t*) calloc(2 * int_num * SIZE, sizeof(int64_t));
det_coef = (double*) calloc(SIZE, sizeof(double));
int64_t size_list = TREXIO_NORB_PER_INT * int_num;
const int32_t orb_list_up[4] = {0,1,2,3};
const int32_t orb_list_dn[3] = {0,1,2};
@ -54,7 +63,7 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
}
// write dataset chunks of sparse data in the file (including FAKE statements)
uint64_t chunk_size = (uint64_t) SIZE/N_CHUNKS;
uint64_t chunk_size = (uint64_t) (SIZE-1)/N_CHUNKS+1;
uint64_t offset_f = 0UL;
uint64_t offset_d = 0UL;
if (offset != 0L) offset_f += offset;
@ -67,7 +76,10 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
// write n_chunks times using write_sparse
for(int i=0; i<N_CHUNKS; ++i){
if (i*chunk_size + chunk_size > SIZE) {
chunk_size = SIZE % chunk_size;
}
//printf("chunk_size: %ld | %ld\n", chunk_size, offset_f+chunk_size);
rc = trexio_write_determinant_list(file, offset_f, chunk_size, &det_list[2*int_num*offset_d]);
assert(rc == TREXIO_SUCCESS);
@ -96,7 +108,6 @@ static int test_write_determinant (const char* file_name, const back_end_t backe
// free the allocated memeory
free(det_list);
free(det_coef);
printf("write determinants OK\n");
/*================= END OF TEST ==================*/
@ -133,7 +144,6 @@ static int test_has_determinant(const char* file_name, const back_end_t backend)
assert (rc == TREXIO_SUCCESS);
/*================= END OF TEST ==================*/
printf("has_determinant OK\n");
return 0;
}
@ -166,7 +176,7 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
int64_t* det_list_read;
double* det_coef_read;
double check_diff;
uint64_t size_r = 40L;
uint64_t size_r = 2*SIZE;
det_list_read = (int64_t*) calloc(2*int_num*size_r,sizeof(int64_t));
det_coef_read = (double*) calloc(size_r,sizeof(double));
@ -182,7 +192,7 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
if (offset != 0L) offset_file_read += offset;
// read one chunk using the aforementioned parameters
printf("int_num: %d\n", int_num);
//printf("int_num: %d\n", int_num);
rc = trexio_read_determinant_list(file, offset_file_read, &chunk_read, &det_list_read[2*int_num*offset_data_read]);
assert(rc == TREXIO_SUCCESS);
assert(chunk_read == read_size_check);
@ -218,10 +228,12 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
/*
printf("%s\n", trexio_string_of_error(rc));
for (int i=0; i<size_r; i++) {
printf("%lld %lld\n", det_list_read[6*i], det_list_read[6*i+5]);
printf("%ld %ld\n", det_list_read[6*i], det_list_read[6*i+5]);
}
*/
assert(rc == TREXIO_END);
//printf("%d %d\n", (int) chunk_read, (int) eof_read_size_check);
//fflush(stdout);
assert(chunk_read == eof_read_size_check);
chunk_read = read_size_check;
@ -240,11 +252,11 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
assert(check_diff*check_diff < 1e-14);
// check the value of determinant_num
int32_t det_num = 0;
int32_t size_check = SIZE;
int64_t det_num = 0;
int64_t size_check = SIZE;
if (offset != 0L) size_check += offset;
rc = trexio_read_determinant_num(file, &det_num);
rc = trexio_read_determinant_num_64(file, &det_num);
assert(rc == TREXIO_SUCCESS);
assert(det_num == size_check);
@ -254,7 +266,28 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
int32_t* orb_list_dn = (int32_t*) calloc(size_list, sizeof(int32_t));
int32_t occ_num_up, occ_num_dn;
rc = trexio_read_determinant_list(file, 0L, &chunk_read, &det_list_read[0L]);
// rc = trexio_read_determinant_list(file, 0L, &chunk_read, &det_list_read[0L]);
// read n_chunks times using read_sparse
int64_t chunk_size = (int64_t) (SIZE-1)/N_CHUNKS+1;
uint64_t offset_f = 0UL;
uint64_t offset_d = 0UL;
for(int i=0; i<N_CHUNKS; ++i){
/*
if (i*chunk_size + chunk_size > SIZE) {
chunk_size = SIZE % chunk_size;
}
*/
//printf("chunk_size: %ld | %ld\n", chunk_size, offset_f+chunk_size);
rc = trexio_read_determinant_list(file, offset_f, &chunk_size, &det_list_read[2*int_num*offset_d]);
assert(rc == TREXIO_SUCCESS || rc == TREXIO_END);
rc = trexio_read_determinant_coefficient(file, offset_f, &chunk_size, &det_coef_read[offset_d]);
assert(rc == TREXIO_SUCCESS || rc == TREXIO_END);
offset_d += chunk_size;
offset_f += chunk_size;
}
assert (rc == TREXIO_SUCCESS);
rc = trexio_to_orbital_list_up_dn (int_num, &det_list_read[0], orb_list_up, orb_list_dn, &occ_num_up, &occ_num_dn);
@ -305,7 +338,6 @@ int main(){
assert (rc == 0);
// check the first write attempt (SIZE elements written in N_CHUNKS chunks)
printf("mo_num = %d\n", mo_nums[i]);
test_write_determinant (TREXIO_FILE, TEST_BACKEND, 0L, mo_nums[i]);
test_has_determinant (TREXIO_FILE, TEST_BACKEND);
test_read_determinant (TREXIO_FILE, TEST_BACKEND, 0L);

View File

@ -23,12 +23,12 @@ static int test_write_dset_sparse (const char* file_name, const back_end_t backe
// parameters to be written
int32_t* index;
double* value;
int64_t size = mo_num/2;
uint64_t size = mo_num/2;
index = calloc(4L*size, sizeof(int32_t));
value = calloc(size, sizeof(double));
for(int i=0; i<size; i++){
for(int i=0; (uint64_t) i<size; i++){
index[4*i] = i;
index[4*i+1] = i+1;
index[4*i+2] = i+2;
@ -38,16 +38,13 @@ static int test_write_dset_sparse (const char* file_name, const back_end_t backe
// write mo_num which will be used to determine the optimal size of int indices
if (trexio_has_mo_num(file) == TREXIO_HAS_NOT) {
rc = trexio_write_mo_num(file, mo_num);
rc = trexio_write_mo_num_64(file, mo_num);
assert(rc == TREXIO_SUCCESS);
}
// write dataset chunks of sparse data in the file (including FAKE statements)
uint64_t chunk_size = (uint64_t) size/N_CHUNKS;
chunk_size = chunk_size > 0 ? chunk_size : (uint64_t) size;
int n_chunks = size/chunk_size;
printf("chunk_size = %ld\n", (long) chunk_size);
printf("n_chunks = %d\n", n_chunks);
uint64_t offset_f = 0UL + offset;
uint64_t offset_d = 0UL;
@ -55,10 +52,10 @@ static int test_write_dset_sparse (const char* file_name, const back_end_t backe
// write n_chunks times using write_sparse
while(offset_d < size) {
if (offset_d+chunk_size > size) chunk_size = size-offset_d;
printf("chunk_size = %ld\n", (long) chunk_size);
//printf("chunk_size = %ld\n", (long) chunk_size);
if (chunk_size == 0L) break;
rc = trexio_write_mo_2e_int_eri(file, offset_f, chunk_size, &index[4*offset_d], &value[offset_d]);
printf("%5d: %s\n", __LINE__, trexio_string_of_error(rc));
//printf("%5d: %s\n", __LINE__, trexio_string_of_error(rc));
assert(rc == TREXIO_SUCCESS);
offset_d += chunk_size;
offset_f += chunk_size;
@ -137,7 +134,7 @@ static int test_read_dset_sparse (const char* file_name, const back_end_t backen
int32_t mo_num = 0;
rc = trexio_read_mo_num(file, &mo_num);
assert(rc == TREXIO_SUCCESS);
printf("%5d: mo_num = %d\n", __LINE__, mo_num);
//printf("%5d: mo_num = %d\n", __LINE__, mo_num);
const int64_t size = mo_num/2;
// define arrays to read into
@ -160,7 +157,7 @@ static int test_read_dset_sparse (const char* file_name, const back_end_t backen
// read one chunk using the aforementioned parameters
rc = trexio_read_mo_2e_int_eri(file, offset_file_read, &chunk_read, &index_read[0], &value_read[0]);
printf("%5d: %s\n", __LINE__, trexio_string_of_error(rc));
//printf("%5d: %s\n", __LINE__, trexio_string_of_error(rc));
/*
for (int i=0 ; i<chunk_read ; ++i) {
printf("%d %d | %ld %ld %ld\n", i, index_read[i], (long) offset, (long) offset_file_read, (long) chunk_read);
@ -181,12 +178,12 @@ static int test_read_dset_sparse (const char* file_name, const back_end_t backen
// read one chunk that will reach EOF and return TREXIO_END code
rc = trexio_read_mo_2e_int_eri(file, offset_file_read, &chunk_read, &index_read[0], &value_read[0]);
printf("%5d: %s\n", __LINE__, trexio_string_of_error(rc));
//printf("%5d: %s\n", __LINE__, trexio_string_of_error(rc));
assert(rc == TREXIO_END);
printf("%d %d x\n", (int32_t) index_read[0], (int32_t) (4L*offset_file_read));
printf("%ld %ld\n", (long) chunk_read, (long) eof_read_size_check);
//printf("%d %d x\n", (int32_t) index_read[0], (int32_t) (4L*offset_file_read));
//printf("%ld %ld\n", (long) chunk_read, (long) eof_read_size_check);
assert(chunk_read == eof_read_size_check);
printf("%d %d\n", index_read[0] , (int32_t) (offset_file_read - offset));
//printf("%d %d\n", index_read[0] , (int32_t) (offset_file_read - offset));
assert(index_read[0] == (int32_t) offset_file_read - offset);
// close current session
@ -222,7 +219,7 @@ static int test_read_dset_sparse_size (const char* file_name, const back_end_t b
// read one chunk using the aforementioned parameters
rc = trexio_read_mo_2e_int_eri_size(file, &size_written);
assert(rc == TREXIO_SUCCESS);
printf("%5d: %ld %ld\n", __LINE__, (long) size_written, (long) size_check);
//printf("%5d: %ld %ld\n", __LINE__, (long) size_written, (long) size_check);
assert(size_written == size_check);
// close current session
@ -246,7 +243,7 @@ int main(){
for (int i=0 ; i<8 ; ++i) {
printf("%5d: mo_num = %d\n", __LINE__, mo_num[i]);
//printf("%5d: mo_num = %d\n", __LINE__, mo_num[i]);
const int64_t size = mo_num[i]/2;
// check the first write attempt (SIZE elements written in N_CHUNKS chunks)
test_write_dset_sparse (TREXIO_FILE, TEST_BACKEND, 0, mo_num[i]);

View File

@ -63,9 +63,13 @@ static int test_has_dset_str (const char* file_name, const back_end_t backend) {
// open file
file = trexio_open(file_name, 'r', backend, &rc);
assert (file != NULL);
assert (rc == TREXIO_SUCCESS);
// check that the previously written dataset of strings exists
rc = trexio_has_nucleus_label(file);
if (rc != TREXIO_SUCCESS) {
printf("%s\n", trexio_string_of_error(rc));
}
assert (rc == TREXIO_SUCCESS);
// check that the dataset of strings does not exist

View File

@ -1,5 +1,6 @@
#include "trexio.h"
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -119,25 +120,25 @@ static int test_read_jastrow (const char* file_name, const back_end_t backend) {
double ee [2] = { 0., 0. };
rc = trexio_read_jastrow_ee(file, ee);
assert (rc == TREXIO_SUCCESS);
assert (ee[0] == 0.5);
assert (ee[1] == 2.0);
assert (fabs(ee[0]-0.5) < 1.e-15);
assert (fabs(ee[1]-2.0) < 1.e-15);
double en [3] = { 0., 0., 0. };
rc = trexio_read_jastrow_en(file, en);
assert (rc == TREXIO_SUCCESS);
assert (en[0] == 1.0);
assert (en[1] == 2.0);
assert (en[2] == 3.0);
assert (fabs(en[0]-1.0) < 1.e-15);
assert (fabs(en[1]-2.0) < 1.e-15);
assert (fabs(en[2]-3.0) < 1.e-15);
double een [6];
rc = trexio_read_jastrow_een(file, een);
assert (rc == TREXIO_SUCCESS);
assert (een[0] == 11.0);
assert (een[1] == 12.0);
assert (een[2] == 13.0);
assert (een[3] == 14.0);
assert (een[4] == 15.0);
assert (een[5] == 16.0);
assert (fabs(een[0]-11.0) < 1.e-15);
assert (fabs(een[1]-12.0) < 1.e-15);
assert (fabs(een[2]-13.0) < 1.e-15);
assert (fabs(een[3]-14.0) < 1.e-15);
assert (fabs(een[4]-15.0) < 1.e-15);
assert (fabs(een[5]-16.0) < 1.e-15);
int en_nucleus [3] = { 0, 0, 0 };
rc = trexio_read_jastrow_en_nucleus(file, en_nucleus);
@ -159,14 +160,14 @@ static int test_read_jastrow (const char* file_name, const back_end_t backend) {
double ee_scaling = 0.0;
rc = trexio_read_jastrow_ee_scaling(file, &ee_scaling);
assert (rc == TREXIO_SUCCESS);
assert (ee_scaling == 1.0);
assert (fabs(ee_scaling-1.0) < 1.e-15);
double en_scaling[3] = { 0.5, 1.0, 0.5 };
rc = trexio_read_jastrow_en_scaling(file, en_scaling);
assert (rc == TREXIO_SUCCESS);
assert (en_scaling[0] == 0.5);
assert (en_scaling[1] == 1.0);
assert (en_scaling[2] == 0.5);
assert (fabs(en_scaling[0]-0.5) < 1.e-15);
assert (fabs(en_scaling[1]-1.0) < 1.e-15);
assert (fabs(en_scaling[2]-0.5) < 1.e-15);
rc = trexio_close(file);
/*================= END OF TEST ==================*/

View File

@ -117,7 +117,7 @@ static int test_open_errors (const back_end_t backend) {
}
static int test_inquire (const back_end_t backend) {
static int test_inquire () {
/* Try to call trexio_inquire function */
@ -151,7 +151,7 @@ int main(void) {
test_open_r (TREXIO_FILE, TEST_BACKEND);
test_open_auto (TREXIO_FILE);
test_open_errors(TEST_BACKEND);
test_inquire (TEST_BACKEND);
test_inquire ();
rc = system(RM_COMMAND);
assert (rc == 0);

View File

@ -170,7 +170,7 @@ static int test_overwrite_safe (const char* file_name, const back_end_t backend)
}
int test_read(const char* file_name, const back_end_t backend) {
static int test_read(const char* file_name, const back_end_t backend) {
/*========= Test read ===========*/

44
tests/run_valgrind.sh Executable file
View File

@ -0,0 +1,44 @@
#!/bin/bash
set -e
TESTS_C="\
io_all \
open_text \
io_num_text \
io_dset_float_text \
io_dset_int_text \
io_dset_sparse_text \
io_determinant_text \
io_jastrow_text \
io_safe_dset_float_text \
io_str_text \
io_dset_str_text \
delete_group_text \
overwrite_all_text \
pre_close \
open_hdf5 \
io_num_hdf5 \
io_dset_float_hdf5 \
io_dset_int_hdf5 \
io_dset_sparse_hdf5 \
io_determinant_hdf5 \
io_jastrow_hdf5 \
io_safe_dset_float_hdf5 \
io_str_hdf5 \
io_dset_str_hdf5 \
delete_group_hdf5 \
overwrite_all_hdf5"
TESTS="$TESTS_C test_f"
for test in $TESTS; do
echo "$test"
libtool --mode=execute valgrind \
--leak-check=full \
--show-leak-kinds=all \
--error-exitcode=666 \
--errors-for-leak-kinds=all \
--suppressions=valgrind.supp \
"./$test"
done

View File

@ -5,6 +5,7 @@ program test_trexio
integer :: rc
logical :: have_hdf5
character*(64) :: trexio_file1, trexio_file2
print'(a)' , "============================================"
print'(a,a)' , " TREXIO VERSION STRING : ", TREXIO_PACKAGE_VERSION
@ -14,20 +15,40 @@ program test_trexio
rc = trexio_info()
call system('rm -f -- test_write_f.dir/*.txt test_write_f.dir/*.txt.size test_write_f.dir/.lock ' &
// 'test_write_f2.dir/*.txt test_write_f2.dir/*.txt.size test_write_f2.dir/.lock && ' &
// 'rm -fd -- test_write_f.dir test_write_f2.dir')
print *, 'call test_write(''test_write_f.dir'', TREXIO_TEXT)'
call test_write('test_write_f.dir', TREXIO_TEXT)
rc = trexio_cp('test_write_f.dir', 'test_write_f2.dir')
call trexio_assert(rc, TREXIO_SUCCESS)
print *, 'call test_read(''test_write_f2.dir'', TREXIO_TEXT)'
call test_read('test_write_f2.dir', TREXIO_TEXT)
call system('rm -f -- test_write_f.dir/*.txt test_write_f.dir/*.txt.size test_write_f.dir/.lock ' &
// 'test_write_f2.dir/*.txt test_write_f2.dir/*.txt.size test_write_f2.dir/.lock && ' &
// 'rm -fd -- test_write_f.dir test_write_f2.dir')
trexio_file1 = 'test_write_f.dir'
trexio_file2 = 'test_write_f2.dir'
call test_read_void('test_write_f.dir', TREXIO_TEXT)
call system('rm -f -- '//trim(trexio_file1)//'/*.txt')
call system('rm -f -- '//trim(trexio_file1)//'/*.txt.size')
call system('rm -f -- '//trim(trexio_file1)//'/.lock ')
call system('rm -rf -- '//trim(trexio_file1))
call system('rm -f -- '//trim(trexio_file2)//'/*.txt')
call system('rm -f -- '//trim(trexio_file2)//'/*.txt.size')
call system('rm -f -- '//trim(trexio_file2)//'/.lock ')
call system('rm -rf -- '//trim(trexio_file2))
print *, 'call test_write'
call test_write('test_write_f.dir', TREXIO_TEXT)
rc = trexio_cp(trexio_file1, trexio_file2)
call trexio_assert(rc, TREXIO_SUCCESS)
print *, 'call test_read'
call test_read(trexio_file2, TREXIO_TEXT)
call system('rm -f -- '//trim(trexio_file1)//'/*.txt')
call system('rm -f -- '//trim(trexio_file1)//'/*.txt.size')
call system('rm -f -- '//trim(trexio_file1)//'/.lock ')
call system('rm -rf -- '//trim(trexio_file1))
call system('rm -f -- '//trim(trexio_file2)//'/*.txt')
call system('rm -f -- '//trim(trexio_file2)//'/*.txt.size')
call system('rm -f -- '//trim(trexio_file2)//'/.lock ')
call system('rm -rf -- '//trim(trexio_file2))
print *, 'call test_read_void'
call test_read_void(trexio_file1, TREXIO_TEXT)
! No way to conditionally check whether compilation was done with HDF5
! So temporarily disable the test for HDF5 back end at the moment
@ -69,16 +90,18 @@ subroutine test_write(file_name, back_end)
double precision :: charge(12)
double precision :: coord(3,12)
character(len=32), allocatable :: sym_str
character(len=32) :: sym_str
character(len=8), allocatable :: label(:)
double precision, allocatable :: energy(:)
integer , allocatable :: spin(:)
! sparse data
integer(4) :: index_sparse_ao_2e_int_eri(4,100)
double precision :: value_sparse_ao_2e_int_eri(100)
integer(4), allocatable :: index_sparse_ao_2e_int_eri(:,:)
double precision, allocatable :: value_sparse_ao_2e_int_eri(:)
! determinants
integer :: nup, ndn
integer :: det_occ(10,2)
integer*8 :: det_list(6, 50)
integer*8 :: det_num
integer :: int_num
@ -87,9 +110,12 @@ subroutine test_write(file_name, back_end)
integer(8) :: buf_size_sparse, buf_size_det, offset
integer :: state_id
buf_size_sparse = 100/n_buffers
buf_size_det = 50/n_buffers
allocate(index_sparse_ao_2e_int_eri(4,100), value_sparse_ao_2e_int_eri(100))
! fill sparse indices and values
do i = 1, 100
index_sparse_ao_2e_int_eri(1,i) = 4*i - 3
@ -100,10 +126,16 @@ subroutine test_write(file_name, back_end)
enddo
! fill determinant list
nup = 8
ndn = 6
det_occ = 0
det_occ(1:nup,1) = (/ 1, 2, 3, 4, 76, 128, 129, 143 /)
det_occ(1:ndn,2) = (/ 1, 3, 4, 80, 81, 139 /)
do i = 1, 50
do j = 1, 6
det_list(j,i) = 6*i+(j-1) - 5
enddo
rc = trexio_to_bitfield_list(det_occ(1:8,1), nup, det_list(1:3,i), 3)
call trexio_assert(rc, TREXIO_SUCCESS)
rc = trexio_to_bitfield_list(det_occ(1:6,2), ndn, det_list(4:6,i), 3)
call trexio_assert(rc, TREXIO_SUCCESS)
enddo
! parameters to be written
@ -161,6 +193,18 @@ subroutine test_write(file_name, back_end)
rc = trexio_has_nucleus_charge(trex_file)
call trexio_assert(rc, TREXIO_HAS_NOT, 'SUCCESS HAS NOT 2')
rc = trexio_has_electron_up_num(trex_file)
call trexio_assert(rc, TREXIO_HAS_NOT, 'SUCCESS HAS NOT 2.1')
rc = trexio_write_electron_up_num(trex_file, nup)
call trexio_assert(rc, TREXIO_SUCCESS)
rc = trexio_has_electron_dn_num(trex_file)
call trexio_assert(rc, TREXIO_HAS_NOT, 'SUCCESS HAS NOT 2.2')
rc = trexio_write_electron_dn_num(trex_file, ndn)
call trexio_assert(rc, TREXIO_SUCCESS)
rc = trexio_has_ao_2e_int_eri(trex_file)
call trexio_assert(rc, TREXIO_HAS_NOT, 'SUCCESS HAS NOT 3')
@ -187,7 +231,6 @@ subroutine test_write(file_name, back_end)
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE LABEL')
rc = trexio_write_nucleus_point_group(trex_file, sym_str, 32)
deallocate(sym_str)
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE POINT GROUP')
rc = trexio_write_basis_shell_num(trex_file, basis_shell_num)
@ -244,6 +287,7 @@ subroutine test_write(file_name, back_end)
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE DET LIST')
offset = offset + buf_size_det
enddo
deallocate(index_sparse_ao_2e_int_eri, value_sparse_ao_2e_int_eri)
rc = trexio_has_nucleus_num(trex_file)
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS HAS 1')
@ -283,7 +327,8 @@ subroutine test_read(file_name, back_end)
integer(trexio_t) :: trex_file
integer :: i, j, k, ind, offset, flag
integer*8 :: i
integer :: j, k, ind, offset, flag
integer(trexio_exit_code) :: rc = 1
integer :: num, num_read, basis_shell_num
@ -313,7 +358,7 @@ subroutine test_read(file_name, back_end)
! determinant data
integer*8 :: det_list(6,50)
integer*8 :: det_list_check(3)
integer*8 :: det_list_check(6)
integer*8 :: read_buf_det_size = 20
integer*8 :: offset_det_read = 10
integer*8 :: offset_det_data_read = 5
@ -477,17 +522,39 @@ subroutine test_read(file_name, back_end)
! read a chunk of determinants
rc = trexio_read_determinant_list(trex_file, offset_det_read, read_buf_det_size, &
det_list(1, offset_det_data_read + 1))
!do i = 1,50
! write(*,*) det_list(1,i)
!enddo
call trexio_assert(rc, TREXIO_SUCCESS)
if (det_list(1, 1) == 0 .and. &
det_list(1, offset_det_data_read + 1) == offset_det_read*6 + 1) then
write(*,*) 'SUCCESS READ DET LIST'
else
print *, 'FAILURE DET LIST CHECK'
call exit(-1)
endif
det_list_check = (/15_8, -9223372036854773760_8, 16385_8, 13_8, 98304_8, 1024_8 /)
do i = 1,offset_det_data_read
do j=1,6
if (det_list(j,i) /= 0_8) then
print *, det_list(j,i)
print *, 'FAILURE DET LIST CHECK 1'
call exit(-1)
endif
enddo
enddo
do i = offset_det_data_read+1, offset_det_data_read+read_buf_det_size
do j=1,6
if (det_list(j,i) /= det_list_check(j)) then
print *, det_list(j,i)
print *, 'FAILURE DET LIST CHECK 2'
call exit(-1)
endif
enddo
enddo
do i = offset_det_data_read+read_buf_det_size+1,50
do j=1,6
if (det_list(j,i) /= 0_8) then
print *, det_list(j,i)
print *, 'FAILURE DET LIST CHECK 3'
call exit(-1)
endif
enddo
enddo
write(*,*) 'SUCCESS READ DET LIST'
! read the total number of stored determinants
rc = trexio_read_determinant_num_64(trex_file, determinant_num)
@ -509,7 +576,7 @@ subroutine test_read(file_name, back_end)
! Print binary representation of the first integer bit field of a given determinant
!write(*,'(B64.64)') det_list(1, offset_det_data_read+1)
call trexio_assert(rc, TREXIO_SUCCESS)
if (occ_num_up == 16 .and. occ_num_dn == 5) then
if (occ_num_up == 8 .and. occ_num_dn == 6) then
write(*,*) 'SUCCESS CONVERT DET LIST'
else
print *, 'FAILURE DET CONVERT CHECK'
@ -593,11 +660,12 @@ subroutine test_read_void(file_name, back_end)
integer, intent(in) :: back_end
integer(trexio_t) :: trex_file
integer :: rc = 1
character(128) :: str
integer :: rc
character*(128) :: str
! ================= START OF TEST ===================== !
rc = TREXIO_SUCCESS
trex_file = trexio_open(file_name, 'r', back_end, rc)
if (rc /= TREXIO_OPEN_ERROR) then
rc = trexio_close(trex_file)

84
tests/valgrind.supp Normal file
View File

@ -0,0 +1,84 @@
{
supp1
Memcheck:Leak
match-leak-kinds: reachable
fun:calloc
fun:H5TS_cancel_count_inc
fun:H5check_version
fun:trexio_hdf5_init
fun:trexio_open
fun:test_*
fun:main
}
{
supp2
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
obj:/usr/lib/x86_64-linux-gnu/libhdf5_serial.so.103.3.0
obj:/usr/lib/x86_64-linux-gnu/libhdf5_serial.so.103.3.0
fun:H5CX_push
fun:H5Fcreate
fun:trexio_hdf5_init
fun:trexio_open
fun:test_*
fun:main
}
{
supp3
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
fun:H5E__get_stack
fun:H5E_clear_stack
fun:H5Fcreate
fun:trexio_hdf5_init
fun:trexio_open
fun:test_*
fun:main
}
{
fortsupp1
Memcheck:Leak
match-leak-kinds: reachable
fun:calloc
fun:H5TS_cancel_count_inc
fun:H5check_version
fun:trexio_hdf5_init
fun:trexio_open
fun:__trexio_MOD_trexio_open
fun:test_write_
fun:MAIN__
fun:main
}
{
fortsupp2
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
obj:/usr/lib/x86_64-linux-gnu/libhdf5_serial.so.103.3.0
obj:/usr/lib/x86_64-linux-gnu/libhdf5_serial.so.103.3.0
fun:H5CX_push
fun:H5Fcreate
fun:trexio_hdf5_init
fun:trexio_open
fun:__trexio_MOD_trexio_open
fun:test_write_
fun:MAIN__
fun:main
}
{
fortsupp3
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
fun:H5E__get_stack
fun:H5E_clear_stack
fun:H5Fcreate
fun:trexio_hdf5_init
fun:trexio_open
fun:__trexio_MOD_trexio_open
fun:test_write_
fun:MAIN__
fun:main
}

11
tools/nix/overlay.nix Normal file
View File

@ -0,0 +1,11 @@
final: prev: {
trexio = final.callPackage ./trexio.nix { };
haskell = prev.haskell // {
packageOverrides = hfinal: hprev: {
trexio-hs = hfinal.callCabal2nix "trexio" ../haskell {
inherit (final) trexio;
};
};
};
}

55
tools/nix/trexio.nix Normal file
View File

@ -0,0 +1,55 @@
{ stdenv
, lib
, fetchFromGitHub
, cmake
, gfortran
, hdf5
, python3
, emacs
, swig
}:
stdenv.mkDerivation rec {
pname = "trexio";
version = "2.5.0";
src = lib.cleanSourceWith {
src = ../../.;
filter = path: type: ! (builtins.elem (builtins.baseNameOf path) [
"haskell"
"docker"
"helpers-debian"
"ocaml"
"rust"
"python"
] && type == "directory" );
};
postPatch = ''
patchShebangs tools/*
'';
nativeBuildInputs = [
cmake
gfortran
emacs
swig
python3
];
buildInputs = [
hdf5
];
outputs = [ "out" "dev" ];
doCheck = true;
meta = with lib; {
description = "File format and library for the storage of quantum chemical wave functions";
homepage = "https://trex-coe.github.io/trexio/";
downloadPage = "https://github.com/TREX-CoE/trexio";
license = licenses.bsd3;
maintainers = [ maintainers.sheepforce ];
};
}

View File

@ -130,12 +130,13 @@
#+NAME: pbc
| Variable | Type | Row-major Dimensions | Column-major Dimensions | Description |
|------------------+---------+----------------------+-------------------------+-------------------------|
| ~periodic~ | ~int~ | | | ~1~: true or ~0~: false |
| ~k_point_num~ | ~dim~ | | | Number of $k$-points |
| ~k_point~ | ~float~ | ~[3]~ | ~(3)~ | $k$-point sampling |
| ~k_point_weight~ | ~float~ | ~[pbc.k_point_num]~ | ~(pbc.k_point_num)~ | $k$-point weight |
| Variable | Type | Row-major Dimensions | Column-major Dimensions | Description |
|------------------+---------+----------------------+-------------------------+------------------------------------------------------|
| ~periodic~ | ~int~ | | | ~1~: true or ~0~: false |
| ~k_point_num~ | ~dim~ | | | Number of $k$-points |
| ~k_point~ | ~float~ | ~[3]~ | ~(3)~ | $k$-point sampling |
| ~k_point_weight~ | ~float~ | ~[pbc.k_point_num]~ | ~(pbc.k_point_num)~ | $k$-point weight |
| ~madelung~ | ~float~ | | | Madelung correction of the Ewald probe charge method |
#+CALL: json(data=pbc, title="pbc")
@ -147,6 +148,7 @@
, "k_point_num" : [ "dim" , [] ]
, "k_point" : [ "float", [ "3" ] ]
, "k_point_weight" : [ "float", [ "pbc.k_point_num" ] ]
, "madelung" : [ "float", [] ]
} ,
#+end_src
:end:
@ -259,7 +261,7 @@
constant for the primitive $ks$ needs to be computed and stored. If
this normalization factor is not required, $f_{ks}=1$.
Some codes assume that the basis function are normalized. This
Some codes assume that the basis functions are normalized. This
implies the computation of an extra normalization factor, $\mathcal{N}_s$.
If the the basis function is not considered normalized, $\mathcal{N}_s=1$.
@ -684,13 +686,19 @@ power = [
\]
where $i$ is the atomic orbital index, $P$ refers to either
polynomials or spherical harmonics, and $s(i)$ specifies the shell
on which the AO is expanded.
polynomials in $x,y,z$ or real solid harmonics
\[
S^m_{\ell}(\mathbf{r}) \equiv \sqrt{\frac{4\pi}{2\ell+1}}\; r^\ell
Y^m_{\ell}(\theta,\varphi)
\]
(see [[https://en.wikipedia.org/wiki/Solid_harmonics][Wikipedia]]), and $s(i)$
specifies the shell on which the AO is expanded.
$\eta(i)$ denotes the chosen angular function. The AOs can be
expressed using real spherical harmonics or polynomials in Cartesian
coordinates. In the case of real spherical harmonics, the AOs are
ordered as $0, +1, -1, +2, -2, \dots, + m, -m$ (see [[https://en.wikipedia.org/wiki/Table_of_spherical_harmonics#Real_spherical_harmonics][Wikipedia]]). In
expressed using real solid harmonics or polynomials in Cartesian
coordinates. In the case of real solid harmonics, the AOs are
ordered as $0, +1, -1, +2, -2, \dots, + m, -m$). In
the case of polynomials, the canonical (or alphabetical) ordering is
used,

View File

@ -5,4 +5,4 @@ To update the version, change:
- ocaml/trexio/trexio.opam
- python/pytrexio/_version.py
- rust/trexio/Cargo.toml
- tools/nix/trexio.nix