Open sethaxen opened 1 week ago
I can reproduce the failure by compiling a cmdstan model with CXXFLAGS+=-DSTAN_MODEL_FVAR_VAR
(which is what BridgeStan is actually defining), so it seems like this is a Stan math library issue. Digging into it now.
https://github.com/stan-dev/math/pull/2535 seems related
It appears this was an include-order issue in stan-dev/stan
Thanks, @WardBrian for the diagnosis and the fix! In the meantime, is there a workaround? e.g. if I replace target += y
with target += sum(y)
, will I still hit this issue? And are there other Stan function calls this would cause to error?
It’s hard to say what other functions would be affected - luckily, they would all manifest in compiler errors, so if they compile you can assume it didn’t run into this problem.
If you run into others, a valid workaround for now is probably just applying the patch I submitted to Stan to your local bridgestan copy - it’s only a few lines changed
Hi @WardBrian, I hit a perhaps unrelated issue that only shows up when compiling for Hessian AD if the target is incremented by a constant in the model
block.:
test.stan
data {
int<lower=1> N;
}
parameters {
vector[N] y;
}
model {
target += 0;
}
Running the same command as in https://github.com/roualdes/bridgestan/issues/237#issue-2370499296 we get the error:
Traceback (most recent call last):
File "<string>", line 4, in <module>
File "/home/sethaxen/software/mambaforge/envs/bridgestan-test/lib/python3.11/site-packages/bridgestan/compile.py", line 142, in compile_model
raise RuntimeError(error)
RuntimeError: Command make BRIDGESTAN_AD_HESSIAN=true STANCFLAGS=--include-paths=. /home/sethaxen/bridgestan_test/test_model.so failed with code 2.
stdout:
--- Translating Stan model to C++ code ---
./bin/stanc --include-paths=. --o=/home/sethaxen/bridgestan_test/test.hpp /home/sethaxen/bridgestan_test/test.stan
stderr:
./bin/stanc: line 1: Not: command not found
make: *** [Makefile:73: /home/sethaxen/bridgestan_test/test.hpp] Error 127
If it's incremented by a non-constant in an _lp
function we still get this error, e.g.
test.stan
:
functions {
vector foo_lp(vector y) {
target += sum(y);
return y;
}
}
data {
int<lower=1> N;
}
parameters {
vector[N] y;
}
transformed parameters {
vector[N] x = foo_lp(y);
}
model {
target += 1;
}
This probably also is not a bridgestan issue, but I'm not sure where to report it.
./bin/stanc: line 1: Not: command not found
This is odd -- can you check in the bridgestan folder if stanc
does exist in bin/ ?
This is odd -- can you check in the bridgestan folder if
stanc
does exist in bin/ ?
Yes, it's there. If I just increment by target += 0 * sum(y)
then compilation was successful.
Weirdly, I deleted .bridgestan
and reinstalled everything, and now this issue is mysteriously resolved. But it wasn't just on my machine; I've been seeing this on CI as well but for different models. (e.g. https://github.com/bob-carpenter/transforms/actions/runs/9713116976/job/26809228120#step:7:264). But anyways, seems unrelated to this and probably something to do with steps I took to install bridgestan.
Since stanc is downloaded from github on first use, maybe something was rate-limiting/blocking you, or perhaps github's servers hiccuped?
Perhaps, though it still seems to be an issue. Is there a way to manually trigger the download of stanc other than compiling a dummy model? I'm wondering if there's somehow an issue with doing this while running pytest.
make bin/stanc
(bin/stanc.exe
on Windows) should do it. But we use pytest ourselves for the Python bindings and this doesn't seem to be an issue
I'm not certain if this is an issue with bridgestan or coming from somewhere else in the toolchain, but if I install gxx from conda-forge, install bridgestan from pypi, and then compile a model requesting
BRIDGESTAN_AD_HESSIAN=true
, then it errors if I have an expression liketarget += y
for a vectory
. It doesn't fail if I usetarget += sum(y)
, and it also doesn't fail if I don't setBRIDGESTAN_AD_HESSIAN=true
.Here's a reproducible example:
test.stan
:Script:
Error: