diff --git a/orbit/utils/stan.py b/orbit/utils/stan.py index 4f8441c3..39a7c912 100644 --- a/orbit/utils/stan.py +++ b/orbit/utils/stan.py @@ -1,3 +1,4 @@ +from datetime import datetime import json import os import platform @@ -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, @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 2ceebee4..bf140ca1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/requirements.txt b/requirements.txt index 1d034f4a..395bdf61 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ arviz -cmdstanpy>=1.0.4 +cmdstanpy>=1.2.1 importlib_resources ipywidgets matplotlib>=3.3.2