From 8f978d95c20bf449299746031cb42a13f1bb0636 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Tue, 10 Oct 2017 09:39:58 +0200 Subject: [PATCH] Update for OCaml 4.04 --- ocaml/Block.ml | 4 ++-- ocaml/Default.ml | 2 +- ocaml/Input.ml | 2 +- ocaml/Launcher.ml | 2 +- ocaml/Md5.ml | 2 +- ocaml/Message.ml | 2 +- ocaml/Qmcchem_config.ml | 2 +- ocaml/Qmcchem_dataserver.ml | 4 ++-- ocaml/Qmcchem_debug.ml | 4 ++-- ocaml/Qmcchem_edit.ml | 2 +- ocaml/Qmcchem_forwarder.ml | 12 ++++++------ ocaml/Qmcchem_info.ml | 6 +++--- ocaml/Qmcchem_md5.ml | 2 +- ocaml/Qmcchem_result.ml | 4 ++-- ocaml/Qmcchem_run.ml | 18 +++++++++--------- ocaml/Qmcchem_stop.ml | 2 +- ocaml/Qputils.ml | 2 +- ocaml/Random_variable.ml | 4 ++-- ocaml/Sample.ml | 4 ++-- ocaml/Sample.mli | 4 +++- ocaml/Scheduler.ml | 2 +- ocaml/Watchdog.ml | 6 +++--- ocaml/build.ninja | 4 ++-- ocaml/ninja_ocaml.py | 2 +- ocaml/qmcchem.ml | 2 +- ocaml/qptypes_generator.ml | 12 ++++++------ 26 files changed, 57 insertions(+), 55 deletions(-) diff --git a/ocaml/Block.ml b/ocaml/Block.ml index b78eabe..a26c1f8 100644 --- a/ocaml/Block.ml +++ b/ocaml/Block.ml @@ -1,5 +1,5 @@ -open Core.Std;; -open Qptypes;; +open Core +open Qptypes type t = { property : Property.t ; diff --git a/ocaml/Default.ml b/ocaml/Default.ml index 12f5f86..c0c3dce 100644 --- a/ocaml/Default.ml +++ b/ocaml/Default.ml @@ -1,4 +1,4 @@ -open Core.Std;; +open Core let simulation_nucl_fitcusp_factor = lazy( diff --git a/ocaml/Input.ml b/ocaml/Input.ml index 70b321b..028acc2 100644 --- a/ocaml/Input.ml +++ b/ocaml/Input.ml @@ -1,4 +1,4 @@ -open Core.Std +open Core open Qptypes open Qputils diff --git a/ocaml/Launcher.ml b/ocaml/Launcher.ml index 4b9de5a..7b4066d 100644 --- a/ocaml/Launcher.ml +++ b/ocaml/Launcher.ml @@ -1,4 +1,4 @@ -open Core.Std;; +open Core type t = | Srun diff --git a/ocaml/Md5.ml b/ocaml/Md5.ml index 48d0b9b..fa177f1 100644 --- a/ocaml/Md5.ml +++ b/ocaml/Md5.ml @@ -1,4 +1,4 @@ -open Core.Std +open Core (** Directory containing the list of input files. The directory is created is inexistant. *) let input_directory = lazy ( diff --git a/ocaml/Message.ml b/ocaml/Message.ml index 8e103ae..2db843b 100644 --- a/ocaml/Message.ml +++ b/ocaml/Message.ml @@ -1,4 +1,4 @@ -open Core.Std +open Core open Qptypes type t = diff --git a/ocaml/Qmcchem_config.ml b/ocaml/Qmcchem_config.ml index 894279a..d9f302d 100644 --- a/ocaml/Qmcchem_config.ml +++ b/ocaml/Qmcchem_config.ml @@ -1,4 +1,4 @@ -open Core.Std;; +open Core (** QMC=Chem installation directory *) diff --git a/ocaml/Qmcchem_dataserver.ml b/ocaml/Qmcchem_dataserver.ml index 3dce4f1..6386771 100644 --- a/ocaml/Qmcchem_dataserver.ml +++ b/ocaml/Qmcchem_dataserver.ml @@ -1,4 +1,4 @@ -open Core.Std +open Core open Qptypes (** Data server of QMC=Chem. @@ -36,7 +36,7 @@ let run ?(daemon=true) ezfio_filename = begin Printf.printf "Generating initial walkers...\n%!"; Unix.fork_exec ~prog:(Lazy.force Qmcchem_config.qmc_create_walkers) - ~args:["qmc_create_walkers" ; ezfio_filename] () + ~argv:["qmc_create_walkers" ; ezfio_filename] () |> Unix.waitpid_exn ; Printf.printf "Initial walkers ready\n%!" end ; diff --git a/ocaml/Qmcchem_debug.ml b/ocaml/Qmcchem_debug.ml index 950446e..887d90d 100644 --- a/ocaml/Qmcchem_debug.ml +++ b/ocaml/Qmcchem_debug.ml @@ -1,4 +1,4 @@ -open Core.Std +open Core let run ~t ezfio_filename= @@ -49,7 +49,7 @@ let run ~t ezfio_filename= in tot_size := Byte_units.create `Bytes ((Byte_units.bytes !tot_size) +. (Byte_units.bytes bytes)); Printf.printf "%s\n%!" (Byte_units.to_string !tot_size); - Time.pause (Time.Span.of_float 1.) + Time.pause (Time.Span.of_sec 1.) done end else diff --git a/ocaml/Qmcchem_edit.ml b/ocaml/Qmcchem_edit.ml index bcad9c7..8a757f3 100644 --- a/ocaml/Qmcchem_edit.ml +++ b/ocaml/Qmcchem_edit.ml @@ -1,4 +1,4 @@ -open Core.Std +open Core let file_header filename = Printf.sprintf " diff --git a/ocaml/Qmcchem_forwarder.ml b/ocaml/Qmcchem_forwarder.ml index 6a5719c..b5807d3 100644 --- a/ocaml/Qmcchem_forwarder.ml +++ b/ocaml/Qmcchem_forwarder.ml @@ -1,4 +1,4 @@ -open Core.Std;; +open Core let bind_socket ~socket_type ~socket ~address = let rec loop = function @@ -11,7 +11,7 @@ let bind_socket ~socket_type ~socket ~address = ZMQ.Socket.bind socket address; loop (-1) with - | Unix.Unix_error _ -> (Time.pause @@ Time.Span.of_float 1. ; loop (i-1) ) + | Unix.Unix_error _ -> (Time.pause @@ Time.Span.of_sec 1. ; loop (i-1) ) | other_exception -> raise other_exception in loop 10 @@ -40,7 +40,7 @@ let run ezfio_filename dataserver = in (* Build qmc executable command *) - let prog, args = + let prog, argv = qmc, [ qmc ; ezfio_filename ; Printf.sprintf "ipc://%s:%d" Qmcchem_config.dev_shm port ]; @@ -57,7 +57,7 @@ let run ezfio_filename dataserver = | Unix.Unix_error _ -> begin Unix.chdir tmpdir; - Time.pause @@ Time.Span.of_float 0.1; + Time.pause @@ Time.Span.of_sec 0.1; match (Sys.file_exists "PID") with | `No | `Unknown -> () @@ -75,7 +75,7 @@ let run ezfio_filename dataserver = begin match Signal.send (Signal.of_system_int 0) (`Pid (Pid.of_int pid)) with | `No_such_process -> () - | _ -> ignore @@ Unix.exec ~prog ~args () + | _ -> ignore @@ Unix.exec ~prog ~argv () end end in @@ -89,7 +89,7 @@ let run ezfio_filename dataserver = (* Fork a qmc *) ignore @@ - Watchdog.fork_exec ~prog ~args (); + Watchdog.fork_exec ~prog ~argv (); (* If there are MICs, use them here (TODO) *) diff --git a/ocaml/Qmcchem_info.ml b/ocaml/Qmcchem_info.ml index 3a81458..a293791 100644 --- a/ocaml/Qmcchem_info.ml +++ b/ocaml/Qmcchem_info.ml @@ -1,4 +1,4 @@ -open Core.Std +open Core let run ezfio_filename = @@ -6,12 +6,12 @@ let run ezfio_filename = let qmcchem_info = Lazy.force Qmcchem_config.qmcchem_info in - let prog, args = + let prog, argv = qmcchem_info, [ qmcchem_info ; ezfio_filename ] in ignore @@ - Unix.exec ~prog ~args () + Unix.exec ~prog ~argv () let spec = diff --git a/ocaml/Qmcchem_md5.ml b/ocaml/Qmcchem_md5.ml index 54669a6..2f728cd 100644 --- a/ocaml/Qmcchem_md5.ml +++ b/ocaml/Qmcchem_md5.ml @@ -1,4 +1,4 @@ -open Core.Std +open Core let run ?c ?d ~l ~update ezfio_filename = diff --git a/ocaml/Qmcchem_result.ml b/ocaml/Qmcchem_result.ml index c1737d6..de93ec5 100644 --- a/ocaml/Qmcchem_result.ml +++ b/ocaml/Qmcchem_result.ml @@ -1,4 +1,4 @@ -open Core.Std +open Core open Qptypes (** Display a table that can be plotted by gnuplot *) @@ -65,7 +65,7 @@ let display_cumulants ~range property = Printf.printf "Variance = %16.10f\n" cum.(1); Printf.printf "Centered k3 = %16.10f\n" cum.(2); Printf.printf "Centered k4 = %16.10f\n" cum.(3); - print_newline (); + Printf.printf "\n%!"; let n = 1. /. 12. *. cum.(2) *. cum.(2) +. 1. /. 48. *. cum.(3) *. cum.(3) in diff --git a/ocaml/Qmcchem_run.ml b/ocaml/Qmcchem_run.ml index 03d9bc1..7a1a465 100644 --- a/ocaml/Qmcchem_run.ml +++ b/ocaml/Qmcchem_run.ml @@ -1,4 +1,4 @@ -open Core.Std +open Core let full_run ?(start_dataserver=true) ezfio_filename = (* Identify the job scheduler *) @@ -36,13 +36,13 @@ let full_run ?(start_dataserver=true) ezfio_filename = (* Start the data server *) - let prog, args = + let prog, argv = qmcchem, [ qmcchem; "run" ; "-d" ; ezfio_filename] in let pid_dataserver = - Watchdog.fork_exec ~prog ~args () + Watchdog.fork_exec ~prog ~argv () in - Printf.printf "%7d : %s\n%!" (Pid.to_int pid_dataserver) (String.concat ~sep:" " args) + Printf.printf "%7d : %s\n%!" (Pid.to_int pid_dataserver) (String.concat ~sep:" " argv) end; @@ -83,7 +83,7 @@ let full_run ?(start_dataserver=true) ezfio_filename = | n -> if (not (test_open_rep_socket ())) then begin - Time.pause (Time.Span.of_float 0.5); + Time.pause (Time.Span.of_sec 0.5); count (n-1); end else @@ -94,7 +94,7 @@ let full_run ?(start_dataserver=true) ezfio_filename = (* Start the qmc processes *) - let prog, args = + let prog, argv = let launcher = Launcher.(find () |> to_string) in @@ -110,12 +110,12 @@ let full_run ?(start_dataserver=true) ezfio_filename = in let pid_qmc = try - Watchdog.fork_exec ~prog ~args () + Watchdog.fork_exec ~prog ~argv () with | Unix.Unix_error _ -> begin let command = - String.concat ~sep:" " args + String.concat ~sep:" " argv in Printf.printf " ============================================================ @@ -126,7 +126,7 @@ Error: Unable to run the following command Watchdog.kill () end in - Printf.printf "%7d : %s\n%!" (Pid.to_int pid_qmc) (String.concat ~sep:" " args); + Printf.printf "%7d : %s\n%!" (Pid.to_int pid_qmc) (String.concat ~sep:" " argv); (* Wait for processes to finish *) Watchdog.join () diff --git a/ocaml/Qmcchem_stop.ml b/ocaml/Qmcchem_stop.ml index 3224d29..2607eac 100644 --- a/ocaml/Qmcchem_stop.ml +++ b/ocaml/Qmcchem_stop.ml @@ -1,4 +1,4 @@ -open Core.Std +open Core let run ezfio_filename = diff --git a/ocaml/Qputils.ml b/ocaml/Qputils.ml index 19a5565..7ae4ffa 100644 --- a/ocaml/Qputils.ml +++ b/ocaml/Qputils.ml @@ -1,4 +1,4 @@ -open Core.Std +open Core let split_re = Str.regexp " +" diff --git a/ocaml/Random_variable.ml b/ocaml/Random_variable.ml index c1ae8ad..b8e8a26 100644 --- a/ocaml/Random_variable.ml +++ b/ocaml/Random_variable.ml @@ -1,4 +1,4 @@ -open Core.Std +open Core open Qptypes type t = @@ -64,7 +64,7 @@ end = struct (x -. mu) *. ( x -. mu) /. sigma2 in let pi = - acos (-1.) + Float.acos (-1.) in let c = 1. /. (sqrt (sigma2 *. (pi +. pi))) diff --git a/ocaml/Sample.ml b/ocaml/Sample.ml index 14b709d..8f6818f 100644 --- a/ocaml/Sample.ml +++ b/ocaml/Sample.ml @@ -1,9 +1,9 @@ -open Core.Std +open Core type t = | One_dimensional of float | Multidimensional of (float array * int) -with sexp +[@ deriving sexp] let dimension = function | One_dimensional _ -> 1 diff --git a/ocaml/Sample.mli b/ocaml/Sample.mli index 27c965c..afa2308 100644 --- a/ocaml/Sample.mli +++ b/ocaml/Sample.mli @@ -1,4 +1,6 @@ -type t with sexp +open Core + +type t [@@ deriving sexp] val to_float : ?idx:int -> t -> float val to_float_array : t -> float array val of_float : float -> t diff --git a/ocaml/Scheduler.ml b/ocaml/Scheduler.ml index 06084c6..f20b184 100644 --- a/ocaml/Scheduler.ml +++ b/ocaml/Scheduler.ml @@ -1,4 +1,4 @@ -open Core.Std;; +open Core type t = | SGE diff --git a/ocaml/Watchdog.ml b/ocaml/Watchdog.ml index 3a6a0aa..d0e92b8 100644 --- a/ocaml/Watchdog.ml +++ b/ocaml/Watchdog.ml @@ -1,4 +1,4 @@ -open Core.Std;; +open Core let _list = ref [] ;; let _running = ref false;; @@ -90,9 +90,9 @@ let del pid = ;; (** Fork and exec a new process *) -let fork_exec ~prog ~args () = +let fork_exec ~prog ~argv () = let pid = - Unix.fork_exec ~prog ~args () + Unix.fork_exec ~prog ~argv () in let f () = diff --git a/ocaml/build.ninja b/ocaml/build.ninja index 8238517..76786c0 100644 --- a/ocaml/build.ninja +++ b/ocaml/build.ninja @@ -1,7 +1,7 @@ MAIN=qmcchem # Main program to build -PACKAGES=-package core,cryptokit,str,ZMQ,sexplib.syntax +PACKAGES=-package core,cryptokit,str,ZMQ #,ppx_sexp_conv # Required opam packages, for example: # PACKAGES=-package core,sexplib.syntax @@ -10,7 +10,7 @@ THREAD=-thread # If you need threding support, use: # THREAD=-thread -SYNTAX=-syntax camlp4o +SYNTAX= # If you need pre-processing, use: # SYNTAX=-syntax camlp4o diff --git a/ocaml/ninja_ocaml.py b/ocaml/ninja_ocaml.py index 00d992e..775b670 100755 --- a/ocaml/ninja_ocaml.py +++ b/ocaml/ninja_ocaml.py @@ -196,7 +196,7 @@ MAIN= PACKAGES= # Required opam packages, for example: -# PACKAGES=-package core,sexplib.syntax +# PACKAGES=-package core THREAD= # If you need threding support, use: diff --git a/ocaml/qmcchem.ml b/ocaml/qmcchem.ml index db1d35a..ad341b3 100644 --- a/ocaml/qmcchem.ml +++ b/ocaml/qmcchem.ml @@ -1,4 +1,4 @@ -open Core.Std +open Core let command = diff --git a/ocaml/qptypes_generator.ml b/ocaml/qptypes_generator.ml index cbcbd26..9889b92 100644 --- a/ocaml/qptypes_generator.ml +++ b/ocaml/qptypes_generator.ml @@ -1,4 +1,4 @@ -open Core.Std;; +open Core let input_data = " * Positive_float : float @@ -156,12 +156,12 @@ let untouched = " let template = format_of_string " module %s : sig - type t with sexp + type t [@@ deriving sexp] val to_%s : t -> %s val of_%s : %s %s -> t val to_string : t -> string end = struct - type t = %s with sexp + type t = %s [@@ deriving sexp] let to_%s x = x let of_%s %s x = ( %s x ) let to_string x = %s.to_string x @@ -199,13 +199,13 @@ let parse_input input= let ezfio_template = format_of_string " module %s : sig - type t with sexp + type t [@@ deriving sexp] val to_%s : t -> %s val get_max : unit -> %s val of_%s : ?min:%s -> ?max:%s -> %s -> t val to_string : t -> string end = struct - type t = %s with sexp + type t = %s [@@ deriving sexp] let to_string x = %s.to_string x let get_max () = if (Ezfio.has_%s ()) then @@ -312,7 +312,7 @@ match msg with " ] @ let () = let input = String.concat ~sep:"\n" - [ "open Core.Std\nlet warning = print_string\n\n" ; + [ "open Core\nlet warning = print_string\n\n" ; parse_input input_data ; parse_input_ezfio input_ezfio ; create_ezfio_handler ();