{"id":17062580,"url":"https://github.com/wardbrian/pybind_expose_stan_fns","last_synced_at":"2025-04-12T18:31:03.471Z","repository":{"id":95242113,"uuid":"533498349","full_name":"WardBrian/pybind_expose_stan_fns","owner":"WardBrian","description":"Exposing Stan functions in Python","archived":false,"fork":false,"pushed_at":"2025-01-30T17:06:57.000Z","size":35,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T12:51:07.606Z","etag":null,"topics":["cmdstan","pybind11","python","stan"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WardBrian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-06T20:51:32.000Z","updated_at":"2025-01-30T17:07:01.000Z","dependencies_parsed_at":"2025-01-30T16:32:58.360Z","dependency_job_id":"d66459e2-ce8c-4c66-80b6-5572ed8f436c","html_url":"https://github.com/WardBrian/pybind_expose_stan_fns","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WardBrian%2Fpybind_expose_stan_fns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WardBrian%2Fpybind_expose_stan_fns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WardBrian%2Fpybind_expose_stan_fns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WardBrian%2Fpybind_expose_stan_fns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WardBrian","download_url":"https://codeload.github.com/WardBrian/pybind_expose_stan_fns/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248613235,"owners_count":21133473,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmdstan","pybind11","python","stan"],"created_at":"2024-10-14T10:50:17.757Z","updated_at":"2025-04-12T18:31:03.451Z","avatar_url":"https://github.com/WardBrian.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Exposing Stan functions in Python through PyBind11\n\nThis repo contains (a very work in progress attempt at) code to expose functions\nwritten in a Stan model to the Python runtime through the\n[PyBind11](https://pybind11.readthedocs.io/en/stable/) library.\n\nThis is very similar to *[Exposing Stan user-defined functions using CmdStanR and Rcpp](https://rok-cesnovar.github.io/misc/exposing_cmdstanr_udf.html)*.\n\nThis supports all possible Stan functions, including pRNGs and functions which edit the `target` variable.\nThese are supported through two objects exposed on all models, `StanRNG` and `StanAccumulator`, which are\nthin wrappers for `stan::rng_t` and `stan::math::accumulator\u003cdouble\u003e`, respectively.\n\n## Running\n\nThis assumes you have a working installation of\n[CmdStan](https://github.com/stan-dev/cmdstan), and a Python environment with both\n[cmdstanpy](https://github.com/stan-dev/cmdstanpy) and [PyBind11](https://github.com/pybind/pybind11)\n\n```python\nimport pybind_stan_fns\nbasic = pybind_stan_fns.expose('./test/basic.stan')\nbasic.test_printing() # etc\n```\n\n**Note**: On Windows, the above is not sufficient. One also must have\nthe [Microsoft Visual Studio Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/),\nincluding the optional LLVM/Clang extensions, and a pre-built version of both Sundials and TBB.\nThe `expose` function assumes these were installed via [conda](https://docs.conda.io/en/latest/).\nOur [CI Pipeline](./github/workflows/main.yaml) shows how this is done in Github Actions\n\n### Miscellany\n\nThere is a (possibly outdated) pure-shell version of this which just runs `g++` directly.\n\n```shell\n./build.sh basic.stan\npython test_basic.stan\n```\n\nSimilarly on Windows, there is a `build.ps1` powershell script.\n\nFinally, there is also a version which attempts to use `setuptools` for the same effect.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwardbrian%2Fpybind_expose_stan_fns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwardbrian%2Fpybind_expose_stan_fns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwardbrian%2Fpybind_expose_stan_fns/lists"}