From d4a30601f768804fa1efae814ef9d609379d642b Mon Sep 17 00:00:00 2001 From: Mark Evenson Date: Sun, 4 Sep 2022 08:41:38 +0200 Subject: [PATCH] Refactor run machinery into separate file --- mevenson/simulation/glacier.asd | 1 + mevenson/simulation/glacier.lisp | 80 ------------------------------ mevenson/simulation/runner.lisp | 84 ++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 80 deletions(-) create mode 100644 mevenson/simulation/runner.lisp diff --git a/mevenson/simulation/glacier.asd b/mevenson/simulation/glacier.asd index d664fd9..8af2350 100644 --- a/mevenson/simulation/glacier.asd +++ b/mevenson/simulation/glacier.asd @@ -9,5 +9,6 @@ :components ((:file "package") (:file "json-path") (:file "plot") + (:file "runner") (:file "glacier"))))) diff --git a/mevenson/simulation/glacier.lisp b/mevenson/simulation/glacier.lisp index a138a96..72074f2 100644 --- a/mevenson/simulation/glacier.lisp +++ b/mevenson/simulation/glacier.lisp @@ -1,10 +1,5 @@ (in-package glacier) -(defparameter +consensus-simulations+ - (merge-pathnames - "work/consensus-prototypes/target/release-opt/consensus-simulations" - (user-homedir-pathname))) - (defun jsown-template () "Return the json template in jsown format used for each run" '(:OBJ @@ -57,82 +52,7 @@ (let ((name (pathname-name (pathname filename)))) (do-urlencode:urldecode name :queryp t))) -(defun run (trials - &key - parameters - (jsown (jsown-template))) - "Run the Glacier simulation TRIALS times for PARAMETERS" - (when parameters - (loop :for (path value) :in parameters - :doing - (set-path jsown path value))) - (let* ((parameter-string - (encode-parameters jsown)) - (id ;; TODO use host-date)) - "0") - (base - (format nil "~a-~a" id parameter-string)) - (input-settings - (merge-pathnames - (concatenate 'string "var/" base ".json") - (user-homedir-pathname))) - (output-file - (merge-pathnames - (concatenate 'string "var/" base ".out") - (user-homedir-pathname)))) - (alexandria:write-string-into-file - (jsown:to-json jsown) - input-settings - :if-exists :supersede) - (format *standard-output* - "~&Runnning ~a trials across ~a nodes for ~a rounds~ -~&k=~a l=~a a1=~a a2=~a~%~tyes=~a no=~a~%" - trials - (get-path jsown '$.byzantine_settings.total_size) - (get-path (first (get-path jsown '$.wards)) '$.time_to_finality.ttf_threshold) - (get-path jsown '$.consensus_settings.glacier.query.initial_query_size) - (get-path jsown '$.consensus_settings.glacier.look_ahead) - (get-path jsown '$.consensus_settings.glacier.evidence_alpha) - (get-path jsown '$.consensus_settings.glacier.evidence_alpha_2) - (get-path jsown '$.distribution.yes) - (get-path jsown '$.distribution.no)) - - (loop :for i :from 1 :upto trials - :doing - (let ((output (namestring - (make-pathname :defaults output-file - :name (format nil "~a-~a" - (pathname-name output-file) - i))))) - (uiop:run-program - `(,(namestring +consensus-simulations+) - "--input-settings" ,(namestring input-settings) - "--output-file" ,(namestring output)) - :ignore-error-status t - :error-output :string - :output :string) - (format *standard-output* "."))) - (format *standard-output* "done~%") - - (values - base))) - -(defun search-parameters () - "A parameter search run" - ;; not exactly sure why something like - ;; (loop :for yes :from 0.4 :to 0.6 :by 0.05… has rounding problems - ;; - (loop :for yes :from 2/5 :to 3/5 :by 1/20 - :for no :from 3/5 :downto 2/5 :by 1/20 - :with rounds = 10000 - :doing - (run 10 - :parameters - `(($.byzantine_settings.total_size ,(expt 10 4)) - ($.distribution.yes ,(coerce yes 'single-float)) - ($.distribution.no ,(coerce no 'single-float)))))) - ;;; unused (defun json-parameters () `($.consensus_settings.glacier.evidence_alpha diff --git a/mevenson/simulation/runner.lisp b/mevenson/simulation/runner.lisp new file mode 100644 index 0000000..a84a20d --- /dev/null +++ b/mevenson/simulation/runner.lisp @@ -0,0 +1,84 @@ +(in-package :glacier) + +(defparameter +consensus-simulations+ + (merge-pathnames + "work/consensus-prototypes/target/release-opt/consensus-simulations" + (user-homedir-pathname))) + + +(defun run (trials + &key + parameters + (jsown (jsown-template))) + "Run the Glacier simulation TRIALS times for PARAMETERS" + (when parameters + (loop :for (path value) :in parameters + :doing + (set-path jsown path value))) + (let* ((parameter-string + (encode-parameters jsown)) + (id ;; TODO use host-date)) + "0") + (base + (format nil "~a-~a" id parameter-string)) + (input-settings + (merge-pathnames + (concatenate 'string "var/" base ".json") + (user-homedir-pathname))) + (output-file + (merge-pathnames + (concatenate 'string "var/" base ".out") + (user-homedir-pathname)))) + (alexandria:write-string-into-file + (jsown:to-json jsown) + input-settings + :if-exists :supersede) + + (format *standard-output* + "~&Runnning ~a trials across ~a nodes for ~a rounds~ +~&k=~a l=~a a1=~a a2=~a~%~tyes=~a no=~a~%" + trials + (get-path jsown '$.byzantine_settings.total_size) + (get-path (first (get-path jsown '$.wards)) '$.time_to_finality.ttf_threshold) + (get-path jsown '$.consensus_settings.glacier.query.initial_query_size) + (get-path jsown '$.consensus_settings.glacier.look_ahead) + (get-path jsown '$.consensus_settings.glacier.evidence_alpha) + (get-path jsown '$.consensus_settings.glacier.evidence_alpha_2) + (get-path jsown '$.distribution.yes) + (get-path jsown '$.distribution.no)) + + (loop :for i :from 1 :upto trials + :doing + (let ((output (namestring + (make-pathname :defaults output-file + :name (format nil "~a-~a" + (pathname-name output-file) + i))))) + (uiop:run-program + `(,(namestring +consensus-simulations+) + "--input-settings" ,(namestring input-settings) + "--output-file" ,(namestring output)) + :ignore-error-status t + :error-output :string + :output :string) + (format *standard-output* "."))) + (format *standard-output* "done~%") + + (values + base))) + +(defun search-parameters () + "A parameter search run" + ;; not exactly sure why something like + ;; (loop :for yes :from 0.4 :to 0.6 :by 0.05… has rounding problems + ;; + (loop :for yes :from 2/5 :to 3/5 :by 1/20 + :for no :from 3/5 :downto 2/5 :by 1/20 + :with rounds = 10000 + :doing + (run 10 + :parameters + `(($.byzantine_settings.total_size ,(expt 10 4)) + ($.distribution.yes ,(coerce yes 'single-float)) + ($.distribution.no ,(coerce no 'single-float)))))) +