mirror of
https://github.com/LCPQ/quantum_package
synced 2025-05-06 07:05:25 +02:00
Bitmasks OK
This commit is contained in:
parent
5deb211473
commit
a4688e7500
2
ocaml/.gitignore
vendored
2
ocaml/.gitignore
vendored
@ -1,5 +1,5 @@
|
|||||||
ezfio.ml
|
ezfio.ml
|
||||||
qptypes.ml
|
Qptypes.ml
|
||||||
*.byte
|
*.byte
|
||||||
*.native
|
*.native
|
||||||
_build
|
_build
|
||||||
|
@ -62,6 +62,12 @@ let of_int64_list l =
|
|||||||
List.flatten result
|
List.flatten result
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
let zero n_int =
|
||||||
|
let n_int = N_int_number.to_int n_int in
|
||||||
|
let a = Array.init n_int (fun i-> 0L) in
|
||||||
|
of_int64_list ( Array.to_list a )
|
||||||
|
;;
|
||||||
|
|
||||||
(* Create an int64 list from a bit list *)
|
(* Create an int64 list from a bit list *)
|
||||||
let to_int64_list l =
|
let to_int64_list l =
|
||||||
let rec do_work accu buf counter = function
|
let rec do_work accu buf counter = function
|
||||||
|
@ -36,7 +36,7 @@ let create_active range = Active (_mo_number_list_of_range range) ;;
|
|||||||
let create_virtual range = Virtual (_mo_number_list_of_range range) ;;
|
let create_virtual range = Virtual (_mo_number_list_of_range range) ;;
|
||||||
let create_deleted range = Deleted (_mo_number_list_of_range range) ;;
|
let create_deleted range = Deleted (_mo_number_list_of_range range) ;;
|
||||||
|
|
||||||
let to_bitlist x =
|
let to_bitlist n_int x =
|
||||||
match x with
|
match x with
|
||||||
| Core l
|
| Core l
|
||||||
| Inactive l
|
| Inactive l
|
||||||
|
@ -19,8 +19,9 @@ MLIFILES=$(wildcard *.mli)
|
|||||||
ALL_TESTS=$(patsubst %.ml,%.byte,$(wildcard test_*.ml))
|
ALL_TESTS=$(patsubst %.ml,%.byte,$(wildcard test_*.ml))
|
||||||
ALL_EXE=$(patsubst %.ml,%.native,$(wildcard qp_*.ml))
|
ALL_EXE=$(patsubst %.ml,%.native,$(wildcard qp_*.ml))
|
||||||
|
|
||||||
|
.PHONY: executables default
|
||||||
|
|
||||||
default: $(ALL_TESTS) executables
|
default: $(ALL_TESTS) $(ALL_EXE)
|
||||||
|
|
||||||
executables: $(ALL_EXE)
|
executables: $(ALL_EXE)
|
||||||
|
|
||||||
@ -39,7 +40,7 @@ ezfio.ml: ${QPACKAGE_ROOT}/EZFIO/Ocaml/ezfio.ml
|
|||||||
qptypes_generator.byte: qptypes_generator.ml
|
qptypes_generator.byte: qptypes_generator.ml
|
||||||
$(OCAMLBUILD) qptypes_generator.byte -use-ocamlfind
|
$(OCAMLBUILD) qptypes_generator.byte -use-ocamlfind
|
||||||
|
|
||||||
qptypes.ml: qptypes_generator.byte
|
Qptypes.ml: qptypes_generator.byte
|
||||||
./qptypes_generator.byte > Qptypes.ml
|
./qptypes_generator.byte > Qptypes.ml
|
||||||
rm qptypes_generator.byte
|
rm qptypes_generator.byte
|
||||||
|
|
||||||
|
@ -30,30 +30,6 @@ let build_mask from upto n_int =
|
|||||||
|> List.rev
|
|> List.rev
|
||||||
;;
|
;;
|
||||||
|
|
||||||
let apply_mask mask n_int mo_tot_num =
|
|
||||||
let full_mask = build_mask (MO_number.of_int 1) (MO_number.of_int mo_tot_num) n_int in
|
|
||||||
let occ_mask = build_mask (MO_number.of_int 1) (MO_number.of_int mo_tot_num) n_int in
|
|
||||||
let virt_mask = Bitlist.not_operator occ_mask
|
|
||||||
in
|
|
||||||
let newmask = Bitlist.and_operator occ_mask mask
|
|
||||||
in
|
|
||||||
newmask |> Bitlist.to_string |> print_string;
|
|
||||||
Ezfio.set_bitmasks_n_int (N_int_number.to_int n_int);
|
|
||||||
Ezfio.set_bitmasks_bit_kind 8;
|
|
||||||
Ezfio.set_bitmasks_n_mask_gen 1;
|
|
||||||
let d = newmask
|
|
||||||
|> Bitlist.to_int64_list
|
|
||||||
in
|
|
||||||
let rec append_d = function
|
|
||||||
| 1 -> List.rev d
|
|
||||||
| n -> d@(append_d (n-1))
|
|
||||||
in
|
|
||||||
let d = append_d 12 in
|
|
||||||
Ezfio.ezfio_array_of_list ~rank:4 ~dim:([| (N_int_number.to_int n_int) ; 2; 6; 1|]) ~data:d
|
|
||||||
|> Ezfio.set_bitmasks_generators ;
|
|
||||||
;;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let failure s = raise (Failure s)
|
let failure s = raise (Failure s)
|
||||||
;;
|
;;
|
||||||
@ -88,6 +64,7 @@ let run ?(core="[]") ?(inact="[]") ?(act="[]") ?(virt="[]") ?(del="[]") ezfio_fi
|
|||||||
|
|
||||||
let mo_class = Array.init mo_tot_num ~f:(fun i -> None) in
|
let mo_class = Array.init mo_tot_num ~f:(fun i -> None) in
|
||||||
|
|
||||||
|
(* Check input data *)
|
||||||
let apply_class l =
|
let apply_class l =
|
||||||
let rec apply_class t = function
|
let rec apply_class t = function
|
||||||
| [] -> ()
|
| [] -> ()
|
||||||
@ -109,11 +86,17 @@ let run ?(core="[]") ?(inact="[]") ?(act="[]") ?(virt="[]") ?(del="[]") ezfio_fi
|
|||||||
| MO_class.Deleted x -> apply_class Deleted x
|
| MO_class.Deleted x -> apply_class Deleted x
|
||||||
in
|
in
|
||||||
|
|
||||||
MO_class.create_core core |> apply_class ;
|
let core = MO_class.create_core core in
|
||||||
MO_class.create_inactive inact |> apply_class ;
|
let inact = MO_class.create_inactive inact in
|
||||||
MO_class.create_active act |> apply_class ;
|
let act = MO_class.create_active act in
|
||||||
MO_class.create_virtual virt |> apply_class ;
|
let virt = MO_class.create_virtual virt in
|
||||||
MO_class.create_deleted del |> apply_class ;
|
let del = MO_class.create_deleted del in
|
||||||
|
|
||||||
|
apply_class core ;
|
||||||
|
apply_class inact ;
|
||||||
|
apply_class act ;
|
||||||
|
apply_class virt ;
|
||||||
|
apply_class del ;
|
||||||
|
|
||||||
for i=1 to (Array.length mo_class)
|
for i=1 to (Array.length mo_class)
|
||||||
do
|
do
|
||||||
@ -122,28 +105,91 @@ let run ?(core="[]") ?(inact="[]") ?(act="[]") ?(virt="[]") ?(del="[]") ezfio_fi
|
|||||||
done;
|
done;
|
||||||
|
|
||||||
|
|
||||||
MO_class.create_core core |> MO_class.to_string |> print_endline ;
|
(* Debug output *)
|
||||||
MO_class.create_inactive inact |> MO_class.to_string |> print_endline ;
|
MO_class.to_string core |> print_endline ;
|
||||||
MO_class.create_active act |> MO_class.to_string |> print_endline ;
|
MO_class.to_string inact |> print_endline ;
|
||||||
MO_class.create_virtual virt |> MO_class.to_string |> print_endline ;
|
MO_class.to_string act |> print_endline ;
|
||||||
MO_class.create_deleted del |> MO_class.to_string |> print_endline ;
|
MO_class.to_string virt |> print_endline ;
|
||||||
(*
|
MO_class.to_string del |> print_endline ;
|
||||||
|
|
||||||
|
(* Create masks *)
|
||||||
let inactive_mask = Range.of_string inact
|
let ia = Excitation.create_single inact act
|
||||||
|> List.map ~f:MO_number.of_int
|
and aa = Excitation.create_single act act
|
||||||
|> Bitlist.of_mo_number_list n_int
|
and av = Excitation.create_single act virt
|
||||||
and active_mask =
|
|
||||||
let s = Range.of_string act
|
|
||||||
in
|
|
||||||
List.map ~f:MO_number.of_int s
|
|
||||||
|> Bitlist.of_mo_number_list n_int
|
|
||||||
in
|
in
|
||||||
let mask =
|
let single_excitations = [ ia ; aa ; av ]
|
||||||
Bitlist.not_operator inactive_mask
|
|> List.map ~f:Excitation.(fun x ->
|
||||||
|> Bitlist.and_operator active_mask
|
match x with
|
||||||
in apply_mask mask n_int mo_tot_num
|
| Single (x,y) ->
|
||||||
*)
|
( MO_class.to_bitlist n_int (Hole.to_mo_class x),
|
||||||
|
MO_class.to_bitlist n_int (Particle.to_mo_class y) )
|
||||||
|
| Double _ -> assert false
|
||||||
|
)
|
||||||
|
|
||||||
|
and double_excitations = [
|
||||||
|
Excitation.double_of_singles ia ia ;
|
||||||
|
Excitation.double_of_singles ia aa ;
|
||||||
|
Excitation.double_of_singles ia av ;
|
||||||
|
Excitation.double_of_singles aa aa ;
|
||||||
|
Excitation.double_of_singles aa av ;
|
||||||
|
Excitation.double_of_singles av av ]
|
||||||
|
|> List.map ~f:Excitation.(fun x ->
|
||||||
|
match x with
|
||||||
|
| Single _ -> assert false
|
||||||
|
| Double (x,y,z,t) ->
|
||||||
|
( MO_class.to_bitlist n_int (Hole.to_mo_class x),
|
||||||
|
MO_class.to_bitlist n_int (Particle.to_mo_class y) ,
|
||||||
|
MO_class.to_bitlist n_int (Hole.to_mo_class z),
|
||||||
|
MO_class.to_bitlist n_int (Particle.to_mo_class t) )
|
||||||
|
)
|
||||||
|
in
|
||||||
|
|
||||||
|
let extract_hole = function
|
||||||
|
| (h,_) -> h
|
||||||
|
and extract_particle = function
|
||||||
|
| (_,p) -> p
|
||||||
|
and extract_hole1 = function
|
||||||
|
| (h,_,_,_) -> h
|
||||||
|
| _ -> assert false
|
||||||
|
and extract_particle1 = function
|
||||||
|
| (_,p,_,_) -> p
|
||||||
|
| _ -> assert false
|
||||||
|
and extract_hole2 = function
|
||||||
|
| (_,_,h,_) -> h
|
||||||
|
| _ -> assert false
|
||||||
|
and extract_particle2 = function
|
||||||
|
| (_,_,_,p) -> p
|
||||||
|
| _ -> assert false
|
||||||
|
in
|
||||||
|
let result = [
|
||||||
|
List.map ~f:extract_hole single_excitations
|
||||||
|
|> List.fold ~init:(Bitlist.zero n_int) ~f:Bitlist.or_operator ;
|
||||||
|
List.map ~f:extract_particle single_excitations
|
||||||
|
|> List.fold ~init:(Bitlist.zero n_int) ~f:Bitlist.or_operator ;
|
||||||
|
List.map ~f:extract_hole1 double_excitations
|
||||||
|
|> List.fold ~init:(Bitlist.zero n_int) ~f:Bitlist.or_operator ;
|
||||||
|
List.map ~f:extract_particle1 double_excitations
|
||||||
|
|> List.fold ~init:(Bitlist.zero n_int) ~f:Bitlist.or_operator ;
|
||||||
|
List.map ~f:extract_hole2 double_excitations
|
||||||
|
|> List.fold ~init:(Bitlist.zero n_int) ~f:Bitlist.or_operator ;
|
||||||
|
List.map ~f:extract_particle2 double_excitations
|
||||||
|
|> List.fold ~init:(Bitlist.zero n_int) ~f:Bitlist.or_operator ;
|
||||||
|
]
|
||||||
|
in
|
||||||
|
|
||||||
|
List.iter ~f:(fun x-> print_endline (Bitlist.to_string x)) result;
|
||||||
|
let result = List.map ~f:(fun x ->
|
||||||
|
let y = Bitlist.to_int64_list x in y@y )
|
||||||
|
result
|
||||||
|
|> List.concat
|
||||||
|
in
|
||||||
|
|
||||||
|
(* Write masks *)
|
||||||
|
Ezfio.set_bitmasks_n_int (N_int_number.to_int n_int);
|
||||||
|
Ezfio.set_bitmasks_bit_kind 8;
|
||||||
|
Ezfio.set_bitmasks_n_mask_gen 1;
|
||||||
|
Ezfio.ezfio_array_of_list ~rank:4 ~dim:([| (N_int_number.to_int n_int) ; 2; 6; 1|]) ~data:result
|
||||||
|
|> Ezfio.set_bitmasks_generators ;
|
||||||
;;
|
;;
|
||||||
|
|
||||||
let ezfio_file =
|
let ezfio_file =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user