Refactor run machinery into separate file

This commit is contained in:
Mark Evenson 2022-09-04 08:41:38 +02:00
parent 7effa57921
commit d4a30601f7
3 changed files with 85 additions and 80 deletions

View File

@ -9,5 +9,6 @@
:components ((:file "package")
(:file "json-path")
(:file "plot")
(:file "runner")
(:file "glacier")))))

View File

@ -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

View File

@ -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))))))