Cmdstanpy recompiles models and fails on some systems

Hi,

the following problem was reported by two people using Gloria and is related to an open issue. The repository contains both .stan files as well as the respective compiled .exe files. After the users clone the repository and try to run the model, cmdstanpy attempts to re-compile and fails with the error

ValueError: Failed to compile Stan model ‘..\Lib\site-packages\gloria\stan_models\poisson.stan’. Console:

Command: [‘mingw32-make’, ‘STANCFLAGS+=–filename-in-msg=poisson.stan’, ‘../Lib/site-packages/gloria/stan_models/poisson.exe’]
failed with error [WinError 2] Das System kann die angegebene Datei nicht finden

The German message at the end just states “file not found”.

Indeed, when the users run where mingw32-make they get “file not found” although the toolchain was installed successfully using the command

install_cmdstan(version="2.36.0", compiler=True)

Manual installations of RTools in their virtual environment or globally did not help.

I tried to reproduce this error on three machines, covering Windows 10 and 11 as well as home-networks and company-networks, but never encountered it (similar to the users’ setups). Therefore, I am a little limited on how to debug this issue. Do you have ideas why the build tools are not installed correctly?

On a related note, if you’ll allow me: I thought the re-compilation is triggered as both .stan and .exe have the same last-modified timestamp from the moment the repository was cloned, but this seems to be not true. Can you tell, what actually causes the recompilation?

Thanks for your help!

Recompilation will be triggered if any dependency of the executable is newer.

This includes the .stan file, but it also includes parts of the cmdstan distribution, so installing cmdstan freshly will almost always mean the model is considered out-of-date to the build system. The upshot of this is including the exe as you have but still installing cmdstan ends up making this somewhat self-defeating. A user who didn’t already have cmdstan will see new builds every time, and users who already had cmdstan probably didn’t need the binary to be pre-built for them.

This unfortunately doesn’t help the user who was getting file-not-found errors, but it’s quite difficult to say what would be the cause based only on that. If the user can run the command in a normal terminal outside of python this sometimes gives a more descriptive error