Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmdstanpy version, and force compile logic #865

Merged
merged 1 commit into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading