Derive filename from simulation parameters

This commit is contained in:
Mark 2022-09-02 10:29:37 +00:00
parent df0d2f8d8e
commit 930a23efee
3 changed files with 42 additions and 12 deletions

View File

@ -1,6 +1,7 @@
(defsystem glacier
:version "0.0.1"
:depends-on (alexandria
drakma
jsown
split-sequence)
:components ((:module source

View File

@ -7,15 +7,15 @@
2/5
$.consensus_settings.glacier.look_ahead
997
$.consensus_settings.query.initial_query_size
$.consensus_settings.glacier.query.initial_query_size
100
$.consensus_settings.query_multiplier
$.consensus_settings.glacier.query.query_multiplier
2
$.consensus_settings.max_multiplier
$.consensus_settings.glacier.query.max_multiplier
1
$.byzantine_settings.total_size
,(expt 10 4)
$.byzantine_settings.honest
$.byzantine_settings.distribution.honest
1
$.distribution.yes
1/2
@ -24,8 +24,11 @@
(defun jsown-template ()
'(:OBJ
("consensus_settings" :OBJ
("glacier" :OBJ ("evidence_alpha" . 4/5) ("evidence_alpha_2" . 1/2)
("consensus_settings"
:OBJ
("glacier"
:OBJ
("evidence_alpha" . 4/5) ("evidence_alpha_2" . 1/2)
("look_ahead" . 20)
("query" :OBJ ("query_size" . 7) ("initial_query_size" . 7)
("query_multiplier" . 2) ("max_multiplier" . 4))))
@ -45,10 +48,38 @@
(jsown:parse json)))
;; TODO set the template based on the parameters
(values
(uiop:run-program '("./target/release-opt/consensus-simulations"
"--input-settings" "etc/glacier.json"
"--output-file" "var/glacier.output")) ;; name the output something sensible
result
template)))
(defun run ()
(values
(uiop:run-program '("./target/release-opt/consensus-simulations"
"--input-settings" "etc/glacier.json"
"--output-file" "var/glacier.output"))))
;;; N.b. assumes that all JSON keys are 1) lowercase, and 2) unique
(defun encode-filename (jsown)
(let* ((key-json-paths
(loop :for (json-path _) :on (json-parameters) :by #'cddr
:collecting json-path))
(keys
(loop :for key :in key-json-paths
:collecting (cons
(first (last (parse-json-path key)))
key)))
(key-values
(loop :for (key . path-symbol) :in keys
:collecting (cons
key
(ignore-errors
(get-path jsown
(parse-json-path path-symbol))))))
(string
(values
(format nil "~{~a ~}"
(loop for (key . value) :in key-values
:collecting (format nil "~a=~a" key value))))))
(values
(drakma:url-encode string :utf8)
string)))

View File

@ -2,14 +2,12 @@
(in-package glacier)
(defun parse-json-path (symbol)
"Transform a symbol into names of json nodes to navigate"
"Transform a symbol into a list names of json nodes to navigate"
(rest (split-sequence:split-sequence #\. (string-downcase
(symbol-name symbol)))))
;; the result returned here is not setf-able
(defun get-path (jsown path)
;; path may either by a string or a list of strings
(cond ((stringp path)
(jsown:filter jsown path))
((and (consp path)