10
1
mirror of https://gitlab.com/scemama/qmcchem.git synced 2024-09-01 07:43:41 +02:00

Compare commits

...

16 Commits

Author SHA1 Message Date
161900c87a Bug fixes 2019-10-01 10:58:43 +02:00
be84027a8c Fixed Makefiles 2019-10-01 09:36:29 +02:00
1e99c27416 Merge lpqdh82.ups-tlse.fr:qmcchem into core 2019-09-30 20:10:20 +02:00
e0e7c73adc Compiling 2019-09-30 20:09:54 +02:00
f26b8fd9c5 Fixed qp_types 2019-09-30 17:03:19 +02:00
cb7d8a1e4f Fixed OCaml 2019-09-27 15:20:02 +02:00
35a083f6f3 Bugfix 2019-07-31 15:07:04 +02:00
b0fa735311 Fixing small bugs 2019-07-23 17:42:55 +02:00
f7ffed3a5a Seems to work again 2019-07-23 17:34:58 +02:00
380169d219 Fixing Ocaml 2019-07-23 17:27:02 +02:00
5e25738f53 Removed core 2019-07-22 12:19:12 +02:00
b14fe1dc34 Removing core 2019-07-22 11:51:14 +02:00
a13410d277 Removing core 2019-07-21 07:37:44 +02:00
a719c694ce Removing core 2019-07-19 11:46:29 +02:00
4c870cb62b Removing core 2019-07-17 19:10:22 +02:00
16acf1fe89 Removed core 2019-07-17 11:49:34 +02:00
57 changed files with 2106 additions and 1802 deletions

2
.gitignore vendored
View File

@ -1,5 +1,3 @@
.ninja_deps
.ninja_log
EZFIO EZFIO
install/Downloads install/Downloads
install/_build install/_build

66
Makefile Normal file
View File

@ -0,0 +1,66 @@
include make.config
default_target: all
.phony: clean always
clean:
./scripts/clean.sh
# put all files of PROPERTIES here
# --------------------------------
ezfio_config/properties.config ocaml/Property.ml: scripts/create_properties_python.py src/PROPERTIES/properties.irp.f src/PROPERTIES/properties_energy.irp.f src/PROPERTIES/properties_general.irp.f src/irpf90.make
bash -c "source qmcchemrc ; exec python2 ./scripts/create_properties_ezfio.py"
# EZFIO
# -----
build lib/libezfio.a lib/libezfio_irp.a EZFIO/lib/libezfio.a EZFIO/lib/libezfio_irp.a EZFIO/Ocaml/ezfio.ml EZFIO/Python/ezfio.py: ezfio_config/qmc.config ezfio_config/properties.config make.config scripts/create_properties_ezfio.py src/tags src/irpf90_entities src/irpf90.make src/irpf90.make
./scripts/compile_ezfio.sh
# Fortran executables
# -------------------
always: /dev/null
src/tags src/irpf90_entities src/irpf90.make: make.config always
./scripts/compile_irpf90.sh
src/MAIN/qmc src/MAIN/qmc_create_walkers src/MAIN/qmcchem_info: lib/libezfio.a lib/libezfio_irp.a src/tags src/irpf90_entities src/irpf90.make src/irpf90.make
./scripts/compile_src.sh
# OCaml
# -----
ocaml/qmcchem: EZFIO/Ocaml/ezfio.ml $(wildcard ocaml/*.ml)
./scripts/compile_ocaml.sh
# Archive
# -------
qmcchem.tar.gz: all
git archive --format tar.gz HEAD --prefix "QmcChem/" -7 -o qmcchem.tar.gz
# Binaries
# --------
bin/qmc: src/MAIN/qmc
cp src/MAIN/qmc bin/
bin/qmcchem_info: src/MAIN/qmcchem_info
cp src/MAIN/qmcchem_info bin/
bin/qmc_create_walkers: src/MAIN/qmc_create_walkers
cp src/MAIN/qmc_create_walkers bin/
bin/qmcchem: ocaml/qmcchem
cp ocaml/qmcchem bin/
all: bin/qmc bin/qmcchem_info bin/qmc_create_walkers bin/qmcchem

View File

@ -35,13 +35,12 @@ Warnings:
Requirements Requirements
------------ ------------
* [Ninja build tool](http://github.com/martine/ninja)
* [OCaml compiler with Opam and Core library](http://github.com/ocaml) * [OCaml compiler with Opam and Core library](http://github.com/ocaml)
* [ZeroMQ high performance communication library](http://www.zeromq.org) * [ZeroMQ high performance communication library](http://www.zeromq.org)
* [F77_ZMQ ZeroMQ Fortran interface](http://github.com/scemama/f77_zmq/) * [F77_ZMQ ZeroMQ Fortran interface](http://github.com/scemama/f77_zmq/)
* [IRPF90 Fortran code generator](http://irpf90.ups-tlse.fr) * [IRPF90 Fortran code generator](http://irpf90.ups-tlse.fr)
* [EZFIO Easy Fortran I/O library generator](http://github.com/scemama/EZFIO) * [EZFIO Easy Fortran I/O library generator](http://github.com/scemama/EZFIO)
* GNU C++ Compiler (g++) for ZeroMQ and Ninja * GNU C++ Compiler (g++) for ZeroMQ
* Python >= 2.6 for install scripts * Python >= 2.6 for install scripts
* Bash for install scripts * Bash for install scripts
* Fortran compiler, Intel Fortran recommended * Fortran compiler, Intel Fortran recommended
@ -58,9 +57,8 @@ Installation
The ``make.config`` file contains compiler specific parameters. You should change The ``make.config`` file contains compiler specific parameters. You should change
them to match your hardware. them to match your hardware.
The ``configure.sh`` script will first download the The ``configure.sh`` script will first download the dependencies by running
[Ninja](http://github.com/martine/ninja) build tool, and will then run Ninja ``make`` in the ``install/`` directory. The configuration script will work in
using the ``install/build.ninja`` file. The configuration script will work in
the ``install`` directory. It will first download into the the ``install`` directory. It will first download into the
``install/Downloads`` directory everything that needs to be installed. ``install/Downloads`` directory everything that needs to be installed.
The building of the dependencies takes place in the ``install/_build`` The building of the dependencies takes place in the ``install/_build``
@ -80,17 +78,20 @@ environment variables are located in the ``qmcchemrc`` file:
$ source qmcchemrc $ source qmcchemrc
``` ```
The ``QMCCHEM_NIC`` environment variable should be set to the proper network interface,
usually ``ib0`` on HPC machines.
To compile the program, run To compile the program, run
```bash ```bash
$ ninja $ make
``` ```
Example of a QMC=Chem calculation Example of a QMC=Chem calculation
--------------------------------- ---------------------------------
1.Calculation with the [quantum package](http://github.com/LCPQ/quantum_package) 1.Calculation with the [quantum package](http://github.com/QuantumPackage/qp2)
Create the `xyz` file containing the nuclear coordinates of the system Create the `xyz` file containing the nuclear coordinates of the system
@ -108,18 +109,18 @@ EOF
Choose a suitable basis set and create the [EZFIO database](https://github.com/LCPQ/ezfio) Choose a suitable basis set and create the [EZFIO database](https://github.com/LCPQ/ezfio)
```bash ```bash
$ qp_create_ezfio_from_xyz -b cc-pvdz h2o.xyz -o h2o $ qp_create_ezfio -b cc-pvdz h2o.xyz -o h2o
``` ```
Run the SCF calculation Run the SCF calculation
```bash ```bash
$ qp_run SCF h2o $ qp_run scf h2o
``` ```
Run the CIPSI calculation Run the CIPSI calculation
```bash ```bash
$ qp_run full_ci h2o $ qp_run fci h2o
``` ```
Transform the input for use in QMC=Chem Transform the input for use in QMC=Chem
@ -135,7 +136,7 @@ $ qp_run save_for_qmcchem h2o
Before using QMC=Chem, you need to load the environment variables: Before using QMC=Chem, you need to load the environment variables:
```bash ```bash
$ source qmcchem.rc $ source qmcchemrc
``` ```
In QMC=Chem, everything goes through the use of the ``qmcchem`` command. In QMC=Chem, everything goes through the use of the ``qmcchem`` command.

View File

@ -1,88 +0,0 @@
rule compile_ezfio
command = ./scripts/compile_ezfio.sh
description = Compiling the EZFIO library
pool = console
rule build_properties_config
command = bash -c "source qmcchemrc ; exec python2 ./scripts/create_properties_ezfio.py"
pool = console
rule compile_irpf90
command = ./scripts/compile_irpf90.sh
description = Compiling IRPF90
pool = console
rule compile_src
command = ./scripts/compile_src.sh
description = Compiling src
pool = console
rule create_archive
command = git archive --format tar.gz HEAD --prefix "QmcChem/" -7 -o qmcchem.tar.gz
description = Creating archive
pool = console
rule compile_ocaml_dep
command = scripts/compile_ocaml_dep.sh
description = Finding dependencies in OCaml files
pool = console
rule compile_ocaml
command = cd ocaml ; ninja $target
description = Compiling OCaml tools
pool = console
rule copy_to_bin
command = bash -c "cp $in $out ; touch $out"
description = Copying $in into bin/
pool = console
rule clean
command = ./scripts/clean.sh
pool = console
# put all files of PROPERTIES here
# --------------------------------
build ezfio_config/properties.config ocaml/Property.ml: build_properties_config | scripts/create_properties_python.py src/PROPERTIES/properties.irp.f src/PROPERTIES/properties_energy.irp.f src/PROPERTIES/properties_general.irp.f || src/IRPF90_temp/build.ninja
# EZFIO
# -----
build lib/libezfio.a lib/libezfio_irp.a EZFIO/lib/libezfio.a EZFIO/lib/libezfio_irp.a EZFIO/Ocaml/ezfio.ml EZFIO/Python/ezfio.py: compile_ezfio | ezfio_config/qmc.config ezfio_config/properties.config make.config scripts/create_properties_ezfio.py || src/tags src/irpf90_entities src/irpf90.make src/IRPF90_temp/build.ninja
# Fortran executables
# -------------------
build always: phony
build src/tags src/irpf90_entities src/irpf90.make src/IRPF90_temp/build.ninja: compile_irpf90 | make.config always
build src/MAIN/qmc src/MAIN/qmc_create_walkers src/MAIN/qmcchem_info: compile_src | lib/libezfio.a lib/libezfio_irp.a src/tags || src/irpf90_entities src/irpf90.make src/IRPF90_temp/build.ninja
# Archive
# -------
build qmcchem.tar.gz: create_archive
# Ocaml
# -----
build ocaml/qmcchem : compile_ocaml | EZFIO/Ocaml/ezfio.ml ocaml/Property.ml
# Copy binaries in bin
# --------------------
build bin/qmc: copy_to_bin src/MAIN/qmc
build bin/qmcchem_info: copy_to_bin src/MAIN/qmcchem_info
build bin/qmc_create_walkers: copy_to_bin src/MAIN/qmc_create_walkers
build bin/qmcchem: copy_to_bin ocaml/qmcchem
default bin/qmc bin/qmcchem_info bin/qmc_create_walkers bin/qmcchem
# Clean
# -----
build clean: clean

View File

@ -6,20 +6,6 @@ QMCCHEM_PATH=$PWD
mkdir -p "${QMCCHEM_PATH}"/bin mkdir -p "${QMCCHEM_PATH}"/bin
cd "${QMCCHEM_PATH}"/install cd "${QMCCHEM_PATH}"/install
mkdir -p Downloads _build mkdir -p Downloads _build
# TODO : Check if network is up (ping)
if [[ ! -x "${QMCCHEM_PATH}"/bin/ninja ]]
then
echo "Installing Ninja"
./scripts/install_ninja.sh &> _build/ninja.log
if [[ ! -x "${QMCCHEM_PATH}"/bin/ninja ]]
then
echo "Installation of Ninja failed"
exit 1
fi
touch _build/ninja.ok
fi
touch "${QMCCHEM_PATH}"/{src,ocaml}/.ls_md5
"${QMCCHEM_PATH}"/bin/ninja "$@"
cd "${QMCCHEM_PATH}" cd "${QMCCHEM_PATH}"
@ -39,7 +25,7 @@ echo "Configuration OK."
echo "Now, source the qmcchemrc file and build the program:" echo "Now, source the qmcchemrc file and build the program:"
echo "" echo ""
echo "source qmcchemrc" echo "source qmcchemrc"
echo "ninja" echo "make"
echo "" echo ""
echo "=====================================================================" echo "====================================================================="

View File

@ -8,12 +8,12 @@ ao_basis
ao_expo real (ao_basis_ao_num,ao_basis_ao_prim_num_max) ao_expo real (ao_basis_ao_num,ao_basis_ao_prim_num_max)
mo_basis mo_basis
mo_tot_num integer mo_num integer
mo_coef real (ao_basis_ao_num,mo_basis_mo_tot_num) mo_coef real (ao_basis_ao_num,mo_basis_mo_num)
mo_classif character (mo_basis_mo_tot_num) mo_classif character (mo_basis_mo_num)
mo_energy real (mo_basis_mo_tot_num) mo_energy real (mo_basis_mo_num)
mo_occ real (mo_basis_mo_tot_num) mo_occ real (mo_basis_mo_num)
mo_symmetry character*(8) (mo_basis_mo_tot_num) mo_symmetry character*(8) (mo_basis_mo_num)
electrons electrons
elec_alpha_num integer elec_alpha_num integer

67
install/Makefile Normal file
View File

@ -0,0 +1,67 @@
default_target: all
Downloads/irpf90.tar.gz:
wget --no-check-certificate \
"https://gitlab.com/scemama/irpf90/-/archive/v1.7.2/irpf90-v1.7.2.tar.gz" \
-O $@.tmp -o /dev/null && mv $@.tmp $@
Downloads/ezfio.tar.gz:
wget --no-check-certificate \
"https://gitlab.com/scemama/EZFIO/-/archive/master/EZFIO-master.tar.gz" \
-O $@.tmp -o /dev/null && mv $@.tmp $@
Downloads/zmq.tar.gz:
wget --no-check-certificate \
"http://github.com/zeromq/libzmq/releases/download/v4.2.5/zeromq-4.2.5.tar.gz" \
-O $@.tmp -o /dev/null && mv $@.tmp $@
Downloads/f77_zmq.tar.gz:
wget --no-check-certificate \
"https://github.com/scemama/f77_zmq/archive/v4.2.5.tar.gz" \
-O $@.tmp -o /dev/null && mv $@.tmp $@
Downloads/opam_installer.sh:
wget --no-check-certificate \
"https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh" \
-O $@.tmp -o /dev/null && mv $@.tmp $@
_build/irpf90.ok ../bin/irpman ../bin/irpf90: Downloads/irpf90.tar.gz
export target=irpf90 ; \
./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
touch _build/$${target}.ok || cat _build/$${target}.log
_build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h: Downloads/zmq.tar.gz
export target=zmq ; \
./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
touch _build/$${target}.ok || cat _build/$${target}.log
_build/ezfio.ok: Downloads/ezfio.tar.gz
export target=ezfio ; \
./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
touch _build/$${target}.ok || cat _build/$${target}.log
_build/f77_zmq.ok ../src/ZMQ/f77_zmq.h ../lib/libf77zmq.a ../lib/libf77zmq.so: Downloads/f77_zmq.tar.gz _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h
export target=f77_zmq ; \
./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
touch _build/$${target}.ok || cat _build/$${target}.log
_build/qmcchemrc.ok ../qmcchemrc: _build/irpf90.ok ../bin/irpman ../bin/irpf90 _build/ezfio.ok
export target=qmcchemrc; \
./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
touch _build/$${target}.ok || cat _build/$${target}.log
_build/ocaml.ok ../bin/opam: Downloads/opam_installer.sh _build/qmcchemrc.ok ../qmcchemrc
export target=ocaml; \
./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
touch _build/$${target}.ok || cat _build/$${target}.log
_build/ocaml_zmq.ok: ../bin/opam ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h _build/ocaml.ok _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h
export target=ocaml_zmq; \
./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
touch _build/$${target}.ok || cat _build/$${target}.log
all: _build/ocaml_zmq.ok _build/ocaml.ok ../bin/opam _build/qmcchemrc.ok ../qmcchemrc _build/f77_zmq.ok ../src/ZMQ/f77_zmq.h ../lib/libf77zmq.a ../lib/libf77zmq.so _build/ezfio.ok _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h _build/irpf90.ok ../bin/irpman ../bin/irpf90

View File

@ -1,75 +0,0 @@
# This script should be run in the install dircetory
# URLs
######
URL_OPAM ="https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh"
URL_IRPF90="https://gitlab.com/scemama/irpf90/-/archive/v1.7.2/irpf90-v1.7.2.tar.gz"
URL_EZFIO ="https://gitlab.com/scemama/EZFIO/-/archive/master/EZFIO-master.tar.gz"
URL_ZMQ ="http://github.com/zeromq/libzmq/releases/download/v4.2.5/zeromq-4.2.5.tar.gz"
URL_F77ZMQ="https://github.com/scemama/f77_zmq/archive/v4.2.5.tar.gz"
# Rules
#######
rule download
command = [ -e ${out} ] || (wget --no-check-certificate ${url} -O ${out}.tmp -o /dev/null && mv ${out}.tmp ${out})
description = Downloading ${descr}
rule install
command = ./scripts/install_${target}.sh > _build/${target}.log 2>&1 && touch _build/${target}.ok || cat _build/${target}.log
description = Installing ${descr} | tail -f install/_build/${target}.log
# Builds
########
build Downloads/irpf90.tar.gz: download
url = ${URL_IRPF90}
descr = IRPF90 code generator
build Downloads/ezfio.tar.gz: download
url = ${URL_EZFIO}
descr = EZFIO I/O library generator
build Downloads/zmq.tar.gz: download
url = ${URL_ZMQ}
descr = ZeroMQ communication library
build Downloads/f77_zmq.tar.gz: download
url = ${URL_F77ZMQ}
descr = Fortran ZeroMQ interface
build Downloads/opam_installer.sh: download
url = ${URL_OPAM}
descr = OCaml OPAM installer
build _build/irpf90.ok ../bin/irpman ../bin/irpf90: install | Downloads/irpf90.tar.gz
target = irpf90
descr = IRPF90
build _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h: install | Downloads/zmq.tar.gz
target = zmq
descr = ZeroMQ
build _build/ezfio.ok: install | Downloads/ezfio.tar.gz _build/irpf90.ok ../bin/irpman ../bin/irpf90
target = ezfio
descr = EZFIO
build _build/f77_zmq.ok ../src/ZMQ/f77_zmq.h ../lib/libf77zmq.a ../lib/libf77zmq.so: install | Downloads/f77_zmq.tar.gz _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h
target = f77_zmq
descr = Fortran ZeroMQ interface
build _build/qmcchemrc.ok ../qmcchemrc: install | _build/irpf90.ok ../bin/irpman ../bin/irpf90 _build/ezfio.ok
target = qmcchemrc
description = QMC=Chem environment variables
build _build/ocaml.ok ../bin/opam: install | Downloads/opam_installer.sh _build/qmcchemrc.ok ../qmcchemrc
target = ocaml
descr = OCaml compiler
build _build/ocaml_zmq.ok: install | ../bin/opam ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h _build/ocaml.ok _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h
target = ocaml_zmq
descr = OCaml ZeroMQ interface

View File

@ -1,27 +0,0 @@
#!/bin/bash -x
set -u
set -e
TARGET=ninja
URL="https://github.com/martine/ninja/archive/v1.5.3.tar.gz"
function _install()
{
cd .. ; QMCCHEM_PATH="$PWD" ; cd -
set -e
set -u
cd "${BUILD}"
./configure.py --bootstrap
cd -
mv "${BUILD}/ninja" "${QMCCHEM_PATH}"/bin/
return 0
}
if [[ ! -f "Downloads/${TARGET}.tar.gz" ]]
then
wget --no-check-certificate ${URL} -O "Downloads/${TARGET}.tar.gz.tmp"
mv "Downloads/${TARGET}.tar.gz"{.tmp,}
fi
source scripts/build.sh

View File

@ -6,13 +6,12 @@ CPU_TYPE="-mavx"
## FORTRAN compiler ## FORTRAN compiler
FC="gfortran -ffree-line-length-none" FC="gfortran -ffree-line-length-none"
NINJA="ninja"
FCFLAGS="-O2 -g ${CPU_TYPE}" FCFLAGS="-O2 -g ${CPU_TYPE}"
LIB="-lblas -llapack" LIB="-lblas -llapack -lpthread"
## IRPF90 ## IRPF90
IRPF90="${QMCCHEM_PATH}/bin/irpf90" IRPF90="${QMCCHEM_PATH}/bin/irpf90"
IRPF90_FLAGS="--align=16" IRPF90_FLAGS="--align=16"
export FC NINJA FCFLAGS LIB IRPF90 IRPF90_FLAGS export FC FCFLAGS LIB IRPF90 IRPF90_FLAGS

View File

@ -10,13 +10,12 @@ ALIGN="32"
## FORTRAN compiler ## FORTRAN compiler
FC="ifort" FC="ifort"
NINJA="ninja"
FCFLAGS="-O2 -g -ip -ftz -finline ${CPU_TYPE}" #-traceback FCFLAGS="-O2 -g -ip -ftz -finline ${CPU_TYPE}" #-traceback
LIB="-mkl=sequential" LIB="-mkl=sequential"
## IRPF90 ## IRPF90
IRPF90="${QMCCHEM_PATH}/bin/irpf90" IRPF90="${QMCCHEM_PATH}/bin/irpf90"
IRPF90_FLAGS="--align=${ALIGN} ${IRPF90_FLAGS}" IRPF90_FLAGS="--align=${ALIGN}"
export FC NINJA FCFLAGS LIB IRPF90 IRPF90_FLAGS export FC FCFLAGS LIB IRPF90 IRPF90_FLAGS

3
ocaml/.gitignore vendored
View File

@ -5,9 +5,6 @@
ezfio.ml ezfio.ml
Qptypes.ml Qptypes.ml
.ls_md5 .ls_md5
.ninja_deps
.ninja_log
generated.ninja
qmcchem qmcchem
qptypes_generator qptypes_generator
Property.ml Property.ml

View File

@ -1,3 +1,3 @@
PKG core cryptokit str zmq PKG cryptokit str zmq
S . S .

View File

@ -1,4 +1,3 @@
open Core
open Qptypes open Qptypes
type t = type t =
@ -6,7 +5,7 @@ type t =
value : Sample.t ; value : Sample.t ;
weight : Weight.t ; weight : Weight.t ;
compute_node : Compute_node.t ; compute_node : Compute_node.t ;
pid : Pid.t ; pid : int ;
block_id : Block_id.t ; block_id : Block_id.t ;
} }
@ -23,17 +22,17 @@ let of_string s =
match lst with match lst with
| b :: pid :: c:: p :: w :: v :: [] -> Some | b :: pid :: c:: p :: w :: v :: [] -> Some
{ property = Property.of_string p ; { property = Property.of_string p ;
value = Sample.of_float (Float.of_string v) ; value = Sample.of_float (float_of_string v) ;
weight = Weight.of_float (Float.of_string w) ; weight = Weight.of_float (float_of_string w) ;
compute_node = Compute_node.of_string c; compute_node = Compute_node.of_string c;
pid = Pid.of_string pid; pid = int_of_string pid;
block_id = Block_id.of_int (Int.of_string b) ; block_id = Block_id.of_int (int_of_string b) ;
} }
| b :: pid :: c:: p :: w :: v -> | b :: pid :: c:: p :: w :: v ->
let v = let v =
List.rev v List.rev v
|> Array.of_list |> Array.of_list
|> Array.map ~f:Float.of_string |> Array.map float_of_string
in in
let dim = let dim =
Array.length v Array.length v
@ -41,10 +40,10 @@ let of_string s =
Some Some
{ property = Property.of_string p ; { property = Property.of_string p ;
value = Sample.of_float_array ~dim v ; value = Sample.of_float_array ~dim v ;
weight = Weight.of_float (Float.of_string w) ; weight = Weight.of_float (float_of_string w) ;
compute_node = Compute_node.of_string c; compute_node = Compute_node.of_string c;
pid = Pid.of_string pid; pid = int_of_string pid;
block_id = Block_id.of_int (Int.of_string b) ; block_id = Block_id.of_int (int_of_string b) ;
} }
| _ -> None | _ -> None
with with
@ -55,10 +54,10 @@ let of_string s =
let to_string b = let to_string b =
Printf.sprintf "%s %s # %s %s %s %d" Printf.sprintf "%s %s # %s %s %s %d"
(Sample.to_string b.value ) (Sample.to_string b.value )
(Weight.to_float b.weight |> Float.to_string) (Weight.to_float b.weight |> string_of_float)
(Property.to_string b.property) (Property.to_string b.property)
(Compute_node.to_string b.compute_node) (Compute_node.to_string b.compute_node)
(Pid.to_string b.pid) (string_of_int b.pid)
(Block_id.to_int b.block_id) (Block_id.to_int b.block_id)
@ -70,8 +69,11 @@ let dir_name = lazy(
let md5 = let md5 =
QmcMd5.hash () QmcMd5.hash ()
in in
List.fold_right ~init:"" ~f:Filename.concat let d = Filename.concat ezfio_filename "blocks" in
[ ezfio_filename ; "blocks" ; md5 ; Filename.dir_sep ] if not ( Sys.file_exists d ) then
Unix.mkdir d 0o755;
List.fold_right Filename.concat
[ ezfio_filename ; "blocks" ; md5 ; Filename.dir_sep ] ""
) )
@ -87,29 +89,31 @@ let update_raw_data ?(locked=true) () =
in in
let files = let files =
let result = let result =
match Sys.is_directory dir_name with if Sys.file_exists dir_name && Sys.is_directory dir_name then
| `Yes ->
begin begin
Sys.readdir dir_name Sys.readdir dir_name
|> Array.map ~f:(fun x -> dir_name^x) |> Array.map (fun x -> dir_name^x)
|> Array.to_list |> Array.to_list
end end
| _ -> [] else []
in in
if locked then if locked then
result result
else else
List.filter result ~f:(fun x -> List.filter (fun x ->
match String.substr_index ~pattern:"locked" x with try
| Some x -> false let _ =
| None -> true Str.search_backward (Str.regexp "locked") x ((String.length x) - 1)
) in false
with
| Not_found -> true
) result
in in
let rec transform new_list = function let rec transform new_list = function
| [] -> new_list | [] -> new_list
| head :: tail -> | head :: tail ->
let head = String.strip head in let head = String.trim head in
let item = of_string head in let item = of_string head in
match item with match item with
| None -> transform new_list tail | None -> transform new_list tail
@ -117,13 +121,18 @@ let update_raw_data ?(locked=true) () =
in in
let result = let result =
List.map files ~f:(fun filename -> let rec aux ic accu =
In_channel.with_file filename ~f:(fun in_channel -> try
In_channel.input_all in_channel) aux ic ( (input_line ic)::accu )
) with
|> String.concat | End_of_file -> List.rev accu
|> String.split_lines in
|> List.rev List.map (fun filename ->
let ic = open_in filename in
let result = aux ic [] in
close_in ic;
result ) files
|> List.concat
|> transform [] |> transform []
in in
result result
@ -142,9 +151,11 @@ let raw_data ?(locked=true) () =
let properties = lazy ( let properties = lazy (
let set = Set.Poly.empty in let h = Hashtbl.create 63 in
List.fold (raw_data ()) ~init:set ~f:(fun s x -> Set.add s x.property) List.iter (fun x ->
|> Set.to_list Hashtbl.replace h (Property.to_string x.property) x.property)
(raw_data ());
Hashtbl.fold (fun k v a -> v :: a) h []
) )

218
ocaml/Command_line.ml Normal file
View File

@ -0,0 +1,218 @@
type short_opt = char
type long_opt = string
type optional = Mandatory | Optional
type documentation = string
type argument = With_arg of string | Without_arg | With_opt_arg of string
type description = {
short: short_opt ;
long : long_opt ;
opt : optional ;
doc : documentation ;
arg : argument ;
}
(* Mutable variables *)
let anon_args = ref []
and header_doc = ref ""
and description_doc = ref ""
and footer_doc = ref ""
and specs = ref []
let reset () =
anon_args := [];
header_doc := "";
description_doc := "";
footer_doc := "";
specs := []
(* End mutable variables *)
let set_header_doc s = header_doc := s
let set_description_doc s = description_doc := s
let set_footer_doc s = footer_doc := s
(* Hash table containing all the options *)
let dict = Hashtbl.create 67
let get_bool x = Hashtbl.mem dict x
let show_help () = get_bool "help"
let get x =
try Some (Hashtbl.find dict x)
with Not_found -> None
let anonymous name opt doc =
{ short=' ' ; long=name; opt; doc; arg=Without_arg; }
let output_text t =
Format.printf "@[<v 0>";
begin
match Str.split (Str.regexp "\n") t with
| x :: [] -> Format.printf "@[<hov 0>";
Str.split (Str.regexp " ") x
|> List.iter (fun y -> Format.printf "@[%s@]@ " y) ;
Format.printf "@]"
| t -> List.iter (fun x ->
Format.printf "@[<hov 0>";
Str.split (Str.regexp " ") x
|> List.iter (fun y -> Format.printf "@[%s@]@ " y) ;
Format.printf "@]@;") t
end;
Format.printf "@]"
;;
let output_short x =
match x.short, x.opt, x.arg with
| ' ', Mandatory, _ -> Format.printf "@[%s@]" x.long
| ' ', Optional , _ -> Format.printf "@[[%s]@]" x.long
| _ , Mandatory, Without_arg -> Format.printf "@[-%c@]" x.short
| _ , Optional , Without_arg -> Format.printf "@[[-%c]@]" x.short
| _ , Mandatory, With_arg arg -> Format.printf "@[-%c %s@]" x.short arg
| _ , Optional , With_arg arg -> Format.printf "@[[-%c %s]@]" x.short arg
| _ , Mandatory, With_opt_arg arg -> Format.printf "@[-%c [%s]@]" x.short arg
| _ , Optional , With_opt_arg arg -> Format.printf "@[[-%c [%s]]@]" x.short arg
let output_long max_width x =
let arg =
match x.short, x.arg with
| ' ' , _ -> x.long
| _ , Without_arg -> x.long
| _ , With_arg arg -> Printf.sprintf "%s=%s" x.long arg
| _ , With_opt_arg arg -> Printf.sprintf "%s[=%s]" x.long arg
in
let long =
let l = String.length arg in
arg^(String.make (max_width-l) ' ')
in
Format.printf "@[<v 0>";
begin
match x.short with
| ' ' -> Format.printf "@[%s @]" long
| short -> Format.printf "@[-%c --%s @]" short long
end;
Format.printf "@]";
output_text x.doc
let help () =
(* Print the header *)
output_text !header_doc;
Format.printf "@.@.";
(* Find the anonymous arguments *)
let anon =
List.filter (fun x -> x.short = ' ') !specs
in
(* Find the options *)
let options =
List.filter (fun x -> x.short <> ' ') !specs
|> List.sort (fun x y -> Char.compare x.short y.short)
in
(* Find column lengths *)
let max_width =
List.map (fun x ->
( match x.arg with
| Without_arg -> String.length x.long
| With_arg arg -> String.length x.long + String.length arg
| With_opt_arg arg -> String.length x.long + String.length arg + 2
)
+ ( if x.opt = Optional then 2 else 0)
) !specs
|> List.fold_left max 0
in
(* Print usage *)
Format.printf "@[<v>@[<v 2>Usage:@,@,@[<hov 4>@[%s@]" Sys.argv.(0);
List.iter (fun x -> Format.printf "@ "; output_short x) options;
Format.printf "@ @[[--]@]";
List.iter (fun x -> Format.printf "@ "; output_short x;) anon;
Format.printf "@]@,@]@,";
(* Print arguments and doc *)
Format.printf "@[<v 2>Arguments:@,";
Format.printf "@[<v 0>" ;
List.iter (fun x -> Format.printf "@ "; output_long max_width x) anon;
Format.printf "@]@,@]@,";
(* Print options and doc *)
Format.printf "@[<v 2>Options:@,";
Format.printf "@[<v 0>" ;
List.iter (fun x -> Format.printf "@ "; output_long max_width x) options;
Format.printf "@]@,@]@,";
(* Print footer *)
if !description_doc <> "" then
begin
Format.printf "@[<v 2>Description:@,@,";
output_text !description_doc;
Format.printf "@,"
end;
(* Print footer *)
output_text !footer_doc;
Format.printf "@."
let set_specs ?(no_help=false) specs_in =
specs := { short='h' ;
long ="help" ;
doc ="Prints the help message." ;
arg =Without_arg ;
opt =Optional ;
} :: specs_in;
let cmd_specs =
List.filter (fun x -> x.short != ' ') !specs
|> List.map (fun { short ; long ; opt ; doc ; arg } ->
match arg with
| With_arg _ ->
(short, long, None, Some (fun x -> Hashtbl.replace dict long x) )
| Without_arg ->
(short, long, Some (fun () -> Hashtbl.replace dict long ""), None)
| With_opt_arg _ ->
(short, long, Some (fun () -> Hashtbl.replace dict long ""),
Some (fun x -> Hashtbl.replace dict long x) )
)
in
let cmdline =
Sys.argv
|> Array.to_list
|> List.filter (fun x -> x <> "")
|> Array.of_list
in
Getopt.parse cmd_specs (fun x -> anon_args := !anon_args @ [x])
cmdline 1 (Array.length cmdline -1);
if not no_help && (show_help ()) then
(help () ; exit 0);
(* Check that all mandatory arguments are set *)
List.filter (fun x -> x.short <> ' ' && x.opt = Mandatory) !specs
|> List.iter (fun x ->
match get x.long with
| Some _ -> ()
| None -> failwith ("Error: --"^x.long^" option is missing.")
)
;;
let anon_args () = !anon_args

129
ocaml/Command_line.mli Normal file
View File

@ -0,0 +1,129 @@
(** Handles command-line arguments, using getopt.
Example:
let () =
(* Command-line specs *)
let open Command_line in
begin
set_header_doc (Sys.argv.(0) ^ " - quantum_package command");
set_description_doc
"Opens a text editor to edit the parameters of an EZFIO directory.";
[ { short='c'; long="check"; opt=Optional;
doc="Checks the input data";
arg=Without_arg; };
{ short='n'; long="ndet"; opt=Optional;
doc="Truncate the wavefunction to the target number of determinants";
arg=With_arg "<int>"; };
{ short='s'; long="state"; opt=Optional;
doc="Extract selected states, for example \"[1,3-5]\"";
arg=With_arg "<range>"; };
anonymous "EZFIO_DIR" Mandatory "EZFIO directory";
]
|> set_specs ;
end;
(* Handle options *)
let ndet =
match Command_line.get "ndet" with
| None -> None
| Some s -> (try Some (int_of_string s)
with _ -> failwith "[-n|--ndet] expects an integer")
in
let state =
match Command_line.get "state" with
| None -> None
| Some s -> (try Some (Range.of_string s)
with _ -> failwith "[-s|--state] expects a range")
in
let c = Command_line.get_bool "check" in
let filename =
match Command_line.anon_args () with
| [x] -> x
| _ -> (Command_line.help () ; failwith "EZFIO_DIR is missing")
in
(* Run the program *)
run c ?ndet ?state filename
*)
type short_opt = char
type long_opt = string
type optional = Mandatory
| Optional
type documentation = string
type argument = With_arg of string
| Without_arg
| With_opt_arg of string
type description =
{
short : short_opt;
long : long_opt;
opt : optional;
doc : documentation;
arg : argument;
}
(** Sets the header of the help message. *)
val set_header_doc : string -> unit
(** Sets the description of the help message. *)
val set_description_doc : string -> unit
(** Sets the footer of the help message. *)
val set_footer_doc : string -> unit
(** Gets the value of an option. If the option is not set, returns [None]. If
the option is set, returns Some <string>. *)
val get : string -> string option
(** Gets the value of an option with no argument. If the option is set, returns [true]. *)
val get_bool : string -> bool
(** True if the '-h' or "--help" option was found. *)
val show_help : unit -> bool
(** Creates a specification of an anonymous argument. *)
val anonymous : long_opt -> optional -> documentation -> description
(** Prints the help message *)
val help : unit -> unit
(** Sets the specification list as a list of tuples:
( short option, long option, documentation, argument ) *)
val set_specs : ?no_help:bool -> description list -> unit
(** Returns the list of anonymous arguments *)
val anon_args : unit -> string list
(** Reset the internal state *)
val reset : unit -> unit

View File

@ -1,6 +1,3 @@
open Core
let simulation_nucl_fitcusp_factor = lazy( let simulation_nucl_fitcusp_factor = lazy(
let default = let default =
1. 1.
@ -26,7 +23,7 @@ let simulation_time_step = lazy ( 0.15 )
let simulation_srmc_projection_time = lazy ( 1. ) let simulation_srmc_projection_time = lazy ( 1. )
let reset_defaults () = let reset_defaults () =
List.iter ~f:(fun x -> Sys.remove ( (Lazy.force Qputils.ezfio_filename) ^ x)) List.iter (fun x -> Sys.remove ( (Lazy.force Qputils.ezfio_filename) ^ x))
[ "/electrons/elec_walk_num" ; [ "/electrons/elec_walk_num" ;
"/electrons/elec_walk_num_tot" ; "/electrons/elec_walk_num_tot" ;
"/jastrow/jast_type" ; "/jastrow/jast_type" ;

View File

@ -1,4 +1,3 @@
open Core
open Qptypes open Qptypes
open Qputils open Qputils
@ -38,13 +37,13 @@ end = struct
let to_string t = let to_string t =
to_bool t to_bool t
|> Bool.to_string |> string_of_bool
let of_string t = let of_string t =
try try
String.lowercase t String.lowercase_ascii t
|> Bool.of_string |> bool_of_string
|> of_bool |> of_bool
with with
| Invalid_argument msg -> failwith msg | Invalid_argument msg -> failwith msg
@ -119,12 +118,12 @@ Fit is done for r < r_c(f) where r_c(f) = (1s orbital radius) x f. Value of f"
let to_string t = let to_string t =
to_float t to_float t
|> Float.to_string |> string_of_float
let of_string t = let of_string t =
try try
Float.of_string t float_of_string t
|> of_float |> of_float
with with
| Invalid_argument msg -> failwith msg | Invalid_argument msg -> failwith msg
@ -181,21 +180,21 @@ end = struct
let to_string t = let to_string t =
to_int t to_int t
|> Int.to_string |> string_of_int
let of_string t = let of_string t =
Int.of_string t int_of_string t
|> of_int |> of_int
let to_float t = let to_float t =
to_int t to_int t
|> Float.of_int |> float_of_int
let of_float t = let of_float t =
Int.of_float t int_of_float t
|> of_int |> of_int
@ -248,11 +247,11 @@ end = struct
let to_string t = let to_string t =
to_int t to_int t
|> Int.to_string |> string_of_int
let of_string t = let of_string t =
Int.of_string t int_of_string t
|> of_int |> of_int
@ -305,11 +304,11 @@ end = struct
let to_string t = let to_string t =
to_int t to_int t
|> Int.to_string |> string_of_int
let of_string t = let of_string t =
Int.of_string t int_of_string t
|> of_int |> of_int
@ -364,21 +363,21 @@ end = struct
let to_string t = let to_string t =
to_int t to_int t
|> Int.to_string |> string_of_int
let of_string t = let of_string t =
Int.of_string t int_of_string t
|> of_int |> of_int
let to_float t = let to_float t =
to_int t to_int t
|> Float.of_int |> float_of_int
let of_float t = let of_float t =
Int.of_float t int_of_float t
|> of_int |> of_int
end end
@ -456,7 +455,7 @@ end = struct
let doc = "Sampling algorithm : [ Langevin | Brownian ]" let doc = "Sampling algorithm : [ Langevin | Brownian ]"
let of_string s = let of_string s =
match String.capitalize (String.strip s) with match String.capitalize_ascii (String.trim s) with
| "Langevin" -> Langevin | "Langevin" -> Langevin
| "Brownian" -> Brownian | "Brownian" -> Brownian
| x -> failwith ("Sampling should be [ Brownian | Langevin ], not "^x^".") | x -> failwith ("Sampling should be [ Brownian | Langevin ], not "^x^".")
@ -536,13 +535,13 @@ end = struct
let of_string x = let of_string x =
Float.of_string x float_of_string x
|> of_float |> of_float
let to_string x = let to_string x =
to_float x to_float x
|> Float.to_string |> string_of_float
end end
@ -593,13 +592,13 @@ end = struct
let of_string x = let of_string x =
Float.of_string x float_of_string x
|> of_float |> of_float
let to_string x = let to_string x =
to_float x to_float x
|> Float.to_string |> string_of_float
end end
@ -652,13 +651,13 @@ contribution to the norm less than t (au)"
let of_string x = let of_string x =
Float.of_string x float_of_string x
|> of_float |> of_float
let to_string x = let to_string x =
to_float x to_float x
|> Float.to_string |> string_of_float
end end
@ -708,13 +707,13 @@ end = struct
let of_string x = let of_string x =
Float.of_string x float_of_string x
|> of_float |> of_float
let to_string x = let to_string x =
to_float x to_float x
|> Float.to_string |> string_of_float
end end
@ -764,13 +763,13 @@ end = struct
let of_string x = let of_string x =
Float.of_string x float_of_string x
|> of_float |> of_float
let to_string x = let to_string x =
to_float x to_float x
|> Float.to_string |> string_of_float
end end
@ -789,7 +788,7 @@ end = struct
let doc = "Type of Jastrow factor [ None | Core | Simple ]" let doc = "Type of Jastrow factor [ None | Core | Simple ]"
let of_string s = let of_string s =
match String.capitalize (String.strip s) with match String.capitalize_ascii (String.trim s) with
| "Core" -> Core | "Core" -> Core
| "Simple" -> Simple | "Simple" -> Simple
| "None" -> None | "None" -> None
@ -841,31 +840,31 @@ end = struct
let read () = let read () =
List.map Property.all ~f:(fun x -> (x, Property.calc x)) List.map (fun x -> (x, Property.calc x)) Property.all
let write l = let write l =
List.iter l ~f:(fun (x,b) -> Property.set_calc x b) List.iter (fun (x,b) -> Property.set_calc x b) l
let to_string l = let to_string l =
List.map l ~f:(fun (x,b) -> List.map (fun (x,b) ->
let ch = let ch =
if b then "X" else " " if b then "X" else " "
in in
Printf.sprintf "(%s) %s" ch (Property.to_string x)) Printf.sprintf "(%s) %s" ch (Property.to_string x)) l
|> String.concat ~sep:"\n" |> String.concat "\n"
let of_string s = let of_string s =
String.split s ~on:'\n' String.split_on_char '\n' s
|> List.map ~f:(fun x -> |> List.map (fun x ->
let (calc,prop) = let (calc,prop) =
String.strip x String.trim x
|> String.rsplit2_exn ~on:' ' |> String_ext.rsplit2_exn ~on:' '
in in
let prop = let prop =
String.strip prop String.trim prop
|> Property.of_string |> Property.of_string
and calc = and calc =
match calc with match calc with

View File

@ -1,5 +1,3 @@
open Core
type t = type t =
| Srun | Srun
| MPI | MPI
@ -50,19 +48,21 @@ let create_nodefile () =
in in
let h = let h =
String.Table.create ~size:1000 () Hashtbl.create 1000
in in
let in_channel = let in_channel =
Unix.open_process_in (launcher_command^" hostname -s") Unix.open_process_in (launcher_command^" hostname -s")
in in
In_channel.input_lines in_channel String_ext.input_lines in_channel
|> List.map ~f:String.strip |> List.map String.trim
|> List.iter ~f:( fun host -> |> List.iter ( fun host ->
Hashtbl.change h host (function let n =
| Some x -> Some (x+1) match Hashtbl.find_opt h host with
| None -> Some 1 | Some x -> x+1
) | None -> 1
in
Hashtbl.replace h host n
); );
match match
Unix.close_process_in in_channel Unix.close_process_in in_channel
@ -80,9 +80,8 @@ let create_nodefile () =
fun (node, n) -> fun (node, n) ->
Printf.sprintf "%s %d\n" node n Printf.sprintf "%s %d\n" node n
in in
Hashtbl.to_alist h Hashtbl.fold (fun k v a -> (f (k,v)) :: a) h []
|> List.map ~f |> String.concat "\n"
|> String.concat

59
ocaml/Makefile Normal file
View File

@ -0,0 +1,59 @@
.NOPARALLEL:
# Check if QMCCHEM_PATH is defined
ifndef QMCCHEM_PATH
$(info -------------------- Error --------------------)
$(info QMCCHEM_PATH undefined. Source the qmcchem.rc script)
$(info -----------------------------------------------)
$(error )
endif
LIBS=
PKGS=
OCAMLCFLAGS="-g"
OCAMLOPTFLAGS="opt -O3 -remove-unused-arguments -rounds 16 -inline 100 -inline-max-unroll 100"
OCAMLBUILD=ocamlbuild -j 0 -cflags $(OCAMLCFLAGS) -lflags $(OCAMLCFLAGS) -ocamlopt $(OCAMLOPTFLAGS)
MLLFILES=$(wildcard *.mll)
MLFILES=$(wildcard *.ml) ezfio.ml Qptypes.ml
MLIFILES=$(wildcard *.mli)
ALL_TESTS=$(patsubst %.ml,%.byte,$(wildcard test_*.ml))
ALL_EXE=$(patsubst %.ml,%.native,$(wildcard qp_*.ml)) qmcchem.native
.PHONY: default
default: $(ALL_EXE)
tests: $(ALL_TESTS)
%.inferred.mli: $(MLFILES)
$(OCAMLBUILD) $*.inferred.mli -use-ocamlfind $(PKGS)
mv _build/$*.inferred.mli .
%.byte: $(MLFILES) $(MLIFILES)
rm -f -- $*
$(OCAMLBUILD) $*.byte -use-ocamlfind $(PKGS)
ln -s $*.byte $*
%.native: $(MLFILES) $(MLIFILES)
rm -f -- $*
$(OCAMLBUILD) $*.native -use-ocamlfind $(PKGS)
ln -s $*.native $*
ezfio.ml: ${QMCCHEM_PATH}/EZFIO/Ocaml/ezfio.ml
cp ${QMCCHEM_PATH}/EZFIO/Ocaml/ezfio.ml .
qptypes_generator.byte: qptypes_generator.ml
$(OCAMLBUILD) qptypes_generator.byte -use-ocamlfind
Qptypes.ml: qptypes_generator.byte
./qptypes_generator.byte > Qptypes.ml
${QMCCHEM_PATH}/EZFIO/Ocaml/ezfio.ml:
${MAKE) -C ${QMCCHEM_PATH}/EZFIO/
clean:
rm -rf _build Qptypes.ml $(ALL_EXE) $(ALL_TESTS)

View File

@ -1,149 +0,0 @@
open Core
(** Directory containing the list of input files. The directory is created is inexistant. *)
let input_directory = lazy (
let ezfio_filename =
Lazy.force Qputils.ezfio_filename
in
let dirname =
Filename.concat ezfio_filename "input"
in
begin
match ( Sys.is_directory dirname ) with
| `No -> Unix.mkdir dirname
| _ -> ()
end ;
dirname
)
(** List of files responsible for the MD5 key of the input *)
let files_to_track = [
"ao_basis/ao_coef.gz" ;
"ao_basis/ao_expo.gz" ;
"ao_basis/ao_nucl.gz" ;
"ao_basis/ao_num" ;
"ao_basis/ao_power.gz" ;
"ao_basis/ao_prim_num.gz" ;
"electrons/elec_alpha_num" ;
"electrons/elec_beta_num" ;
"electrons/elec_walk_num" ;
"jastrow/jast_type" ;
"mo_basis/mo_coef.gz" ;
"mo_basis/mo_tot_num" ;
"nuclei/nucl_charge.gz" ;
"nuclei/nucl_coord.gz" ;
"nuclei/nucl_num" ;
"simulation/ci_threshold" ;
"simulation/nucl_fitcusp_factor" ;
"simulation/jast_a_up_dn" ;
"simulation/jast_a_up_up" ;
"simulation/jast_b_up_dn" ;
"simulation/jast_b_up_up" ;
"simulation/jast_core_a1" ;
"simulation/jast_core_a2" ;
"simulation/jast_core_b1" ;
"simulation/jast_core_b2" ;
"simulation/jast_een_e_a.gz" ;
"simulation/jast_een_e_b.gz" ;
"simulation/jast_een_n.gz" ;
"simulation/jast_pen.gz" ;
"simulation/method" ;
"simulation/time_step" ;
"simulation/dmc_projection_time" ;
"spindeterminants/bit_kind" ;
"spindeterminants/n_det" ;
"spindeterminants/n_det_alpha" ;
"spindeterminants/n_det_beta" ;
"spindeterminants/n_int" ;
"spindeterminants/n_states" ;
"spindeterminants/psi_coef_matrix_columns.gz" ;
"spindeterminants/psi_coef_matrix_rows.gz" ;
"spindeterminants/psi_coef_matrix_values.gz" ;
"spindeterminants/psi_det_alpha.gz" ;
"spindeterminants/psi_det_beta.gz" ;
"/pseudo/do_pseudo" ;
"/pseudo/mo_pseudo_grid.gz" ;
"/pseudo/pseudo_dz_kl.gz";
"/pseudo/pseudo_klocmax" ;
"/pseudo/pseudo_n_k.gz" ;
"/pseudo/pseudo_v_kl.gz" ;
"/pseudo/pseudo_grid_rmax" ;
"/pseudo/pseudo_kmax" ;
"/pseudo/pseudo_n_kl.gz" ;
"/pseudo/pseudo_dz_k.gz" ;
"/pseudo/pseudo_grid_size" ;
"/pseudo/pseudo_v_k.gz" ;
]
(** Get an MD5 ke from the content of a file. *)
let hash_file filename =
match Sys.is_file filename with
| `Yes ->
begin
In_channel.with_file filename ~f:(fun ic ->
Cryptokit.hash_channel (Cryptokit.Hash.md5 ()) ic
|> Cryptokit.transform_string (Cryptokit.Hexa.encode ()) )
end
| _ -> ""
(** Cache containing the current value of the MD5 hash. *)
let _hash =
ref None
(** Get the hash correcponding to the EZFIO file. *)
let hash () =
let compute_hash () =
let ezfio_filename =
Lazy.force Qputils.ezfio_filename
in
let old_md5 =
if Ezfio.has_simulation_md5_key () then
Ezfio.get_simulation_md5_key ()
else
""
in
let md5_string =
files_to_track
|> List.map ~f:(fun x -> Printf.sprintf "%s/%s" ezfio_filename x)
|> List.map ~f:hash_file
|> String.concat
in
let new_md5 =
md5_string
|> Cryptokit.hash_string (Cryptokit.Hash.md5 ())
|> Cryptokit.transform_string (Cryptokit.Hexa.encode ())
in
if (new_md5 <> old_md5) then
begin
Printf.eprintf "Info : MD5 key changed\n %s\n-> %s\n%!" old_md5 new_md5 ;
Ezfio.set_simulation_md5_key new_md5
end
;
new_md5
in
match (!_hash) with
| Some key -> key
| None ->
begin
let key =
compute_hash ()
in
_hash := Some key ;
key
end
(** Reset the cache of the MD5 hash. *)
let reset_hash () =
_hash := None;
ignore (hash ())

View File

@ -1,11 +1,10 @@
open Core
open Qptypes open Qptypes
type t = type t =
| Property of Block.t | Property of Block.t
| Walkers of Compute_node.t * Pid.t * (float array) array | Walkers of Compute_node.t * int * (float array) array
| Register of Compute_node.t * Pid.t | Register of Compute_node.t * int
| Unregister of Compute_node.t * Pid.t | Unregister of Compute_node.t * int
| Test | Test
| GetWalkers of Strictly_positive_int.t | GetWalkers of Strictly_positive_int.t
| Ezfio of string | Ezfio of string
@ -19,45 +18,45 @@ let create m =
let open Block in let open Block in
Property Property
{ property = Property.Cpu; { property = Property.Cpu;
value = Sample.of_float (Float.of_string v) ; value = Sample.of_float (float_of_string v) ;
weight = Weight.of_float 1.; weight = Weight.of_float 1.;
compute_node = Compute_node.of_string c; compute_node = Compute_node.of_string c;
pid = Pid.of_string pid; pid = int_of_string pid;
block_id = Block_id.of_int (Int.of_string b); block_id = Block_id.of_int (int_of_string b);
} }
| [ "accep" ; c ; pid ; b ; "1" ; v ] -> | [ "accep" ; c ; pid ; b ; "1" ; v ] ->
let open Block in let open Block in
Property Property
{ property = Property.Accep; { property = Property.Accep;
value = Sample.of_float (Float.of_string v) ; value = Sample.of_float (float_of_string v) ;
weight = Weight.of_float 1.; weight = Weight.of_float 1.;
compute_node = Compute_node.of_string c; compute_node = Compute_node.of_string c;
pid = Pid.of_string pid; pid = int_of_string pid;
block_id = Block_id.of_int (Int.of_string b); block_id = Block_id.of_int (int_of_string b);
} }
| [ prop ; c ; pid ; b ; w ; v ] -> | [ prop ; c ; pid ; b ; w ; v ] ->
let open Block in let open Block in
Property Property
{ property = Property.of_string prop; { property = Property.of_string prop;
value = Sample.of_float (Float.of_string v); value = Sample.of_float (float_of_string v);
weight = Weight.of_float (Float.of_string w); weight = Weight.of_float (float_of_string w);
compute_node = Compute_node.of_string c; compute_node = Compute_node.of_string c;
pid = Pid.of_string pid; pid = int_of_string pid;
block_id = Block_id.of_int (Int.of_string b); block_id = Block_id.of_int (int_of_string b);
} }
| "elec_coord" :: c :: pid :: _ :: n ::walkers -> | "elec_coord" :: c :: pid :: _ :: n ::walkers ->
begin begin
let elec_num = let elec_num =
Lazy.force Qputils.elec_num Lazy.force Qputils.elec_num
and n = and n =
Int.of_string n int_of_string n
in in
assert (n = List.length walkers); assert (n = List.length walkers);
let rec build_walker accu = function let rec build_walker accu = function
| (0,tail) -> | (0,tail) ->
let result = let result =
List.rev accu List.rev accu
|> List.map ~f:Float.of_string |> List.map float_of_string
|> Array.of_list |> Array.of_list
in in
(result, tail) (result, tail)
@ -73,11 +72,11 @@ let create m =
in in
build (result::accu) tail build (result::accu) tail
in in
Walkers (Compute_node.of_string c, Pid.of_string pid, build [] walkers) Walkers (Compute_node.of_string c, int_of_string pid, build [] walkers)
end end
| [ "get_walkers" ; n ] -> GetWalkers (n |> Int.of_string |> Strictly_positive_int.of_int) | [ "get_walkers" ; n ] -> GetWalkers (n |> int_of_string |> Strictly_positive_int.of_int)
| [ "register" ; c ; pid ] -> Register (Compute_node.of_string c, Pid.of_string pid) | [ "register" ; c ; pid ] -> Register (Compute_node.of_string c, int_of_string pid)
| [ "unregister" ; c ; pid ] -> Unregister (Compute_node.of_string c, Pid.of_string pid) | [ "unregister" ; c ; pid ] -> Unregister (Compute_node.of_string c, int_of_string pid)
| [ "Test" ] -> Test | [ "Test" ] -> Test
| [ "Ezfio" ; ezfio_msg ] -> Ezfio ezfio_msg | [ "Ezfio" ; ezfio_msg ] -> Ezfio ezfio_msg
| prop :: c :: pid :: b :: d :: w :: l -> | prop :: c :: pid :: b :: d :: w :: l ->
@ -88,22 +87,22 @@ let create m =
assert (not (Property.is_scalar property)); assert (not (Property.is_scalar property));
let a = let a =
Array.of_list l Array.of_list l
|> Array.map ~f:Float.of_string |> Array.map float_of_string
and dim = and dim =
Int.of_string d int_of_string d
in in
assert (Array.length a = dim); assert (Array.length a = dim);
let open Block in let open Block in
Property Property
{ property = property ; { property = property ;
value = Sample.of_float_array ~dim a; value = Sample.of_float_array ~dim a;
weight = Weight.of_float (Float.of_string w); weight = Weight.of_float (float_of_string w);
compute_node = Compute_node.of_string c; compute_node = Compute_node.of_string c;
pid = Pid.of_string pid; pid = int_of_string pid;
block_id = Block_id.of_int (Int.of_string b); block_id = Block_id.of_int (int_of_string b);
} }
end end
| l -> Error (String.concat ~sep:":" l) | l -> Error (String.concat ":" l)
with with
| Assert_failure (l,_,_) -> Error l | Assert_failure (l,_,_) -> Error l
| _ -> Error "Unknown error" | _ -> Error "Unknown error"
@ -111,14 +110,13 @@ let create m =
let to_string = function let to_string = function
| Property b -> "Property : "^(Block.to_string b) | Property b -> "Property : "^(Block.to_string b)
| Walkers (h,p,w) -> Printf.sprintf "Walkers : %s %s : %d walkers" | Walkers (h,p,w) -> Printf.sprintf "Walkers : %s %d : %d walkers"
(Compute_node.to_string h) (Pid.to_string p) (Compute_node.to_string h) p (Array.length w)
(Array.length w)
| GetWalkers n -> Printf.sprintf "GetWalkers %d" (Strictly_positive_int.to_int n) | GetWalkers n -> Printf.sprintf "GetWalkers %d" (Strictly_positive_int.to_int n)
| Register (h,p) -> Printf.sprintf "Register : %s %s" | Register (h,p) -> Printf.sprintf "Register : %s %d"
(Compute_node.to_string h) (Pid.to_string p) (Compute_node.to_string h) p
| Unregister (h,p) -> Printf.sprintf "Unregister : %s %s" | Unregister (h,p) -> Printf.sprintf "Unregister : %s %d"
(Compute_node.to_string h) (Pid.to_string p) (Compute_node.to_string h) p
| Test -> "Test" | Test -> "Test"
| Ezfio msg -> "Ezfio "^msg | Ezfio msg -> "Ezfio "^msg
| Error msg -> "Error "^msg | Error msg -> "Error "^msg

View File

@ -1,5 +1,3 @@
open Core
(** Directory containing the list of input files. The directory is created is inexistant. *) (** Directory containing the list of input files. The directory is created is inexistant. *)
let input_directory = lazy ( let input_directory = lazy (
@ -12,9 +10,8 @@ let input_directory = lazy (
in in
begin begin
match ( Sys.is_directory dirname ) with if not (Sys.file_exists dirname) then
| `No -> Unix.mkdir dirname Unix.mkdir dirname 0o777
| _ -> ()
end ; end ;
dirname dirname
@ -83,14 +80,17 @@ let files_to_track = [
(** Get an MD5 ke from the content of a file. *) (** Get an MD5 ke from the content of a file. *)
let hash_file filename = let hash_file filename =
match Sys.is_file filename with if Sys.file_exists filename then
| `Yes ->
begin begin
In_channel.with_file filename ~f:(fun ic -> let ic = open_in filename in
let result =
Cryptokit.hash_channel (Cryptokit.Hash.md5 ()) ic Cryptokit.hash_channel (Cryptokit.Hash.md5 ()) ic
|> Cryptokit.transform_string (Cryptokit.Hexa.encode ()) ) |> Cryptokit.transform_string (Cryptokit.Hexa.encode ())
in
close_in ic;
result
end end
| _ -> "" else ""
(** Cache containing the current value of the MD5 hash. *) (** Cache containing the current value of the MD5 hash. *)
@ -111,9 +111,9 @@ let hash () =
in in
let md5_string = let md5_string =
files_to_track files_to_track
|> List.map ~f:(fun x -> Printf.sprintf "%s/%s" ezfio_filename x) |> List.map (fun x -> Printf.sprintf "%s/%s" ezfio_filename x)
|> List.map ~f:hash_file |> List.map hash_file
|> String.concat |> String.concat ""
in in
let new_md5 = let new_md5 =

View File

@ -1,22 +1,18 @@
open Core
(** QMC=Chem installation directory *) (** QMC=Chem installation directory *)
let root = lazy ( let root = lazy (
match ( Sys.getenv "QMCCHEM_PATH" ) with try Sys.getenv "QMCCHEM_PATH" with
| Some x -> x | Not_found -> failwith "QMCCHEM_PATH environment variable not set"
| None -> failwith "QMCCHEM_PATH environment variable not set"
) )
(* PATH environment variable as a list of strings *) (* PATH environment variable as a list of strings *)
let path = lazy ( let path = lazy (
let p = let p =
match Sys.getenv "PATH" with try Sys.getenv "PATH" with
| None -> failwith "PATH environment variable is not set" | Not_found -> failwith "PATH environment variable is not set"
| Some p -> p
in in
String.split ~on:':' p String.split_on_char ':' p
) )
@ -30,9 +26,10 @@ let full_path exe =
let fp = let fp =
Filename.concat head exe Filename.concat head exe
in in
match (Sys.is_file fp) with if Sys.file_exists fp then
| `Yes -> Some fp Some fp
| _ -> in_path_rec tail else
in_path_rec tail
end end
in in
Lazy.force path Lazy.force path
@ -42,7 +39,7 @@ let full_path exe =
(* True if an executable is in the PATH *) (* True if an executable is in the PATH *)
let in_path x = let in_path x =
match (full_path x) with match full_path x with
| Some _ -> true | Some _ -> true
| None -> false | None -> false
@ -51,13 +48,13 @@ let has_parallel = lazy( in_path "parallel" )
let has_mpirun = lazy( in_path "mpirun" ) let has_mpirun = lazy( in_path "mpirun" )
let has_srun = lazy( in_path "parallel" ) let has_srun = lazy( in_path "parallel" )
let has_qmc = lazy( in_path "qmc" ) let has_qmc = lazy( in_path "qmc" )
let has_qmc_mic = lazy( in_path "qmc_mic" )
let mpirun = lazy ( let mpirun = lazy (
match Sys.getenv "QMCCHEM_MPIRUN" with try
| None -> "mpirun" Sys.getenv "QMCCHEM_MPIRUN"
| Some p -> p with
| Not_found -> "mpirun"
) )
let qmcchem = lazy( let qmcchem = lazy(
@ -69,9 +66,7 @@ and qmc = lazy(
and qmcchem_info = lazy( and qmcchem_info = lazy(
Filename.concat (Lazy.force root) "bin/qmcchem_info" Filename.concat (Lazy.force root) "bin/qmcchem_info"
) )
and qmc_mic = lazy(
Filename.concat (Lazy.force root) "bin/qmc_mic"
)
and qmc_create_walkers = lazy( and qmc_create_walkers = lazy(
Filename.concat (Lazy.force root) "bin/qmc_create_walkers" Filename.concat (Lazy.force root) "bin/qmc_create_walkers"
) )
@ -87,28 +82,35 @@ let hostname = lazy (
) )
external get_ipv4_address_for_interface : string -> string =
"get_ipv4_address_for_interface"
let ip_address = lazy ( let ip_address = lazy (
match Sys.getenv "QMCCHEM_NIC" with let interface =
try Some (Sys.getenv "QMCCHEM_NIC")
with Not_found -> None
in
match interface with
| None -> | None ->
begin begin
try try
let host =
Lazy.force hostname Lazy.force hostname
|> Unix.Inet_addr.of_string_or_getbyname |> Unix.gethostbyname
|> Unix.Inet_addr.to_string in
Unix.string_of_inet_addr host.h_addr_list.(0);
with with
| Unix.Unix_error _ -> | Unix.Unix_error _ ->
failwith "Unable to find IP address from host name." failwith "Unable to find IP address from host name."
end end
| Some interface -> | Some interface ->
begin let result = get_ipv4_address_for_interface interface in
try if String.sub result 0 5 = "error" then
ok_exn Linux_ext.get_ipv4_address_for_interface interface Printf.sprintf "Unable to use network interface %s" interface
with |> failwith
| Unix.Unix_error _ -> else
Lazy.force hostname result
|> Unix.Inet_addr.of_string_or_getbyname
|> Unix.Inet_addr.to_string
end
) )

View File

@ -1,4 +1,3 @@
open Core
open Qptypes open Qptypes
(** Data server of QMC=Chem. (** Data server of QMC=Chem.
@ -35,20 +34,26 @@ let run ?(daemon=true) ezfio_filename =
if ( not(Ezfio.has_electrons_elec_coord_pool ()) ) then if ( not(Ezfio.has_electrons_elec_coord_pool ()) ) then
begin begin
Printf.printf "Generating initial walkers...\n%!"; Printf.printf "Generating initial walkers...\n%!";
Unix.fork_exec ~prog:(Lazy.force Qmcchem_config.qmc_create_walkers) match Unix.fork () with
~argv:["qmc_create_walkers" ; ezfio_filename] () | 0 ->
|> Unix.waitpid_exn ; Unix.execvp
(Lazy.force Qmcchem_config.qmc_create_walkers)
[|"qmc_create_walkers" ; ezfio_filename|]
| pid ->
begin
ignore @@ Unix.waitpid [] pid;
Printf.printf "Initial walkers ready\n%!" Printf.printf "Initial walkers ready\n%!"
end ; end
end
in in
(** Measures the time difference between [t0] and [Time.now ()] *) (** Measures the time difference between [t0] and [Unix.gettimeofday ()] *)
let delta_t t0 = let delta_t t0 =
let t1 = let t1 =
Time.now () Unix.gettimeofday ()
in in
Time.abs_diff t1 t0 t1 -. t0
in in
(** {2 ZeroMQ initialization} *) (** {2 ZeroMQ initialization} *)
@ -60,8 +65,7 @@ let run ?(daemon=true) ezfio_filename =
(** Maximum size of the blocks file before compressing *) (** Maximum size of the blocks file before compressing *)
let max_file_size = ref ( let max_file_size = ref ( 64 * 1024 )
Byte_units.create `Kilobytes 64.)
in in
@ -88,9 +92,9 @@ let run ?(daemon=true) ezfio_filename =
"tcp://*:" "tcp://*:"
in in
let result = let result =
List.fold [0;1;2;3] ~init:true ~f:(fun accu i -> List.fold_left (fun accu i ->
let address = let address =
adress_prefix ^ (Int.to_string (n+i)) adress_prefix ^ (string_of_int (n+i))
in in
let socket = let socket =
Zmq.Socket.create zmq_context Zmq.Socket.rep Zmq.Socket.create zmq_context Zmq.Socket.rep
@ -104,7 +108,7 @@ let run ?(daemon=true) ezfio_filename =
in in
Zmq.Socket.close socket; Zmq.Socket.close socket;
result result
) ) true [0;1;2;3]
in in
if (result) then if (result) then
`Available `Available
@ -145,8 +149,8 @@ let run ?(daemon=true) ezfio_filename =
delta_t t0 delta_t t0
in in
let message = let message =
Printf.sprintf "%20s : %8d : %10s : %s" Printf.sprintf "%20s : %8d : %10s : %e"
socket size text (Time.Span.to_string dt) socket size text dt
in in
Zmq.Socket.send debug_socket message Zmq.Socket.send debug_socket message
in in
@ -179,7 +183,7 @@ let run ?(daemon=true) ezfio_filename =
(** Array of walkers. The size is [walk_num_tot]. *) (** Array of walkers. The size is [walk_num_tot]. *)
let walkers_array = let walkers_array =
let t0 = let t0 =
Time.now () Unix.gettimeofday ()
in in
let j = let j =
3*elec_num + 3 3*elec_num + 3
@ -190,16 +194,16 @@ let run ?(daemon=true) ezfio_filename =
and ez = and ez =
Ezfio.get_electrons_elec_coord_pool () Ezfio.get_electrons_elec_coord_pool ()
|> Ezfio.flattened_ezfio |> Ezfio.flattened_ezfio
|> Array.map ~f:Float.to_string |> Array.map string_of_float
in in
try try
Array.init walk_num_tot ~f:(fun i -> Array.init walk_num_tot (fun i ->
Array.sub ~pos:(j*(i mod size)) ~len:j ez) Array.sub ez (j*(i mod size)) j )
with with
| Invalid_argument _ -> | Invalid_argument _ ->
failwith "Walkers file is broken." failwith "Walkers file is broken."
in in
String.concat [ "Read " ; Int.to_string (Array.length result) ; String.concat " " [ "Read" ; string_of_int (Array.length result) ;
"walkers"] "walkers"]
|> send_log "status" 0 t0 ; |> send_log "status" 0 t0 ;
result result
@ -214,28 +218,28 @@ let run ?(daemon=true) ezfio_filename =
(** Last time when the walkers were saved to disk. *) (** Last time when the walkers were saved to disk. *)
let last_save_walkers = let last_save_walkers =
ref (Time.now ()) ref (Unix.gettimeofday ())
in in
(** Saves the walkers to disk. *) (** Saves the walkers to disk. *)
let save_walkers () = let save_walkers () =
if (delta_t !last_save_walkers > (Time.Span.of_sec 10.) ) then if (delta_t !last_save_walkers > 10. ) then
begin begin
let t0 = let t0 =
Time.now () Unix.gettimeofday ()
in in
Ezfio.set_electrons_elec_coord_pool_size walk_num_tot ; Ezfio.set_electrons_elec_coord_pool_size walk_num_tot ;
let walkers_list = let walkers_list =
Array.map walkers_array ~f:Array.to_list Array.map Array.to_list walkers_array
|> Array.to_list |> Array.to_list
|> List.concat |> List.concat
|> List.map ~f:Float.of_string |> List.map float_of_string
in in
Ezfio.set_electrons_elec_coord_pool (Ezfio.ezfio_array_of_list Ezfio.set_electrons_elec_coord_pool (Ezfio.ezfio_array_of_list
~rank:3 ~dim:[| elec_num+1 ; 3 ; walk_num_tot |] ~data:walkers_list); ~rank:3 ~dim:[| elec_num+1 ; 3 ; walk_num_tot |] ~data:walkers_list);
send_log "status" walk_num_tot t0 "Saved walkers"; send_log "status" walk_num_tot t0 "Saved walkers";
last_save_walkers := Time.now (); last_save_walkers := Unix.gettimeofday ();
end end
in in
@ -245,7 +249,7 @@ let run ?(daemon=true) ezfio_filename =
disk if the array of walkers is filled. In that case, sets the last_walker to 0. disk if the array of walkers is filled. In that case, sets the last_walker to 0.
*) *)
let increment_last_walker () = let increment_last_walker () =
last_walker := !last_walker + 1; incr last_walker;
if (!last_walker = walk_num_tot) then if (!last_walker = walk_num_tot) then
begin begin
last_walker := 0 ; last_walker := 0 ;
@ -266,16 +270,16 @@ let run ?(daemon=true) ezfio_filename =
(** The hash table for workers *) (** The hash table for workers *)
let workers_hash = let workers_hash =
String.Table.create () Hashtbl.create 63
in in
(** Creates a key using the couple ([Compute_node], [PID]) *) (** Creates a key using the couple ([Compute_node], [PID]) *)
let key compute_node pid = let key compute_node pid =
String.concat [ String.concat " " [
(Compute_node.to_string compute_node); " "; (Compute_node.to_string compute_node);
(Pid.to_string pid) ] (string_of_int pid) ]
in in
@ -286,9 +290,9 @@ let run ?(daemon=true) ezfio_filename =
let s = let s =
key w pid key w pid
in in
match Hashtbl.add workers_hash ~key:s ~data:(Time.now ()) with match Hashtbl.find_opt workers_hash s with
| `Ok -> () | Some _ -> failwith (s^" already registered")
| `Duplicate -> failwith (s^" already registered") | None -> Hashtbl.add workers_hash s (Unix.gettimeofday ())
in in
@ -299,29 +303,33 @@ let run ?(daemon=true) ezfio_filename =
let s = let s =
key w pid key w pid
in in
match Hashtbl.find workers_hash s with match Hashtbl.find_opt workers_hash s with
| Some x -> Hashtbl.remove workers_hash s | Some x -> Hashtbl.remove workers_hash s
| None -> failwith (s^" not registered") | None -> failwith (s^" not registered")
in in
(** Sets the last access of the worker to [Time.now ()] *) (** Sets the last access of the worker to [Unix.gettimeofday ()] *)
let touch_worker w pid = let touch_worker w pid =
let s = let s =
key w pid key w pid
in in
Hashtbl.set workers_hash ~key:s ~data:(Time.now ()) Hashtbl.replace workers_hash s (Unix.gettimeofday ())
in in
(** Returns the number of connected workers *) (** Returns the number of connected workers *)
let n_connected hash now = let n_connected hash now =
let delta = let delta =
Time.Span.of_sec (initialization_timeout +. block_time *. 2.) initialization_timeout +. block_time *. 2.
in in
Hashtbl.filter hash ~f:(fun x -> (Time.abs_diff now x) <= delta) Hashtbl.fold (fun k v accu ->
|> Hashtbl.length if (now -. v) <= delta then
v :: accu
else
accu ) hash []
|> List.length
in in
@ -339,12 +347,11 @@ let run ?(daemon=true) ezfio_filename =
Lazy.force Block.dir_name Lazy.force Block.dir_name
in in
let () = let () =
match Sys.is_directory dirname with if not ( Sys.file_exists dirname ) then
| `Yes -> () Unix.mkdir dirname 0o755
| _ -> Unix.mkdir_p dirname
in in
Filename.concat dirname ( Filename.concat dirname (
hostname ^ "." ^ (Pid.to_string dataserver_pid) hostname ^ "." ^ (string_of_int dataserver_pid)
) )
in in
@ -361,14 +368,14 @@ let run ?(daemon=true) ezfio_filename =
(** [Out_channel] corresponding to the blocks file written by the current process. *) (** [Out_channel] corresponding to the blocks file written by the current process. *)
let block_channel = let block_channel =
try try
ref (Out_channel.create block_channel_filename_locked) ref (open_out block_channel_filename_locked)
with with
| Sys_error _ -> | Sys_error _ ->
begin begin
(* NFS Stale file handle : (* NFS Stale file handle :
* Wait 5 seconds, and retry *) * Wait 5 seconds, and retry *)
Time.Span.of_sec 5. |> Time.pause; Unix.sleep 5;
ref (Out_channel.create block_channel_filename_locked) ref (open_out block_channel_filename_locked)
end end
in in
@ -379,13 +386,16 @@ let run ?(daemon=true) ezfio_filename =
*) *)
let compress_block_file filename = let compress_block_file filename =
let t0 = let t0 =
Time.now () Unix.gettimeofday ()
in in
Out_channel.close !block_channel; close_out !block_channel;
Unix.rename ~src:block_channel_filename_locked ~dst:block_channel_filename_tmp; Unix.rename block_channel_filename_locked block_channel_filename_tmp;
Random_variable.compress_files (); Random_variable.compress_files ();
send_log "status" 0 t0 "Compressed block file"; send_log "status" 0 t0 "Compressed block file";
block_channel := Out_channel.create ~append:true block_channel_filename_locked if Sys.file_exists block_channel_filename_locked then
block_channel := open_out_gen [ Open_append ] 0o660 block_channel_filename_locked
else
block_channel := open_out block_channel_filename_locked
in in
@ -396,7 +406,7 @@ let run ?(daemon=true) ezfio_filename =
let start_status_thread = let start_status_thread =
let t0 = let t0 =
Time.now () Unix.gettimeofday ()
in in
Thread.create (fun () -> Thread.create (fun () ->
send_log "status" 0 t0 "Starting status thread"; send_log "status" 0 t0 "Starting status thread";
@ -407,16 +417,14 @@ let run ?(daemon=true) ezfio_filename =
Printf.sprintf "tcp://*:%d" (port+1) Printf.sprintf "tcp://*:%d" (port+1)
in in
bind_socket "PUB" socket address; bind_socket "PUB" socket address;
let delay = let delay = 0.3
Time.Span.of_ms 300. and delay_read = 2.
and delay_read =
Time.Span.of_sec 2.
in in
let start_time = let start_time =
Time.now () Unix.gettimeofday ()
and stop_time = and stop_time =
ref (Time.Span.of_sec Input.Stop_time.(read () |> to_float) ) ref (Input.Stop_time.(read () |> to_float) )
in in
let last_update = let last_update =
@ -425,9 +433,9 @@ let run ?(daemon=true) ezfio_filename =
while (!status <> Status.Stopped) while (!status <> Status.Stopped)
do do
Time.pause delay; Unix.sleepf delay;
let now = let now =
Time.now () Unix.gettimeofday ()
in in
let status_string = let status_string =
Status.to_string !status Status.to_string !status
@ -436,14 +444,14 @@ let run ?(daemon=true) ezfio_filename =
send_log "status" (String.length status_string) now status_string; send_log "status" (String.length status_string) now status_string;
let test = let test =
if (Time.abs_diff now !last_update > delay_read) then if (now -. !last_update > delay_read) then
let n_connect = let n_connect =
n_connected workers_hash now n_connected workers_hash now
in in
`Update n_connect `Update n_connect
else if (Time.abs_diff now start_time > !stop_time) then else if (now -. start_time > !stop_time) then
`Terminate `Terminate
else if (Time.abs_diff now start_time > Time.Span.of_sec initialization_timeout) then else if (now -. start_time > initialization_timeout) then
`Timeout `Timeout
else else
`None `None
@ -458,7 +466,7 @@ let run ?(daemon=true) ezfio_filename =
begin begin
status := Status.read (); status := Status.read ();
last_update := now; last_update := now;
stop_time := Time.Span.of_sec Input.Stop_time.(read () |> to_float) ; stop_time := Input.Stop_time.(read () |> to_float) ;
let n_tot = let n_tot =
Hashtbl.length workers_hash Hashtbl.length workers_hash
in in
@ -482,7 +490,7 @@ let run ?(daemon=true) ezfio_filename =
let start_log_thread = let start_log_thread =
let t0 = let t0 =
Time.now () Unix.gettimeofday ()
in in
Thread.create (fun () -> Thread.create (fun () ->
send_log "status" 0 t0 "Starting log thread"; send_log "status" 0 t0 "Starting log thread";
@ -509,10 +517,10 @@ let run ?(daemon=true) ezfio_filename =
begin begin
let message = let message =
Zmq.Socket.recv_all ~block:false socket Zmq.Socket.recv_all ~block:false socket
|> String.concat ~sep:" " |> String.concat " "
in in
let now = let now =
Time.now () Unix.gettimeofday ()
in in
send_log "log" 0 now message send_log "log" 0 now message
end end
@ -548,7 +556,7 @@ let run ?(daemon=true) ezfio_filename =
let start_main_thread = let start_main_thread =
let wall0 = let wall0 =
Time.now () Unix.gettimeofday ()
in in
let f () = let f () =
@ -569,19 +577,18 @@ let run ?(daemon=true) ezfio_filename =
(** EZFIO Cache *) (** EZFIO Cache *)
let ezfio_cache = let ezfio_cache =
String.Table.create () Hashtbl.create 63
in in
let handle_ezfio msg = let handle_ezfio msg =
match Hashtbl.find ezfio_cache msg with match Hashtbl.find_opt ezfio_cache msg with
| Some result -> result | Some result -> result
| None -> | None ->
begin begin
let result = let result =
decode_ezfio_message msg decode_ezfio_message msg
in in
match (Hashtbl.add ezfio_cache ~key:msg ~data:result) with Hashtbl.add ezfio_cache msg result;
| `Ok -> result result
| `Duplicate -> result
end end
in in
@ -620,13 +627,13 @@ let run ?(daemon=true) ezfio_filename =
Zmq.Socket.recv_all ~block:false rep_socket Zmq.Socket.recv_all ~block:false rep_socket
in in
let t0 = let t0 =
Time.now () Unix.gettimeofday ()
in in
let msg = let msg =
List.map ~f:String.strip raw_msg List.map String.trim raw_msg
|> Message.create |> Message.create
and msg_size = and msg_size =
List.fold ~init:0 ~f:(fun accu x -> accu + (String.length x)) raw_msg List.fold_left (fun accu x -> accu + (String.length x)) 0 raw_msg
in in
let handle = function let handle = function
| Message.Error _ -> () | Message.Error _ -> ()
@ -654,9 +661,9 @@ let run ?(daemon=true) ezfio_filename =
| Status.Queued | Status.Queued
| Status.Running -> | Status.Running ->
begin begin
String.concat [ "Register : " ; String.concat " " [ "Register :" ;
(Compute_node.to_string w) ; " " ; Compute_node.to_string w ;
(Pid.to_string pid) ] string_of_int pid ]
|> send_log "req" msg_size t0; |> send_log "req" msg_size t0;
add_worker w pid; add_worker w pid;
if (!status = Status.Queued) then if (!status = Status.Queued) then
@ -670,14 +677,14 @@ let run ?(daemon=true) ezfio_filename =
end end
| Message.Unregister (w,pid) -> | Message.Unregister (w,pid) ->
begin begin
String.concat [ "Unregister : " ; String.concat " " [ "Unregister :" ;
(Compute_node.to_string w) ; " " ; (Compute_node.to_string w) ;
(Pid.to_string pid) ] (string_of_int pid) ]
|> send_log "req" msg_size t0; |> send_log "req" msg_size t0;
Zmq.Socket.send rep_socket "OK"; Zmq.Socket.send rep_socket "OK";
del_worker w pid; del_worker w pid;
String.concat [ "Unregister : "; String.concat " " [ "Unregister :";
(Hashtbl.length workers_hash) |> Int.to_string ; (Hashtbl.length workers_hash) |> string_of_int ;
"remaining" ] "remaining" ]
|> send_log "rep" 2 t0 ; |> send_log "rep" 2 t0 ;
let n_connect = let n_connect =
@ -705,13 +712,13 @@ let run ?(daemon=true) ezfio_filename =
Zmq.Socket.recv_all ~block:false pull_socket Zmq.Socket.recv_all ~block:false pull_socket
in in
let t0 = let t0 =
Time.now () Unix.gettimeofday ()
in in
let msg = let msg =
List.map ~f:String.strip raw_msg List.map String.trim raw_msg
|> Message.create |> Message.create
and msg_size = and msg_size =
List.fold ~init:0 ~f:(fun accu x -> accu + (String.length x)) raw_msg List.fold_left (fun accu x -> accu + (String.length x)) 0 raw_msg
in in
let recv_log = let recv_log =
send_log "pull" msg_size t0 send_log "pull" msg_size t0
@ -730,22 +737,25 @@ let run ?(daemon=true) ezfio_filename =
recv_log log_msg ; recv_log log_msg ;
for i=0 to ((Array.length w)-1) for i=0 to ((Array.length w)-1)
do do
(*
Array.replace walkers_array (!last_walker) (fun _ -> Array.map Array.replace walkers_array (!last_walker) (fun _ -> Array.map
~f:Float.to_string w.(i)); string_of_float w.(i));
*)
walkers_array.(!last_walker) <- Array.map string_of_float w.(i);
increment_last_walker (); increment_last_walker ();
done; done;
let wall = let wall =
Printf.sprintf "%f %f # %s %s %s %d" Printf.sprintf "%f %f # %s %s %s %d"
(Time.Span.to_sec (Time.abs_diff (Time.now ()) wall0)) (Unix.gettimeofday () -. wall0)
1. (Property.to_string Property.Wall) 1. (Property.to_string Property.Wall)
hostname (Pid.to_string dataserver_pid) 1 hostname (string_of_int dataserver_pid) 1
|> Block.of_string |> Block.of_string
in in
match wall with match wall with
| Some wall -> | Some wall ->
begin begin
Out_channel.output_string !block_channel (Block.to_string wall); output_string !block_channel (Block.to_string wall);
Out_channel.output_char !block_channel '\n'; output_char !block_channel '\n';
end end
| _ -> () | _ -> ()
end end
@ -753,8 +763,8 @@ let run ?(daemon=true) ezfio_filename =
begin begin
if (status = Status.Running) then if (status = Status.Running) then
touch_worker b.Block.compute_node b.Block.pid ; touch_worker b.Block.compute_node b.Block.pid ;
Out_channel.output_string !block_channel (Block.to_string b); output_string !block_channel (Block.to_string b);
Out_channel.output_char !block_channel '\n'; output_char !block_channel '\n';
recv_log (Block.to_string b) recv_log (Block.to_string b)
end end
| Message.Test | Message.Test
@ -780,22 +790,20 @@ let run ?(daemon=true) ezfio_filename =
| Some Zmq.Poll.In -> handle_rep () | Some Zmq.Poll.In -> handle_rep ()
| _ -> | _ ->
begin begin
Out_channel.flush !block_channel ; flush !block_channel ;
let file_size = let file_size =
(Unix.stat block_channel_filename_locked).Unix.st_size (Unix.stat block_channel_filename_locked).Unix.st_size
|> Float.of_int64
|> Byte_units.create `Bytes
in in
if (file_size > !max_file_size) then if (file_size > !max_file_size) then
begin begin
compress_block_file (); compress_block_file ();
max_file_size := Byte_units.scale file_size 1.2; max_file_size := (file_size * 12) / 10;
end end
end end
end end
done; done;
List.iter ~f:(fun socket -> List.iter (fun socket ->
Zmq.Socket.set_linger_period socket 1000 ; Zmq.Socket.set_linger_period socket 1000 ;
Zmq.Socket.close socket) Zmq.Socket.close socket)
[ rep_socket ; pull_socket ] [ rep_socket ; pull_socket ]
@ -819,8 +827,8 @@ let run ?(daemon=true) ezfio_filename =
Zmq.Context.terminate zmq_context; Zmq.Context.terminate zmq_context;
begin begin
try try
Out_channel.close !block_channel; close_out !block_channel;
Unix.remove block_channel_filename_locked Unix.unlink block_channel_filename_locked
with with
| _ -> () | _ -> ()
end; end;
@ -830,27 +838,28 @@ let run ?(daemon=true) ezfio_filename =
(** {3 Main function} *) (** {3 Main function} *)
let t0 = let t0 =
Time.now () Unix.gettimeofday ()
in in
(* Handle signals *) (* Handle signals *)
let handler s = let handler s =
Printf.printf "Dataserver received the %s signal... killing\n%!" (Signal.to_string s); Printf.printf "Dataserver received signal %d... killing\n%!" s;
Watchdog.kill (); Watchdog.kill ();
in in
List.iter [ List.iter (fun s -> ignore @@ Sys.signal s (Sys.Signal_handle handler))
Signal.int ; [
Signal.term ; Sys.sigint ;
Signal.quit ; Sys.sigterm ;
Sys.sigquit ;
] ]
~f:(fun x -> Signal.Expert.handle x handler)
; ;
(* Run threads *) (* Run threads *)
begin begin
try try
(List.iter ~f:Thread.join (List.iter Thread.join
[ start_status_thread () ; [ start_status_thread () ;
start_log_thread () ; start_log_thread () ;
start_main_thread () ; start_main_thread () ;
@ -860,7 +869,7 @@ let run ?(daemon=true) ezfio_filename =
begin begin
print_endline "Trapped error. Waiting 10 seconds..."; print_endline "Trapped error. Waiting 10 seconds...";
change_status Status.Stopping; change_status Status.Stopping;
Time.Span.of_sec 10. |> Time.pause; Unix.sleep 10;
finalize ~t0; finalize ~t0;
raise err raise err
end end

View File

@ -1,6 +1,3 @@
open Core
let run ~t ezfio_filename= let run ~t ezfio_filename=
Qputils.set_ezfio_filename ezfio_filename; Qputils.set_ezfio_filename ezfio_filename;
@ -20,9 +17,9 @@ let run ~t ezfio_filename=
let address = let address =
match (Ezfio.get_simulation_http_server () match (Ezfio.get_simulation_http_server ()
|> String.rsplit2 ~on:':' ) |> String_ext.rsplit2 ~on:':' )
with with
| Some (a,p) -> a^":"^( (Int.of_string p)+4 |> Int.to_string ) | Some (a,p) -> a^":"^( (int_of_string p)+4 |> string_of_int )
| None -> failwith "Badly formed address" | None -> failwith "Badly formed address"
in in
Zmq.Socket.connect socket address; Zmq.Socket.connect socket address;
@ -34,7 +31,7 @@ let run ~t ezfio_filename=
Str.regexp " *: *" Str.regexp " *: *"
in in
let tot_size = let tot_size =
ref (Byte_units.create `Bytes 0.) ref 0.
in in
while true while true
do do
@ -44,12 +41,12 @@ let run ~t ezfio_filename=
let (socket, bytes) = let (socket, bytes) =
match Str.split re_split msg with match Str.split re_split msg with
| socket :: bytes :: _ -> | socket :: bytes :: _ ->
(socket, Byte_units.create `Bytes (Float.of_string bytes)) (socket, float_of_string bytes)
| _ -> (print_endline msg ; ("", Byte_units.create `Bytes 0.)) | _ -> (print_endline msg ; ("", 0.))
in in
tot_size := Byte_units.create `Bytes ((Byte_units.bytes !tot_size) +. (Byte_units.bytes bytes)); tot_size := !tot_size +. bytes;
Printf.printf "%s\n%!" (Byte_units.to_string !tot_size); Printf.printf "%f\n%!" !tot_size;
Time.pause (Time.Span.of_sec 1.) Unix.sleep 1
done done
end end
else else
@ -65,20 +62,29 @@ let run ~t ezfio_filename=
let spec = let command () =
let open Command.Spec in let open Command_line in
empty begin
+> flag "t" no_arg set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command");
~doc:"Measure the throughput" set_description_doc "Debug ZeroMQ communications";
+> anon ("ezfio_file" %: string) [ { short='t' ; long="traffic" ; opt=Optional ;
doc="Print traffic in bytes" ;
arg=Without_arg } ;
anonymous "EZFIO_DIR" Mandatory "EZFIO directory" ]
|> set_specs
end;
let t = Command_line.get_bool "traffic" in
let ezfio_file =
match Command_line.anon_args () with
| ezfio_file :: [] -> ezfio_file
| _ -> (Command_line.help () ; failwith "Inconsistent command line")
in
run t ezfio_file
let command =
Command.basic_spec
~summary: "Debug ZeroMQ communications"
~readme:(fun () -> "Gets debug information from the Zmq debug sockets.")
spec
(fun t ezfio_file () -> run t ezfio_file)

View File

@ -1,5 +1,3 @@
open Core
let file_header filename = Printf.sprintf let file_header filename = Printf.sprintf
" "
+----------------------------------------------------------------+ +----------------------------------------------------------------+
@ -12,7 +10,7 @@ Editing file `%s`
let make_header s = let make_header s =
let l = String.length s in let l = String.length s in
"\n\n"^s^"\n"^(String.init l ~f:(fun _ -> '='))^"\n\n" "\n\n"^s^"\n"^(String.init l (fun _ -> '='))^"\n\n"
type field = type field =
@ -84,11 +82,11 @@ let create_temp_file ?temp_filename ezfio_filename fields =
| None -> Filename.temp_file "qmcchem_edit_" ".rst" | None -> Filename.temp_file "qmcchem_edit_" ".rst"
| Some name -> name | Some name -> name
in in
Out_channel.with_file filename ~f:(fun out_channel -> let out_channel = open_out filename in
(file_header ezfio_filename) :: (List.map ~f:get fields) (file_header ezfio_filename) :: (List.map get fields)
|> String.concat ~sep:"\n" |> String.concat "\n"
|> Out_channel.output_string out_channel |> output_string out_channel
) ; close_out out_channel
; filename ; filename
@ -104,7 +102,7 @@ let write_input_in_ezfio ezfio_filename fields =
let input_filename = let input_filename =
create_temp_file ~temp_filename ezfio_filename fields create_temp_file ~temp_filename ezfio_filename fields
in in
assert (Sys.file_exists_exn input_filename) assert (Sys.file_exists input_filename)
(** Run the edit command *) (** Run the edit command *)
@ -133,19 +131,19 @@ let run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename =
in (); in ();
in in
handle_option Input.Ref_energy.(of_float , write) e; handle_option Input.Ref_energy.(of_string, write) e;
handle_option Input.Trial_wf_energy.(of_float , write) et; handle_option Input.Trial_wf_energy.(of_string, write) et;
handle_option Input.Jastrow_type.(of_string, write) j; handle_option Input.Jastrow_type.(of_string, write) j;
handle_option Input.Block_time.(of_int , write) l; handle_option Input.Block_time.(of_string, write) l;
handle_option Input.Method.(of_string, write) m; handle_option Input.Method.(of_string, write) m;
handle_option Input.Stop_time.(of_int , write) t; handle_option Input.Stop_time.(of_string, write) t;
handle_option Input.Sampling.(of_string, write) s; handle_option Input.Sampling.(of_string, write) s;
handle_option Input.Fitcusp_factor.(of_float , write) f; handle_option Input.Fitcusp_factor.(of_string, write) f;
handle_option Input.Time_step.(of_float , write) ts; handle_option Input.Time_step.(of_string, write) ts;
handle_option Input.Walk_num.(of_int , write) w; handle_option Input.Walk_num.(of_string, write) w;
handle_option Input.Walk_num_tot.(of_int , write) wt; handle_option Input.Walk_num_tot.(of_string, write) wt;
handle_option Input.CI_threshold.(of_float , write) n; handle_option Input.CI_threshold.(of_string, write) n;
handle_option Input.SRMC_projection_time.(of_float , write) p; handle_option Input.SRMC_projection_time.(of_string, write) p;
let fields = let fields =
@ -179,21 +177,24 @@ let run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename =
if (not !interactive) then if (not !interactive) then
failwith "Input file not allowed with command line arguments" failwith "Input file not allowed with command line arguments"
else else
begin let rc =
Printf.sprintf "cp %s %s" filename temp_filename Printf.sprintf "cp %s %s" filename temp_filename
|> Sys.command_exn ; |> Sys.command
end in
assert (rc = 0)
end end
| None -> | None ->
begin begin
(* Open the temp file with external editor *) (* Open the temp file with external editor *)
let editor = let editor =
match Sys.getenv "EDITOR" with try Sys.getenv "EDITOR" with
| Some editor -> editor | Not_found -> "vi"
| None -> "vi"
in in
let rc =
Printf.sprintf "%s %s ; tput sgr0 2> /dev/null" editor temp_filename Printf.sprintf "%s %s ; tput sgr0 2> /dev/null" editor temp_filename
|> Sys.command_exn |> Sys.command
in
assert (rc = 0)
end end
in in
@ -203,18 +204,20 @@ let run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename =
and re_prop = and re_prop =
Str.regexp "([ xX]) .*$" Str.regexp "([ xX]) .*$"
and raw_data = and raw_data =
In_channel.with_file temp_filename ~f:In_channel.input_lines let ic = open_in temp_filename in
let result = String_ext.input_lines ic in
close_in ic ; result
in in
let data = let data =
( List.filter raw_data ~f:(fun x -> Str.string_match re_data x 0) ( List.filter (fun x -> Str.string_match re_data x 0) raw_data
|> List.map ~f:String.strip ) @ |> List.map String.trim ) @
[ [
List.filter raw_data ~f:(fun x -> Str.string_match re_prop x 0) List.filter (fun x -> Str.string_match re_prop x 0) raw_data
|> List.map ~f:String.strip |> List.map String.trim
|> String.concat ~sep:"\n" ] |> String.concat "\n" ]
in in
let open Input in let open Input in
List.iter2_exn data fields ~f:(fun s f -> List.iter2 (fun s f ->
try try
begin begin
match f with match f with
@ -235,7 +238,7 @@ let run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename =
end end
with with
| Failure msg -> Printf.eprintf "%s\n" msg | Failure msg -> Printf.eprintf "%s\n" msg
); ) data fields ;
(* Remove temp_file *) (* Remove temp_file *)
Sys.remove temp_filename; Sys.remove temp_filename;
@ -249,19 +252,18 @@ let run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename =
Filename.concat (Filename.concat ezfio_filename "blocks") (QmcMd5.hash ()) Filename.concat (Filename.concat ezfio_filename "blocks") (QmcMd5.hash ())
in in
let rec clean_dir y = let rec clean_dir y =
match Sys.is_directory y with if Sys.file_exists y && Sys.is_directory y then
| `Yes -> begin
Sys.ls_dir y Sys.readdir y
|> List.map ~f:(Filename.concat y) |> Array.map (fun x -> Filename.concat y x)
|> List.iter ~f:(function x -> |> Array.iter (function x ->
match ( Sys.is_directory x, Sys.is_file x ) with if Sys.file_exists x && Sys.is_directory x then
| (`Yes, _) -> clean_dir x clean_dir x
| (_, `Yes) -> Sys.remove x else
| (_,_) -> () Sys.remove x
); );
Unix.rmdir y Unix.rmdir y
| `Unknown end
| `No -> ()
in clean_dir dirname; in clean_dir dirname;
Printf.printf "Blocks cleared\n" Printf.printf "Blocks cleared\n"
end end
@ -272,51 +274,96 @@ let run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename =
write_input_in_ezfio ezfio_filename fields write_input_in_ezfio ezfio_filename fields
let spec = let command () =
let open Command.Spec in let open Command_line in
empty begin
+> flag "c" no_arg set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command");
~doc:(" Clear blocks") set_description_doc "Edits input data";
+> flag "f" (optional float)
~doc:("float "^Input.Fitcusp_factor.doc)
+> flag "t" (optional int)
~doc:("seconds "^Input.Stop_time.doc)
+> flag "l" (optional int)
~doc:("seconds "^Input.Block_time.doc)
+> flag "m" (optional string)
~doc:("method "^Input.Method.doc)
+> flag "e" (optional float)
~doc:("energy "^Input.Ref_energy.doc)
+> flag "et" (optional float)
~doc:("energy "^Input.Trial_wf_energy.doc)
+> flag "s" (optional string)
~doc:("sampling "^Input.Sampling.doc)
+> flag "ts" (optional float)
~doc:("time_step "^Input.Time_step.doc)
+> flag "w" (optional int)
~doc:("walk_num "^Input.Walk_num.doc)
+> flag "wt" (optional int)
~doc:("walk_num_tot "^Input.Walk_num_tot.doc)
+> flag "n" (optional float)
~doc:("norm "^Input.CI_threshold.doc)
+> flag "j" (optional string)
~doc:("jastrow_type "^Input.Jastrow_type.doc)
+> flag "p" (optional float)
~doc:("projection_time "^Input.SRMC_projection_time.doc)
+> anon ("ezfio_file" %: string)
+> anon (maybe ("input" %: string))
;;
let command = [ { short='c' ; long="clear" ; opt=Optional ;
Command.basic_spec doc="Clears blocks" ;
~summary: "Edit input data" arg=Without_arg ; };
~readme:(fun () ->
" { short='e' ; long="ref-energy" ; opt=Optional ;
Edit input data doc=Input.Ref_energy.doc;
") arg=With_arg "<float>"; };
spec
(fun c f t l m e et s ts w wt n j p ezfio_file input () -> { short='f' ; long="fitcusp" ; opt=Optional ;
run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_file ) doc=Input.Fitcusp_factor.doc;
arg=With_arg "<float>"; };
{ short='i' ; long="time-step" ; opt=Optional ;
doc=Input.Time_step.doc;
arg=With_arg "<float>"; };
{ short='j' ; long="jastrow" ; opt=Optional ;
doc=Input.Jastrow_type.doc;
arg=With_arg "<string>"; };
{ short='l' ; long="block-time" ; opt=Optional ;
doc=Input.Block_time.doc;
arg=With_arg "<int>"; };
{ short='m' ; long="method" ; opt=Optional ;
doc=Input.Method.doc;
arg=With_arg "<string>"; };
{ short='n' ; long="norm" ; opt=Optional ;
doc=Input.CI_threshold.doc;
arg=With_arg "<float>"; };
{ short='p' ; long="projection-time" ; opt=Optional ;
doc=Input.SRMC_projection_time.doc;
arg=With_arg "<float>"; };
{ short='r' ; long="trial-energy" ; opt=Optional ;
doc=Input.Trial_wf_energy.doc;
arg=With_arg "<float>"; };
{ short='s' ; long="sampling" ; opt=Optional ;
doc=Input.Sampling.doc;
arg=With_arg "<string>"; };
{ short='t' ; long="stop-time" ; opt=Optional ;
doc=Input.Stop_time.doc;
arg=With_arg "<int>"; };
{ short='w' ; long="walk-num" ; opt=Optional ;
doc=Input.Walk_num.doc;
arg=With_arg "<int>"; };
{ short='x' ; long="walk-num-tot" ; opt=Optional ;
doc=Input.Walk_num_tot.doc;
arg=With_arg "<int>"; };
anonymous "EZFIO_DIR" Mandatory "EZFIO directory";
anonymous "FILE" Optional "Name of the input file";
]
|> set_specs
end;
let c = Command_line.get_bool "clear" in
let f = Command_line.get "fitcusp" in
let t = Command_line.get "stop-time" in
let l = Command_line.get "block-time" in
let m = Command_line.get "method" in
let e = Command_line.get "ref-energy" in
let et = Command_line.get "trial-energy" in
let s = Command_line.get "stop-time" in
let ts = Command_line.get "time-step" in
let w = Command_line.get "walk-num" in
let wt = Command_line.get "walk-num-tot" in
let n = Command_line.get "norm" in
let j = Command_line.get "jastrow" in
let p = Command_line.get "projection-time" in
let ezfio_file, input =
match Command_line.anon_args () with
| ezfio_file :: [] -> ezfio_file, None
| ezfio_file :: file :: [] -> ezfio_file, (Some file)
| _ -> (Command_line.help () ; failwith "Inconsistent command line")
in
run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_file

View File

@ -1,5 +1,3 @@
open Core
let bind_socket ~socket_type ~socket ~address = let bind_socket ~socket_type ~socket ~address =
let rec loop = function let rec loop = function
| 0 -> failwith @@ Printf.sprintf | 0 -> failwith @@ Printf.sprintf
@ -11,7 +9,7 @@ let bind_socket ~socket_type ~socket ~address =
Zmq.Socket.bind socket address; Zmq.Socket.bind socket address;
loop (-1) loop (-1)
with with
| Unix.Unix_error _ -> (Time.pause @@ Time.Span.of_sec 1. ; loop (i-1) ) | Unix.Unix_error _ -> (Unix.sleep 1 ; loop (i-1) )
| other_exception -> raise other_exception | other_exception -> raise other_exception
in loop 10 in loop 10
@ -20,9 +18,8 @@ let bind_socket ~socket_type ~socket ~address =
let run ezfio_filename dataserver = let run ezfio_filename dataserver =
let dataserver_address, dataserver_port = let dataserver_address, dataserver_port =
Substring.create ~pos:6 (Bytes.of_string dataserver) String.sub dataserver 6 (String.length dataserver - 6)
|> Substring.to_string |> String_ext.lsplit2_exn ~on:':'
|> String.lsplit2_exn ~on:':'
and qmc = and qmc =
Lazy.force Qmcchem_config.qmc Lazy.force Qmcchem_config.qmc
in in
@ -36,14 +33,14 @@ let run ezfio_filename dataserver =
(* Port of the data server *) (* Port of the data server *)
let port = let port =
(Int.of_string dataserver_port)+10 (int_of_string dataserver_port)+10
in in
(* Build qmc executable command *) (* Build qmc executable command *)
let prog, argv = let prog, argv =
qmc, qmc,
[ qmc ; ezfio_filename ; [| qmc ; ezfio_filename ;
Printf.sprintf "ipc://%s:%d" Qmcchem_config.dev_shm port ]; Printf.sprintf "ipc://%s:%d" Qmcchem_config.dev_shm port |];
in in
(* Create the temporary directory. If it is possible, then the process is a (* Create the temporary directory. If it is possible, then the process is a
@ -51,47 +48,44 @@ let run ezfio_filename dataserver =
*) *)
let () = let () =
try try
Unix.mkdir tmpdir; Unix.mkdir tmpdir 0o755;
Unix.chdir tmpdir Unix.chdir tmpdir
with with
| Unix.Unix_error _ -> | Unix.Unix_error _ ->
begin begin
Unix.chdir tmpdir; Unix.chdir tmpdir;
Time.pause @@ Time.Span.of_sec 0.1; Unix.sleepf 0.1 ;
match (Sys.file_exists "PID") with if Sys.file_exists "PID" then
| `No begin
| `Unknown -> ()
| `Yes ->
let pid = let pid =
In_channel.with_file "PID" ~f:(fun ic -> let ic = open_in "PID" in
match (In_channel.input_line ic) with try
| Some x -> x int_of_string (input_line ic)
| None -> "-1" ) with
|> Int.of_string | End_of_file -> -1
in in
match pid with match pid with
| -1 -> () | -1 -> ()
| pid -> | pid ->
begin try
match Signal.send (Signal.of_system_int 0) (`Pid (Pid.of_int pid)) with Unix.kill pid 0 ;
| `No_such_process -> () ignore @@ Unix.execvp prog argv
| _ -> ignore @@ Unix.exec ~prog ~argv () with
| Unix.Unix_error (Unix.ESRCH, _, _) -> ()
end end
end end
in in
(* Now, only one forwarder will execute the following code *) (* Now, only one forwarder will execute the following code *)
Out_channel.with_file "PID" ~f:(fun oc -> let oc = open_out "PID" in
Unix.getpid () Unix.getpid ()
|> Pid.to_int
|> Printf.sprintf "%d\n" |> Printf.sprintf "%d\n"
|> Out_channel.output_string oc); |> output_string oc
;
(* Fork a qmc *) (* Fork a qmc *)
ignore @@ ignore @@
Watchdog.fork_exec ~prog ~argv (); Watchdog.fork_exec ~prog ~args:argv ();
(* If there are MICs, use them here (TODO) *)
(* Fetch input *) (* Fetch input *)
let zmq_context = let zmq_context =
@ -104,9 +98,10 @@ let run ezfio_filename dataserver =
let command = let command =
Printf.sprintf "rm -rf -- \"%s\" " tmpdir Printf.sprintf "rm -rf -- \"%s\" " tmpdir
in in
match Unix.system command with try
| Ok _ -> () ignore @@ Unix.system command
| _ -> print_endline "Unable to remove temporary directory" with
| Unix.Unix_error _ -> print_endline "Unable to remove temporary directory"
; ;
Zmq.Context.terminate zmq_context ; Zmq.Context.terminate zmq_context ;
for i=port to port+4 for i=port to port+4
@ -126,15 +121,15 @@ let run ezfio_filename dataserver =
(* Signal handler to Kill properly all the processes *) (* Signal handler to Kill properly all the processes *)
let handler s = let handler s =
Printf.printf "Forwarder received the %s signal... killing\n%!" (Signal.to_string s); Printf.printf "Forwarder received signal %d... killing\n%!" s;
terminate (); terminate ();
in in
List.iter [ List.iter (fun s -> ignore @@ Sys.signal s (Sys.Signal_handle handler))
Signal.int ; [
Signal.term ; Sys.sigint ;
Signal.quit ; Sys.sigterm ;
Sys.sigquit ;
] ]
~f:(fun x -> Signal.Expert.handle x handler)
; ;
@ -189,7 +184,7 @@ let run ezfio_filename dataserver =
status := Status.of_string msg; status := Status.of_string msg;
end; end;
done; done;
List.iter ~f:(fun socket -> List.iter (fun socket ->
Zmq.Socket.set_linger_period socket 1000 ; Zmq.Socket.set_linger_period socket 1000 ;
Zmq.Socket.close socket) Zmq.Socket.close socket)
[ sub_socket ; pub_socket ] [ sub_socket ; pub_socket ]
@ -239,7 +234,7 @@ let run ezfio_filename dataserver =
|> Zmq.Socket.send sub_socket ; |> Zmq.Socket.send sub_socket ;
end end
done; done;
List.iter ~f:(fun socket -> List.iter (fun socket ->
Zmq.Socket.set_linger_period socket 1000 ; Zmq.Socket.set_linger_period socket 1000 ;
Zmq.Socket.close socket) Zmq.Socket.close socket)
[ sub_socket ; pub_socket ] [ sub_socket ; pub_socket ]
@ -268,7 +263,7 @@ let run ezfio_filename dataserver =
Zmq.Socket.set_linger_period dealer_socket 600_000; Zmq.Socket.set_linger_period dealer_socket 600_000;
let fetch_walkers () = let fetch_walkers () =
Zmq.Socket.send_all req_socket ["get_walkers" ; Int.to_string !walk_num ]; Zmq.Socket.send_all req_socket ["get_walkers" ; string_of_int !walk_num ];
Zmq.Socket.recv_all req_socket Zmq.Socket.recv_all req_socket
in in
@ -280,10 +275,10 @@ let run ezfio_filename dataserver =
(* EZFIO Cache *) (* EZFIO Cache *)
let ezfio_cache = let ezfio_cache =
String.Table.create () Hashtbl.create 63
in in
let handle_ezfio msg = let handle_ezfio msg =
match Hashtbl.find ezfio_cache msg with match Hashtbl.find_opt ezfio_cache msg with
| Some result -> result | Some result -> result
| None -> | None ->
begin begin
@ -291,9 +286,8 @@ let run ezfio_filename dataserver =
let result = let result =
Zmq.Socket.recv_all req_socket Zmq.Socket.recv_all req_socket
in in
match (Hashtbl.add ezfio_cache ~key:msg ~data:result) with Hashtbl.add ezfio_cache msg result;
| `Ok -> result result
| `Duplicate -> result
end end
in in
@ -315,7 +309,7 @@ let run ezfio_filename dataserver =
| head :: tail -> aux (head::header) tail | head :: tail -> aux (head::header) tail
| _ -> failwith "Too many routers in the middle" | _ -> failwith "Too many routers in the middle"
in in
aux [] (List.map ~f:String.strip raw_msg) aux [] (List.map String.trim raw_msg)
in in
let handle message = let handle message =
match message with match message with
@ -407,7 +401,7 @@ let run ezfio_filename dataserver =
| head :: tail -> aux (head::header) tail | head :: tail -> aux (head::header) tail
| _ -> failwith "Too many routers in the middle" | _ -> failwith "Too many routers in the middle"
in in
aux [] (List.map ~f:String.strip raw_msg) aux [] (List.map String.trim raw_msg)
in in
let handle message = let handle message =
match message with match message with
@ -469,16 +463,17 @@ let run ezfio_filename dataserver =
match message with match message with
| "elec_coord":: hostname :: pid :: id :: n_str :: rest -> | "elec_coord":: hostname :: pid :: id :: n_str :: rest ->
let n = let n =
Int.of_string n_str int_of_string n_str
in in
let len = let len =
if !walk_num = 0 then n else
n / !walk_num n / !walk_num
in in
if (n < 5*len) then if (n < 5*len) then
message message
else else
List.concat [ [ "elec_coord" ; hostname ; pid ; id ; List.concat [ [ "elec_coord" ; hostname ; pid ; id ;
Int.to_string (5*len)] ; ( select_n_of ~n:5 ~len rest ) ] string_of_int (5*len)] ; ( select_n_of ~n:5 ~len rest ) ]
| _ -> message | _ -> message
in in
Zmq.Socket.send_all push_socket new_message Zmq.Socket.send_all push_socket new_message
@ -508,7 +503,7 @@ let run ezfio_filename dataserver =
if (polling.(3) = Some Zmq.Poll.In) then if (polling.(3) = Some Zmq.Poll.In) then
handle_proxy (); handle_proxy ();
done; done;
List.iter ~f:(fun socket -> List.iter (fun socket ->
Zmq.Socket.set_linger_period socket 1000 ; Zmq.Socket.set_linger_period socket 1000 ;
Zmq.Socket.close socket) Zmq.Socket.close socket)
[ router_socket ; dealer_socket ; push_socket ; pull_socket ; proxy_socket ] [ router_socket ; dealer_socket ; push_socket ; pull_socket ; proxy_socket ]
@ -520,7 +515,7 @@ let run ezfio_filename dataserver =
(* Start the status thread and the main thread *) (* Start the status thread and the main thread *)
begin begin
try try
(List.iter ~f:Thread.join (List.iter Thread.join
[ start_status_thread (); [ start_status_thread ();
start_log_thread (); start_log_thread ();
start_proxy_thread (); start_proxy_thread ();
@ -531,7 +526,7 @@ let run ezfio_filename dataserver =
begin begin
print_endline "Trapped error. Waiting 10 seconds..."; print_endline "Trapped error. Waiting 10 seconds...";
status := Status.Stopping; status := Status.Stopping;
Time.Span.of_sec 10. |> Time.pause; Unix.sleep 10 ;
raise err raise err
end end
end; end;

View File

@ -1,4 +1,3 @@
open Core
let run ezfio_filename = let run ezfio_filename =
@ -8,25 +7,25 @@ let run ezfio_filename =
in in
let prog, argv = let prog, argv =
qmcchem_info, qmcchem_info,
[ qmcchem_info ; ezfio_filename ] [| qmcchem_info ; ezfio_filename |]
in in
ignore @@ ignore @@
Unix.exec ~prog ~argv () Unix.execvp prog argv
let command () =
let open Command_line in
begin
set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command");
set_description_doc "Display info on an EZFIO database";
[ anonymous "EZFIO_DIR" Mandatory "EZFIO directory" ]
|> set_specs
end;
let spec = let ezfio_file =
let open Command.Spec in match Command_line.anon_args () with
empty | ezfio_file :: [] -> ezfio_file
+> anon ("ezfio_file" %: string) | _ -> (Command_line.help () ; failwith "Inconsistent command line")
in
let command =
Command.basic_spec
~summary: "Display info on an EZFIO database"
~readme:(fun () ->
"
Display info on an EZFIO database
")
spec
(fun ezfio_file () -> run ezfio_file )
run ezfio_file

View File

@ -1,4 +1,3 @@
open Core
let run ?c ?d ~l ~update ezfio_filename = let run ?c ?d ~l ~update ezfio_filename =
@ -22,7 +21,7 @@ let run ?c ?d ~l ~update ezfio_filename =
let filename = let filename =
filename_of_key key filename_of_key key
in in
Sys.file_exists_exn filename Sys.file_exists filename
in in
if (update) then if (update) then
@ -37,27 +36,28 @@ let run ?c ?d ~l ~update ezfio_filename =
if (old_key <> new_key) then if (old_key <> new_key) then
begin begin
let prefix =
Filename.concat ezfio_filename "blocks"
in
let new_name = let new_name =
String.concat ~sep:"/" [ ezfio_filename; "blocks"; new_key ] Filename.concat prefix new_key
and old_name = and old_name =
String.concat ~sep:"/" [ ezfio_filename; "blocks"; old_key ] Filename.concat prefix old_key
in in
Printf.printf "Renaming %s -> %s\n" old_name new_name; Printf.printf "Renaming %s -> %s\n" old_name new_name;
try Sys.rename old_name new_name with try Sys.rename old_name new_name with
| Sys_error _ -> (); | Sys_error _ -> ();
let old_name = let old_name =
String.concat ~sep:"/" [ ezfio_filename; "input"; old_key ] String.concat "/" [ ezfio_filename; "input"; old_key ]
in in
Printf.printf "Removing %s\n%!" old_name; Printf.printf "Removing %s\n%!" old_name;
try Sys.remove old_name with try Sys.remove old_name with
| Sys_error _ -> (); | Sys_error _ -> ();
end end
in in
let l = Sys.readdir input_directory
Sys.ls_dir input_directory |> Array.iter (fun x -> update_one x) ;
in
List.iter l ~f:(fun x -> update_one x) ;
Printf.printf "Done\n%!" ; Printf.printf "Done\n%!" ;
end end
; ;
@ -76,8 +76,8 @@ let run ?c ?d ~l ~update ezfio_filename =
match l with match l with
| false -> () | false -> ()
| true -> | true ->
Sys.ls_dir input_directory Sys.readdir input_directory
|> List.iter ~f:(fun md5 -> |> Array.iter (fun md5 ->
let filename = let filename =
Filename.concat input_directory md5 Filename.concat input_directory md5
in in
@ -88,10 +88,9 @@ let run ?c ?d ~l ~update ezfio_filename =
"" ""
in in
let date = let date =
(Unix.stat filename).Unix.st_mtime let open Unix in
in localtime (stat filename).st_mtime
let date = |> Time.string_of_date
Unix.strftime (Unix.localtime date) "%a, %d %b %Y %T %z"
in in
Printf.printf "%s : %s %s\n" md5 date this) Printf.printf "%s : %s %s\n" md5 date this)
in in
@ -102,13 +101,12 @@ let run ?c ?d ~l ~update ezfio_filename =
| Some other_key -> | Some other_key ->
if (key_is_valid other_key) then if (key_is_valid other_key) then
let command = let command =
String.concat ~sep:" " String.concat " "
[ "diff" ; "-u" ; "-w" ; [ "diff" ; "-u" ; "-w" ;
(filename_of_key current_md5) ; (filename_of_key current_md5) ;
(filename_of_key other_key) ] (filename_of_key other_key) ]
in in
match (Unix.system command) with ignore @@ Unix.system command
| _ -> ()
else else
failwith ("Error: " ^ other_key ^ " does not exist") failwith ("Error: " ^ other_key ^ " does not exist")
in in
@ -122,30 +120,45 @@ let run ?c ?d ~l ~update ezfio_filename =
| _ -> handle_options () | _ -> handle_options ()
let spec = let command () =
let open Command.Spec in let open Command_line in
empty begin
+> flag "c" (optional string) set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command");
~doc:("<key> Change to input to <key>") set_description_doc "Manipulate input MD5 keys";
+> flag "d" (optional string)
~doc:("<key> Show input differences with <key>")
+> flag "l" no_arg
~doc:(" List all the saved MD5 keys.")
+> flag "update" no_arg
~doc:(" Update to the latest MD5 format.")
+> anon ("ezfio_file" %: string)
[ { short='c' ; long="clear" ; opt=Optional ;
doc="Change to input to <key>" ;
arg=With_arg "<string>" ; };
{ short='d' ; long="diff" ; opt=Optional ;
doc="Show input differences with <key>" ;
arg=With_arg "<string>" ; };
let command = { short='l' ; long="list" ; opt=Optional ;
Command.basic_spec doc="List all the saved MD5 keys." ;
~summary: "Manipulate input MD5 keys" arg=Without_arg ; };
~readme:(fun () ->
" { short='u' ; long="update" ; opt=Optional ;
Manipulate input MD5 keys doc="Update to the latest MD5 format." ;
") arg=Without_arg ; };
spec
(fun c d l update ezfio_file () -> run ?c ?d ~l ~update ezfio_file ) anonymous "EZFIO_DIR" Mandatory "EZFIO directory";
]
|> set_specs
end;
let update = Command_line.get_bool "update" in
let c = Command_line.get "clear" in
let d = Command_line.get "diff" in
let l = Command_line.get_bool "list" in
let ezfio_file =
match Command_line.anon_args () with
| ezfio_file :: [] -> ezfio_file
| _ -> (Command_line.help () ; failwith "Inconsistent command line")
in
run ?c ?d ~l ~update ezfio_file

View File

@ -1,4 +1,3 @@
open Core
open Qptypes open Qptypes
(** Display a table that can be plotted by gnuplot *) (** Display a table that can be plotted by gnuplot *)
@ -12,19 +11,17 @@ let display_table ~range property =
and data = p.Random_variable.data and data = p.Random_variable.data
in in
let results = let results =
List.map2_exn conv rconv ~f:(fun (val1, err1) (val2,err2) -> (val1, err1, val2, err2)) List.map2 (fun (val1, err1) (val2,err2) -> (val1, err1, val2, err2)) conv rconv
in in
List.iter2_exn results data ~f:(fun (val1, err1, val2, err2) block -> List.iter2 (fun (val1, err1, val2, err2) block ->
Printf.printf "%10.6f %10.6f %10.6f %10.6f %10.6f\n" Printf.printf "%10.6f %10.6f %10.6f %10.6f %10.6f\n"
val1 err1 val2 err2 (Sample.to_float block.Block.value) val1 err1 val2 err2 (Sample.to_float block.Block.value)
) ) results data
;;
(** Display a convergence plot of the requested property *) (** Display a convergence plot of the requested property *)
let display_plot ~range property = let display_plot ~range property =
print_string ("display_plot "^property^".\n") print_string ("display_plot "^property^".\n")
;;
(** Display a convergence table of the error *) (** Display a convergence table of the error *)
@ -51,7 +48,7 @@ let display_err_convergence ~range property =
| (ave, None) -> () | (ave, None) -> ()
in in
aux 1 p aux 1 p
;;
(** Display the centered cumulants of a property *) (** Display the centered cumulants of a property *)
let display_cumulants ~range property = let display_cumulants ~range property =
@ -71,7 +68,7 @@ let display_cumulants ~range property =
1. /. 48. *. cum.(3) *. cum.(3) 1. /. 48. *. cum.(3) *. cum.(3)
in in
Printf.printf "Non-gaussianity = %16.10f\n" n Printf.printf "Non-gaussianity = %16.10f\n" n
;;
(** Display a table for the autocovariance of the property *) (** Display a table for the autocovariance of the property *)
@ -81,9 +78,9 @@ let display_autocovariance ~range property =
|> Random_variable.of_raw_data ~range |> Random_variable.of_raw_data ~range
in in
Random_variable.autocovariance p Random_variable.autocovariance p
|> List.iteri ~f:(fun i x -> |> List.iteri (fun i x ->
Printf.printf "%10d %16.10f\n" i x) Printf.printf "%10d %16.10f\n" i x)
;;
(** Display a histogram of the property *) (** Display a histogram of the property *)
let display_histogram ~range property = let display_histogram ~range property =
@ -104,8 +101,8 @@ let display_histogram ~range property =
let g = let g =
Random_variable.GaussianDist.eval ~g Random_variable.GaussianDist.eval ~g
in in
List.iter histo ~f:( fun (x,y) -> List.iter ( fun (x,y) ->
Printf.printf "%16.10f %16.10f %16.10f\n" x y (g ~x)) Printf.printf "%16.10f %16.10f %16.10f\n" x y (g ~x)) histo
(* (*
and sigma2 = and sigma2 =
(Random_variable.centered_cumulants p).(1) (Random_variable.centered_cumulants p).(1)
@ -128,7 +125,7 @@ let display_histogram ~range property =
|> List.iter ~f:(fun (x,y,g) -> |> List.iter ~f:(fun (x,y,g) ->
Printf.printf "%16.10f %16.10f %16.10f\n" x y g) Printf.printf "%16.10f %16.10f %16.10f\n" x y g)
*) *)
;;
@ -144,7 +141,7 @@ let display_summary ~range =
(Property.to_string property) (Property.to_string property)
(Random_variable.to_string p) (Random_variable.to_string p)
in in
List.iter properties ~f:print_property ; List.iter print_property properties ;
let cpu = let cpu =
@ -159,8 +156,8 @@ let display_summary ~range =
let speedup = let speedup =
cpu /. wall cpu /. wall
in in
Printf.printf "%20s : %10.2f x\n" "Speedup" speedup; Printf.printf "%20s : %10.2f x\n" "Speedup" speedup
;;
let run ?a ?c ?e ?h ?t ?p ?rmin ?rmax ezfio_file = let run ?a ?c ?e ?h ?t ?p ?rmin ?rmax ezfio_file =
@ -170,15 +167,15 @@ let run ?a ?c ?e ?h ?t ?p ?rmin ?rmax ezfio_file =
let rmin = let rmin =
match rmin with match rmin with
| None -> 0. | None -> 0.
| Some x when (x<0) -> failwith "rmin should be >= 0" | Some x when (float_of_string x < 0.) -> failwith "rmin should be >= 0"
| Some x when (x>100) -> failwith "rmin should be <= 100" | Some x when (float_of_string x > 100.) -> failwith "rmin should be <= 100"
| Some x -> Float.of_int x | Some x -> float_of_string x
and rmax = and rmax =
match rmax with match rmax with
| None -> 100. | None -> 100.
| Some x when (x<0) -> failwith "rmax should be >= 0" | Some x when (float_of_string x < 0.) -> failwith "rmax should be >= 0"
| Some x when (x>100) -> failwith "rmax should be <= 100" | Some x when (float_of_string x > 100.) -> failwith "rmax should be <= 100"
| Some x -> Float.of_int x | Some x -> float_of_string x
in in
let range = let range =
(rmin, rmax) (rmin, rmax)
@ -194,54 +191,80 @@ let run ?a ?c ?e ?h ?t ?p ?rmin ?rmax ezfio_file =
] ]
in in
let f (x,func) = List.iter (fun (x,func) ->
match x with match x with
| Some property -> func ~range property | Some property -> func ~range property
| None -> () | None -> ()
in ) l;
List.iter ~f l if (List.fold_left (fun accu x ->
;
if (List.fold ~init:true ~f:(fun accu x ->
match x with match x with
| (None, _) -> accu && true | (None, _) -> accu && true
| (Some _,_) -> false | (Some _,_) -> false
) l ) true l
) then ) then
display_summary ~range display_summary ~range
;;
let spec = let command () =
let open Command.Spec in let open Command_line in
empty begin
+> flag "a" (optional string) set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command");
~doc:"property Display the autcovariance function of the property" set_description_doc "Displays the results computed in an EZFIO directory.";
+> flag "c" (optional string)
~doc:"property Print the centered cumulants of a property"
+> flag "e" (optional string)
~doc:"property Display the convergence of the error of the property by merging blocks"
+> flag "h" (optional string)
~doc:"property Display the histogram of the property blocks"
+> flag "p" (optional string)
~doc:"property Display a convergence plot for a property"
+> flag "rmin" (optional int)
~doc:"int Lower bound of the percentage of the total weight to consider (default 0)"
+> flag "rmax" (optional int)
~doc:"int Upper bound of the percentage of the total weight to consider (default 100)"
+> flag "t" (optional string)
~doc:"property Print a table for the convergence of a property"
+> anon ("ezfio_file" %: string)
;;
let command = [ { short='a' ; long="autocovariance" ; opt=Optional ;
Command.basic_spec doc="Display the autcovariance function of the property";
~summary: "Displays the results computed in an EZFIO directory." arg=With_arg "<string>" ; };
~readme:(fun () -> "Displays the results computed in an EZFIO directory.")
spec { short='c' ; long="centered-cumulants" ; opt=Optional ;
(fun a c e h p rmin rmax t ezfio_file () -> run ?a ?c ?e ?h ?t ?p ?rmin ?rmax ezfio_file ) doc="Print the centered cumulants of a property" ;
;; arg=With_arg "<string>"; };
{ short='e' ; long="error" ; opt=Optional ;
doc="Display the convergence of the error of the property by merging blocks";
arg=With_arg "<string>"; };
{ short='i' ; long="histogram" ; opt=Optional ;
doc="Display the histogram of the property blocks" ;
arg=With_arg "<string>"; };
{ short='p' ; long="plot" ; opt=Optional ;
doc="Display a convergence plot for a property";
arg=With_arg "<string>"; };
{ short='m' ; long="rmin" ; opt=Optional ;
doc="Lower bound of the percentage of the total weight to consider (default 0)" ;
arg=With_arg "<int>"; };
{ short='n' ; long="rmax" ; opt=Optional ;
doc="Upper bound of the percentage of the total weight to consider (default 100)" ;
arg=With_arg "<int>"; };
{ short='t' ; long="table" ; opt=Optional ;
doc="Print a table for the convergence of a property" ;
arg=With_arg "<string>"; };
anonymous "EZFIO_DIR" Mandatory "EZFIO directory";
]
|> set_specs ;
end;
let a = Command_line.get "autocovariance" in
let c = Command_line.get "centered-cumulants" in
let e = Command_line.get "error" in
let h = Command_line.get "histogram" in
let t = Command_line.get "table" in
let p = Command_line.get "plot" in
let rmin = Command_line.get "m" in
let rmax = Command_line.get "n" in
let ezfio_file =
match Command_line.anon_args () with
| ezfio_file :: [] -> ezfio_file
| _ -> (Command_line.help () ; failwith "Inconsistent command line")
in
run ?a ?c ?e ?h ?t ?p ?rmin ?rmax ezfio_file

View File

@ -1,4 +1,3 @@
open Core
let full_run ?(start_dataserver=true) ezfio_filename = let full_run ?(start_dataserver=true) ezfio_filename =
(* Identify the job scheduler *) (* Identify the job scheduler *)
@ -39,17 +38,16 @@ let full_run ?(start_dataserver=true) ezfio_filename =
(* Start the data server *) (* Start the data server *)
let prog, argv = let prog, args =
qmcchem, [ qmcchem; "run" ; "-d" ; ezfio_filename] qmcchem, [| qmcchem; "run" ; "-d" ; ezfio_filename |]
in in
let pid_dataserver = let pid_dataserver =
Watchdog.fork_exec ~prog ~argv () Watchdog.fork_exec ~prog ~args ()
in in
Printf.printf "%7d : %s\n%!" (Pid.to_int pid_dataserver) (String.concat ~sep:" " argv) Printf.printf "%7d : %s\n%!" pid_dataserver (String.concat " " (Array.to_list args))
end; end;
(*
(* Check if the Zmq Rep socket is open *) (* Check if the Zmq Rep socket is open *)
let test_open_rep_socket () = let test_open_rep_socket () =
let zmq_context = let zmq_context =
@ -87,7 +85,7 @@ let full_run ?(start_dataserver=true) ezfio_filename =
| n -> | n ->
if (not (test_open_rep_socket ())) then if (not (test_open_rep_socket ())) then
begin begin
Time.pause (Time.Span.of_sec 0.5); Unix.sleep 2;
count (n-1); count (n-1);
end end
else else
@ -95,33 +93,33 @@ let full_run ?(start_dataserver=true) ezfio_filename =
in in
if (not (count 300)) then if (not (count 300)) then
Watchdog.kill (); Watchdog.kill ();
*) Unix.sleep 3;
Time.pause (Time.Span.of_sec 3.);
(* Start the qmc processes *) (* Start the qmc processes *)
let prog, argv = let prog, args_list =
let launcher = let launcher =
Launcher.(find () |> to_string) Launcher.(find () |> to_string)
in in
match launcher match launcher
|> String.split ~on:' ' |> String.split_on_char ' '
|> List.map ~f:String.strip |> List.map String.trim
|> List.filter ~f:(fun x -> x <> "") |> List.filter (fun x -> x <> "")
with with
| launcher_exe::launcher_flags -> | launcher_exe::launcher_flags ->
launcher_exe, launcher_exe :: launcher_flags @ qmc @ [ launcher_exe, launcher_exe :: launcher_flags @ qmc @ [
Ezfio.get_simulation_http_server () ; ezfio_filename ] Ezfio.get_simulation_http_server () ; ezfio_filename ]
| _ -> failwith "Error in launcher" | _ -> failwith "Error in launcher"
in in
let args = Array.of_list args_list in
let pid_qmc = let pid_qmc =
try try
Watchdog.fork_exec ~prog ~argv () Watchdog.fork_exec ~prog ~args ()
with with
| Unix.Unix_error _ -> | Unix.Unix_error _ ->
begin begin
let command = let command =
String.concat ~sep:" " argv String.concat " " args_list
in in
Printf.printf " Printf.printf "
============================================================ ============================================================
@ -132,7 +130,7 @@ Error: Unable to run the following command
Watchdog.kill () Watchdog.kill ()
end end
in in
Printf.printf "%7d : %s\n%!" (Pid.to_int pid_qmc) (String.concat ~sep:" " argv); Printf.printf "%7d : %s\n%!" pid_qmc (String.concat " " args_list);
(* Wait for processes to finish *) (* Wait for processes to finish *)
Watchdog.join () Watchdog.join ()
@ -153,17 +151,18 @@ let run a d ?q ?s ezfio_filename =
(* Signal handler to Kill properly all the processes *) (* Signal handler to Kill properly all the processes *)
let handler s = let handler s =
Printf.printf "QMC=Chem received the %s signal... killing\n%!" (Signal.to_string s); Printf.printf "QMC=Chem received signal %d... killing\n%!" s;
Watchdog.kill (); Watchdog.kill ();
in in
List.iter [ List.iter (fun s -> ignore @@ Sys.signal s (Sys.Signal_handle handler))
Signal.int ; [
Signal.term ; Sys.sigint ;
Signal.quit ; Sys.sigterm ;
Sys.sigquit ;
] ]
~f:(fun x -> Signal.Expert.handle x handler)
; ;
(* Validate input *) (* Validate input *)
Input.validate (); Input.validate ();
(* Printf.printf "MD5 : %s\n" (Lazy.force Md5.hash) ; *) (* Printf.printf "MD5 : %s\n" (Lazy.force Md5.hash) ; *)
@ -191,30 +190,45 @@ let run a d ?q ?s ezfio_filename =
let spec = let command () =
let open Command.Spec in let open Command_line in
empty begin
+> flag "a" no_arg set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command");
~doc:(" Add more resources to a running calculation.") set_description_doc "Run a calculation";
+> flag "d" no_arg
~doc:(" Start a dataserver process on the local host.") [ { short='a' ; long="add" ; opt=Optional ;
+> flag "q" (optional string) doc="Add more resources to a running calculation" ;
~doc:("<dataserver_addr> Start a qmc process on the local host.") arg=Without_arg ; };
+> flag "s" (optional string)
~doc:("<host> Start a qmc process on <host>.") { short='d' ; long="data-server" ; opt=Optional ;
+> anon ("ezfio_file" %: string) doc="Start a dataserver process on the local host" ;
arg=Without_arg ; };
{ short='q' ; long="local-qmc" ; opt=Optional ;
let command = doc="Start a qmc process on the local host attached to the addres given as an argument" ;
Command.basic_spec arg=With_arg "<string>" ; };
~summary: "Run a calculation"
~readme:(fun () -> { short='s' ; long="remote-qmc" ; opt=Optional ;
" doc="Start a qmc process on the remote host as an argument" ;
Run QMC=Chem arg=With_arg "<string>" ; };
")
spec anonymous "EZFIO_DIR" Mandatory "EZFIO directory";
(fun a d q s ezfio_file () -> run a d ?q ?s ezfio_file ) ]
|> set_specs
end;
let a = Command_line.get_bool "add" in
let d = Command_line.get_bool "data-server" in
let q = Command_line.get "local-qmc" in
let s = Command_line.get "remote-qmc" in
let ezfio_file =
match Command_line.anon_args () with
| ezfio_file :: [] -> ezfio_file
| _ -> (Command_line.help () ; failwith "Inconsistent command line")
in
run a d ?q ?s ezfio_file

View File

@ -1,24 +1,23 @@
open Core
let run ezfio_filename = let run ezfio_filename =
Qputils.set_ezfio_filename ezfio_filename; Qputils.set_ezfio_filename ezfio_filename;
Status.write Status.Stopping Status.write Status.Stopping
let command () =
let open Command_line in
begin
set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command");
set_description_doc "Stop a running calculation";
[ anonymous "EZFIO_DIR" Mandatory "EZFIO directory" ]
|> set_specs
end;
let spec = let ezfio_file =
let open Command.Spec in match Command_line.anon_args () with
empty | ezfio_file :: [] -> ezfio_file
+> anon ("ezfio_file" %: string) | _ -> (Command_line.help () ; failwith "Inconsistent command line")
in
let command = run ezfio_file
Command.basic_spec
~summary: "Stop a running calculation"
~readme:(fun () ->
"
Stop a running calculation
")
spec
(fun ezfio_file () -> run ezfio_file )

View File

@ -1,27 +1,26 @@
open Core
let split_re = let split_re =
Str.regexp " +" Str.regexp " +"
let split s = let split s =
String.strip s String.trim s
|> Str.split split_re |> Str.split split_re
let set_ezfio_filename ezfio_filename = let set_ezfio_filename ezfio_filename =
let () = let () =
if (not (Sys.file_exists_exn ezfio_filename)) then if (not (Sys.file_exists ezfio_filename)) then
failwith (ezfio_filename^" does not exist") failwith (ezfio_filename^" does not exist")
in in
let () = let () =
match (Sys.is_directory ezfio_filename) with if Sys.file_exists ezfio_filename && Sys.is_directory ezfio_filename then
| `Yes -> Ezfio.set_file ezfio_filename ; Ezfio.set_file ezfio_filename
| _ -> failwith ("Error : "^ezfio_filename^" is not a directory") else
failwith ("Error : "^ezfio_filename^" is not a directory")
in in
let dir, result = let dir, result =
Filename.realpath ezfio_filename Filename.dirname ezfio_filename,
|> Filename.split Filename.basename ezfio_filename
in in
Unix.chdir dir ; Unix.chdir dir ;
Ezfio.set_file result Ezfio.set_file result
@ -35,13 +34,18 @@ let ezfio_filename = lazy (
match f with match f with
| "EZFIO_File" -> | "EZFIO_File" ->
begin begin
if (Array.length Sys.argv = 1) then let args =
Command_line.anon_args ()
|> Array.of_list
in
if (Array.length args < 1) then
failwith "Error : EZFIO directory not specified on the command line\n"; failwith "Error : EZFIO directory not specified on the command line\n";
Sys.argv.(1) args.(0)
end end
| f -> f | f -> f
in in
set_ezfio_filename full_path; set_ezfio_filename full_path;
!Ezfio.ezfio_filename !Ezfio.ezfio_filename
) )

View File

@ -1,4 +1,3 @@
open Core
open Qptypes open Qptypes
type t = type t =
@ -26,7 +25,7 @@ module Skewness: sig
val to_string : t -> string val to_string : t -> string
end = struct end = struct
type t = float type t = float
let to_string = Float.to_string let to_string = string_of_float
let to_float x = x let to_float x = x
let of_float x = x let of_float x = x
end end
@ -38,7 +37,7 @@ module Kurtosis: sig
val to_string : t -> string val to_string : t -> string
end = struct end = struct
type t = float type t = float
let to_string = Float.to_string let to_string = string_of_float
let to_float x = x let to_float x = x
let of_float x = x let of_float x = x
end end
@ -64,7 +63,7 @@ end = struct
(x -. mu) *. ( x -. mu) /. sigma2 (x -. mu) *. ( x -. mu) /. sigma2
in in
let pi = let pi =
Float.acos (-1.) acos (-1.)
in in
let c = let c =
1. /. (sqrt (sigma2 *. (pi +. pi))) 1. /. (sqrt (sigma2 *. (pi +. pi)))
@ -74,20 +73,35 @@ end = struct
end end
let hashtbl_to_alist table =
Hashtbl.fold (fun k v a -> (k,v) :: a) table []
let hashtbl_change table key f =
let elt =
try
Some (Hashtbl.find table key)
with
| Not_found -> None
in
let new_elt = f elt in
match new_elt with
| None -> Hashtbl.remove table key
| Some value -> Hashtbl.replace table key value
(** Build from raw data. Range values are given in percent. *) (** Build from raw data. Range values are given in percent. *)
let of_raw_data ?(locked=true) ~range property = let of_raw_data ?(locked=true) ~range property =
let data = let data =
Block.raw_data ~locked () Block.raw_data ~locked ()
|> List.filter ~f:(fun x -> x.Block.property = property) |> List.filter (fun x -> x.Block.property = property)
in in
let data_in_range rmin rmax = let data_in_range rmin rmax =
let total_weight = let total_weight =
List.fold_left data ~init:0. ~f:(fun accu x -> List.fold_left (fun accu x ->
(Weight.to_float x.Block.weight) +. accu (Weight.to_float x.Block.weight) +. accu
) ) 0. data
in in
let wmin, wmax = let wmin, wmax =
@ -96,7 +110,7 @@ let of_raw_data ?(locked=true) ~range property =
in in
let (_, new_data) = let (_, new_data) =
List.fold_left data ~init:(0.,[]) ~f:(fun (wsum, l) x -> List.fold_left (fun (wsum, l) x ->
if (wsum > wmax) then if (wsum > wmax) then
(wsum,l) (wsum,l)
else else
@ -109,7 +123,7 @@ let of_raw_data ?(locked=true) ~range property =
else else
(wsum_new, l) (wsum_new, l)
end end
) ) (0.,[]) data
in in
List.rev new_data List.rev new_data
in in
@ -127,13 +141,13 @@ let of_raw_data ?(locked=true) ~range property =
let average { property ; data } = let average { property ; data } =
if Property.is_scalar property then if Property.is_scalar property then
let (num,denom) = let (num,denom) =
List.fold ~init:(0., 0.) ~f:(fun (an, ad) x -> List.fold_left (fun (an, ad) x ->
let num = let num =
(Weight.to_float x.Block.weight) *. (Sample.to_float x.Block.value) (Weight.to_float x.Block.weight) *. (Sample.to_float x.Block.value)
and den = and den =
(Weight.to_float x.Block.weight) (Weight.to_float x.Block.weight)
in (an +. num, ad +. den) in (an +. num, ad +. den)
) data ) (0., 0.) data
in in
num /. denom num /. denom
|> Average.of_float |> Average.of_float
@ -144,20 +158,18 @@ let average { property ; data } =
| x :: tl -> Sample.dimension x.Block.value | x :: tl -> Sample.dimension x.Block.value
in in
let (num,denom) = let (num,denom) =
List.fold ~init:(Array.create ~len:dim 0. , 0.) ~f:(fun (an, ad) x -> List.fold_left (fun (an, ad) x ->
let num = let num =
Array.map (Sample.to_float_array x.Block.value) ~f:(fun y -> Array.map (fun y -> (Weight.to_float x.Block.weight) *. y)
(Weight.to_float x.Block.weight) *. y) (Sample.to_float_array x.Block.value)
and den = (Weight.to_float x.Block.weight) and den = (Weight.to_float x.Block.weight)
in ( in ( Array.mapi (fun i y -> y +. num.(i)) an , ad +. den)
Array.mapi an ~f:(fun i y -> y +. num.(i)) , ) (Array.make dim 0. , 0.) data
ad +. den)
) data
in in
let denom_inv = let denom_inv =
1. /. denom 1. /. denom
in in
Array.map num ~f:(fun x -> x *. denom_inv) Array.map (fun x -> x *. denom_inv) num
|> Average.of_float_array ~dim |> Average.of_float_array ~dim
@ -166,10 +178,10 @@ let average { property ; data } =
(** Compute sum (for CPU/Wall time) *) (** Compute sum (for CPU/Wall time) *)
let sum { property ; data } = let sum { property ; data } =
List.fold data ~init:0. ~f:(fun accu x -> List.fold_left (fun accu x ->
let num = (Weight.to_float x.Block.weight) *. (Sample.to_float x.Block.value) let num = (Weight.to_float x.Block.weight) *. (Sample.to_float x.Block.value)
in accu +. num in accu +. num
) ) 0. data
@ -181,7 +193,7 @@ let ave_error { property ; data } =
begin begin
if (n > 0.) then if (n > 0.) then
( Average.of_float (sum /. ansum), ( Average.of_float (sum /. ansum),
Some (Error.of_float (sqrt ( Float.abs ( avsq /.( ansum *. n)))) )) Some (Error.of_float (sqrt ( abs_float ( avsq /.( ansum *. n)))) ))
else else
( Average.of_float (sum /. ansum), None) ( Average.of_float (sum /. ansum), None)
end end
@ -220,10 +232,10 @@ let ave_error { property ; data } =
in in
if (Property.is_scalar property) then if (Property.is_scalar property) then
List.map data ~f:(fun x -> List.map (fun x ->
(Sample.to_float x.Block.value, (Sample.to_float x.Block.value,
Weight.to_float x.Block.weight) Weight.to_float x.Block.weight)
) ) data
|> ave_error_scalar |> ave_error_scalar
else else
match data with match data with
@ -234,22 +246,22 @@ let ave_error { property ; data } =
|> Sample.dimension |> Sample.dimension
in in
let result = let result =
Array.init dim ~f:(fun idx -> Array.init dim (fun idx ->
List.map list_of_samples ~f:(fun x -> List.map (fun x ->
(Sample.to_float ~idx x.Block.value, (Sample.to_float ~idx x.Block.value,
Weight.to_float x.Block.weight) Weight.to_float x.Block.weight)
) ) list_of_samples
|> ave_error_scalar |> ave_error_scalar
) )
in in
( Array.map result ~f:(fun (x,_) -> Average.to_float x) ( Array.map (fun (x,_) -> Average.to_float x) result
|> Average.of_float_array ~dim , |> Average.of_float_array ~dim ,
if (Array.length result < 2) then if (Array.length result < 2) then
None None
else else
Some (Array.map result ~f:(function Some (Array.map (function
| (_,Some y) -> Error.to_float y | (_,Some y) -> Error.to_float y
| (_,None) -> 0.) | (_,None) -> 0.) result
|> Average.of_float_array ~dim) |> Average.of_float_array ~dim)
) )
@ -258,14 +270,17 @@ let ave_error { property ; data } =
(** Fold function for block values *) (** Fold function for block values *)
let fold_blocks ~f { property ; data } = let fold_blocks ~f { property ; data } =
let init = match List.hd data with let init =
| None -> 0. try
| Some block -> Sample.to_float block.Block.value let block = List.hd data in
Sample.to_float block.Block.value
with
| Failure _ -> 0.
in in
List.fold_left data ~init:init ~f:(fun accu block -> List.fold_left (fun accu block ->
let x = Sample.to_float block.Block.value let x = Sample.to_float block.Block.value
in f accu x in f accu x
) ) init data
@ -288,7 +303,7 @@ let convergence { property ; data } =
in in
let accu = let accu =
if (n > 0.) then if (n > 0.) then
(sum /. ansum, sqrt ( Float.abs ( avsq /.( ansum *. n))))::accu (sum /. ansum, sqrt ( abs_float ( avsq /.( ansum *. n))))::accu
else else
(sum /. ansum, 0.)::accu (sum /. ansum, 0.)::accu
in in
@ -347,13 +362,13 @@ let max_block =
let create_hash ~create_key ?(update_block_id=(fun x->x)) let create_hash ~create_key ?(update_block_id=(fun x->x))
?(update_value=(fun wc vc wb vb sw -> (wc *. vc +. wb *. vb) /. sw) ) ?(update_value=(fun wc vc wb vb sw -> (wc *. vc +. wb *. vb) /. sw) )
?(update_weight=(fun wc wb -> wc +. wb) ) t = ?(update_weight=(fun wc wb -> wc +. wb) ) t =
let table = String.Table.create () let table = Hashtbl.create 63
in in
List.iter t.data ~f:(fun block -> List.iter (fun block ->
let key = create_key block let key = create_key block
in in
let open Block in let open Block in
Hashtbl.change table key (function hashtbl_change table key (function
| Some current -> | Some current ->
let wc, wb = let wc, wb =
Weight.to_float current.weight, Weight.to_float current.weight,
@ -384,7 +399,7 @@ let create_hash ~create_key ?(update_block_id=(fun x->x))
{ property = current.property ; { property = current.property ;
weight = Weight.of_float sw ; weight = Weight.of_float sw ;
value = value =
Array.init dim ~f:(fun i -> update_value wc vc.(i) wb vb.(i) sw) Array.init dim (fun i -> update_value wc vc.(i) wb vb.(i) sw)
|> Sample.of_float_array ~dim ; |> Sample.of_float_array ~dim ;
block_id = update_block_id block.block_id; block_id = update_block_id block.block_id;
pid = block.pid ; pid = block.pid ;
@ -399,7 +414,7 @@ let create_hash ~create_key ?(update_block_id=(fun x->x))
compute_node = block.compute_node; compute_node = block.compute_node;
} }
) )
); ) t.data ;
table table
@ -409,12 +424,12 @@ let merge ~create_key ?update_block_id ?update_value ?update_weight t =
let table = create_hash ~create_key ?update_block_id ?update_value ?update_weight t let table = create_hash ~create_key ?update_block_id ?update_value ?update_weight t
in in
{ property = t.property ; { property = t.property ;
data = Hashtbl.to_alist table data = hashtbl_to_alist table
|> List.sort ~cmp:(fun x y -> |> List.sort (fun x y ->
if (x>y) then 1 if (x>y) then 1
else if (x<y) then -1 else if (x<y) then -1
else 0) else 0)
|> List.map ~f:(fun (x,y) -> y) |> List.map (fun (x,y) -> y)
} }
@ -440,7 +455,7 @@ let merge_per_compute_node_and_pid =
~create_key:(fun block -> ~create_key:(fun block ->
Printf.sprintf "%s %10.10d" Printf.sprintf "%s %10.10d"
(Compute_node.to_string block.Block.compute_node) (Compute_node.to_string block.Block.compute_node)
(Pid.to_int block.Block.pid) ) (block.Block.pid) )
@ -466,7 +481,7 @@ let error_x_over_y = function
in in
let avcu = ref !avbl let avcu = ref !avbl
in in
List.iter tail ~f:(fun (x,w) -> List.iter (fun (x,w) ->
avcu0 := !avsum /. !ansum; avcu0 := !avsum /. !ansum;
ansum := !ansum +. w; ansum := !ansum +. w;
avsum := !avsum +. x; avsum := !avsum +. x;
@ -476,9 +491,9 @@ let error_x_over_y = function
else (); else ();
avsq := !avsq +. (1. -. w /. !ansum) *. (!avbl -. !avcu0) *. (!avbl -. !avcu0) *. w; avsq := !avsq +. (1. -. w /. !ansum) *. (!avbl -. !avcu0) *. (!avbl -. !avcu0) *. w;
n := !n +. 1. n := !n +. 1.
); ) tail ;
let arg = let arg =
Float.abs (!avsq /.(!ansum *. (!n -. 1.))) abs_float (!avsq /.(!ansum *. (!n -. 1.)))
in in
let error = let error =
sqrt arg sqrt arg
@ -490,7 +505,7 @@ let error_x_over_y = function
(** Create float, variable operators *) (** Create float, variable operators *)
let one_variable_operator ~update_value p f = let one_variable_operator ~update_value p f =
{ p with { p with
data = List.map ~f:(fun b -> { b with data = List.map (fun b -> { b with
Block.value = Sample.of_float (update_value (Sample.to_float b.Block.value) ) } Block.value = Sample.of_float (update_value (Sample.to_float b.Block.value) ) }
) p.data } ) p.data }
@ -515,7 +530,7 @@ let two_variable_operator ~update_value p1 p2 =
Printf.sprintf "%s %10.10d %10.10d" Printf.sprintf "%s %10.10d %10.10d"
(Compute_node.to_string block.Block.compute_node) (Compute_node.to_string block.Block.compute_node)
(Block_id.to_int block.Block.block_id) (Block_id.to_int block.Block.block_id)
(Pid.to_int block.Block.pid) ) (block.Block.pid) )
~update_weight:(fun wc wb -> wc ) ~update_weight:(fun wc wb -> wc )
{ property = p1.property ; { property = p1.property ;
data = List.concat [ p1.data ; p2.data ] } data = List.concat [ p1.data ; p2.data ] }
@ -550,18 +565,18 @@ let compress =
(** Last value on each compute node (for wall_time) *) (** Last value on each compute node (for wall_time) *)
let max_value_per_compute_node t = let max_value_per_compute_node t =
let table = String.Table.create () let table = Hashtbl.create 63
in in
let create_key block = let create_key block =
Printf.sprintf "%s %10.10d" Printf.sprintf "%s %10.10d"
(Compute_node.to_string block.Block.compute_node) (Compute_node.to_string block.Block.compute_node)
(Pid.to_int block.Block.pid) (block.Block.pid)
in in
List.iter t.data ~f:(fun block -> List.iter (fun block ->
let key = create_key block let key = create_key block
in in
let open Block in let open Block in
Hashtbl.change table key (function hashtbl_change table key (function
| Some current -> | Some current ->
let vc = Sample.to_float current.value let vc = Sample.to_float current.value
and vb = Sample.to_float block.value and vb = Sample.to_float block.value
@ -572,14 +587,14 @@ let max_value_per_compute_node t =
Some block Some block
| None -> Some block | None -> Some block
) )
); ) t.data ;
{ property = t.property ; { property = t.property ;
data = Hashtbl.to_alist table data = hashtbl_to_alist table
|> List.sort ~cmp:(fun x y -> |> List.sort (fun x y ->
if (x>y) then 1 if (x>y) then 1
else if (x<y) then -1 else if (x<y) then -1
else 0) else 0)
|> List.map ~f:(fun (x,y) -> y) |> List.map (fun (x,y) -> y)
} }
@ -588,8 +603,8 @@ let max_value_per_compute_node t =
(** String representation *) (** String representation *)
let to_string p = let to_string p =
match p.property with match p.property with
| Property.Cpu -> Printf.sprintf "%s" (Time.Span.to_string (Time.Span.of_sec (sum p))) | Property.Cpu -> Printf.sprintf "%s" (Time.string_of_sec (sum p))
| Property.Wall -> Printf.sprintf "%s" (Time.Span.to_string (Time.Span.of_sec (sum (max_value_per_compute_node p)))) | Property.Wall -> Printf.sprintf "%s" (Time.string_of_sec (sum (max_value_per_compute_node p)))
| Property.Accep -> Printf.sprintf "%16.10f" (average p |> Average.to_float) | Property.Accep -> Printf.sprintf "%16.10f" (average p |> Average.to_float)
| _ -> | _ ->
begin begin
@ -652,17 +667,33 @@ let compress_files () =
Lazy.force dir_name Lazy.force dir_name
in in
let files = let files =
Sys.ls_dir dir_name Sys.readdir dir_name
|> List.filter ~f:(fun x -> |> Array.to_list
match String.substr_index ~pattern:"locked" x with |> List.filter (fun x ->
| Some x -> false try
| None -> true Str.search_backward (Str.regexp "locked") x (String.length x) >= 0
with
| Not_found -> true
) )
|> List.map ~f:(fun x -> dir_name^x) |> List.map (fun x -> dir_name^x)
in in
let out_channel_dir = let out_channel_dir =
Filename.temp_dir ~in_dir:(!Ezfio.ezfio_filename ^ "/blocks/") "qmc" "" let rand_num = Random.int 1000000 |> string_of_int in
let dirname =
Filename.concat !Ezfio.ezfio_filename "blocks"
in
if not ( Sys.file_exists dirname ) then
Unix.mkdir dirname 0o755;
let tmp_dir =
Filename.concat dirname ("qmc"^rand_num)
in
try
Unix.mkdir tmp_dir 0o755;
tmp_dir
with _ ->
let message = Printf.sprintf "Cannot create temp dir %s" tmp_dir in
raise (Sys_error message)
in in
let out_channel_name = let out_channel_name =
@ -670,16 +701,17 @@ let compress_files () =
Lazy.force Qmcchem_config.hostname Lazy.force Qmcchem_config.hostname
and suffix = and suffix =
Unix.getpid () Unix.getpid ()
|> Pid.to_string |> string_of_int
in in
String.concat [ hostname ; "." ; suffix ] String.concat "." [ hostname ; suffix ]
in in
let block_channel = let block_channel =
Out_channel.create (out_channel_dir ^ out_channel_name) Filename.concat out_channel_dir out_channel_name
|> open_out
in in
List.iter properties ~f:(fun p -> List.iter (fun p ->
let l = let l =
match p with match p with
| Property.Cpu | Property.Cpu
@ -693,15 +725,16 @@ let compress_files () =
of_raw_data ~locked:false ~range:(0.,100.) p of_raw_data ~locked:false ~range:(0.,100.) p
|> merge_per_compute_node_and_block_id |> merge_per_compute_node_and_block_id
in in
List.iter l.data ~f:(fun x -> List.iter (fun x ->
Out_channel.output_string block_channel (Block.to_string x); output_string block_channel (Block.to_string x);
Out_channel.output_char block_channel '\n'; output_char block_channel '\n';
); ) l.data
); ) properties ;
Out_channel.close block_channel; close_out block_channel;
List.iter files ~f:Unix.remove ; List.iter Unix.unlink files ;
Unix.rename ~src:(out_channel_dir^out_channel_name) ~dst:(dir_name^out_channel_name); Unix.rename (Filename.concat out_channel_dir out_channel_name)
(Filename.concat dir_name out_channel_name);
Unix.rmdir out_channel_dir Unix.rmdir out_channel_dir
@ -716,20 +749,20 @@ let autocovariance { property ; data } =
with { property ; data } -> Array.of_list data with { property ; data } -> Array.of_list data
in in
let x_t = let x_t =
Array.map ~f:(fun x -> (Sample.to_float x.Block.value) -. ave) data Array.map (fun x -> (Sample.to_float x.Block.value) -. ave) data
in in
let f i = let f i =
let denom = let denom =
if (i > 1) then (Float.of_int i) else 1. if (i > 1) then (float_of_int i) else 1.
in in
let r = let r =
Array.sub ~pos:0 ~len:i x_t Array.sub x_t 0 i
|> Array.fold ~init:0. ~f:(fun accu x -> |> Array.fold_left (fun accu x ->
accu +. x *. x_t.(i)) accu +. x *. x_t.(i)) 0.
in in
r /. denom r /. denom
in in
Array.init ~f (Array.length data) Array.init (Array.length data) f
|> Array.to_list |> Array.to_list
@ -741,7 +774,7 @@ let centered_cumulants { property ; data } =
|> Average.to_float |> Average.to_float
in in
let centered_data = let centered_data =
List.map ~f:(fun x -> List.map (fun x ->
( (Weight.to_float x.Block.weight), ( (Weight.to_float x.Block.weight),
(Sample.to_float x.Block.value) -. ave ) (Sample.to_float x.Block.value) -. ave )
) )
@ -749,20 +782,20 @@ let centered_cumulants { property ; data } =
in in
let var = let var =
let (num, denom) = let (num, denom) =
List.fold ~init:(0., 0.) ~f:(fun (a2, ad) (w,x) -> List.fold_left (fun (a2, ad) (w,x) ->
let x2 = x *. x let x2 = x *. x
in in
let var = w *. x2 let var = w *. x2
and den = w and den = w
in (a2 +. var, ad +. den) in (a2 +. var, ad +. den)
) centered_data ) (0., 0.) centered_data
in num /. denom in num /. denom
in in
let centered_data = let centered_data =
let sigma_inv = let sigma_inv =
1. /. (sqrt var) 1. /. (sqrt var)
in in
List.map ~f:(fun x -> List.map (fun x ->
( (Weight.to_float x.Block.weight), ( (Weight.to_float x.Block.weight),
( (Sample.to_float x.Block.value) -. ave ) *. sigma_inv ) ( (Sample.to_float x.Block.value) -. ave ) *. sigma_inv )
) )
@ -770,14 +803,14 @@ let centered_cumulants { property ; data } =
in in
let (cum3,cum4) = let (cum3,cum4) =
let (cum3, cum4, denom) = let (cum3, cum4, denom) =
List.fold ~init:(0., 0., 0.) ~f:(fun (a3, a4, ad) (w,x) -> List.fold_left (fun (a3, a4, ad) (w,x) ->
let x2 = x *. x let x2 = x *. x
in in
let cum3 = w *. x2 *. x let cum3 = w *. x2 *. x
and cum4 = w *. x2 *. x2 and cum4 = w *. x2 *. x2
and den = w and den = w
in (a3 +. cum3, a4 +. cum4, ad +. den) in (a3 +. cum3, a4 +. cum4, ad +. den)
) centered_data ) (0., 0., 0.) centered_data
in in
( cum3 /. denom, cum4 /. denom -. 3. ) ( cum3 /. denom, cum4 /. denom -. 3. )
in in
@ -796,15 +829,15 @@ let histogram { property ; data } =
max -. min max -. min
and n = and n =
List.length data List.length data
|> Float.of_int |> float_of_int
|> sqrt |> sqrt
in in
let delta_x = let delta_x =
length /. (n-.1.) length /. (n-.1.)
and result = and result =
Array.init ~f:(fun _ -> 0.) (Int.of_float (n +. 1.)) Array.init (int_of_float n + 1) (fun _ -> 0.)
in in
List.iter ~f:(fun x -> List.iter (fun x ->
let w = let w =
(Weight.to_float x.Block.weight) (Weight.to_float x.Block.weight)
and x = and x =
@ -812,17 +845,17 @@ let histogram { property ; data } =
in in
let i = let i =
(x -. min) /. delta_x +. 0.5 (x -. min) /. delta_x +. 0.5
|> Float.to_int |> int_of_float
in in
result.(i) <- result.(i) +. w result.(i) <- result.(i) +. w
) data ) data
; ;
let norm = let norm =
1. /. ( delta_x *. ( 1. /. ( delta_x *. (
Array.fold ~init:0. ~f:(fun accu x -> accu +. x) result Array.fold_left (fun accu x -> accu +. x) 0. result
) ) ) )
in in
Array.mapi ~f:(fun i x -> (min +. (Float.of_int i)*.delta_x, x *. norm) ) result Array.mapi (fun i x -> (min +. (float_of_int i)*.delta_x, x *. norm) ) result
|> Array.to_list |> Array.to_list

View File

@ -1,9 +1,9 @@
open Core open Sexplib.Std
type t = type t =
| One_dimensional of float | One_dimensional of float
| Multidimensional of (float array * int) | Multidimensional of (float array * int)
[@ deriving sexp] [@@deriving sexp]
let dimension = function let dimension = function
| One_dimensional _ -> 1 | One_dimensional _ -> 1
@ -38,9 +38,10 @@ let of_float_array ~dim x =
| _ -> Multidimensional (x, dim) | _ -> Multidimensional (x, dim)
let to_string = function let to_string = function
| One_dimensional x -> Float.to_string x | One_dimensional x -> string_of_float x
| Multidimensional (x,_) -> | Multidimensional (x,_) ->
Array.map x ~f:Float.to_string Array.map string_of_float x
|> String.concat_array ~sep:" " |> Array.to_list
|> String.concat " "
|> Printf.sprintf "%s" |> Printf.sprintf "%s"

View File

@ -1,5 +1,3 @@
open Core
type t [@@deriving sexp] type t [@@deriving sexp]
val to_float : ?idx:int -> t -> float val to_float : ?idx:int -> t -> float
val to_float_array : t -> float array val to_float_array : t -> float array

View File

@ -1,5 +1,3 @@
open Core
type t = type t =
| SGE | SGE
| PBS | PBS
@ -18,12 +16,10 @@ let to_string = function
let find () = let find () =
let scheduler = let scheduler =
[ "SLURM_NODELIST" ; "PE_HOSTFILE" ; "PBS_NODEFILE" ] [ "SLURM_NODELIST" ; "PE_HOSTFILE" ; "PBS_NODEFILE" ]
|> List.map ~f:(function x -> |> List.map (function x ->
match (Sys.getenv x) with try Some (Sys.getenv x) with
| Some _ -> x | Not_found -> None
| None -> ""
) )
|> List.filter ~f:(function x -> x <> "")
|> List.hd |> List.hd
in in
let result = let result =

160
ocaml/String_ext.ml Normal file
View File

@ -0,0 +1,160 @@
include String
(** Split a string on a given character *)
let split ?(on=' ') str =
split_on_char on str
(** Strip blanks on the left of a string *)
let ltrim s =
let rec do_work s l =
match s.[0] with
| '\n'
| ' ' -> do_work (sub s 1 (l-1)) (l-1)
| _ -> s
in
let l =
length s
in
if (l > 0) then
do_work s l
else
s
(** Strip blanks on the right of a string *)
let rtrim s =
let rec do_work s l =
let newl =
l-1
in
match s.[newl] with
| '\n'
| ' ' -> do_work (sub s 0 (newl)) (newl)
| _ -> s
in
let l =
length s
in
if (l > 0) then
do_work s l
else
s
(** Strip blanks on the right and left of a string *)
let strip = String.trim
(** Split a string in two pieces when a character is found the 1st time from the left *)
let lsplit2_exn ?(on=' ') s =
let length =
String.length s
in
let rec do_work i =
if (i = length) then
begin
raise Not_found
end
else if (s.[i] = on) then
( String.sub s 0 i,
String.sub s (i+1) (length-i-1) )
else
do_work (i+1)
in
do_work 0
(** Split a string in two pieces when a character is found the 1st time from the right *)
let rsplit2_exn ?(on=' ') s =
let length =
String.length s
in
let rec do_work i =
if (i = -1) then
begin
raise Not_found
end
else if (s.[i] = on) then
( String.sub s 0 i,
String.sub s (i+1) (length-i-1) )
else
do_work (i-1)
in
do_work (length-1)
let lsplit2 ?(on=' ') s =
try
Some (lsplit2_exn ~on s)
with
| Not_found -> None
let rsplit2 ?(on=' ') s =
try
Some (rsplit2_exn ~on s)
with
| Not_found -> None
let to_list s =
Array.init (String.length s) (fun i -> s.[i])
|> Array.to_list
let of_list l =
let a = Array.of_list l in
String.init (Array.length a) (fun i -> a.(i))
let rev s =
to_list s
|> List.rev
|> of_list
let fold ~init ~f s =
to_list s
|> List.fold_left f init
let is_prefix ~prefix s =
let len =
String.length prefix
in
if len > String.length s then
false
else
prefix = String.sub s 0 len
let of_char c =
String.make 1 c
let tr ~target ~replacement s =
String.map (fun c -> if c = target then replacement else c) s
let substr_index ?(pos=0) ~pattern s =
try
let regexp =
Str.regexp pattern
in
Some (Str.search_forward regexp s pos)
with Not_found -> None
let substr_replace_all ~pattern ~with_ s =
let regexp =
Str.regexp pattern
in
Str.global_replace regexp with_ s
let input_lines ic =
let rec aux ic accu =
try
aux ic ((input_line ic)::accu)
with
| End_of_file -> List.rev accu
in
aux ic []

50
ocaml/Time.ml Normal file
View File

@ -0,0 +1,50 @@
let of_sec s =
Unix.gmtime s
let to_sec t =
let sec = t.Unix.tm_sec
and min = t.Unix.tm_min
and hour = t.Unix.tm_hour
and mday = t.Unix.tm_mday
in
sec +
min * 60 +
hour * 60 * 60 +
(mday-1) * 60 * 60 * 24
let string_of_t t =
let mday = t.Unix.tm_mday - 1 in
let sec = t.Unix.tm_sec
and min = t.Unix.tm_min
and hour = t.Unix.tm_hour + 24*mday
in
Printf.sprintf "%2d:%2.2d:%2.2d" hour min sec
let string_of_date t =
let year = 1900 + t.Unix.tm_year in
let mon = t.Unix.tm_mon in
let mday = t.Unix.tm_mday in
let sec = t.Unix.tm_sec
and min = t.Unix.tm_min
and hour = t.Unix.tm_hour
in
let month =
match mon with
| 0 -> "Jan" | 1 -> "Feb" | 2 -> "Mar" | 3 -> "Apr"
| 4 -> "May" | 5 -> "Jun" | 6 -> "Jul" | 7 -> "Aug"
| 8 -> "Sep" | 9 -> "Oct" | 10 -> "Nov" | 11 -> "Dec"
| _ -> assert false
in
Printf.sprintf "%2d %3s %4d - %2d:%2.2d:%2.2d" mday month year hour min sec
let string_of_now () =
Unix.gettimeofday ()
|> Unix.localtime
|> string_of_date
let string_of_sec s =
of_sec s
|> string_of_t

View File

@ -1,18 +1,16 @@
open Core let _list = ref []
let _running = ref false
let _list = ref [] ;; let _threads = ref []
let _running = ref false;;
let _threads = ref [] ;;
(** Kill the current process and all children *) (** Kill the current process and all children *)
let kill () = let kill () =
let kill pid = let kill pid =
Signal.send_i Signal.int (`Pid pid); Unix.kill pid Sys.sigkill;
Printf.printf "Killed %d\n%!" (Pid.to_int pid) Printf.printf "Killed %d\n%!" pid
in in
List.iter ~f:kill (!_list); List.iter kill (!_list);
exit 1 exit 1
;;
(** Start watchdog *) (** Start watchdog *)
@ -25,14 +23,11 @@ let start () =
_running := true; _running := true;
let pause () = let pause () =
Time.Span.of_sec 1. Unix.sleep 1
|> Time.pause
in in
let pid_is_running pid = let pid_is_running pid =
match (Sys.file_exists ("/proc/"^(Pid.to_string pid)^"/stat")) with Sys.file_exists ("/proc/"^(string_of_int pid)^"/stat")
| `No | `Unknown -> false
| `Yes -> true
in in
let f () = let f () =
@ -41,13 +36,13 @@ let start () =
pause () ; pause () ;
(*DEBUG (*DEBUG
List.iter (!_list) ~f:(fun x -> Printf.printf "%d\n%!" (Pid.to_int x)); List.iter (fun x -> Printf.printf "%d\n%!" x) (!_list) ;
*) *)
let continue () = let continue () =
List.fold_left (!_list) ~init:true ~f:( List.fold_left
fun accu x -> accu && (pid_is_running x) ( fun accu x -> accu && (pid_is_running x))
) true (!_list)
in in
if ( not (continue ()) ) then if ( not (continue ()) ) then
kill () kill ()
@ -55,7 +50,7 @@ let start () =
in in
_threads := ( (Thread.create f) () ) :: (!_threads) _threads := ( (Thread.create f) () ) :: (!_threads)
end end
;;
(** Stop watchdog *) (** Stop watchdog *)
let stop () = let stop () =
@ -63,14 +58,14 @@ let stop () =
_running := false _running := false
else else
failwith "Watchdog error: Already stopped" failwith "Watchdog error: Already stopped"
;;
(** Add a PID to tracking *) (** Add a PID to tracking *)
let add pid = let add pid =
if (not !_running) then if (not !_running) then
start (); start ();
_list := pid :: (!_list) _list := pid :: (!_list)
;;
(** Remove a PID from tracking *) (** Remove a PID from tracking *)
let del pid = let del pid =
@ -87,27 +82,26 @@ let del pid =
match (!_list) with match (!_list) with
| [] -> if (!_running) then stop () | [] -> if (!_running) then stop ()
| _ -> () | _ -> ()
;;
(** Fork and exec a new process *) (** Fork and exec a new process *)
let fork_exec ~prog ~argv () = let fork_exec ~prog ~args () =
let pid = let pid =
Unix.fork_exec ~prog ~argv () match Unix.fork () with
| 0 -> Unix.execvp prog args
| pid -> pid
in in
let f () = let f () =
add pid; add pid;
let success = let success =
match (Unix.waitpid pid) with match (Unix.waitpid [] pid) with
| Core_kernel.Std.Result.Ok () -> true | pid , Unix.WEXITED n -> true
| Core_kernel.Std.Result.Error (`Exit_non_zero n) -> | pid , Unix.WSIGNALED n ->
( Printf.printf "PID %d exited with code %d\n%!" ( Printf.printf "PID %d killed with signal %d\n%!" pid n;
(Pid.to_int pid) n ;
false ) false )
| Core_kernel.Std.Result.Error (`Signal n) -> | pid , Unix.WSTOPPED n ->
( Printf.printf "PID %d killed with signal %d (%s)\n%!" ( Printf.printf "PID %d stopped with signal %d\n%!" pid n;
(Pid.to_int pid) (Signal.to_system_int n)
(Signal.to_string n) ;
false ) false )
in in
del pid ; del pid ;
@ -116,11 +110,11 @@ let fork_exec ~prog ~argv () =
in in
_threads := ( (Thread.create f) () ) :: (!_threads); _threads := ( (Thread.create f) () ) :: (!_threads);
pid pid
;;
(** Wait for threads to finish *) (** Wait for threads to finish *)
let join () = let join () =
(* if (!_running) then stop (); *) (* if (!_running) then stop (); *)
List.iter ~f:Thread.join (!_threads); List.iter Thread.join (!_threads);
assert (not !_running) assert (not !_running)
;;

6
ocaml/_tags Normal file
View File

@ -0,0 +1,6 @@
true: package(cryptokit,zmq,str,sexplib,ppx_sexp_conv,ppx_deriving,getopt)
true: thread
false: profile
<*byte> : linkdep(c_bindings.o), custom
<*.native>: linkdep(c_bindings.o)

View File

@ -1,84 +0,0 @@
MAIN=qmcchem
# Main program to build
PACKAGES=-package core,cryptokit,str,zmq
#,ppx_sexp_conv
# Required opam packages, for example:
# PACKAGES=-package core,sexplib.syntax
THREAD=-thread
# If you need threding support, use:
# THREAD=-thread
SYNTAX=
# If you need pre-processing, use:
# SYNTAX=-syntax camlp4o
OCAMLC_FLAGS=-g -warn-error A
# Flags to give to ocamlc, for example:
# OCAMLC_FLAGS=-g -warn-error A
LINK_FLAGS=
# Flags to give to the linker, for example:
# LINK_FLAGS=-cclib '-Wl,-rpath=../lib,--enable-new-dtags'
GENERATED_NINJA=generated.ninja
# Name of the auto-generated ninja file
rule run_ninja
command = ../scripts/compile_ocaml.sh $target
description = Compiling OCaml executables
pool = console
rule run_ninja_ocaml
command = ../scripts/compile_ocaml_dep.sh
description = Finding dependencies in OCaml files
rule run_clean
command = ninja -f $GENERATED_NINJA -t clean ; rm -f $GENERATED_NINJA rm -f *.cmx *.cmi *.o .ls_md5 ; ninja -t clean
pool = console
description = Cleaning directory
rule ocamlc
command = ocamlfind ocamlc -c $OCAMLC_FLAGS $THREAD $PACKAGES $SYNTAX -o $out $in
description = Compiling $in (bytecode)
rule ocamlopt
command = ocamlfind ocamlopt -c $OCAMLC_FLAGS $THREAD $PACKAGES $SYNTAX -o $out $in
description = Compiling $in (native)
rule ocamlc_link
command = ocamlfind ocamlc $OCAMLC_FLAGS $THREAD $LINK_FLAGS $PACKAGES $SYNTAX -o $out $in
description = Compiling $out (bytecode)
rule ocamlopt_link
command = ocamlfind ocamlopt $OCAMLC_FLAGS $THREAD -linkpkg $PACKAGES $PACKAGES $SYNTAX -o $out $in
description = Compiling $out (native)
rule create_qptypes
command = ./$in
description = Creating $out
rule copy
command = cp $in $out
description = Copying $in to $out
build always: phony
build $GENERATED_NINJA: run_ninja_ocaml | Qptypes.ml ezfio.ml always
build ezfio.ml: copy ../EZFIO/Ocaml/ezfio.ml
build Qptypes.ml: create_qptypes qptypes_generator | ezfio.ml
build qptypes_generator.o qptypes_generator.cmx: ocamlopt qptypes_generator.ml | ezfio.ml
build qptypes_generator: ocamlopt_link qptypes_generator.cmx
build clean: run_clean
build $MAIN: run_ninja | ezfio.ml Qptypes.ml $GENERATED_NINJA
target = $MAIN
build all: run_ninja | ezfio.ml Qptypes.ml $GENERATED_NINJA
target =
default $MAIN

70
ocaml/c_bindings.c Normal file
View File

@ -0,0 +1,70 @@
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/alloc.h>
#include <caml/custom.h>
#include <caml/threads.h>
#include <string.h>
/* Adapted from
https://github.com/monadbobo/ocaml-core/blob/master/base/core/lib/linux_ext_stubs.c
*/
#include <unistd.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
CAMLprim value get_ipv4_address_for_interface(value v_interface)
{
CAMLparam1(v_interface);
struct ifreq ifr;
int fd = -1;
value res;
char* error = NULL;
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_addr.sa_family = AF_INET;
/* [ifr] is already initialized to zero, so it doesn't matter if the
incoming string is too long, and [strncpy] fails to add a \0. */
strncpy(ifr.ifr_name, String_val(v_interface), IFNAMSIZ - 1);
caml_enter_blocking_section();
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd == -1)
error = "error: couldn't allocate socket";
else {
if (ioctl(fd, SIOCGIFADDR, &ifr) < 0)
error = "error: ioctl(fd, SIOCGIFADDR, ...) failed";
(void) close(fd);
}
caml_leave_blocking_section();
if (error == NULL) {
/* This is weird but doing the usual casting causes errors when using
* the new gcc on CentOS 6. This solution was picked up on Red Hat's
* bugzilla or something. It also works to memcpy a sockaddr into
* a sockaddr_in. This is faster hopefully.
*/
union {
struct sockaddr sa;
struct sockaddr_in sain;
} u;
u.sa = ifr.ifr_addr;
res = caml_copy_string(inet_ntoa(u.sain.sin_addr));
}
else
res = caml_copy_string(error);
CAMLreturn(res);
}

13
ocaml/myocamlbuild.ml Normal file
View File

@ -0,0 +1,13 @@
open Ocamlbuild_plugin;;
dispatch begin function
| Before_rules ->
begin
end
| After_rules ->
begin
flag ["ocaml";"compile";"native";"gprof"] (S [ A "-p"]);
pdep ["link"] "linkdep" (fun param -> [param]);
end
| _ -> ()
end

View File

@ -1,288 +0,0 @@
#!/usr/bin/env python2
#
# Copyright 2015 Anthony Scemama
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file can be downloaded here:
# https://raw.githubusercontent.com/scemama/ninja_ocaml/master/ninja_ocaml.py
#
"""Build OCaml projects using ninja."""
__author__ = """Anthony Scemama <scemama@irsamc.ups-tlse.fr>"""
import os
import sys
import subprocess
def _help_ ():
print """
1) Download and install ninja :
https://github.com/martine/ninja/releases/latest
2) Copy the script into your OCaml project.
3) Run the script. It will build a default build.ninja file
4) Edit the build.ninja file
5) Compile the main target using `ninja`
6) Compile all the targets using `ninja all`
"""
def create_generated_ninja():
"""Creates the generated.ninja file"""
# Header
PACKAGES=""
THREAD=""
SYNTAX=""
OCAMLC_FLAGS=""
GENERATED_NINJA="generated.ninja"
with open('build.ninja','r') as f:
for line in f:
if line.startswith("PACKAGES"):
PACKAGES=line.split('=',1)[1].strip()
elif line.startswith("THREAD"):
THREAD=line.split('=',1)[1].strip()
elif line.startswith("SYNTAX"):
SYNTAX=line.split('=',1)[1].strip()
elif line.startswith("OCAMLC_FLAGS"):
OCAMLC_FLAGS=line.split('=',1)[1].strip()
elif line.startswith("LINK_FLAGS"):
LINK_FLAGS=line.split('=',1)[1].strip()
elif line.startswith("GENERATED_NINJA"):
GENERATED_NINJA=line.split('=',1)[1].strip()
if PACKAGES != "":
LINK_FLAGS = "-linkpkg "+PACKAGES
header = [
"""
########################################################
# This file was auto-generated. #
# This file will be overwritten. Don't edit this file! #
# Changes should be done in the build.ninja file. #
########################################################
""",
"PACKAGES=%s"%(PACKAGES),
"THREAD=%s"%(THREAD),
"SYNTAX=%s"%(SYNTAX),
"OCAMLC_FLAGS=%s"%(OCAMLC_FLAGS),
"LINK_FLAGS=%s"%(LINK_FLAGS),
"GENERATED_NINJA=%s"%(GENERATED_NINJA),
]
header += """
rule ocamlc
command = ocamlfind ocamlc -c $OCAMLC_FLAGS $THREAD $PACKAGES $SYNTAX -o $out $in
description = Compiling $out (bytecode)
rule ocamlopt
command = ocamlfind ocamlopt -c $OCAMLC_FLAGS $THREAD $PACKAGES $SYNTAX -o $o $in
description = Compiling $out (native)
rule ocamlc_link
command = ocamlfind ocamlc $OCAMLC_FLAGS $THREAD $LINK_FLAGS $PACKAGES $SYNTAX -o $out $in
description = Compiling $out (bytecode)
rule ocamlopt_link
command = ocamlfind ocamlopt $OCAMLC_FLAGS $THREAD $LINK_FLAGS $PACKAGES $SYNTAX -o $out $in
description = Compiling $out (native)
""".splitlines()
# Get the list of .ml files
all_files = os.listdir(os.getcwd())
files = [ os.path.splitext(i)[0] for i in all_files if i.endswith('.ml') ]
while "myocamlbuild" in files:
files.remove("myocamlbuild")
ml_files = ' '.join( [ '%s.ml'%i for i in files ] )
# Dependencies
result = subprocess.Popen(
("ocamlfind ocamldep {0} {1} {2}".format(PACKAGES,SYNTAX,ml_files)).split()
,stdout=subprocess.PIPE).communicate()[0]
result = result.replace('\\\n',' ')
dependencies = {}
for line in result.splitlines():
key, value = line.split(':')
dependencies[key.strip()] = value.strip()
result = header
template = """
build {0}.cmi: ocamlc {0}.mli | $GENERATED_NINJA
build {0}.cmo: ocamlc {0}.ml | $GENERATED_NINJA {1}
build {0}.cmx {0}.o: ocamlopt {0}.ml | $GENERATED_NINJA {2}
o = {0}.o
"""
template_root_byte = """
build {2}.byte: ocamlc_link {1} {0}
"""
template_root_native = """
build {2}: ocamlopt_link {1} {0}
"""
# Find roots
dep = {}
for f in dependencies:
dep[f] = [ i.strip() for i in dependencies[f].split() ]
roots = {}
for f in dependencies:
Found = False
for g,l in dep.iteritems():
if f in l:
Found = True
if not Found:
roots[f] = []
def get_deps(l):
result = []
for i in l:
if i in dep:
result += get_deps(dep[i])
result += l
newresult = []
for r in result:
if r not in newresult:
newresult.append(r)
return newresult
for r in roots:
roots[r] = [ i for i in get_deps(dep[r]) if not i.endswith(".cmi") ]
# Write the $GENERATED_NINJA file
result += [ template.format(basename,
dependencies["%s.cmo"%basename],
dependencies["%s.cmx"%basename]
) for basename in files ]
result += [ template_root_byte.format(basename,
' '.join(roots[basename]),
os.path.splitext(basename)[0]
) for basename in roots if basename.endswith('.cmo')]
result += [ template_root_native.format(basename,
' '.join(roots[basename]),
os.path.splitext(basename)[0]
) for basename in roots if basename.endswith('.cmx')]
output = '\n'.join(result)
try:
with open(GENERATED_NINJA,'r') as f:
inp = f.read()
except IOError:
inp = ""
if inp != output:
with open(GENERATED_NINJA,'w') as f:
f.write(output)
def create_build_ninja ():
with open('build.ninja','w') as f:
f.write("""
MAIN=
# Main program to build
PACKAGES=
# Required opam packages, for example:
# PACKAGES=-package core
THREAD=
# If you need threding support, use:
# THREAD=-thread
SYNTAX=
# If you need pre-processing, use:
# SYNTAX=-syntax camlp4o
OCAMLC_FLAGS=
# Flags to give to ocamlc, for example:
# OCAMLC_FLAGS=-g -warn-error A
LINK_FLAGS=
# Flags to give to the linker, for example:
# LINK_FLAGS=-cclib '-Wl,-rpath=../lib,--enable-new-dtags'
GENERATED_NINJA=generated.ninja
# Name of the auto-generated ninja file
rule create_generated
command = python2 ./ninja_ocaml.py
description = Finding dependencies between modules
rule run_ninja
command = ninja -f $in $target
description = Compiling OCaml executables
pool = console
rule run_clean
command = ninja -f $GENERATED_NINJA -t clean ; rm $GENERATED_NINJA
pool = console
description = Cleaning directory
rule ocamlc
command = ocamlfind ocamlc -c $OCAMLC_FLAGS $THREAD $PACKAGES $SYNTAX -o $out $in
description = Compiling $in (bytecode)
rule ocamlopt
command = ocamlfind ocamlopt -c $OCAMLC_FLAGS $THREAD $PACKAGES $SYNTAX -o $out $in
description = Compiling $in (native)
rule ocamlc_link
command = ocamlfind ocamlc $OCAMLC_FLAGS $THREAD $LINK_FLAGS $PACKAGES $SYNTAX -o $out $in
description = Compiling $out (bytecode)
rule ocamlopt_link
command = ocamlfind ocamlopt $OCAMLC_FLAGS $THREAD $LINK_FLAGS $PACKAGES $SYNTAX -o $out $in
description = Compiling $out (native)
build clean: run_clean
build always $GENERATED_NINJA: create_generated
build $MAIN: run_ninja $GENERATED_NINJA
target = $MAIN
build all: run_ninja $GENERATED_NINJA
target =
default $MAIN
""")
def main():
for h in "help -h -help --help ?".split():
if h in sys.argv:
_help_ ()
return
if "build.ninja" in os.listdir(os.getcwd()):
create_generated_ninja ()
else:
create_build_ninja ()
print """
==========================================================
A default build.ninja file was created.
Now, edit build.ninja and compile your project using:
ninja
==========================================================
"""
if __name__ == '__main__':
main()

View File

@ -1,16 +1,60 @@
open Core let update_command_line () =
let last = (Array.length Sys.argv) - 2 in
Sys.argv.(0) <- Sys.argv.(0) ^ "_" ^ Sys.argv.(1);
for i=1 to last do
Sys.argv.(i) <- Sys.argv.(i+1)
done;
Sys.argv.(last+1) <- ""
let command = let help () =
Command.group ~summary:"QMC=Chem command" [ Printf.printf "
"debug" , Qmcchem_debug.command ; qmcchem - QMC=Chem command
"edit" , Qmcchem_edit.command ;
"info" , Qmcchem_info.command ; Usage:
"md5" , Qmcchem_md5.command ;
"result", Qmcchem_result.command ; qmcchem [-h] COMMAND
"run" , Qmcchem_run.command ;
"stop" , Qmcchem_stop.command ; Arguments:
]
COMMAND QMC=Chem command to run :
[run|edit|stop|result|md5|info|debug]
Options:
-h --help Prints the help message.
Description:
Driver for subcommands.
"
let () = let () =
Command.run command if Array.length Sys.argv < 2 then
(help (); failwith "Inconsistent command line") ;
match String.trim Sys.argv.(1) with
| "-h" | "--help" ->
begin
help () ;
exit 0
end
| _ ->
begin
let command =
Sys.argv.(1)
in
update_command_line ();
match command with
| "debug" -> let open Qmcchem_debug in command ()
| "edit" -> let open Qmcchem_edit in command ()
| "info" -> let open Qmcchem_info in command ()
| "md5" -> let open Qmcchem_md5 in command ()
| "result" -> let open Qmcchem_result in command ()
| "run" -> let open Qmcchem_run in command ()
| "stop" -> let open Qmcchem_stop in command ()
| _ -> (help () ; failwith "Inconsistent command line")
end

View File

@ -1,85 +1,98 @@
open Core let global_replace x =
x
|> Str.global_replace (Str.regexp "Float.to_string") "string_of_float"
|> Str.global_replace (Str.regexp "Float.of_string") "float_of_string"
|> Str.global_replace (Str.regexp "Int.to_string") "string_of_int"
|> Str.global_replace (Str.regexp "Int.of_string") "int_of_string"
|> Str.global_replace (Str.regexp "String.\\(to\\|of\\)_string") ""
let input_data = " let input_data = "
* Positive_float : float * Positive_float : float
assert (x >= 0.) ; if not (x >= 0.) then
raise (Invalid_argument (Printf.sprintf \"Positive_float : (x >= 0.) : x=%f\" x));
* Strictly_positive_float : float * Strictly_positive_float : float
assert (x > 0.) ; if not (x > 0.) then
raise (Invalid_argument (Printf.sprintf \"Strictly_positive_float : (x > 0.) : x=%f\" x));
* Negative_float : float * Negative_float : float
assert (x <= 0.) ; if not (x <= 0.) then
raise (Invalid_argument (Printf.sprintf \"Negative_float : (x <= 0.) : x=%f\" x));
* Strictly_negative_float : float * Strictly_negative_float : float
assert (x < 0.) ; if not (x < 0.) then
raise (Invalid_argument (Printf.sprintf \"Strictly_negative_float : (x < 0.) : x=%f\" x));
* Positive_int64 : int64
if not (x >= 0L) then
raise (Invalid_argument (Printf.sprintf \"Positive_int64 : (x >= 0L) : x=%s\" (Int64.to_string x)));
* Positive_int : int * Positive_int : int
assert (x >= 0) ; if not (x >= 0) then
raise (Invalid_argument (Printf.sprintf \"Positive_int : (x >= 0) : x=%d\" x));
* Strictly_positive_int : int * Strictly_positive_int : int
assert (x > 0) ; if not (x > 0) then
raise (Invalid_argument (Printf.sprintf \"Strictly_positive_int : (x > 0) : x=%d\" x));
* Negative_int : int * Negative_int : int
if not (x <= 0) then
raise (Invalid_argument (Printf.sprintf \"Negative_int : (x <= 0) : x=%d\" x));
assert (x <= 0) ; assert (x <= 0) ;
* Det_coef : float * Det_coef : float
assert (x >= -1.) ; if (x < -1.) || (x > 1.) then
assert (x <= 1.) ; raise (Invalid_argument (Printf.sprintf \"Det_coef : (-1. <= x <= 1.) : x=%f\" x));
* Normalized_float : float * Normalized_float : float
assert (x <= 1.) ; if (x < 0.) || (x > 1.) then
assert (x >= 0.) ; raise (Invalid_argument (Printf.sprintf \"Normalized_float : (0. <= x <= 1.) : x=%f\" x));
* Strictly_negative_int : int * Strictly_negative_int : int
assert (x < 0) ; if not (x < 0) then
raise (Invalid_argument (Printf.sprintf \"Strictly_negative_int : (x < 0) : x=%d\" x));
* Non_empty_string : string * Non_empty_string : string
assert (x <> \"\") ; if (x = \"\") then
raise (Invalid_argument \"Non_empty_string\");
* Det_number_max : int * Det_number_max : int
assert (x > 0) ; assert (x > 0) ;
if (x > 100000000) then if (x > 100_000_000) then
warning \"More than 100 million determinants\"; warning \"More than 100 million determinants\";
"^
(*
"
* States_number : int * States_number : int
assert (x > 0) ; assert (x > 0) ;
if (x > 100) then if (x > 1000) then
warning \"More than 100 states\"; warning \"More than 1000 states\";
if (Ezfio.has_determinants_n_states_diag ()) then
assert (x <= (Ezfio.get_determinants_n_states_diag ()))
else if (Ezfio.has_determinants_n_states ()) then
assert (x <= (Ezfio.get_determinants_n_states ()));
* Bit_kind_size : int * Bit_kind_size : int
begin match x with begin match x with
| 8 | 16 | 32 | 64 -> () | 8 | 16 | 32 | 64 -> ()
| _ -> raise (Failure \"Bit_kind_size should be (8|16|32|64).\") | _ -> raise (Invalid_argument \"Bit_kind_size should be (8|16|32|64).\")
end; end;
* Bit_kind : int * Bit_kind : int
begin match x with begin match x with
| 1 | 2 | 4 | 8 -> () | 1 | 2 | 4 | 8 -> ()
| _ -> raise (Failure \"Bit_kind should be (1|2|4|8).\") | _ -> raise (Invalid_argument \"Bit_kind should be (1|2|4|8).\")
end; end;
* Bitmask_number : int * Bitmask_number : int
assert (x > 0) ; assert (x > 0) ;
"^
*)
"
* MO_coef : float * MO_coef : float
* MO_occ : float * MO_occ : float
assert (x >= 0.); if x < 0. then 0. else
if x > 2. then 2. else
* AO_coef : float * AO_coef : float
* AO_expo : float * AO_expo : float
assert (x >= 0.) ; if (x < 0.) then
raise (Invalid_argument (Printf.sprintf \"AO_expo : (x >= 0.) : x=%f\" x));
* AO_prim_number : int * AO_prim_number : int
assert (x > 0) ; assert (x > 0) ;
@ -102,6 +115,12 @@ let input_data = "
* MD5 : string * MD5 : string
assert ((String.length x) = 32); assert ((String.length x) = 32);
assert (
let a =
Array.init (String.length x) (fun i -> x.[i])
in
Array.fold_left (fun accu x -> accu && (x < 'g')) true a
);
* Rst_string : string * Rst_string : string
@ -116,40 +135,36 @@ let input_data = "
assert (x <> \"\") ; assert (x <> \"\") ;
" "
;;
let input_ezfio = " let input_ezfio = "
* MO_number : int * MO_number : int
mo_basis_mo_tot_num mo_basis_mo_num
1 : 10000 1 : 10_000
More than 10000 MOs More than 10_000 MOs
* AO_number : int * AO_number : int
ao_basis_ao_num ao_basis_ao_num
1 : 10000 1 : 10_000
More than 10000 AOs More than 10_000 AOs
* Nucl_number : int * Nucl_number : int
nuclei_nucl_num nuclei_nucl_num
1 : 10000 1 : 10_000
More than 10000 nuclei More than 10_000 nuclei
"^
(*
"
* N_int_number : int * N_int_number : int
determinants_n_int spindeterminants_n_int
1 : 30 1 : 30
N_int > 30 N_int > 30
* Det_number : int * Det_number : int
determinants_n_det spindeterminants_n_det
1 : 100000000 1 : 100_000_000
More than 100 million determinants More than 100 million determinants
" "
*)
""
;;
let untouched = " let untouched = "
" "
@ -168,33 +183,37 @@ end = struct
end end
" "
;;
let parse_input input= let parse_input input=
print_string "open Sexplib.Std\nlet warning = print_string\n" ;
let rec parse result = function let rec parse result = function
| [] -> result | [] -> result
| ( "" , "" )::tail -> parse result tail | ( "" , "" )::tail -> parse result tail
| ( t , text )::tail -> | ( t , text )::tail ->
let name,typ,params,params_val = let name,typ,params,params_val =
match String.split ~on:':' t with match String.split_on_char ':' t with
| [name;typ] -> (name,typ,"","") | [name;typ] -> (name,typ,"","")
| name::typ::params::params_val -> (name,typ,params, | name::typ::params::params_val -> (name,typ,params,
(String.concat params_val ~sep:":") ) (String.concat ":" params_val) )
| _ -> assert false | _ -> assert false
in in
let typ = String.strip typ let typ = String_ext.strip typ
and name = String.strip name in and name = String_ext.strip name in
let typ_cap = String.capitalize typ in let typ_cap = String.capitalize_ascii typ in
let newstring = Printf.sprintf template name typ typ typ params_val typ typ let newstring = Printf.sprintf template name typ typ typ params_val typ typ
typ typ params ( String.strip text ) typ_cap typ typ params ( String_ext.strip text ) typ_cap
in in
List.rev (parse (newstring::result) tail ) List.rev (parse (newstring::result) tail )
in in
String.split ~on:'*' input String_ext.split ~on:'*' input
|> List.map ~f:(String.lsplit2_exn ~on:'\n') |> List.map (String_ext.lsplit2_exn ~on:'\n')
|> parse [] |> parse []
|> String.concat |> String.concat ""
;; |> global_replace
|> print_string
let ezfio_template = format_of_string " let ezfio_template = format_of_string "
@ -223,7 +242,9 @@ end = struct
begin begin
match max with match max with
| %s -> () | %s -> ()
| i -> assert ( x <= i ) | i ->
if ( x > i ) then
raise (Invalid_argument (Printf.sprintf \"%s: %%s\" (%s.to_string x) ))
end ; end ;
x x
end end
@ -234,102 +255,103 @@ end
let parse_input_ezfio input= let parse_input_ezfio input=
let parse s = let parse s =
match ( match (
String.split s ~on:'\n' String_ext.split s ~on:'\n'
|> List.filter ~f:(fun x -> (String.strip x) <> "") |> List.filter (fun x -> (String_ext.strip x) <> "")
) with ) with
| [] -> "" | [] -> ""
| a :: b :: c :: d :: [] -> | a :: b :: c :: d :: [] ->
begin begin
let (name,typ) = String.lsplit2_exn ~on:':' a let (name,typ) = String_ext.lsplit2_exn ~on:':' a
and ezfio_func = b and ezfio_func = b
and (min, max) = String.lsplit2_exn ~on:':' c and (min, max) = String_ext.lsplit2_exn ~on:':' c
and msg = d and msg = d
in in
let (name, typ, ezfio_func, min, max, msg) = let (name, typ, ezfio_func, min, max, msg) =
match (List.map [ name ; typ ; ezfio_func ; min ; max ; msg ] ~f:String.strip) with match List.map String_ext.strip [ name ; typ ; ezfio_func ; min ; max ; msg ] with
| [ name ; typ ; ezfio_func ; min ; max ; msg ] -> (name, typ, ezfio_func, min, max, msg) | [ name ; typ ; ezfio_func ; min ; max ; msg ] -> (name, typ, ezfio_func, min, max, msg)
| _ -> assert false | _ -> assert false
in in
Printf.sprintf ezfio_template Printf.sprintf ezfio_template
name typ typ typ typ typ typ typ typ (String.capitalize typ) name typ typ typ typ typ typ typ typ (String.capitalize_ascii typ)
ezfio_func ezfio_func max min typ typ max msg min ezfio_func ezfio_func max min typ typ max msg min name (String.capitalize_ascii typ)
end end
| _ -> failwith "Error in input_ezfio" | _ -> failwith "Error in input_ezfio"
in in
String.split ~on:'*' input String_ext.split ~on:'*' input
|> List.map ~f:parse |> List.map parse
|> String.concat |> String.concat ""
|> global_replace
|> print_string
(** EZFIO *) (** EZFIO *)
let input_lines filename =
let ic = open_in filename in
let result = String_ext.input_lines ic in
close_in ic;
result
let create_ezfio_handler () = let create_ezfio_handler () =
let lines = let lines =
In_channel.with_file "ezfio.ml" ~f:In_channel.input_lines input_lines "ezfio.ml"
|> List.filteri ~f:(fun i _ -> i > 470) |> List.mapi (fun i l -> if i > 474 then Some l else None)
|> List.filter (fun x -> x <> None)
|> List.map (fun x ->
match x with
| Some x -> x
| None -> assert false)
in in
let functions = let functions =
List.map lines ~f:(fun x -> List.map (fun x ->
match String.split x ~on:' ' with match String.split_on_char ' ' x with
| _ :: x :: "()" :: "=" :: f :: dir :: item :: _-> (x, f, dir, item) | _ :: x :: "()" :: "=" :: f :: dir :: item :: _-> (x, f, dir, item)
| _ :: x :: "=" :: f :: dir :: item :: _-> (x, f, dir, item) | _ :: x :: "=" :: f :: dir :: item :: _-> (x, f, dir, item)
| _ -> ("","","","") | _ -> ("","","","")
) ) lines
in in
let has_functions = let has_functions =
List.filter functions ~f:(fun (x,_,_,_) -> String.is_prefix ~prefix:"has_" x) List.filter (fun (x,_,_,_) -> String.sub x 0 4 = "has_") functions
and get_functions = and get_functions =
List.filter functions ~f:(fun (x,_,_,_) -> String.is_prefix ~prefix:"get_" x) List.filter (fun (x,_,_,_) -> String.sub x 0 4 = "get_") functions
in in
let chop s =
match (Str.split_delim (Str.regexp ";;") s) with
| x :: _ -> x
| _ -> assert false
in
let result = let result =
[ "let decode_ezfio_message msg = [ "let decode_ezfio_message msg =
match msg with " ] @ match msg with " ] @
( (
List.map get_functions ~f:(fun (x,f,d,i) -> List.map (fun (x,f,d,i) ->
let i = let i = chop i in
match (String.chop_suffix i ~suffix:";;") with if (String.sub f ((String.length f)-6) 6 = "_array") then
| Some x -> x
| None -> i
in
if (String.is_suffix f ~suffix:"_array") then
Printf.sprintf " | \"%s\" -> Printf.sprintf " | \"%s\" ->
Ezfio.read_string_array %s %s Ezfio.read_string_array %s %s
|> Ezfio.flattened_ezfio |> Ezfio.flattened_ezfio
|> Array.to_list |> Array.to_list
|> String.concat ~sep:\" \"" x d i |> String.concat \" \"" x d i
else else
Printf.sprintf " | \"%s\" -> Ezfio.read_string %s %s" x d i Printf.sprintf " | \"%s\" -> Ezfio.read_string %s %s" x d i
) ) get_functions
) @ ( ) @ (
List.map has_functions ~f:(fun (x,_,_,_) -> List.map (fun (x,_,_,_) ->
Printf.sprintf " | \"%s\" -> if (Ezfio.%s ()) then \"T\" else \"F\"" x x Printf.sprintf " | \"%s\" -> if (Ezfio.%s ()) then \"T\" else \"F\"" x x
) ) has_functions
) @ [" | x -> failwith (x^\" : Unknown EZFIO function\")\n;;"] ) @ [" | x -> failwith (x^\" : Unknown EZFIO function\")\n;;"]
in in
String.concat result ~sep:"\n" String.concat "\n" result
|> print_endline
(** Main *) (** Main *)
let () = let () =
let input =
String.concat ~sep:"\n"
[ "open Core\nlet warning = print_string\n\n" ;
parse_input input_data ; parse_input input_data ;
parse_input_ezfio input_ezfio; parse_input_ezfio input_ezfio;
create_ezfio_handler (); print_endline untouched;
untouched ] create_ezfio_handler ()
and old_input =
let filename =
"Qptypes.ml"
in
match Sys.file_exists filename with
| `Yes -> In_channel.read_all "Qptypes.ml"
| `No | `Unknown -> "empty"
in
if input <> old_input then
Out_channel.write_all "Qptypes.ml" ~data:input

View File

@ -1,14 +1,15 @@
#!/bin/bash #!/bin/bash
# This script is supposed to run in $QMCCHEM_PATH # This script is supposed to run in $QMCCHEM_PATH
ninja -C ocaml clean make -C ocaml clean
if [[ -d src/IRPF90_temp ]] if [[ -d src/IRPF90_temp ]]
then then
ninja -C src/IRPF90_temp -t clean make -C src/IRPF90_temp clean
fi fi
ninja -t clean
rm -f ocaml/qmcchem ocaml/.ls_md5 ocaml/generated.ninja make -C EZFIO clean
rm -f ocaml/qmcchem ocaml/.ls_md5
rm -f EZFIO/Ocaml/ezfio.ml rm -f EZFIO/Ocaml/ezfio.ml
cd src cd src
rm -rf tags irpf90_entities irpf90.make IRPF90_temp IRPF90_man .ls_md5 rm -rf tags irpf90_entities irpf90.make IRPF90_temp IRPF90_man .ls_md5

View File

@ -19,8 +19,11 @@ then
REF=$(cat ${LSMD5_FILE}) REF=$(cat ${LSMD5_FILE})
fi fi
if [[ ${MD5} != ${REF} ]] if [[ ${MD5} == ${REF} ]]
then then
exit 0
fi
echo ${MD5} > ${LSMD5_FILE} echo ${MD5} > ${LSMD5_FILE}
echo Running IRPF90 echo Running IRPF90
@ -30,7 +33,7 @@ then
SRC="${SRC} ZMQ/f77_zmq_module.f90" SRC="${SRC} ZMQ/f77_zmq_module.f90"
OBJ="${OBJ} IRPF90_temp/ZMQ/f77_zmq_module.o" OBJ="${OBJ} IRPF90_temp/ZMQ/f77_zmq_module.o"
INCLUDES="${INCLUDES} -I AO -I SAMPLING -I TOOLS -I JASTROW -I MAIN -I PROPERTIES -I ZMQ" INCLUDES="${INCLUDES} -I AO -I SAMPLING -I TOOLS -I JASTROW -I MAIN -I PROPERTIES -I ZMQ"
IRPF90_FLAGS="${IRPF90_FLAGS} --ninja" IRPF90_FLAGS="${IRPF90_FLAGS}"
# Check IRPF90 version # Check IRPF90 version
if [[ $( ${IRPF90} -v | python2 -c "import sys ; print float(sys.stdin.read().rsplit('.',1)[0]) >= 1.6") == False ]] if [[ $( ${IRPF90} -v | python2 -c "import sys ; print float(sys.stdin.read().rsplit('.',1)[0]) >= 1.6") == False ]]
@ -42,8 +45,5 @@ then
export IRPF90 IRPF90_FLAGS INCLUDES LIB SRC OBJ export IRPF90 IRPF90_FLAGS INCLUDES LIB SRC OBJ
exec ${IRPF90} ${IRPF90_FLAGS} ${INCLUDES} || exit -1 exec ${IRPF90} ${IRPF90_FLAGS} ${INCLUDES} || exit -1
fi

View File

@ -8,4 +8,4 @@ fi
cd ${QMCCHEM_PATH}/ocaml || exit -1 cd ${QMCCHEM_PATH}/ocaml || exit -1
exec ninja -f generated.ninja ${@} || exit -1 exec make

View File

@ -1,31 +0,0 @@
#!/bin/bash
if [[ -z ${QMCCHEM_PATH} ]]
then
echo "Error: qmcchemrc not loaded"
exit -1
fi
cd ${QMCCHEM_PATH}/ocaml || exit -1
cp ${QMCCHEM_PATH}/EZFIO/Ocaml/ezfio.ml . || exit -1
LSMD5_FILE=${QMCCHEM_PATH}/ocaml/.ls_md5
FILES="*.ml *.mli"
MD5=$(ls -ltr --full-time ${FILES} 2>/dev/null | md5sum | cut -d ' ' -f 1)
REF=0
if [[ -f ${LSMD5_FILE} ]]
then
REF=$(cat ${LSMD5_FILE})
fi
if [[ ${MD5} != ${REF} ]]
then
echo ${MD5} > ${LSMD5_FILE}
echo Finding dependencies in OCaml files
python2 ./ninja_ocaml.py || exit -1
fi

View File

@ -6,6 +6,25 @@ then
exit -1 exit -1
fi fi
cd ${QMCCHEM_PATH}/src/IRPF90_temp || exit -1
exec ninja ${@} cd ${QMCCHEM_PATH}/src || exit -1
source ${QMCCHEM_PATH}/make.config
LIB="${LIB} ${QMCCHEM_PATH}/lib/libezfio_irp.a ${QMCCHEM_PATH}/lib/libf77zmq.a ${QMCCHEM_PATH}/lib/libzmq.a -lstdc++ -lrt -lz"
SRC="${SRC} ZMQ/f77_zmq_module.f90"
OBJ="${OBJ} IRPF90_temp/ZMQ/f77_zmq_module.o"
INCLUDES="${INCLUDES} -I AO -I SAMPLING -I TOOLS -I JASTROW -I MAIN -I PROPERTIES -I ZMQ"
IRPF90_FLAGS="${IRPF90_FLAGS} ${INCLUDES}"
# Check IRPF90 version
if [[ $( ${IRPF90} -v | python2 -c "import sys ; print float(sys.stdin.read().rsplit('.',1)[0]) >= 1.6") == False ]]
then
echo "IRPF90 version >= 1.6 required"
exit -1
fi
export IRPF90 IRPF90_FLAGS INCLUDES LIB SRC OBJ
exec make ${@}

1
src/.gitignore vendored
View File

@ -4,5 +4,4 @@ irpf90.make
irpf90_entities irpf90_entities
tags tags
.ls_md5 .ls_md5
Makefile
properties.pyc properties.pyc

6
src/Makefile Normal file
View File

@ -0,0 +1,6 @@
IRPF90+= $(IRPF90_FLAGS)
include irpf90.make
export
irpf90.make: $(filter-out IRPF90_temp/%, $(wildcard */*.irp.f)) $(wildcard *.irp.f) $(wildcard *.inc.f) Makefile
$(IRPF90)

View File

@ -52,7 +52,7 @@ data = [ \
] ]
data_no_set = [\ data_no_set = [\
("mo_basis_mo_tot_num" , "integer" , ""), ("mo_basis_mo_num" , "integer" , ""),
("pseudo_ao_pseudo_grid" , "double precision" , "(ao_num,pseudo_lmax+pseudo_lmax+1,pseudo_lmax-0+1,nucl_num,pseudo_grid_size)"), ("pseudo_ao_pseudo_grid" , "double precision" , "(ao_num,pseudo_lmax+pseudo_lmax+1,pseudo_lmax-0+1,nucl_num,pseudo_grid_size)"),
("pseudo_mo_pseudo_grid" , "double precision" , "(ao_num,pseudo_lmax+pseudo_lmax+1,pseudo_lmax-0+1,nucl_num,pseudo_grid_size)"), ("pseudo_mo_pseudo_grid" , "double precision" , "(ao_num,pseudo_lmax+pseudo_lmax+1,pseudo_lmax-0+1,nucl_num,pseudo_grid_size)"),
("pseudo_pseudo_dz_k" , "double precision" , "(nucl_num,pseudo_klocmax)"), ("pseudo_pseudo_dz_k" , "double precision" , "(nucl_num,pseudo_klocmax)"),

View File

@ -410,7 +410,7 @@ BEGIN_PROVIDER [ integer, mo_tot_num ]
END_DOC END_DOC
mo_tot_num = -1 mo_tot_num = -1
call get_mo_basis_mo_tot_num(mo_tot_num) call get_mo_basis_mo_num(mo_tot_num)
if (mo_tot_num <= 0) then if (mo_tot_num <= 0) then
call abrt(irp_here,'Total number of MOs can''t be <0') call abrt(irp_here,'Total number of MOs can''t be <0')
endif endif