roualdes / bridgestan

BridgeStan provides efficient in-memory access through Python, Julia, and R to the methods of a Stan model.
https://roualdes.github.io/bridgestan
BSD 3-Clause "New" or "Revised" License
87 stars 12 forks source link

any way to reduce UserWarning level on loading already loaded model? #219

Closed bob-carpenter closed 3 months ago

bob-carpenter commented 3 months ago

I'm calling Stan in a loop and getting this warning every iteration:

/usr/local/lib/python3.9/site-packages/bridgestan/model.py:137: UserWarning: Loading a shared object /Users/bcarpenter/github/bob-carpenter/adaptive-hmc/stan/normal_model.so that has already been loaded.
If the file has changed since the last time it was loaded, this load may not update the library!

This arises from calling this repeatedly in a loop with the same model_path:

   model = bs.StanModel(model_lib=model_path, data=data,
                             capture_stan_prints=False)

In this instance (and many others), I could pull the model creation out of the loop and pass it into the loop as an argument. I'd rather not have to do that here as it's more natural to have the caller not know anything about these low-level model-creation details.

roualdes commented 3 months ago

Yep, Aki, just requested the same https://github.com/roualdes/bridgestan/issues/217. Brian fixed it https://github.com/roualdes/bridgestan/pull/218. Should be in the next release. Or you can pull the latest from GitHub and point your code to the local copy on your machine.

WardBrian commented 3 months ago

I don't like releasing on Fridays, otherwise I would get it out there for you now (it would be a small release, really just #218, #197, and #213 which would be user-facing)

WardBrian commented 3 months ago

If you run pip install --upgrade bridgestan now it will have the warn argument