From 82a285774c4343641391b9f1c1c24ff1cfbe5089 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Tue, 28 Oct 2014 17:16:51 +0100 Subject: [PATCH] Bug in psi_det N_det psi_coef --- ocaml/Input_ao_basis.ml | 2 +- ocaml/Input_cisd_sc2.ml | 11 +++---- ocaml/Input_determinants.ml | 35 ++++++++++++++++---- ocaml/Input_electrons.ml | 12 +++++-- ocaml/Input_full_ci.ml | 11 +++---- ocaml/Input_hartree_fock.ml | 3 +- ocaml/Input_mo_basis.ml | 11 +++++++ ocaml/qp_edit.ml | 65 ++++++++++++++++++++++++++++++------- ocaml/qptypes_generator.ml | 9 +++-- src/Dets/H_apply.irp.f | 2 +- 10 files changed, 123 insertions(+), 38 deletions(-) diff --git a/ocaml/Input_ao_basis.ml b/ocaml/Input_ao_basis.ml index a96993f2..9dc78987 100644 --- a/ocaml/Input_ao_basis.ml +++ b/ocaml/Input_ao_basis.ml @@ -142,7 +142,7 @@ end = struct let to_string b = let short_basis = to_basis b in - Printf.sprintf "Basis name : %s\n\n%s" b.ao_basis + Printf.sprintf "Basis name : %s\n\n%s\n" b.ao_basis (Basis.to_string short_basis) ;; diff --git a/ocaml/Input_cisd_sc2.ml b/ocaml/Input_cisd_sc2.ml index b560aa65..4057edd5 100644 --- a/ocaml/Input_cisd_sc2.ml +++ b/ocaml/Input_cisd_sc2.ml @@ -4,7 +4,7 @@ open Core.Std;; module Cisd_sc2 : sig type t = - { n_det_max_cisd_sc2 : Det_number.t; + { n_det_max_cisd_sc2 : Det_number_max.t; pt2_max : PT2_energy.t; do_pt2_end : bool; } with sexp @@ -13,7 +13,7 @@ module Cisd_sc2 : sig val to_string : t -> string end = struct type t = - { n_det_max_cisd_sc2 : Det_number.t; + { n_det_max_cisd_sc2 : Det_number_max.t; pt2_max : PT2_energy.t; do_pt2_end : bool; } with sexp @@ -28,7 +28,7 @@ end = struct |> Ezfio.set_cisd_sc2_selected_n_det_max_cisd_sc2 ; Ezfio.get_cisd_sc2_selected_n_det_max_cisd_sc2 () - |> Det_number.of_int + |> Det_number_max.of_int ;; @@ -61,12 +61,11 @@ end = struct ;; let to_string b = - Printf.sprintf " -n_det_max_cisd_sc2 = %s + Printf.sprintf "n_det_max_cisd_sc2 = %s pt2_max = %s do_pt2_end = %s " - (Det_number.to_string b.n_det_max_cisd_sc2) + (Det_number_max.to_string b.n_det_max_cisd_sc2) (PT2_energy.to_string b.pt2_max) (Bool.to_string b.do_pt2_end) end diff --git a/ocaml/Input_determinants.ml b/ocaml/Input_determinants.ml index c8f1854c..db27c0ca 100644 --- a/ocaml/Input_determinants.ml +++ b/ocaml/Input_determinants.ml @@ -10,7 +10,7 @@ module Determinants : sig n_det : Det_number.t; n_states : States_number.t; n_states_diag : States_number.t; - n_det_max_jacobi : Det_number.t; + n_det_max_jacobi : Strictly_positive_int.t; threshold_generators : Threshold.t; threshold_selectors : Threshold.t; read_wf : bool; @@ -30,7 +30,7 @@ end = struct n_det : Det_number.t; n_states : States_number.t; n_states_diag : States_number.t; - n_det_max_jacobi : Det_number.t; + n_det_max_jacobi : Strictly_positive_int.t; threshold_generators : Threshold.t; threshold_selectors : Threshold.t; read_wf : bool; @@ -106,7 +106,7 @@ end = struct |> Ezfio.set_determinants_n_det_max_jacobi ; Ezfio.get_determinants_n_det_max_jacobi () - |> Det_number.of_int + |> Strictly_positive_int.of_int ;; let read_threshold_generators () = @@ -234,6 +234,30 @@ end = struct ;; let to_string b = + Printf.sprintf "read_wf = %s +n_det = %s +n_states = %s +threshold_generators = %s +threshold_selectors = %s +n_det_max_jacobi = %s +n_states_diag = %s +s2_eig = %s +expected_s2 = %s +mo_label = \"%s\" +" + (b.read_wf |> Bool.to_string) + (b.n_det |> Det_number.to_string) + (b.n_states |> States_number.to_string) + (b.threshold_generators |> Threshold.to_string) + (b.threshold_selectors |> Threshold.to_string) + (b.n_det_max_jacobi |> Strictly_positive_int.to_string) + (b.n_states_diag |> States_number.to_string) + (b.s2_eig |> Bool.to_string) + (b.expected_s2 |> Positive_float.to_string) + (b.mo_label |> Non_empty_string.to_string) + ;; + + let debug b = Printf.sprintf " n_int = %s bit_kind = %s @@ -256,7 +280,7 @@ psi_det = %s (b.n_det |> Det_number.to_string) (b.n_states |> States_number.to_string) (b.n_states_diag |> States_number.to_string) - (b.n_det_max_jacobi |> Det_number.to_string) + (b.n_det_max_jacobi |> Strictly_positive_int.to_string) (b.threshold_generators |> Threshold.to_string) (b.threshold_selectors |> Threshold.to_string) (b.read_wf |> Bool.to_string) @@ -269,8 +293,7 @@ psi_det = %s Int64.to_string x )|> Array.to_list |> String.concat ~sep:", ") |> Array.to_list |> String.concat ~sep:" | ") - ; -;; + ;; end diff --git a/ocaml/Input_electrons.ml b/ocaml/Input_electrons.ml index 8de68dbf..2d52f7a4 100644 --- a/ocaml/Input_electrons.ml +++ b/ocaml/Input_electrons.ml @@ -47,14 +47,22 @@ end = struct ;; let to_string b = - Printf.sprintf " -elec_alpha_num = %s + Printf.sprintf "elec_alpha_num = %s +elec_beta_num = %s +" + (Elec_alpha_number.to_string b.elec_alpha_num) + (Elec_beta_number.to_string b.elec_beta_num) + ;; + + let debug b = + Printf.sprintf "elec_alpha_num = %s elec_beta_num = %s elec_num = %s " (Elec_alpha_number.to_string b.elec_alpha_num) (Elec_beta_number.to_string b.elec_beta_num) (Elec_number.to_string b.elec_num) + ;; end diff --git a/ocaml/Input_full_ci.ml b/ocaml/Input_full_ci.ml index 16de2a20..5a552b14 100644 --- a/ocaml/Input_full_ci.ml +++ b/ocaml/Input_full_ci.ml @@ -4,7 +4,7 @@ open Core.Std;; module Full_ci : sig type t = - { n_det_max_fci : Det_number.t; + { n_det_max_fci : Det_number_max.t; pt2_max : PT2_energy.t; do_pt2_end : bool; } with sexp @@ -13,7 +13,7 @@ module Full_ci : sig val to_string : t -> string end = struct type t = - { n_det_max_fci : Det_number.t; + { n_det_max_fci : Det_number_max.t; pt2_max : PT2_energy.t; do_pt2_end : bool; } with sexp @@ -28,7 +28,7 @@ end = struct |> Ezfio.set_full_ci_n_det_max_fci ; Ezfio.get_full_ci_n_det_max_fci () - |> Det_number.of_int + |> Det_number_max.of_int ;; let read_pt2_max () = @@ -59,12 +59,11 @@ end = struct ;; let to_string b = - Printf.sprintf " -n_det_max_fci = %s + Printf.sprintf "n_det_max_fci = %s pt2_max = %s do_pt2_end = %s " - (Det_number.to_string b.n_det_max_fci) + (Det_number_max.to_string b.n_det_max_fci) (PT2_energy.to_string b.pt2_max) (Bool.to_string b.do_pt2_end) end diff --git a/ocaml/Input_hartree_fock.ml b/ocaml/Input_hartree_fock.ml index 6f2f12b2..206395f1 100644 --- a/ocaml/Input_hartree_fock.ml +++ b/ocaml/Input_hartree_fock.ml @@ -46,8 +46,7 @@ end = struct ;; let to_string b = - Printf.sprintf " -n_it_scf_max = %s + Printf.sprintf "n_it_scf_max = %s thresh_scf = %s " (Strictly_positive_int.to_string b.n_it_scf_max) diff --git a/ocaml/Input_mo_basis.ml b/ocaml/Input_mo_basis.ml index f2ad0888..c4e81fb8 100644 --- a/ocaml/Input_mo_basis.ml +++ b/ocaml/Input_mo_basis.ml @@ -72,6 +72,16 @@ end = struct let to_string b = Printf.sprintf " mo_label = %s +mo_tot_num = %s +" + (Non_empty_string.to_string b.mo_label) + (MO_number.to_string b.mo_tot_num) + + ;; + + let debug b = + Printf.sprintf " +mo_label = %s mo_tot_num = \"%s\" mo_occ = %s mo_coef = %s @@ -82,6 +92,7 @@ mo_coef = %s ~f:(Positive_float.to_string) |> String.concat ~sep:", " ) (b.mo_coef |> Array.to_list |> List.map ~f:(MO_coef.to_string) |> String.concat ~sep:", " ) + ;; end diff --git a/ocaml/qp_edit.ml b/ocaml/qp_edit.ml index 6bbc9573..60a31e88 100644 --- a/ocaml/qp_edit.ml +++ b/ocaml/qp_edit.ml @@ -15,11 +15,23 @@ let instructions filename = Printf.sprintf type keyword = | Ao_basis | Bielec_integrals +| Cisd_sc2 +| Determinants +| Electrons +| Full_ci +| Hartree_fock +| Mo_basis ;; let keyword_to_string = function -| Ao_basis -> "AO basis" +| Ao_basis -> "AO basis" | Bielec_integrals -> "Two electron integrals" +| Cisd_sc2 -> "CISD (SC)^2" +| Determinants -> "Determinants" +| Electrons -> "Electrons" +| Full_ci -> "Selected Full-CI" +| Hartree_fock -> "Hartree-Fock" +| Mo_basis -> "MO basis" ;; let make_header kw = @@ -28,15 +40,37 @@ let make_header kw = "\n\n# "^s^"\n"^"# "^(String.init l ~f:(fun _ -> '='))^"\n\n" ;; -let get_bielec () = - (make_header Bielec_integrals)^ - (Input.Bielec_integrals.(to_string (read ()))) +let get s = + let header = (make_header s) + in header^(match s with + | Bielec_integrals -> + Input.Bielec_integrals.(to_string (read ())) + | Ao_basis -> + Input.Ao_basis.(to_string (read ())) + | Cisd_sc2 -> + Input.Cisd_sc2.(to_string (read ())) + | Determinants -> + Input.Determinants.(to_string (read ())) + | Electrons -> + Input.Electrons.(to_string (read ())) + | Full_ci -> + Input.Full_ci.(to_string (read ())) + | Hartree_fock -> + Input.Hartree_fock.(to_string (read ())) + | Mo_basis -> + Input.Mo_basis.(to_string (read ())) + ) ;; -let get_ao_basis () = - (make_header Ao_basis)^ - (Input.Ao_basis.(to_string (read ()))) +(* +let create_temp_file ezfio_filename fields = + In_channel.with_file filename ~f:(func out_channel -> + (instructions ezfio_filename) :: (List.map ~f:get fields) + |> String.concat output + |> print_string + ) ;; +*) let run ezfio_filename = @@ -46,11 +80,18 @@ let run ezfio_filename = Ezfio.set_file ezfio_filename; - let output = [ - (instructions ezfio_filename) ; - (get_ao_basis ()) ; - (get_bielec ()) - ] in + let output = (instructions ezfio_filename) :: ( + List.map ~f:get [ + Electrons ; + Ao_basis ; + Mo_basis ; + Bielec_integrals ; + Cisd_sc2 ; + Determinants ; + Full_ci ; + Hartree_fock ; + ]) + in String.concat output |> print_string ;; diff --git a/ocaml/qptypes_generator.ml b/ocaml/qptypes_generator.ml index 68455d97..220419ea 100644 --- a/ocaml/qptypes_generator.ml +++ b/ocaml/qptypes_generator.ml @@ -68,8 +68,13 @@ let input_data = " assert (x > 0) ; if (x > 100000000) then warning \"More than 100 million determinants\"; - if (Ezfio.has_determinants_det_num ()) then - assert (x <= (Ezfio.get_determinants_det_num ())); + if (Ezfio.has_determinants_n_det ()) then + assert (x <= (Ezfio.get_determinants_n_det ())); + +* Det_number_max : int + assert (x > 0) ; + if (x > 100000000) then + warning \"More than 100 million determinants\"; * States_number : int assert (x > 0) ; diff --git a/src/Dets/H_apply.irp.f b/src/Dets/H_apply.irp.f index 18dd0201..801d00a5 100644 --- a/src/Dets/H_apply.irp.f +++ b/src/Dets/H_apply.irp.f @@ -136,7 +136,6 @@ subroutine copy_H_apply_buffer_to_wf do j=0,nproc-1 N_det = N_det + H_apply_buffer(j)%N_det enddo - SOFT_TOUCH N_det if (psi_det_size < N_det) then psi_det_size = N_det @@ -180,6 +179,7 @@ subroutine copy_H_apply_buffer_to_wf H_apply_buffer(j)%N_det = 0 !$OMP END PARALLEL call normalize(psi_coef,N_det) + SOFT_TOUCH N_det psi_det psi_coef end