Skip to content

Commit

Permalink
Rel 4.0.0 - Switch to JSON3
Browse files Browse the repository at this point in the history
  • Loading branch information
goedman committed Jan 30, 2022
1 parent b41c737 commit b26255b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StanOptimize"
uuid = "fbd8da12-e93d-5a64-9231-612a0707ab99"
authors = ["Rob J Goedman <[email protected]>"]
version = "3.3.0"
version = "4.0.0"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand All @@ -20,13 +20,13 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[compat]
CSV = "0.9, 0.10"
DataFrames = "1.0"
CSV = "0.10"
DataFrames = "1.3"
DocStringExtensions = "0.8"
Documenter = "0.27"
Parameters = "0.12"
Reexport = "1.2"
StanBase = "3.2"
StanBase = "4.0"
StanDump = "0.2"
julia = "1"

Expand Down
3 changes: 2 additions & 1 deletion examples/Bernoulli/bernoulli.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ model {
";

data = Dict("N" => 10, "y" => [0, 1, 0, 1, 0, 0, 0, 0, 0, 1])
init = (theta = .5,)
tmpdir = joinpath(@__DIR__, "tmp")

stanmodel = OptimizeModel("bernoulli", bernoulli_model, tmpdir);
rc = stan_optimize(stanmodel; data);
rc = stan_optimize(stanmodel; data, init);

if success(rc)
optim1, cnames = read_optimize(stanmodel)
Expand Down
2 changes: 1 addition & 1 deletion src/StanOptimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using DocStringExtensions: FIELDS, SIGNATURES, TYPEDEF

import StanBase: update_model_file, par, handle_keywords!
import StanBase: executable_path, ensure_executable, stan_compile
import StanBase: update_R_files
import StanBase: update_R_files, update_json_files
import StanBase: data_file_path, init_file_path, sample_file_path
import StanBase: generated_quantities_file_path, log_file_path
import StanBase: diagnostic_file_path, setup_diagnostics
Expand Down
18 changes: 13 additions & 5 deletions src/stanrun/stan_run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Optimize a StanJulia OptimizationModel <: CmdStanModel
### Dispatch arguments
```julia
* `m:: OptimizeModel` # CmdStanModel subtype
* `use_json=true` # Use JSON3 for data and init files
```
### Keyword arguments
Expand Down Expand Up @@ -51,7 +52,7 @@ See extended help for other keyword arguments ( `??stan_optimize` ).
* `save_iterations=0` # Stream iterations to output
```
"""
function stan_run(m::T; kwargs...) where {T <: CmdStanModels}
function stan_run(m::T, use_json=true; kwargs...) where {T <: CmdStanModels}

handle_keywords!(m, kwargs)

Expand All @@ -61,10 +62,17 @@ function stan_run(m::T; kwargs...) where {T <: CmdStanModels}
isfile(sfile) && rm(sfile)
end

:init in keys(kwargs) && update_R_files(m, kwargs[:init],
m.num_chains, "init")
:data in keys(kwargs) && update_R_files(m, kwargs[:data],
m.num_chains, "data")
if use_json
:init in keys(kwargs) && update_json_files(m, kwargs[:init],
m.num_chains, "init")
:data in keys(kwargs) && update_json_files(m, kwargs[:data],
m.num_chains, "data")
else
:init in keys(kwargs) && update_R_files(m, kwargs[:init],
m.num_chains, "init")
:data in keys(kwargs) && update_R_files(m, kwargs[:data],
m.num_chains, "data")
end

m.cmds = [stan_cmds(m, id; kwargs...) for id in 1:m.num_chains]

Expand Down

0 comments on commit b26255b

Please sign in to comment.