Suddenly KeyError 'message' after running without problems

Hi,

Since today I am suddenly getting a KeyError when I run the below code

model = stan.build(open('model.stan').read(), data)
stan_fit = model.sample(num_chains=4, num_samples=500)

Everything worked fine before. The full error traceback


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[51], line 1
----> 1 model = stan.build(open(
      2     'model.stan').read(), data)
      3 stan_fit = model.sample(num_chains=4, num_samples=500)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/stan/model.py:519, in build(program_code, data, random_seed)
    516         return Model(model_name, program_code, data, param_names, constrained_param_names, dims, random_seed)
    518 try:
--> 519     return asyncio.run(go())
    520 except KeyboardInterrupt:
    521     return

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/nest_asyncio.py:35, in _patch_asyncio.<locals>.run(main, debug)
     33 task = asyncio.ensure_future(main)
     34 try:
---> 35     return loop.run_until_complete(task)
     36 finally:
     37     if not task.done():

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/nest_asyncio.py:90, in _patch_loop.<locals>.run_until_complete(self, future)
     87 if not f.done():
     88     raise RuntimeError(
     89         'Event loop stopped before Future completed.')
---> 90 return f.result()

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/futures.py:203, in Future.result(self)
    201 self.__log_traceback = False
    202 if self._exception is not None:
--> 203     raise self._exception.with_traceback(self._exception_tb)
    204 return self._result

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/tasks.py:267, in Task.__step(***failed resolving arguments***)
    263 try:
    264     if exc is None:
    265         # We use the `send` method directly, because coroutines
    266         # don't have `__iter__` and `__next__` methods.
--> 267         result = coro.send(None)
    268     else:
    269         result = coro.throw(exc)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/stan/model.py:511, in build.<locals>.go()
    509 resp = await client.post(f"/{model_name}/params", json={"data": data})
    510 if resp.status != 200:
--> 511     raise RuntimeError(resp.json()["message"])
    512 params_list = resp.json()["params"]
    513 assert len({param["name"] for param in params_list}) == len(params_list)

KeyError: 'message'

I am using Python 3.11, Pystan 3.7, asyncio 3.4.3 in a Jupyter Notebook.

Any idea why this is happening suddenly? Thank you

Apparently it is caused by a known bug.

I would suggest using cmdstanpy:

https://cmdstanpy.readthedocs.io/en/v1.1.0/