10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-06-02 03:15:19 +02:00

F12 matrix built as a stream

This commit is contained in:
Anthony Scemama 2019-03-25 16:50:36 +01:00
parent e63bec19d1
commit 99f5fe0aef
2 changed files with 44 additions and 51 deletions

View File

@ -147,11 +147,13 @@ let store_class basis ?(cutoff=integrals_cutoff) data contracted_shell_pair_coup
and shell_q = Cspc.shell_pair_q contracted_shell_pair_couple and shell_q = Cspc.shell_pair_q contracted_shell_pair_couple
in in
(*
let s = let s =
Overlap.of_basis basis Overlap.of_basis basis
|> Overlap.matrix |> Overlap.matrix
in in
let lambda_inv = 1. /. expo_s in let lambda_inv = 1. /. expo_s in
*)
Array.iteri (fun i_c powers_i -> Array.iteri (fun i_c powers_i ->
let i_c = Cs.index (Csp.shell_a shell_p) + i_c + 1 in let i_c = Cs.index (Csp.shell_a shell_p) + i_c + 1 in
let xi = to_powers powers_i in let xi = to_powers powers_i in
@ -166,7 +168,10 @@ let store_class basis ?(cutoff=integrals_cutoff) data contracted_shell_pair_coup
let xl = to_powers powers_l in let xl = to_powers powers_l in
let key = Zkey.of_powers_twelve xi xj xk xl in let key = Zkey.of_powers_twelve xi xj xk xl in
let value = Zmap.find cls key in let value = Zmap.find cls key in
(*
lambda_inv *. (s.{i_c,j_c} *. s.{k_c,l_c} -. value) lambda_inv *. (s.{i_c,j_c} *. s.{k_c,l_c} -. value)
*)
value
|> set_chem data i_c j_c k_c l_c |> set_chem data i_c j_c k_c l_c
) (Cs.zkey_array (Csp.shell_b shell_q)) ) (Cs.zkey_array (Csp.shell_b shell_q))
) (Cs.zkey_array (Csp.shell_a shell_q)) ) (Cs.zkey_array (Csp.shell_a shell_q))
@ -359,15 +364,20 @@ let of_basis_parallel basis =
Fis.create ~size:0 `Dense Fis.create ~size:0 `Dense
in in
(*
let s = let s =
Overlap.of_basis basis Overlap.of_basis basis
|> Overlap.matrix |> Overlap.matrix
in in
let lambda_inv = 1. /. expo_s in let lambda_inv = 1. /. expo_s in
*)
Farm.run ~ordered:false ~f input_stream Farm.run ~ordered:false ~f input_stream
|> Stream.iter (fun l -> |> Stream.iter (fun l ->
Array.iter (fun (i_c,j_c,k_c,l_c,value) -> Array.iter (fun (i_c,j_c,k_c,l_c,value) ->
(*
lambda_inv *. (s.{i_c,j_c} *. s.{k_c,l_c} -. value) lambda_inv *. (s.{i_c,j_c} *. s.{k_c,l_c} -. value)
*)
value
|> set_chem eri_array i_c j_c k_c l_c) l); |> set_chem eri_array i_c j_c k_c l_c) l);
if Parallel.master then if Parallel.master then

View File

@ -112,65 +112,47 @@ let dressing_vector gamma ~frozen_core aux_basis f12_amplitudes ci =
*) *)
let out_dets =
DeterminantSpace.fci_of_mo_basis ~frozen_core aux_basis
|> DeterminantSpace.determinants_array
|> Array.to_list
|> List.filter (fun i -> not (is_internal ci.CI.det_space i))
in
let in_dets =
DeterminantSpace.determinants_array ci.CI.det_space
|> Array.to_list
in
Printf.printf "Building matrix\n%!"; Printf.printf "Building matrix\n%!";
let m_H_aux, m_F_aux = let m_H_aux, m_F_aux =
let rec col_vecs_list accu_H accu_F = function let out_dets_stream =
| [] -> DeterminantSpace.fci_of_mo_basis ~frozen_core aux_basis
List.rev_map Vec.of_list accu_H, |> DeterminantSpace.determinant_stream
List.rev_map Vec.of_list accu_F in
| ki :: rest ->
let h, f = let in_dets =
List.map (fun kj -> DeterminantSpace.determinants_array ci.CI.det_space
match hf_ij aux_basis ki kj with |> Array.to_list
| [ a ; b ] -> a, b in
| _ -> assert false ) in_dets
|> List.split let rec col_vecs_list accu_H accu_F =
in try
col_vecs_list (h::accu_H) (f::accu_F) rest let ki = Stream.next out_dets_stream in
if is_internal ci.CI.det_space ki then
raise Exit
else
let h, f =
List.map (fun kj ->
match hf_ij aux_basis ki kj with
| [ a ; b ] -> a, b
| _ -> assert false ) in_dets
|> List.split
in
col_vecs_list (h::accu_H) (f::accu_F)
with
| Exit -> col_vecs_list accu_H accu_F
| Stream.Failure ->
List.rev_map Vec.of_list accu_H,
List.rev_map Vec.of_list accu_F
in in
let h, f = let h, f =
col_vecs_list [] [] out_dets col_vecs_list [] []
in in
Mat.of_col_vecs_list h, Mat.of_col_vecs_list h,
Mat.of_col_vecs_list f Mat.of_col_vecs_list f
in in
(*
let m_H_aux =
List.map (fun ki ->
List.map (fun kj ->
h_ij aux_basis ki kj
) out_dets
|> Array.of_list
) in_dets
|> Array.of_list
|> Mat.of_array
in
let m_F_aux =
List.map (fun ki ->
List.map (fun kj ->
f_ij aux_basis ki kj
) out_dets
|> Array.of_list
) in_dets
|> Array.of_list
|> Mat.of_array
in
*)
Printf.printf "Matrix product\n%!"; Printf.printf "Matrix product\n%!";
let m_HF = let m_HF =
@ -189,7 +171,7 @@ let dressing_vector gamma ~frozen_core aux_basis f12_amplitudes ci =
let make ~simulation ?(threshold=1.e-12) ~frozen_core ~mo_basis ~aux_basis_filename () = let make ~simulation ?(threshold=1.e-12) ~frozen_core ~mo_basis ~aux_basis_filename () =
let gamma = 0.5 in let gamma = -0.5 /. F12.expo_s in
let mo_num = MOBasis.size mo_basis in let mo_num = MOBasis.size mo_basis in
@ -316,7 +298,8 @@ TODO SINGLE STATE HERE
(Mat.to_col_vecs eigenvectors).(0) ) (Mat.to_col_vecs eigenvectors).(0) )
in in
if Parallel.master then if Parallel.master then
Printf.printf "F12 Convergence : %e %f\n" conv (eigenvalues.{1} +. e_shift); Printf.printf "F12 Convergence : %e %f\n" conv (eigenvalues.{1} +. e_shift
+. Simulation.nuclear_repulsion simulation);
if conv > threshold then if conv > threshold then
iteration eigenvectors iteration eigenvectors