diff --git a/org/qmckl_jastrow_champ.org b/org/qmckl_jastrow_champ.org index 3f6314b..f51f6be 100644 --- a/org/qmckl_jastrow_champ.org +++ b/org/qmckl_jastrow_champ.org @@ -68,10 +68,11 @@ ** Reformulation of the three-body part To accelerate the computation of the three-body part, the Jastrow - factor is re-expressed as follows: + factor is re-expressed as follows, with $m=(p-k)/2 -l/2$: + \begin{eqnarray*} - & & \sum_{\alpha=1}^{N_{\text{nucl}}} + J_{kpl} & = & \sum_{\alpha=1}^{N_{\text{nucl}}} \sum_{i=1}^{N_{\text{elec}}} \sum_{j=1}^{i-1} c_{lkp\alpha} \left[ g_\text{e}({r}_{ij}) \right]^k @@ -93,8 +94,35 @@ \left[ \left[ g_\alpha({R}_{i\alpha}) \right]^{l+m} \left[ g_\alpha({R}_{j\alpha}) \right]^{m} + \left[ g_\alpha({R}_{i\alpha}) \right]^{l} \left[ g_\alpha({R}_{j\alpha}) \right]^{l+m} \right] \\ + & = & + \sum_{\alpha=1}^{N_{\text{nucl}}} c_{lkp\alpha} + \sum_{i=1}^{N_{\text{elec}}} + \sum_{j=1}^{N_{\text{elec}}} + \left[ g_\alpha({R}_{i\alpha}) \right]^{l+m} + \left[ g_\text{e}({r}_{ij}) \right]^k + \left[ g_\alpha({R}_{j\alpha}) \right]^{m} \\ + & = & + \sum_{\alpha=1}^{N_{\text{nucl}}} c_{lkp\alpha} + \sum_{i=1}^{N_{\text{elec}}} + \left[ g_\alpha({R}_{i\alpha}) \right]^{l+m} + P_{i\alpha}^{km}, \text{ with } + P_{i\alpha}^{km} = + \sum_{j=1}^{N_{\text{elec}}} + \left[ g_\text{e}({r}_{ij}) \right]^k + \left[ g_\alpha({R}_{j\alpha}) \right]^{m}. \\ +J & = & + \sum_{p=2}^{N_{\text{ord}}} + \sum_{k=0}^{p-1} + \sum_{l=0}^{p-k-2\delta_{k,0}} + \sum_{\alpha=1}^{N_{\text{nucl}}} c_{lkp\alpha} + \sum_{i=1}^{N_{\text{elec}}} + \left[ g_\alpha({R}_{i\alpha}) \right]^{(p-k+l)/2} + P_{i\alpha}^{k, (p-k-l)/2} \end{eqnarray*} + The computation of $P$ scales as $\mathcal{O}(N_\text{elec}^2 N_\text{nucl}n^2)$, and + the computation of $J$ scales as $\mathcal{O}(N_\text{elec}N_\text{nucl}n^2)$. + * Headers :noexport: #+begin_src elisp :noexport :results none (org-babel-lob-ingest "../tools/lib.org") @@ -126,6 +154,11 @@ #include "qmckl_context_private_type.h" #include "qmckl_jastrow_champ_private_func.h" +#ifdef __GNUC__ +#pragma GCC push_options +#pragma GCC optimize ("O0") +#endif + int main() { qmckl_context context; context = qmckl_context_create(); @@ -1798,7 +1831,6 @@ for (int64_t i=0 ; i> elec_coord = np.array(elec_coord)[0] elec_dist = np.zeros(shape=(elec_num, elec_num),dtype=float) + for i in range(elec_num): for j in range(elec_num): - elec_dist[i, j] = np.linalg.norm(elec_coord[i] - elec_coord[j]) + elec_dist[i,j] = np.linalg.norm(elec_coord[i] - elec_coord[j]) -kappa = 0.6 +kappa_e = 0.6 -een_rescaled_e_ij = np.zeros(shape=(elec_num * (elec_num - 1)//2, cord_num+1), dtype=float) -een_rescaled_e_ij[:,0] = 1.0 - -k = 0 -for j in range(elec_num): - for i in range(j): - een_rescaled_e_ij[k, 1] = np.exp(-kappa * elec_dist[i, j]) - k = k + 1 - -for l in range(2, cord_num + 1): - for k in range(elec_num * (elec_num - 1)//2): - een_rescaled_e_ij[k, l] = een_rescaled_e_ij[k, l - 1] * een_rescaled_e_ij[k, 1] - -een_rescaled_e = np.zeros(shape=(elec_num, elec_num, cord_num + 1), dtype=float) -een_rescaled_e[:,:,0] = 1.0 - -for l in range(1,cord_num+1): - k = 0 +een_rescaled_e = np.zeros(shape=(cord_num+1, elec_num, elec_num), dtype=float) +for i in range(elec_num): for j in range(elec_num): - for i in range(j): - x = een_rescaled_e_ij[k, l] - een_rescaled_e[i, j, l] = x - een_rescaled_e[j, i, l] = x - k = k + 1 - -for l in range(0,cord_num+1): - for j in range(0, elec_num): - een_rescaled_e[j,j,l] = 0.0 - -print(" een_rescaled_e[0, 2, 1] = ",een_rescaled_e[0, 2, 1]) -print(" een_rescaled_e[0, 3, 1] = ",een_rescaled_e[0, 3, 1]) -print(" een_rescaled_e[0, 4, 1] = ",een_rescaled_e[0, 4, 1]) -print(" een_rescaled_e[1, 3, 2] = ",een_rescaled_e[1, 3, 2]) -print(" een_rescaled_e[1, 4, 2] = ",een_rescaled_e[1, 4, 2]) -print(" een_rescaled_e[1, 5, 2] = ",een_rescaled_e[1, 5, 2]) + for p in range(0, cord_num+1): + een_rescaled_e[p,i,j] = np.exp(-kappa_e * p * elec_dist[i,j]) #+end_src - #+RESULTS: - : een_rescaled_e[0, 2, 1] = 0.2211015082992776 - : een_rescaled_e[0, 3, 1] = 0.2611178387068169 - : een_rescaled_e[0, 4, 1] = 0.08840123507637472 - : een_rescaled_e[1, 3, 2] = 0.10166855073546568 - : een_rescaled_e[1, 4, 2] = 0.011311807324686948 - : een_rescaled_e[1, 5, 2] = 0.5257156022077619 + #+NAME:test_ee + #+begin_src python :results output :exports none :noweb yes +<> +for p in range(cord_num+1): +# for i in range(elec_num): +# for j in range(elec_num): + for i in range(3): + for j in range(3): + print(f"assert( fabs(een_rescaled_e[0][{p}][{i}][{j}] - ({een_rescaled_e[p,i,j]})) < 1.e-10 );") + #+end_src - #+begin_src c :tangle (eval c_test) + #+begin_src c :tangle (eval c_test) :noweb yes assert(qmckl_electron_provided(context)); { -double een_rescaled_e[walk_num][(cord_num + 1)][elec_num][elec_num]; -rc = qmckl_get_jastrow_champ_een_distance_rescaled_e(context, &(een_rescaled_e[0][0][0][0]),elec_num*elec_num*(cord_num+1)*walk_num); + double een_rescaled_e[walk_num][(cord_num + 1)][elec_num][elec_num]; + rc = qmckl_get_jastrow_champ_een_distance_rescaled_e(context, &(een_rescaled_e[0][0][0][0]),elec_num*elec_num*(cord_num+1)*walk_num); -// value of (0,2,1) -assert(fabs(een_rescaled_e[0][1][0][2]- 0.2211015082992776 ) < 1.e-12); -assert(fabs(een_rescaled_e[0][1][0][3]- 0.2611178387068169 ) < 1.e-12); -assert(fabs(een_rescaled_e[0][1][0][4]- 0.0884012350763747 ) < 1.e-12); -assert(fabs(een_rescaled_e[0][2][1][3]- 0.1016685507354656 ) < 1.e-12); -assert(fabs(een_rescaled_e[0][2][1][4]- 0.0113118073246869 ) < 1.e-12); -assert(fabs(een_rescaled_e[0][2][1][5]- 0.5257156022077619 ) < 1.e-12); + <> } { @@ -7236,13 +7225,13 @@ assert(fabs(een_rescaled_e[0][2][1][5]- 0.5257156022077619 ) < 1.e-12); double een_rescaled_e_doc[walk_num][cord_num+1][elec_num][elec_num]; memset(&(een_rescaled_e_doc[0][0][0][0]), 0, sizeof(een_rescaled_e_doc)); rc = qmckl_compute_een_rescaled_e(context, walk_num, elec_num, cord_num, - 0.6, &(ee_distance[0]), &(een_rescaled_e_doc[0][0][0][0])); + rescale_factor_ee, &(ee_distance[0]), &(een_rescaled_e_doc[0][0][0][0])); assert(rc == QMCKL_SUCCESS); double een_rescaled_e_hpc[walk_num][cord_num+1][elec_num][elec_num]; memset(&(een_rescaled_e_hpc[0][0][0][0]), 0, sizeof(een_rescaled_e_hpc)); rc = qmckl_compute_een_rescaled_e_hpc(context, walk_num, elec_num, cord_num, - 0.6, &(ee_distance[0]), &(een_rescaled_e_hpc[0][0][0][0])); + rescale_factor_ee, &(ee_distance[0]), &(een_rescaled_e_hpc[0][0][0][0])); assert(rc == QMCKL_SUCCESS); for (int64_t i = 0; i < walk_num; i++) { @@ -7270,7 +7259,12 @@ assert(fabs(een_rescaled_e[0][2][1][5]- 0.5257156022077619 ) < 1.e-12); \[ \frac{\partial}{\partial x} \left[ {g_\text{e}(r)}\right]^p = -\frac{x}{r} \kappa_\text{e}\, p\,\left[ {g_\text{e}(r)}\right]^p \] - \[ \Delta \left[ {g_\text{e}(r)}\right]^p = \frac{2}{r} \kappa_\text{e}\, p\,\left[ {g_\text{e}(r)}\right]^p \right] + \left(\frac{\partial}{\partial x}\left[ {g_\text{e}(r)}\right]^p \right)^2 + \left(\frac{\partial}{\partial y}\left[ {g_\text{e}(r)}\right]^p \right)^2 + \left(\frac{\partial}{\partial z}\left[ {g_\text{e}(r)}\right]^p \right)^2 \] + + \[ \Delta \left[ {g_\text{e}(r)}\right]^p = \kappa_\text{e}\, + p\,\left[ - \frac{2}{r} + \kappa_\text{e}\, p \right] \left[ + {g_\text{e}(r)} \right]^p \] + + Derivatives are set to zero at $r_{ii}$ to avoid NaNs. **** Get @@ -7408,6 +7402,7 @@ qmckl_exit_code qmckl_provide_een_rescaled_e_gl(qmckl_context context) :END: #+NAME: qmckl_factor_een_rescaled_e_gl_args + |---------------------+-------------------------------------------------------+--------+--------------------------------------| | Variable | Type | In/Out | Description | |---------------------+-------------------------------------------------------+--------+--------------------------------------| | ~context~ | ~qmckl_context~ | in | Global state | @@ -7419,6 +7414,7 @@ qmckl_exit_code qmckl_provide_een_rescaled_e_gl(qmckl_context context) | ~ee_distance~ | ~double[walk_num][elec_num][elec_num]~ | in | Electron-electron distances | | ~een_rescaled_e~ | ~double[walk_num][0:cord_num][elec_num][elec_num]~ | in | Electron-electron distances | | ~een_rescaled_e_gl~ | ~double[walk_num][0:cord_num][elec_num][4][elec_num]~ | out | Electron-electron rescaled distances | + |---------------------+-------------------------------------------------------+--------+--------------------------------------| #+begin_src f90 :comments org :tangle (eval f) :noweb yes function qmckl_compute_jastrow_champ_factor_een_rescaled_e_gl_doc( & @@ -7433,7 +7429,7 @@ function qmckl_compute_jastrow_champ_factor_een_rescaled_e_gl_doc( & integer(c_int64_t) , intent(in), value :: elec_num integer(c_int64_t) , intent(in), value :: cord_num real(c_double) , intent(in), value :: rescale_factor_ee - real(c_double) , intent(in) :: coord_ee(elec_num,3,walk_num) + real(c_double) , intent(in) :: coord_ee(elec_num,walk_num,3) real(c_double) , intent(in) :: ee_distance(elec_num,elec_num,walk_num) real(c_double) , intent(in) :: een_rescaled_e(elec_num,elec_num,0:cord_num,walk_num) real(c_double) , intent(out) :: een_rescaled_e_gl(elec_num,4,elec_num,0:cord_num,walk_num) @@ -7445,7 +7441,10 @@ function qmckl_compute_jastrow_champ_factor_een_rescaled_e_gl_doc( & double precision :: rij_inv(elec_num) + allocate(elec_dist_gl(elec_num, 4, elec_num)) + elec_dist_gl = 0.d0 + een_rescaled_e_gl = 0.d0 info = QMCKL_SUCCESS @@ -7482,7 +7481,7 @@ function qmckl_compute_jastrow_champ_factor_een_rescaled_e_gl_doc( & enddo do i = 1, elec_num do ii = 1, 3 - elec_dist_gl(i, ii, j) = (coord_ee(i, ii, nw) - coord_ee(j, ii, nw)) * rij_inv(i) + elec_dist_gl(i, ii, j) = (coord_ee(i, nw, ii) - coord_ee(j, nw, ii)) * rij_inv(i) end do elec_dist_gl(i, 4, j) = 2.0d0 * rij_inv(i) end do @@ -7492,27 +7491,20 @@ function qmckl_compute_jastrow_champ_factor_een_rescaled_e_gl_doc( & een_rescaled_e_gl(:,:,:,0,nw) = 0.d0 do l = 1, cord_num - kappa_l = - dble(l) * rescale_factor_ee + kappa_l = -dble(l) * rescale_factor_ee do j = 1, elec_num do i = 1, elec_num - een_rescaled_e_gl(i, 1, j, l, nw) = kappa_l * elec_dist_gl(i, 1, j) - een_rescaled_e_gl(i, 2, j, l, nw) = kappa_l * elec_dist_gl(i, 2, j) - een_rescaled_e_gl(i, 3, j, l, nw) = kappa_l * elec_dist_gl(i, 3, j) - een_rescaled_e_gl(i, 4, j, l, nw) = kappa_l * elec_dist_gl(i, 4, j) - end do - - do i = 1, elec_num - een_rescaled_e_gl(i, 4, j, l, nw) = een_rescaled_e_gl(i, 4, j, l, nw) & - + een_rescaled_e_gl(i, 1, j, l, nw) * een_rescaled_e_gl(i, 1, j, l, nw) & - + een_rescaled_e_gl(i, 2, j, l, nw) * een_rescaled_e_gl(i, 2, j, l, nw) & - + een_rescaled_e_gl(i, 3, j, l, nw) * een_rescaled_e_gl(i, 3, j, l, nw) - end do - - do i = 1, elec_num - een_rescaled_e_gl(i,1,j,l,nw) = een_rescaled_e_gl(i,1,j,l,nw) * een_rescaled_e(i,j,l,nw) - een_rescaled_e_gl(i,2,j,l,nw) = een_rescaled_e_gl(i,2,j,l,nw) * een_rescaled_e(i,j,l,nw) - een_rescaled_e_gl(i,3,j,l,nw) = een_rescaled_e_gl(i,3,j,l,nw) * een_rescaled_e(i,j,l,nw) - een_rescaled_e_gl(i,4,j,l,nw) = een_rescaled_e_gl(i,4,j,l,nw) * een_rescaled_e(i,j,l,nw) + if (i /= j) then + een_rescaled_e_gl(i, 1, j, l, nw) = kappa_l * elec_dist_gl(i, 1, j) * een_rescaled_e(i,j,l,nw) + een_rescaled_e_gl(i, 2, j, l, nw) = kappa_l * elec_dist_gl(i, 2, j) * een_rescaled_e(i,j,l,nw) + een_rescaled_e_gl(i, 3, j, l, nw) = kappa_l * elec_dist_gl(i, 3, j) * een_rescaled_e(i,j,l,nw) + een_rescaled_e_gl(i, 4, j, l, nw) = kappa_l * (elec_dist_gl(i, 4, j) + kappa_l) * een_rescaled_e(i,j,l,nw) + else + een_rescaled_e_gl(i, 1, j, l, nw) = 0.d0 + een_rescaled_e_gl(i, 2, j, l, nw) = 0.d0 + een_rescaled_e_gl(i, 3, j, l, nw) = 0.d0 + een_rescaled_e_gl(i, 4, j, l, nw) = 0.d0 + end if end do end do end do @@ -7599,10 +7591,10 @@ qmckl_compute_jastrow_champ_factor_een_rescaled_e_gl_hpc (const qmckl_context co #endif for (int64_t nw = 0; nw < walk_num; ++nw) { - double rij_inv[elec_num]; - for (int64_t j=0; j> -<> - -elec_coord = np.array(elec_coord)[0] -elec_dist = np.zeros(shape=(elec_num, elec_num),dtype=float) +een_rescaled_e_gl = np.zeros(shape=(4, cord_num+1, elec_num, elec_num), dtype=float) for i in range(elec_num): - for j in range(elec_num): - elec_dist[i, j] = np.linalg.norm(elec_coord[i] - elec_coord[j]) - -elec_dist_gl = np.zeros(shape=(4,elec_num, elec_num),dtype=float) -for j in range(elec_num): - for i in range(elec_num): - rij_inv = 1.0 / elec_dist[i, j] - for ii in range(3): - elec_dist_gl[ii, i, j] = (elec_coord[i][ii] - elec_coord[j][ii]) * rij_inv - elec_dist_gl[3, i, j] = 2.0 * rij_inv - elec_dist_gl[:, j, j] = 0.0 - - -kappa = 0.6 - -een_rescaled_e_ij = np.zeros(shape=(elec_num * (elec_num - 1)//2, cord_num+1), dtype=float) -een_rescaled_e_ij[:,0] = 1.0 - -k = 0 -for j in range(elec_num): - for i in range(j): - een_rescaled_e_ij[k, 1] = np.exp(-kappa * elec_dist[i, j]) - k = k + 1 - -for l in range(2, cord_num + 1): - for k in range(elec_num * (elec_num - 1)//2): - een_rescaled_e_ij[k, l] = een_rescaled_e_ij[k, l - 1] * een_rescaled_e_ij[k, 1] - -een_rescaled_e = np.zeros(shape=(elec_num, elec_num, cord_num + 1), dtype=float) -een_rescaled_e[:,:,0] = 1.0 - -for l in range(1,cord_num+1): - k = 0 - for j in range(elec_num): - for i in range(j): - x = een_rescaled_e_ij[k, l] - een_rescaled_e[i, j, l] = x - een_rescaled_e[j, i, l] = x - k = k + 1 - -een_rescaled_e_gl = np.zeros(shape=(elec_num,4,elec_num,cord_num+1),dtype=float) -for l in range(0,cord_num+1): - kappa_l = -1.0 * kappa * l - for j in range(0,elec_num): - for i in range(0,elec_num): - for ii in range(0,4): - een_rescaled_e_gl[i,ii,j,l] = kappa_l * elec_dist_gl[ii,i,j] - een_rescaled_e_gl[i,3,j,l] = een_rescaled_e_gl[i,3,j,l] + \ - een_rescaled_e_gl[i,0,j,l] * een_rescaled_e_gl[i,0,j,l] + \ - een_rescaled_e_gl[i,1,j,l] * een_rescaled_e_gl[i,1,j,l] + \ - een_rescaled_e_gl[i,2,j,l] * een_rescaled_e_gl[i,2,j,l] - - for ii in range(0,4): - een_rescaled_e_gl[i,ii,j,l] = een_rescaled_e_gl[i,ii,j,l] * een_rescaled_e[i,j,l] - -print(" een_rescaled_e_gl[1, 1, 3, 1] = ",een_rescaled_e_gl[0, 0, 2, 1]) -print(" een_rescaled_e_gl[1, 1, 4, 1] = ",een_rescaled_e_gl[0, 0, 3, 1]) -print(" een_rescaled_e_gl[1, 1, 5, 1] = ",een_rescaled_e_gl[0, 0, 4, 1]) -print(" een_rescaled_e_gl[2, 1, 4, 2] = ",een_rescaled_e_gl[1, 0, 3, 2]) -print(" een_rescaled_e_gl[2, 1, 5, 2] = ",een_rescaled_e_gl[1, 0, 4, 2]) -print(" een_rescaled_e_gl[2, 1, 6, 2] = ",een_rescaled_e_gl[1, 0, 5, 2]) + for j in range(elec_num): + if j != i: + r = elec_dist[i,j] + for p in range(cord_num+1): + f = een_rescaled_e[p,i,j] + for k in range(3): + een_rescaled_e_gl[k,p,i,j] = -kappa_e * p * (elec_coord[j,k] - elec_coord[i,k])/r * f + een_rescaled_e_gl[3,p,i,j] = kappa_e*p*(-2.0/r + kappa_e*p)*f #+end_src - #+begin_src c :tangle (eval c_test) + #+NAME:test_ee_gl + #+begin_src python :results output :exports none :noweb yes +<> +for p in range(cord_num+1): +# for i in range(elec_num): + for i in range(3): + for k in range(4): +# for j in range(elec_num): + for j in range(3): + print(f"printf( \"%e %e\\n\", een_rescaled_e_gl[0][{p}][{i}][{k}][{j}], {een_rescaled_e_gl[k,p,i,j]});") + print(f"assert( fabs(een_rescaled_e_gl[0][{p}][{i}][{k}][{j}] - ({een_rescaled_e_gl[k,p,i,j]})) < 1.e-10 );") + #+end_src + + #+begin_src c :tangle (eval c_test) :noweb yes assert(qmckl_electron_provided(context)); { @@ -7810,13 +7734,7 @@ assert(qmckl_electron_provided(context)); size_max=walk_num*(cord_num + 1)*elec_num*4*elec_num; rc = qmckl_get_jastrow_champ_een_distance_rescaled_e_gl(context, &(een_rescaled_e_gl[0][0][0][0][0]),size_max); - - assert(fabs(een_rescaled_e_gl[0][1][0][0][2] + 0.09831391870751387 ) < 1.e-8); - assert(fabs(een_rescaled_e_gl[0][1][0][0][3] + 0.017204157459682526 ) < 1.e-8); - assert(fabs(een_rescaled_e_gl[0][1][0][0][4] + 0.013345768421098641 ) < 1.e-8); - assert(fabs(een_rescaled_e_gl[0][2][1][0][3] + 0.03733086358273962 ) < 1.e-8); - assert(fabs(een_rescaled_e_gl[0][2][1][0][4] + 0.004922634822943517 ) < 1.e-8); - assert(fabs(een_rescaled_e_gl[0][2][1][0][5] + 0.5416751547830984 ) < 1.e-8); + <> } @@ -7848,19 +7766,27 @@ assert(qmckl_electron_provided(context)); een_rescaled_e_gl_hpc); assert(rc == QMCKL_SUCCESS); - for (int64_t i = 0; i < walk_num*(cord_num + 1)*elec_num*4*elec_num; i++) { - if (fabs(een_rescaled_e_gl_doc[i] - een_rescaled_e_gl_hpc[i]) > 1.e-12) { - printf("i = %ld, doc = %f, hpc = %f\n", i, een_rescaled_e_gl_doc[i], een_rescaled_e_gl_hpc[i]); - fflush(stdout); + for (int nw=0 ; nw < walk_num ; nw++) { + for (int c=0 ; c <= cord_num ; c++) { + for (int i=0 ; i < elec_num ; i++) { + for (int j=0 ; j < elec_num ; j++) { + for (int k=0 ; k < 4 ; k++) { + printf("nw=%d c=%d i=%d k=%d j=%d doc=%e hpc=%e\n", nw, c, i, k, j, een_rescaled_e_gl_doc[nw*(cord_num + 1)*elec_num*4*elec_num + c*elec_num*4*elec_num + i*4*elec_num + k*elec_num + j], een_rescaled_e_gl_hpc[nw*(cord_num + 1)*elec_num*4*elec_num + c*elec_num*4*elec_num + i*4*elec_num + k*elec_num + j]); + if (fabs(een_rescaled_e_gl_doc[nw*(cord_num + 1)*elec_num*4*elec_num + c*elec_num*4*elec_num + i*4*elec_num + k*elec_num + j] - een_rescaled_e_gl_hpc[nw*(cord_num + 1)*elec_num*4*elec_num + c*elec_num*4*elec_num + i*4*elec_num + k*elec_num + j]) > 1.e-12) { + printf("nw=%d c=%d i=%d k=%d j=%d doc=%e hpc=%e\n", nw, c, i, k, j, een_rescaled_e_gl_doc[nw*(cord_num + 1)*elec_num*4*elec_num + c*elec_num*4*elec_num + i*4*elec_num + k*elec_num + j], een_rescaled_e_gl_hpc[nw*(cord_num + 1)*elec_num*4*elec_num + c*elec_num*4*elec_num + i*4*elec_num + k*elec_num + j]); + fflush(stdout); + } + assert(fabs(een_rescaled_e_gl_doc[nw*(cord_num + 1)*elec_num*4*elec_num + c*elec_num*4*elec_num + i*4*elec_num + k*elec_num + j] - een_rescaled_e_gl_hpc[nw*(cord_num + 1)*elec_num*4*elec_num + c*elec_num*4*elec_num + i*4*elec_num + k*elec_num + j]) < 1.e-8); + } + } + } } - assert(fabs(een_rescaled_e_gl_doc[i] - een_rescaled_e_gl_hpc[i]) < 1.e-8); } } { /* Finite difference test fails and I can't understand why... */ -/* printf("een_distance_rescaled_e_gl\n"); @@ -7876,11 +7802,11 @@ assert(qmckl_electron_provided(context)); qmckl_exit_code rc; - double elec_coord[walk_num][3][elec_num]; - rc = qmckl_get_electron_coord (context, 'T', &(elec_coord[0][0][0]), 3*walk_num*elec_num); + double elec_coord[walk_num][elec_num][3]; + rc = qmckl_get_electron_coord (context, 'N', &(elec_coord[0][0][0]), 3*walk_num*elec_num); assert (rc == QMCKL_SUCCESS); - double temp_coord[walk_num][3][elec_num]; + double temp_coord[walk_num][elec_num][3]; memcpy(&(temp_coord[0][0][0]), &(elec_coord[0][0][0]), sizeof(temp_coord)); double function_values[walk_num][cord_num+1][elec_num][elec_num]; @@ -7890,12 +7816,13 @@ assert(qmckl_electron_provided(context)); for (int64_t k = 0; k < 3; k++) { for (int64_t m = -4; m <= 4; m++) { // Apply finite difference displacement + memcpy(&(temp_coord[0][0][0]), &(elec_coord[0][0][0]), sizeof(temp_coord)); for (int64_t nw=0 ; nw> - -elec_coord = np.array(elec_coord)[0] -nucl_coord = np.array(nucl_coord) -elnuc_dist = np.zeros(shape=(elec_num, nucl_num),dtype=float) -for i in range(elec_num): - for a in range(nucl_num): - elnuc_dist[i, a] = np.linalg.norm(elec_coord[i] - nucl_coord[:,a]) - -kappa = 0.6 - -een_rescaled_n = np.zeros(shape=(nucl_num, elec_num, cord_num + 1), dtype=float) -een_rescaled_n[:,:,0] = 1.0 - -for a in range(nucl_num): - for i in range(elec_num): - een_rescaled_n[a, i, 1] = np.exp(-kappa * elnuc_dist[i, a]) - -for l in range(2,cord_num+1): - for a in range(nucl_num): - for i in range(elec_num): - een_rescaled_n[a, i, l] = een_rescaled_n[a, i, l - 1] * een_rescaled_n[a, i, 1] - -elec_dist = np.zeros(shape=(elec_num, elec_num),dtype=float) -for i in range(elec_num): - for j in range(elec_num): - elec_dist[i, j] = np.linalg.norm(elec_coord[i] - elec_coord[j]) - -kappa = 0.6 - -een_rescaled_e_ij = np.zeros(shape=(elec_num * (elec_num - 1)//2, cord_num+1), dtype=float) -een_rescaled_e_ij[:,0] = 1.0 - -k = 0 -for j in range(elec_num): - for i in range(j): - een_rescaled_e_ij[k, 1] = np.exp(-kappa * elec_dist[i, j]) - k = k + 1 - -for l in range(2, cord_num + 1): - for k in range(elec_num * (elec_num - 1)//2): - een_rescaled_e_ij[k, l] = een_rescaled_e_ij[k, l - 1] * een_rescaled_e_ij[k, 1] - -een_rescaled_e = np.zeros(shape=(elec_num, elec_num, cord_num + 1), dtype=float) -een_rescaled_e[:,:,0] = 1.0 - -for l in range(1,cord_num+1): - k = 0 - for j in range(elec_num): - for i in range(j): - x = een_rescaled_e_ij[k, l] - een_rescaled_e[i, j, l] = x - een_rescaled_e[j, i, l] = x - k = k + 1 - -for l in range(0,cord_num+1): - for j in range(0, elec_num): - een_rescaled_e[j,j,l] = 0.0 - lkpm_of_cindex = np.array(lkpm_combined_index).T +<> +<> #+end_src - #+RESULTS: helper_funcs - #+begin_src c :tangle (eval c_test) -assert(qmckl_electron_provided(context)); + #+NAME: test_tmpc + #+begin_src python :results output :exports none :noweb yes +<> +tmp_c = np.einsum("pij,qaj->pqai", een_rescaled_e, een_rescaled_n) +for p in range(cord_num): + for q in range(cord_num+1): + for a in range(nucl_num): +# for i in range(elec_num): + for i in range(3): + print(f"assert( fabs(tmp_c[0][{p}][{q}][{a}][{i}] - ({tmp_c[p,q,a,i]})) < 1.e-10 );") + #+end_src -double tmp_c[walk_num][cord_num][cord_num+1][nucl_num][elec_num]; -rc = qmckl_get_jastrow_champ_tmp_c(context, &(tmp_c[0][0][0][0][0]), sizeof(tmp_c)/sizeof(double)); + #+NAME: test_dtmpc + #+begin_src python :results output :exports none :noweb yes +<> +dtmp_c = np.einsum("lpji,qaj->pqali", een_rescaled_e_gl, een_rescaled_n) +for p in range(cord_num): + for q in range(cord_num+1): + for a in range(nucl_num): + for l in range(4): +# for i in range(elec_num): + for i in range(3): + print(f"printf(\"%e %e\\n\", dtmp_c[0][{p}][{q}][{a}][{l}][{i}], {dtmp_c[p,q,a,l,i]}); fflush(stdout);") + print(f"assert( fabs(dtmp_c[0][{p}][{q}][{a}][{l}][{i}] - ({dtmp_c[p,q,a,l,i]})) < 1.e-10 );") + #+end_src -double dtmp_c[walk_num][cord_num][cord_num+1][nucl_num][4][elec_num]; -rc = qmckl_get_jastrow_champ_dtmp_c(context, &(dtmp_c[0][0][0][0][0][0]), sizeof(dtmp_c)/sizeof(double)); + #+RESULTS: test_dtmpc -printf("%e\n%e\n", tmp_c[0][0][1][0][0], 3.954384); -fflush(stdout); -assert(fabs(tmp_c[0][0][1][0][0] - 3.954384) < 1e-6); + #+begin_src c :tangle (eval c_test) :noweb yes +{ + assert(qmckl_electron_provided(context)); -printf("%e\n%e\n", dtmp_c[0][1][0][0][0][0],3.278657e-01); -fflush(stdout); -assert(fabs(dtmp_c[0][1][0][0][0][0] - 3.278657e-01 ) < 1e-6); + printf("tmp_c\n"); + double tmp_c[walk_num][cord_num][cord_num+1][nucl_num][elec_num]; + rc = qmckl_get_jastrow_champ_tmp_c(context, &(tmp_c[0][0][0][0][0]), sizeof(tmp_c)/sizeof(double)); + + <> +} + +{ + printf("dtmp_c\n"); + double dtmp_c[walk_num][cord_num][cord_num+1][nucl_num][4][elec_num]; + rc = qmckl_get_jastrow_champ_dtmp_c(context, &(dtmp_c[0][0][0][0][0][0]), sizeof(dtmp_c)/sizeof(double)); + + <> +} #+end_src *** Electron-electron-nucleus Jastrow $f_{een}$ @@ -11386,8 +11298,6 @@ import numpy as np <> -<> - <> kappa = 0.6 @@ -12989,7 +12899,7 @@ assert(qmckl_jastrow_champ_provided(context)); } #+end_src - + * End of files :noexport: #+begin_src c :tangle (eval h_private_type)