mirror of
https://github.com/TREX-CoE/trexio.git
synced 2025-04-29 03:44:45 +02:00
Merge branch 'master' into patch-v220
This commit is contained in:
commit
0d948ac64c
22
.github/workflows/actions.yml
vendored
22
.github/workflows/actions.yml
vendored
@ -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:
|
||||
|
||||
|
2
.github/workflows/build-wheels.yml
vendored
2
.github/workflows/build-wheels.yml
vendored
@ -222,7 +222,7 @@ jobs:
|
||||
|
||||
#- name: Publish distribution 📦 to Test PyPI
|
||||
# uses: pypa/gh-action-pypi-publish@master
|
||||
# with:
|
||||
# with:
|
||||
# password: ${{ secrets.TEST_PYPI_API_TOKEN }}
|
||||
# repository_url: https://test.pypi.org/legacy/
|
||||
#verbose: true
|
||||
|
10
.pre-commit-config.yaml
Normal file
10
.pre-commit-config.yaml
Normal file
@ -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
|
@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
# Initialize the CMake project.
|
||||
project(Trexio
|
||||
VERSION 2.2.1
|
||||
VERSION 2.3.0
|
||||
DESCRIPTION "TREX I/O library"
|
||||
LANGUAGES C Fortran
|
||||
)
|
||||
|
11
ChangeLog
11
ChangeLog
@ -1,6 +1,17 @@
|
||||
CHANGES
|
||||
=======
|
||||
|
||||
2.3
|
||||
---
|
||||
|
||||
- Added trexio_to_bitfield_list functionality
|
||||
- Added `trexio_has_group` functionality
|
||||
- Added OCaml binding
|
||||
- Added spin and energy in MOs
|
||||
- Added CSF group
|
||||
- Added `trexio_flush` functionality
|
||||
- Optional compilation `--without-fortran`
|
||||
|
||||
2.2
|
||||
---
|
||||
|
||||
|
67
Makefile.am
67
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@
|
||||
@ -45,10 +49,13 @@ 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) $(trexio_f)
|
||||
if HAVE_FORTRAN
|
||||
trexio_f = include/trexio_f.f90
|
||||
include_HEADERS += $(trexio_f)
|
||||
endif
|
||||
|
||||
AM_CPPFLAGS = -I$(srcdir)/src -I$(srcdir)/include
|
||||
|
||||
@ -56,7 +63,6 @@ lib_LTLIBRARIES = src/libtrexio.la
|
||||
|
||||
|
||||
SOURCES = \
|
||||
$(trexio_h) \
|
||||
src/trexio.c \
|
||||
src/trexio_private.h \
|
||||
src/trexio_s.h \
|
||||
@ -75,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 \
|
||||
@ -117,17 +123,20 @@ TESTS_C += \
|
||||
tests/overwrite_all_hdf5
|
||||
endif
|
||||
|
||||
TESTS_F = \
|
||||
tests/test_f
|
||||
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
|
||||
|
||||
test_trexio_f = $(srcdir)/tests/trexio_f.f90
|
||||
CLEANFILES += $(test_trexio_f)
|
||||
if HAVE_FORTRAN
|
||||
test_trexio_f = tests/trexio_f.f90
|
||||
|
||||
$(test_trexio_f): $(trexio_f)
|
||||
cp $(trexio_f) $(test_trexio_f)
|
||||
@ -135,10 +144,16 @@ $(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__/
|
||||
|
||||
# =============== GUIX MANIFEST =============== #
|
||||
|
||||
trexio_scm = $(srcdir)/tools/trexio.scm
|
||||
EXTRA_DIST += $(trexio_scm)
|
||||
|
||||
# =============== DOCUMENTATION =============== #
|
||||
|
||||
HTML_TANGLED = docs/index.html \
|
||||
@ -176,9 +191,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_f) $(test_trexio_f)
|
||||
BUILT_SOURCES += $(SOURCES) $(trexio_h)
|
||||
|
||||
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
|
||||
@ -188,10 +209,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
|
||||
@ -208,6 +229,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.cma
|
||||
|
||||
ocaml-install: ocaml/trexio/_build/default/lib/trexio.cma
|
||||
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
|
||||
@ -277,6 +314,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
|
||||
|
35
README.md
35
README.md
@ -1,5 +1,6 @@
|
||||
|
||||
# TREXIO
|
||||
<img src="https://trex-coe.eu/sites/default/files/styles/responsive_no_crop/public/2022-01/TREXIO%20Code.png" width=200>
|
||||
|
||||
[](https://github.com/TREX-CoE/trexio/actions/workflows/actions.yml)
|
||||

|
||||
@ -9,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):
|
||||
@ -63,6 +64,9 @@ The aforementioned instructions rely on [Autotools](https://www.gnu.org/software
|
||||
|
||||
## Installation procedure for conda users
|
||||
|
||||
[](https://anaconda.org/conda-forge/trexio)
|
||||
[](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:
|
||||
|
||||
@ -73,6 +77,33 @@ 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 [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 \
|
||||
--cores=<n_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 <n_cores> trexio
|
||||
```
|
||||
|
||||
## Compilation without the HDF5 library
|
||||
|
||||
By default, the configuration step proceeds to search for the [HDF5 library](https://portal.hdfgroup.org/display/HDF5/HDF5).
|
||||
|
47
configure.ac
47
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.1],[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])
|
||||
@ -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()
|
||||
@ -66,6 +72,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
|
||||
@ -138,7 +169,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
|
||||
|
83
examples.org
83
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,83 @@ 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 ! TREXIO file handle
|
||||
character*(128) :: err_msg ! Error message
|
||||
|
||||
|
||||
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)
|
||||
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
|
||||
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
|
||||
|
||||
deallocate(buffer, orb_list_dn, orb_list_up)
|
||||
|
||||
end
|
||||
#+end_src
|
||||
|
||||
|
@ -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
|
||||
|
3
ocaml/trexio/.ocamlinit
Normal file
3
ocaml/trexio/.ocamlinit
Normal file
@ -0,0 +1,3 @@
|
||||
#use "topfind";;
|
||||
open Printf;;
|
||||
|
9
ocaml/trexio/Makefile
Normal file
9
ocaml/trexio/Makefile
Normal file
@ -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
|
9
ocaml/trexio/README.md
Normal file
9
ocaml/trexio/README.md
Normal file
@ -0,0 +1,9 @@
|
||||
# TREXIO OCaml interface
|
||||
|
||||
## Building the source code
|
||||
|
||||
The hand-written source files are located in the `src` directory. These files contain
|
||||
the pieces of code that can't be generated automatically. The source code distributed
|
||||
in the OPAM package is generated by the `read_json.py` script, and is written in files
|
||||
located in the `lib` directory.
|
||||
|
36
ocaml/trexio/dune-project
Normal file
36
ocaml/trexio/dune-project
Normal file
@ -0,0 +1,36 @@
|
||||
(lang dune 3.1)
|
||||
|
||||
(name trexio)
|
||||
(version 2.3.0)
|
||||
|
||||
(generate_opam_files true)
|
||||
|
||||
(source
|
||||
(github trex-coe/trexio_ocaml))
|
||||
|
||||
(authors
|
||||
"Anthony Scemama <scemama@irsamc.ups-tlse.fr>"
|
||||
"Evgeny Posenitskiy <posenitskiy@irsamc.ups-tlse.fr>"
|
||||
)
|
||||
|
||||
(maintainers
|
||||
"Anthony Scemama <scemama@irsamc.ups-tlse.fr>"
|
||||
)
|
||||
|
||||
(license "BSD-3-Clause")
|
||||
|
||||
(documentation "https://trex-coe.github.io/trexio/")
|
||||
|
||||
(package
|
||||
(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
|
||||
dune
|
||||
(dune-configurator :build)
|
||||
(conf-pkg-config :build))
|
||||
(tags
|
||||
("Quantum chemistry" "Library"))
|
||||
)
|
||||
|
||||
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project
|
22
ocaml/trexio/lib/config/discover.ml
Normal file
22
ocaml/trexio/lib/config/discover.ml
Normal file
@ -0,0 +1,22 @@
|
||||
module C = Configurator.V1
|
||||
|
||||
let () =
|
||||
C.main ~name:"trexio" (fun c ->
|
||||
let default : C.Pkg_config.package_conf =
|
||||
{ libs = ["-ltrexio"]
|
||||
; cflags = ["-fPIC"]
|
||||
}
|
||||
in
|
||||
let conf =
|
||||
match C.Pkg_config.get c with
|
||||
| None -> default
|
||||
| Some pc ->
|
||||
match (C.Pkg_config.query pc ~package:"trexio") with
|
||||
| None -> default
|
||||
| Some deps -> deps
|
||||
in
|
||||
|
||||
|
||||
C.Flags.write_sexp "c_flags.sexp" conf.cflags;
|
||||
C.Flags.write_sexp "c_library_flags.sexp" conf.libs)
|
||||
|
3
ocaml/trexio/lib/config/dune
Normal file
3
ocaml/trexio/lib/config/dune
Normal file
@ -0,0 +1,3 @@
|
||||
(executable
|
||||
(name discover)
|
||||
(libraries dune-configurator))
|
19
ocaml/trexio/lib/dune
Normal file
19
ocaml/trexio/lib/dune
Normal file
@ -0,0 +1,19 @@
|
||||
(library
|
||||
(name trexio)
|
||||
(public_name trexio)
|
||||
(foreign_stubs
|
||||
(language c)
|
||||
(names trexio_stubs)
|
||||
(flags (:include c_flags.sexp) "-fPIC"))
|
||||
(c_library_flags (:include c_library_flags.sexp))
|
||||
)
|
||||
|
||||
(rule
|
||||
(targets c_flags.sexp c_library_flags.sexp)
|
||||
(action (run ./config/discover.exe)))
|
||||
|
||||
(env
|
||||
(dev
|
||||
(flags ))
|
||||
(release
|
||||
(ocamlopt_flags )))
|
659
ocaml/trexio/read_json.py
Executable file
659
ocaml/trexio/read_json.py
Executable file
@ -0,0 +1,659 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import json
|
||||
|
||||
json_file = "../../trex.json"
|
||||
stubs_file= "trexio_stubs.c"
|
||||
ml_file = "trexio.ml"
|
||||
mli_file = ml_file+"i"
|
||||
|
||||
def write_stubs(data):
|
||||
|
||||
with open("src/"+stubs_file,'r') as f:
|
||||
content = f.readlines()
|
||||
index = -1
|
||||
for i, line in enumerate(content):
|
||||
if line.startswith("/**** ****/"):
|
||||
index = i
|
||||
break
|
||||
content_pre = ''.join(content[:index])
|
||||
content_post = ''.join(content[index:])
|
||||
|
||||
with open("lib/"+stubs_file,'w') as f:
|
||||
f.write(content_pre)
|
||||
|
||||
for group in data:
|
||||
t = """
|
||||
CAMLprim value caml_delete_{group}(value file)
|
||||
{
|
||||
CAMLparam1(file);
|
||||
trexio_exit_code rc = trexio_delete_{group}( File_val(file) );
|
||||
if (rc == TREXIO_SUCCESS) {
|
||||
CAMLreturn ( Val_unit );
|
||||
} else {
|
||||
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) )
|
||||
|
||||
for element in data[group]:
|
||||
t = """
|
||||
CAMLprim value caml_has_{group}_{element}(value file)
|
||||
{
|
||||
CAMLparam1(file);
|
||||
trexio_exit_code rc = trexio_has_{group}_{element}( File_val(file) );
|
||||
CAMLreturn ( Val_bool(rc == TREXIO_SUCCESS) );
|
||||
}
|
||||
"""
|
||||
f.write( t.replace("{group}", group)
|
||||
.replace("{element}", element) )
|
||||
|
||||
# Scalar elements
|
||||
if data[group][element][1] == []:
|
||||
|
||||
if data[group][element][0] in [ "int", "dim", "index" ]:
|
||||
t = """
|
||||
CAMLprim value caml_read_{group}_{element}(value file)
|
||||
{
|
||||
CAMLparam1(file);
|
||||
int64_t result;
|
||||
trexio_exit_code rc = trexio_read_{group}_{element}_64( File_val(file), &result );
|
||||
if (rc == TREXIO_SUCCESS) {
|
||||
CAMLreturn ( Val_int(result) );
|
||||
} else {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
}
|
||||
|
||||
CAMLprim value caml_write_{group}_{element}(value file, value data)
|
||||
{
|
||||
CAMLparam2(file, data);
|
||||
trexio_exit_code rc = trexio_write_{group}_{element}_64( File_val(file), (int64_t) Int_val(data) );
|
||||
if (rc == TREXIO_SUCCESS) {
|
||||
CAMLreturn ( Val_unit );
|
||||
} else {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
}
|
||||
"""
|
||||
f.write( t.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", data[group][element][0]) )
|
||||
|
||||
elif data[group][element][0] in [ "float" ]:
|
||||
t = """
|
||||
CAMLprim value caml_read_{group}_{element}(value file)
|
||||
{
|
||||
CAMLparam1(file);
|
||||
double result;
|
||||
trexio_exit_code rc = trexio_read_{group}_{element}_64( File_val(file), &result );
|
||||
if (rc == TREXIO_SUCCESS) {
|
||||
CAMLreturn ( caml_copy_double(result) );
|
||||
} else {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
}
|
||||
|
||||
CAMLprim value caml_write_{group}_{element}(value file, value data)
|
||||
{
|
||||
CAMLparam2(file, data);
|
||||
trexio_exit_code rc = trexio_write_{group}_{element}_64( File_val(file), (double) Double_val(data) );
|
||||
if (rc == TREXIO_SUCCESS) {
|
||||
CAMLreturn ( Val_unit );
|
||||
} else {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
}
|
||||
"""
|
||||
f.write( t.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", data[group][element][0]) )
|
||||
|
||||
elif data[group][element][0] in [ "string" ]:
|
||||
t = """
|
||||
CAMLprim value caml_read_{group}_{element}(value file, value max_str_len_in)
|
||||
{
|
||||
CAMLparam2(file, max_str_len_in);
|
||||
int32_t max_str_len = Int_val(max_str_len_in);
|
||||
char result[max_str_len];
|
||||
trexio_exit_code rc = trexio_read_{group}_{element}( File_val(file), result, max_str_len);
|
||||
if (rc == TREXIO_SUCCESS) {
|
||||
CAMLreturn ( caml_copy_string(result) );
|
||||
} else {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
}
|
||||
|
||||
CAMLprim value caml_write_{group}_{element}(value file, value data)
|
||||
{
|
||||
CAMLparam2(file, data);
|
||||
const char* val = String_val(data);
|
||||
trexio_exit_code rc = trexio_write_{group}_{element}( File_val(file), val, (int32_t) strlen(val));
|
||||
if (rc == TREXIO_SUCCESS) {
|
||||
CAMLreturn ( Val_unit );
|
||||
} else {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
}
|
||||
"""
|
||||
f.write( t.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", data[group][element][0]) )
|
||||
|
||||
if data[group][element][0] in [ "dim readonly" ]:
|
||||
t = """
|
||||
CAMLprim value caml_read_{group}_{element}(value file)
|
||||
{
|
||||
CAMLparam1(file);
|
||||
int64_t result;
|
||||
trexio_exit_code rc = trexio_read_{group}_{element}_64( File_val(file), &result );
|
||||
if (rc == TREXIO_SUCCESS) {
|
||||
CAMLreturn ( Val_int(result) );
|
||||
} else {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
f.write( t.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", data[group][element][0].split()[0]) )
|
||||
|
||||
# Array elements
|
||||
else:
|
||||
|
||||
if data[group][element][0] in [ "float" ]:
|
||||
t = """
|
||||
CAMLprim value caml_read_safe_{group}_{element}(value file_in, value size_max_in)
|
||||
{
|
||||
CAMLparam2 ( file_in, size_max_in );
|
||||
CAMLlocal1 ( result );
|
||||
|
||||
trexio_t* file = File_val( file_in );
|
||||
int64_t size_max = (int64_t) Int_val(size_max_in);
|
||||
|
||||
double* read_data = (double*) malloc (size_max * sizeof(double));
|
||||
trexio_exit_code rc = trexio_read_safe_{group}_{element}_64(file, read_data, size_max);
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
|
||||
result = caml_alloc(size_max * Double_wosize, Double_array_tag);
|
||||
for (size_t i=0 ; i<size_max ; ++i) {
|
||||
Store_double_field( result, i, read_data[i] );
|
||||
}
|
||||
free(read_data);
|
||||
|
||||
CAMLreturn (result);
|
||||
}
|
||||
|
||||
CAMLprim value caml_write_safe_{group}_{element}(value file_in, value size_max_in, value array)
|
||||
{
|
||||
CAMLparam3 ( file_in, size_max_in, array );
|
||||
|
||||
trexio_t* file = File_val( file_in );
|
||||
int64_t size_max = (int64_t) Int_val(size_max_in);
|
||||
|
||||
double* c_array = (double*) malloc (size_max * sizeof(double));
|
||||
for (size_t i=0 ; i<size_max ; ++i) {
|
||||
c_array[i] = Double_field(array, i);
|
||||
}
|
||||
|
||||
trexio_exit_code rc = trexio_write_safe_{group}_{element}_64(file, c_array, size_max);
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
free(c_array);
|
||||
|
||||
CAMLreturn ( Val_unit );
|
||||
}
|
||||
|
||||
"""
|
||||
f.write( t.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", data[group][element][0]) )
|
||||
|
||||
elif data[group][element][0] in [ "int", "index", "dim" ]:
|
||||
t = """
|
||||
CAMLprim value caml_read_safe_{group}_{element}(value file_in, value size_max_in)
|
||||
{
|
||||
CAMLparam2 ( file_in, size_max_in );
|
||||
CAMLlocal1 ( result );
|
||||
|
||||
trexio_t* file = File_val( file_in );
|
||||
int64_t size_max = (int64_t) Int_val(size_max_in);
|
||||
|
||||
int64_t* read_data = (int64_t*) malloc (size_max * sizeof(int64_t));
|
||||
trexio_exit_code rc = trexio_read_safe_{group}_{element}_64(file, read_data, size_max);
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
|
||||
result = caml_alloc(size_max, 0);
|
||||
for (size_t i=0 ; i<size_max ; ++i) {
|
||||
Store_field( result, i, Val_int(read_data[i]) );
|
||||
}
|
||||
free(read_data);
|
||||
|
||||
CAMLreturn (result);
|
||||
}
|
||||
|
||||
CAMLprim value caml_write_safe_{group}_{element}(value file_in, value size_max_in, value array)
|
||||
{
|
||||
CAMLparam3 ( file_in, size_max_in, array );
|
||||
|
||||
trexio_t* file = File_val( file_in );
|
||||
int64_t size_max = (int64_t) Int_val(size_max_in);
|
||||
|
||||
int64_t* c_array = (int64_t*) malloc (size_max * sizeof(int64_t));
|
||||
for (size_t i=0 ; i<size_max ; ++i) {
|
||||
c_array[i] = Int_val( Field(array, i) );
|
||||
}
|
||||
|
||||
trexio_exit_code rc = trexio_write_safe_{group}_{element}_64(file, c_array, size_max);
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
free(c_array);
|
||||
|
||||
CAMLreturn ( Val_unit );
|
||||
}
|
||||
|
||||
"""
|
||||
f.write( t.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", data[group][element][0]) )
|
||||
|
||||
elif data[group][element][0] in [ "string" ]:
|
||||
t = """
|
||||
CAMLprim value caml_read_safe_{group}_{element}(value file_in, value size_max_in, value max_str_len_in)
|
||||
{
|
||||
CAMLparam3 ( file_in, size_max_in, max_str_len_in );
|
||||
CAMLlocal1 ( result );
|
||||
|
||||
trexio_t* file = File_val( file_in );
|
||||
int64_t size_max = (int64_t) Int_val(size_max_in);
|
||||
int32_t max_str_len = Int_val(max_str_len_in);
|
||||
|
||||
char** read_data = (char**) malloc (size_max * sizeof(char*));
|
||||
read_data[0] = (char*) malloc (size_max * (int64_t) (max_str_len+1) * sizeof(char));
|
||||
for (size_t i=1 ; i<size_max ; ++i) {
|
||||
read_data[i] = read_data[i-1] + max_str_len+1;
|
||||
}
|
||||
trexio_exit_code rc = trexio_read_{group}_{element}(file, read_data, max_str_len);
|
||||
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
|
||||
result = caml_alloc(size_max, 0);
|
||||
for (size_t i=0 ; i<size_max ; ++i) {
|
||||
Store_field( result, i, caml_copy_string(read_data[i]) );
|
||||
}
|
||||
|
||||
free(read_data[0]);
|
||||
free(read_data);
|
||||
|
||||
CAMLreturn (result);
|
||||
|
||||
}
|
||||
|
||||
CAMLprim value caml_write_safe_{group}_{element}(value file_in, value size_max_in, value max_str_len_in, value array)
|
||||
{
|
||||
CAMLparam4 ( file_in, size_max_in, max_str_len_in, array );
|
||||
|
||||
trexio_t* file = File_val( file_in );
|
||||
int64_t size_max = (int64_t) Int_val(size_max_in);
|
||||
int32_t max_str_len = Int_val(max_str_len_in);
|
||||
|
||||
char** c_array = (char**) malloc (size_max * sizeof(char*));
|
||||
c_array[0] = (char*) malloc (size_max * (max_str_len+1) * sizeof(char*));
|
||||
for (size_t i=1 ; i<size_max ; ++i) {
|
||||
c_array[i] = c_array[i-1] + max_str_len+1;
|
||||
}
|
||||
for (size_t i=0 ; i<size_max ; ++i) {
|
||||
strcpy(c_array[i], String_val( Field(array, i) ));
|
||||
}
|
||||
|
||||
printf("%d\\n", max_str_len);
|
||||
fprintf(stderr,"%d\\n", max_str_len);
|
||||
trexio_exit_code rc = trexio_write_{group}_{element}(file, (const char**) c_array, max_str_len);
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
free(c_array[0]);
|
||||
free(c_array);
|
||||
|
||||
CAMLreturn ( Val_unit );
|
||||
}
|
||||
|
||||
"""
|
||||
f.write( t.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", data[group][element][0]) )
|
||||
|
||||
if data[group][element][0] in [ "float sparse" ]:
|
||||
size = len(data[group][element][1])
|
||||
t = """
|
||||
CAMLprim value caml_read_{group}_{element}(value file_in, value offset_in, value buffer_size_in)
|
||||
{
|
||||
CAMLparam3 ( file_in, offset_in, buffer_size_in );
|
||||
CAMLlocal2 ( result, data );
|
||||
|
||||
trexio_t* file = File_val( file_in );
|
||||
int64_t offset = Int_val( offset_in );
|
||||
int64_t buffer_size = Int_val( buffer_size_in );
|
||||
|
||||
int64_t size_max = buffer_size;
|
||||
int32_t* index_sparse_read = (int32_t*) malloc ({size}*size_max*sizeof(int32_t));
|
||||
double* value_sparse_read = (double*) malloc (size_max*sizeof(double));
|
||||
|
||||
trexio_exit_code rc = trexio_read_safe_{group}_{element}(file, offset, &buffer_size,
|
||||
index_sparse_read, size_max,
|
||||
value_sparse_read, size_max);
|
||||
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
|
||||
result = caml_alloc(buffer_size, 0);
|
||||
for (size_t i=0 ; i<buffer_size ; ++i) {
|
||||
data = caml_alloc_tuple({size}+1);
|
||||
for (int j=0 ; j<{size} ; ++j) {
|
||||
Store_field(data, j, Val_int( index_sparse_read[{size}*i+j] ));
|
||||
}
|
||||
Store_field(data, {size}, caml_copy_double( value_sparse_read[i] ));
|
||||
Store_field(result, i, data);
|
||||
}
|
||||
|
||||
free(index_sparse_read);
|
||||
free(value_sparse_read);
|
||||
|
||||
CAMLreturn(result);
|
||||
|
||||
}
|
||||
|
||||
|
||||
CAMLprim value caml_write_{group}_{element}(value file_in, value offset_in, value buffer_in)
|
||||
{
|
||||
CAMLparam3 ( file_in, offset_in, buffer_in );
|
||||
CAMLlocal1 ( data );
|
||||
|
||||
trexio_t* file = File_val( file_in );
|
||||
int64_t offset = Int_val( offset_in );
|
||||
int64_t buffer_size = Wosize_val( buffer_in );
|
||||
const int64_t size_max = buffer_size;
|
||||
|
||||
int32_t* index_sparse_write = (int32_t*) malloc ({size}*size_max*sizeof(int32_t));
|
||||
double* value_sparse_write = (double*) malloc (size_max*sizeof(double));
|
||||
|
||||
for (size_t i=0 ; i<buffer_size ; ++i) {
|
||||
|
||||
data = Field(buffer_in, i);
|
||||
for (int j=0 ; j<{size} ; ++j) {
|
||||
index_sparse_write[{size}*i+j] = Int_val( Field(data, j) );
|
||||
}
|
||||
value_sparse_write[i] = Double_val( Field(data, {size}) );
|
||||
}
|
||||
|
||||
trexio_exit_code rc = trexio_write_safe_{group}_{element}(file, offset, buffer_size,
|
||||
index_sparse_write, size_max,
|
||||
value_sparse_write, size_max);
|
||||
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
|
||||
free(index_sparse_write);
|
||||
free(value_sparse_write);
|
||||
|
||||
CAMLreturn( Val_unit );
|
||||
|
||||
}
|
||||
|
||||
|
||||
"""
|
||||
f.write( t.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{size}", str(size))
|
||||
.replace("{type}", data[group][element][0]) )
|
||||
|
||||
f.write(content_post)
|
||||
|
||||
def write_mli(data):
|
||||
|
||||
with open("src/"+mli_file,'r') as f:
|
||||
content = f.readlines()
|
||||
index = -1
|
||||
for i, line in enumerate(content):
|
||||
if line.startswith("(**** ****)"):
|
||||
index = i
|
||||
break
|
||||
content_pre = ''.join(content[:index])
|
||||
content_post = ''.join(content[index:])
|
||||
|
||||
with open("lib/"+mli_file,'w') as f:
|
||||
f.write(content_pre)
|
||||
|
||||
for group in data:
|
||||
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]:
|
||||
t = "val has_{group}_{element}: trexio_file -> bool\n"
|
||||
f.write( t.replace("{group}", group)
|
||||
.replace("{element}", element) )
|
||||
|
||||
# Scalar elements
|
||||
if data[group][element][1] == []:
|
||||
|
||||
if data[group][element][0] in [ "int", "float", "dim", "index" ]:
|
||||
t = [ "val read_{group}_{element} : trexio_file -> {type}\n" ,
|
||||
"val write_{group}_{element}: trexio_file -> {type} -> unit\n" ]
|
||||
for i in t:
|
||||
f.write( i.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", data[group][element][0]) )
|
||||
|
||||
elif data[group][element][0] in [ "string" ]:
|
||||
t = [ "val read_{group}_{element} : ?max_str_len:int -> trexio_file -> {type}\n" ,
|
||||
"val write_{group}_{element}: trexio_file -> {type} -> unit\n" ]
|
||||
for i in t:
|
||||
f.write( i.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", data[group][element][0]) )
|
||||
|
||||
elif data[group][element][0] in [ "dim readonly" ]:
|
||||
t = [ "val read_{group}_{element} : trexio_file -> {type}\n" ]
|
||||
for i in t:
|
||||
f.write( i.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", data[group][element][0].split()[0]) )
|
||||
|
||||
# Arrays
|
||||
else:
|
||||
|
||||
if data[group][element][0] in [ "int", "float", "dim", "index" ]:
|
||||
t = [ "val read_safe_{group}_{element} : trexio_file -> int -> {type} array\n" ,
|
||||
"val write_safe_{group}_{element}: trexio_file -> int -> {type} array -> unit\n"
|
||||
"val read_{group}_{element} : trexio_file -> {type} array\n" ,
|
||||
"val write_{group}_{element}: trexio_file -> {type} array -> unit\n"
|
||||
]
|
||||
for i in t:
|
||||
f.write( i.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", data[group][element][0]) )
|
||||
|
||||
elif data[group][element][0] in [ "string" ]:
|
||||
t = [ "val read_safe_{group}_{element} : trexio_file -> int -> int -> {type} array\n" ,
|
||||
"val write_safe_{group}_{element}: trexio_file -> int -> int -> {type} array -> unit\n"
|
||||
"val read_{group}_{element} : ?max_str_len:int -> trexio_file -> {type} array\n" ,
|
||||
"val write_{group}_{element}: trexio_file -> {type} array -> unit\n"
|
||||
]
|
||||
for i in t:
|
||||
f.write( i.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", data[group][element][0]) )
|
||||
|
||||
elif data[group][element][0] in [ "float sparse" ]:
|
||||
size = len(data[group][element][1])
|
||||
typ = "(" + "*".join( [ "int" for _ in range(size) ]) + " * float) array"
|
||||
t = [ "val read_{group}_{element} : trexio_file -> offset:dim -> buffer_size:dim -> {type}\n" ,
|
||||
"val write_{group}_{element} : trexio_file -> offset:dim -> {type} -> unit\n" ,
|
||||
]
|
||||
for i in t:
|
||||
f.write( i.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", typ) )
|
||||
|
||||
f.write(content_post)
|
||||
|
||||
|
||||
def write_ml(data):
|
||||
|
||||
with open("src/"+ml_file,'r') as f:
|
||||
content = f.readlines()
|
||||
index = -1
|
||||
for i, line in enumerate(content):
|
||||
if line.startswith("(**** ****)"):
|
||||
index = i
|
||||
break
|
||||
content_pre = ''.join(content[:index])
|
||||
content_post = ''.join(content[index:])
|
||||
|
||||
with open("lib/"+ml_file,'w') as f:
|
||||
f.write(content_pre)
|
||||
|
||||
for group in data:
|
||||
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]:
|
||||
t = "external has_{group}_{element}: trexio_file -> bool = \"caml_has_{group}_{element}\"\n"
|
||||
f.write( t.replace("{group}", group)
|
||||
.replace("{element}", element) )
|
||||
|
||||
# Scalar elements
|
||||
if data[group][element][1] == []:
|
||||
|
||||
if data[group][element][0] in [ "int", "float", "dim", "index" ]:
|
||||
t = [ "external read_{group}_{element} : trexio_file -> {type} = \"caml_read_{group}_{element}\"\n" ,
|
||||
"external write_{group}_{element}: trexio_file -> {type} -> unit = \"caml_write_{group}_{element}\"\n" ]
|
||||
for i in t:
|
||||
f.write( i.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", data[group][element][0]) )
|
||||
|
||||
if data[group][element][0] in [ "string" ]:
|
||||
t = [ "external read_{group}_{element}_c : trexio_file -> int -> {type} = \"caml_read_{group}_{element}\"\n" ,
|
||||
"let read_{group}_{element} ?(max_str_len=8192) f = read_{group}_{element}_c f max_str_len\n",
|
||||
"external write_{group}_{element}: trexio_file -> {type} -> unit = \"caml_write_{group}_{element}\"\n" ]
|
||||
for i in t:
|
||||
f.write( i.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", data[group][element][0]) )
|
||||
|
||||
elif data[group][element][0] in [ "dim readonly" ]:
|
||||
t = [ "external read_{group}_{element} : trexio_file -> {type} = \"caml_read_{group}_{element}\"\n" ]
|
||||
for i in t:
|
||||
f.write( i.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", data[group][element][0].split()[0]) )
|
||||
|
||||
# Arrays
|
||||
else:
|
||||
|
||||
if data[group][element][0] in [ "int", "float", "dim", "index" ]:
|
||||
t = [ "external read_safe_{group}_{element} : trexio_file -> int -> {type} array = \"caml_read_safe_{group}_{element}\"\n" ,
|
||||
"external write_safe_{group}_{element}: trexio_file -> int -> {type} array -> unit = \"caml_write_safe_{group}_{element}\"\n",
|
||||
"let read_{group}_{element} f = \n let size = 1 in \n"]
|
||||
t_prime = []
|
||||
for dim in data[group][element][1]:
|
||||
try: # A dimensioning variable
|
||||
dim_group, dim_element = dim.split('.')
|
||||
t_prime += [f" let size = size * read_{dim_group}_{dim_element} f in\n"]
|
||||
except: # Only an integer
|
||||
t_prime += [f" let size = size * {dim} in\n"]
|
||||
|
||||
t += t_prime
|
||||
t += [ " read_safe_{group}_{element} f size\n\n" ]
|
||||
t += [ "let write_{group}_{element} f a = \n let size = 1 in \n"]
|
||||
t += t_prime
|
||||
t += [ " write_safe_{group}_{element} f size a\n\n" ]
|
||||
for i in t:
|
||||
f.write( i.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", data[group][element][0]) )
|
||||
|
||||
elif data[group][element][0] in [ "string" ]:
|
||||
t = [ "external read_safe_{group}_{element} : trexio_file -> int -> int -> {type} array = \"caml_read_safe_{group}_{element}\"\n" ,
|
||||
"external write_safe_{group}_{element}: trexio_file -> int -> int -> {type} array -> unit = \"caml_write_safe_{group}_{element}\"\n",
|
||||
"let read_{group}_{element} ?(max_str_len=1024) f = \n let size = 1 in \n"]
|
||||
t_prime = []
|
||||
for dim in data[group][element][1]:
|
||||
try: # A dimensioning variable
|
||||
dim_group, dim_element = dim.split('.')
|
||||
t_prime += [f" let size = size * read_{dim_group}_{dim_element} f in\n"]
|
||||
except: # Only an integer
|
||||
t_prime += [f" let size = size * {dim} in\n"]
|
||||
|
||||
t += t_prime
|
||||
t += [ " read_safe_{group}_{element} f size max_str_len\n\n" ,
|
||||
"let write_{group}_{element} f a = \n let size = 1 in \n",
|
||||
" let max_str_len = Array.map String.length a\n" ,
|
||||
" |> Array.fold_left (fun x y -> if x>y then x else y) 0\n",
|
||||
" |> (+) 1 in\n" ]
|
||||
t += t_prime
|
||||
t += [ " write_safe_{group}_{element} f size max_str_len a\n\n" ]
|
||||
for i in t:
|
||||
f.write( i.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", data[group][element][0]) )
|
||||
|
||||
|
||||
elif data[group][element][0] in [ "float sparse" ]:
|
||||
size = len(data[group][element][1])
|
||||
typ = "(" + "*".join( [ "int" for _ in range(size) ]) + " * float) array"
|
||||
t = [ "external read_{group}_{element} : trexio_file -> offset:dim -> buffer_size:dim -> {type} = \"caml_read_{group}_{element}\"\n" ,
|
||||
"external write_{group}_{element} : trexio_file -> offset:dim -> {type} -> unit = \"caml_write_{group}_{element}\"\n"
|
||||
]
|
||||
for i in t:
|
||||
f.write( i.replace("{group}", group)
|
||||
.replace("{element}", element)
|
||||
.replace("{type}", typ) )
|
||||
|
||||
f.write(content_post)
|
||||
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
with open(json_file,'r') as f:
|
||||
data = json.load(f)
|
||||
for group in data:
|
||||
for element in data[group]:
|
||||
if data[group][element][0] == "str":
|
||||
data[group][element][0] = "string"
|
||||
|
||||
write_ml(data)
|
||||
write_mli(data)
|
||||
write_stubs(data)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
37
ocaml/trexio/src/trexio.ml
Normal file
37
ocaml/trexio/src/trexio.ml
Normal file
@ -0,0 +1,37 @@
|
||||
|
||||
type trexio_file
|
||||
|
||||
type trexio_exit_code = int
|
||||
|
||||
type trexio_backend =
|
||||
| HDF5
|
||||
| TEXT
|
||||
| AUTO
|
||||
|
||||
type index = int
|
||||
type dim = int
|
||||
|
||||
external open_file : string -> char -> trexio_backend -> trexio_file = "caml_open_file"
|
||||
external close_file : trexio_file -> unit = "caml_close_file"
|
||||
external inquire_file : string -> bool = "caml_inquire_file"
|
||||
external set_one_based : trexio_file -> unit = "caml_set_one_based"
|
||||
external get_state : trexio_file -> int = "caml_get_state"
|
||||
external set_state : trexio_file -> int -> unit = "caml_set_state"
|
||||
external info : unit -> unit = "caml_info"
|
||||
|
||||
external to_orbital_list : Int64.t array -> int list = "caml_to_orbital_list"
|
||||
|
||||
|
||||
(**** ****)
|
||||
|
||||
external read_determinant_list : trexio_file -> offset:int -> buffer_size:int -> (bytes * bytes) array = "caml_read_determinant_list"
|
||||
external write_determinant_list : trexio_file -> offset:int -> (bytes * bytes) array -> unit = "caml_write_determinant_list"
|
||||
|
||||
external read_determinant_coefficient : trexio_file -> offset:int -> buffer_size:int -> float array = "caml_read_determinant_coefficient"
|
||||
external write_determinant_coefficient : trexio_file -> offset:int -> float array -> unit = "caml_write_determinant_coefficient"
|
||||
|
||||
|
||||
let to_orbital_list_up_dn (up,dn) =
|
||||
(to_orbital_list up, to_orbital_list dn)
|
||||
|
||||
|
41
ocaml/trexio/src/trexio.mli
Normal file
41
ocaml/trexio/src/trexio.mli
Normal file
@ -0,0 +1,41 @@
|
||||
(*
|
||||
(** Constants *)
|
||||
val package_version : string
|
||||
val version_major : int
|
||||
val version_minor : int
|
||||
val version_patch : int
|
||||
val git_hash : string
|
||||
*)
|
||||
|
||||
(** Open/close *)
|
||||
|
||||
type trexio_file
|
||||
type trexio_exit_code
|
||||
type trexio_backend =
|
||||
| HDF5
|
||||
| TEXT
|
||||
| AUTO
|
||||
|
||||
type index = int
|
||||
type dim = int
|
||||
|
||||
val open_file : string -> char -> trexio_backend -> trexio_file
|
||||
val inquire_file : string -> bool
|
||||
val close_file : trexio_file -> unit
|
||||
val set_one_based : trexio_file -> unit
|
||||
val get_state : trexio_file -> int
|
||||
val set_state : trexio_file -> int -> unit
|
||||
val info : unit -> unit
|
||||
|
||||
val to_orbital_list : Int64.t array -> int list
|
||||
val to_orbital_list_up_dn : (Int64.t array)*(Int64.t array) -> (int list)*(int list)
|
||||
|
||||
(**** ****)
|
||||
|
||||
val read_determinant_list : trexio_file -> offset:int -> buffer_size:int -> (bytes * bytes) array
|
||||
val write_determinant_list : trexio_file -> offset:int -> (bytes * bytes) array -> unit
|
||||
|
||||
val read_determinant_coefficient : trexio_file -> offset:int -> buffer_size:int -> float array
|
||||
val write_determinant_coefficient : trexio_file -> offset:int -> float array -> unit
|
||||
|
||||
|
268
ocaml/trexio/src/trexio_stubs.c
Normal file
268
ocaml/trexio/src/trexio_stubs.c
Normal file
@ -0,0 +1,268 @@
|
||||
#include <stdio.h>
|
||||
#include <trexio.h>
|
||||
#include <string.h>
|
||||
#define CAML_NAME_SPACE
|
||||
#include <caml/alloc.h>
|
||||
#include <caml/custom.h>
|
||||
#include <caml/mlvalues.h>
|
||||
#include <caml/memory.h>
|
||||
#include <caml/fail.h>
|
||||
#include <caml/misc.h>
|
||||
|
||||
static trexio_t* File_val( value file )
|
||||
{
|
||||
return *((trexio_t**) Data_abstract_val(file));
|
||||
}
|
||||
|
||||
|
||||
CAMLprim value caml_open_file(value filename, value mode, value backend)
|
||||
{
|
||||
CAMLparam3(filename, mode, backend);
|
||||
|
||||
trexio_exit_code rc = 0;
|
||||
value v = caml_alloc(1, Abstract_tag);
|
||||
|
||||
trexio_t* result = trexio_open (String_val(filename),
|
||||
Int_val(mode),
|
||||
Int_val(backend),
|
||||
&rc);
|
||||
|
||||
*((trexio_t **) Data_abstract_val(v)) = result;
|
||||
|
||||
if (rc == TREXIO_SUCCESS) {
|
||||
CAMLreturn( v );
|
||||
} else {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CAMLprim value caml_close_file(value file)
|
||||
{
|
||||
CAMLparam1(file);
|
||||
trexio_exit_code rc = trexio_close( File_val(file) );
|
||||
if (rc == TREXIO_SUCCESS) {
|
||||
CAMLreturn ( Val_unit );
|
||||
} else {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CAMLprim value caml_inquire_file(value filename)
|
||||
{
|
||||
CAMLparam1 (filename);
|
||||
trexio_exit_code rc = trexio_inquire( String_val (filename) );
|
||||
CAMLreturn(Val_bool(rc == TREXIO_SUCCESS));
|
||||
}
|
||||
|
||||
|
||||
CAMLprim value caml_set_one_based(value file)
|
||||
{
|
||||
CAMLparam1(file);
|
||||
trexio_exit_code rc = trexio_set_one_based( File_val(file) );
|
||||
if (rc == TREXIO_SUCCESS) {
|
||||
CAMLreturn ( Val_unit );
|
||||
} else {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CAMLprim value caml_set_state(value file, value state)
|
||||
{
|
||||
CAMLparam2(file, state);
|
||||
printf("%d\n", Int_val(state));
|
||||
trexio_exit_code rc = trexio_set_state( File_val(file), (int32_t) Int_val(state) );
|
||||
if (rc == TREXIO_SUCCESS) {
|
||||
CAMLreturn ( Val_unit );
|
||||
} else {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CAMLprim value caml_get_state(value file)
|
||||
{
|
||||
CAMLparam1(file);
|
||||
int32_t result;
|
||||
trexio_exit_code rc = trexio_get_state( File_val(file), &result );
|
||||
if (rc == TREXIO_SUCCESS) {
|
||||
CAMLreturn ( Val_int(result) );
|
||||
} else {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CAMLprim value caml_info(value unit)
|
||||
{
|
||||
CAMLparam1(unit);
|
||||
trexio_exit_code rc = trexio_info();
|
||||
if (rc == TREXIO_SUCCESS) {
|
||||
CAMLreturn ( Val_unit );
|
||||
} else {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CAMLprim value caml_to_orbital_list(value bitfield)
|
||||
{
|
||||
CAMLparam1 ( bitfield );
|
||||
CAMLlocal2 ( result, cons );
|
||||
|
||||
int32_t N_int = Wosize_val(bitfield);
|
||||
bitfield_t* d1 = (bitfield_t*) malloc (N_int * sizeof(bitfield_t));
|
||||
for (int i=0 ; i<N_int ; ++i) {
|
||||
d1[i] = Int64_val(Field(bitfield,i));
|
||||
}
|
||||
|
||||
int32_t* list = (int32_t*) malloc(N_int * sizeof(bitfield_t) * sizeof(int32_t));
|
||||
int32_t occupied_num = 0;
|
||||
|
||||
trexio_exit_code rc = trexio_to_orbital_list (N_int, d1, list, &occupied_num);
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
|
||||
free(d1);
|
||||
|
||||
result = Val_emptylist;
|
||||
for (int i=occupied_num-1 ; i >= 0 ; --i) {
|
||||
cons = caml_alloc(2, 0);
|
||||
Store_field(cons, 0, Val_int(list[i])); // head
|
||||
Store_field(cons, 1, result); // head
|
||||
result = cons;
|
||||
}
|
||||
|
||||
free(list);
|
||||
CAMLreturn(result);
|
||||
}
|
||||
|
||||
|
||||
/**** ****/
|
||||
|
||||
CAMLprim value caml_read_determinant_list(value file_in, value offset_in, value buffer_size_in)
|
||||
{
|
||||
CAMLparam3 ( file_in, offset_in, buffer_size_in );
|
||||
CAMLlocal4 ( result, detup, detdn, det );
|
||||
|
||||
trexio_t* file = File_val(file_in);
|
||||
int64_t offset = Int_val( offset_in );
|
||||
int64_t buffer_size = Int_val( buffer_size_in );
|
||||
|
||||
int32_t int_num = 0;
|
||||
trexio_exit_code rc = trexio_get_int64_num(file, &int_num);
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
|
||||
int64_t* buffer = (int64_t*) malloc ( buffer_size * int_num * 2 * sizeof(int64_t) );
|
||||
|
||||
rc = trexio_read_determinant_list (file, offset, &buffer_size, buffer);
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
|
||||
result = caml_alloc(buffer_size, 0);
|
||||
size_t icount = 0;
|
||||
for (size_t i=0 ; i<buffer_size ; ++i) {
|
||||
detup = caml_alloc_initialized_string(int_num*sizeof(int64_t), (char*) &(buffer[icount]));
|
||||
icount += int_num;
|
||||
detdn = caml_alloc_initialized_string(int_num*sizeof(int64_t), (char*) &(buffer[icount]));
|
||||
icount += int_num;
|
||||
det = caml_alloc_tuple(2);
|
||||
Store_field( det, 0, detup );
|
||||
Store_field( det, 1, detdn );
|
||||
Store_field( result, i, det );
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
CAMLreturn(result);
|
||||
}
|
||||
|
||||
CAMLprim value caml_write_determinant_list(value file_in, value offset_in, value array)
|
||||
{
|
||||
CAMLparam3 ( file_in, offset_in, array );
|
||||
CAMLlocal3 ( detup, detdn, det );
|
||||
|
||||
trexio_t* file = File_val(file_in);
|
||||
int64_t offset = Int_val( offset_in );
|
||||
int64_t buffer_size = Wosize_val( array );
|
||||
|
||||
int32_t int_num = 0;
|
||||
trexio_exit_code rc = trexio_get_int64_num(file, &int_num);
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
|
||||
int64_t* buffer = (int64_t*) malloc ( buffer_size * int_num * 2 * sizeof(int64_t) );
|
||||
|
||||
for (size_t i=0 ; i<buffer_size ; ++i) {
|
||||
det = Field(array, i);
|
||||
detup = Field(det, 0);
|
||||
detdn = Field(det, 1);
|
||||
memcpy(&(buffer[i*int_num*2]), String_val(detup), int_num*sizeof(int64_t));
|
||||
memcpy(&(buffer[i*int_num*2 + int_num]), String_val(detdn), int_num*sizeof(int64_t));
|
||||
}
|
||||
|
||||
rc = trexio_write_determinant_list (file, offset, buffer_size, buffer);
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
CAMLreturn( Val_unit );
|
||||
}
|
||||
|
||||
CAMLprim value caml_read_determinant_coefficient(value file_in, value offset_in, value buffer_size_in)
|
||||
{
|
||||
CAMLparam3 ( file_in, offset_in, buffer_size_in );
|
||||
CAMLlocal1 ( result );
|
||||
|
||||
trexio_t* file = File_val(file_in);
|
||||
int64_t offset = Int_val( offset_in );
|
||||
int64_t buffer_size = Int_val( buffer_size_in );
|
||||
|
||||
double* buffer = (double*) malloc ( buffer_size * sizeof(double) );
|
||||
|
||||
trexio_exit_code rc = trexio_read_determinant_coefficient (file, offset, &buffer_size, buffer);
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
|
||||
result = caml_alloc(buffer_size * Double_wosize, Double_array_tag);
|
||||
for (size_t i=0 ; i<buffer_size ; ++i) {
|
||||
Store_double_field( result, i, buffer[i]);
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
CAMLreturn(result);
|
||||
}
|
||||
|
||||
|
||||
CAMLprim value caml_write_determinant_coefficient(value file_in, value offset_in, value array)
|
||||
{
|
||||
CAMLparam3 ( file_in, offset_in, array );
|
||||
|
||||
trexio_t* file = File_val(file_in);
|
||||
int64_t offset = Int_val( offset_in );
|
||||
int64_t buffer_size = Wosize_val( array );
|
||||
|
||||
double* buffer = (double*) malloc ( buffer_size * sizeof(double) );
|
||||
|
||||
for (size_t i=0 ; i<buffer_size ; ++i) {
|
||||
buffer[i] = Double_field(array, i);
|
||||
}
|
||||
|
||||
trexio_exit_code rc = trexio_write_determinant_coefficient (file, offset, buffer_size, buffer);
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
caml_failwith(trexio_string_of_error(rc));
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
CAMLreturn( Val_unit );
|
||||
}
|
||||
|
||||
|
@ -1 +1 @@
|
||||
__version__ = "1.2.0"
|
||||
__version__ = "1.3.0"
|
||||
|
@ -94,6 +94,7 @@ pytrexio_module = Extension('pytrexio._pytrexio',
|
||||
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'
|
||||
|
@ -43,4 +43,7 @@ dets = [i for i in range(det_num * int64_num * 2)]
|
||||
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]
|
||||
det_test = [1, 2, 3, 2, 1, 3]
|
||||
|
||||
orb_up_test = [0, 65, 128, 129]
|
||||
orb_dn_test = [1, 64, 128, 129]
|
||||
|
@ -35,10 +35,21 @@ 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
|
||||
|
||||
|
||||
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."""
|
||||
|
||||
@ -64,7 +75,7 @@ class TestIO:
|
||||
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 +84,7 @@ class TestIO:
|
||||
|
||||
self.test_file = trexio.File(filename, mode, back_end)
|
||||
assert self.test_file.exists
|
||||
|
||||
|
||||
|
||||
def test_close(self):
|
||||
"""Close the file."""
|
||||
@ -82,7 +93,7 @@ class TestIO:
|
||||
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 +114,7 @@ class TestIO:
|
||||
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 +144,7 @@ class TestIO:
|
||||
"""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 +203,21 @@ class TestIO:
|
||||
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 +336,6 @@ class TestIO:
|
||||
|
||||
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
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
@ -1755,6 +1833,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 +4094,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$):
|
||||
@ -5189,6 +5359,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
|
||||
@ -5197,16 +5370,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,
|
||||
@ -5386,10 +5593,24 @@ 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
|
||||
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
|
||||
@ -5428,6 +5649,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.
|
||||
@ -5454,8 +5702,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.
|
||||
|
||||
@ -5539,6 +5789,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
|
||||
|
@ -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
|
||||
@ -179,6 +194,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
|
||||
|
@ -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
|
||||
|
@ -112,6 +112,23 @@ 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
|
||||
|
||||
#+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
|
||||
@ -127,7 +144,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;
|
||||
@ -268,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
|
||||
@ -404,13 +449,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, 32);
|
||||
tmp_$group_dset$ += tmp_$group_dset$_len + 1;
|
||||
}
|
||||
}
|
||||
@ -468,14 +514,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;
|
||||
@ -493,6 +540,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 +1151,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 +1638,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 +1725,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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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<int_num; i++) {
|
||||
assert (det_list_check[i] == det_list_read[2*int_num*5+i]);
|
||||
}
|
||||
|
||||
// close current session
|
||||
rc = trexio_close(file);
|
||||
@ -316,6 +324,7 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
||||
free(det_list_read);
|
||||
free(det_coef_read);
|
||||
free(det_coef_s2_read);
|
||||
free(det_list_check);
|
||||
free(orb_list_up);
|
||||
free(orb_list_dn);
|
||||
|
||||
|
@ -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<int_num; i++) {
|
||||
assert (det_list_check[i] == det_list_read[2*int_num*5+i]);
|
||||
}
|
||||
|
||||
// close current session
|
||||
rc = trexio_close(file);
|
||||
@ -316,6 +324,7 @@ static int test_read_determinant (const char* file_name, const back_end_t backen
|
||||
free(det_list_read);
|
||||
free(det_coef_read);
|
||||
free(det_coef_s2_read);
|
||||
free(det_list_check);
|
||||
free(orb_list_up);
|
||||
free(orb_list_dn);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<size_r; ++i){
|
||||
printf("%d %lf\n", index_read[4*i], value_read[i]);
|
||||
}
|
||||
*/
|
||||
|
||||
// close current session
|
||||
rc = trexio_close(file);
|
||||
|
@ -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);
|
||||
|
101
tests/test_f.f90
101
tests/test_f.f90
@ -6,11 +6,11 @@ program test_trexio
|
||||
integer :: rc
|
||||
logical :: have_hdf5
|
||||
|
||||
print * , "============================================"
|
||||
print'(a)' , "============================================"
|
||||
print'(a,a)' , " TREXIO VERSION STRING : ", TREXIO_PACKAGE_VERSION
|
||||
print'(a,i3)', " TREXIO MAJOR VERSION : ", TREXIO_VERSION_MAJOR
|
||||
print'(a,i3)', " TREXIO MINOR VERSION : ", TREXIO_VERSION_MINOR
|
||||
print * , "============================================"
|
||||
print'(a)' , "============================================"
|
||||
|
||||
rc = trexio_info()
|
||||
|
||||
@ -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)
|
||||
@ -143,6 +145,12 @@ subroutine test_write(file_name, back_end)
|
||||
rc = trexio_has_determinant_list(trex_file)
|
||||
call trexio_assert(rc, TREXIO_HAS_NOT, 'SUCCESS HAS NOT 4')
|
||||
|
||||
rc = trexio_has_nucleus(trex_file)
|
||||
call trexio_assert(rc, TREXIO_HAS_NOT, 'SUCCESS HAS NOT 5')
|
||||
|
||||
rc = trexio_has_ao_2e_int(trex_file)
|
||||
call trexio_assert(rc, TREXIO_HAS_NOT, 'SUCCESS HAS NOT 6')
|
||||
|
||||
rc = trexio_write_nucleus_num(trex_file, nucleus_num)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE NUM')
|
||||
|
||||
@ -177,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
|
||||
@ -190,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
|
||||
@ -207,6 +232,12 @@ subroutine test_write(file_name, back_end)
|
||||
rc = trexio_has_determinant_list(trex_file)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS HAS 4')
|
||||
|
||||
rc = trexio_has_nucleus(trex_file)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS HAS 5')
|
||||
|
||||
rc = trexio_has_ao_2e_int(trex_file)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS HAS 6')
|
||||
|
||||
rc = trexio_close(trex_file)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS CLOSE')
|
||||
|
||||
@ -240,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)
|
||||
@ -254,6 +288,7 @@ subroutine test_read(file_name, back_end)
|
||||
|
||||
! determinant data
|
||||
integer*8 :: det_list(6,50)
|
||||
integer*8 :: det_list_check(3)
|
||||
integer*8 :: read_buf_det_size = 20
|
||||
integer*8 :: offset_det_read = 10
|
||||
integer*8 :: offset_det_data_read = 5
|
||||
@ -315,9 +350,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'
|
||||
@ -346,8 +383,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
|
||||
@ -364,8 +401,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
|
||||
@ -403,7 +440,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
|
||||
@ -443,6 +480,46 @@ subroutine test_read(file_name, back_end)
|
||||
call exit(-1)
|
||||
endif
|
||||
|
||||
! convert one orbital list into a bitfield determinant representation
|
||||
rc = trexio_to_bitfield_list(orb_list_up, occ_num_up, det_list_check, 3)
|
||||
!write(*,*) occ_num_up, occ_num_dn
|
||||
! Print occupied orbitals for an up-spin component of a given determinant
|
||||
!write(*,*) orb_list_up(1:occ_num_up)
|
||||
! Print integers representanting a given determinant fully (up- and down-spin components)
|
||||
!write(*,*) det_list(1:3, offset_det_data_read+1)
|
||||
!write(*,*) det_list_check(1:3)
|
||||
! Print binary representation of the first integer bit field of a given determinant
|
||||
!write(*,'(B64.64)') det_list(1, offset_det_data_read+1)
|
||||
call trexio_assert(rc, TREXIO_SUCCESS)
|
||||
if (det_list_check(1) == det_list(1, offset_det_data_read+1) .and. &
|
||||
det_list_check(2) == det_list(2, offset_det_data_read+1) .and. &
|
||||
det_list_check(3) == det_list(3, offset_det_data_read+1)) then
|
||||
write(*,*) 'SUCCESS CONVERT ORB LIST'
|
||||
else
|
||||
print *, 'FAILURE ORB CONVERT CHECK'
|
||||
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)
|
||||
|
@ -65,7 +65,7 @@ for fname in files_todo['dset_sparse']:
|
||||
# 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:
|
||||
|
@ -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)
|
||||
|
@ -1,15 +1,15 @@
|
||||
(define-module (gnu packages trexio)
|
||||
(define-module (trexio)
|
||||
#:use-module (guix packages)
|
||||
#:use-module (gnu packages pkg-config)
|
||||
#: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,15 +20,48 @@
|
||||
".tar.gz"))
|
||||
(sha256
|
||||
(base32
|
||||
;; the hash below is produced by guix download <url>
|
||||
"1d2cn4w2r9gfid5b9wrq9q290kqdnbjdmvli76s1i5r58kdg5vkf"
|
||||
))))
|
||||
(build-system gnu-build-system)
|
||||
(arguments '(#:configure-flags '("--enable-silent-rules")))
|
||||
(inputs `(("hdf5" ,hdf5-1.12) ("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.")
|
||||
(inputs `(("hdf5" ,hdf5) ("gfortran", gfortran)))
|
||||
(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)))
|
||||
|
||||
(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 <url>
|
||||
"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 <url>
|
||||
"1n9n1gbk5hgvg73am991xrv7ap002rz719a3nvh8m8ff9x10qd76"
|
||||
))))))
|
||||
|
||||
(define-public trexio
|
||||
;; Default version of TREXIO.
|
||||
trexio-2.2)
|
||||
|
||||
trexio
|
||||
|
231
trex.org
231
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
|
||||
{
|
||||
@ -68,19 +70,19 @@ the [[./examples.html][examples]].
|
||||
|
||||
#+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)
|
||||
|
||||
@ -195,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
|
||||
|
||||
@ -322,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
|
||||
|
||||
@ -468,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:
|
||||
@ -512,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:
|
||||
@ -579,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)
|
||||
|
||||
@ -620,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)
|
||||
|
||||
@ -678,11 +684,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 |
|
||||
@ -694,15 +705,51 @@ 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:
|
||||
|
||||
* 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)
|
||||
|
||||
@ -720,21 +767,21 @@ 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)
|
||||
|
||||
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 \\
|
||||
@ -812,15 +859,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)
|
||||
|
||||
@ -833,14 +880,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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user