Skip to content

Commit

Permalink
Merge pull request #865 from uber/cmdstanpy-version-and-compile-fix
Browse files Browse the repository at this point in the history
Cmdstanpy version, and force compile logic
  • Loading branch information
edwinnglabs committed Mar 23, 2024
2 parents 60b3dde + 3c9009b commit 0b5fd69
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
16 changes: 12 additions & 4 deletions orbit/utils/stan.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
import json
import os
import platform
Expand Down Expand Up @@ -30,6 +31,12 @@
os.environ["Path"] += ";" + os.path.normpath(os.path.expanduser(path_string))


def get_file_time(path: str):
return datetime.fromtimestamp(os.path.getmtime(path)).replace(
second=0, microsecond=0
)


def get_compiled_stan_model(
stan_model_name: str = "",
stan_file_path: Optional[str] = None,
Expand Down Expand Up @@ -71,13 +78,14 @@ def get_compiled_stan_model(
)
# Check if exe is older than .stan file.
# This behavior is default on CmdStanModel if we don't have to specify the exe_file.
# if not os.path.isfile(exe_file) or (
# os.path.getmtime(exe_file) <= os.path.getmtime(stan_file)
# ):
if not os.path.isfile(exe_file) or (
get_file_time(exe_file) <= get_file_time(stan_file)
):
force_compile = True

if not os.path.isfile(exe_file) or force_compile:
logger.info(f"Compiling stan model:{stan_file}. ETA 3 - 5 mins.")
sm = CmdStanModel(stan_file=stan_file)
sm = CmdStanModel(stan_file=stan_file, force_compile=force_compile)
else:
sm = CmdStanModel(stan_file=stan_file, exe_file=exe_file)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ readme = "README.md"
requires-python = ">=3.7"
dependencies = [
"arviz",
"cmdstanpy>=1.0.4",
"cmdstanpy>=1.2.1",
"importlib_resources",
"matplotlib>=3.3.2",
"numpy>=1.18",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
arviz
cmdstanpy>=1.0.4
cmdstanpy>=1.2.1
importlib_resources
ipywidgets
matplotlib>=3.3.2
Expand Down

0 comments on commit 0b5fd69

Please sign in to comment.