-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP installs without cmdstanpy however also does not fail when using …
…pseudobatch[error_propagation]
- Loading branch information
Showing
4 changed files
with
236 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
# remove the old virtual environment if it exists | ||
rm -rf .venv-docker | ||
|
||
# Create a new virtual environment | ||
python -m venv .venv-docker | ||
|
||
# Activate the virtual environment | ||
source .venv-docker/bin/activate | ||
|
||
# Install the current directory | ||
pip install -e '.[development]' | ||
|
||
# Run the tests | ||
pytest | ||
|
||
# install error_propagation | ||
pip install '.[error_propagation]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,57 @@ | ||
import shutil | ||
import warnings | ||
from pathlib import Path | ||
import cmdstanpy | ||
from pseudobatch.error_propagation.error_propagation import ( | ||
run_error_propagation, | ||
) | ||
|
||
STAN_FILES_FOLDER = Path(__file__).parent / "stan" | ||
CMDSTAN_VERSION = "2.31.0" | ||
|
||
|
||
# on Windows specifically, we should point cmdstanpy to the repackaged | ||
# CmdStan if it exists. This lets cmdstanpy handle the TBB path for us. | ||
local_cmdstan = STAN_FILES_FOLDER / f"cmdstan-{CMDSTAN_VERSION}" | ||
if local_cmdstan.exists(): | ||
cmdstanpy.set_cmdstan_path(str(local_cmdstan.resolve())) | ||
|
||
|
||
def load_stan_model(name: str) -> cmdstanpy.CmdStanModel: | ||
""" | ||
Try to load precompiled Stan models. If that fails, | ||
compile them. | ||
""" | ||
try: | ||
model = cmdstanpy.CmdStanModel( | ||
exe_file=STAN_FILES_FOLDER / f"{name}.exe", | ||
stan_file=STAN_FILES_FOLDER / f"{name}.stan", | ||
compile=False, | ||
) | ||
except ValueError: | ||
warnings.warn(f"Failed to load pre-built model '{name}.exe', compiling") | ||
model = cmdstanpy.CmdStanModel( | ||
stan_file=STAN_FILES_FOLDER / f"{name}.stan", | ||
stanc_options={"O1": True}, | ||
) | ||
shutil.copy( | ||
model.exe_file, # type: ignore | ||
STAN_FILES_FOLDER / f"{name}.exe", | ||
) | ||
|
||
return model | ||
|
||
|
||
ERROR_PROPAGATION = load_stan_model("error_propagation") | ||
|
||
|
||
# example: just print the info of the model | ||
print(ERROR_PROPAGATION.exe_info()) | ||
from importlib.metadata import distribution | ||
|
||
try: | ||
distribution("cmdstanpy") | ||
import cmdstanpy | ||
|
||
cmdstanpy_installed = True | ||
except: | ||
cmdstanpy_installed = False | ||
|
||
if cmdstanpy_installed: | ||
from pseudobatch.error_propagation.error_propagation import ( | ||
run_error_propagation, | ||
) | ||
|
||
STAN_FILES_FOLDER = Path(__file__).parent / "stan" | ||
CMDSTAN_VERSION = "2.31.0" | ||
|
||
# on Windows specifically, we should point cmdstanpy to the repackaged | ||
# CmdStan if it exists. This lets cmdstanpy handle the TBB path for us. | ||
local_cmdstan = STAN_FILES_FOLDER / f"cmdstan-{CMDSTAN_VERSION}" | ||
if local_cmdstan.exists(): | ||
cmdstanpy.set_cmdstan_path(str(local_cmdstan.resolve())) | ||
|
||
def load_stan_model(name: str) -> cmdstanpy.CmdStanModel: | ||
""" | ||
Try to load precompiled Stan models. If that fails, | ||
compile them. | ||
""" | ||
try: | ||
model = cmdstanpy.CmdStanModel( | ||
exe_file=STAN_FILES_FOLDER / f"{name}.exe", | ||
stan_file=STAN_FILES_FOLDER / f"{name}.stan", | ||
compile=False, | ||
) | ||
except ValueError: | ||
warnings.warn( | ||
f"Failed to load pre-built model '{name}.exe', compiling" | ||
) | ||
model = cmdstanpy.CmdStanModel( | ||
stan_file=STAN_FILES_FOLDER / f"{name}.stan", | ||
stanc_options={"O1": True}, | ||
) | ||
shutil.copy( | ||
model.exe_file, # type: ignore | ||
STAN_FILES_FOLDER / f"{name}.exe", | ||
) | ||
|
||
return model | ||
|
||
ERROR_PROPAGATION = load_stan_model("error_propagation") | ||
|
||
# example: just print the info of the model | ||
print(ERROR_PROPAGATION.exe_info()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.