10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-07-11 22:03:47 +02:00

Merge pull request #153 from scemama/master

Fixed #152 and corrected qp_edit bug
This commit is contained in:
Thomas Applencourt 2016-03-04 13:57:19 +01:00
commit 7c0c3e0391
4 changed files with 148 additions and 182 deletions

View File

@ -16,6 +16,7 @@ module Determinants_by_hand : sig
val to_string : t -> string val to_string : t -> string
val to_rst : t -> Rst_string.t val to_rst : t -> Rst_string.t
val of_rst : Rst_string.t -> t option val of_rst : Rst_string.t -> t option
val read_n_int : unit -> N_int_number.t
end = struct end = struct
type t = type t =
{ n_int : N_int_number.t; { n_int : N_int_number.t;
@ -157,58 +158,44 @@ end = struct
let read_psi_det () = let read_psi_det () =
let n_int = let n_int = read_n_int ()
read_n_int () and n_alpha = Ezfio.get_electrons_elec_alpha_num ()
and alpha =
Ezfio.get_electrons_elec_alpha_num ()
|> Elec_alpha_number.of_int |> Elec_alpha_number.of_int
and beta = and n_beta = Ezfio.get_electrons_elec_beta_num ()
Ezfio.get_electrons_elec_beta_num ()
|> Elec_beta_number.of_int |> Elec_beta_number.of_int
in in
if not (Ezfio.has_determinants_psi_det ()) then if not (Ezfio.has_determinants_psi_det ()) then
begin begin
let mo_tot_num = let mo_tot_num = MO_number.get_max () in
MO_number.get_max ()
in
let rec build_data accu = function let rec build_data accu = function
| 0 -> accu | 0 -> accu
| n -> build_data ((MO_number.of_int ~max:mo_tot_num n)::accu) (n-1) | n -> build_data ((MO_number.of_int ~max:mo_tot_num n)::accu) (n-1)
in in
let det_a = let det_a = build_data [] (Elec_alpha_number.to_int n_alpha)
build_data [] (Elec_alpha_number.to_int alpha)
|> Bitlist.of_mo_number_list n_int |> Bitlist.of_mo_number_list n_int
and det_b = and det_b = build_data [] (Elec_beta_number.to_int n_beta)
build_data [] (Elec_beta_number.to_int beta)
|> Bitlist.of_mo_number_list n_int |> Bitlist.of_mo_number_list n_int
in in
let data = let data = ( (Bitlist.to_int64_list det_a) @
( (Bitlist.to_int64_list det_a) @
(Bitlist.to_int64_list det_b) ) (Bitlist.to_int64_list det_b) )
in in
Ezfio.ezfio_array_of_list ~rank:3 ~dim:[| N_int_number.to_int n_int ; 2 ; 1 |] ~data:data Ezfio.ezfio_array_of_list ~rank:3 ~dim:[| N_int_number.to_int n_int ; 2 ; 1 |] ~data:data
|> Ezfio.set_determinants_psi_det ; |> Ezfio.set_determinants_psi_det ;
end ; end ;
let n_int_i = let n_int = N_int_number.to_int n_int in
N_int_number.to_int n_int in let psi_det_array = Ezfio.get_determinants_psi_det () in
let psi_det_array = let dim = psi_det_array.Ezfio.dim
Ezfio.get_determinants_psi_det () and data = Ezfio.flattened_ezfio psi_det_array
in in
let dim = assert (n_int = dim.(0));
psi_det_array.Ezfio.dim
and data =
Ezfio.flattened_ezfio psi_det_array
in
assert (n_int_i = dim.(0));
assert (dim.(1) = 2); assert (dim.(1) = 2);
assert (dim.(2) = (Det_number.to_int (read_n_det ()))); assert (dim.(2) = (Det_number.to_int (read_n_det ())));
let len = List.init dim.(2) ~f:(fun i ->
2 * n_int_i Array.sub ~pos:(2*n_int*i) ~len:(2*n_int) data)
in |> List.map ~f:(Determinant.of_int64_array
Array.init dim.(2) ~f:(fun i -> ~n_int:(N_int_number.of_int n_int)
Array.sub ~pos:(len * i) ~len data ~alpha:n_alpha ~beta:n_beta )
|> Determinant.of_int64_array ~n_int ~alpha ~beta |> Array.of_list
)
;; ;;
let write_psi_det ~n_int ~n_det d = let write_psi_det ~n_int ~n_det d =
@ -286,9 +273,13 @@ end = struct
|> String.concat_array ~sep:"\t" |> String.concat_array ~sep:"\t"
in in
Array.init ndet ~f:(fun i -> Array.init ndet ~f:(fun i ->
String.concat [ " " ; Printf.sprintf " %s\n%s\n"
(coefs_string i) ; "\n" ; (coefs_string i)
(Determinant.to_string ~mo_tot_num b.psi_det.(i)) ; "\n" ] (Determinant.to_string ~mo_tot_num:mo_tot_num b.psi_det.(i)
|> String.split ~on:'\n'
|> List.map ~f:(fun x -> " "^x)
|> String.concat ~sep:"\n"
)
) )
|> String.concat_array ~sep:"\n" |> String.concat_array ~sep:"\n"
in in
@ -334,18 +325,18 @@ psi_det = %s
;; ;;
let of_rst r = let of_rst r =
let dets = Rst_string.to_string r let r = Rst_string.to_string r
in in
(* Split into header and determinants data *) (* Split into header and determinants data *)
let idx = String.substr_index_exn dets ~pos:0 ~pattern:"\nDeterminants" let idx = String.substr_index_exn r ~pos:0 ~pattern:"\nDeterminants"
in in
let header = let (header, dets) =
String.prefix dets idx (String.prefix r idx, String.suffix r ((String.length r)-idx) )
in in
(* Handle header *) (* Handle header *)
let header = header let header = r
|> String.split ~on:'\n' |> String.split ~on:'\n'
|> List.filter ~f:(fun line -> |> List.filter ~f:(fun line ->
if (line = "") then if (line = "") then
@ -361,117 +352,91 @@ psi_det = %s
|> String.concat |> String.concat
in in
(* Handle determinants and coefs *) (* Handle determinant coefs *)
let dets_stream = let dets = match ( dets
|> String.split ~on:'\n'
|> List.map ~f:(String.strip)
) with
| _::lines -> lines
| _ -> failwith "Error in determinants"
in
let ipos, jmax = let psi_coef =
ref idx, String.length dets let rec read_coefs accu = function
in | [] -> List.rev accu
let next_line = | ""::""::tail -> read_coefs accu tail
Stream.from (fun _ -> | ""::c::tail ->
let rec loop line = let c =
let j = String.split ~on:'\t' c
!ipos + 1 |> List.map ~f:(fun x -> Det_coef.of_float (Float.of_string x))
in
ipos := j;
if (j < jmax) then
match dets.[j] with
| '\n' -> Some (String.of_char_list @@ List.rev line )
| ' ' -> loop line
| c -> loop (c :: line)
else
None
in loop []
)
in
ignore @@ Stream.next next_line; (* Determinants :: *)
ignore @@ Stream.next next_line; (* *)
Stream.from (fun _ ->
try
begin
let result =
let coefs =
let line =
Stream.next next_line
in
String.split ~on:'\t' line
|> Array.of_list |> Array.of_list
|> Array.map ~f:(fun x -> Det_coef.of_float @@ Float.of_string x)
in in
Some (coefs, read_coefs (c::accu) tail
Stream.next next_line |> String.rev, | _::tail -> read_coefs accu tail
Stream.next next_line |> String.rev )
in
ignore @@ Stream.next next_line;
result
end
with
| Stream.Failure -> None
)
in
let psi_coef, psi_det =
let alpha =
Ezfio.get_electrons_elec_alpha_num ()
|> Elec_alpha_number.of_int
and beta =
Ezfio.get_electrons_elec_beta_num ()
|> Elec_beta_number.of_int
and n_int =
N_int_number.get_max ()
|> N_int_number.of_int
in
let rec read coefs dets_bit = function
| None -> (List.rev coefs), (List.rev dets_bit)
| Some (c, alpha_str, beta_str) ->
begin
ignore @@ Stream.next dets_stream;
let new_coefs =
c :: coefs
and new_dets =
let newdet =
(Bitlist.of_string_mp alpha_str, Bitlist.of_string_mp beta_str)
|> Determinant.of_bitlist_couple ~n_int ~alpha ~beta
in
newdet :: dets_bit
in
read new_coefs new_dets (Stream.peek dets_stream)
end
in
let coefs, dets_bit =
read [] [] (Stream.peek dets_stream)
in
let nstates =
List.hd_exn coefs |> Array.length
in in
let a = let a =
let buffer =
read_coefs [] dets
in
let nstates =
List.hd_exn buffer
|> Array.length
in
let extract_state i = let extract_state i =
let i = let i =
i-1 i-1
in in
List.map ~f:(fun x -> x.(i)) coefs List.map ~f:(fun x -> Det_coef.to_string x.(i)) buffer
|> String.concat ~sep:" "
in in
let rec build_result accu = function let rec build_result = function
| 0 -> accu | 1 -> extract_state 1
| i -> | i -> (build_result (i-1))^" "^(extract_state i)
let new_accu =
(extract_state i) :: accu
in in
build_result new_accu (i-1) build_result nstates
in in
build_result [] nstates "(psi_coef ("^a^"))"
in in
let new_coefs =
List.concat a |> Array.of_list (* Handle determinants *)
and new_dets = let psi_det =
Array.of_list dets_bit let n_alpha = Ezfio.get_electrons_elec_alpha_num ()
|> Elec_alpha_number.of_int
and n_beta = Ezfio.get_electrons_elec_beta_num ()
|> Elec_beta_number.of_int
in in
new_coefs, new_dets let rec read_dets accu = function
| [] -> List.rev accu
| ""::_::alpha::beta::tail ->
begin
let newdet =
(Bitlist.of_string ~zero:'-' ~one:'+' alpha ,
Bitlist.of_string ~zero:'-' ~one:'+' beta)
|> Determinant.of_bitlist_couple ~alpha:n_alpha ~beta:n_beta
|> Determinant.sexp_of_t
|> Sexplib.Sexp.to_string
in
read_dets (newdet::accu) tail
end
| _::tail -> read_dets accu tail
in
let dets =
List.map ~f:String.rev dets
in
let sze =
List.fold ~init:0 ~f:(fun accu x -> accu + (String.length x)) dets
in
let control =
Gc.get ()
in
Gc.tune ~minor_heap_size:(sze) ~space_overhead:(sze/10)
~max_overhead:100000 ~major_heap_increment:(sze/10) ();
let a =
read_dets [] dets
|> String.concat
in
Gc.set control;
"(psi_det ("^a^"))"
in in
@ -482,15 +447,10 @@ psi_det = %s
Printf.sprintf "(n_int %d)" (N_int_number.get_max ()) Printf.sprintf "(n_int %d)" (N_int_number.get_max ())
in in
let s = let s =
[ header ; bitkind ; n_int ; "(psi_coef ())" ; "(psi_det ())"] String.concat [ header ; bitkind ; n_int ; psi_coef ; psi_det]
|> String.concat
in in
let result =
Generic_input_of_rst.evaluate_sexp t_of_sexp s Generic_input_of_rst.evaluate_sexp t_of_sexp s
in
match result with
| Some x -> Some { x with psi_coef ; psi_det }
| None -> None
;; ;;
end end

View File

@ -32,14 +32,19 @@ let zmq_context =
let bind_socket ~socket_type ~socket ~address = let bind_socket ~socket_type ~socket ~address =
let rec loop = function
| 0 -> failwith @@ Printf.sprintf
"Unable to bind the %s socket : %s "
socket_type address
| -1 -> ();
| i ->
try try
ZMQ.Socket.bind socket address ZMQ.Socket.bind socket address;
loop (-1)
with with
| Unix.Unix_error (_, message, f) -> | Unix.Unix_error _ -> (Time.pause @@ Time.Span.of_float 1. ; loop (i-1) )
failwith @@ Printf.sprintf
"\n%s\nUnable to bind the %s socket :\n %s\n%s"
f socket_type address message
| other_exception -> raise other_exception | other_exception -> raise other_exception
in loop 10
let hostname = lazy ( let hostname = lazy (

View File

@ -32,12 +32,12 @@ let run ~master exe ezfio_file =
let address = let address =
Printf.sprintf "tcp://%s:%d" (Lazy.force TaskServer.ip_address) (port_number+i) Printf.sprintf "tcp://%s:%d" (Lazy.force TaskServer.ip_address) (port_number+i)
in in
TaskServer.bind_socket "REP" dummy_socket address ; ZMQ.Socket.bind dummy_socket address;
ZMQ.Socket.unbind dummy_socket address; ZMQ.Socket.unbind dummy_socket address;
); );
port_number port_number
with with
| Failure _ -> try_new_port (port_number+100) | Unix.Unix_error _ -> try_new_port (port_number+100)
in in
let result = let result =
try_new_port 41279 try_new_port 41279

View File

@ -59,7 +59,8 @@ def save_new_module(path, l_child):
with open(os.path.join(path, "%s.main.irp.f"%(module_name) ), "w") as f: with open(os.path.join(path, "%s.main.irp.f"%(module_name) ), "w") as f:
f.write("program {0}".format(module_name) ) f.write("program {0}".format(module_name) )
f.write(""" implicit none f.write("""
implicit none
BEGIN_DOC BEGIN_DOC
! TODO ! TODO
END_DOC END_DOC