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

Fix Sundials make config #152

Merged
merged 4 commits into from
Jul 6, 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 .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
build:
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
env:
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ INC_FIRST ?= -I $(STAN)src -I $(RAPIDJSON)

## Set -fPIC globally since we're always building a shared library
CXXFLAGS += -fPIC
CXXFLAGS_SUNDIALS += -fPIC

## set flags for stanc compiler (math calls MIGHT? set STAN_OPENCL)
ifdef STAN_OPENCL
Expand Down Expand Up @@ -56,12 +57,12 @@ $(BRIDGE_O) : $(BRIDGE_DEPS)
.PRECIOUS: %.hpp

## builds executable (suffix depends on platform)
%_model.so : %.hpp $(BRIDGE_O) $(LIBSUNDIALS) $(MPI_TARGETS) $(TBB_TARGETS)
%_model.so : %.hpp $(BRIDGE_O) $(SUNDIALS_TARGETS) $(MPI_TARGETS) $(TBB_TARGETS)
@echo ''
@echo '--- Compiling C++ code ---'
$(COMPILE.cpp) -x c++ -o $(subst \,/,$*).o $(subst \,/,$<)
@echo '--- Linking C++ code ---'
$(LINK.cpp) -shared -lm -o $(patsubst %.hpp, %_model.so, $(subst \,/,$<)) $(subst \,/,$*.o) $(BRIDGE_O) $(LDLIBS) $(LIBSUNDIALS) $(MPI_TARGETS) $(TBB_TARGETS)
$(LINK.cpp) -shared -lm -o $(patsubst %.hpp, %_model.so, $(subst \,/,$<)) $(subst \,/,$*.o) $(BRIDGE_O) $(LDLIBS) $(SUNDIALS_TARGETS) $(MPI_TARGETS) $(TBB_TARGETS)
$(RM) $(subst \,/,$*).o

.PHONY: docs
Expand Down Expand Up @@ -94,7 +95,7 @@ stan-update-remote:
# print compilation command line config
.PHONY: compile_info
compile_info:
@echo '$(LINK.cpp) $(BRIDGE_O) $(LDLIBS) $(LIBSUNDIALS) $(MPI_TARGETS) $(TBB_TARGETS)'
@echo '$(LINK.cpp) $(BRIDGE_O) $(LDLIBS) $(SUNDIALS_TARGETS) $(MPI_TARGETS) $(TBB_TARGETS)'

## print value of makefile variable (e.g., make print-TBB_TARGETS)
.PHONY: print-%
Expand Down
6 changes: 6 additions & 0 deletions python/test/test_stanmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def test_constructor():
with pytest.raises(RuntimeError, match="find this text: datafails"):
b4 = bs.StanModel(throw_data_so)

load_sundials = str(STAN_FOLDER / "ode_sundials" / "ode_sundials_model.so")
ode_sundials_data = (
STAN_FOLDER / "ode_sundials" / "ode_sundials.data.json"
).read_text()
bs.StanModel(load_sundials, ode_sundials_data)


def test_name():
std_so = str(STAN_FOLDER / "stdnormal" / "stdnormal_model.so")
Expand Down
7 changes: 7 additions & 0 deletions test_models/ode_sundials/ode_sundials.data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"T": 5,
"y0":[5.0, 6.0],
"t0": 0.0,
"ts": [1.0, 2.0, 3.0, 4.0, 5.0],
"theta": 0.1
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// example model from https://mc-stan.org/docs/stan-users-guide/measurement-error-models.html
functions {
vector sho(real t, vector y, real theta) {
vector sho(real t,
vector y,
real theta) {
vector[2] dydt;
dydt[1] = y[2];
dydt[2] = -y[1] - theta * y[2];
Expand All @@ -15,12 +16,11 @@ data {
real theta;
}
model {

}
generated quantities {
array[T] vector[2] y_sim = ode_rk45(sho, y0, t0, ts, theta);
array[T] vector[2] y_sim = ode_bdf(sho, y0, t0, ts, theta);
// add measurement error
for (t in 1 : T) {
for (t in 1:T) {
y_sim[t, 1] += normal_rng(0, 0.1);
y_sim[t, 2] += normal_rng(0, 0.1);
}
Expand Down