Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download bridgestan repo as artifact for BridgeStan.jl #70

Merged
merged 16 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ bridgestan.Rcheck/
# Julia
.juliahistory
build/
Manifest.toml

.DS_Store

Expand Down
1 change: 1 addition & 0 deletions docs/languages/julia.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


This assumes you have followed the [Getting Started guide](../getting-started.rst) to install BridgeStan's pre-requisites and downloaded a copy of the BridgeStan source code.
Note that the Julia interface has the ability to install the BridgeStan source if the ``BRIDGESTAN`` environment variable is not set.


To install the Julia interface, you can either install it directly from Github by running the following inside a Julia REPL
Expand Down
7 changes: 7 additions & 0 deletions julia/Artifacts.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[bridgestan]
git-tree-sha1 = "730b3ee2b8c9fd643dcb2bee6c0ea5995db142d7"
lazy = true

[[bridgestan.download]]
sha256 = "b66a01322b650022bbc7944fa5229cbc90bab63fab28b063c0eae714cd927872"
url = "https://github.com/roualdes/bridgestan/releases/download/v1.0.0/bridgestan-1.0.0.tar.gz"
7 changes: 0 additions & 7 deletions julia/Manifest.toml

This file was deleted.

6 changes: 6 additions & 0 deletions julia/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ name = "BridgeStan"
uuid = "c88b6f0a-829e-4b0b-94b7-f06ab5908f5a"
authors = ["Brian Ward <bward@flatironinstitute.org>", "Bob Carpenter <bcarpenter@flatironinstitute.org", "Edward Roualdes <eroualdes@csuchico.edu>"]
version = "1.0.0"

[deps]
LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3"

[compat]
julia = "1.8"
109 changes: 0 additions & 109 deletions julia/docs/Manifest.toml

This file was deleted.

1 change: 1 addition & 0 deletions julia/docs/src/julia.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@ param_unconstrain_json!
### Compilation utilities
```@docs
compile_model
get_bridgestan_path
set_bridgestan_path!
```
3 changes: 3 additions & 0 deletions julia/src/BridgeStan.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module BridgeStan

using LazyArtifacts

export StanModel,
name,
model_info,
Expand All @@ -18,6 +20,7 @@ export StanModel,
log_density,
log_density_gradient,
log_density_hessian,
get_bridgestan_path,
set_bridgestan_path!,
compile_model

Expand Down
18 changes: 13 additions & 5 deletions julia/src/compile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ function get_make()
get(ENV, "MAKE", Sys.iswindows() ? "mingw32-make.exe" : "make")
end

function get_bridgestan()
"""
get_bridgestan_path() -> String

Return the path the the BridgeStan directory.

If the environment variable `BRIDGESTAN` is set, this will be returned. Otherwise, this
function downloads an artifact containing the BridgeStan repository and returns the path to
the extracted directory.
"""
function get_bridgestan_path()
path = get(ENV, "BRIDGESTAN", "")
if path == ""
error(
"BridgeStan path was not set, compilation will not work until you call `set_bridgestan_path!()`",
)
artifact_path = artifact"bridgestan"
path = joinpath(artifact_path, only(readdir(artifact_path)))
end
return path
end
Expand Down Expand Up @@ -58,7 +66,7 @@ function compile_model(
stanc_args::AbstractVector{String} = String[],
make_args::AbstractVector{String} = String[],
)
bridgestan = get_bridgestan()
bridgestan = get_bridgestan_path()
validate_stan_dir(bridgestan)

if !isfile(stan_file)
Expand Down
66 changes: 0 additions & 66 deletions julia/test/Manifest.toml

This file was deleted.

12 changes: 9 additions & 3 deletions julia/test/compile_tests.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using BridgeStan
using Test

models = joinpath(@__DIR__, "../../test_models/")


@testset "compile good" begin
BridgeStan.set_bridgestan_path!("../..")
models = joinpath(BridgeStan.get_bridgestan_path(), "test_models/")


@testset "compile good" begin
stanfile = joinpath(models, "multi", "multi.stan")
lib = splitext(stanfile)[1] * "_model.so"
rm(lib, force = true)
Expand Down Expand Up @@ -36,3 +36,9 @@ end
@test_throws ErrorException BridgeStan.set_bridgestan_path!("dummy")
@test_throws ErrorException BridgeStan.set_bridgestan_path!(models)
end

@testset "download artifact" begin
withenv("BRIDGESTAN" => nothing) do
BridgeStan.validate_stan_dir(BridgeStan.get_bridgestan_path())
end
end
5 changes: 3 additions & 2 deletions julia/test/model_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ using Test
using Printf

function load_test_model(name::String, with_data = true)
lib = joinpath(@__DIR__, @sprintf("../../test_models/%s/%s_model.so", name, name))
bridgestan = BridgeStan.get_bridgestan_path()
lib = joinpath(bridgestan, @sprintf("test_models/%s/%s_model.so", name, name))
if with_data
data = joinpath(@__DIR__, @sprintf("../../test_models/%s/%s.data.json", name, name))
data = joinpath(bridgestan, @sprintf("test_models/%s/%s.data.json", name, name))
else
data = ""
end
Expand Down