Skip to content

Commit c85790f

Browse files
authored
Update to Stan 2.35 (#5)
* Get ready for Stan 2.35 changes * Update metadata * Clear cache * 3.12 fix * Update main.yaml
1 parent 21d95a6 commit c85790f

File tree

11 files changed

+45
-45
lines changed

11 files changed

+45
-45
lines changed

.github/windows-env.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ channels:
55
dependencies:
66
- tbb-devel>=2021
77
- sundials==6.1.1
8-
- cmdstan==2.34.0 # for speed, we don't really need all the mingw stuff this pulls in
8+
- cmdstan==2.35.0 # for speed, we don't really need all the mingw stuff this pulls in
99
- pip

.github/workflows/main.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ on:
1111
workflow_dispatch: {}
1212

1313
env:
14-
CMDSTAN_VERSION: "2.34.0"
15-
CACHE_NUMBER: 1
14+
CMDSTAN_VERSION: "2.35.0"
15+
CACHE_NUMBER: 0
1616

1717
jobs:
1818
test-package:
@@ -21,7 +21,8 @@ jobs:
2121
strategy:
2222
matrix:
2323
os: [ubuntu-latest, macos-latest]
24-
python-version: [3.8, 3.9, "3.10", 3.11]
24+
python-version: [3.9, "3.10", 3.11, 3.12]
25+
fail-fast: false
2526

2627
steps:
2728
- name: Check out github
@@ -57,7 +58,8 @@ jobs:
5758
runs-on: windows-latest
5859
strategy:
5960
matrix:
60-
python-version: [3.8, 3.9, "3.10", 3.11]
61+
python-version: [3.9, "3.10", 3.11, 3.12]
62+
fail-fast: false
6163

6264
steps:
6365
- name: Check out github

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ __pycache__/
88
build/
99
.pytest_cache/
1010
*.egg-info/
11+
env/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This is very similar to *[Exposing Stan user-defined functions using CmdStanR an
88

99
This supports all possible Stan functions, including pRNGs and functions which edit the `target` variable.
1010
These are supported through two objects exposed on all models, `StanRNG` and `StanAccumulator`, which are
11-
thin wrappers for `boost::ecuyer1988` and `stan::math::accumulator<double>`, respectively.
11+
thin wrappers for `stan::rng_t` and `stan::math::accumulator<double>`, respectively.
1212

1313
## Running
1414

misc/build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $extension = python -c "from distutils import sysconfig; print(sysconfig.get_con
1717
$pybind_includes = python -m pybind11 --includes
1818

1919
$cxxflags = '-std=c++1y -O3 -D_REENTRANT -DBOOST_DISABLE_ASSERTS -D_BOOST_LGAMMA -DTBB_INTERFACE_NEW -Wno-sign-compare -Wno-deprecated-builtins -Wno-ignored-attributes -shared'
20-
$cppflags = "-I $conda_library_path\include\ -I $cmdstan_location/stan/src -I $cmdstan_location/stan/lib/rapidjson_1.1.0/ -I $cmdstan_location/stan/lib/stan_math/ -I $cmdstan_location/stan/lib/stan_math/lib/eigen_3.4.0 -I $cmdstan_location/stan/lib/stan_math/lib/boost_1.78.0 $pybind_includes"
20+
$cppflags = "-I $conda_library_path\include\ -I $cmdstan_location/stan/src -I $cmdstan_location/stan/lib/rapidjson_1.1.0/ -I $cmdstan_location/stan/lib/stan_math/ -I $cmdstan_location/stan/lib/stan_math/lib/eigen_3.4.0 -I $cmdstan_location/stan/lib/stan_math/lib/boost_1.84.0 $pybind_includes"
2121

2222
$linkflags = "-Wl`",/LIBPATH:$conda_library_path\lib\`" -Wl`",/LIBPATH:$cpython_libs`""
2323
$linklibs = '-ltbb -lsundials_nvecserial -lsundials_cvodes -lsundials_idas -lsundials_kinsol'

misc/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ else
1414
extra_args=""
1515
dll_ext=".so.2"
1616
fi
17-
g++ -std=c++1y $extra_args -O3 -D_REENTRANT -DBOOST_DISABLE_ASSERTS -Wno-sign-compare -Wno-ignored-attributes -I "$CMDSTAN"/stan/lib/stan_math/lib/tbb_2020.3/include -I "$CMDSTAN"/stan/src -I "$CMDSTAN"/lib/rapidjson_1.1.0/ -I "$CMDSTAN"/stan/lib/stan_math/ -I "$CMDSTAN"/stan/lib/stan_math/lib/eigen_3.4.0 -I "$CMDSTAN"/stan/lib/stan_math/lib/boost_1.78.0 -I "$CMDSTAN"/stan/lib/stan_math/lib/sundials_6.1.1/include -I $CMDSTAN/stan/lib/stan_math/lib/sundials_6.1.1/src/sundials $(python3 -m pybind11 --includes) -shared -fPIC "$model_name".cpp -o "$model_name$(python3-config --extension-suffix)" -Wl,-L,"$CMDSTAN/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"$CMDSTAN/stan/lib/stan_math/lib/tbb" "$CMDSTAN"/stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_nvecserial.a "$CMDSTAN"/stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_cvodes.a "$CMDSTAN"/stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_idas.a "$CMDSTAN"/stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_kinsol.a "$CMDSTAN"/stan/lib/stan_math/lib/tbb/libtbb"$dll_ext"
17+
g++ -std=c++1y $extra_args -O3 -D_REENTRANT -DBOOST_DISABLE_ASSERTS -Wno-sign-compare -Wno-ignored-attributes -I "$CMDSTAN"/stan/lib/stan_math/lib/tbb_2020.3/include -I "$CMDSTAN"/stan/src -I "$CMDSTAN"/lib/rapidjson_1.1.0/ -I "$CMDSTAN"/stan/lib/stan_math/ -I "$CMDSTAN"/stan/lib/stan_math/lib/eigen_3.4.0 -I "$CMDSTAN"/stan/lib/stan_math/lib/boost_1.84.0 -I "$CMDSTAN"/stan/lib/stan_math/lib/sundials_6.1.1/include -I $CMDSTAN/stan/lib/stan_math/lib/sundials_6.1.1/src/sundials $(python3 -m pybind11 --includes) -shared -fPIC "$model_name".cpp -o "$model_name$(python3-config --extension-suffix)" -Wl,-L,"$CMDSTAN/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"$CMDSTAN/stan/lib/stan_math/lib/tbb" "$CMDSTAN"/stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_nvecserial.a "$CMDSTAN"/stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_cvodes.a "$CMDSTAN"/stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_idas.a "$CMDSTAN"/stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_kinsol.a "$CMDSTAN"/stan/lib/stan_math/lib/tbb/libtbb"$dll_ext"

misc/setuptools_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
cmdstan_path + "/lib/rapidjson_1.1.0/",
1212
cmdstan_path + "/stan/lib/stan_math/",
1313
cmdstan_path + "/stan/lib/stan_math/lib/eigen_3.4.0",
14-
cmdstan_path + "/stan/lib/stan_math/lib/boost_1.78.0",
14+
cmdstan_path + "/stan/lib/stan_math/lib/boost_1.84.0",
1515
cmdstan_path + "/stan/lib/stan_math/lib/sundials_6.1.1/include",
1616
cmdstan_path + "/stan/lib/stan_math/lib/sundials_6.1.1/src/sundials",
1717
]

pybind_stan_fns/__init__.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import subprocess
55
import sys
66
import sysconfig
7-
from distutils import sysconfig as dist_sysconfig
87
from pathlib import Path
98

109
import cmdstanpy
@@ -47,7 +46,7 @@ def get_pybind_includes():
4746
("stan", "lib", "rapidjson_1.1.0"),
4847
("stan", "lib", "stan_math"),
4948
("stan", "lib", "stan_math", "lib", "eigen_3.4.0"),
50-
("stan", "lib", "stan_math", "lib", "boost_1.81.0"),
49+
("stan", "lib", "stan_math", "lib", "boost_1.84.0"),
5150
]
5251

5352
OTHER_INCLUDES = []
@@ -68,7 +67,7 @@ def get_pybind_includes():
6867
STANC = STANC.with_suffix(".exe")
6968
CPP_DEFINES.extend(["_BOOST_LGAMMA", "TBB_INTERFACE_NEW"])
7069
CONDA_PATH = Path(os.environ["CONDA_PREFIX"])
71-
OTHER_INCLUDES.append(str(CONDA_PATH / "Library" / "include"))
70+
OTHER_INCLUDES.append(os.fspath(CONDA_PATH / "Library" / "include"))
7271
LDFLAGS = [
7372
f'-Wl,/LIBPATH:{CONDA_PATH / "Library" / "lib"}',
7473
f'-Wl,/LIBPATH:{CONDA_PATH / "libs"}',
@@ -93,13 +92,13 @@ def get_pybind_includes():
9392
CXX = "clang++"
9493
CXX_FLAGS.extend(["-undefined", "dynamic_lookup"])
9594

96-
CMDSTAN_INCLUDE_PATHS = [str(CMDSTAN.joinpath(*sub)) for sub in CMDSTAN_SUB_INCLUDES]
95+
CMDSTAN_INCLUDE_PATHS = [os.fspath(CMDSTAN.joinpath(*sub)) for sub in CMDSTAN_SUB_INCLUDES]
9796

9897
CPP_FLAGS = [f"-D{define}" for define in CPP_DEFINES] + [
9998
f"-I{path}"
10099
for path in CMDSTAN_INCLUDE_PATHS + OTHER_INCLUDES + get_pybind_includes()
101100
]
102-
EXT_SUFFIX = dist_sysconfig.get_config_var("EXT_SUFFIX")
101+
EXT_SUFFIX = sysconfig.get_config_var("EXT_SUFFIX")
103102
LDLIBS = [f"-l{lib}" for lib in LIBRARIES]
104103

105104

@@ -109,17 +108,17 @@ def expose(file: str):
109108
# create .cpp file and add pybind specific code
110109
subprocess.run(
111110
[
112-
str(STANC),
111+
os.fspath(STANC),
113112
"--standalone-functions",
114113
f"--include-paths={file_path.parent}",
115-
f"--o={file_path.parent / file_path.stem}.cpp-pre",
116-
str(file_path),
114+
f"--o={file_path.parent / file_path.with_suffix('.cpp-pre')}",
115+
os.fspath(file_path),
117116
],
118117
check=True,
119118
)
120119
preprocess.preprocess(
121-
str(file_path.parent / file_path.stem) + ".cpp-pre",
122-
out=(str(file_path.parent / file_path.stem) + ".cpp"),
120+
os.fspath(file_path.parent / file_path.with_suffix(".cpp-pre")),
121+
out=os.fspath(file_path.parent / file_path.with_suffix(".cpp")),
123122
)
124123

125124
# invoke compiler
@@ -128,8 +127,8 @@ def expose(file: str):
128127
+ CXX_FLAGS
129128
+ CPP_FLAGS
130129
+ [
131-
f"-o{file_path.parent / file_path.stem}{EXT_SUFFIX}",
132-
f"{file_path.parent / file_path.stem}.cpp",
130+
f"-o{file_path.parent / file_path.with_suffix(EXT_SUFFIX)}",
131+
os.fspath(file_path.parent / file_path.with_suffix(".cpp")),
133132
]
134133
+ LDFLAGS
135134
+ LDLIBS
@@ -138,6 +137,6 @@ def expose(file: str):
138137

139138
if res.returncode:
140139
raise RuntimeError("Build failed!\n" + " ".join(compile_command) + "\n" + res.stderr)
141-
sys.path.append(str(file_path.parent))
140+
sys.path.append(os.fspath(file_path.parent))
142141

143142
return importlib.import_module(file_path.stem)

pybind_stan_fns/preprocess.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def insert_includes(text):
2222
PYBIND11_MODULE({model_name}, m)
2323
{{
2424
25-
py::class_<boost::ecuyer1988>(m, "StanRNG")
25+
py::class_<stan::rng_t>(m, "StanRNG")
2626
.def(py::init<int>());
2727
2828
using acc = stan::math::accumulator<double>;
@@ -108,8 +108,8 @@ def populate_boilerplate(model_name, text):
108108
arg_names.append(arg_name.replace("&", "").replace("__", ""))
109109
arg_tys.append(arg_ty)
110110

111-
if arg.startswith("boost::ecuyer"):
112-
arg_defaults.append("boost::ecuyer1988(1234)")
111+
if arg.startswith("stan::rng_t"):
112+
arg_defaults.append("stan::rng_t(1234)")
113113
else:
114114
arg_defaults.append("")
115115

pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
11
[build-system]
22
requires = ["setuptools", "wheel"]
33
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "pybind_stan_fns"
7+
readme = "README.md"
8+
version = "0.0.1"
9+
license = { text = "BSD-3-Clause" }
10+
authors = [{ name = "Brian Ward", email = "bward@flatironinstitute.org" }]
11+
requires-python = ">=3.8"
12+
dependencies = ["numpy>=1.21.0", "cmdstanpy>=1.0.6", "pybind11"]
13+
14+
[project.urls]
15+
"Homepage" = "https://github.com/WardBrian/pybind_expose_stan_fns"
16+
17+
[tool.setuptools]
18+
packages = ["pybind_stan_fns"]
19+
20+
[project.optional-dependencies]
21+
test = ["pytest"]

0 commit comments

Comments
 (0)