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

Add dedicated hpp generation step for future cmdstan compatibility #863

Merged
merged 3 commits into from
Jan 8, 2024

Conversation

andrjohns
Copy link
Collaborator

Submission Checklist

  • Run unit tests
  • Declare copyright holder and agree to license (see below)

Summary

As discovered in this thread on the forum, the next version of cmdstan will automatically delete the .hpp file during the make process. This causes R to error when we try to read it in for later use in the model-methods compilation.

This PR adds a separate step for generating and reading the hpp file into the Model object

Copyright and Licensing

Please list the copyright holder for the work you are submitting
(this will be you or your assignee, such as a university or company):
Andrew Johnson

By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses:

@andrjohns
Copy link
Collaborator Author

Also a good reminder to set up the CI to test against cmdstan develop at some point

@WardBrian
Copy link
Member

You can also update your make command to "make foo.hpp foo" and it should build both the executable and hpp (if you also need the .o you can list it there as well)

@codecov-commenter
Copy link

codecov-commenter commented Oct 1, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (48a2b3e) 88.36% compared to head (efd2958) 88.35%.

❗ Current head efd2958 differs from pull request most recent head 447f5f7. Consider uploading reports for the commit 447f5f7 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #863      +/-   ##
==========================================
- Coverage   88.36%   88.35%   -0.01%     
==========================================
  Files          12       12              
  Lines        4528     4527       -1     
==========================================
- Hits         4001     4000       -1     
  Misses        527      527              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@andrjohns
Copy link
Collaborator Author

You can also update your make command to "make foo.hpp foo" and it should build both the executable and hpp (if you also need the .o you can list it there as well)

Ah good call, that should be a bit cleaner, will do

@andrjohns
Copy link
Collaborator Author

You can also update your make command to "make foo.hpp foo" and it should build both the executable and hpp (if you also need the .o you can list it there as well)

Ah good call, that should be a bit cleaner, will do

Hmm it looks like processx package is causing some weird behaviour with this, and the .hpp file is getting deleted anyway, but the same thing doesn't happen through the CLI:

> mod <- cmdstan_model(write_stan_file(modfile), force_recompile = TRUE, quiet = FALSE)
Compiling Stan program...
Running make /var/folders/1d/rjvd0h_n0yq20j13h4gdfytw0000gn/T//RtmpakNfuk/model-19f7c4a9fa8.hpp \
  /var/folders/1d/rjvd0h_n0yq20j13h4gdfytw0000gn/T/RtmpakNfuk/model-19f7c4a9fa8 \
  "STANCFLAGS +=  --name='model_292e651ef3fa7c848ba97246a126a03b_model'"

--- Translating Stan model to C++ code ---
bin/stanc --name='model_292e651ef3fa7c848ba97246a126a03b_model' --o=/var/folders/1d/rjvd0h_n0yq20j13h4gdfytw0000gn/T//RtmpakNfuk/model-19f7c4a9fa8.hpp /var/folders/1d/rjvd0h_n0yq20j13h4gdfytw0000gn/T//RtmpakNfuk/model-19f7c4a9fa8.stan

--- Translating Stan model to C++ code ---
bin/stanc --name='model_292e651ef3fa7c848ba97246a126a03b_model' --o=/var/folders/1d/rjvd0h_n0yq20j13h4gdfytw0000gn/T/RtmpakNfuk/model-19f7c4a9fa8.hpp /var/folders/1d/rjvd0h_n0yq20j13h4gdfytw0000gn/T/RtmpakNfuk/model-19f7c4a9fa8.stan

--- Compiling, linking C++ code ---
clang++ -Wno-deprecated-declarations -ffp-contract=off -std=c++1y -Wno-unknown-warning-option -Wno-tautological-compare -Wno-sign-compare -D_REENTRANT -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2020.3/include    -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.78.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials    -DBOOST_DISABLE_ASSERTS          -c -include-pch stan/src/stan/model/model_header_15_0.hpp.gch -x c++ -o /var/folders/1d/rjvd0h_n0yq20j13h4gdfytw0000gn/T/RtmpakNfuk/model-19f7c4a9fa8.o /var/folders/1d/rjvd0h_n0yq20j13h4gdfytw0000gn/T/RtmpakNfuk/model-19f7c4a9fa8.hpp
clang++ -Wno-deprecated-declarations -ffp-contract=off -std=c++1y -Wno-unknown-warning-option -Wno-tautological-compare -Wno-sign-compare -D_REENTRANT -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2020.3/include    -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.78.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials    -DBOOST_DISABLE_ASSERTS               -Wl,-L,"/Users/andrew/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"/Users/andrew/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/tbb"        /var/folders/1d/rjvd0h_n0yq20j13h4gdfytw0000gn/T/RtmpakNfuk/model-19f7c4a9fa8.o src/cmdstan/main.o       -Wl,-L,"/Users/andrew/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"/Users/andrew/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/tbb"     stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_nvecserial.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_cvodes.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_idas.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_kinsol.a  stan/lib/stan_math/lib/tbb/libtbb.dylib stan/lib/stan_math/lib/tbb/libtbbmalloc.dylib stan/lib/stan_math/lib/tbb/libtbbmalloc_proxy.dylib -o /var/folders/1d/rjvd0h_n0yq20j13h4gdfytw0000gn/T/RtmpakNfuk/model-19f7c4a9fa8
ld: warning: duplicate -rpath '/Users/andrew/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/tbb' ignored
ld: warning: duplicate -rpath '/Users/andrew/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/tbb' ignored

rm -f /var/folders/1d/rjvd0h_n0yq20j13h4gdfytw0000gn/T/RtmpakNfuk/model-19f7c4a9fa8.o
rm /var/folders/1d/rjvd0h_n0yq20j13h4gdfytw0000gn/T/RtmpakNfuk/model-19f7c4a9fa8.hpp

Given that this indicates some flakiness with the processx call to make, I think it's best to leave the .hpp generation explicit like in the current changes

@andrjohns
Copy link
Collaborator Author

@rok-cesnovar just a heads up that we'll need this in before the 2.34 release

@rok-cesnovar
Copy link
Member

Reviewing this later today, thanks for the heads up!

Copy link
Member

@rok-cesnovar rok-cesnovar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, had some downtime just now. This looks great to me!

@rok-cesnovar rok-cesnovar merged commit 187ede9 into master Jan 8, 2024
12 checks passed
@rok-cesnovar rok-cesnovar deleted the fix-hpp-generation branch January 8, 2024 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants