From 4adf6484ba8a9c1c6ce3c7387ba34b053cc45e8b Mon Sep 17 00:00:00 2001 From: Evgeny Posenitskiy <45995097+q-posev@users.noreply.github.com> Date: Fri, 3 Jun 2022 10:02:49 +0200 Subject: [PATCH 01/58] [wheel build] test PyPI --- .github/workflows/build-wheels.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-wheels.yml b/.github/workflows/build-wheels.yml index 4f8170c7..4f35275d 100644 --- a/.github/workflows/build-wheels.yml +++ b/.github/workflows/build-wheels.yml @@ -220,15 +220,15 @@ jobs: ls -sh -w 1 working-directory: dist - #- name: Publish distribution 📦 to Test PyPI - # uses: pypa/gh-action-pypi-publish@master - # with: - # password: ${{ secrets.TEST_PYPI_API_TOKEN }} - # repository_url: https://test.pypi.org/legacy/ - #verbose: true - - - name: Publish distribution 📦 to PyPI + - name: Publish distribution 📦 to Test PyPI uses: pypa/gh-action-pypi-publish@master with: - password: ${{ secrets.PYPI_API_TOKEN }} + password: ${{ secrets.TEST_PYPI_API_TOKEN }} + repository_url: https://test.pypi.org/legacy/ + #verbose: true + + #- name: Publish distribution 📦 to PyPI + # uses: pypa/gh-action-pypi-publish@master + # with: + # password: ${{ secrets.PYPI_API_TOKEN }} #if: startsWith(github.ref, 'refs/tags') From 4f07eb095355969712cd64c1ada447df9ef48ff8 Mon Sep 17 00:00:00 2001 From: Evgeny Posenitskiy <45995097+q-posev@users.noreply.github.com> Date: Fri, 3 Jun 2022 10:38:13 +0200 Subject: [PATCH 02/58] [wheel build] PyPI release --- .github/workflows/build-wheels.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-wheels.yml b/.github/workflows/build-wheels.yml index 4f35275d..672ff126 100644 --- a/.github/workflows/build-wheels.yml +++ b/.github/workflows/build-wheels.yml @@ -220,15 +220,15 @@ jobs: ls -sh -w 1 working-directory: dist - - name: Publish distribution 📦 to Test PyPI - uses: pypa/gh-action-pypi-publish@master - with: - password: ${{ secrets.TEST_PYPI_API_TOKEN }} - repository_url: https://test.pypi.org/legacy/ - #verbose: true - - #- name: Publish distribution 📦 to PyPI + #- name: Publish distribution 📦 to Test PyPI # uses: pypa/gh-action-pypi-publish@master # with: - # password: ${{ secrets.PYPI_API_TOKEN }} + # password: ${{ secrets.TEST_PYPI_API_TOKEN }} + # repository_url: https://test.pypi.org/legacy/ + #verbose: true + + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@master + with: + password: ${{ secrets.PYPI_API_TOKEN }} #if: startsWith(github.ref, 'refs/tags') From 6fa97ac21decc00e5f9988970ea439ea04241e08 Mon Sep 17 00:00:00 2001 From: q-posev Date: Fri, 3 Jun 2022 11:32:15 +0200 Subject: [PATCH 03/58] Add conda badges --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 91b1889f..5e28e64f 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,9 @@ The aforementioned instructions rely on [Autotools](https://www.gnu.org/software ## Installation procedure for conda users +[![Anaconda-Server Badge](https://anaconda.org/conda-forge/trexio/badges/version.svg)](https://anaconda.org/conda-forge/trexio) +[![Anaconda-Server Badge](https://anaconda.org/conda-forge/trexio/badges/platforms.svg)](https://anaconda.org/conda-forge/trexio) + The official releases of TREXIO `>2.0.0` are also available via the `conda-forge` channel. The pre-compiled stable binaries of `trexio` can be installed as follows: From 189f6de6a9cd51d0be6c44be95deca045f97c555 Mon Sep 17 00:00:00 2001 From: q-posev Date: Fri, 3 Jun 2022 11:37:02 +0200 Subject: [PATCH 04/58] Upgrade the minor versions after the release --- CMakeLists.txt | 2 +- configure.ac | 2 +- python/pytrexio/_version.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index faf56bd5..8a5712f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.16) # Initialize the CMake project. project(Trexio - VERSION 2.2.0 + VERSION 2.3.0 DESCRIPTION "TREX I/O library" LANGUAGES C Fortran ) diff --git a/configure.ac b/configure.ac index 3d312f6f..01005c36 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) -AC_INIT([trexio],[2.2.0],[https://github.com/TREX-CoE/trexio/issues]) +AC_INIT([trexio],[2.3.0],[https://github.com/TREX-CoE/trexio/issues]) AC_CONFIG_SRCDIR([Makefile.in]) AC_CONFIG_HEADERS([include/config.h]) diff --git a/python/pytrexio/_version.py b/python/pytrexio/_version.py index c68196d1..67bc602a 100644 --- a/python/pytrexio/_version.py +++ b/python/pytrexio/_version.py @@ -1 +1 @@ -__version__ = "1.2.0" +__version__ = "1.3.0" From d5df21cf0c1e7eeb720fa65cc11c225d0fb64cb8 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 16 Jun 2022 17:18:56 +0200 Subject: [PATCH 05/58] TREXIO logo in readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5e28e64f..ea6cfada 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # TREXIO + [![build](https://github.com/TREX-CoE/trexio/actions/workflows/actions.yml/badge.svg)](https://github.com/TREX-CoE/trexio/actions/workflows/actions.yml) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/TREX-CoE/trexio) From d478497af99f4a050820b2dbb9e7d38f2eeca72d Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 24 Jun 2022 12:04:57 +0200 Subject: [PATCH 06/58] Added CSF group --- trex.org | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/trex.org b/trex.org index e9c1a55e..8805f3a2 100644 --- a/trex.org +++ b/trex.org @@ -704,6 +704,42 @@ prim_factor = #+end_src :END: +* Configuration state functions (csf group) + + The configuration interaction (CI) wave function $\Psi$ can be + expanded in the basis of [[https://en.wikipedia.org/wiki/Configuration_state_function][configuration state functions]] (CSFs) + $\Psi_I$ as follows + + \[ + \Psi = \sum_I C_I \psi_I. + \] + + Each CSF is a linear combination of Slater determinants. Slater + determinants are stored in the =determinant= section. In this group + we store the CI coefficients in the basis of CSFs, and the + matrix $\langle D_I | \psi_J \rangle$ needed to project the CSFs in + the basis of Slater determinants. + + #+NAME: csf + | Variable | Type | Dimensions | Description | + |-------------------+-----------------+-----------------------------+------------------------------------------------| + | ~num~ | ~dim readonly~ | | Number of CSFs | + | ~coefficient~ | ~float special~ | ~(state.num,csf.num)~ | Coefficients of the CSFs from the CI expansion | + | ~det_coefficient~ | ~float sparse~ | ~(determinant.num,csf.num)~ | Projection on the determinant basis | + + #+CALL: json(data=csf, title="csf") + + #+RESULTS: + :results: + #+begin_src python :tangle trex.json + "csf": { + "num" : [ "dim readonly" , [] ] + , "coefficient" : [ "float special", [ "csf.num", "state.num" ] ] + , "det_coefficient" : [ "float sparse" , [ "csf.num", "determinant.num" ] ] + } , + #+end_src + :end: + * Excited states (state group) By default, the ~determinant~ group corresponds to the ground state. From 3c2197b36a69fcb6d710337448d30d37430c2347 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 27 Jun 2022 17:15:27 +0200 Subject: [PATCH 07/58] Update examples.org --- examples.org | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/examples.org b/examples.org index eaa7d58e..b8ac7faa 100644 --- a/examples.org +++ b/examples.org @@ -3,7 +3,8 @@ #+SETUPFILE: docs/theme.setup -* Accessing sparse quantities +* Accessing sparse quantities (integrals) + ** Fortran :PROPERTIES: :header-args: :tangle print_energy.f90 @@ -270,3 +271,69 @@ program print_energy end program #+end_src + + +* Reading determinants + +** Fortran + :PROPERTIES: + :header-args: :tangle print_dets.f90 + :END: + + #+begin_src f90 +program test + + use trexio + implicit none + + character*(128) :: filename ! Name of the input file + integer(trexio_exit_code) :: rc ! Return code for error checking + integer(trexio_t) :: trex_determinant_file + + integer*8, allocatable :: buffer(:,:,:) + integer(8) :: offset, icount, BUFSIZE + integer :: ndet, int64_num, m + + integer :: occ_num_up, occ_num_dn + integer, allocatable :: orb_list_up(:), orb_list_dn(:) + + call getarg(1, filename) + + trex_determinant_file = trexio_open(filename, 'r', TREXIO_AUTO, rc) + if (rc /= TREXIO_SUCCESS) then + call trexio_string_of_error(rc, err_msg) + print *, 'Error opening TREXIO file: '//trim(err_msg) + stop + end if + + rc = trexio_read_determinant_num(trex_determinant_file, ndet) + print *, 'ndet', ndet + + rc = trexio_get_int64_num(trex_determinant_file, int64_num) + print *, 'int64_num', int64_num + + BUFSIZE = 1000_8 + allocate(buffer(int64_num, 2, BUFSIZE)) + allocate(orb_list_up(int64_num*64), orb_list_dn(int64_num*64)) + + offset = 0_8 + icount = BUFSIZE + do while (icount == BUFSIZE) + if (offset < ndet) then + rc = trexio_read_determinant_list(trex_determinant_file, offset, icount, buffer) + offset = offset + icount + else + icount = 0 + end if + print *, '---' + do m=1,icount + rc = trexio_to_orbital_list_up_dn(int64_num, buffer(1,1,m), & + orb_list_up, orb_list_dn, occ_num_up, occ_num_dn) + print '(100(I3,X))', (orb_list_up(1:occ_num_up)), (orb_list_dn(1:occ_num_dn)) + print *, '' + end do + end do + +end + #+end_src + From 5f259d8e19ab28288e928fd743b25bd4b1f8d0f1 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 27 Jun 2022 17:17:08 +0200 Subject: [PATCH 08/58] Update examples.org --- examples.org | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples.org b/examples.org index b8ac7faa..ab939284 100644 --- a/examples.org +++ b/examples.org @@ -289,6 +289,8 @@ program test character*(128) :: filename ! Name of the input file integer(trexio_exit_code) :: rc ! Return code for error checking integer(trexio_t) :: trex_determinant_file + character*(128) :: err_msg ! Error message + integer*8, allocatable :: buffer(:,:,:) integer(8) :: offset, icount, BUFSIZE From a77021c9d39a4d33b117504f16ac3b427ad52eca Mon Sep 17 00:00:00 2001 From: Evgeny Posenitskiy <45995097+q-posev@users.noreply.github.com> Date: Tue, 28 Jun 2022 10:15:38 +0200 Subject: [PATCH 09/58] Add missing deallocation and error handling --- examples.org | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/examples.org b/examples.org index ab939284..241c63ef 100644 --- a/examples.org +++ b/examples.org @@ -286,10 +286,10 @@ program test use trexio implicit none - character*(128) :: filename ! Name of the input file - integer(trexio_exit_code) :: rc ! Return code for error checking - integer(trexio_t) :: trex_determinant_file - character*(128) :: err_msg ! Error message + character*(128) :: filename ! Name of the input file + integer(trexio_exit_code) :: rc ! Return code for error checking + integer(trexio_t) :: trex_determinant_file ! TREXIO file handle + character*(128) :: err_msg ! Error message integer*8, allocatable :: buffer(:,:,:) @@ -309,9 +309,19 @@ program test end if rc = trexio_read_determinant_num(trex_determinant_file, ndet) + if (rc /= TREXIO_SUCCESS) then + call trexio_string_of_error(rc, err_msg) + print *, 'Error reading determinant_num: '//trim(err_msg) + stop + end if print *, 'ndet', ndet rc = trexio_get_int64_num(trex_determinant_file, int64_num) + if (rc /= TREXIO_SUCCESS) then + call trexio_string_of_error(rc, err_msg) + print *, 'Error reading int64_num: '//trim(err_msg) + stop + end if print *, 'int64_num', int64_num BUFSIZE = 1000_8 @@ -334,7 +344,9 @@ program test print '(100(I3,X))', (orb_list_up(1:occ_num_up)), (orb_list_dn(1:occ_num_dn)) print *, '' end do - end do + end do + + deallocate(buffer, orb_list_dn, orb_list_up) end #+end_src From 5e4531f810cc19994e31d186a6f14220a77849b9 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 1 Jul 2022 10:29:44 +0200 Subject: [PATCH 10/58] Typos --- tools/generator_tools.py | 2 +- trex.org | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/generator_tools.py b/tools/generator_tools.py index 04cbe074..ab03b9b8 100644 --- a/tools/generator_tools.py +++ b/tools/generator_tools.py @@ -232,7 +232,7 @@ def iterative_populate_file (filename: str, paths: dict, detailed_all: dict) -> for line in f_in : id = check_triggers(line, triggers) if id == 0: - # special case for proper error handling when deallocting text groups + # special case for proper error handling when deallocating text groups error_handler = ' if (rc != TREXIO_SUCCESS) return rc;\n' populated_line = iterative_replace_line(line, '$group$', detailed_all['groups'], add_line=error_handler) f_out.write(populated_line) diff --git a/trex.org b/trex.org index e9c1a55e..3b684fcd 100644 --- a/trex.org +++ b/trex.org @@ -37,6 +37,8 @@ fetched using multiple function calls to perform I/O on buffers. For more information on how to read/write sparse data structures, see the [[./examples.html][examples]]. +For determinants, the ~special~ attribute is present in the type. This +means that the source code is not produced by the generator, but hand-written. #+begin_src python :tangle trex.json :exports none { @@ -678,11 +680,16 @@ prim_factor = in the memory. \[ - D_I = \alpha_1 \alpha_2 \ldots \alpha_{n\uparrow} \beta_1 \beta_2 \ldots \beta_{n\downarrow} + D_I = \alpha_1 \alpha_2 \ldots \alpha_{n_\uparrow} \beta_1 \beta_2 \ldots \beta_{n_\downarrow} \] - where $\alpha$ and $\beta$ denote $\uparrow$-spin and $\downarrow$-spin electrons, respectively, - $n\uparrow$ and $n\downarrow$ correspond to ~electron.up_num~ and ~electron.dn_num~, respectively. + where $\alpha$ and $\beta$ denote \uparrow-spin and \downarrow-spin electrons, respectively, + $n_\uparrow$ and $n_\downarrow$ correspond to ~electron.up_num~ and ~electron.dn_num~, respectively. + + Note: the ~special~ attribute is present in the types, meaning that the source node is not + produced by the code generator. + + An illustration on how to read determinants is presented in the [[./examples.html][examples]]. #+NAME: determinant | Variable | Type | Dimensions | Description | @@ -734,7 +741,7 @@ prim_factor = The reduced density matrices are defined in the basis of molecular orbitals. - The $\uparrow$-spin and $\downarrow$-spin components of the one-body + The \uparrow-spin and \downarrow-spin components of the one-body density matrix are given by \begin{eqnarray*} \gamma_{ij}^{\uparrow} &=& \langle \Psi | \hat{a}^{\dagger}_{j\alpha}\, \hat{a}_{i\alpha} | \Psi \rangle \\ From 6494ddbc22f7059b542975b9b0fe25c2bf718e69 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 1 Jul 2022 15:06:19 +0200 Subject: [PATCH 11/58] make ocaml-install in Makefile.am --- Makefile.am | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 2bfe8897..f1195707 100644 --- a/Makefile.am +++ b/Makefile.am @@ -227,6 +227,22 @@ cppcheck.out: $(trexio_h) --language=c --std=c99 -rp --platform=unix64 \ -I../include *.c *.h 2>../$@ +################# +# OCaml binding # +################# + +ocaml/trexio/_build/default/lib/trexio.cma: + $(MAKE) -C ocaml/trexio + +ocaml: ocaml/trexio/_build/default/lib/trexio.a + +ocaml-install: ocaml/trexio/_build/default/lib/trexio.a + opam install ocaml/trexio + +################## +# Python binding # +################## + setup_py = $(srcdir)/python/setup.py setup_cfg = $(srcdir)/python/setup.cfg pytrexio_py = $(srcdir)/python/pytrexio/pytrexio.py @@ -278,6 +294,6 @@ CLEANFILES += $(pytrexio_c) \ python/src/*.c \ python/src/*.h -.PHONY: cppcheck python-test python-install python-sdist check-numpy FORCE +.PHONY: cppcheck python-test python-install python-sdist check-numpy FORCE ocaml endif From 94f2adf1f272b5bcd0c3cb6f5b8f40345d74f5a5 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 1 Jul 2022 15:16:21 +0200 Subject: [PATCH 12/58] Forgot Makefile in previous commit --- ocaml/trexio/Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 ocaml/trexio/Makefile diff --git a/ocaml/trexio/Makefile b/ocaml/trexio/Makefile new file mode 100644 index 00000000..91d0b694 --- /dev/null +++ b/ocaml/trexio/Makefile @@ -0,0 +1,9 @@ +default: sources + dune build + +lib/trexio.ml: ../../trex.json read_json.py src/trexio.ml src/trexio.mli src/trexio_stubs.c + ./read_json.py + +sources: lib/trexio.ml + +.PHONY: sources default From 34563a2a7653b4494676ed2c9e7edfc32d082777 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 1 Jul 2022 15:17:50 +0200 Subject: [PATCH 13/58] Fix Makefile.am --- Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index f1195707..c28459d2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -234,9 +234,9 @@ cppcheck.out: $(trexio_h) ocaml/trexio/_build/default/lib/trexio.cma: $(MAKE) -C ocaml/trexio -ocaml: ocaml/trexio/_build/default/lib/trexio.a +ocaml: ocaml/trexio/_build/default/lib/trexio.cma -ocaml-install: ocaml/trexio/_build/default/lib/trexio.a +ocaml-install: ocaml/trexio/_build/default/lib/trexio.cma opam install ocaml/trexio ################## From 9912b09596208a5f829d1b02a1e7e996620e9a54 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 1 Jul 2022 16:14:20 +0200 Subject: [PATCH 14/58] Update repo name for OCaml --- ocaml/trexio/dune-project | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ocaml/trexio/dune-project b/ocaml/trexio/dune-project index 69f5bb4f..be375e72 100644 --- a/ocaml/trexio/dune-project +++ b/ocaml/trexio/dune-project @@ -1,11 +1,12 @@ (lang dune 3.1) (name trexio) +(version 2.2.0) (generate_opam_files true) (source - (github trex-coe/trexio)) + (github trex-coe/trexio_ocaml)) (authors "Anthony Scemama " From add6a549d8dce4a715d5f9762405a4072c3594a8 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 1 Jul 2022 16:56:45 +0200 Subject: [PATCH 15/58] Update dune file for OCaml --- ocaml/trexio/dune-project | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ocaml/trexio/dune-project b/ocaml/trexio/dune-project index be375e72..2248d22c 100644 --- a/ocaml/trexio/dune-project +++ b/ocaml/trexio/dune-project @@ -25,8 +25,12 @@ (name trexio) (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.") - (depends ocaml dune) + (depends + dune + (dune-configurator :build) + (conf-pkg-config :build)) (tags - ("Quantum chemistry" "Library"))) + ("Quantum chemistry" "Library")) +) ; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project From 4ed3e0c6d02a0f16304f602531d22fd72ccb5b13 Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 4 Jul 2022 11:22:31 +0200 Subject: [PATCH 16/58] Implement trexio_has_group templates --- src/templates_front/templator_front.org | 94 +++++++++++++++++++- src/templates_hdf5/templator_hdf5.org | 32 +++++++ src/templates_text/templator_text.org | 110 ++++++++++++++++++++++++ tools/generator.py | 2 +- 4 files changed, 236 insertions(+), 2 deletions(-) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index 5a0e423a..0947a0ae 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -1755,6 +1755,98 @@ trexio_pre_close (trexio_t* file) considered dimensioning variables and cannot be negative or 0. An attempt to write negative or 0 value will result in ~TREXIO_INVALID_ARG_2~ exit code. +** Templates for front end has_group functions +*** Introduction + + This section concerns API calls related to TREXIO groups + + | Function name | Description | + |----------------------+-----------------------------------| + | ~trexio_has_$group$~ | Check if a group exists in a file | + +*** C templates for front end + + The ~C~ templates that correspond to each of the abovementioned + functions can be found below. First parameter is the ~TREXIO~ file + handle. + +**** Function declarations + + #+begin_src c :tangle hrw_group_front.h :exports none +trexio_exit_code trexio_has_$group$(trexio_t* const file); + #+end_src + +**** Source code + + #+begin_src c :tangle has_group_front.c +trexio_exit_code +trexio_has_$group$ (trexio_t* const file) +{ + + if (file == NULL) return TREXIO_INVALID_ARG_1; + + assert(file->back_end < TREXIO_INVALID_BACK_END); + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_has_$group$(file); + + case TREXIO_HDF5: +#ifdef HAVE_HDF5 + return trexio_hdf5_has_$group$(file); +#else + return TREXIO_BACK_END_MISSING; +#endif +/* + case TREXIO_JSON: + return trexio_json_has_$group$(file); + break; +,*/ + } + + return TREXIO_FAILURE; +} + #+end_src + +*** Fortran templates for front end + + The ~Fortran~ templates that provide an access to the ~C~ API calls from Fortran. + These templates are based on the use of ~iso_c_binding~. Pointers have to be passed by value. + + #+begin_src f90 :tangle has_group_front_fortran.f90 +interface + integer(trexio_exit_code) function trexio_has_$group$ (trex_file) bind(C) + use, intrinsic :: iso_c_binding + import + integer(c_int64_t), intent(in), value :: trex_file + end function trexio_has_$group$ +end interface + #+end_src + +*** Python templates for front end + + #+begin_src python :tangle has_group_front.py +def has_$group$(trexio_file) -> bool: + """Check that $group$ group exists in the TREXIO file. + + Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function. + + Returns: + True if the variable exists, False otherwise + + Raises: + - trexio.Error if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error. + - Exception from some other error (e.g. RuntimeError). + """ + + rc = pytr.trexio_has_$group$(trexio_file.pytrexio_s) + if rc == TREXIO_FAILURE: + raise Error(rc) + + return rc == TREXIO_SUCCESS + #+end_src + ** Templates for front end has/read/write a single numerical attribute *** Introduction @@ -3924,7 +4016,7 @@ def read_$group_dset$(trexio_file, dim = None) -> list: """ $group_dset_dim$ = read_$group_dset_dim$(trexio_file) - + dims_list = [$group_dset_dim_list$] dim_real = 1 for i in range($group_dset_rank$): diff --git a/src/templates_hdf5/templator_hdf5.org b/src/templates_hdf5/templator_hdf5.org index bdfaf61e..535f0779 100644 --- a/src/templates_hdf5/templator_hdf5.org +++ b/src/templates_hdf5/templator_hdf5.org @@ -179,6 +179,38 @@ trexio_hdf5_deinit (trexio_t* const file) } #+end_src +* Template for HDF5 has a group + + #+begin_src c :tangle hrw_group_hdf5.h :exports none +trexio_exit_code trexio_hdf5_has_$group$ (trexio_t* const file); + #+end_src + + + #+begin_src c :tangle has_group_hdf5.c +trexio_exit_code +trexio_hdf5_has_$group$ (trexio_t* const file) +{ + + if (file == NULL) return TREXIO_INVALID_ARG_1; + + const trexio_hdf5_t* f = (const trexio_hdf5_t*) file; + + struct H5G_info_t group_info; + + /* H5Gget_info return info about the HDF5 group as a group_info struct */ + herr_t status = H5Gget_info(f->$group$_group, &group_info); + if (status < 0) return TREXIO_FAILURE; + + /* If nlinks==0 --> the group is empty, i.e. non-existent */ + if (group_info.nlinks == (hsize_t) 0) { + return TREXIO_HAS_NOT; + } else { + return TREXIO_SUCCESS; + } + +} + #+end_src + * Template for HDF5 has/read/write a numerical attribute #+begin_src c :tangle hrw_attr_num_hdf5.h :exports none diff --git a/src/templates_text/templator_text.org b/src/templates_text/templator_text.org index 7ad22b17..d0953469 100644 --- a/src/templates_text/templator_text.org +++ b/src/templates_text/templator_text.org @@ -112,6 +112,22 @@ trexio_exit_code trexio_text_inquire(const char* file_name); trexio_exit_code trexio_text_deinit(trexio_t* const file); trexio_exit_code trexio_text_lock(trexio_t* const file); trexio_exit_code trexio_text_unlock(trexio_t* const file); +bool trexio_text_file_exists(const char* file_name); + #+end_src + + #+begin_src c :tangle basic_text.c +bool +trexio_text_file_exists (const char* file_name) +{ + /* Check if the file with "file_name" exists */ + struct stat st; + + int rc = stat(file_name, &st); + + bool file_exists = rc == 0; + + return file_exists; +} #+end_src #+begin_src c :tangle basic_text.c @@ -493,6 +509,47 @@ trexio_text_read_$group$ (trexio_text_t* const file) } #+end_src +* Template for text has a group + + #+begin_src c :tangle hrw_group_text.h :exports none +trexio_exit_code trexio_text_has_$group$(trexio_t* const file); + #+end_src + + #+begin_src c :tangle has_group_text.c +trexio_exit_code +trexio_text_has_$group$ (trexio_t* const file) +{ + + if (file == NULL) return TREXIO_INVALID_ARG_1; + + /* Flush the group to make sure the group.txt file is created */ + if (file->mode != 'r') { + trexio_exit_code rc = trexio_text_flush_$group$((trexio_text_t*) file); + if (rc != TREXIO_SUCCESS) return TREXIO_FAILURE; + } + + /* Build the file name */ + char $group$_full_path[TREXIO_MAX_FILENAME_LENGTH]; + + const char* $group$_file_name = "/$group$.txt"; + + strncpy ($group$_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH); + strncat ($group$_full_path, $group$_file_name, + TREXIO_MAX_FILENAME_LENGTH-strlen($group$_file_name)); + + if ($group$_full_path[TREXIO_MAX_FILENAME_LENGTH-1] != '\0') return TREXIO_FAILURE; + + bool file_exists; + file_exists = trexio_text_file_exists($group$_full_path); + + if (file_exists) { + return TREXIO_SUCCESS; + } else { + return TREXIO_HAS_NOT; + } +} + #+end_src + * Template for text flush a group #+begin_src c :tangle flush_group_text.h :exports none @@ -1063,6 +1120,23 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file, rc = fclose(f_wSize); if (rc != 0) return TREXIO_FILE_ERROR; + const char $group$_file_name[256] = "/$group$.txt"; + + 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); + /* Append name of the file with sparse data */ + strncat (file_full_path, $group$_file_name, + TREXIO_MAX_FILENAME_LENGTH-strlen($group$_file_name)); + + bool file_exists = trexio_text_file_exists(file_full_path); + + /* Create an empty file for the trexio_text_has_group to work */ + if (!file_exists) { + FILE *fp = fopen(file_full_path, "ab+"); + fclose(fp); + } + /* Exit upon success */ return TREXIO_SUCCESS; } @@ -1533,6 +1607,24 @@ trexio_exit_code trexio_text_write_determinant_list(trexio_t* const file, rc = fclose(f); if (rc != 0) return TREXIO_FILE_ERROR; + /* Additional part for the trexio_text_has_group to work */ + const char det_file_name[256] = "/determinant.txt"; + + 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); + /* Append name of the file with sparse data */ + strncat (file_full_path, det_file_name, + TREXIO_MAX_FILENAME_LENGTH-strlen(det_file_name)); + + bool file_exists = trexio_text_file_exists(file_full_path); + + /* Create an empty file for the trexio_text_has_group to work */ + if (!file_exists) { + FILE *fp = fopen(file_full_path, "ab+"); + fclose(fp); + } + /* Exit upon success */ return TREXIO_SUCCESS; } @@ -1602,6 +1694,24 @@ trexio_exit_code trexio_text_write_determinant_coefficient(trexio_t* const file, rc = fclose(f_wSize); if (rc != 0) return TREXIO_FILE_ERROR; + /* Additional part for the trexio_text_has_group to work */ + const char det_file_name[256] = "/determinant.txt"; + + 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); + /* Append name of the file with sparse data */ + strncat (file_full_path, det_file_name, + TREXIO_MAX_FILENAME_LENGTH-strlen(det_file_name)); + + bool file_exists = trexio_text_file_exists(file_full_path); + + /* Create an empty file for the trexio_text_has_group to work */ + if (!file_exists) { + FILE *fp = fopen(file_full_path, "ab+"); + fclose(fp); + } + /* Exit upon success */ return TREXIO_SUCCESS; } diff --git a/tools/generator.py b/tools/generator.py index 99049216..22db5930 100644 --- a/tools/generator.py +++ b/tools/generator.py @@ -65,7 +65,7 @@ # populate group-related functions with mixed scheme for fname in files_todo['group']: # recursive scheme for delete_group functions - if 'delete' in fname: + if 'delete' in fname or 'has' in fname: recursive_populate_file(fname, template_paths, group_dict) # mixed (iterative+recursive) scheme [text backend] else: From 0bbe16efcedf14de4ae0adfb104fb565183cc5d8 Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 4 Jul 2022 11:23:04 +0200 Subject: [PATCH 17/58] Adapt the TEXT back end builder script --- src/templates_text/build.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/templates_text/build.sh b/src/templates_text/build.sh index b5d73f68..fccd3d24 100644 --- a/src/templates_text/build.sh +++ b/src/templates_text/build.sh @@ -13,6 +13,9 @@ cat basic_text.h >> trexio_text.h cat hrw_determinant_text.h >> trexio_text.h cat *_determinant_text.c >> trexio_text.c +cat populated/pop_has_group_text.c >> trexio_text.c +cat populated/pop_hrw_group_text.h >> trexio_text.h + cat populated/pop_free_group_text.c >> trexio_text.c cat populated/pop_read_group_text.c >> trexio_text.c cat populated/pop_flush_group_text.c >> trexio_text.c From 405f19c4bc5732ebd49a2806ace359e90d718598 Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 4 Jul 2022 11:23:47 +0200 Subject: [PATCH 18/58] Adapt the tests --- python/test/test_api.py | 24 +++++++++++++++++------- tests/io_dset_int_hdf5.c | 14 ++++++++++---- tests/io_dset_int_text.c | 14 ++++++++++---- tests/io_dset_sparse_hdf5.c | 15 +++++++++------ tests/io_dset_sparse_text.c | 8 ++++++++ tests/test_f.f90 | 12 ++++++++++++ 6 files changed, 66 insertions(+), 21 deletions(-) diff --git a/python/test/test_api.py b/python/test/test_api.py index e9eea8b9..c1569877 100644 --- a/python/test/test_api.py +++ b/python/test/test_api.py @@ -35,7 +35,7 @@ def test_void(): def test_orbital_list(): """Convert one determinant into a list of orbitals.""" orb_list_up, orb_list_dn = trexio.to_orbital_list_up_dn(int64_num, det_test) - assert orb_list_up[0] == 0 + assert orb_list_up[0] == 0 assert orb_list_dn[0] == 1 @@ -64,7 +64,7 @@ def open(self, filename=None, mode=None, back_end=None): self.filename = filename if not mode: mode = self.mode - else: + else: self.mode = mode if not back_end: back_end = self.back_end @@ -73,7 +73,7 @@ def open(self, filename=None, mode=None, back_end=None): self.test_file = trexio.File(filename, mode, back_end) assert self.test_file.exists - + def test_close(self): """Close the file.""" @@ -82,7 +82,7 @@ def test_close(self): self.test_file.close() assert not self.test_file.isOpen - + def test_errors(self): """Test some exceptions based on trexio.Error class.""" self.open(filename='unsafe_' + self.filename, mode='w', back_end=self.back_end) @@ -103,7 +103,7 @@ def test_num(self): trexio.write_nucleus_num(self.test_file, nucleus_num) assert trexio.has_nucleus_num(self.test_file) - + def test_str(self): """Write a string.""" self.open() @@ -133,7 +133,7 @@ def test_array_2D(self): """Write array of coordinates.""" self.open() if not trexio.has_nucleus_num(self.test_file): - self.test_num() + self.test_num() trexio.write_nucleus_coord(self.test_file, nucleus_coord) assert trexio.has_nucleus_coord(self.test_file) @@ -192,11 +192,21 @@ def test_delete_group(self): self.test_array_1D() self.test_array_2D() + assert trexio.has_nucleus(self.test_file) + trexio.delete_nucleus(self.test_file) assert not trexio.has_nucleus_num(self.test_file) assert not trexio.has_nucleus_charge(self.test_file) assert not trexio.has_nucleus_coord(self.test_file) + assert not trexio.has_nucleus(self.test_file) + + + def test_has_group(self): + """Check existense of a group.""" + self.open() + assert trexio.has_nucleus(self.test_file) + assert not trexio.has_rdm(self.test_file) def test_context_manager(self): @@ -315,6 +325,6 @@ def test_array_str_read(self): def test_str_read(self): """Read a string.""" - self.open(mode='r') + self.open(mode='r') point_group_r = trexio.read_nucleus_point_group(self.test_file) assert point_group_r == point_group diff --git a/tests/io_dset_int_hdf5.c b/tests/io_dset_int_hdf5.c index 50a39886..42db22b5 100644 --- a/tests/io_dset_int_hdf5.c +++ b/tests/io_dset_int_hdf5.c @@ -27,7 +27,7 @@ static int test_write_dset (const char* file_name, const back_end_t backend) { // write numerical attribute in an empty file rc = trexio_write_basis_shell_num(file, num); assert (rc == TREXIO_SUCCESS); - + // write numerical (integer) dataset in a file rc = trexio_write_basis_nucleus_index(file, nucl_index); assert (rc == TREXIO_SUCCESS); @@ -51,10 +51,18 @@ static int test_has_dset (const char* file_name, const back_end_t backend) { /*================= START OF TEST ==================*/ - // open file + // open file file = trexio_open(file_name, 'r', backend, &rc); assert (file != NULL); + // check that the group exists + rc = trexio_has_basis(file); + assert(rc==TREXIO_SUCCESS); + + // check that the group does not exist + rc = trexio_has_mo(file); + assert(rc==TREXIO_HAS_NOT); + // check that the previously written dataset exists rc = trexio_has_basis_nucleus_index(file); assert (rc == TREXIO_SUCCESS); @@ -130,5 +138,3 @@ int main(void) { return 0; } - - diff --git a/tests/io_dset_int_text.c b/tests/io_dset_int_text.c index 456d2065..d1386cc9 100644 --- a/tests/io_dset_int_text.c +++ b/tests/io_dset_int_text.c @@ -27,7 +27,7 @@ static int test_write_dset (const char* file_name, const back_end_t backend) { // write numerical attribute in an empty file rc = trexio_write_basis_shell_num(file, num); assert (rc == TREXIO_SUCCESS); - + // write numerical (integer) dataset in a file rc = trexio_write_basis_nucleus_index(file, nucl_index); assert (rc == TREXIO_SUCCESS); @@ -51,10 +51,18 @@ static int test_has_dset (const char* file_name, const back_end_t backend) { /*================= START OF TEST ==================*/ - // open file + // open file file = trexio_open(file_name, 'r', backend, &rc); assert (file != NULL); + // check that the group exists + rc = trexio_has_basis(file); + assert(rc==TREXIO_SUCCESS); + + // check that the group does not exist + rc = trexio_has_mo(file); + assert(rc==TREXIO_HAS_NOT); + // check that the previously written dataset exists rc = trexio_has_basis_nucleus_index(file); assert (rc == TREXIO_SUCCESS); @@ -130,5 +138,3 @@ int main(void) { return 0; } - - diff --git a/tests/io_dset_sparse_hdf5.c b/tests/io_dset_sparse_hdf5.c index 67b83571..7e57ec68 100644 --- a/tests/io_dset_sparse_hdf5.c +++ b/tests/io_dset_sparse_hdf5.c @@ -86,6 +86,14 @@ static int test_has_dset_sparse (const char* file_name, const back_end_t backend assert (file != NULL); assert (rc == TREXIO_SUCCESS); + // check that the group exists + rc = trexio_has_mo_2e_int(file); + assert(rc==TREXIO_SUCCESS); + + // check that the group does not exist + rc = trexio_has_rdm(file); + assert(rc==TREXIO_HAS_NOT); + // first check that mo_2e_int_eri_lr (we only write non-lr component in this unit test) rc = trexio_has_mo_2e_int_eri_lr(file); assert(rc==TREXIO_HAS_NOT); @@ -147,7 +155,7 @@ static int test_read_dset_sparse (const char* file_name, const back_end_t backen assert(index_read[4*offset_data_read] == 4 * (int32_t) (offset_file_read-offset)); // now attempt to read so that one encounters end of file during reading (i.e. offset_file_read + chunk_read > size_max) - offset_file_read = 97; + offset_file_read = 97L; offset_data_read = 1; int64_t eof_read_size_check = SIZE - offset_file_read; // if offset_file_read=97 => only 3 integrals will be read out of total of 100 @@ -159,11 +167,6 @@ static int test_read_dset_sparse (const char* file_name, const back_end_t backen assert(chunk_read == eof_read_size_check); assert(index_read[4*size_r-1] == 0); assert(index_read[4*offset_data_read] == 4 * (int32_t) (offset_file_read-offset)); - /* - for(int i=0; i Date: Mon, 4 Jul 2022 11:24:30 +0200 Subject: [PATCH 19/58] Add the minimal pre-commit config --- .pre-commit-config.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..fd16ba2d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files From f3ab78376c6ccc1af06d4c0b6e7cbbd1d52ced23 Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 4 Jul 2022 11:26:17 +0200 Subject: [PATCH 20/58] Update ChangeLog --- ChangeLog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index 13e97294..bbca1f2c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ CHANGES ======= +2.3 +--- + +- Added `trexio_has_group` functionality +- Added OCaml binding + 2.2 --- From 950ae7a50849c8f5e848de5dead665c2b31131de Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 1 Jul 2022 15:06:19 +0200 Subject: [PATCH 21/58] make ocaml-install in Makefile.am --- Makefile.am | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 2bfe8897..f1195707 100644 --- a/Makefile.am +++ b/Makefile.am @@ -227,6 +227,22 @@ cppcheck.out: $(trexio_h) --language=c --std=c99 -rp --platform=unix64 \ -I../include *.c *.h 2>../$@ +################# +# OCaml binding # +################# + +ocaml/trexio/_build/default/lib/trexio.cma: + $(MAKE) -C ocaml/trexio + +ocaml: ocaml/trexio/_build/default/lib/trexio.a + +ocaml-install: ocaml/trexio/_build/default/lib/trexio.a + opam install ocaml/trexio + +################## +# Python binding # +################## + setup_py = $(srcdir)/python/setup.py setup_cfg = $(srcdir)/python/setup.cfg pytrexio_py = $(srcdir)/python/pytrexio/pytrexio.py @@ -278,6 +294,6 @@ CLEANFILES += $(pytrexio_c) \ python/src/*.c \ python/src/*.h -.PHONY: cppcheck python-test python-install python-sdist check-numpy FORCE +.PHONY: cppcheck python-test python-install python-sdist check-numpy FORCE ocaml endif From d23c3b3308ada9a2c74e854cd1e08d0bec7ca17d Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 1 Jul 2022 15:16:21 +0200 Subject: [PATCH 22/58] Forgot Makefile in previous commit --- ocaml/trexio/Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 ocaml/trexio/Makefile diff --git a/ocaml/trexio/Makefile b/ocaml/trexio/Makefile new file mode 100644 index 00000000..91d0b694 --- /dev/null +++ b/ocaml/trexio/Makefile @@ -0,0 +1,9 @@ +default: sources + dune build + +lib/trexio.ml: ../../trex.json read_json.py src/trexio.ml src/trexio.mli src/trexio_stubs.c + ./read_json.py + +sources: lib/trexio.ml + +.PHONY: sources default From 3b47f26b0a767e8ef56bec8aa2e4cf469aed88b7 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 1 Jul 2022 15:17:50 +0200 Subject: [PATCH 23/58] Fix Makefile.am --- Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index f1195707..c28459d2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -234,9 +234,9 @@ cppcheck.out: $(trexio_h) ocaml/trexio/_build/default/lib/trexio.cma: $(MAKE) -C ocaml/trexio -ocaml: ocaml/trexio/_build/default/lib/trexio.a +ocaml: ocaml/trexio/_build/default/lib/trexio.cma -ocaml-install: ocaml/trexio/_build/default/lib/trexio.a +ocaml-install: ocaml/trexio/_build/default/lib/trexio.cma opam install ocaml/trexio ################## From 72e44a918ea8ca6c79c43599f9a754d5e9034f68 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 1 Jul 2022 16:14:20 +0200 Subject: [PATCH 24/58] Update repo name for OCaml --- ocaml/trexio/dune-project | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ocaml/trexio/dune-project b/ocaml/trexio/dune-project index 69f5bb4f..be375e72 100644 --- a/ocaml/trexio/dune-project +++ b/ocaml/trexio/dune-project @@ -1,11 +1,12 @@ (lang dune 3.1) (name trexio) +(version 2.2.0) (generate_opam_files true) (source - (github trex-coe/trexio)) + (github trex-coe/trexio_ocaml)) (authors "Anthony Scemama " From 19c30fce53ff2e5ebf761dd736cf37c3d075ee44 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 1 Jul 2022 16:56:45 +0200 Subject: [PATCH 25/58] Update dune file for OCaml --- ocaml/trexio/dune-project | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ocaml/trexio/dune-project b/ocaml/trexio/dune-project index be375e72..2248d22c 100644 --- a/ocaml/trexio/dune-project +++ b/ocaml/trexio/dune-project @@ -25,8 +25,12 @@ (name trexio) (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.") - (depends ocaml dune) + (depends + dune + (dune-configurator :build) + (conf-pkg-config :build)) (tags - ("Quantum chemistry" "Library"))) + ("Quantum chemistry" "Library")) +) ; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project From d8e6f43ac192422484858def5544f4dbbd9abaa7 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 1 Jul 2022 19:41:05 +0200 Subject: [PATCH 26/58] Better packaging --- Makefile.am | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index c28459d2..830f1c64 100644 --- a/Makefile.am +++ b/Makefile.am @@ -146,7 +146,6 @@ check_PROGRAMS = $(TESTS) LDADD = src/libtrexio.la test_trexio_f = $(srcdir)/tests/trexio_f.f90 -CLEANFILES += $(test_trexio_f) $(test_trexio_f): $(trexio_f) cp $(trexio_f) $(test_trexio_f) From e953d15bbdfc298f6325127833ea249bd8107c6f Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 4 Jul 2022 12:55:09 +0200 Subject: [PATCH 27/58] Add has_group in OCaml --- ocaml/trexio/read_json.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ocaml/trexio/read_json.py b/ocaml/trexio/read_json.py index 94b2711b..d41bc00a 100755 --- a/ocaml/trexio/read_json.py +++ b/ocaml/trexio/read_json.py @@ -34,6 +34,17 @@ def write_stubs(data): caml_failwith(trexio_string_of_error(rc)); } } + +CAMLprim value caml_has_{group}(value file) +{ + CAMLparam1(file); + trexio_exit_code rc = trexio_has_{group}( File_val(file) ); + if (rc == TREXIO_SUCCESS) { + CAMLreturn ( Val_bool(true) ); + } else { + CAMLreturn ( Val_bool(false) ); + } +} """ f.write( t.replace("{group}",group) ) @@ -437,7 +448,8 @@ def write_mli(data): f.write(content_pre) for group in data: - t = "val delete_{group}: trexio_file -> unit\n" + t = "val delete_{group}: trexio_file -> unit\n" + t += "val has_{group}: trexio_file -> bool\n" f.write( t.replace("{group}",group) ) for element in data[group]: @@ -526,7 +538,8 @@ def write_ml(data): f.write(content_pre) for group in data: - t = "external delete_{group}: trexio_file -> unit = \"caml_delete_{group}\"\n" + t = "external delete_{group}: trexio_file -> unit = \"caml_delete_{group}\"\n" + t += "external has_{group}: trexio_file -> bool = \"caml_has_{group}\"\n" f.write( t.replace("{group}",group) ) for element in data[group]: From c33e203a0b824df5c9860b9adb4a1239f95995a4 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 4 Jul 2022 12:56:29 +0200 Subject: [PATCH 28/58] Update version in OCaml --- ocaml/trexio/dune-project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocaml/trexio/dune-project b/ocaml/trexio/dune-project index 2248d22c..7793cce6 100644 --- a/ocaml/trexio/dune-project +++ b/ocaml/trexio/dune-project @@ -1,7 +1,7 @@ (lang dune 3.1) (name trexio) -(version 2.2.0) +(version 2.3.0) (generate_opam_files true) From a8c3619655a069c9ff6c7874ccddbf200b407875 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 4 Jul 2022 14:35:24 +0200 Subject: [PATCH 29/58] Add UHF possibility (#96) --- ChangeLog | 1 + README.md | 4 +- tests/test_f.f90 | 58 ++++++++++++--- trex.org | 180 ++++++++++++++++++++++++----------------------- 4 files changed, 145 insertions(+), 98 deletions(-) diff --git a/ChangeLog b/ChangeLog index bbca1f2c..53c73e0e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ CHANGES - Added `trexio_has_group` functionality - Added OCaml binding +- Added spin and energy in MOs 2.2 --- diff --git a/README.md b/README.md index ea6cfada..d82149b9 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,10 @@ TREX library for efficient I/O. ## Minimal requirements (for users): -- Autotools (autoconf >= 2.69, automake >= 1.11, libtool >= 2.2) or CMake (>= 3.16) +- Autotools (autoconf >= 2.69, automake >= 1.11, libtool >= 2.2) or CMake (>= 3.16) - C compiler (gcc/icc/clang) - Fortran compiler (gfortran/ifort) -- HDF5 library (>= 1.8) [optional, recommended for high performance] +- HDF5 library (>= 1.8) [optional, recommended for high performance] ## Installation procedure from the tarball (for users): diff --git a/tests/test_f.f90 b/tests/test_f.f90 index f36356c1..363dd541 100644 --- a/tests/test_f.f90 +++ b/tests/test_f.f90 @@ -63,6 +63,8 @@ subroutine test_write(file_name, back_end) character(len=:), allocatable :: sym_str character(len=:), allocatable :: label(:) + double precision, allocatable :: energy(:) + integer , allocatable :: spin(:) ! sparse data integer(4) :: index_sparse_ao_2e_int_eri(4,100) @@ -183,12 +185,29 @@ subroutine test_write(file_name, back_end) call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE MO NUM') endif + allocate(energy(mo_num)) + do i=1,mo_num + energy(i) = dble(i)-100.d0 + enddo + rc = trexio_write_mo_energy(trex_file, energy) + call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE ENERGY') + deallocate(energy) + + allocate(spin(mo_num)) + spin(:) = 0 + do i=mo_num/2+1,mo_num + spin(i) = 1 + enddo + rc = trexio_write_mo_spin(trex_file, spin) + call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE SPIN') + deallocate(spin) + offset = 0 do i = 1,n_buffers rc = trexio_write_ao_2e_int_eri(trex_file, offset, buf_size_sparse, & - index_sparse_ao_2e_int_eri(1,offset+1), & - value_sparse_ao_2e_int_eri(offset+1)) + index_sparse_ao_2e_int_eri(1,offset+1), & + value_sparse_ao_2e_int_eri(offset+1)) call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE SPARSE') offset = offset + buf_size_sparse enddo @@ -196,7 +215,7 @@ subroutine test_write(file_name, back_end) offset = 0 do i = 1,n_buffers rc = trexio_write_determinant_list(trex_file, offset, buf_size_det, & - det_list(1,offset+1)) + det_list(1,offset+1)) call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE DET LIST') offset = offset + buf_size_det enddo @@ -252,6 +271,9 @@ subroutine test_read(file_name, back_end) character(len=4) :: label(12) ! also works with allocatable arrays character(len=32) :: sym_str + integer :: mo_num + double precision, allocatable :: energy(:) + integer , allocatable :: spin(:) ! sparse data integer(4) :: index_sparse_ao_2e_int_eri(4,20) @@ -358,8 +380,8 @@ subroutine test_read(file_name, back_end) rc = trexio_read_ao_2e_int_eri(trex_file, offset_read, read_buf_size, & - index_sparse_ao_2e_int_eri(1, offset_data_read + 1), & - value_sparse_ao_2e_int_eri(offset_data_read + 1)) + index_sparse_ao_2e_int_eri(1, offset_data_read + 1), & + value_sparse_ao_2e_int_eri(offset_data_read + 1)) !do i = 1,20 ! write(*,*) index_sparse_ao_2e_int_eri(1,i) !enddo @@ -376,8 +398,8 @@ subroutine test_read(file_name, back_end) ! attempt to read reaching EOF: should return TREXIO_END and ! NOT increment the existing values in the buffer (only upd with what has been read) rc = trexio_read_ao_2e_int_eri(trex_file, offset_eof, read_buf_size, & - index_sparse_ao_2e_int_eri(1, offset_data_eof + 1), & - value_sparse_ao_2e_int_eri(offset_data_eof + 1)) + index_sparse_ao_2e_int_eri(1, offset_data_eof + 1), & + value_sparse_ao_2e_int_eri(offset_data_eof + 1)) !do i = 1,20 ! write(*,*) index_sparse_ao_2e_int_eri(1,i) !enddo @@ -415,7 +437,7 @@ 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)) + det_list(1, offset_det_data_read + 1)) !do i = 1,50 ! write(*,*) det_list(1,i) !enddo @@ -455,6 +477,26 @@ subroutine test_read(file_name, back_end) call exit(-1) endif + rc = trexio_read_mo_num(trex_file, mo_num) + call trexio_assert(rc, TREXIO_SUCCESS) + + allocate(spin(mo_num), energy(mo_num)) + rc = trexio_read_mo_energy(trex_file, energy) + call trexio_assert(rc, TREXIO_SUCCESS) + + if (energy(10) /= -90.d0) then + print *, 'Failure to read MO energy: ', energy(10) + call exit(-1) + end if + + rc = trexio_read_mo_spin(trex_file, spin) + call trexio_assert(rc, TREXIO_SUCCESS) + + if (sum(spin) /= mo_num/2) then + print *, 'Failure to read MO spin', mo_num, sum(spin) + call exit(-1) + end if + ! close the file rc = trexio_close(trex_file) call trexio_assert(rc, TREXIO_SUCCESS) diff --git a/trex.org b/trex.org index 3b684fcd..0ace038f 100644 --- a/trex.org +++ b/trex.org @@ -70,19 +70,19 @@ means that the source code is not produced by the generator, but hand-written. #+CALL: json(data=metadata, title="metadata") #+RESULTS: - :RESULTS: + :results: #+begin_src python :tangle trex.json "metadata": { - "code_num" : [ "dim", [] ] - , "code" : [ "str", [ "metadata.code_num" ] ] - , "author_num" : [ "dim", [] ] - , "author" : [ "str", [ "metadata.author_num" ] ] - , "package_version" : [ "str", [] ] - , "description" : [ "str", [] ] - , "unsafe" : [ "int", [] ] + "code_num" : [ "dim", [] ] + , "code" : [ "str", [ "metadata.code_num" ] ] + , "author_num" : [ "dim", [] ] + , "author" : [ "str", [ "metadata.author_num" ] ] + , "package_version" : [ "str", [] ] + , "description" : [ "str", [] ] + , "unsafe" : [ "int", [] ] } , #+end_src - :END: + :end: * Electron (electron group) @@ -197,20 +197,20 @@ If you encounter the aforementioned issue, please report it to our [[https://git #+CALL: json(data=ecp, title="ecp") #+RESULTS: - :RESULTS: + :results: #+begin_src python :tangle trex.json "ecp": { - "max_ang_mom_plus_1" : [ "int" , [ "nucleus.num" ] ] - , "z_core" : [ "int" , [ "nucleus.num" ] ] - , "num" : [ "dim" , [] ] - , "ang_mom" : [ "int" , [ "ecp.num" ] ] - , "nucleus_index" : [ "index", [ "ecp.num" ] ] - , "exponent" : [ "float", [ "ecp.num" ] ] - , "coefficient" : [ "float", [ "ecp.num" ] ] - , "power" : [ "int" , [ "ecp.num" ] ] + "max_ang_mom_plus_1" : [ "int" , [ "nucleus.num" ] ] + , "z_core" : [ "int" , [ "nucleus.num" ] ] + , "num" : [ "dim" , [] ] + , "ang_mom" : [ "int" , [ "ecp.num" ] ] + , "nucleus_index" : [ "index", [ "ecp.num" ] ] + , "exponent" : [ "float", [ "ecp.num" ] ] + , "coefficient" : [ "float", [ "ecp.num" ] ] + , "power" : [ "int" , [ "ecp.num" ] ] } , #+end_src - :END: + :end: ** Example @@ -324,22 +324,22 @@ power = [ #+CALL: json(data=basis, title="basis") #+RESULTS: - :RESULTS: + :results: #+begin_src python :tangle trex.json "basis": { - "type" : [ "str" , [] ] - , "prim_num" : [ "dim" , [] ] - , "shell_num" : [ "dim" , [] ] - , "nucleus_index" : [ "index", [ "basis.shell_num" ] ] - , "shell_ang_mom" : [ "int" , [ "basis.shell_num" ] ] - , "shell_factor" : [ "float", [ "basis.shell_num" ] ] - , "shell_index" : [ "index", [ "basis.prim_num" ] ] - , "exponent" : [ "float", [ "basis.prim_num" ] ] - , "coefficient" : [ "float", [ "basis.prim_num" ] ] - , "prim_factor" : [ "float", [ "basis.prim_num" ] ] + "type" : [ "str" , [] ] + , "prim_num" : [ "dim" , [] ] + , "shell_num" : [ "dim" , [] ] + , "nucleus_index" : [ "index", [ "basis.shell_num" ] ] + , "shell_ang_mom" : [ "int" , [ "basis.shell_num" ] ] + , "shell_factor" : [ "float", [ "basis.shell_num" ] ] + , "shell_index" : [ "index", [ "basis.prim_num" ] ] + , "exponent" : [ "float", [ "basis.prim_num" ] ] + , "coefficient" : [ "float", [ "basis.prim_num" ] ] + , "prim_factor" : [ "float", [ "basis.prim_num" ] ] } , #+end_src - :END: + :end: ** Example @@ -470,16 +470,16 @@ prim_factor = #+CALL: json(data=ao, title="ao") #+RESULTS: - :RESULTS: + :results: #+begin_src python :tangle trex.json "ao": { - "cartesian" : [ "int" , [] ] - , "num" : [ "dim" , [] ] - , "shell" : [ "index", [ "ao.num" ] ] - , "normalization" : [ "float", [ "ao.num" ] ] + "cartesian" : [ "int" , [] ] + , "num" : [ "dim" , [] ] + , "shell" : [ "index", [ "ao.num" ] ] + , "normalization" : [ "float", [ "ao.num" ] ] } , #+end_src - :END: + :end: ** One-electron integrals (~ao_1e_int~ group) :PROPERTIES: @@ -514,22 +514,22 @@ prim_factor = #+CALL: json(data=ao_1e_int, title="ao_1e_int") #+RESULTS: - :RESULTS: + :results: #+begin_src python :tangle trex.json "ao_1e_int": { - "overlap" : [ "float", [ "ao.num", "ao.num" ] ] - , "kinetic" : [ "float", [ "ao.num", "ao.num" ] ] - , "potential_n_e" : [ "float", [ "ao.num", "ao.num" ] ] - , "ecp" : [ "float", [ "ao.num", "ao.num" ] ] - , "core_hamiltonian" : [ "float", [ "ao.num", "ao.num" ] ] - , "overlap_im" : [ "float", [ "ao.num", "ao.num" ] ] - , "kinetic_im" : [ "float", [ "ao.num", "ao.num" ] ] - , "potential_n_e_im" : [ "float", [ "ao.num", "ao.num" ] ] - , "ecp_im" : [ "float", [ "ao.num", "ao.num" ] ] - , "core_hamiltonian_im" : [ "float", [ "ao.num", "ao.num" ] ] + "overlap" : [ "float", [ "ao.num", "ao.num" ] ] + , "kinetic" : [ "float", [ "ao.num", "ao.num" ] ] + , "potential_n_e" : [ "float", [ "ao.num", "ao.num" ] ] + , "ecp" : [ "float", [ "ao.num", "ao.num" ] ] + , "core_hamiltonian" : [ "float", [ "ao.num", "ao.num" ] ] + , "overlap_im" : [ "float", [ "ao.num", "ao.num" ] ] + , "kinetic_im" : [ "float", [ "ao.num", "ao.num" ] ] + , "potential_n_e_im" : [ "float", [ "ao.num", "ao.num" ] ] + , "ecp_im" : [ "float", [ "ao.num", "ao.num" ] ] + , "core_hamiltonian_im" : [ "float", [ "ao.num", "ao.num" ] ] } , #+end_src - :END: + :end: ** Two-electron integrals (~ao_2e_int~ group) :PROPERTIES: @@ -581,23 +581,27 @@ prim_factor = | ~class~ | ~str~ | ~(mo.num)~ | Choose among: Core, Inactive, Active, Virtual, Deleted | | ~symmetry~ | ~str~ | ~(mo.num)~ | Symmetry in the point group | | ~occupation~ | ~float~ | ~(mo.num)~ | Occupation number | + | ~energy~ | ~float~ | ~(mo.num)~ | For canonical MOs, corresponding eigenvalue | + | ~spin~ | ~int~ | ~(mo.num)~ | For UHF wave functions, 0 is $\alpha$ and 1 is $\beta$ | #+CALL: json(data=mo, title="mo") #+RESULTS: - :RESULTS: + :results: #+begin_src python :tangle trex.json "mo": { - "type" : [ "str" , [] ] - , "num" : [ "dim" , [] ] - , "coefficient" : [ "float", [ "mo.num", "ao.num" ] ] - , "coefficient_im" : [ "float", [ "mo.num", "ao.num" ] ] - , "class" : [ "str" , [ "mo.num" ] ] - , "symmetry" : [ "str" , [ "mo.num" ] ] - , "occupation" : [ "float", [ "mo.num" ] ] + "type" : [ "str" , [] ] + , "num" : [ "dim" , [] ] + , "coefficient" : [ "float", [ "mo.num", "ao.num" ] ] + , "coefficient_im" : [ "float", [ "mo.num", "ao.num" ] ] + , "class" : [ "str" , [ "mo.num" ] ] + , "symmetry" : [ "str" , [ "mo.num" ] ] + , "occupation" : [ "float", [ "mo.num" ] ] + , "energy" : [ "float", [ "mo.num" ] ] + , "spin" : [ "int" , [ "mo.num" ] ] } , #+end_src - :END: + :end: ** One-electron integrals (~mo_1e_int~ group) @@ -622,22 +626,22 @@ prim_factor = #+CALL: json(data=mo_1e_int, title="mo_1e_int") #+RESULTS: - :RESULTS: + :results: #+begin_src python :tangle trex.json "mo_1e_int": { - "overlap" : [ "float", [ "mo.num", "mo.num" ] ] - , "kinetic" : [ "float", [ "mo.num", "mo.num" ] ] - , "potential_n_e" : [ "float", [ "mo.num", "mo.num" ] ] - , "ecp" : [ "float", [ "mo.num", "mo.num" ] ] - , "core_hamiltonian" : [ "float", [ "mo.num", "mo.num" ] ] - , "overlap_im" : [ "float", [ "mo.num", "mo.num" ] ] - , "kinetic_im" : [ "float", [ "mo.num", "mo.num" ] ] - , "potential_n_e_im" : [ "float", [ "mo.num", "mo.num" ] ] - , "ecp_im" : [ "float", [ "mo.num", "mo.num" ] ] - , "core_hamiltonian_im" : [ "float", [ "mo.num", "mo.num" ] ] + "overlap" : [ "float", [ "mo.num", "mo.num" ] ] + , "kinetic" : [ "float", [ "mo.num", "mo.num" ] ] + , "potential_n_e" : [ "float", [ "mo.num", "mo.num" ] ] + , "ecp" : [ "float", [ "mo.num", "mo.num" ] ] + , "core_hamiltonian" : [ "float", [ "mo.num", "mo.num" ] ] + , "overlap_im" : [ "float", [ "mo.num", "mo.num" ] ] + , "kinetic_im" : [ "float", [ "mo.num", "mo.num" ] ] + , "potential_n_e_im" : [ "float", [ "mo.num", "mo.num" ] ] + , "ecp_im" : [ "float", [ "mo.num", "mo.num" ] ] + , "core_hamiltonian_im" : [ "float", [ "mo.num", "mo.num" ] ] } , #+end_src - :END: + :end: ** Two-electron integrals (~mo_2e_int~ group) @@ -701,15 +705,15 @@ prim_factor = #+CALL: json(data=determinant, title="determinant") #+RESULTS: - :RESULTS: + :results: #+begin_src python :tangle trex.json "determinant": { - "num" : [ "dim readonly" , [] ] - , "list" : [ "int special" , [ "determinant.num" ] ] - , "coefficient" : [ "float special", [ "determinant.num", "state.num" ] ] + "num" : [ "dim readonly" , [] ] + , "list" : [ "int special" , [ "determinant.num" ] ] + , "coefficient" : [ "float special", [ "determinant.num", "state.num" ] ] } , #+end_src - :END: + :end: * Excited states (state group) @@ -727,14 +731,14 @@ prim_factor = #+CALL: json(data=state, title="state") #+RESULTS: - :RESULTS: + :results: #+begin_src python :tangle trex.json "state": { - "num" : [ "dim", [] ] - , "label" : [ "str", [ "state.num" ] ] + "num" : [ "dim", [] ] + , "label" : [ "str", [ "state.num" ] ] } , #+end_src - :END: + :end: * Reduced density matrices (rdm group) @@ -819,15 +823,15 @@ prim_factor = #+CALL: json(data=cell, title="cell") #+RESULTS: - :RESULTS: + :results: #+begin_src python :tangle trex.json "cell": { - "a" : [ "float", [ "3" ] ] - , "b" : [ "float", [ "3" ] ] - , "c" : [ "float", [ "3" ] ] + "a" : [ "float", [ "3" ] ] + , "b" : [ "float", [ "3" ] ] + , "c" : [ "float", [ "3" ] ] } , #+end_src - :END: + :end: * Periodic boundary calculations (pbc group) @@ -840,14 +844,14 @@ prim_factor = #+CALL: json(data=pbc, title="pbc") #+RESULTS: - :RESULTS: + :results: #+begin_src python :tangle trex.json "pbc": { - "periodic" : [ "int" , [] ] - , "k_point" : [ "float", [ "3" ] ] + "periodic" : [ "int" , [] ] + , "k_point" : [ "float", [ "3" ] ] } , #+end_src - :END: + :end: * Quantum Monte Carlo data (qmc group) From 583749b24255772227059e32adce5793630df40c Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 4 Jul 2022 15:47:10 +0200 Subject: [PATCH 30/58] ChangeLog --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index 53c73e0e..116b6a54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ CHANGES - Added `trexio_has_group` functionality - Added OCaml binding - Added spin and energy in MOs +- Added CSF group 2.2 --- From 14d5a23c23e5f6f3f7178724a14f7dea65ce6778 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 4 Jul 2022 16:00:08 +0200 Subject: [PATCH 31/58] Bump version of python interface --- python/pytrexio/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pytrexio/_version.py b/python/pytrexio/_version.py index 67bc602a..55e47090 100644 --- a/python/pytrexio/_version.py +++ b/python/pytrexio/_version.py @@ -1 +1 @@ -__version__ = "1.3.0" +__version__ = "2.3.0" From 2d1a3da8bcf2d79423d350b78e024c6f61cea910 Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 4 Jul 2022 17:03:55 +0200 Subject: [PATCH 32/58] Revert "Bump version of python interface" This reverts commit 14d5a23c23e5f6f3f7178724a14f7dea65ce6778. --- python/pytrexio/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pytrexio/_version.py b/python/pytrexio/_version.py index 55e47090..67bc602a 100644 --- a/python/pytrexio/_version.py +++ b/python/pytrexio/_version.py @@ -1 +1 @@ -__version__ = "2.3.0" +__version__ = "1.3.0" From 1bc4fe44e3f258d8004a2141bb87cff583e88600 Mon Sep 17 00:00:00 2001 From: Evgeny Posenitskiy <45995097+q-posev@users.noreply.github.com> Date: Fri, 8 Jul 2022 11:26:17 +0200 Subject: [PATCH 33/58] Add AddressSanitizer debug to the CI --- .github/workflows/actions.yml | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 7a23aa0d..0b1298f5 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -52,10 +52,10 @@ jobs: ./configure --enable-silent-rules - name: compile TREXIO - run: make -j 2 + run: make -j2 - name: check TREXIO - run: make check + run: make -j2 check - name: create virtual environment run: | @@ -82,8 +82,22 @@ jobs: name: pytrexio-source path: ./trexio-*.tar.gz - - name: clean - run: make clean + - name: maintainer clean + run: make maintainer-clean + + - name: reconfigure with clang and AddressSanitizer + run: | + ./autogen.sh + ./configure CC=clang-11 CFLAGS="-O2 -fsanitize=address -fno-omit-frame-pointer" LDFLAGS="-fsanitize=address" --enable-silent-rules + + - name: recompile TREXIO + run: make -j2 + + - name: recheck TREXIO for memory leaks + run: make -j2 check + + - name: maintainer clean + run: make maintainer-clean trexio_macos: From 3cd7cac8f1b519cd1cc85d4eb94496d9be732749 Mon Sep 17 00:00:00 2001 From: q-posev Date: Fri, 8 Jul 2022 12:26:23 +0200 Subject: [PATCH 34/58] Fix potential buffer overflows in text back end --- src/templates_text/templator_text.org | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/templates_text/templator_text.org b/src/templates_text/templator_text.org index d0953469..88908e76 100644 --- a/src/templates_text/templator_text.org +++ b/src/templates_text/templator_text.org @@ -420,13 +420,14 @@ trexio_text_read_$group$ (trexio_text_t* const file) /* 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]" */ - rc = fscanf(f, " %1023[^\n]", tmp_$group_dset$); + rc = fscanf(f, " %1023[^\n]", buffer); if (rc != 1) { trexio_text_free_read_$group$(buffer, f, file, $group$); return NULL; } - size_t tmp_$group_dset$_len = strlen($group$->$group_dset$[i]); + size_t tmp_$group_dset$_len = strlen(buffer); + strncpy(tmp_$group_dset$, buffer, tmp_$group_dset$_len + 1); tmp_$group_dset$ += tmp_$group_dset$_len + 1; } } @@ -484,14 +485,15 @@ trexio_text_read_$group$ (trexio_text_t* const file) return NULL; } - rc = fscanf(f, " %1023[^\n]", $group$->$group_str$); + rc = fscanf(f, " %1023[^\n]", buffer); if (rc != 1) { trexio_text_free_read_$group$(buffer, f, file, $group$); return NULL; } + /* Safer string conversion to avoid buffer overflow in fscanf */ + strncpy($group$->$group_str$, buffer, $group$->len_$group_str$); } - // END REPEAT GROUP_ATTR_STR } else { continue; From 3ccbb4e71814900063ab1e09df54d03f3d5d4a6a Mon Sep 17 00:00:00 2001 From: q-posev Date: Fri, 8 Jul 2022 12:27:24 +0200 Subject: [PATCH 35/58] Better Fortran tests for arrays of strings --- tests/test_f.f90 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_f.f90 b/tests/test_f.f90 index 363dd541..1fa93813 100644 --- a/tests/test_f.f90 +++ b/tests/test_f.f90 @@ -349,9 +349,11 @@ subroutine test_read(file_name, back_end) endif - rc = trexio_read_nucleus_label(trex_file, label, 2) + rc = trexio_read_nucleus_label(trex_file, label, 4) call trexio_assert(rc, TREXIO_SUCCESS) - if (trim(label(2)) == 'Na') then + if (trim(label(2)) == 'Na' .and. & + trim(label(4)) == 'C 66' .and. & + trim(label(5)) == 'C') then write(*,*) 'SUCCESS READ LABEL' else print *, 'FAILURE LABEL CHECK' From 6d0293a379f8090782923e73480d1c765f3a3104 Mon Sep 17 00:00:00 2001 From: q-posev Date: Fri, 8 Jul 2022 18:12:50 +0200 Subject: [PATCH 36/58] Disable the malloc check to improve cross-compilation For example, compiling with gcc compiler with -fsanitize=address flag with use a different library for malloc-ing. This will fail if Autoconf add some symbols due to the use of AC_FUNC_MALLOC --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 01005c36..a2ea4395 100644 --- a/configure.ac +++ b/configure.ac @@ -138,7 +138,7 @@ AC_TYPE_UINT32_T AC_TYPE_UINT64_T # Checks for library functions. -AC_FUNC_MALLOC +# AC_FUNC_MALLOC AC_CHECK_FUNCS([memset mkdir strerror]) if test "x$enable_maintainer_mode" == "xyes"; then From 7b408aed2e87ad0c077f7236befbce2962dfda35 Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 11 Jul 2022 15:32:57 +0200 Subject: [PATCH 37/58] Enforce C99 standard during pytrexio compilation --- python/setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/setup.py b/python/setup.py index 14de5905..aaba4349 100644 --- a/python/setup.py +++ b/python/setup.py @@ -94,6 +94,7 @@ def parse_setuppy_commands(): include_dirs = [h5_cflags, srcpath, numpy_includedir], libraries = ['hdf5', 'hdf5_hl'], extra_compile_args = [ + '-std=c99', '-Wno-discarded-qualifiers', '-Wno-unused-variable', '-Wno-unused-but-set-variable' From b656b13cc6f1d021ec4978dd048387edd6806e1d Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 11 Jul 2022 16:28:46 +0200 Subject: [PATCH 38/58] More portable directory macros --- src/templates_text/templator_text.org | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/templates_text/templator_text.org b/src/templates_text/templator_text.org index 88908e76..b54f0c11 100644 --- a/src/templates_text/templator_text.org +++ b/src/templates_text/templator_text.org @@ -143,7 +143,15 @@ trexio_text_inquire (const char* file_name) if (file_exists) { - bool is_a_directory = st.st_mode & S_IFDIR; + bool is_a_directory = false; +#ifdef S_IFDIR + is_a_directory = st.st_mode & S_IFDIR; +#elif S_ISDIR + is_a_directory = S_ISDIR(s.st_mode); +#else + printf("Some important macros are missing for directory handling.\n"); + return TREXIO_FAILURE; +#endif if (!is_a_directory) return TREXIO_FILE_ERROR; return TREXIO_SUCCESS; From 8428a0ab0f51f7278511c4d938b90b1aa5ebec84 Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 11 Jul 2022 16:36:58 +0200 Subject: [PATCH 39/58] Fix compiler warning during strncpy The size of 32 correspond to previously allocated block of memory and SHOULD be adapted accordingly --- src/templates_text/templator_text.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates_text/templator_text.org b/src/templates_text/templator_text.org index b54f0c11..f1ebae49 100644 --- a/src/templates_text/templator_text.org +++ b/src/templates_text/templator_text.org @@ -435,7 +435,7 @@ trexio_text_read_$group$ (trexio_text_t* const file) } size_t tmp_$group_dset$_len = strlen(buffer); - strncpy(tmp_$group_dset$, buffer, tmp_$group_dset$_len + 1); + strncpy(tmp_$group_dset$, buffer, 32); tmp_$group_dset$ += tmp_$group_dset$_len + 1; } } From e8dffaac159405a2a020450407151bc7c39e0735 Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 12 Jul 2022 17:07:38 +0200 Subject: [PATCH 40/58] Manually append -fPIC flag This solves issues with some compilers, e.g. Intel ones, which fail to resolve some linking symbols when configured in a simple manner (./configure CC=icc FC=ifort) --- configure.ac | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/configure.ac b/configure.ac index a2ea4395..d4d14186 100644 --- a/configure.ac +++ b/configure.ac @@ -66,6 +66,31 @@ AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_GREP +# Specific options required with some compilers +case $FC in + *gfortran*) + FCFLAGS="$FCFLAGS -fPIC" + ;; + *flang*) + FCFLAGS="$FCFLAGS -fPIC" + ;; + *ifort*) + FCFLAGS="$FCFLAGS -fPIC" + ;; +esac + +case $CC in + *gcc*) + CFLAGS="$CFLAGS -fPIC" + ;; + *clang*) + CFLAGS="$CFLAGS -fPIC" + ;; + *icc*) + CFLAGS="$CFLAGS -fPIC" + ;; +esac + ## --------- ## Libraries From af828ea6cd0a19c153cd4ba54cb90a46cc80e7ff Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 12 Jul 2022 17:21:08 +0200 Subject: [PATCH 41/58] Implement trexio_to_bitfield_list functions in all APIs --- src/pytrexio.i | 3 + src/templates_front/templator_front.org | 109 +++++++++++++++++++++++- 2 files changed, 108 insertions(+), 4 deletions(-) diff --git a/src/pytrexio.i b/src/pytrexio.i index 121d465d..b6e54854 100644 --- a/src/pytrexio.i +++ b/src/pytrexio.i @@ -104,6 +104,9 @@ import_array(); %apply (int64_t* ARGOUT_ARRAY1, int64_t DIM1) {(int64_t* const dset_up_out, const int64_t dim_up_out)}; %apply (int64_t* ARGOUT_ARRAY1, int64_t DIM1) {(int64_t* const dset_dn_out, const int64_t dim_dn_out)}; %apply (bitfield_t* IN_ARRAY1, int64_t DIM1) {(const bitfield_t* dset_in, const int64_t dim_in)}; +%apply (int32_t* IN_ARRAY1, int32_t DIM1) {(const int32_t* orb_list, const int32_t occupied_num)}; +/* For some reasons SWIG does not apply the proper bitfield_t typemap, so one has to manually specify int64_t* ARGOUT_ARRAY1 below */ +%apply (int64_t* ARGOUT_ARRAY1, int32_t DIM1) {(bitfield_t* const bit_list, const int32_t N_int)}; /* This tells SWIG to treat char ** dset_in pattern as a special case Enables access to trexio_[...]_write_dset_str set of functions directly, i.e. diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index 0947a0ae..684ddfc1 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -5281,6 +5281,9 @@ def has_determinant_coefficient(trexio_file) -> bool: ~trexio_to_orbital_list_up_dn~ function does the same but for both up- and down-spin components of the determinant and returns two list of orbitals each corresponding to a different component. + ~trexio_to_bitfield_list~ function converts the list of occupied orbitals (up- or down-spin) + into the corresponding ~int64_t~ bitfield representation of the determinant. + ** C #+begin_src c :tangle prefix_front.h @@ -5289,16 +5292,50 @@ trexio_exit_code trexio_mark_safety(trexio_t* const file, const int32_t safety_f typedef int64_t bitfield_t; -#define TREXIO_ORBITAL_SHIFT 1 -#define TREXIO_INT_SIZE 64 -#define TREXIO_NORB_PER_INT ( 8*sizeof(bitfield_t) ) -# +#define TREXIO_ORBITAL_SHIFT 1 +#define TREXIO_INT_SIZE 64 +#define TREXIO_NORB_PER_INT ( 8*sizeof(bitfield_t) ) +#define TREXIO_NORB_PER_INT_SHIFT ( trailz( TREXIO_NORB_PER_INT ) ) + trexio_exit_code trexio_to_orbital_list (const int32_t N_int, const bitfield_t* d1, int32_t* const list, int32_t* const occupied_num); trexio_exit_code trexio_to_orbital_list_up_dn (const int32_t N_int, const bitfield_t* d1, int32_t* const list_up, int32_t* const list_dn, int32_t* const occ_num_up, int32_t* const occ_num_dn); trexio_exit_code trexio_safe_to_orbital_list (const int32_t N_int, const bitfield_t* dset_in, const int64_t dim_in, int32_t* const dset_out, const int64_t dim_out, int32_t* const num); trexio_exit_code trexio_safe_to_orbital_list_up_dn (const int32_t N_int, const bitfield_t* dset_in, const int64_t dim_in, int32_t* const dset_up_out, const int64_t dim_up_out, int32_t* const dset_dn_out, const int64_t dim_dn_out, int32_t* const num_up, int32_t* const num_dn); +trexio_exit_code trexio_to_bitfield_list (const int32_t* orb_list, const int32_t occupied_num, bitfield_t* const bit_list, const int32_t N_int); #+end_src + + #+begin_src c :tangle prefix_front.c +trexio_exit_code trexio_to_bitfield_list (const int32_t* orb_list, + const int32_t occupied_num, + bitfield_t* const bit_list, + const int32_t N_int) +{ + if (orb_list == NULL) return TREXIO_INVALID_ARG_1; + if (occupied_num <= 0) return TREXIO_INVALID_ARG_2; + if (bit_list == NULL) return TREXIO_INVALID_ARG_3; + if (N_int <= 0) return TREXIO_INVALID_ARG_4; + + uint32_t i; + uint32_t k; + uint32_t iorb; + + for (int32_t j = 0 ; j < N_int ; j++) { + bit_list[j] = (bitfield_t) 0; + } + + for (int32_t pos = 0 ; pos < occupied_num ; pos++) { + iorb = ((uint32_t) (orb_list[pos] + 1)) - TREXIO_ORBITAL_SHIFT; + i = (uint32_t) (iorb >> TREXIO_NORB_PER_INT_SHIFT); + k = (uint32_t) (iorb & (TREXIO_NORB_PER_INT - 1) ); + bit_list[i] |= ((bitfield_t) 1) << k; + } + + return TREXIO_SUCCESS; +} + #+end_src + + #+begin_src c :tangle prefix_front.c trexio_exit_code trexio_to_orbital_list(const int32_t N_int, const bitfield_t* d1, @@ -5478,6 +5515,18 @@ interface end interface #+end_src + #+begin_src f90 :tangle prefix_fortran.f90 +interface + integer(trexio_exit_code) function trexio_to_bitfield_list_c(list, occupied_num, det_list, N_int) bind(C, name="trexio_to_bitfield_list") + use, intrinsic :: iso_c_binding + import + integer(c_int32_t), intent(in) :: list(*) + integer(c_int32_t), intent(in), value :: occupied_num + integer(c_int64_t), intent(inout) :: det_list(*) + integer(c_int32_t), intent(in), value :: N_int + end function trexio_to_bitfield_list_c +end interface + #+end_src #+begin_src f90 :tangle prefix_fortran.f90 interface @@ -5520,6 +5569,33 @@ def info(): #+end_src + #+begin_src python :tangle basic_python.py +def to_bitfield_list(n_int: int, orbitals: list) -> list: + """Convert a list of occupied orbitals into a bitfield determinant. + + Input: + ~orbitals~ - list of occupied orbital indices fields (integers) + ~n_int~ - number of bitfields per determinant of a given spin + + Returns: + ~bitfield_list~: list + + Raises: + - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error. + - Exception from some other error (e.g. RuntimeError). + """ + + + rc, bitfield_list = pytr.trexio_to_bitfield_list(orbitals, n_int) + if rc != TREXIO_SUCCESS: + raise Error(rc) + if len(bitfield_list) != n_int: + raise Exception("Inconsistent size of the bitfield_list.") + + return bitfield_list + #+end_src + + #+begin_src python :tangle basic_python.py def to_orbital_list(n_int: int, determinant: list) -> list: """Convert a given determinant into a list of occupied orbitals. @@ -5546,8 +5622,10 @@ def to_orbital_list(n_int: int, determinant: list) -> list: raise Exception("Inconsistent size of the orbital_list.") return orbital_list[0:occ_num] + #+end_src + #+begin_src python :tangle basic_python.py def to_orbital_list_up_dn(n_int: int, determinant: list) -> tuple: """Convert a given determinant into two lists of occupied orbitals. @@ -5631,6 +5709,29 @@ contains by 1 since in Fortran arrays are 1-based and C/Python they are 0-based. #+begin_src f90 :tangle helper_fortran.f90 + integer(trexio_exit_code) function trexio_to_bitfield_list(list, occupied_num, det_list, N_int) + use, intrinsic :: iso_c_binding + implicit none + + integer(c_int32_t), intent(in) :: list(*) + integer(c_int32_t), intent(in), value :: occupied_num + integer(c_int64_t), intent(out) :: det_list(*) + integer(c_int32_t), intent(in), value :: N_int + integer(c_int32_t) :: list_0based(occupied_num) + + integer :: i + do i = 1,occupied_num + list_0based(i) = list(i) - 1 + enddo + + trexio_to_bitfield_list = trexio_to_bitfield_list_c(list_0based, occupied_num, det_list, N_int) + if (trexio_to_bitfield_list /= TREXIO_SUCCESS) then + return + endif + + end function trexio_to_bitfield_list + + integer(trexio_exit_code) function trexio_to_orbital_list(N_int, d1, list, occupied_num) use, intrinsic :: iso_c_binding implicit none From 755e94afab7ad27f07a01c01651d8e888cd28dee Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 12 Jul 2022 17:21:53 +0200 Subject: [PATCH 42/58] Add tests for to_bitfield_list conversion --- python/test/benzene_data.py | 5 ++++- python/test/test_api.py | 11 +++++++++++ tests/io_determinant_hdf5.c | 9 +++++++++ tests/io_determinant_text.c | 9 +++++++++ tests/test_f.f90 | 25 +++++++++++++++++++++++-- 5 files changed, 56 insertions(+), 3 deletions(-) diff --git a/python/test/benzene_data.py b/python/test/benzene_data.py index e9dd45cc..d64f9173 100644 --- a/python/test/benzene_data.py +++ b/python/test/benzene_data.py @@ -43,4 +43,7 @@ coeffs = [float(i/det_num) for i in range(det_num)] coeffs_s2 = [float(i*2/det_num) for i in range(det_num)] -det_test = [1, 2, 3, 2, 1, 3] \ No newline at end of file +det_test = [1, 2, 3, 2, 1, 3] + +orb_up_test = [0, 65, 128, 129] +orb_dn_test = [1, 64, 128, 129] diff --git a/python/test/test_api.py b/python/test/test_api.py index c1569877..342a528c 100644 --- a/python/test/test_api.py +++ b/python/test/test_api.py @@ -39,6 +39,17 @@ def test_orbital_list(): assert orb_list_dn[0] == 1 +def test_bitfield_list(): + """Convert lists of occupied up- and down-spin orbitals into determinants.""" + # convert det_test list into a numpy array for .all() assertion to work + det_test_np = np.array(det_test, dtype=np.int64) + + det_list_up = trexio.to_bitfield_list(int64_num, orb_up_test) + assert (det_list_up == det_test_np[:int64_num]).all() + det_list_dn = trexio.to_bitfield_list(int64_num, orb_dn_test) + assert (det_list_dn == det_test_np[int64_num:]).all() + + class TestIO: """Unit tests for writing/reading different blocks of the TREXIO file.""" diff --git a/tests/io_determinant_hdf5.c b/tests/io_determinant_hdf5.c index c51c2575..c90a2811 100644 --- a/tests/io_determinant_hdf5.c +++ b/tests/io_determinant_hdf5.c @@ -307,6 +307,14 @@ static int test_read_determinant (const char* file_name, const back_end_t backen printf("\n"); */ + // check conversion of one orbital list into the bitfield determinant representation + int64_t* det_list_check = (int64_t*) calloc(int_num, sizeof(int64_t)); + + rc = trexio_to_bitfield_list (orb_list_up, occ_num_up, det_list_check, int_num); + assert (rc == TREXIO_SUCCESS); + for (int i=0; i Date: Tue, 12 Jul 2022 17:59:45 +0200 Subject: [PATCH 43/58] Update ChangeLog --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index 53c73e0e..d47d22ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ CHANGES 2.3 --- +- Added trexio_to_bitfield_list functionality - Added `trexio_has_group` functionality - Added OCaml binding - Added spin and energy in MOs From 43bb57de59c80d1ed03b8f5df065258143f30c01 Mon Sep 17 00:00:00 2001 From: Evgeny Posenitskiy <45995097+q-posev@users.noreply.github.com> Date: Tue, 12 Jul 2022 19:35:15 +0200 Subject: [PATCH 44/58] Fix line truncation --- src/templates_front/templator_front.org | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index 684ddfc1..b0618e45 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -5517,7 +5517,8 @@ end interface #+begin_src f90 :tangle prefix_fortran.f90 interface - integer(trexio_exit_code) function trexio_to_bitfield_list_c(list, occupied_num, det_list, N_int) bind(C, name="trexio_to_bitfield_list") + integer(trexio_exit_code) function trexio_to_bitfield_list_c(list, occupied_num, det_list, N_int) & + bind(C, name="trexio_to_bitfield_list") use, intrinsic :: iso_c_binding import integer(c_int32_t), intent(in) :: list(*) @@ -5530,7 +5531,8 @@ end interface #+begin_src f90 :tangle prefix_fortran.f90 interface - integer(trexio_exit_code) function trexio_to_orbital_list_c(N_int, d1, list, occupied_num) bind(C, name="trexio_to_orbital_list") + integer(trexio_exit_code) function trexio_to_orbital_list_c(N_int, d1, list, occupied_num) & + bind(C, name="trexio_to_orbital_list") use, intrinsic :: iso_c_binding import integer(c_int32_t), intent(in), value :: N_int From 25517f3f774e50effde6205b2f1b21433e9e51b0 Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 26 Jul 2022 14:05:30 +0200 Subject: [PATCH 45/58] Update the Guix manifest file for trexio package --- tools/trexio.scm | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/tools/trexio.scm b/tools/trexio.scm index 5f8deb96..4b75519f 100644 --- a/tools/trexio.scm +++ b/tools/trexio.scm @@ -4,12 +4,12 @@ #:use-module (gnu packages glib) #:use-module (gnu packages gcc) #:use-module (gnu packages autotools) - #:use-module (gnu packages maths) + #:use-module (gnu packages maths) ;; contains hdf5 #:use-module (guix download) #:use-module (guix build-system gnu) #:use-module (guix licenses)) -(define-public trexio +(define-public trexio-2.0 (package (name "trexio") (version "2.0") @@ -20,6 +20,7 @@ ".tar.gz")) (sha256 (base32 + ;; the hash below is produced by guix download "1d2cn4w2r9gfid5b9wrq9q290kqdnbjdmvli76s1i5r58kdg5vkf" )))) (build-system gnu-build-system) @@ -31,4 +32,36 @@ (home-page "https://trex-coe.github.io/trexio") (license bsd-3))) +(define-public trexio-2.1 + (package/inherit trexio-2.0 + (version "2.1.0") + (source (origin + (method url-fetch) + (uri (string-append "https://github.com/TREX-CoE/trexio/releases/download/v" version + "/trexio-" version + ".tar.gz")) + (sha256 + (base32 + ;; the hash below is produced by guix download + "10syfw4mq3wpp9anahmxnm7660bm1ya5xd9l5njai3xr8g4nca13" + )))))) + +(define-public trexio-2.2 + (package/inherit trexio-2.0 + (version "2.2.0") + (source (origin + (method url-fetch) + (uri (string-append "https://github.com/TREX-CoE/trexio/releases/download/v" version + "/trexio-" version + ".tar.gz")) + (sha256 + (base32 + ;; the hash below is produced by guix download + "1n9n1gbk5hgvg73am991xrv7ap002rz719a3nvh8m8ff9x10qd76" + )))))) + +(define-public trexio + ;; Default version of TREXIO. + trexio-2.2) + trexio From 91defb120f5e3314eba3398b5df5efda5222f8f4 Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 26 Jul 2022 14:05:55 +0200 Subject: [PATCH 46/58] Add instructions for Guix users --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index d82149b9..9c21c335 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,19 @@ conda install trexio -c conda-forge More details can be found in the corresponding [trexio-feedstock](https://github.com/conda-forge/trexio-feedstock). Note that both parallel (see `mpi_openmpi` prefix) and serial (`nompi`) variants are provided. +## Installation procedure for Guix users + +The official releases of TREXIO `>=2.0.0` can be installed using the +[GNU Guix](https://guix.gnu.org) +functional package manager. +The [tools/trexio.scm](https://github.com/TREX-CoE/trexio/blob/master/tools/trexio.scm) +Schema file contains the manifest specification for the `trexio` package. +It can be installed within the selected `$GUIX_PROFILE` as follows: + +``` +guix package --profile=$GUIX_PROFILE --install-from-file=trexio.scm +``` + ## Compilation without the HDF5 library By default, the configuration step proceeds to search for the [HDF5 library](https://portal.hdfgroup.org/display/HDF5/HDF5). From 351c2bcffa4833fa32aec435c0ca652b875cc4fd Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 26 Jul 2022 15:54:33 +0200 Subject: [PATCH 47/58] Update manifest to link against any HDF5 --- tools/trexio.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/trexio.scm b/tools/trexio.scm index 4b75519f..f4e00af3 100644 --- a/tools/trexio.scm +++ b/tools/trexio.scm @@ -25,7 +25,7 @@ )))) (build-system gnu-build-system) (arguments '(#:configure-flags '("--enable-silent-rules"))) - (inputs `(("hdf5" ,hdf5-1.12) ("gfortran", gfortran))) + (inputs `(("hdf5" ,hdf5) ("gfortran", gfortran))) (synopsis "TREX I/O lbrary: trexio package") (description "APIs in C and Fortran to exchange wavefunction data. Supports HDF5 and TEXT back ends.") From 83a5308086fef725782b1d8bf2874a349fc2b9e6 Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 26 Jul 2022 16:46:18 +0200 Subject: [PATCH 48/58] Adapt the description [Guix] --- tools/trexio.scm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/trexio.scm b/tools/trexio.scm index f4e00af3..502ae6e3 100644 --- a/tools/trexio.scm +++ b/tools/trexio.scm @@ -26,9 +26,9 @@ (build-system gnu-build-system) (arguments '(#:configure-flags '("--enable-silent-rules"))) (inputs `(("hdf5" ,hdf5) ("gfortran", gfortran))) - (synopsis "TREX I/O lbrary: trexio package") - (description "APIs in C and Fortran to exchange wavefunction data. - Supports HDF5 and TEXT back ends.") + (synopsis "TREX I/O library") + (description "The TREXIO library defines a standard format for storing wave functions, together with + an C-compatible API such that it can be easily used in any programming language.") (home-page "https://trex-coe.github.io/trexio") (license bsd-3))) From 659110aa38ce303b512330278977b6c91c54b4bb Mon Sep 17 00:00:00 2001 From: q-posev Date: Thu, 28 Jul 2022 13:48:39 +0200 Subject: [PATCH 49/58] Minor fix to indicate that trexio is a custom module --- tools/trexio.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/trexio.scm b/tools/trexio.scm index 502ae6e3..5b3d6eee 100644 --- a/tools/trexio.scm +++ b/tools/trexio.scm @@ -1,4 +1,4 @@ -(define-module (gnu packages trexio) +(define-module (trexio) #:use-module (guix packages) #:use-module (gnu packages pkg-config) #:use-module (gnu packages glib) From 46385517e1861aa7664530eea1e007e0b311a61c Mon Sep 17 00:00:00 2001 From: q-posev Date: Thu, 28 Jul 2022 13:48:56 +0200 Subject: [PATCH 50/58] Add instructions for Spack users --- README.md | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9c21c335..9d5c3644 100644 --- a/README.md +++ b/README.md @@ -80,14 +80,28 @@ Note that both parallel (see `mpi_openmpi` prefix) and serial (`nompi`) variants ## Installation procedure for Guix users The official releases of TREXIO `>=2.0.0` can be installed using the -[GNU Guix](https://guix.gnu.org) -functional package manager. -The [tools/trexio.scm](https://github.com/TREX-CoE/trexio/blob/master/tools/trexio.scm) +[GNU Guix](https://guix.gnu.org) functional package manager. +The [trexio.scm](https://github.com/TREX-CoE/trexio/blob/master/tools/trexio.scm) Schema file contains the manifest specification for the `trexio` package. It can be installed within the selected `$GUIX_PROFILE` as follows: ``` -guix package --profile=$GUIX_PROFILE --install-from-file=trexio.scm +guix package \ + --profile=$GUIX_PROFILE \ + --cores= \ + --install-from-file=trexio.scm +``` + +## Installation procedure for Spack users + +The official releases `>=2.0.0` and the development version of TREXIO can be installed using the +[Spack](https://spack.io/) package manager. +The [trexio/package.py](https://github.com/spack/spack/blob/develop/var/spack/repos/builtin/packages/trexio/package.py) +file contains the Spack specifications required to build different variants of `trexio` library. +It can be installed as follows + +``` +spack install --jobs trexio ``` ## Compilation without the HDF5 library From c0879ad974d0707f4c8d37d7f08e2c29b716d53a Mon Sep 17 00:00:00 2001 From: q-posev Date: Thu, 28 Jul 2022 14:14:42 +0200 Subject: [PATCH 51/58] Add Guix manifest to the distribution --- Makefile.am | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile.am b/Makefile.am index 830f1c64..aebab9a4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -157,6 +157,11 @@ tests_test_f_SOURCES = $(test_trexio_f) tests/test_f.f90 clean-local: -rm -rf -- *.dir/ *.h5 __pycache__/ +# =============== GUIX MANIFEST =============== # + +trexio_scm = $(srcdir)/tools/trexio.scm +EXTRA_DIST += $(trexio_scm) + # =============== DOCUMENTATION =============== # HTML_TANGLED = docs/index.html \ From 1fde6f9aa1ac936f2cf9152893153c3387ed00e5 Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 6 Sep 2022 11:52:36 +0200 Subject: [PATCH 52/58] Optionally disable the Fortran tests in the user mode --- Makefile.am | 16 ++++++++++++++-- configure.ac | 18 ++++++++++++------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Makefile.am b/Makefile.am index aebab9a4..66fd2c77 100644 --- a/Makefile.am +++ b/Makefile.am @@ -34,7 +34,11 @@ ACLOCAL_AMFLAGS = -I m4 CLEANFILES = trexio.mod +if HAVE_FORTRAN BUILT_SOURCES = trexio.mod +else +BUILT_SOURCES = +endif EXTRA_DIST = .git_hash PACKAGE_VERSION = @PACKAGE_VERSION@ @@ -48,7 +52,10 @@ pkgconfig_DATA = pkgconfig/trexio.pc trexio_h = $(srcdir)/include/trexio.h trexio_f = $(srcdir)/include/trexio_f.f90 -include_HEADERS = $(trexio_h) $(trexio_f) +include_HEADERS = $(trexio_h) +if HAVE_FORTRAN +include_HEADERS += $(trexio_f) +endif AM_CPPFLAGS = -I$(srcdir)/src -I$(srcdir)/include @@ -136,15 +143,19 @@ TESTS_C += \ tests/overwrite_all_hdf5 endif +TESTS = $(TESTS_C) +if HAVE_FORTRAN TESTS_F = \ tests/test_f +TESTS += $(TESTS_F) +endif -TESTS = $(TESTS_C) $(TESTS_F) check_PROGRAMS = $(TESTS) # specify common LDADD options for all tests LDADD = src/libtrexio.la +if HAVE_FORTRAN test_trexio_f = $(srcdir)/tests/trexio_f.f90 $(test_trexio_f): $(trexio_f) @@ -153,6 +164,7 @@ $(test_trexio_f): $(trexio_f) trexio.mod: tests/trexio_f.o tests_test_f_SOURCES = $(test_trexio_f) tests/test_f.f90 +endif clean-local: -rm -rf -- *.dir/ *.h5 __pycache__/ diff --git a/configure.ac b/configure.ac index d4d14186..606e1295 100644 --- a/configure.ac +++ b/configure.ac @@ -50,12 +50,18 @@ AS_IF([test "$ac_cv_prog_cc_c99" = "no"], [AC_MSG_ERROR([The compiler does not support C99])]) AC_PROG_CC_C_O -# Fortran -AC_PROG_FC -AC_FC_FREEFORM -AC_FC_SRCEXT([f90]) -AC_PROG_FC_C_O -AC_FC_LIBRARY_LDFLAGS + +# Fortran API [default: --with-fortran], do not disable in the dev mode +AC_ARG_WITH(fortran, [AS_HELP_STRING([--without-fortran],[do not test and install the Fortran API])], ok=$withval, ok=yes) +if test "$ok" = "yes"; then + AC_PROG_FC + AC_FC_FREEFORM + AC_FC_SRCEXT([f90]) + AC_PROG_FC_C_O + AC_FC_LIBRARY_LDFLAGS +fi + +AM_CONDITIONAL([HAVE_FORTRAN],[test "$ok" = "yes"]) # pkg-config PKG_PROG_PKG_CONFIG() From cd48a74fd7fd69ffb3289cac88e49d7bce9e9126 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Tue, 6 Sep 2022 17:19:38 +0200 Subject: [PATCH 53/58] Fixed 'warning: cannot check for file existence when cross compiling' --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 606e1295..3ef8c862 100644 --- a/configure.ac +++ b/configure.ac @@ -19,8 +19,8 @@ LT_INIT # Activate developer mode when the source is the git repository. # Otherwise, it is the source distribution and the developer mode should not be activated. TEST_IFEXISTS=".git" -AC_CHECK_FILE([$TEST_IFEXISTS], - [enable_maintainer_mode="yes"], +AS_IF([test -d $TEST_IFEXISTS], + [enable_maintainer_mode="yes"] ) VERSION_MAJOR=`echo ${PACKAGE_VERSION} | cut -d. -f1` From 560f1880eef5dddd21ac0e748fe3f16d4f7d6cd9 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Tue, 6 Sep 2022 17:25:57 +0200 Subject: [PATCH 54/58] Fixed 'warning: The macro AC_HAVE_LIBRARY is obsolete.' --- m4/ax_lib_hdf5.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/m4/ax_lib_hdf5.m4 b/m4/ax_lib_hdf5.m4 index 074c2a82..86f97fb8 100644 --- a/m4/ax_lib_hdf5.m4 +++ b/m4/ax_lib_hdf5.m4 @@ -257,7 +257,7 @@ HDF5 support is being disabled (equivalent to --with-hdf5=no). AC_MSG_WARN([Unable to compile HDF5 test program]) fi dnl Look for HDF5's high level library - AC_HAVE_LIBRARY([hdf5_hl], [HDF5_LIBS="-lhdf5_hl $HDF5_LIBS"], [], []) + AC_CHECK_LIB([hdf5_hl], [main],[HDF5_LIBS="-lhdf5_hl $HDF5_LIBS"], [], []) CC=$ax_lib_hdf5_save_CC CPPFLAGS=$ax_lib_hdf5_save_CPPFLAGS From bbb9bcb085315dcf4afe12cc6558760a3af62eb6 Mon Sep 17 00:00:00 2001 From: q-posev Date: Sat, 10 Sep 2022 21:16:43 +0200 Subject: [PATCH 55/58] Fix Makefile after introduction of HAVE_FORTRAN --- Makefile.am | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/Makefile.am b/Makefile.am index 66fd2c77..5a52ab29 100644 --- a/Makefile.am +++ b/Makefile.am @@ -49,11 +49,11 @@ pkgconfig_DATA = pkgconfig/trexio.pc # =============== BUILD =============== # -trexio_h = $(srcdir)/include/trexio.h -trexio_f = $(srcdir)/include/trexio_f.f90 +trexio_h = include/trexio.h +include_HEADERS = $(trexio_h) -include_HEADERS = $(trexio_h) if HAVE_FORTRAN +trexio_f = include/trexio_f.f90 include_HEADERS += $(trexio_f) endif @@ -63,7 +63,6 @@ lib_LTLIBRARIES = src/libtrexio.la SOURCES = \ - $(trexio_h) \ src/trexio.c \ src/trexio_private.h \ src/trexio_s.h \ @@ -82,7 +81,7 @@ ORG_FILES = \ trex.org -src_libtrexio_la_SOURCES = $(SOURCES) +src_libtrexio_la_SOURCES = $(trexio_h) $(SOURCES) # Include CMake-related files in the distribution. EXTRA_DIST += CMakeLists.txt \ @@ -143,10 +142,10 @@ TESTS_C += \ tests/overwrite_all_hdf5 endif -TESTS = $(TESTS_C) +TESTS = $(TESTS_C) + if HAVE_FORTRAN -TESTS_F = \ - tests/test_f +TESTS_F = tests/test_f TESTS += $(TESTS_F) endif @@ -156,7 +155,7 @@ check_PROGRAMS = $(TESTS) LDADD = src/libtrexio.la if HAVE_FORTRAN -test_trexio_f = $(srcdir)/tests/trexio_f.f90 +test_trexio_f = tests/trexio_f.f90 $(test_trexio_f): $(trexio_f) cp $(trexio_f) $(test_trexio_f) @@ -211,9 +210,15 @@ HDF5_CPPFLAGS = @HDF5_CPPFLAGS@ if TREXIO_DEVEL -CLEANFILES += $(SOURCES) $(trexio_f) $(trexio_h) $(HTML_TANGLED) $(htmlizer) .git_hash +CLEANFILES += $(SOURCES) $(trexio_h) $(HTML_TANGLED) $(htmlizer) .git_hash + +BUILT_SOURCES += $(SOURCES) $(trexio_h) -BUILT_SOURCES += $(SOURCES) $(trexio_f) $(test_trexio_f) +if HAVE_FORTRAN +CLEANFILES += $(trexio_f) +BUILT_SOURCES += $(trexio_f) $(test_trexio_f) +$(trexio_f): $(trexio_h) +endif .git_hash: FORCE git log | head -1 | cut -d ' ' -f 2 > .git_hash @@ -223,10 +228,10 @@ all: .git_hash GENERATOR_FILES = $(srcdir)/tools/generator.py \ $(srcdir)/tools/generator_tools.py -$(SOURCES): $(trexio_f) +$(SOURCES): $(trexio_h) src/trexio.c: $(trexio_h) -$(trexio_f): $(ORG_FILES) $(GENERATOR_FILES) +$(trexio_h): $(ORG_FILES) $(GENERATOR_FILES) cd $(srcdir)/tools && ./build_trexio.sh $(htmlizer): $(ORG_FILES) $(srcdir)/src/README.org From 7fc4465d33f6bfc52f468af21519c1fa920ed86f Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 13 Sep 2022 11:29:59 +0200 Subject: [PATCH 56/58] Add functions to force flushing of data buffers --- src/templates_front/templator_front.org | 78 +++++++++++++++++++++++++ src/templates_hdf5/templator_hdf5.org | 15 +++++ src/templates_text/templator_text.org | 21 +++++++ tests/io_all.c | 4 ++ 4 files changed, 118 insertions(+) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index b0618e45..11e25b73 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -1424,6 +1424,84 @@ def _close(trexio_file): raise Error(rc) #+end_src +** File flushing + + ~trexio_flush~ flushes all buffers into the ~trexio_t~ file. + + input parameters: + ~file~ -- TREXIO file handle. + + output: + ~trexio_exit_code~ exit code. + +*** C + + #+begin_src c :tangle prefix_front.h :exports none +trexio_exit_code trexio_flush(trexio_t* file); + #+end_src + + #+begin_src c :tangle prefix_front.c +trexio_exit_code +trexio_flush (trexio_t* file) +{ + + if (file == NULL) return TREXIO_FILE_ERROR; + + trexio_exit_code rc = TREXIO_FAILURE; + + assert(file->back_end < TREXIO_INVALID_BACK_END); + + /* Terminate the back end */ + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_flush(file); + break; + + case TREXIO_HDF5: +#ifdef HAVE_HDF5 + rc = trexio_hdf5_flush(file); + break; +#else + return TREXIO_BACK_END_MISSING; +#endif +/* + case TREXIO_JSON: + rc = trexio_json_flush(file); + break; +,*/ + } + + return rc; +} + #+end_src + +*** Fortran + + #+begin_src f90 :tangle prefix_fortran.f90 +interface + integer(trexio_exit_code) function trexio_flush (trex_file) bind(C) + use, intrinsic :: iso_c_binding + import + integer(c_int64_t), intent(in), value :: trex_file + end function trexio_flush +end interface + #+end_src + +*** Python + + #+begin_src python :tangle basic_python.py +def flush(trexio_file): + """Flush buffers into the TREXIO file. + + Parameter is a ~trexio_file~ object that has been created by a call to ~open~ function. + """ + + rc = pytr.trexio_flush(trexio_file) + if rc != TREXIO_SUCCESS: + raise Error(rc) + #+end_src + ** File existence ~trexio_inquire~ check whether TREXIO file exists. diff --git a/src/templates_hdf5/templator_hdf5.org b/src/templates_hdf5/templator_hdf5.org index 535f0779..989fb67b 100644 --- a/src/templates_hdf5/templator_hdf5.org +++ b/src/templates_hdf5/templator_hdf5.org @@ -79,6 +79,21 @@ typedef struct trexio_hdf5_s { trexio_exit_code trexio_hdf5_init(trexio_t* const file); trexio_exit_code trexio_hdf5_deinit(trexio_t* const file); trexio_exit_code trexio_hdf5_inquire(const char* file_name); +trexio_exit_code trexio_hdf5_flush(trexio_t* const file); + #+end_src + + #+begin_src c :tangle basic_hdf5.c +trexio_exit_code +trexio_hdf5_flush(trexio_t* const file) +{ + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t rc = H5Fflush(f->file_id, H5F_SCOPE_GLOBAL); + if (rc < 0) return TREXIO_FAILURE; + + return TREXIO_SUCCESS; +} #+end_src #+begin_src c :tangle basic_hdf5.c diff --git a/src/templates_text/templator_text.org b/src/templates_text/templator_text.org index f1ebae49..c59e81cd 100644 --- a/src/templates_text/templator_text.org +++ b/src/templates_text/templator_text.org @@ -112,6 +112,7 @@ trexio_exit_code trexio_text_inquire(const char* file_name); trexio_exit_code trexio_text_deinit(trexio_t* const file); trexio_exit_code trexio_text_lock(trexio_t* const file); trexio_exit_code trexio_text_unlock(trexio_t* const file); +trexio_exit_code trexio_text_flush(trexio_t* const file); bool trexio_text_file_exists(const char* file_name); #+end_src @@ -292,6 +293,26 @@ trexio_text_deinit (trexio_t* const file) } #+end_src +* Flush function (templated part) + + #+begin_src c :tangle basic_text_group.c +trexio_exit_code +trexio_text_flush (trexio_t* const file) +{ + + if (file == NULL) return TREXIO_INVALID_ARG_1; + + 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); + + return TREXIO_SUCCESS; + +} + #+end_src + * Template for text read a group #+begin_src c :tangle read_group_text.h :exports none diff --git a/tests/io_all.c b/tests/io_all.c index e476efd0..cde61cd7 100644 --- a/tests/io_all.c +++ b/tests/io_all.c @@ -94,6 +94,10 @@ int test_write(const char* file_name, const back_end_t backend) { rc = trexio_write_nucleus_coord(file,coord); assert (rc == TREXIO_SUCCESS); + // check the force flushing + rc = trexio_flush(file); + assert (rc == TREXIO_SUCCESS); + rc = trexio_write_nucleus_label(file, label, 32); assert (rc == TREXIO_SUCCESS); rc = trexio_write_nucleus_point_group(file, sym, 32); From 0e961123d4f43b1af37760ca576dd6464ffb87a6 Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 13 Sep 2022 11:30:13 +0200 Subject: [PATCH 57/58] Update ChangeLog --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index 04885ceb..e3bb2174 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,8 @@ CHANGES - Added OCaml binding - Added spin and energy in MOs - Added CSF group +- Added `trexio_flush` functionality +- Optional compilation `--without-fortran` 2.2 --- From 5b5730ed81d63642d86e89036f2bf0153b090eb0 Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 26 Sep 2022 17:06:04 +0200 Subject: [PATCH 58/58] Do not rely on the .git folder for TREXIO_DEVEL setup This poses issues when packaging for Guix and Debian --- .devel | 0 CMakeLists.txt | 2 +- configure.ac | 6 +++--- 3 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 .devel diff --git a/.devel b/.devel new file mode 100644 index 00000000..e69de29b diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a5712f8..ba6f6c6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ set(CMAKE_C_STANDARD_REQUIRED ON) # Optional configure for developer mode to generate source code from org-mode files. option(TREXIO_DEVEL "TREXIO developer mode (for code generation)." OFF) -if(EXISTS "${CMAKE_SOURCE_DIR}/.git/config") +if(EXISTS "${CMAKE_SOURCE_DIR}/.devel") set(TREXIO_DEVEL ON) find_package(Python3 REQUIRED) if(Python3_FOUND) diff --git a/configure.ac b/configure.ac index 3ef8c862..cd0a7b2a 100644 --- a/configure.ac +++ b/configure.ac @@ -16,10 +16,10 @@ AM_PROG_AR LT_PREREQ([2.2]) LT_INIT -# Activate developer mode when the source is the git repository. +# Activate developer mode when if a dummy file is present (true when cloning the git repository). # Otherwise, it is the source distribution and the developer mode should not be activated. -TEST_IFEXISTS=".git" -AS_IF([test -d $TEST_IFEXISTS], +TEST_IFEXISTS=".devel" +AS_IF([test -f $TEST_IFEXISTS], [enable_maintainer_mode="yes"] )