Skip to content
New issue

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

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

Already on GitHub? # to your account

Rebase of MJA pull request on main (#241) #245

Merged
merged 1 commit into from
Jul 12, 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
5 changes: 5 additions & 0 deletions smash/_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def get_rr_states_from_structure(structure: str) -> list[str]:
return rr_states


### FLOAT PRECISION FOR FLOAT COMPARISON ###
F_PRECISION = 1.0e-5
############################################


### MODULE ###
##############

Expand Down
18 changes: 12 additions & 6 deletions smash/core/model/_standardize.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from smash._constant import (
DEFAULT_MODEL_SETUP,
F_PRECISION,
FEASIBLE_RR_INITIAL_STATES,
FEASIBLE_RR_PARAMETERS,
FEASIBLE_SERR_MU_PARAMETERS,
Expand All @@ -32,11 +33,16 @@
from smash.util._typing import AnyTuple, ListLike, Numeric


def _standardize_model_setup_bool(key: str, value: bool) -> bool:
if not isinstance(value, bool):
raise TypeError(f"{key} model setup must be a boolean")
def _standardize_model_setup_bool(key: str, value: bool | int) -> bool:
if isinstance(value, bool):
pass
elif isinstance(value, int):
if value not in (0, 1):
raise ValueError(f"{key} model setup must be equal to 0 or 1")
else:
raise TypeError(f"{key} model setup must be a boolean or integer (0, 1)")

return value
return bool(value)


def _standardize_model_setup_directory(read: bool, key: str, value: str | None) -> str:
Expand Down Expand Up @@ -531,7 +537,7 @@ def _standardize_rr_parameters_value(
f"{value.shape} into shape {model.mesh.flwdir.shape}"
)

if low_arr <= low or upp_arr >= upp:
if (low_arr + F_PRECISION) <= low or (upp_arr - F_PRECISION) >= upp:
raise ValueError(
f"Invalid value for model rr_parameter '{key}'. rr_parameter domain [{low_arr}, {upp_arr}] is "
f"not included in the feasible domain ]{low}, {upp}["
Expand All @@ -557,7 +563,7 @@ def _standardize_rr_states_value(
f"{value.shape} into shape {model.mesh.flwdir.shape}"
)

if low_arr <= low or upp_arr >= upp:
if (low_arr + F_PRECISION) <= low or (upp_arr - F_PRECISION) >= upp:
raise ValueError(
f"Invalid value for model {state_kind} '{key}'. {state_kind} domain [{low_arr}, {upp_arr}] is "
f"not included in the feasible domain ]{low}, {upp}["
Expand Down
15 changes: 8 additions & 7 deletions smash/core/simulation/_standardize.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
DEFAULT_TERMINATION_CRIT,
EVENT_SEG_KEYS,
F90_OPTIMIZER_CONTROL_TFM,
F_PRECISION,
FEASIBLE_RR_INITIAL_STATES,
FEASIBLE_RR_PARAMETERS,
FEASIBLE_SERR_MU_PARAMETERS,
Expand Down Expand Up @@ -107,7 +108,7 @@ def _standardize_simulation_samples(model: Model, samples: Samples) -> Samples:
arr = getattr(samples, key)
low_arr = np.min(arr)
upp_arr = np.max(arr)
if low_arr <= low or upp_arr >= upp:
if (low_arr + F_PRECISION) <= low or (upp_arr - F_PRECISION) >= upp:
raise ValueError(
f"Invalid sample values for parameter '{key}'. Sample domain [{low_arr}, {upp_arr}] is "
f"not included in the feasible domain ]{low}, {upp}["
Expand Down Expand Up @@ -239,13 +240,13 @@ def _standardize_simulation_optimize_options_bounds(

low_arr = np.min(arr)
upp_arr = np.max(arr)
if (low_arr + 1e-3) < value[0] or (upp_arr - 1e-3) > value[1]:
if (low_arr + F_PRECISION) < value[0] or (upp_arr - F_PRECISION) > value[1]:
raise ValueError(
f"Invalid bounds values for parameter '{key}'. Bounds domain [{value[0]}, {value[1]}] does "
f"not include parameter domain [{low_arr}, {upp_arr}] in bounds optimize_options"
)

if value[0] <= low or value[1] >= upp:
if (value[0] + F_PRECISION) <= low or (value[1] - F_PRECISION) >= upp:
raise ValueError(
f"Invalid bounds values for parameter '{key}'. Bounds domain [{value[0]}, {value[1]}] is not "
f"included in the feasible domain ]{low}, {upp}[ in bounds optimize_options"
Expand Down Expand Up @@ -1099,7 +1100,7 @@ def _standardize_simulation_parameters_feasibility(model: Model):
low_arr = np.min(arr)
upp_arr = np.max(arr)

if low_arr <= low or upp_arr >= upp:
if (low_arr + F_PRECISION) <= low or (upp_arr - F_PRECISION) >= upp:
raise ValueError(
f"Invalid value for model rr_parameter '{key}'. rr_parameter domain [{low_arr}, {upp_arr}] "
f"is not included in the feasible domain ]{low}, {upp}["
Expand All @@ -1111,7 +1112,7 @@ def _standardize_simulation_parameters_feasibility(model: Model):
low_arr = np.min(arr)
upp_arr = np.max(arr)

if low_arr <= low or upp_arr >= upp:
if (low_arr + F_PRECISION) <= low or (upp_arr - F_PRECISION) >= upp:
raise ValueError(
f"Invalid value for model rr_initial_state '{key}'. rr_initial_state domain "
f"[{low_arr}, {upp_arr}] is not included in the feasible domain ]{low}, {upp}["
Expand All @@ -1126,7 +1127,7 @@ def _standardize_simulation_parameters_feasibility(model: Model):
low_arr = np.min(arr)
upp_arr = np.max(arr)

if low_arr <= low or upp_arr >= upp:
if (low_arr + F_PRECISION) <= low or (upp_arr - F_PRECISION) >= upp:
raise ValueError(
f"Invalid value for model serr_mu_parameter '{key}'. serr_mu_parameter domain "
f"[{low_arr}, {upp_arr}] is not included in the feasible domain ]{low}, {upp}["
Expand All @@ -1140,7 +1141,7 @@ def _standardize_simulation_parameters_feasibility(model: Model):
low_arr = np.min(arr)
upp_arr = np.max(arr)

if low_arr <= low or upp_arr >= upp:
if (low_arr + F_PRECISION) <= low or (upp_arr - F_PRECISION) >= upp:
raise ValueError(
f"Invalid value for model serr_sigma_parameter '{key}'. serr_sigma_parameter domain "
f"[{low_arr}, {upp_arr}] is not included in the feasible domain ]{low}, {upp}["
Expand Down
20 changes: 5 additions & 15 deletions venv_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#When running this script, you will be prompted for your administrator password to install the required dependencies.

venv_path=~/python_venv
env_name=smash_1.0
env_name=smash_dev_1.0


#Parse input arguments
Expand Down Expand Up @@ -51,14 +51,14 @@ fi
#Warning to the user
if [ $(cat /etc/*release | grep ^NAME | grep -o Ubuntu) == "Ubuntu" ]; then

DEB_PACKAGE_NAME="gfortran build-essential gdal-bin libgdal-dev libshp-dev python3-gdal python3-venv python3-dev"
DEB_PACKAGE_NAME="gfortran build-essential python3-venv"
echo "==============================================="
echo "Make sure you first installed the following package (ubuntu): $DEB_PACKAGE_NAME"
echo "==============================================="

else

PACKAGE_NAME="gfortran build-essential gdal-bin libgdal-dev libshp-dev python3-gdal python3-venv python3-dev"
PACKAGE_NAME="gfortran build-essential python3-venv python3-dev"
echo "==============================================="
echo "Builging smash require some packages. Make sure you install them first. Install the corresponding package depending your distribution. On Debian/Ubuntu these package are: $PACKAGE_NAME"
echo "==============================================="
Expand All @@ -83,23 +83,14 @@ if [ ! -d "${venv_path}/.venv-${env_name}" ] ; then

#install python dependencies
pip install --upgrade pip
pip install 'numpy>=1.13,<=1.23'
pip install f90wrap
pip install wheel
pip install rasterio pandas h5py tqdm scipy pyyaml terminaltables matplotlib
pip install -r requirements-dev.txt

echo ''
echo 'Building Smash...'
echo ''

make

echo ''
echo 'Installing extra-package for building the documentation...'
echo ''
#install extra-package for building the documentation:
pip install sphinx numpydoc pydata-sphinx-theme ipython sphinxcontrib-bibtex sphinx-design sphinx-autosummary-accessors pytest pytest-cov black ruff fprettify

else
echo ''
echo "The python environnemnt ${venv_path}/${env_name} already exist..."
Expand All @@ -121,5 +112,4 @@ echo '>Then launch python:'
echo '(smash)> python'
echo 'Import the SMASH package in your python shell:'
echo '>>> import smash'
echo '************************************************'

echo '************************************************'