How do I tell pystan which compiler to use?

I am trying to build a Stan model within a Docker container using Ubuntu 18.04 and PyStan 3.2.0. I installed PyStan using poetry, and can run the eight schools model with no problems.

The model itself was developed on my local machine with rstan, and compilation and sampling work fine there. But within the Docker + PyStan environment, I get the following warnings and errors which make me think it might be a compiler issue.

Building: found in cache, done.
Messages from stanc:
Warning in '/tmp/httpstan_6y_btqbz/model_kuf5ecx3.stan', line 5, column 13: Use of poisson_cdf without a vertical bar (|) between the first two arguments is deprecated.Warning: The parameter theta has no priors.
Warning: The parameter beta_shop_device has no priors.
Warning: The parameter beta_other has no priors.

KeyError                                  Traceback (most recent call last)
/tmp/ipykernel_18/ in <module>
----> 1 posterior =, stan_data)

/opt/miniconda/lib/python3.8/site-packages/stan/ in build(program_code, data, random_seed)
    511     try:
--> 512         return
    513     except KeyboardInterrupt:
    514         return  # type: ignore

/opt/miniconda/lib/python3.8/site-packages/ in run(future, debug)
     30         loop = asyncio.get_event_loop()
     31         loop.set_debug(debug)
---> 32         return loop.run_until_complete(future)
     34     if sys.version_info >= (3, 6, 0):

/opt/miniconda/lib/python3.8/site-packages/ in run_until_complete(self, future)
     68                 raise RuntimeError(
     69                     'Event loop stopped before Future completed.')
---> 70             return f.result()
     72     def _run_once(self):

/opt/miniconda/lib/python3.8/asyncio/ in result(self)
    176         self.__log_traceback = False
    177         if self._exception is not None:
--> 178             raise self._exception
    179         return self._result

/opt/miniconda/lib/python3.8/asyncio/ in __step(***failed resolving arguments***)
    278                 # We use the `send` method directly, because coroutines
    279                 # don't have `__iter__` and `__next__` methods.
--> 280                 result = coro.send(None)
    281             else:
    282                 result = coro.throw(exc)

/opt/miniconda/lib/python3.8/site-packages/stan/ in go()
    502             resp = await"/{model_name}/params", json={"data": data})
    503             if resp.status != 200:
--> 504                 raise RuntimeError(resp.json()["message"])
    505             params_list = resp.json()["params"]
    506             assert len({param["name"] for param in params_list}) == len(params_list)

KeyError: 'message'

The model file starts with these lines relevant to the warning above, and the parameters beta_shop_device and beta_other both have priors.

functions {
  // Truncated at 1 for now
  real poisson_lccdf_trunc(int y, real lambda) {
    real a = 1 / (1 - exp(-lambda));
    real b = poisson_cdf(y, lambda);
    return(log1m(a * (b - exp(-lambda))));

I see that PyStan requires gcc >= 9.0.0 or clang >= 10.0.0. The Docker machine had gcc 6.0.0 when I first installed PyStan and ran the eight schools model. After getting the above errors though, I tried to install newer compilers: gcc 9 isn’t available in the standard repos for this edition of Ubuntu so I installed clang 10.0.0 but still no luck.

Is there a way that I can tell Stan which compiler to use when building the model? I can’t even see from the errors above which compiler it has used. Perhaps I also need to reinstall PyStan using the modern compiler?

Thank you!

I think this is not related to compiler but there is a bug in httpstan for catching some error. cc @ariddell

(Or maybe the real error is, but it is masked under httpstan error)

Can you try setting CC and CXX env vars to compiler you want.

No joy, unfortunately (both with gcc-9 and clang-10). Same messages as in the post above.

If it helps, there are 84 warnings generated during compilation. These are related to:

  • unused type alias
  • static’ function ‘set_zero_all_adjoints’ declared in header file should be declared ‘static inline’
  • lambda capture ‘a’ is not used and similar
  • comparison of integers of different signs: ‘size_t’ (aka ‘unsigned long’) and ‘Eigen::EigenBase::Index’ (aka ‘long’)
  • Plus more and some notes