From 152093dd7c777f9a97cc7c91cc3c6f5aa0fd62d5 Mon Sep 17 00:00:00 2001 From: Francois Coppens Date: Wed, 14 Apr 2021 11:42:45 +0200 Subject: [PATCH] - Added python program that computes general properties of a given Slater-matrix. - Added a Verificarlo option to smvars.sh that sets the Verificarlo backend and uses LLVM for compilation. - Fixed residual_max() to give the Max-norm. --- smvars.sh | 6 +++ tests/test_h5.cpp | 1 + tools/convert-to-h5.py | 1 + tools/matrix_properties.py | 87 ++++++++++++++++++++++++++++++++++++++ tools/stats.py | 1 - 5 files changed, 95 insertions(+), 1 deletion(-) mode change 100644 => 100755 tools/convert-to-h5.py create mode 100755 tools/matrix_properties.py diff --git a/smvars.sh b/smvars.sh index 06cc242..b9695aa 100644 --- a/smvars.sh +++ b/smvars.sh @@ -30,6 +30,12 @@ case $ENV in export HDF5_CXXLINKER=clang++ export ENV=LLVM ;; + vfc) + export HDF5_CXX=clang++ + export HDF5_CXXLINKER=clang++ + export ENV=LLVM + export VFC_BACKENDS="libinterflop_ieee.so --count-op" + ;; gnu) export HDF5_CXX=g++ export HDF5_CXXLINKER=g++ diff --git a/tests/test_h5.cpp b/tests/test_h5.cpp index b7ad2e1..eb719e5 100644 --- a/tests/test_h5.cpp +++ b/tests/test_h5.cpp @@ -17,6 +17,7 @@ double residual_max(double * A, unsigned int Dim) { for (unsigned int i = 0; i < Dim; i++) { for (unsigned int j = 0; j < Dim; j++) { double delta = (A[i * Dim + j] - (i == j)); + delta = abs(delta); if (delta > max) max = delta; } } diff --git a/tools/convert-to-h5.py b/tools/convert-to-h5.py old mode 100644 new mode 100755 index c98aea6..d9faffe --- a/tools/convert-to-h5.py +++ b/tools/convert-to-h5.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python import h5py import numpy as np from parse import parse diff --git a/tools/matrix_properties.py b/tools/matrix_properties.py new file mode 100755 index 0000000..71f90ca --- /dev/null +++ b/tools/matrix_properties.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python +import h5py +import sys +import numpy as np +import math + +fname = sys.argv[1] +dataset =h5py.File(fname, "r") +cycle_num = sys.argv[2] +cycle = "cycle_" + cycle_num +cgroup = dataset[cycle] + +slater_matrix = cgroup["slater_matrix"][()] +slater_inverse = cgroup["slater_inverse"][()] +nupdates = cgroup["nupdates"][()] +update_idxs = cgroup["col_update_index"][()] +updates = cgroup["updates"][()] +dim = cgroup["slater_matrix_dim"][()] +Id = np.identity(dim) + +print(f'========================\n== UPDATE CYCLE: {cycle_num} ==\n========================') +print() +print(f'Number of updates: {nupdates}') +print(f'Columns that need to be updated (replaced): {update_idxs}\n') + +# det_sm = np.linalg.det(slater_matrix) +# det_si = np.linalg.det(slater_inverse) +# eigen_values_sm, eigen_vectors_sm = np.linalg.eig(slater_matrix) +# eigen_values_si, eigen_vectors_si = np.linalg.eig(slater_inverse) + +# SSi = np.matmul(slater_matrix, slater_inverse) +# detSSi = np.linalg.det(SSi) +# delta = Id - SSi +# res_max = np.amax(abs(delta)) +# res_max2 = res_max*res_max +# res_fro = np.linalg.norm(delta, 'fro') +# res_fro2 = res_fro*res_fro + +# print(f'Determinant of Slater-matrix: {det_sm}') +# print(f'Determinant of inverse Slater-matrix: {det_si}\n') + +# print(f'Smalles eigenvalue (modulus) of Slater-matrix: {np.amin(abs(eigen_values_sm))}') +# print(f'Smalles eigenvalue (modulus) of inverse Slater-matrix: {np.amin(abs(eigen_values_si))}\n') + +# print(f'Det(S*Sinv): {detSSi}') +# print(f'Residual (Id - S*Sinv) (Max norm): {res_max}') +# print(f'Residual (Max norm sq.): {res_max2}') +# print(f'Residual (Frob. norm): {res_fro}') +# print(f'Residual (Frob. norm sq.): {res_fro2}\n') + +print(f'+-----------------------------------------------+\n| Updating Slater-matrix... |') +slater_matrix_new = slater_matrix +index = 0 +for update in updates: + column = update_idxs[index] - 1 + slater_matrix_new[column] = update + index = index + 1 + +print(f'| Computing inverse of updated Slater-matrix... |\n+-----------------------------------------------+\n') +slater_inverse_new = np.linalg.inv(slater_matrix_new) + +det_sm = np.linalg.det(slater_matrix_new) +det_si = np.linalg.det(slater_inverse_new) +eigen_values_sm, eigen_vectors_sm = np.linalg.eig(slater_matrix_new) +eigen_values_si, eigen_vectors_si = np.linalg.eig(slater_inverse_new) + +SSi = np.matmul(slater_matrix_new, slater_inverse_new) +detSSi = np.linalg.det(SSi) +delta = Id - SSi +res_max = np.amax(abs(delta)) +res_max2 = res_max*res_max +res_fro = np.linalg.norm(delta, 'fro') +res_fro2 = res_fro*res_fro + +print(f'(DUSM) Determinant of UPDATED Slater-matrix: {cycle_num}, {det_sm}') +print(f'(DUSI) Determinant of UPDATED inverse Slater-matrix: {det_si}\n') + +print(f'(SEVUSM) Smalles eigenvalue (modulus) of UPDATED Slater-matrix: {np.amin(abs(eigen_values_sm))}') +print(f'(SEVUSI) Smalles eigenvalue (modulus) of UPDATED inverse Slater-matrix: {np.amin(abs(eigen_values_si))}\n') + +print(f'(DSSI) det(S*Sinv): {detSSi}') +print(f'(RMN) Residual (Id - S*Sinv) (Max norm): {res_max}') +print(f'(RMN2) Residual (Max norm sq.): {res_max2}') +print(f'(RFN) Residual (Frob. norm): {res_fro}') +print(f'(RFN2) Residual (Frob. norm sq.): {res_fro2}\n') + +dataset.close() \ No newline at end of file diff --git a/tools/stats.py b/tools/stats.py index f685547..4f58415 100755 --- a/tools/stats.py +++ b/tools/stats.py @@ -1,5 +1,4 @@ #!/usr/bin/env python - import sys import numpy as np