Skip to content

Commit 255afcb

Browse files
committed
- added support for passing command line arguments
1 parent f616ad0 commit 255afcb

2 files changed

Lines changed: 25 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Change Log
22
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).
33

4+
## [1-alpha3] - 2024-09-11
5+
- added support for passing command line arguments
6+
47
## [1-alpha2] - 2024-07-30
58
- updated deps, added bababashka/process dependency
69
- improved handling of shell commands

src/scicloj/cmdstan_clj/v1/api.clj

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,35 @@
4646
(spit path code)
4747
path))))
4848

49-
(defn model [code]
50-
(let [path (-> code
51-
code->stan-path
52-
(str/replace #"\.stan$" ""))
53-
ret (verbose-shell {:dir STAN_HOME}
54-
"make" path)]
55-
(assoc ret
56-
:path path)))
49+
(defn model
50+
([code]
51+
(model code []))
52+
([code make-args]
53+
(let [path (-> code
54+
code->stan-path
55+
(str/replace #"\.stan$" ""))
56+
ret (apply verbose-shell
57+
{:dir STAN_HOME}
58+
"make"
59+
(conj make-args path))]
60+
(assoc ret
61+
:path path))))
5762

5863
(defn sample
5964
([model data]
6065
(sample model data {}))
61-
([model data {:keys [num-chains]}]
66+
([model data {:as options
67+
:keys [num-chains]}]
6268
(let [data-path (:path (tempfiles/tempfile! ".json"))
6369
samples-path (:path (tempfiles/tempfile! ".csv"))
6470
_ (charred/write-json data-path data)
65-
args [(when num-chains
66-
(str "num_chains=" num-chains))
67-
"data" (str "file=" data-path)
68-
"output" (str "file=" samples-path)]
71+
args (concat (some->> options
72+
(map (fn [[k v]]
73+
(format "%s=%s"
74+
(-> k name (str/replace #"-" "_"))
75+
(str v)))))
76+
["data" (str "file=" data-path)
77+
"output" (str "file=" samples-path)])
6978
ret (->> args
7079
(filter some?)
7180
(apply verbose-shell {} (:path model) "sample"))

0 commit comments

Comments
 (0)